PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/nx-3.5.0/nx-X11/lib/font/Type1/t1info.c

#
C | 1096 lines | 861 code | 94 blank | 141 comment | 100 complexity | a689905ad39f4ce8900a28058a5d0530 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $Xorg: t1info.c,v 1.4 2001/02/09 02:04:01 xorgcvs Exp $ */
  2. /* Copyright International Business Machines,Corp. 1991
  3. * All Rights Reserved
  4. *
  5. * License, subject to the license given below, to use,
  6. * copy, modify, and distribute this software * and its
  7. * documentation for any purpose and without fee is hereby
  8. * granted, provided that the above copyright notice appear
  9. * in all copies and that both that copyright notice and
  10. * this permission notice appear in supporting documentation,
  11. * and that the name of IBM not be used in advertising or
  12. * publicity pertaining to distribution of the software
  13. * without specific, written prior permission.
  14. *
  15. * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
  16. * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
  17. * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
  19. * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
  20. * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
  21. * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
  22. * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
  23. * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
  24. * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  25. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  26. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  27. * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  28. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  29. * SOFTWARE.
  30. *
  31. * Author: Carol H. Thompson IBM Almaden Research Center
  32. * Modeled on spinfo.c by Dave Lemke, Network Computing Devices, Inc
  33. * which contains the following copyright and permission notices:
  34. *
  35. * Copyright 1990, 1991 Network Computing Devices;
  36. * Portions Copyright 1987 by Digital Equipment Corporation
  37. *
  38. * Permission to use, copy, modify, distribute, and sell this software and its
  39. * documentation for any purpose is hereby granted without fee, provided that
  40. * the above copyright notice appear in all copies and that both that
  41. * copyright notice and this permission notice appear in supporting
  42. * documentation, and that the names of Network Computing Devices or Digital
  43. * not be used in advertising or publicity pertaining to distribution of the
  44. * software without specific, written prior permission. Network Computing
  45. * Devices and Digital make no representations about the suitability of this
  46. * software for any purpose. It is provided "as is" without express or
  47. * implied warranty.
  48. *
  49. * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
  50. * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  51. * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
  52. * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  53. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  54. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  55. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  56. */
  57. /*
  58. Copyright 1987, 1998 The Open Group
  59. Permission to use, copy, modify, distribute, and sell this software and its
  60. documentation for any purpose is hereby granted without fee, provided that
  61. the above copyright notice appear in all copies and that both that
  62. copyright notice and this permission notice appear in supporting
  63. documentation.
  64. The above copyright notice and this permission notice shall be included
  65. in all copies or substantial portions of the Software.
  66. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  67. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  68. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  69. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  70. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  71. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  72. OTHER DEALINGS IN THE SOFTWARE.
  73. Except as contained in this notice, the name of The Open Group shall
  74. not be used in advertising or otherwise to promote the sale, use or
  75. other dealings in this Software without prior written authorization
  76. from The Open Group.
  77. */
  78. /* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
  79. *
  80. * The contents of this file are subject to the CID Font Code Public Licence
  81. * Version 1.0 (the "License"). You may not use this file except in compliance
  82. * with the Licence. You may obtain a copy of the License at Silicon Graphics,
  83. * Inc., attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA
  84. * 94043 or at http://www.sgi.com/software/opensource/cid/license.html.
  85. *
  86. * Software distributed under the License is distributed on an "AS IS" basis.
  87. * ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED
  88. * WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE OR OF
  89. * NON-INFRINGEMENT. See the License for the specific language governing
  90. * rights and limitations under the License.
  91. *
  92. * The Original Software is CID font code that was developed by Silicon
  93. * Graphics, Inc.
  94. */
  95. /* $XFree86: xc/lib/font/Type1/t1info.c,v 1.18tsi Exp $ */
  96. #ifdef HAVE_CONFIG_H
  97. #include <config.h>
  98. #endif
  99. #ifdef BUILDCID
  100. #define XFONT_CID 1
  101. #endif
  102. #include <X11/fonts/fntfilst.h>
  103. #include <X11/fonts/fontutil.h>
  104. #ifndef FONTMODULE
  105. #include <stdio.h>
  106. #ifndef BUILDCID
  107. #include <math.h>
  108. #endif
  109. #else
  110. #include "xf86_ansic.h"
  111. #endif
  112. #include <X11/fonts/FSproto.h>
  113. #if XFONT_CID
  114. #ifndef FONTMODULE
  115. #ifdef _XOPEN_SOURCE
  116. #include <math.h>
  117. #else
  118. #define _XOPEN_SOURCE
  119. #include <math.h>
  120. #undef _XOPEN_SOURCE
  121. #endif
  122. #endif
  123. #include "objects.h"
  124. #include "spaces.h"
  125. #include "range.h"
  126. #endif
  127. #if XFONT_CID
  128. #include "util.h"
  129. #include "fontfcn.h"
  130. #if defined(HAVE_CFM) || defined(CID_ALL_CHARS)
  131. #ifndef DEFAULT_CFM_DIR
  132. #define DEFAULT_CFM_DIR "./"
  133. #endif
  134. char cfmDefaultDir[] = DEFAULT_CFM_DIR;
  135. #define CFMMAGIC 0x91239123
  136. #endif
  137. #endif
  138. #include "t1intf.h"
  139. #define DECIPOINTSPERINCH 722.7
  140. #define DEFAULTRES 75
  141. #define DEFAULTPOINTSIZE 120
  142. enum scaleType {
  143. atom, truncate_atom, pixel_size, point_size, resolution_x,
  144. resolution_y, average_width
  145. };
  146. #if XFONT_CID
  147. extern cidfont *CIDFontP;
  148. static int stdpropsinit = 0;
  149. typedef struct cfm_rec {
  150. xCharInfo maxbounds;
  151. xCharInfo minbounds;
  152. xCharInfo ink_maxbounds;
  153. xCharInfo ink_minbounds;
  154. INT32 totalrw;
  155. INT16 maxo;
  156. INT16 alle;
  157. } cfmrec;
  158. #endif
  159. typedef struct _fontProp {
  160. char *name;
  161. long atom;
  162. enum scaleType type;
  163. } fontProp;
  164. static fontProp fontNamePropTable[] = { /* Example: */
  165. { "FOUNDRY", 0, atom }, /* adobe */
  166. { "FAMILY_NAME", 0, atom }, /* times roman */
  167. { "WEIGHT_NAME", 0, atom }, /* bold */
  168. { "SLANT", 0, atom }, /* i */
  169. { "SETWIDTH_NAME", 0, atom }, /* normal */
  170. { "ADD_STYLE_NAME", 0, atom }, /* */
  171. { "PIXEL_SIZE", 0, pixel_size }, /* 18 */
  172. { "POINT_SIZE", 0, point_size }, /* 180 */
  173. { "RESOLUTION_X", 0, resolution_x }, /* 72 */
  174. { "RESOLUTION_Y", 0, resolution_y }, /* 72 */
  175. { "SPACING", 0, atom }, /* p */
  176. { "AVERAGE_WIDTH", 0, average_width }, /* 0 */
  177. { "CHARSET_REGISTRY", 0, atom }, /* ISO8859 */
  178. { "CHARSET_ENCODING", 0, truncate_atom } /* 1 */
  179. };
  180. /* NOTICE: Following array is closely related to the sequence of defines
  181. following it. */
  182. static fontProp extraProps[] = {
  183. { "FONT", 0, },
  184. { "COPYRIGHT", 0, },
  185. { "RAW_PIXEL_SIZE", 0, },
  186. { "RAW_POINT_SIZE", 0, },
  187. { "RAW_ASCENT", 0, },
  188. { "RAW_DESCENT", 0, },
  189. { "RAW_AVERAGE_WIDTH", 0, },
  190. { "FACE_NAME", 0, },
  191. { "FONT_TYPE", 0, },
  192. { "RASTERIZER_NAME", 0, }
  193. };
  194. /* this is a bit kludgy */
  195. #define FONTPROP 0
  196. #define COPYRIGHTPROP 1
  197. #define RAWPIXELPROP 2
  198. #define RAWPOINTPROP 3
  199. #define RAWASCENTPROP 4
  200. #define RAWDESCENTPROP 5
  201. #define RAWWIDTHPROP 6
  202. #define FACE_NAMEPROP 7
  203. #define FONT_TYPEPROP 8
  204. #define RASTERIZER_NAMEPROP 9
  205. #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
  206. #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
  207. #define NPROPS (NNAMEPROPS + NEXTRAPROPS)
  208. /*ARGSUSED*/
  209. static void
  210. FillHeader(FontInfoPtr pInfo, FontScalablePtr Vals)
  211. {
  212. /* OpenScalable in T1FUNCS sets the following:
  213. pInfo->firstCol,
  214. pInfo->firstRow,
  215. pInfo->lastCol, and
  216. pInfo->lastRow. */
  217. /* the following are ununsed
  218. pInfo->pad. */
  219. /* Items we should handle better someday +++ */
  220. pInfo->defaultCh = 0;
  221. pInfo->drawDirection = LeftToRight;
  222. if (Vals->point_matrix[0] == Vals->point_matrix[3])
  223. pInfo->anamorphic = 0;
  224. else
  225. pInfo->anamorphic = 1;
  226. pInfo->inkMetrics = 0; /* no ink metrics here */
  227. pInfo->cachable = 1; /* no licensing (yet) */
  228. }
  229. static void
  230. adjust_min_max(xCharInfo *minc, xCharInfo *maxc, xCharInfo *tmp)
  231. {
  232. #define MINMAX(field,ci) \
  233. if (minc->field > (ci)->field) \
  234. minc->field = (ci)->field; \
  235. if (maxc->field < (ci)->field) \
  236. maxc->field = (ci)->field;
  237. MINMAX(ascent, tmp);
  238. MINMAX(descent, tmp);
  239. MINMAX(leftSideBearing, tmp);
  240. MINMAX(rightSideBearing, tmp);
  241. MINMAX(characterWidth, tmp);
  242. /* Do MINMAX for attributes field. Since that field is CARD16,
  243. we'll cast to a signed integer */
  244. if ((INT16)minc->attributes > (INT16)tmp->attributes)
  245. minc->attributes = tmp->attributes;
  246. if ((INT16)maxc->attributes < (INT16)tmp->attributes)
  247. maxc->attributes = tmp->attributes;
  248. #undef MINMAX
  249. }
  250. static void
  251. ComputeBounds(FontInfoPtr pInfo, CharInfoPtr pChars, FontScalablePtr Vals)
  252. {
  253. int i;
  254. xCharInfo minchar, maxchar;
  255. int numchars = 0;
  256. int totchars;
  257. int overlap;
  258. int maxlap;
  259. minchar.ascent = minchar.descent =
  260. minchar.leftSideBearing = minchar.rightSideBearing =
  261. minchar.characterWidth = minchar.attributes = 32767;
  262. maxchar.ascent = maxchar.descent =
  263. maxchar.leftSideBearing = maxchar.rightSideBearing =
  264. maxchar.characterWidth = maxchar.attributes = -32767;
  265. maxlap = -32767;
  266. totchars = pInfo->lastCol - pInfo->firstCol + 1;
  267. pChars += pInfo->firstCol;
  268. pInfo->allExist = 1;
  269. for (i = 0; i < totchars; i++,pChars++) {
  270. xCharInfo *pmetrics = &pChars->metrics;
  271. if (pmetrics->attributes ||
  272. pmetrics->ascent != -pmetrics->descent ||
  273. pmetrics->leftSideBearing != pmetrics->rightSideBearing) {
  274. numchars++;
  275. adjust_min_max(&minchar, &maxchar, pmetrics);
  276. overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
  277. if (overlap > maxlap) maxlap = overlap;
  278. }
  279. else pInfo->allExist = 0;
  280. }
  281. /* If we're monospaced, round the average width field to the
  282. nearest pixel */
  283. if (minchar.characterWidth == maxchar.characterWidth)
  284. Vals->width = minchar.characterWidth * 10;
  285. pInfo->maxbounds = maxchar;
  286. pInfo->minbounds = minchar;
  287. pInfo->ink_maxbounds = maxchar;
  288. pInfo->ink_minbounds = minchar;
  289. pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
  290. /* Set the pInfo flags */
  291. /* Properties set by FontComputeInfoAccelerators:
  292. pInfo->noOverlap;
  293. pInfo->terminalFont;
  294. pInfo->constantMetrics;
  295. pInfo->constantWidth;
  296. pInfo->inkInside;
  297. */
  298. FontComputeInfoAccelerators (pInfo);
  299. }
  300. #if XFONT_CID
  301. #ifdef CID_ALL_CHARS
  302. void
  303. ComputeBoundsAllChars(FontPtr pFont, char *cfmfilename, double sxmult)
  304. {
  305. FILE *cfm;
  306. CARD32 magic;
  307. int count = 0;
  308. int maxlap, overlap, i, j, k, ret;
  309. xCharInfo minchar, maxchar;
  310. cidrange *cidrangeP;
  311. unsigned char ccode[2];
  312. unsigned long ccount;
  313. xCharInfo *pmetrics;
  314. long total_raw_width = 0, total_width = 0;
  315. char cfmd[CID_PATH_MAX];
  316. cfmrec *cfmp;
  317. char *p;
  318. if (!(cfm = fopen(cfmfilename, "w"))) {
  319. fprintf(stderr,
  320. "Unable to open the file %s. You are probably not logged in as root.\n",
  321. cfmfilename);
  322. p = strrchr(cfmfilename, '/');
  323. if (p == NULL) exit(1);
  324. strcpy(cfmd, cfmDefaultDir);
  325. strcat(cfmd, p + 1);
  326. if (!(cfm = fopen(cfmd, "w"))) {
  327. fprintf(stderr,
  328. "Switching to current directory. Unable to open the file %s.\n",
  329. cfmd);
  330. exit(1);
  331. }
  332. }
  333. if ((cfmp = (cfmrec *)xalloc(sizeof(cfmrec))) == NULL) {
  334. fprintf(stderr, "Unable to allocate memory.");
  335. exit(1);
  336. }
  337. bzero(cfmp, sizeof(cfmrec));
  338. minchar.ascent = minchar.descent =
  339. minchar.leftSideBearing = minchar.rightSideBearing =
  340. minchar.characterWidth = minchar.attributes = 32767;
  341. maxchar.ascent = maxchar.descent =
  342. maxchar.leftSideBearing = maxchar.rightSideBearing =
  343. maxchar.characterWidth = maxchar.attributes = -32767;
  344. maxlap = -32767;
  345. cfmp->alle = 1;
  346. cidrangeP = CIDFontP->cidrangeP;
  347. /* go through all character codes specified in a given CMap */
  348. for (i = 0; i < CIDFontP->cidrangecnt; i++) {
  349. for (j = 0; j < cidrangeP->rangecnt; j++) {
  350. for (k = cidrangeP->range[j].srcCodeLo;
  351. k <= cidrangeP->range[j].srcCodeHi; k++) {
  352. ccode[0] = (k >> 8) & 0xff;
  353. ccode[1] = k & 0xff;
  354. ret = CIDGetMetrics(pFont, 1, ccode, Linear16Bit, &ccount, &pmetrics);
  355. if (ret != Successful || (ret == Successful && pmetrics == NULL))
  356. continue;
  357. total_width += pmetrics->attributes;
  358. total_raw_width += abs((int)(INT16)pmetrics->attributes);
  359. if (pmetrics->attributes ||
  360. pmetrics->ascent != -pmetrics->descent ||
  361. pmetrics->leftSideBearing != pmetrics->rightSideBearing) {
  362. count++;
  363. adjust_min_max(&minchar, &maxchar, pmetrics);
  364. overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
  365. if (overlap > maxlap) maxlap = overlap;
  366. }
  367. else cfmp->alle = 0;
  368. }
  369. }
  370. }
  371. if (count)
  372. {
  373. total_raw_width = (total_raw_width * 10 + count / 2) / count;
  374. if (total_width < 0)
  375. {
  376. /* Predominant direction is R->L */
  377. total_raw_width = -total_raw_width;
  378. }
  379. }
  380. cfmp->totalrw = (INT32)total_raw_width;
  381. cfmp->maxbounds.leftSideBearing =
  382. floor((double)maxchar.leftSideBearing * sxmult + 0.5);
  383. cfmp->maxbounds.rightSideBearing =
  384. floor((double)maxchar.rightSideBearing * sxmult + 0.5);
  385. cfmp->maxbounds.characterWidth =
  386. floor((double)maxchar.characterWidth * sxmult + 0.5);
  387. cfmp->maxbounds.ascent =
  388. floor((double)maxchar.ascent * sxmult + 0.5);
  389. cfmp->maxbounds.descent =
  390. floor((double)maxchar.descent * sxmult);
  391. cfmp->maxbounds.attributes = maxchar.attributes;
  392. cfmp->minbounds.leftSideBearing =
  393. floor((double)minchar.leftSideBearing * sxmult + 0.5);
  394. cfmp->minbounds.rightSideBearing =
  395. floor((double)minchar.rightSideBearing * sxmult + 0.5);
  396. cfmp->minbounds.characterWidth =
  397. floor((double)minchar.characterWidth * sxmult + 0.5);
  398. cfmp->minbounds.ascent =
  399. floor((double)minchar.ascent * sxmult + 0.5);
  400. cfmp->minbounds.descent =
  401. floor((double)minchar.descent * sxmult + 0.5);
  402. cfmp->minbounds.attributes = minchar.attributes;
  403. cfmp->ink_maxbounds.leftSideBearing =
  404. floor((double)maxchar.leftSideBearing * sxmult + 0.5);
  405. cfmp->ink_maxbounds.rightSideBearing =
  406. floor((double)maxchar.rightSideBearing * sxmult + 0.5);
  407. cfmp->ink_maxbounds.characterWidth =
  408. floor((double)maxchar.characterWidth * sxmult + 0.5);
  409. cfmp->ink_maxbounds.ascent =
  410. floor((double)maxchar.ascent * sxmult + 0.5);
  411. cfmp->ink_maxbounds.descent =
  412. floor((double)maxchar.descent * sxmult + 0.5);
  413. cfmp->ink_maxbounds.attributes = maxchar.attributes;
  414. cfmp->ink_minbounds.leftSideBearing =
  415. floor((double)minchar.leftSideBearing * sxmult + 0.5);
  416. cfmp->ink_minbounds.rightSideBearing =
  417. floor((double)minchar.rightSideBearing * sxmult + 0.5);
  418. cfmp->ink_minbounds.characterWidth =
  419. floor((double)minchar.characterWidth * sxmult + 0.5);
  420. cfmp->ink_minbounds.ascent =
  421. floor((double)minchar.ascent * sxmult + 0.5);
  422. cfmp->ink_minbounds.descent =
  423. floor((double)minchar.descent * sxmult + 0.5);
  424. cfmp->ink_minbounds.attributes = minchar.attributes;
  425. cfmp->maxo = (INT32)(maxlap + -(minchar.leftSideBearing));
  426. magic = CFMMAGIC;
  427. fwrite(&magic, sizeof(CARD32), 1, cfm);
  428. fwrite(cfmp, sizeof(cfmrec), 1, cfm);
  429. xfree(cfmp);
  430. fclose(cfm);
  431. }
  432. #else
  433. static long
  434. ComputeBoundsAll(FontPtr pFont)
  435. {
  436. int count = 0;
  437. int maxlap, overlap, i, j, k, ret;
  438. xCharInfo minchar, maxchar;
  439. cidrange *cidrangeP;
  440. unsigned char ccode[2];
  441. unsigned long ccount;
  442. xCharInfo *pmetrics;
  443. CharInfoRec *cinfo[1];
  444. long total_raw_width = 0, total_width = 0;
  445. FontInfoPtr pInfo = &(pFont->info);
  446. minchar.ascent = minchar.descent =
  447. minchar.leftSideBearing = minchar.rightSideBearing =
  448. minchar.characterWidth = minchar.attributes = 32767;
  449. maxchar.ascent = maxchar.descent =
  450. maxchar.leftSideBearing = maxchar.rightSideBearing =
  451. maxchar.characterWidth = maxchar.attributes = -32767;
  452. maxlap = -32767;
  453. pInfo->allExist = 1;
  454. cidrangeP = CIDFontP->cidrangeP;
  455. /* go through all character codes specified in a given CMap */
  456. for (i = 0; i < CIDFontP->cidrangecnt; i++) {
  457. for (j = 0; j < cidrangeP->rangecnt; j++) {
  458. for (k = cidrangeP->range[j].srcCodeLo;
  459. k <= cidrangeP->range[j].srcCodeHi; k++) {
  460. ccode[0] = (k >> 8) & 0xff;
  461. ccode[1] = k & 0xff;
  462. ret = CIDGetMetrics(pFont, 1, ccode, Linear16Bit, &ccount, (xCharInfo **)cinfo);
  463. if (ret != Successful || cinfo == NULL)
  464. continue;
  465. pmetrics = &cinfo[0]->metrics;
  466. total_width += pmetrics->attributes;
  467. total_raw_width += abs((int)(INT16)pmetrics->attributes);
  468. if (pmetrics->attributes ||
  469. pmetrics->ascent != -pmetrics->descent ||
  470. pmetrics->leftSideBearing != pmetrics->rightSideBearing) {
  471. count++;
  472. adjust_min_max(&minchar, &maxchar, pmetrics);
  473. overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
  474. if (overlap > maxlap) maxlap = overlap;
  475. }
  476. else pInfo->allExist = 0;
  477. }
  478. }
  479. }
  480. if (count)
  481. {
  482. total_raw_width = (total_raw_width * 10 + count / 2) / count;
  483. if (total_width < 0)
  484. {
  485. /* Predominant direction is R->L */
  486. total_raw_width = -total_raw_width;
  487. }
  488. }
  489. pInfo->maxbounds.leftSideBearing = maxchar.leftSideBearing;
  490. pInfo->maxbounds.rightSideBearing = maxchar.rightSideBearing;
  491. pInfo->maxbounds.characterWidth = maxchar.characterWidth;
  492. pInfo->maxbounds.ascent = maxchar.ascent;
  493. pInfo->maxbounds.descent = maxchar.descent;
  494. pInfo->maxbounds.attributes = maxchar.attributes;
  495. pInfo->minbounds.leftSideBearing = minchar.leftSideBearing;
  496. pInfo->minbounds.rightSideBearing = minchar.rightSideBearing;
  497. pInfo->minbounds.characterWidth = minchar.characterWidth;
  498. pInfo->minbounds.ascent = minchar.ascent;
  499. pInfo->minbounds.descent = minchar.descent;
  500. pInfo->minbounds.attributes = minchar.attributes;
  501. pInfo->ink_maxbounds.leftSideBearing = maxchar.leftSideBearing;
  502. pInfo->ink_maxbounds.rightSideBearing = maxchar.rightSideBearing;
  503. pInfo->ink_maxbounds.characterWidth = maxchar.characterWidth;
  504. pInfo->ink_maxbounds.ascent = maxchar.ascent;
  505. pInfo->ink_maxbounds.descent = maxchar.descent;
  506. pInfo->ink_maxbounds.attributes = maxchar.attributes;
  507. pInfo->ink_minbounds.leftSideBearing = minchar.leftSideBearing;
  508. pInfo->ink_minbounds.rightSideBearing = minchar.rightSideBearing;
  509. pInfo->ink_minbounds.characterWidth = minchar.characterWidth;
  510. pInfo->ink_minbounds.ascent = minchar.ascent;
  511. pInfo->ink_minbounds.descent = minchar.descent;
  512. pInfo->ink_minbounds.attributes = minchar.attributes;
  513. pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
  514. return total_raw_width;
  515. }
  516. #endif
  517. #endif
  518. static void
  519. ComputeProps(FontInfoPtr pInfo, FontScalablePtr Vals, char *Filename,
  520. long *sAscent, long *sDescent)
  521. {
  522. int infoint;
  523. int infoBBox[4];
  524. int rc;
  525. QueryFontLib(Filename, "isFixedPitch", &infoint, &rc);
  526. if (!rc) {
  527. pInfo->constantWidth = infoint;
  528. }
  529. QueryFontLib((char *)0, "FontBBox", infoBBox, &rc);
  530. if (!rc) {
  531. pInfo->fontAscent =
  532. (int)((double)infoBBox[3] * Vals->pixel_matrix[3] +
  533. (infoBBox[3] > 0 ? 500 : -500)) / 1000;
  534. pInfo->fontDescent =
  535. -(int)((double)infoBBox[1] * Vals->pixel_matrix[3] +
  536. (infoBBox[1] > 0 ? 500 : -500)) / 1000;
  537. *sAscent = infoBBox[3];
  538. *sDescent = -infoBBox[1];
  539. }
  540. }
  541. #if XFONT_CID
  542. #ifndef CID_ALL_CHARS
  543. static void
  544. CIDComputeStdProps(FontInfoPtr pInfo, FontScalablePtr Vals,
  545. char *Filename, char *Cmapname, char *Fontname,
  546. long sAscent, long sDescent, long sWidth)
  547. {
  548. FontPropPtr pp;
  549. int i,
  550. nprops;
  551. fontProp *fpt;
  552. char *is_str;
  553. char *ptr1 = NULL,
  554. *ptr2;
  555. char *ptr3;
  556. char *infostrP;
  557. int rc;
  558. char scaledName[CID_PATH_MAX];
  559. strcpy (scaledName, Fontname);
  560. /* Fill in our copy of the fontname from the Vals structure */
  561. FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
  562. /* This form of the properties is used by the X-client; the X-server
  563. doesn't care what they are. */
  564. nprops = pInfo->nprops = NPROPS;
  565. pInfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
  566. pInfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
  567. if (!pInfo->isStringProp || !pInfo->props) {
  568. xfree(pInfo->isStringProp);
  569. pInfo->isStringProp = (char *) 0;
  570. xfree(pInfo->props);
  571. pInfo->props = (FontPropPtr) 0;
  572. pInfo->nprops = 0;
  573. return;
  574. }
  575. bzero(pInfo->isStringProp, (sizeof(char) * nprops));
  576. ptr2 = scaledName;
  577. for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
  578. i;
  579. i--, pp++, fpt++, is_str++) {
  580. if (*ptr2)
  581. {
  582. ptr1 = ptr2 + 1;
  583. if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
  584. }
  585. pp->name = fpt->atom;
  586. switch (fpt->type) {
  587. case atom: /* Just copy info from scaledName */
  588. *is_str = TRUE;
  589. pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
  590. break;
  591. case truncate_atom:
  592. *is_str = TRUE;
  593. for (ptr3 = ptr1; *ptr3; ptr3++)
  594. if (*ptr3 == '[')
  595. break;
  596. pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
  597. break;
  598. case pixel_size:
  599. pp->value = (int)(fabs(Vals->pixel_matrix[3]) + .5);
  600. break;
  601. case point_size:
  602. pp->value = (int)(fabs(Vals->point_matrix[3]) * 10.0 + .5);
  603. break;
  604. case resolution_x:
  605. pp->value = Vals->x;
  606. break;
  607. case resolution_y:
  608. pp->value = Vals->y;
  609. break;
  610. case average_width:
  611. pp->value = Vals->width;
  612. break;
  613. }
  614. }
  615. for (i = 0, fpt = extraProps;
  616. i < NEXTRAPROPS;
  617. i++, is_str++, pp++, fpt++) {
  618. pp->name = fpt->atom;
  619. switch (i) {
  620. case FONTPROP:
  621. *is_str = TRUE;
  622. pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
  623. break;
  624. case COPYRIGHTPROP:
  625. *is_str = TRUE;
  626. CIDQueryFontLib(Filename, Cmapname, "Notice", &infostrP, &rc);
  627. if (rc || !infostrP) {
  628. infostrP = "Copyright Notice not available";
  629. }
  630. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  631. break;
  632. case FACE_NAMEPROP:
  633. *is_str = TRUE;
  634. CIDQueryFontLib(Filename, Cmapname, "CIDFontName", &infostrP, &rc);
  635. if (rc || !infostrP) {
  636. infostrP = "(unknown)";
  637. }
  638. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  639. break;
  640. case FONT_TYPEPROP:
  641. *is_str = TRUE;
  642. infostrP = "CIDFont";
  643. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  644. break;
  645. case RASTERIZER_NAMEPROP:
  646. *is_str = TRUE;
  647. infostrP = "X Consortium Type 1 Rasterizer";
  648. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  649. break;
  650. case RAWPIXELPROP:
  651. *is_str = FALSE;
  652. pp->value = 1000;
  653. break;
  654. case RAWPOINTPROP:
  655. *is_str = FALSE;
  656. pp->value = (long)(72270.0 / (double)Vals->y + .5);
  657. break;
  658. case RAWASCENTPROP:
  659. *is_str = FALSE;
  660. pp->value = sAscent;
  661. break;
  662. case RAWDESCENTPROP:
  663. *is_str = FALSE;
  664. pp->value = sDescent;
  665. break;
  666. case RAWWIDTHPROP:
  667. *is_str = FALSE;
  668. pp->value = sWidth;
  669. break;
  670. }
  671. }
  672. }
  673. #endif
  674. #endif
  675. static void
  676. ComputeStdProps(FontInfoPtr pInfo, FontScalablePtr Vals,
  677. char *Filename, char *Fontname,
  678. long sAscent, long sDescent, long sWidth)
  679. {
  680. FontPropPtr pp;
  681. int i,
  682. nprops;
  683. fontProp *fpt;
  684. char *is_str;
  685. char *ptr1 = NULL,
  686. *ptr2;
  687. char *ptr3;
  688. char *infostrP;
  689. int rc;
  690. char scaledName[MAXFONTNAMELEN];
  691. strcpy (scaledName, Fontname);
  692. /* Fill in our copy of the fontname from the Vals structure */
  693. FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
  694. /* This form of the properties is used by the X-client; the X-server
  695. doesn't care what they are. */
  696. nprops = pInfo->nprops = NPROPS;
  697. pInfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
  698. pInfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
  699. if (!pInfo->isStringProp || !pInfo->props) {
  700. xfree(pInfo->isStringProp);
  701. pInfo->isStringProp = (char *) 0;
  702. xfree(pInfo->props);
  703. pInfo->props = (FontPropPtr) 0;
  704. return;
  705. }
  706. bzero(pInfo->isStringProp, (sizeof(char) * nprops));
  707. ptr2 = scaledName;
  708. for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
  709. i;
  710. i--, pp++, fpt++, is_str++) {
  711. if (*ptr2)
  712. {
  713. ptr1 = ptr2 + 1;
  714. if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
  715. }
  716. pp->name = fpt->atom;
  717. switch (fpt->type) {
  718. case atom: /* Just copy info from scaledName */
  719. *is_str = TRUE;
  720. pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
  721. break;
  722. case truncate_atom:
  723. *is_str = TRUE;
  724. for (ptr3 = ptr1; *ptr3; ptr3++)
  725. if (*ptr3 == '[')
  726. break;
  727. pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
  728. break;
  729. case pixel_size:
  730. pp->value = (int)(fabs(Vals->pixel_matrix[3]) + .5);
  731. break;
  732. case point_size:
  733. pp->value = (int)(fabs(Vals->point_matrix[3]) * 10.0 + .5);
  734. break;
  735. case resolution_x:
  736. pp->value = Vals->x;
  737. break;
  738. case resolution_y:
  739. pp->value = Vals->y;
  740. break;
  741. case average_width:
  742. pp->value = Vals->width;
  743. break;
  744. }
  745. }
  746. for (i = 0, fpt = extraProps;
  747. i < NEXTRAPROPS;
  748. i++, is_str++, pp++, fpt++) {
  749. pp->name = fpt->atom;
  750. switch (i) {
  751. case FONTPROP:
  752. *is_str = TRUE;
  753. pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
  754. break;
  755. case COPYRIGHTPROP:
  756. *is_str = TRUE;
  757. QueryFontLib(Filename, "Notice", &infostrP, &rc);
  758. if (rc || !infostrP) {
  759. infostrP = "Copyright Notice not available";
  760. }
  761. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  762. break;
  763. case FACE_NAMEPROP:
  764. *is_str = TRUE;
  765. QueryFontLib(Filename, "FontName", &infostrP, &rc);
  766. if (rc || !infostrP) {
  767. infostrP = "(unknown)";
  768. }
  769. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  770. break;
  771. case FONT_TYPEPROP:
  772. *is_str = TRUE;
  773. infostrP = "Type 1";
  774. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  775. break;
  776. case RASTERIZER_NAMEPROP:
  777. *is_str = TRUE;
  778. infostrP = "X Consortium Type 1 Rasterizer";
  779. pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
  780. break;
  781. case RAWPIXELPROP:
  782. *is_str = FALSE;
  783. pp->value = 1000;
  784. break;
  785. case RAWPOINTPROP:
  786. *is_str = FALSE;
  787. pp->value = (long)(72270.0 / (double)Vals->y + .5);
  788. break;
  789. case RAWASCENTPROP:
  790. *is_str = FALSE;
  791. pp->value = sAscent;
  792. break;
  793. case RAWDESCENTPROP:
  794. *is_str = FALSE;
  795. pp->value = sDescent;
  796. break;
  797. case RAWWIDTHPROP:
  798. *is_str = FALSE;
  799. pp->value = sWidth;
  800. break;
  801. }
  802. }
  803. }
  804. #if XFONT_CID
  805. /*ARGSUSED*/
  806. int
  807. CIDGetInfoScalable(FontPathElementPtr fpe,
  808. FontInfoPtr pInfo,
  809. FontEntryPtr entry,
  810. FontNamePtr fontName,
  811. char *fileName,
  812. FontScalablePtr Vals)
  813. {
  814. FontPtr pfont;
  815. int flags = 0;
  816. long format = 0; /* It doesn't matter what format for just info */
  817. long fmask = 0;
  818. int ret;
  819. ret = CIDOpenScalable(fpe, &pfont, flags, entry, fileName, Vals,
  820. format, fmask, NULL);
  821. if (ret != Successful)
  822. return ret;
  823. *pInfo = pfont->info;
  824. /* XXX - Set pointers in pfont->info to NULL so they are not freed. */
  825. pfont->info.props = NULL;
  826. pfont->info.isStringProp = NULL;
  827. CIDCloseFont(pfont);
  828. return Successful;
  829. }
  830. #endif
  831. /*ARGSUSED*/
  832. int
  833. Type1GetInfoScalable(FontPathElementPtr fpe,
  834. FontInfoPtr pInfo,
  835. FontEntryPtr entry,
  836. FontNamePtr fontName,
  837. char *fileName,
  838. FontScalablePtr Vals)
  839. {
  840. FontPtr pfont;
  841. int flags = 0;
  842. long format = 0; /* It doesn't matter what format for just info */
  843. long fmask = 0;
  844. int ret;
  845. ret = Type1OpenScalable(fpe, &pfont, flags, entry, fileName, Vals,
  846. format, fmask , NULL);
  847. if (ret != Successful)
  848. return ret;
  849. *pInfo = pfont->info;
  850. /* XXX - Set pointers in pfont->info to NULL so they are not freed. */
  851. pfont->info.props = NULL;
  852. pfont->info.isStringProp = NULL;
  853. Type1CloseFont(pfont);
  854. return Successful;
  855. }
  856. #if XFONT_CID
  857. #ifndef CID_ALL_CHARS
  858. void
  859. CIDFillFontInfo(FontPtr pFont, FontScalablePtr Vals,
  860. char *Filename, char *Fontname, char *Cmapname,
  861. #ifdef HAVE_CFM
  862. char *cfmfilename,
  863. #endif
  864. long sAscent, long sDescent, double sxmult)
  865. {
  866. #ifdef HAVE_CFM
  867. FILE *cfm;
  868. cfmrec *cfmp;
  869. int gotcfm = 0;
  870. CARD32 magic;
  871. #endif
  872. long sWidth = 0;
  873. FontInfoPtr pInfo = &pFont->info;
  874. FillHeader(pInfo, Vals);
  875. #ifdef HAVE_CFM
  876. if ((cfm = fopen(cfmfilename,"r"))) {
  877. fread(&magic,sizeof(CARD32),1,cfm);
  878. if(magic == CFMMAGIC) {
  879. if ((cfmp = (cfmrec *)xalloc(sizeof(cfmrec))) != NULL) {
  880. fread(cfmp,sizeof(cfmrec),1,cfm);
  881. sWidth = (long)cfmp->totalrw;
  882. pInfo->allExist = cfmp->alle;
  883. if (sxmult != 0) {
  884. pInfo->maxbounds.leftSideBearing =
  885. floor((double)cfmp->maxbounds.leftSideBearing /
  886. sxmult + 0.5);
  887. pInfo->maxbounds.rightSideBearing =
  888. floor((double)cfmp->maxbounds.rightSideBearing /
  889. sxmult + 0.5);
  890. pInfo->maxbounds.characterWidth =
  891. floor((double)cfmp->maxbounds.characterWidth /
  892. sxmult + 0.5);
  893. pInfo->maxbounds.ascent =
  894. floor((double)cfmp->maxbounds.ascent /
  895. sxmult + 0.5);
  896. pInfo->maxbounds.descent =
  897. floor((double)cfmp->maxbounds.descent /
  898. sxmult + 0.5);
  899. pInfo->maxbounds.attributes =
  900. cfmp->maxbounds.attributes;
  901. pInfo->minbounds.leftSideBearing =
  902. cfmp->minbounds.leftSideBearing / sxmult;
  903. pInfo->minbounds.rightSideBearing =
  904. cfmp->minbounds.rightSideBearing / sxmult;
  905. pInfo->minbounds.characterWidth =
  906. cfmp->minbounds.characterWidth / sxmult;
  907. pInfo->minbounds.ascent =
  908. cfmp->minbounds.ascent / sxmult;
  909. pInfo->minbounds.descent =
  910. cfmp->minbounds.descent / sxmult;
  911. pInfo->minbounds.attributes = cfmp->minbounds.attributes;
  912. pInfo->ink_maxbounds.leftSideBearing =
  913. cfmp->ink_maxbounds.leftSideBearing / sxmult;
  914. pInfo->ink_maxbounds.rightSideBearing =
  915. cfmp->ink_maxbounds.rightSideBearing / sxmult;
  916. pInfo->ink_maxbounds.characterWidth =
  917. cfmp->ink_maxbounds.characterWidth / sxmult;
  918. pInfo->ink_maxbounds.ascent =
  919. cfmp->ink_maxbounds.ascent / sxmult;
  920. pInfo->ink_maxbounds.descent =
  921. cfmp->ink_maxbounds.descent / sxmult;
  922. pInfo->ink_maxbounds.attributes =
  923. cfmp->ink_maxbounds.attributes;
  924. pInfo->ink_minbounds.leftSideBearing =
  925. cfmp->ink_minbounds.leftSideBearing / sxmult;
  926. pInfo->ink_minbounds.rightSideBearing =
  927. cfmp->ink_minbounds.rightSideBearing / sxmult;
  928. pInfo->ink_minbounds.characterWidth =
  929. cfmp->ink_minbounds.characterWidth / sxmult;
  930. pInfo->ink_minbounds.ascent =
  931. cfmp->ink_minbounds.ascent / sxmult;
  932. pInfo->ink_minbounds.descent =
  933. cfmp->ink_minbounds.descent / sxmult;
  934. pInfo->ink_minbounds.attributes =
  935. cfmp->ink_minbounds.attributes;
  936. pInfo->ink_minbounds.attributes =
  937. cfmp->ink_minbounds.attributes;
  938. pInfo->maxOverlap = (short)cfmp->maxo;
  939. gotcfm = 1;
  940. }
  941. xfree(cfmp);
  942. }
  943. }
  944. fclose(cfm);
  945. }
  946. if (!gotcfm)
  947. #endif
  948. sWidth = ComputeBoundsAll(pFont);
  949. FontComputeInfoAccelerators(pInfo);
  950. CIDComputeStdProps(pInfo, Vals, Filename, Cmapname, Fontname, sAscent,
  951. sDescent, sWidth);
  952. }
  953. #endif /* CID_ALL_CHARS */
  954. #endif /* BUILDCID */
  955. void
  956. T1FillFontInfo(FontPtr pFont, FontScalablePtr Vals,
  957. char *Filename, char *Fontname, long sWidth)
  958. {
  959. FontInfoPtr pInfo = &pFont->info;
  960. struct type1font *p = (struct type1font *)pFont->fontPrivate;
  961. long sAscent, sDescent; /* Scalable 1000-pixel values */
  962. FillHeader(pInfo, Vals);
  963. ComputeBounds(pInfo, p->glyphs, Vals);
  964. ComputeProps(pInfo, Vals, Filename, &sAscent, &sDescent);
  965. ComputeStdProps(pInfo, Vals, Filename, Fontname, sAscent, sDescent, sWidth);
  966. }
  967. /* Called once, at renderer registration time */
  968. void
  969. #if XFONT_CID
  970. Type1InitStdProps(void)
  971. #else
  972. T1InitStdProps(void)
  973. #endif
  974. {
  975. int i;
  976. fontProp *t;
  977. #if XFONT_CID
  978. if (!stdpropsinit) {
  979. stdpropsinit = 1;
  980. i = sizeof(fontNamePropTable) / sizeof(fontProp);
  981. for (t = fontNamePropTable; i; i--, t++)
  982. t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  983. i = sizeof(extraProps) / sizeof(fontProp);
  984. for (t = extraProps; i; i--, t++)
  985. t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  986. }
  987. #else
  988. i = sizeof(fontNamePropTable) / sizeof(fontProp);
  989. for (t = fontNamePropTable; i; i--, t++)
  990. t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  991. i = sizeof(extraProps) / sizeof(fontProp);
  992. for (t = extraProps; i; i--, t++)
  993. t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  994. #endif
  995. }