PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/xorg-x11-xfs-1.1.2/showfont-1.0.3/showfont.c

#
C | 476 lines | 390 code | 30 blank | 56 comment | 92 complexity | 0f121302525129d2ced39ddb62a9fe96 MD5 | raw file
  1. /*
  2. * Copyright 1990 Network Computing Devices;
  3. * Portions Copyright 1987 by Digital Equipment Corporation
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the names of Network Computing Devices or Digital
  10. * not be used in advertising or publicity pertaining to distribution
  11. * of the software without specific, written prior permission.
  12. *
  13. * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
  14. * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETWORK COMPUTING DEVICES
  16. * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  17. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  18. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  19. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  20. * THIS SOFTWARE.
  21. */
  22. /*
  23. Copyright (c) 1987 X Consortium
  24. Permission is hereby granted, free of charge, to any person obtaining
  25. a copy of this software and associated documentation files (the
  26. "Software"), to deal in the Software without restriction, including
  27. without limitation the rights to use, copy, modify, merge, publish,
  28. distribute, sublicense, and/or sell copies of the Software, and to
  29. permit persons to whom the Software is furnished to do so, subject to
  30. the following conditions:
  31. The above copyright notice and this permission notice shall be included
  32. in all copies or substantial portions of the Software.
  33. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  34. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  35. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  36. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  37. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  38. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  39. OTHER DEALINGS IN THE SOFTWARE.
  40. Except as contained in this notice, the name of the X Consortium shall
  41. not be used in advertising or otherwise to promote the sale, use or
  42. other dealings in this Software without prior written authorization
  43. from the X Consortium.
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include <ctype.h>
  49. #include <X11/fonts/FSlib.h>
  50. /*
  51. * the equivalent of showsnf
  52. */
  53. #define GLWIDTHBYTESPADDED(bits,nbytes) \
  54. ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \
  55. :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \
  56. :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \
  57. :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \
  58. : 0)
  59. static int byteorder = MSBFirst; /* -LSB or -MSB */
  60. static int bitorder = MSBFirst; /* -lsb or -msb */
  61. static int bitmap_pad = 0; /* -bitmap_pad: ImageRect bitmap format */
  62. static int scan_pad = 8; /* -pad: ScanlinePad */
  63. static int scan_unit = 8; /* -unit: ScanlineUnit */
  64. static int first_ch = 0; /* -start: first character*/
  65. static int end_ch = ~0; /* -end: end character */
  66. static const char *ProgramName;
  67. static Bool no_props = False; /* -noprops: don't show font properties */
  68. static Bool extents_only = False; /* -extents_only */
  69. static FSServer *svr;
  70. /* set from bitmap_pad to ImageRectMin, ImageMaxWidth, or ImageMax */
  71. static int bitmap_format;
  72. static FSBitmapFormat
  73. make_format(void)
  74. {
  75. FSBitmapFormat format;
  76. format = 0;
  77. /* set up format */
  78. switch (scan_pad) {
  79. case 8:
  80. format |= BitmapFormatScanlinePad8;
  81. break;
  82. case 16:
  83. format |= BitmapFormatScanlinePad16;
  84. break;
  85. case 32:
  86. format |= BitmapFormatScanlinePad32;
  87. break;
  88. case 64:
  89. format |= BitmapFormatScanlinePad64;
  90. break;
  91. default:
  92. fprintf(stderr, "bogus scanline pad value: %d\n", scan_pad);
  93. break;
  94. }
  95. switch (scan_unit) {
  96. case 8:
  97. format |= BitmapFormatScanlineUnit8;
  98. break;
  99. case 16:
  100. format |= BitmapFormatScanlineUnit16;
  101. break;
  102. case 32:
  103. format |= BitmapFormatScanlineUnit32;
  104. break;
  105. case 64:
  106. format |= BitmapFormatScanlineUnit64;
  107. break;
  108. default:
  109. fprintf(stderr, "bogus scanline unit value: %d\n", scan_unit);
  110. break;
  111. }
  112. switch (bitmap_pad) {
  113. case 0:
  114. bitmap_format = BitmapFormatImageRectMin;
  115. break;
  116. case 1:
  117. bitmap_format = BitmapFormatImageRectMaxWidth;
  118. break;
  119. case 2:
  120. bitmap_format = BitmapFormatImageRectMax;
  121. break;
  122. default:
  123. fprintf(stderr, "bogus bitmap pad value: %d\n", bitmap_pad);
  124. break;
  125. }
  126. format |= bitmap_format;
  127. format |= (bitorder == MSBFirst) ? BitmapFormatBitOrderMSB :
  128. BitmapFormatBitOrderLSB;
  129. format |= (byteorder == MSBFirst) ? BitmapFormatByteOrderMSB :
  130. BitmapFormatByteOrderLSB;
  131. return format;
  132. }
  133. static void
  134. show_char_info(FSXCharInfo *ci)
  135. {
  136. printf("Left: %-3d Right: %-3d Ascent: %-3d Descent: %-3d Width: %d\n",
  137. ci->left, ci->right, ci->ascent, ci->descent, ci->width);
  138. }
  139. static void
  140. show_glyphs(
  141. Font fid,
  142. FSXFontInfoHeader *hdr,
  143. Bool show_all,
  144. FSChar2b first,
  145. FSChar2b last)
  146. {
  147. FSXCharInfo *extents;
  148. int err,
  149. ch,
  150. start;
  151. int offset = 0;
  152. unsigned char *glyphs;
  153. FSOffset *offsets;
  154. int scanpad;
  155. int r,
  156. b;
  157. FSBitmapFormat format;
  158. FSChar2b chars[2];
  159. int num_chars;
  160. int row,
  161. col,
  162. temp_ch;
  163. if (show_all) {
  164. num_chars = 0;
  165. } else {
  166. chars[0] = first;
  167. chars[1] = last;
  168. num_chars = 2;
  169. }
  170. FSQueryXExtents16(svr, fid, True, chars, num_chars, &extents);
  171. if (!extents_only) {
  172. format = make_format();
  173. err = FSQueryXBitmaps16(svr, fid, format, True, chars, num_chars,
  174. &offsets, &glyphs);
  175. if (err != FSSuccess) {
  176. fprintf(stderr, "QueryGlyphs failed\n");
  177. exit(1);
  178. }
  179. }
  180. scanpad = scan_pad >> 3;
  181. for (row = (int)first.high; row <= (int)last.high; row++) {
  182. start = first.low + (row << 8);
  183. for (col = (int)first.low; col <= (int)last.low; col++) {
  184. int bottom,
  185. bpr,
  186. charwidth;
  187. ch = ((row - (int)first.high)
  188. * ((int)last.low - (int)first.low + 1))
  189. + (col - (int)first.low);
  190. temp_ch = start + (col - (int)first.low);
  191. printf("char #%d", temp_ch);
  192. if ((temp_ch >= 0) && (temp_ch <= 127) && isprint(temp_ch))
  193. printf(" '%c'\n", (char) (temp_ch));
  194. else
  195. printf(" 0x%04x\n", temp_ch);
  196. show_char_info(&extents[ch]);
  197. if (extents_only)
  198. continue;
  199. if (offset != offsets[ch].position)
  200. fprintf(stderr, "offset mismatch: expected %d, got %d\n",
  201. offset, offsets[ch].position);
  202. switch (bitmap_format) {
  203. case BitmapFormatImageRectMin:
  204. bottom = extents[ch].descent + extents[ch].ascent;
  205. charwidth = extents[ch].right - extents[ch].left;
  206. break;
  207. case BitmapFormatImageRectMaxWidth:
  208. bottom = extents[ch].descent + extents[ch].ascent;
  209. charwidth = hdr->max_bounds.right - hdr->min_bounds.left;
  210. break;
  211. case BitmapFormatImageRectMax:
  212. bottom = hdr->max_bounds.ascent +
  213. hdr->max_bounds.descent;
  214. charwidth = hdr->max_bounds.right - hdr->min_bounds.left;
  215. break;
  216. default:
  217. bottom = 0;
  218. charwidth = 0;
  219. }
  220. if (extents[ch].left == 0 &&
  221. extents[ch].right == 0 &&
  222. extents[ch].width == 0 &&
  223. extents[ch].ascent == 0 &&
  224. extents[ch].descent == 0) {
  225. printf ("Nonexistent character\n");
  226. continue;
  227. }
  228. bpr = GLWIDTHBYTESPADDED(charwidth, scanpad);
  229. if (offsets[ch].length != bottom * bpr) {
  230. fprintf (stderr,
  231. "length mismatch: expected %d (%dx%d), got %d\n",
  232. bottom * bpr, bpr, bottom, offsets[ch].length);
  233. }
  234. offset = offsets[ch].position;
  235. for (r = 0; r < bottom; r++) {
  236. unsigned char *row = glyphs + offset;
  237. for (b = 0; b < charwidth; b++) {
  238. putchar((row[b >> 3] &
  239. (1 << (7 - (b & 7)))) ? '#' : '-');
  240. }
  241. putchar('\n');
  242. offset += bpr;
  243. }
  244. }
  245. }
  246. FSFree((char *) extents);
  247. if (!extents_only) {
  248. FSFree((char *) offsets);
  249. FSFree((char *) glyphs);
  250. }
  251. }
  252. static void
  253. show_props(
  254. FSPropInfo *pi,
  255. FSPropOffset *po,
  256. unsigned char *pd)
  257. {
  258. int i;
  259. char buf[512];
  260. int num_props;
  261. num_props = pi->num_offsets;
  262. for (i = 0; i < num_props; i++, po++) {
  263. strncpy(buf, (char *) (pd + po->name.position), po->name.length);
  264. buf[po->name.length] = '\0';
  265. printf("%s\t", buf);
  266. switch (po->type) {
  267. case PropTypeString:
  268. strncpy(buf, (char *)(pd + po->value.position), po->value.length);
  269. buf[po->value.length] = '\0';
  270. printf("%s\n", buf);
  271. break;
  272. case PropTypeUnsigned:
  273. printf("%lu\n", (unsigned long) po->value.position);
  274. break;
  275. case PropTypeSigned:
  276. printf("%ld\n", (long) po->value.position);
  277. break;
  278. default:
  279. fprintf(stderr, "bogus property\n");
  280. break;
  281. }
  282. }
  283. }
  284. static void
  285. show_info(
  286. Font fid,
  287. FSXFontInfoHeader *hdr,
  288. FSChar2b *first,
  289. FSChar2b *last)
  290. {
  291. FSPropInfo pi;
  292. FSPropOffset *po;
  293. unsigned char *pd;
  294. FSQueryXInfo(svr, fid, hdr, &pi, &po, &pd);
  295. printf("Direction: %s\n", (hdr->draw_direction == LeftToRightDrawDirection)
  296. ? "Left to Right" : "Right to Left");
  297. *first = hdr->char_range.min_char;
  298. *last = hdr->char_range.max_char;
  299. printf("Range: %d to %d\n",
  300. first->low + (first->high << 8),
  301. last->low + (last->high << 8));
  302. if (hdr->flags & FontInfoAllCharsExist)
  303. printf("All chars exist\n");
  304. printf("Default char: %d\n",
  305. hdr->default_char.low + (hdr->default_char.high << 8));
  306. printf("Min bounds: \n");
  307. show_char_info(&hdr->min_bounds);
  308. printf("Max bounds: \n");
  309. show_char_info(&hdr->max_bounds);
  310. printf("Font Ascent: %d Font Descent: %d\n",
  311. hdr->font_ascent, hdr->font_descent);
  312. if (!no_props)
  313. show_props(&pi, po, pd);
  314. FSFree((char *) po);
  315. FSFree((char *) pd);
  316. }
  317. static void
  318. usage(void)
  319. {
  320. printf("%s: [-server servername] [-extents_only] [-noprops] [-lsb] [-msb] [-LSB] [-MSB] [-unit #] [-pad #] [-bitmap_pad value] [-start first_char] [-end last_char] -fn fontname\n", ProgramName);
  321. exit(0);
  322. }
  323. int
  324. main(int argc, char **argv)
  325. {
  326. char *servername = "localhost:7100"; /* -server: font server name */
  327. char *fontname = NULL; /* -fn: font name */
  328. int i;
  329. Font fid,
  330. dummy;
  331. FSBitmapFormat format;
  332. FSBitmapFormatMask fmask;
  333. FSChar2b first,
  334. last;
  335. FSXFontInfoHeader hdr;
  336. Bool show_all = True;
  337. ProgramName = argv[0];
  338. for (i = 1; i < argc; i++) {
  339. if (!strncmp(argv[i], "-se", 3)) {
  340. if (++i < argc)
  341. servername = argv[i];
  342. else
  343. usage();
  344. } else if (!strncmp(argv[i], "-ext", 4)) {
  345. extents_only = True;
  346. } else if (!strncmp(argv[i], "-noprops", 7)) {
  347. no_props = True;
  348. } else if (!strncmp(argv[i], "-lsb", 4)) {
  349. bitorder = LSBFirst;
  350. } else if (!strncmp(argv[i], "-msb", 4)) {
  351. bitorder = MSBFirst;
  352. } else if (!strncmp(argv[i], "-LSB", 4)) {
  353. byteorder = LSBFirst;
  354. } else if (!strncmp(argv[i], "-MSB", 4)) {
  355. byteorder = MSBFirst;
  356. } else if (!strncmp(argv[i], "-p", 2)) {
  357. if (++i < argc)
  358. scan_pad = atoi(argv[i]);
  359. else
  360. usage();
  361. } else if (!strncmp(argv[i], "-u", 2)) {
  362. if (++i < argc)
  363. scan_unit = atoi(argv[i]);
  364. else
  365. usage();
  366. } else if (!strncmp(argv[i], "-b", 2)) {
  367. if (++i < argc)
  368. bitmap_pad = atoi(argv[i]);
  369. else
  370. usage();
  371. } else if (!strncmp(argv[i], "-st", 3)) {
  372. if (++i < argc)
  373. first_ch = atoi(argv[i]);
  374. else
  375. usage();
  376. } else if (!strncmp(argv[i], "-e", 2)) {
  377. if (++i < argc)
  378. end_ch = atoi(argv[i]);
  379. else
  380. usage();
  381. } else if (!strncmp(argv[i], "-f", 2)) {
  382. if (++i < argc)
  383. fontname = argv[i];
  384. else
  385. usage();
  386. } else
  387. usage();
  388. }
  389. if (fontname == NULL)
  390. usage();
  391. if (first_ch != 0 && end_ch != ~0 && end_ch < first_ch) {
  392. fprintf(stderr,
  393. "bad character range -- end (%d) is less than start (%d)\n",
  394. end_ch, first_ch);
  395. exit(1);
  396. }
  397. if ((svr = FSOpenServer(servername)) == NULL) {
  398. if(FSServerName(servername) != NULL)
  399. fprintf(stderr, "can't open server \"%s\"\n", FSServerName(servername));
  400. else
  401. fprintf(stderr, "can't open server \"\"\n");
  402. exit(1);
  403. }
  404. format = make_format();
  405. fmask = (BitmapFormatMaskByte | BitmapFormatMaskBit |
  406. BitmapFormatMaskImageRectangle | BitmapFormatMaskScanLinePad |
  407. BitmapFormatMaskScanLineUnit);
  408. fid = FSOpenBitmapFont(svr, format, fmask, fontname, &dummy);
  409. if (fid) {
  410. printf("opened font %s\n", fontname);
  411. show_info(fid, &hdr, &first, &last);
  412. if (first_ch != 0 &&
  413. ((unsigned)first_ch >= (first.low + (first.high << 8)))) {
  414. first.low = first_ch & 0xff;
  415. first.high = first_ch >> 8;
  416. show_all = False;
  417. }
  418. if (end_ch != ~0 &&
  419. ((unsigned)end_ch <= (last.low + (last.high << 8)))) {
  420. last.low = end_ch & 0xff;
  421. last.high = end_ch >> 8;
  422. show_all = False;
  423. }
  424. /* make sure the range is legal */
  425. if ((first.high > last.high) || (first.high == last.high &&
  426. first.low > last.low)) {
  427. last = first;
  428. fprintf(stderr,
  429. "adjusting range -- specifed first char is after end\n");
  430. }
  431. show_glyphs(fid, &hdr, show_all, first, last);
  432. FSCloseFont(svr, fid);
  433. } else {
  434. fprintf(stderr, "couldn't get font %s\n", fontname);
  435. FSCloseServer(svr);
  436. exit(1);
  437. }
  438. FSCloseServer(svr);
  439. exit(0);
  440. }