home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / fontutils-0.6-base.tgz / fontutils-0.6-base.tar / fsf / fontutils / fontconvert / output-epsf.c < prev    next >
C/C++ Source or Header  |  1992-06-09  |  4KB  |  139 lines

  1. /* output-epsf.c: output EPS files.
  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 "output-epsf.h"
  22.  
  23.  
  24. /* The base part of the fontname to output to.  */
  25. static string output_name;
  26.  
  27.  
  28. /* Remember OUTPUT_NAME, so we can use it to construct the output files.
  29.    It's a fatal error if NAME has a suffix, since that could mean
  30.    overwriting the same file several times with different information.  */
  31.  
  32. void
  33. epsf_start_output (string name)
  34. {
  35.   if (find_suffix (name) != NULL)
  36.     FATAL ("You can't specify a suffix and EPS output");
  37.  
  38.   output_name = name;
  39. }
  40.  
  41.  
  42. /* Write a single character to the file `output_name-CODE.eps',
  43.    where CODE is the character code.  */
  44.  
  45. /* Output the lower eight bits of VALUE to FILE as two hex digits.  For
  46.    reasons I don't understand, when I write these same expressions in
  47.    the arguments to the fprintf, values less than 128 are copied into
  48.    the high nybble; that is, 1 is output as `11'.  */
  49. #define OUTPUT_HEX(file, value)                        \
  50.   do                                    \
  51.     {  one_byte v1 = (value) & 0xf0;                    \
  52.        one_byte v2 = (value) & 0xf;                    \
  53.        fprintf (file, "%x%x", v1 >> 4, v2);                \
  54.     }                                    \
  55.   while (0)
  56.  
  57. void
  58. epsf_output_char (char_info_type c)
  59. {
  60.   unsigned row;
  61.   bitmap_type b = CHAR_BITMAP (c);
  62.   unsigned height = BITMAP_HEIGHT (b);
  63.   unsigned width = BITMAP_WIDTH (b);
  64.   charcode_type code = CHARCODE (c);
  65.   string title = concat3 (output_name, "-", itoa (code));
  66.   string eps_name = concat (title, ".eps");
  67.   FILE *eps = xfopen (eps_name, "w");
  68.   
  69.   /* Write the header.  */
  70.   fputs ("%!PS-Adobe-3.0 EPSF-3.0\n", eps);
  71.   fprintf (eps, "%%%%BoundingBox: 0 0 %u %u\n",
  72.            BITMAP_WIDTH (b), BITMAP_HEIGHT (b));
  73.   fprintf (eps, "%%%%Title: (%s)\n", title);
  74.   fputs ("%%Creator: fontconvert -epsf\n", eps);
  75.   fprintf (eps, "%%%%CreationDate: %s\n", now ());
  76.   fputs ("%%EndComments\n", eps);
  77.   
  78.   /* Write the bitmap as an image.  */
  79.   
  80.   /* First arrange to scale the image to its original size.  */
  81.   fprintf (eps, "%u %u scale\n", width, height);
  82.   
  83.   /* Push the imagemask parameters.  */
  84.   fprintf (eps, "%u %u  true  [%u 0 0 -%u 0 %u]\n",
  85.            width, height, width, height, height);
  86.  
  87.   /* Output the bits.  */
  88.   fputs ("{<", eps);
  89.   for (row = 0; row < height; row++)
  90.     {
  91.       unsigned col;
  92.       one_byte byte = 0;
  93.       unsigned bit = 7;
  94.  
  95.       for (col = 0; col < width; col++)
  96.         {
  97.           byte |= BITMAP_PIXEL (b, row, col) << bit;
  98.           
  99.           /* Output eight bits at a time, since imagemask expects that.  */
  100.           if (bit == 0)
  101.             {
  102.               OUTPUT_HEX (eps, byte);
  103.               byte = 0;
  104.               bit = 8;
  105.             }
  106.           
  107.           /* Decrement `bit' after, so that the test `bit == 0' above is
  108.              true at the right time.  */
  109.           bit--;
  110.         }
  111.       
  112.       /* If the width isn't a multiple of eight, have to output the
  113.          remainder.  */
  114.       if (bit < 7)
  115.         OUTPUT_HEX (eps, byte);
  116.       
  117.       /* In any case, output a newline, just to make the output easier
  118.          to read, in case somebody wants to read it.  */
  119.       fputs ("\n", eps);
  120.     }
  121.   fputs (">}\nimagemask\n", eps);
  122.   
  123.   /* Write the trailer.  */
  124.   fputs ("showpage\n", eps);
  125.   fputs ("%%EOF\n", eps);
  126.   
  127.   xfclose (eps, eps_name);
  128.   free (eps_name);
  129.   free (title);
  130. }
  131.  
  132.  
  133. /* We don't have anything to do at the end.  */
  134.  
  135. void
  136. epsf_finish_output (void)
  137. {
  138. }
  139.