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 / bzrto / text.c < prev    next >
C/C++ Source or Header  |  1992-10-11  |  4KB  |  134 lines

  1. /* text.c: translate the binary BZR font to human-oriented text, but
  2.    make the text sufficiently systematic that a computer can read it,
  3.    too.  The output format resembles the property list (PL) format to which
  4.    the TeX utility `tftopl' translates TFM files.
  5.  
  6. Copyright (C) 1992 Free Software Foundation, Inc.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "config.h"
  23.  
  24. #include <ctype.h>
  25. #include "text.h"
  26. #include "bzr.h"
  27.  
  28. /* Because Emacs Lisp doesn't have floating-point constants, we resort
  29.    to putting the numbers in strings.  */
  30. #define OUT_NUM4(n1, n2, n3, n4)                    \
  31.   do {                                    \
  32.     OUT_NUM2 (n1, n2);                            \
  33.     printf ("  ");                            \
  34.     OUT_NUM2 (n3, n4);                            \
  35.   } while (0)
  36.  
  37. #define OUT_NUM2(n1, n2) printf ("\"%.3f\" \"%.3f\"", n1, n2)
  38.  
  39.  
  40. /* Print the preamble.  */
  41.  
  42. void
  43. text_start_output (string font_name, bzr_preamble_type p)
  44. {
  45.   printf ("(fontfile \"%s\")\n", font_name);
  46.   printf ("(fontcomment \"%s\")\n", BZR_COMMENT (p));
  47.   printf ("(designsize %f)\n", BZR_DESIGN_SIZE (p));
  48. }
  49.  
  50. /* Print one character in the file.  The iteration through the spline
  51.    list isn't quite typical here, since we don't need to find the places
  52.    where a new outline starts.  */
  53.  
  54. void
  55. text_output_bzr_char (bzr_char_type c)
  56. {
  57.   unsigned this_list;
  58.   spline_list_array_type shape = BZR_SHAPE (c);
  59.   
  60.   printf ("(char %d (comment hex 0x%x, octal 0%o",
  61.           CHARCODE (c), CHARCODE (c), CHARCODE (c));
  62.   if (isprint (CHARCODE (c)))
  63.     printf (", ASCII `%c'", CHARCODE (c));
  64.   puts (")");
  65.  
  66.   printf ("  (width \"%.3f\")\n", CHAR_SET_WIDTH (c));
  67.   printf ("  (bb ");
  68.   OUT_NUM4 (CHAR_MIN_COL (c), CHAR_MAX_COL (c),
  69.             CHAR_MIN_ROW (c), CHAR_MAX_ROW (c));
  70.   puts (")");
  71.  
  72.   for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape);
  73.        this_list++)
  74.     {
  75.       unsigned this_spline;
  76.       spline_list_type list = SPLINE_LIST_ARRAY_ELT (shape, this_list);
  77.       
  78.       if (SPLINE_LIST_LENGTH (list) > 0)
  79.         {
  80.           real_coordinate_type start = START_POINT (SPLINE_LIST_ELT (list, 0));
  81.           printf ("  (outline ");
  82.           OUT_NUM2 (start.x, start.y);
  83.           puts ("");
  84.       
  85.           for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list);
  86.                this_spline++)
  87.             {
  88.               spline_type s = SPLINE_LIST_ELT (list, this_spline);
  89.  
  90.               if (SPLINE_DEGREE (s) == LINEAR)
  91.                 {
  92.                   printf ("    (line ");
  93.                   OUT_NUM2 (END_POINT (s).x, END_POINT (s).y);
  94.                 }
  95.  
  96.               else
  97.                 {
  98.                   printf ("    (spline ");
  99.                   OUT_NUM4 (CONTROL1 (s).x, CONTROL1 (s).y,
  100.                             CONTROL2 (s).x, CONTROL2 (s).y);
  101.                   printf ("  ");
  102.                   OUT_NUM2 (END_POINT (s).x, END_POINT(s).y);
  103.                 }
  104.               
  105.               puts (")");
  106.             }
  107.           puts ("  )");
  108.         }
  109.     }
  110.  
  111.   puts (")");
  112. }
  113.  
  114.  
  115. /* Output the composite character.  */
  116. void
  117. text_output_ccc_char (ccc_type c)
  118. {
  119. }
  120.  
  121. /* Print the parts of the postamble (as the library returns it -- some
  122.    more information is in the file, but not returned, because it is only
  123.    interesting for programs that read the file).  */
  124.  
  125. void
  126. text_finish_output (bzr_postamble_type p)
  127. {
  128.   printf ("(fontbb ");
  129.   OUT_NUM4 (MIN_COL (BZR_FONT_BB (p)), MAX_COL (BZR_FONT_BB (p)),
  130.             MIN_ROW (BZR_FONT_BB (p)), MAX_ROW (BZR_FONT_BB (p)));
  131.   puts (")");
  132.   printf ("(nchars %u)\n", BZR_NCHARS (p));
  133. }
  134.