home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fontutils-0.6 / imageto / out-strips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-02  |  3.2 KB  |  95 lines

  1. /* out-strips.c: cut the entire image into strips.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "gf.h"
  22. #include "report.h"
  23.  
  24. #include "main.h"
  25. #include "out-strips.h"
  26.  
  27. /* Output a ``font'' in which each ``character'' is a constant number of
  28.    scanlines from the image.  This might use less than resources than
  29.    the giant PostScript file that -epsf outputs.
  30.    
  31.    We only output the GF characters here; we assume the postamble and
  32.    preamble are written by the caller.  */
  33.  
  34. void
  35. write_chars_as_strips (image_header_type image_header, real design_size)
  36. {
  37.   dimensions_type char_dimens;
  38.   gf_char_type gf_char;
  39.   unsigned gf_row;
  40.   unsigned lines_per_char;
  41.   one_byte *scanline;
  42.   real width_in_points;
  43.   boolean first_char = true;
  44.   unsigned scanline_count = 0;
  45.  
  46.   /* Set up for the first character.  We divide the image into 256 parts,
  47.      each of which will turn into one ``character''.  */
  48.   lines_per_char = image_header.height / 256 + 1;
  49.   GF_CHARCODE (gf_char) = 0;
  50.   DIMENSIONS_WIDTH (char_dimens) = image_header.width;
  51.   DIMENSIONS_HEIGHT (char_dimens) = lines_per_char;
  52.   GF_BITMAP (gf_char) = new_bitmap (char_dimens);
  53.   GF_CHAR_MIN_COL (gf_char) = GF_CHAR_MIN_ROW (gf_char) = 0;
  54.   GF_CHAR_MAX_COL (gf_char) = DIMENSIONS_WIDTH (char_dimens);
  55.   GF_CHAR_MAX_ROW (gf_char) = DIMENSIONS_HEIGHT (char_dimens) - 1;
  56.   
  57.   /* We aren't going to have any side bearings.  */
  58.   GF_H_ESCAPEMENT (gf_char) = DIMENSIONS_WIDTH (char_dimens);
  59.   width_in_points = DIMENSIONS_WIDTH (char_dimens) * POINTS_PER_INCH
  60.                     / (real) image_header.hres;
  61.   GF_TFM_WIDTH (gf_char) = real_to_fix (width_in_points / design_size);
  62.   
  63.   
  64.   /* Read the image.  */
  65.   while (true)
  66.     {
  67.       if (scanline_count % lines_per_char == 0)
  68.         {
  69.           /* We get here when scanline_count == 0, and we haven't read
  70.              anything, so we can't write anything.  */
  71.           if (!first_char)
  72.             {
  73.               gf_put_char (gf_char);
  74.               REPORT2 ("[%u]%c", GF_CHARCODE (gf_char),
  75.                                 (GF_CHARCODE (gf_char) + 1) % 13 ? ' ' : '\n');
  76.               GF_CHARCODE (gf_char)++;
  77.             }
  78.           else
  79.             first_char = false;
  80.           gf_row = 0;
  81.         }
  82.  
  83.       scanline = BITMAP_BITS (GF_BITMAP (gf_char))
  84.                  + gf_row * DIMENSIONS_WIDTH (char_dimens); 
  85.       if (!(*image_get_scanline) (scanline)) break;
  86.  
  87.       scanline_count++;
  88.       gf_row++;
  89.     }
  90.   
  91.   if (scanline_count != image_header.height)
  92.     WARNING2 ("Expected %u scanlines, read %u", image_header.height,
  93.               scanline_count); 
  94. }
  95.