PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/xorg-x11-xfs-1.1.2/fstobdf-1.0.4/chars.c

#
C | 220 lines | 132 code | 21 blank | 67 comment | 24 complexity | c2dc92dcb70c0f9b9f0d6a5192c08fa5 MD5 | raw file
  1. /*
  2. Copyright 1990, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. * Copyright 1990 Network Computing Devices;
  20. * Portions Copyright 1987 by Digital Equipment Corporation
  21. *
  22. * Permission to use, copy, modify, distribute, and sell this software and
  23. * its documentation for any purpose is hereby granted without fee, provided
  24. * that the above copyright notice appear in all copies and that both that
  25. * copyright notice and this permission notice appear in supporting
  26. * documentation, and that the names of Network Computing Devices, or Digital
  27. * not be used in advertising or publicity pertaining to distribution
  28. * of the software without specific, written prior permission.
  29. *
  30. * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
  31. * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  32. * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
  33. * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  34. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  35. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  36. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  37. * THIS SOFTWARE.
  38. */
  39. /* Morten Storgaard Nielsen: chars.c,v 3.2-1 2000/01/30 14:11:19 kat Exp */
  40. #include <stdio.h>
  41. #include <X11/Xlib.h>
  42. #include "fstobdf.h"
  43. #define BIT_ORDER BitmapFormatBitOrderMSB
  44. #ifdef BYTE_ORDER
  45. #undef BYTE_ORDER
  46. #endif
  47. #define BYTE_ORDER BitmapFormatByteOrderMSB
  48. #define SCANLINE_UNIT BitmapFormatScanlineUnit8
  49. #define SCANLINE_PAD BitmapFormatScanlinePad8
  50. #define EXTENTS BitmapFormatImageRectMin
  51. #define SCANLINE_PAD_BYTES 1
  52. #define GLWIDTHBYTESPADDED(bits, nBytes) \
  53. ((nBytes) == 1 ? (((bits) + 7) >> 3) /* pad to 1 byte */\
  54. :(nBytes) == 2 ? ((((bits) + 15) >> 3) & ~1) /* pad to 2 bytes */\
  55. :(nBytes) == 4 ? ((((bits) + 31) >> 3) & ~3) /* pad to 4 bytes */\
  56. :(nBytes) == 8 ? ((((bits) + 63) >> 3) & ~7) /* pad to 8 bytes */\
  57. : 0)
  58. static void
  59. EmitBitmap(FILE *outFile,
  60. FSXFontInfoHeader *fontHeader,
  61. FSXCharInfo *charInfo,
  62. unsigned int encoding,
  63. int bpr,
  64. unsigned char *data)
  65. {
  66. char *glyphName;
  67. unsigned int row;
  68. /*-
  69. * format:
  70. * STARTCHAR name
  71. * ENCODING index
  72. * SWIDTH scalablewidth 0
  73. * DWIDTH pixels 0
  74. * BBX width height xoff yoff
  75. * ATTRIBUTES xxxx
  76. * BITMAP hhhhhhhh ...
  77. * ENDCHAR
  78. *
  79. * where, SWIDTH * (point / 1000) * (yres / 72) = DWIDTH or,
  80. * SWIDTH = 72000 *
  81. * DWIDTH / (point * yres)
  82. */
  83. fprintf(outFile, "STARTCHAR ");
  84. glyphName = XKeysymToString((KeySym) encoding);
  85. if (glyphName)
  86. fputs(glyphName, outFile);
  87. else
  88. fprintf(outFile, (fontHeader->char_range.min_char.low > 0 ?
  89. "C%06o" : "C%03o"), encoding);
  90. fputc('\n', outFile);
  91. fprintf(outFile, "ENCODING %u\n", encoding);
  92. fprintf(outFile, "SWIDTH %ld 0\n",
  93. (((long) charInfo->width) * 72000L) /
  94. (pointSize * yResolution));
  95. fprintf(outFile, "DWIDTH %d 0\n", charInfo->width);
  96. fprintf(outFile, "BBX %d %d %d %d\n",
  97. charInfo->right - charInfo->left,
  98. charInfo->ascent + charInfo->descent,
  99. charInfo->left,
  100. -charInfo->descent);
  101. if (charInfo->attributes)
  102. fprintf(outFile, "ATTRIBUTES %04x\n", charInfo->attributes);
  103. /*
  104. * emit the bitmap
  105. */
  106. fprintf(outFile, "BITMAP\n");
  107. for (row = 0; row < (charInfo->ascent + charInfo->descent); row++) {
  108. unsigned byte;
  109. unsigned bit;
  110. static unsigned maskTab[] =
  111. {
  112. (1 << 7), (1 << 6), (1 << 5), (1 << 4),
  113. (1 << 3), (1 << 2), (1 << 1), (1 << 0),
  114. };
  115. byte = 0;
  116. for (bit = 0; bit < (charInfo->right - charInfo->left); bit++) {
  117. byte |= maskTab[bit & 7] & data[bit >> 3];
  118. if ((bit & 7) == 7) {
  119. fprintf(outFile, "%02x", byte);
  120. byte = 0;
  121. }
  122. }
  123. if ((bit & 7) != 0)
  124. fprintf(outFile, "%02x", byte);
  125. fputc('\n', outFile);
  126. data += bpr;
  127. }
  128. fprintf(outFile, "ENDCHAR\n");
  129. }
  130. Bool
  131. EmitCharacters(FILE *outFile,
  132. FSServer *fontServer,
  133. FSXFontInfoHeader *fontHeader,
  134. Font fontID)
  135. {
  136. FSXCharInfo *extents;
  137. FSXCharInfo *charInfo;
  138. int encoding;
  139. FSOffset *offsets;
  140. unsigned char *glyph;
  141. unsigned char *glyphs;
  142. unsigned int nChars;
  143. int firstCharLow;
  144. int firstCharHigh;
  145. int lastCharLow;
  146. int lastCharHigh;
  147. int chLow;
  148. int chHigh;
  149. FSBitmapFormat format;
  150. nChars = 0;
  151. format = BYTE_ORDER | BIT_ORDER | SCANLINE_UNIT |
  152. SCANLINE_PAD | EXTENTS;
  153. firstCharLow = fontHeader->char_range.min_char.low;
  154. firstCharHigh = fontHeader->char_range.min_char.high;
  155. lastCharLow = fontHeader->char_range.max_char.low;
  156. lastCharHigh = fontHeader->char_range.max_char.high;
  157. (void) FSQueryXExtents16(fontServer, fontID, True, (FSChar2b *) 0, 0,
  158. &extents);
  159. (void) FSQueryXBitmaps16(fontServer, fontID, format, True, (FSChar2b *) 0,
  160. 0, &offsets, &glyphs);
  161. charInfo = extents;
  162. /* calculate the actual number of chars */
  163. for (chHigh = 0; chHigh <= (lastCharHigh-firstCharHigh); chHigh++) {
  164. for (chLow = 0; chLow <= (lastCharLow-firstCharLow); chLow++) {
  165. if ((charInfo->width != 0) || (charInfo->left != charInfo->right))
  166. nChars++;
  167. charInfo++;
  168. }
  169. }
  170. fprintf(outFile, "CHARS %u\n", nChars);
  171. /*
  172. * actually emit the characters
  173. */
  174. charInfo = extents;
  175. glyph = glyphs;
  176. for (chHigh = firstCharHigh; chHigh <= lastCharHigh; chHigh++) {
  177. for (chLow = firstCharLow; chLow <= lastCharLow; chLow++) {
  178. int bpr;
  179. bpr = GLWIDTHBYTESPADDED((charInfo->right - charInfo->left),
  180. SCANLINE_PAD_BYTES);
  181. encoding=(chHigh << 8)+chLow;
  182. if ((charInfo->width != 0) || (charInfo->right != charInfo->left))
  183. EmitBitmap(outFile, fontHeader, charInfo, encoding, bpr, glyph);
  184. glyph = glyphs +
  185. offsets[encoding-((firstCharHigh << 8)+firstCharLow) + 1].position;
  186. charInfo++;
  187. }
  188. }
  189. FSFree((char *) extents);
  190. FSFree((char *) glyphs);
  191. FSFree((char *) offsets);
  192. return (True);
  193. }