PageRenderTime 31ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C | 1668 lines | 1299 code | 214 blank | 155 comment | 298 complexity | acb2c8d00b8500d2745ebe6b0974fd3d MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /* $Xorg: t1funcs.c,v 1.5 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: Jeffrey B. Lotspiech, IBM Almaden Research Center
  32. * Modeled on spfuncs.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
  43. * or Digital not be used in advertising or publicity pertaining to
  44. * distribution of the software without specific, written prior permission.
  45. * Network Computing Devices or Digital make no representations about the
  46. * suitability of this software for any purpose. It is provided "as is"
  47. * without express or 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. /* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
  58. *
  59. * The contents of this file are subject to the CID Font Code Public Licence
  60. * Version 1.0 (the "License"). You may not use this file except in compliance
  61. * with the Licence. You may obtain a copy of the License at Silicon Graphics,
  62. * Inc., attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA
  63. * 94043 or at http://www.sgi.com/software/opensource/cid/license.html.
  64. *
  65. * Software distributed under the License is distributed on an "AS IS" basis.
  66. * ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED
  67. * WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE OR OF
  68. * NON-INFRINGEMENT. See the License for the specific language governing
  69. * rights and limitations under the License.
  70. *
  71. * The Original Software is CID font code that was developed by Silicon
  72. * Graphics, Inc.
  73. */
  74. /* $XFree86: xc/lib/font/Type1/t1funcs.c,v 3.33 2003/07/19 13:16:40 tsi Exp $ */
  75. /*
  76. Copyright 1987, 1994, 1998 The Open Group
  77. Permission to use, copy, modify, distribute, and sell this software and its
  78. documentation for any purpose is hereby granted without fee, provided that
  79. the above copyright notice appear in all copies and that both that
  80. copyright notice and this permission notice appear in supporting
  81. documentation.
  82. The above copyright notice and this permission notice shall be included
  83. in all copies or substantial portions of the Software.
  84. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  85. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  86. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  87. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  88. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  89. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  90. OTHER DEALINGS IN THE SOFTWARE.
  91. Except as contained in this notice, the name of The Open Group shall
  92. not be used in advertising or otherwise to promote the sale, use or
  93. other dealings in this Software without prior written authorization
  94. from The Open Group.
  95. */
  96. #ifdef HAVE_CONFIG_H
  97. #include <config.h>
  98. #endif
  99. #ifdef BUILDCID
  100. #define XFONT_CID 1
  101. #endif
  102. #ifndef FONTMODULE
  103. #include <string.h>
  104. #if XFONT_CID
  105. #include <stdlib.h>
  106. #include <sys/types.h>
  107. #include <dirent.h>
  108. #endif
  109. #ifdef _XOPEN_SOURCE
  110. #include <math.h>
  111. #else
  112. #define _XOPEN_SOURCE /* to get prototype for hypot on some systems */
  113. #include <math.h>
  114. #undef _XOPEN_SOURCE
  115. #endif
  116. #include "X11/Xfuncs.h"
  117. #ifdef USE_MMAP
  118. #include <sys/types.h>
  119. #include <sys/mman.h>
  120. #endif
  121. #else
  122. #include "Xmd.h"
  123. #include "Xdefs.h"
  124. #endif
  125. #ifdef FONTMODULE
  126. #include "os.h"
  127. #include "xf86_ansic.h"
  128. #endif
  129. #include <X11/fonts/fntfilst.h>
  130. #include <X11/fonts/fontutil.h>
  131. #include <X11/fonts/FSproto.h>
  132. #include <X11/fonts/fontenc.h>
  133. #include "t1unicode.h"
  134. #if XFONT_CID
  135. #include "range.h"
  136. #endif
  137. #include "objects.h"
  138. #include "spaces.h"
  139. #include "paths.h"
  140. #include "regions.h"
  141. #include "t1stdio.h"
  142. #include "util.h"
  143. #include "fontfcn.h"
  144. #include "t1intf.h"
  145. static int Type1GetGlyphs ( FontPtr pFont, unsigned long count,
  146. unsigned char *chars, FontEncoding charEncoding,
  147. unsigned long *glyphCount, CharInfoPtr *glyphs );
  148. #if XFONT_CID
  149. #define CMapDir "/CMap/"
  150. #define CFMDir "/CFM/"
  151. #define CIDFontDir "/CIDFont/"
  152. #endif
  153. static int Type1GetMetrics ( FontPtr pFont, unsigned long count,
  154. unsigned char *chars,
  155. FontEncoding charEncoding,
  156. unsigned long *glyphCount,
  157. xCharInfo **glyphs );
  158. #define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))
  159. #define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))
  160. static void fillrun ( char *p, pel x0, pel x1, int bit );
  161. extern psfont *FontP;
  162. extern psobj *ISOLatin1EncArrayP;
  163. #if XFONT_CID
  164. extern char CurCIDFontName[];
  165. extern char CurCMapName[];
  166. static CharInfoPtr CIDGetGlyph ( FontPtr pFont, unsigned int charcode,
  167. CharInfoPtr pci );
  168. extern cidfont *CIDFontP;
  169. extern cmapres *CMapP;
  170. #endif
  171. static void fill ( char *dest, int h, int w, struct region *area, int byte,
  172. int bit, int wordsize );
  173. #if XFONT_CID
  174. int
  175. CIDOpenScalable (FontPathElementPtr fpe,
  176. FontPtr *ppFont,
  177. int flags,
  178. FontEntryPtr entry,
  179. char *fileName,
  180. FontScalablePtr vals,
  181. fsBitmapFormat format,
  182. fsBitmapFormatMask fmask,
  183. FontPtr non_cachable_font) /* We don't do licensing */
  184. {
  185. FontPtr pFont;
  186. int bit,
  187. byte,
  188. glyph,
  189. scan,
  190. image;
  191. long *pool; /* memory pool for ximager objects */
  192. int size; /* for memory size calculations */
  193. struct XYspace *S; /* coordinate space for character */
  194. register int i;
  195. int nchars, len, rc;
  196. cidglyphs *cid;
  197. char *p;
  198. double t1 = .001, t2 = 0.0, t3 = 0.0, t4 = .001;
  199. double sxmult;
  200. char CIDFontName[CID_NAME_MAX];
  201. char CMapName[CID_NAME_MAX];
  202. char cidfontname[CID_PATH_MAX];
  203. char cmapname[CID_PATH_MAX];
  204. char *path;
  205. char cidfontpath[CID_PATH_MAX];
  206. char cmappath[CID_PATH_MAX];
  207. #if defined(HAVE_CFM) || defined(CID_ALL_CHARS)
  208. char cfmdir[CID_PATH_MAX];
  209. char cfmfilename[CID_NAME_MAX];
  210. #endif
  211. #if defined(CID_ALL_CHARS)
  212. char *cf;
  213. #else
  214. long sAscent, sDescent;
  215. #endif
  216. /* check the font name */
  217. len = strlen(fileName);
  218. if (len <= 0 || len > CID_NAME_MAX - 1)
  219. return BadFontName;
  220. #if defined(HAVE_CFM) || defined(CID_ALL_CHARS)
  221. strcpy(cfmdir, fileName);
  222. p = strrchr(cfmdir, '/');
  223. if (p) *p = '\0';
  224. #endif
  225. path = fileName;
  226. if (!(fileName = strrchr(fileName, '/')))
  227. return BadFontName;
  228. len = fileName - path;
  229. strncpy(cidfontpath, path, len);
  230. cidfontpath[len] = '\0';
  231. strcpy(cmappath, cidfontpath);
  232. strcat(cmappath, CMapDir);
  233. #ifdef HAVE_CFM
  234. strcpy(cfmdir, cidfontpath);
  235. strcat(cfmdir, CFMDir);
  236. #endif
  237. strcat(cidfontpath, CIDFontDir);
  238. fileName++;
  239. /* extract the CIDFontName and CMapName from the font name */
  240. /* check for <CIDFontName>--<CMapName> */
  241. if ((p = strstr(fileName, "--"))) {
  242. if (p == fileName)
  243. return BadFontName;
  244. else {
  245. strcpy(CIDFontName, fileName);
  246. CIDFontName[p - fileName] = '\0';
  247. p += 2;
  248. i = 0;
  249. while (*p && *p != '.')
  250. CMapName[i++] = *p++;
  251. CMapName[i] = '\0';
  252. if ((len = strlen(CMapName)) <= 0)
  253. return BadFontName;
  254. }
  255. } else
  256. return BadFontName;
  257. /* The CMap files whose names end with -V are not yet supported */
  258. len = strlen(CMapName);
  259. if ((len >= 2 && CMapName[len - 2] == '-' && CMapName[len - 1] == 'V') ||
  260. (len == 1 && CMapName[len - 1] == 'V'))
  261. return BadFontName;
  262. /* Reject ridiculously small font sizes that will blow up the math */
  263. if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 ||
  264. hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0)
  265. return BadFontName;
  266. #ifdef CID_ALL_CHARS
  267. if ((cf = getenv("CFMDIR")) == NULL)
  268. strcat(cfmdir, CFMDir);
  269. else {
  270. strcpy(cfmdir, cf);
  271. strcat(cfmdir, "/");
  272. }
  273. #endif
  274. #if defined(HAVE_CFM) || defined(CID_ALL_CHARS)
  275. strcpy(cfmfilename, cfmdir);
  276. strcat(cfmfilename, CIDFontName);
  277. strcat(cfmfilename, "--");
  278. strcat(cfmfilename, CMapName);
  279. strcat(cfmfilename, ".cfm");
  280. #endif
  281. /* create a full-path name for a CIDFont file */
  282. if (strlen(cidfontpath) + strlen(CIDFontName) + 2 >
  283. CID_PATH_MAX)
  284. return BadFontName;
  285. strcpy(cidfontname, cidfontpath);
  286. strcat(cidfontname, CIDFontName);
  287. /* create a full-path name for a CMap file */
  288. if (strlen(cmappath) + strlen(CMapName) + 2 > CID_PATH_MAX)
  289. return BadFontName;
  290. strcpy(cmapname, cmappath);
  291. strcat(cmapname, CMapName);
  292. /* set up default values */
  293. FontDefaultFormat(&bit, &byte, &glyph, &scan);
  294. /* get any changes made from above */
  295. rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  296. if (rc != Successful)
  297. return rc;
  298. #define PAD(bits, pad) (((bits)+(pad)-1)&-(pad))
  299. if (!(pFont = CreateFontRec()))
  300. return AllocError;
  301. cid = (cidglyphs *)xalloc(sizeof(cidglyphs));
  302. if (cid == NULL) {
  303. DestroyFontRec(pFont);
  304. return AllocError;
  305. }
  306. bzero(cid, sizeof(cidglyphs));
  307. /* heuristic for "maximum" size of pool we'll need: */
  308. size = 200000 + 600 *
  309. (int)hypot(vals->pixel_matrix[2], vals->pixel_matrix[3])
  310. * sizeof(short);
  311. if (size < 0 || NULL == (pool = (long *) xalloc(size))) {
  312. xfree(cid);
  313. DestroyFontRec(pFont);
  314. return AllocError;
  315. }
  316. addmemory(pool, size);
  317. /* load font if not already loaded */
  318. if (!CIDfontfcnA(cidfontname, cmapname, &rc)) {
  319. FontP = NULL;
  320. delmemory();
  321. xfree(pool);
  322. xfree(cid);
  323. DestroyFontRec(pFont);
  324. return Type1ReturnCodeToXReturnCode(rc);
  325. }
  326. FontP = NULL;
  327. S = (struct XYspace *) t1_Transform((struct xobject *)IDENTITY,
  328. t1, t2, t3, t4);
  329. S = (struct XYspace *) Permanent(t1_Transform((struct xobject *)S,
  330. vals->pixel_matrix[0],
  331. -vals->pixel_matrix[1],
  332. vals->pixel_matrix[2],
  333. -vals->pixel_matrix[3]));
  334. /* multiplier for computation of raw values */
  335. sxmult = hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]);
  336. if (sxmult > EPS) sxmult = 1000.0 / sxmult;
  337. pFont->info.firstRow = CMapP->firstRow;
  338. pFont->info.firstCol = CMapP->firstCol;
  339. pFont->info.lastRow = CMapP->lastRow;
  340. pFont->info.lastCol = CMapP->lastCol;
  341. nchars = (pFont->info.lastRow - pFont->info.firstRow + 1) *
  342. (pFont->info.lastCol - pFont->info.firstCol + 1);
  343. delmemory();
  344. xfree(pool);
  345. if (pFont->info.firstCol > pFont->info.lastCol)
  346. {
  347. xfree(cid);
  348. DestroyFontRec(pFont);
  349. return BadFontName;
  350. }
  351. cid->glyphs = (CharInfoRec **)xalloc(nchars*sizeof(CharInfoRec *));
  352. if (cid->glyphs == NULL) {
  353. xfree(cid);
  354. DestroyFontRec(pFont);
  355. return AllocError;
  356. }
  357. bzero(cid->glyphs, nchars*sizeof(CharInfoRec *));
  358. pFont->info.defaultCh = 0;
  359. pFont->format = format;
  360. pFont->bit = bit;
  361. pFont->byte = byte;
  362. pFont->glyph = glyph;
  363. pFont->scan = scan;
  364. pFont->get_metrics = CIDGetMetrics;
  365. pFont->get_glyphs = CIDGetGlyphs;
  366. pFont->unload_font = CIDCloseFont;
  367. pFont->unload_glyphs = NULL;
  368. pFont->refcnt = 0;
  369. len = strlen(cidfontname);
  370. cid->CIDFontName = (char *)xalloc(len + 1);
  371. if (cid->CIDFontName == NULL) {
  372. xfree(cid->glyphs);
  373. xfree(cid);
  374. DestroyFontRec(pFont);
  375. return AllocError;
  376. }
  377. strcpy(cid->CIDFontName, cidfontname);
  378. len = strlen(cmapname);
  379. cid->CMapName = (char *)xalloc(len + 1);
  380. if (cid->CMapName == NULL) {
  381. xfree(cid->CIDFontName);
  382. xfree(cid->glyphs);
  383. xfree(cid);
  384. DestroyFontRec(pFont);
  385. return AllocError;
  386. }
  387. strcpy(cid->CMapName, cmapname);
  388. cid->pixel_matrix[0] = vals->pixel_matrix[0];
  389. cid->pixel_matrix[1] = vals->pixel_matrix[1];
  390. cid->pixel_matrix[2] = vals->pixel_matrix[2];
  391. cid->pixel_matrix[3] = vals->pixel_matrix[3];
  392. pFont->fontPrivate = (unsigned char *)cid;
  393. pFont->info.fontAscent =
  394. (CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[3].data.integer *
  395. vals->pixel_matrix[3] +
  396. (CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[3].data.integer >
  397. 0 ? 500 : -500)) / 1000;
  398. pFont->info.fontDescent =
  399. -(int)((double)CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[1].data.integer
  400. * vals->pixel_matrix[3] +
  401. (CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[1].data.integer >
  402. 0 ? 500 : -500)) / 1000;
  403. /* Adobe does not put isFixedPitch entries in CID-keyed fonts. */
  404. /* CID-keyed are not constant-width fonts. */
  405. pFont->info.constantWidth = 0;
  406. #ifndef CID_ALL_CHARS
  407. sAscent = CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[3].data.integer;
  408. sDescent = -CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP[1].data.integer;
  409. #endif
  410. if (strncmp(entry->name.name, "-bogus", 6)) {
  411. #ifdef CID_ALL_CHARS
  412. ComputeBoundsAllChars(pFont, cfmfilename, sxmult);
  413. #else
  414. #ifdef HAVE_CFM
  415. CIDFillFontInfo(pFont, vals, cidfontname, entry->name.name, cmapname,
  416. cfmfilename, sAscent, sDescent, sxmult);
  417. #else
  418. CIDFillFontInfo(pFont, vals, cidfontname, entry->name.name, cmapname,
  419. sAscent, sDescent, sxmult);
  420. #endif /* HAVE_CFM */
  421. #endif /* CID_ALL_CHARS */
  422. }
  423. *ppFont = pFont;
  424. return Successful;
  425. }
  426. #endif
  427. /*ARGSUSED*/
  428. int
  429. Type1OpenScalable (FontPathElementPtr fpe,
  430. FontPtr *ppFont,
  431. int flags,
  432. FontEntryPtr entry,
  433. char *fileName,
  434. FontScalablePtr vals,
  435. fsBitmapFormat format,
  436. fsBitmapFormatMask fmask,
  437. FontPtr non_cachable_font) /* We don't do licensing */
  438. {
  439. FontPtr pFont;
  440. int bit,
  441. byte,
  442. glyph,
  443. scan,
  444. image;
  445. int pad,wordsize; /* scan & image in bits */
  446. long *pool; /* memory pool for ximager objects */
  447. int size; /* for memory size calculations */
  448. struct XYspace *S; /* coordinate space for character */
  449. struct region *area;
  450. CharInfoRec *glyphs;
  451. int len, rc, count = 0, i = 0;
  452. struct type1font *type1;
  453. char *p;
  454. FontMapPtr mapping = NULL;
  455. int no_mapping;
  456. psobj *fontmatrix;
  457. long x0, total_width = 0, total_raw_width = 0;
  458. double x1, y1, t1 = .001, t2 = 0.0, t3 = 0.0, t4 = .001;
  459. double sxmult;
  460. /* Reject ridiculously small font sizes that will blow up the math */
  461. if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 ||
  462. hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0)
  463. return BadFontName;
  464. /* set up default values */
  465. FontDefaultFormat(&bit, &byte, &glyph, &scan);
  466. /* get any changes made from above */
  467. rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  468. if (rc != Successful)
  469. return rc;
  470. pad = glyph * 8;
  471. wordsize = scan * 8;
  472. #define PAD(bits, pad) (((bits)+(pad)-1)&-(pad))
  473. pFont = CreateFontRec();
  474. if (pFont == NULL)
  475. return AllocError;
  476. type1 = (struct type1font *)xalloc(sizeof(struct type1font));
  477. if (type1 == NULL) {
  478. DestroyFontRec(pFont);
  479. return AllocError;
  480. }
  481. bzero(type1, sizeof(struct type1font));
  482. /* heuristic for "maximum" size of pool we'll need: */
  483. #if XFONT_CID
  484. size = 400000 + 600 *
  485. #else
  486. size = 200000 + 600 *
  487. #endif
  488. (int)hypot(vals->pixel_matrix[2], vals->pixel_matrix[3])
  489. * sizeof(short);
  490. if (size < 0 || NULL == (pool = (long *) xalloc(size))) {
  491. xfree(type1);
  492. DestroyFontRec(pFont);
  493. return AllocError;
  494. }
  495. addmemory(pool, size);
  496. glyphs = type1->glyphs;
  497. /* load font if not already loaded */
  498. if (!fontfcnA(fileName, &rc)) {
  499. delmemory();
  500. xfree(type1);
  501. DestroyFontRec(pFont);
  502. xfree(pool);
  503. return Type1ReturnCodeToXReturnCode(rc);
  504. }
  505. fontmatrix = &FontP->fontInfoP[FONTMATRIX].value;
  506. if (objPIsArray(fontmatrix) && fontmatrix->len == 6)
  507. {
  508. #define assign(n,d,f) if (objPIsInteger(fontmatrix->data.arrayP + n)) \
  509. d = fontmatrix->data.arrayP[n].data.integer; \
  510. else if (objPIsReal(fontmatrix->data.arrayP + n)) \
  511. d = fontmatrix->data.arrayP[n].data.real; \
  512. else d = f;
  513. assign(0, t1, .001);
  514. assign(1, t2, 0.0);
  515. assign(2, t3, 0.0);
  516. assign(3, t4, .001);
  517. }
  518. S = (struct XYspace *) t1_Transform((struct xobject *)IDENTITY,
  519. t1, t2, t3, t4);
  520. S = (struct XYspace *) Permanent(t1_Transform((struct xobject *)S,
  521. vals->pixel_matrix[0],
  522. -vals->pixel_matrix[1],
  523. vals->pixel_matrix[2],
  524. -vals->pixel_matrix[3]));
  525. /* multiplier for computation of raw values */
  526. sxmult = hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]);
  527. if (sxmult > EPS) sxmult = 1000.0 / sxmult;
  528. no_mapping=0;
  529. p = FontEncFromXLFD(entry->name.name, entry->name.length);
  530. if(p==0) { /* XLFD does not specify an encoding */
  531. mapping=0;
  532. no_mapping=2; /* ISO 8859-1 */
  533. }
  534. if(!strcmp(p, "adobe-fontspecific")) {
  535. mapping=0;
  536. no_mapping=1; /* font's native encoding vector */
  537. }
  538. pFont->info.firstCol = 255;
  539. pFont->info.lastCol = 0;
  540. if(!no_mapping) {
  541. mapping = FontEncMapFind(p,
  542. FONT_ENCODING_POSTSCRIPT, -1, -1,
  543. fileName);
  544. if(!mapping)
  545. mapping = FontEncMapFind(p,
  546. FONT_ENCODING_UNICODE, -1, -1,
  547. fileName);
  548. if(!mapping)
  549. goto NoEncoding;
  550. else
  551. no_mapping=0;
  552. }
  553. for (i=0; i < 256; i++) {
  554. long h,w;
  555. long paddedW;
  556. int j;
  557. char *codename;
  558. if(no_mapping == 1) {
  559. codename = FontP->fontInfoP[ENCODING].
  560. value.data.arrayP[i].data.valueP;
  561. len = FontP->fontInfoP[ENCODING].
  562. value.data.arrayP[i].len;
  563. } else if(no_mapping) {
  564. codename = unicodetoPSname(i);
  565. len = codename ? strlen(codename) : 0;
  566. } else {
  567. if(mapping->type == FONT_ENCODING_UNICODE) {
  568. codename = unicodetoPSname(FontEncRecode(i, mapping));
  569. } else
  570. codename = FontEncName(i, mapping);
  571. len=codename?strlen(codename):0;
  572. }
  573. /* Avoid multiply rasterising the undefined glyph */
  574. if(len==7 && !strncmp(codename, ".notdef", 7)) {
  575. len=0;
  576. codename=0;
  577. }
  578. /* But do rasterise it at least once */
  579. if(len==0) {
  580. if(i==0) {
  581. codename=".notdef";
  582. len=7;
  583. } else
  584. continue;
  585. }
  586. /* See if this character is in the list of ranges specified
  587. in the XLFD name */
  588. if(i!=0) {
  589. for (j = 0; j < vals->nranges; j++)
  590. if (i >= minchar(vals->ranges[j]) &&
  591. i <= maxchar(vals->ranges[j]))
  592. break;
  593. /* If not, don't realize it. */
  594. if (vals->nranges && j == vals->nranges)
  595. continue;
  596. }
  597. rc = 0;
  598. area = (struct region *)fontfcnB(S, (unsigned char *)codename,
  599. &len, &rc);
  600. if (rc < 0) {
  601. rc = Type1ReturnCodeToXReturnCode(rc);
  602. break;
  603. }
  604. else if (rc > 0)
  605. continue;
  606. if (area == NULL)
  607. continue;
  608. if (pFont->info.firstCol > i)
  609. pFont->info.firstCol = i;
  610. if (pFont->info.lastCol < i)
  611. pFont->info.lastCol = i;
  612. h = area->ymax - area->ymin;
  613. w = area->xmax - area->xmin;
  614. paddedW = PAD(w, pad);
  615. if (h > 0 && w > 0) {
  616. size = h * paddedW / 8;
  617. glyphs[i].bits = (char *)xalloc(size);
  618. if (glyphs[i].bits == NULL) {
  619. rc = AllocError;
  620. break;
  621. }
  622. }
  623. else {
  624. size = 0;
  625. h = w = 0;
  626. area->xmin = area->xmax = 0;
  627. area->ymax = area->ymax = 0;
  628. }
  629. glyphs[i].metrics.leftSideBearing = area->xmin;
  630. x1 = (double)(x0 = area->ending.x - area->origin.x);
  631. y1 = (double)(area->ending.y - area->origin.y);
  632. glyphs[i].metrics.characterWidth =
  633. (x0 + (x0 > 0 ? FPHALF : -FPHALF)) / (1 << FRACTBITS);
  634. if (!glyphs[i].metrics.characterWidth && size == 0)
  635. {
  636. /* Zero size and zero extents: presumably caused by
  637. the choice of transformation. Let's create a
  638. small bitmap so we're not mistaken for an undefined
  639. character. */
  640. h = w = 1;
  641. size = paddedW = PAD(w, pad);
  642. glyphs[i].bits = (char *)xalloc(size);
  643. if (glyphs[i].bits == NULL) {
  644. rc = AllocError;
  645. break;
  646. }
  647. }
  648. glyphs[i].metrics.attributes =
  649. NEARESTPEL((long)(hypot(x1, y1) * sxmult));
  650. total_width += glyphs[i].metrics.attributes;
  651. total_raw_width += abs((int)(INT16)glyphs[i].metrics.attributes);
  652. count++;
  653. glyphs[i].metrics.rightSideBearing = w + area->xmin;
  654. glyphs[i].metrics.descent = area->ymax - NEARESTPEL(area->origin.y);
  655. glyphs[i].metrics.ascent = h - glyphs[i].metrics.descent;
  656. bzero(glyphs[i].bits, size);
  657. if (h > 0 && w > 0) {
  658. fill(glyphs[i].bits, h, paddedW, area, byte, bit, wordsize );
  659. }
  660. Destroy(area);
  661. }
  662. NoEncoding:
  663. delmemory();
  664. xfree(pool);
  665. if (pFont->info.firstCol > pFont->info.lastCol)
  666. {
  667. xfree(type1);
  668. DestroyFontRec(pFont);
  669. return BadFontName;
  670. }
  671. if (i != 256) {
  672. for (i--; i >= 0; i--)
  673. if (glyphs[i].bits != NULL)
  674. xfree(glyphs[i].bits);
  675. xfree(type1);
  676. DestroyFontRec(pFont);
  677. return rc;
  678. }
  679. type1->pDefault = NULL;
  680. pFont->format = format;
  681. pFont->bit = bit;
  682. pFont->byte = byte;
  683. pFont->glyph = glyph;
  684. pFont->scan = scan;
  685. pFont->info.firstRow = 0;
  686. pFont->info.lastRow = 0;
  687. pFont->get_metrics = Type1GetMetrics;
  688. pFont->get_glyphs = Type1GetGlyphs;
  689. pFont->unload_font = Type1CloseFont;
  690. pFont->unload_glyphs = NULL;
  691. pFont->refcnt = 0;
  692. pFont->fontPrivate = (unsigned char *) type1;
  693. if (count)
  694. {
  695. total_raw_width = (total_raw_width * 10 + count / 2) / count;
  696. if (total_width < 0)
  697. {
  698. /* Predominant direction is R->L */
  699. total_raw_width = -total_raw_width;
  700. }
  701. vals->width = (int)((double)total_raw_width *
  702. vals->pixel_matrix[0] / 1000.0 +
  703. (vals->pixel_matrix[0] > 0 ? .5 : -.5));
  704. }
  705. T1FillFontInfo(pFont, vals, fileName, entry->name.name, total_raw_width);
  706. *ppFont = pFont;
  707. return Successful;
  708. }
  709. #if XFONT_CID
  710. unsigned int
  711. getCID(FontPtr pFont, unsigned int charcode)
  712. {
  713. unsigned int cidcode = 0;
  714. Bool charvalid = FALSE;
  715. cidglyphs *cid;
  716. int i, j;
  717. unsigned int char_row, char_col, rangelo_row, rangelo_col, k;
  718. unsigned int rangehi_row, rangehi_col;
  719. spacerange *spacerangeP;
  720. cidrange *notdefrangeP, *cidrangeP;
  721. cid = (cidglyphs *)pFont->fontPrivate;
  722. if (cid == NULL)
  723. return cidcode;
  724. char_row = (charcode >> 8) & 0xff;
  725. char_col = charcode & 0xff;
  726. spacerangeP = CIDFontP->spacerangeP;
  727. for (i = 0; i < CIDFontP->spacerangecnt; i++) {
  728. for (j = 0; j < spacerangeP->rangecnt; j++) {
  729. rangelo_row =
  730. (spacerangeP->spacecode[j].srcCodeLo >> 8) & 0xff;
  731. rangelo_col = spacerangeP->spacecode[j].srcCodeLo & 0xff;
  732. rangehi_row =
  733. (spacerangeP->spacecode[j].srcCodeHi >> 8) & 0xff;
  734. rangehi_col = spacerangeP->spacecode[j].srcCodeHi & 0xff;
  735. if (char_row >= rangelo_row && char_row <= rangehi_row &&
  736. char_col >= rangelo_col && char_col <= rangehi_col) {
  737. charvalid = TRUE;
  738. break;
  739. }
  740. }
  741. if (charvalid) break;
  742. spacerangeP = spacerangeP->next;
  743. }
  744. if (charvalid) {
  745. charvalid = FALSE;
  746. cidrangeP = CIDFontP->cidrangeP;
  747. for (i = 0; i < CIDFontP->cidrangecnt; i++) {
  748. for (j = 0; j < cidrangeP->rangecnt; j++) {
  749. rangelo_row =
  750. (cidrangeP->range[j].srcCodeLo >> 8) & 0xff;
  751. rangelo_col = cidrangeP->range[j].srcCodeLo & 0xff;
  752. rangehi_row =
  753. (cidrangeP->range[j].srcCodeHi >> 8) & 0xff;
  754. rangehi_col = cidrangeP->range[j].srcCodeHi & 0xff;
  755. if (char_row >= rangelo_row && char_row <= rangehi_row &&
  756. char_col >= rangelo_col && char_col <= rangehi_col) {
  757. charvalid = TRUE;
  758. for (k = cidrangeP->range[j].srcCodeLo;
  759. k <= cidrangeP->range[j].srcCodeHi; k++) {
  760. if (k == charcode)
  761. cidcode = cidrangeP->range[j].dstCIDLo + k -
  762. cidrangeP->range[j].srcCodeLo;
  763. }
  764. break;
  765. }
  766. }
  767. if (charvalid) break;
  768. cidrangeP = cidrangeP->next;
  769. }
  770. }
  771. if (charvalid) {
  772. charvalid = FALSE;
  773. notdefrangeP = CIDFontP->notdefrangeP;
  774. for (i = 0; i < CIDFontP->notdefrangecnt; i++) {
  775. for (j = 0; j < notdefrangeP->rangecnt; j++) {
  776. rangelo_row =
  777. (notdefrangeP->range[j].srcCodeLo >> 8) & 0xff;
  778. rangelo_col = notdefrangeP->range[j].srcCodeLo & 0xff;
  779. rangehi_row =
  780. (notdefrangeP->range[j].srcCodeHi >> 8) & 0xff;
  781. rangehi_col = notdefrangeP->range[j].srcCodeHi & 0xff;
  782. if (char_row >= rangelo_row && char_row <= rangehi_row &&
  783. char_col >= rangelo_col && char_col <= rangehi_col) {
  784. charvalid = TRUE;
  785. for (k = notdefrangeP->range[j].srcCodeLo;
  786. k <= notdefrangeP->range[j].srcCodeHi; k++) {
  787. if (k == charcode)
  788. /* the whole range is mapped to a single CID code */
  789. cidcode = notdefrangeP->range[j].dstCIDLo;
  790. }
  791. break;
  792. }
  793. }
  794. if (charvalid) break;
  795. notdefrangeP = notdefrangeP->next;
  796. }
  797. }
  798. /* If you specify a CMap that has more CIDs than a specified CIDFont, */
  799. /* the program could go beyond the number of entries in CIDMap. Make */
  800. /* sure that that does not happen. */
  801. if (cidcode < CIDFontP->CIDfontInfoP[CIDCOUNT].value.data.integer)
  802. return cidcode;
  803. else
  804. return 0;
  805. }
  806. static CharInfoPtr
  807. CIDGetGlyph(FontPtr pFont, unsigned int charcode, CharInfoPtr pci)
  808. {
  809. int rc;
  810. CharInfoPtr cp = NULL;
  811. unsigned int cidcode;
  812. /* character code -> CID */
  813. cidcode = getCID(pFont, charcode);
  814. cp = CIDGetGlyphInfo(pFont, cidcode, pci, &rc);
  815. if (rc != Successful && cidcode) {
  816. cidcode = 0;
  817. cp = CIDGetGlyphInfo(pFont, cidcode, pci, &rc);
  818. }
  819. return cp;
  820. }
  821. int
  822. CIDGetGlyphs(FontPtr pFont,
  823. unsigned long count,
  824. unsigned char *chars,
  825. FontEncoding charEncoding,
  826. unsigned long *glyphCount, /* RETURN */
  827. CharInfoPtr *glyphs) /* RETURN */
  828. {
  829. unsigned int code, char_row, char_col;
  830. CharInfoPtr *glyphsBase;
  831. register unsigned int c;
  832. CharInfoPtr pci;
  833. CharInfoPtr pDefault;
  834. cidglyphs *cid;
  835. register int firstCol;
  836. int rc = 0;
  837. int cid_valid = 0;
  838. cid = (cidglyphs *)pFont->fontPrivate;
  839. FontP = NULL;
  840. firstCol = pFont->info.firstCol;
  841. pDefault = cid->pDefault;
  842. glyphsBase = glyphs;
  843. switch (charEncoding) {
  844. #define EXIST(pci) \
  845. ((pci)->metrics.attributes || \
  846. (pci)->metrics.ascent != -(pci)->metrics.descent || \
  847. (pci)->metrics.leftSideBearing != (pci)->metrics.rightSideBearing)
  848. case Linear8Bit:
  849. case TwoD8Bit:
  850. if (pFont->info.firstRow > 0)
  851. break;
  852. while (count--) {
  853. c = (*chars++);
  854. if (c >= firstCol && c <= pFont->info.lastCol) {
  855. code = c - firstCol;
  856. if (!(pci = (CharInfoRec *)cid->glyphs[code]) ||
  857. ((long)pci->bits == CID_BITMAP_UNDEFINED)) {
  858. /* load font if not already loaded */
  859. if(!cid_valid) {
  860. if(!CIDfontfcnA(cid->CIDFontName, cid->CMapName, &rc)) { FontP = NULL;
  861. return Type1ReturnCodeToXReturnCode(rc);
  862. }
  863. cid_valid = 1;
  864. }
  865. pci = CIDGetGlyph(pFont, c, pci);
  866. }
  867. if (pci && EXIST(pci)) {
  868. *glyphs++ = pci;
  869. cid->glyphs[code] = pci;
  870. } else if (pDefault) {
  871. *glyphs++ = pDefault;
  872. cid->glyphs[code] = pDefault;
  873. }
  874. } else if (pDefault)
  875. *glyphs++ = pDefault;
  876. }
  877. break;
  878. case Linear16Bit:
  879. while (count--) {
  880. char_row = *chars++;
  881. char_col = *chars++;
  882. c = char_row << 8;
  883. c = (c | char_col);
  884. if (pFont->info.firstRow <= char_row && char_row <=
  885. pFont->info.lastRow && pFont->info.firstCol <= char_col &&
  886. char_col <= pFont->info.lastCol) {
  887. code = pFont->info.lastCol - pFont->info.firstCol + 1;
  888. char_row = char_row - pFont->info.firstRow;
  889. char_col = char_col - pFont->info.firstCol;
  890. code = char_row * code + char_col;
  891. if (!(pci = (CharInfoRec *)cid->glyphs[code]) ||
  892. ((long)pci->bits == CID_BITMAP_UNDEFINED)) {
  893. /* load font if not already loaded */
  894. if(!cid_valid) {
  895. if(!CIDfontfcnA(cid->CIDFontName, cid->CMapName, &rc)) { FontP = NULL;
  896. return Type1ReturnCodeToXReturnCode(rc);
  897. }
  898. cid_valid = 1;
  899. }
  900. pci = CIDGetGlyph(pFont, c, pci);
  901. }
  902. if (pci && EXIST(pci)) {
  903. *glyphs++ = pci;
  904. cid->glyphs[code] = pci;
  905. } else if (pDefault) {
  906. *glyphs++ = pDefault;
  907. cid->glyphs[code] = pDefault;
  908. }
  909. } else if (pDefault)
  910. *glyphs++ = pDefault;
  911. }
  912. break;
  913. case TwoD16Bit:
  914. while (count--) {
  915. char_row = (*chars++);
  916. char_col = (*chars++);
  917. c = char_row << 8;
  918. c = (c | char_col);
  919. if (pFont->info.firstRow <= char_row && char_row <=
  920. pFont->info.lastRow && pFont->info.firstCol <= char_col &&
  921. char_col <= pFont->info.lastCol) {
  922. code = pFont->info.lastCol - pFont->info.firstCol + 1;
  923. char_row = char_row - pFont->info.firstRow;
  924. char_col = char_col - pFont->info.firstCol;
  925. code = char_row * code + char_col;
  926. if (!(pci = (CharInfoRec *)cid->glyphs[code]) ||
  927. ((long)pci->bits == CID_BITMAP_UNDEFINED)) {
  928. /* load font if not already loaded */
  929. if(!cid_valid) {
  930. if(!CIDfontfcnA(cid->CIDFontName, cid->CMapName, &rc)) { FontP = NULL;
  931. return Type1ReturnCodeToXReturnCode(rc);
  932. }
  933. cid_valid = 1;
  934. }
  935. pci = CIDGetGlyph(pFont, c, pci);
  936. }
  937. if (pci && EXIST(pci)) {
  938. *glyphs++ = pci;
  939. cid->glyphs[code] = pci;
  940. } else if (pDefault) {
  941. *glyphs++ = pDefault;
  942. cid->glyphs[code] = pDefault;
  943. }
  944. } else if (pDefault)
  945. *glyphs++ = pDefault;
  946. }
  947. break;
  948. }
  949. *glyphCount = glyphs - glyphsBase;
  950. return Successful;
  951. #undef EXIST
  952. }
  953. #endif
  954. static int
  955. Type1GetGlyphs(FontPtr pFont,
  956. unsigned long count,
  957. unsigned char *chars,
  958. FontEncoding charEncoding,
  959. unsigned long *glyphCount, /* RETURN */
  960. CharInfoPtr *glyphs) /* RETURN */
  961. {
  962. unsigned int firstRow;
  963. unsigned int numRows;
  964. CharInfoPtr *glyphsBase;
  965. register unsigned int c;
  966. register CharInfoPtr pci;
  967. unsigned int r;
  968. CharInfoPtr pDefault;
  969. register struct type1font *type1Font;
  970. register int firstCol;
  971. type1Font = (struct type1font *) pFont->fontPrivate;
  972. firstCol = pFont->info.firstCol;
  973. pDefault = type1Font->pDefault;
  974. glyphsBase = glyphs;
  975. switch (charEncoding) {
  976. #define EXIST(pci) \
  977. ((pci)->metrics.attributes || \
  978. (pci)->metrics.ascent != -(pci)->metrics.descent || \
  979. (pci)->metrics.leftSideBearing != (pci)->metrics.rightSideBearing)
  980. case Linear8Bit:
  981. case TwoD8Bit:
  982. if (pFont->info.firstRow > 0)
  983. break;
  984. while (count--) {
  985. c = (*chars++);
  986. if (c >= firstCol &&
  987. (pci = &type1Font->glyphs[c]) &&
  988. EXIST(pci))
  989. *glyphs++ = pci;
  990. else if (pDefault)
  991. *glyphs++ = pDefault;
  992. }
  993. break;
  994. case Linear16Bit:
  995. while (count--) {
  996. c = *chars++ << 8;
  997. c = (c | *chars++);
  998. if (c < 256 && c >= firstCol &&
  999. (pci = &type1Font->glyphs[c]) &&
  1000. EXIST(pci))
  1001. *glyphs++ = pci;
  1002. else if (pDefault)
  1003. *glyphs++ = pDefault;
  1004. }
  1005. break;
  1006. case TwoD16Bit:
  1007. firstRow = pFont->info.firstRow;
  1008. numRows = pFont->info.lastRow - firstRow + 1;
  1009. while (count--) {
  1010. r = (*chars++) - firstRow;
  1011. c = (*chars++);
  1012. if (r < numRows && c < 256 && c >= firstCol &&
  1013. (pci = &type1Font->glyphs[(r << 8) + c]) &&
  1014. EXIST(pci))
  1015. *glyphs++ = pci;
  1016. else if (pDefault)
  1017. *glyphs++ = pDefault;
  1018. }
  1019. break;
  1020. }
  1021. *glyphCount = glyphs - glyphsBase;
  1022. return Successful;
  1023. #undef EXIST
  1024. }
  1025. #if XFONT_CID
  1026. static CharInfoRec nonExistantChar;
  1027. int
  1028. CIDGetMetrics(FontPtr pFont,
  1029. unsigned long count,
  1030. unsigned char *chars,
  1031. FontEncoding charEncoding,
  1032. unsigned long *glyphCount, /* RETURN */
  1033. xCharInfo **glyphs) /* RETURN */
  1034. {
  1035. int ret;
  1036. cidglyphs *cid;
  1037. CharInfoPtr oldDefault;
  1038. char cidafmname[CID_PATH_MAX];
  1039. char CIDFontName[CID_NAME_MAX];
  1040. char *ptr;
  1041. cid = (cidglyphs *)pFont->fontPrivate;
  1042. strcpy(cidafmname, cid->CIDFontName);
  1043. if (!(ptr = strrchr(cidafmname, '/')))
  1044. return BadFontName;
  1045. *ptr = '\0';
  1046. strcpy(CIDFontName, ptr + 1);
  1047. if (!(ptr = strrchr(cidafmname, '/')))
  1048. return BadFontName;
  1049. *ptr = '\0';
  1050. strcat(cidafmname, "/AFM/");
  1051. strcat(cidafmname, CIDFontName);
  1052. strcat(cidafmname, ".afm");
  1053. oldDefault = cid->pDefault;
  1054. cid->pDefault = &nonExistantChar;
  1055. ret = CIDGetAFM(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr
  1056. *)glyphs, cidafmname);
  1057. if (ret != Successful)
  1058. ret = CIDGetGlyphs(pFont, count, chars, charEncoding, glyphCount,
  1059. (CharInfoPtr *)glyphs);
  1060. *ptr = 0;
  1061. cid->pDefault = oldDefault;
  1062. return ret;
  1063. }
  1064. #endif
  1065. static int
  1066. Type1GetMetrics(FontPtr pFont,
  1067. unsigned long count,
  1068. unsigned char *chars,
  1069. FontEncoding charEncoding,
  1070. unsigned long *glyphCount, /* RETURN */
  1071. xCharInfo **glyphs) /* RETURN */
  1072. {
  1073. static CharInfoRec nonExistantChar;
  1074. int ret;
  1075. struct type1font *type1Font;
  1076. CharInfoPtr oldDefault;
  1077. type1Font = (struct type1font *) pFont->fontPrivate;
  1078. oldDefault = type1Font->pDefault;
  1079. type1Font->pDefault = &nonExistantChar;
  1080. ret = Type1GetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
  1081. type1Font->pDefault = oldDefault;
  1082. return ret;
  1083. }
  1084. #if XFONT_CID
  1085. void
  1086. CIDCloseFont(FontPtr pFont)
  1087. {
  1088. register int i;
  1089. cidglyphs *cid;
  1090. int nchars;
  1091. if (pFont) {
  1092. cid = (cidglyphs *)pFont->fontPrivate;
  1093. if (cid) {
  1094. if (cid->CIDFontName && !strcmp(cid->CIDFontName, CurCIDFontName)
  1095. && cid->CMapName && !strcmp(cid->CMapName, CurCMapName)){
  1096. strcpy(CurCIDFontName, ""); /* initialize to none */
  1097. strcpy(CurCMapName, ""); /* initialize to none */
  1098. }
  1099. if (cid->CIDFontName)
  1100. xfree(cid->CIDFontName);
  1101. if (cid->CMapName)
  1102. xfree(cid->CMapName);
  1103. nchars = (pFont->info.lastRow - pFont->info.firstRow + 1) *
  1104. (pFont->info.lastCol - pFont->info.firstCol + 1);
  1105. for (i = 0; i < nchars; i++) {
  1106. if (cid->glyphs[i] && (cid->glyphs[i] != &nonExistantChar)) {
  1107. if (cid->glyphs[i]->bits)
  1108. xfree(cid->glyphs[i]->bits);
  1109. xfree(cid->glyphs[i]);
  1110. }
  1111. }
  1112. if (cid->glyphs)
  1113. xfree(cid->glyphs);
  1114. if (cid->AFMinfo)
  1115. xfree(cid->AFMinfo);
  1116. #ifdef USE_MMAP
  1117. if (cid->CIDdata)
  1118. munmap(cid->CIDdata, cid->CIDsize);
  1119. #endif
  1120. xfree(cid);
  1121. }
  1122. if (pFont->info.props)
  1123. xfree(pFont->info.props);
  1124. if (pFont->info.isStringProp)
  1125. xfree(pFont->info.isStringProp);
  1126. DestroyFontRec(pFont);
  1127. }
  1128. }
  1129. #endif
  1130. void
  1131. Type1CloseFont(FontPtr pFont)
  1132. {
  1133. register int i;
  1134. struct type1font *type1;
  1135. type1 = (struct type1font *) pFont->fontPrivate;
  1136. for (i=0; i < 256; i++)
  1137. if (type1->glyphs[i].bits != NULL)
  1138. xfree(type1->glyphs[i].bits);
  1139. xfree(type1);
  1140. if (pFont->info.props)
  1141. xfree(pFont->info.props);
  1142. if (pFont->info.isStringProp)
  1143. xfree(pFont->info.isStringProp);
  1144. DestroyFontRec(pFont);
  1145. }
  1146. static void
  1147. fill(char *dest, /* destination bitmap */
  1148. int h, int w, /* dimensions of 'dest', w padded */
  1149. struct region *area, /* region to write to 'dest' */
  1150. int byte, int bit, /* flags; LSBFirst or MSBFirst */
  1151. int wordsize) /* number of bits per word for LSB/MSB purposes */
  1152. {
  1153. register struct edgelist *edge; /* for looping through edges */
  1154. register char *p; /* current scan line in 'dest' */
  1155. register int y; /* for looping through scans */
  1156. register int wbytes = w / 8; /* number of bytes in width */
  1157. register pel *leftP,*rightP; /* pointers to X values, left and right */
  1158. int xmin = area->xmin; /* upper left X */
  1159. int ymin = area->ymin; /* upper left Y */
  1160. for (edge = area->anchor; VALIDEDGE(edge); edge = edge->link->link) {
  1161. p = dest + (edge->ymin - ymin) * wbytes;
  1162. leftP = edge->xvalues;
  1163. rightP = edge->link->xvalues;
  1164. for (y = edge->ymin; y < edge->ymax; y++) {
  1165. fillrun(p, *leftP++ - xmin, *rightP++ - xmin, bit);
  1166. p += wbytes;
  1167. }
  1168. }
  1169. /*
  1170. Now, as an afterthought, we'll go reorganize if odd byte order requires
  1171. it:
  1172. */
  1173. if (byte == LSBFirst && wordsize != 8) {
  1174. register int i;
  1175. switch (wordsize) {
  1176. case 16:
  1177. {
  1178. register unsigned short data,*p;
  1179. p = (unsigned short *) dest;
  1180. for (i = h * w /16; --i >= 0;) {
  1181. data = *p;
  1182. *p++ = (data << 8) + (data >> 8);
  1183. }
  1184. break;
  1185. }
  1186. case 64:
  1187. case 32:
  1188. {
  1189. register unsigned long data,*p;
  1190. p = (unsigned long *) dest;
  1191. for (i = h * w / 32; --i >= 0;) {
  1192. data = *p;
  1193. *p++ = (data << 24) + (data >> 24)
  1194. + (0xFF00 & (data >> 8))
  1195. + (0xFF0000 & (data << 8));
  1196. }
  1197. if (wordsize == 64) {
  1198. p = (unsigned long *) dest;
  1199. for (i = h * w / 64; --i >= 0;) {
  1200. data = *p++;
  1201. p[-1] = p[0];
  1202. *p++ = data;
  1203. }
  1204. }
  1205. break;
  1206. }
  1207. default:
  1208. Abort("xiFill: unknown format");
  1209. }
  1210. }
  1211. }
  1212. #define ALLONES 0xFF
  1213. static void
  1214. fillrun(char *p, /* address of this scan line */
  1215. pel x0, pel x1, /* left and right X */
  1216. int bit) /* format: LSBFirst or MSBFirst */
  1217. {
  1218. register int startmask,endmask; /* bits to set in first and last char*/
  1219. register int middle; /* number of chars between start and end + 1 */
  1220. if (x1 <= x0)
  1221. return;
  1222. middle = x1/8 - x0/8;
  1223. p += x0/8;
  1224. x0 &= 7; x1 &= 7;
  1225. if (bit == LSBFirst) {
  1226. startmask = ALLONES << x0;
  1227. endmask = ~(ALLONES << x1);
  1228. }
  1229. else {
  1230. startmask = ALLONES >> x0;
  1231. endmask = ~(ALLONES >> x1);
  1232. }
  1233. if (middle == 0)
  1234. *p++ |= startmask & endmask;
  1235. else {
  1236. *p++ |= startmask;
  1237. while (--middle > 0)
  1238. *p++ = (char)ALLONES;
  1239. *p |= endmask;
  1240. }
  1241. }
  1242. #define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
  1243. #if XFONT_CID
  1244. FontRendererRec CIDRendererInfo[] = {
  1245. { ".cid", 4, NULL, CIDOpenScalable,
  1246. NULL, CIDGetInfoScalable, 0, CAPABILITIES }
  1247. };
  1248. #endif
  1249. #if XFONT_CID
  1250. FontRendererRec Type1RendererInfo[] = {
  1251. #else
  1252. static FontRendererRec renderers[] = {
  1253. #endif
  1254. { ".pfa", 4, NULL, Type1OpenScalable,
  1255. NULL, Type1GetInfoScalable, 0, CAPABILITIES },
  1256. { ".pfb", 4, NULL, Type1OpenScalable,
  1257. NULL, Type1GetInfoScalable, 0, CAPABILITIES }
  1258. };
  1259. #if XFONT_CID
  1260. void
  1261. CIDRegisterFontFileFunctions(void)
  1262. {
  1263. int i;
  1264. Type1InitStdProps();
  1265. for (i=0; i < sizeof(CIDRendererInfo) / sizeof(FontRendererRec); i++)
  1266. FontFileRegisterRenderer(&CIDRendererInfo[i]);
  1267. }
  1268. #endif
  1269. void
  1270. Type1RegisterFontFileFunctions(void)
  1271. {
  1272. int i;
  1273. #if XFONT_CID
  1274. Type1InitStdProps();
  1275. for (i=0; i < sizeof(Type1RendererInfo) / sizeof(FontRendererRec); i++)
  1276. FontFilePriorityRegisterRenderer(&Type1RendererInfo[i], -10);
  1277. #else
  1278. T1InitStdProps();
  1279. for (i=0; i < sizeof(renderers) / sizeof(FontRendererRec); i++)
  1280. FontFilePriorityRegisterRenderer(&renderers[i], -10);
  1281. #endif
  1282. }
  1283. int
  1284. Type1ReturnCodeToXReturnCode(int rc)
  1285. {
  1286. switch(rc) {
  1287. case SCAN_OK:
  1288. return Successful;
  1289. case SCAN_FILE_EOF:
  1290. /* fall through to BadFontFormat */
  1291. case SCAN_ERROR:
  1292. return BadFontFormat;
  1293. case SCAN_OUT_OF_MEMORY:
  1294. return AllocError;
  1295. case SCAN_FILE_OPEN_ERROR:
  1296. return BadFontName;
  1297. case SCAN_TRUE:
  1298. case SCAN_FALSE:
  1299. case SCAN_END:
  1300. /* fall through */
  1301. default:
  1302. /* this should not happen */
  1303. #if XFONT_CID
  1304. ErrorF("Font return code cannot be converted to X return code: %d\n", rc);
  1305. #else
  1306. ErrorF("Type1 return code not convertable to X return code: %d\n", rc);
  1307. #endif
  1308. return rc;
  1309. }
  1310. }
  1311. #if XFONT_CID
  1312. CharInfoPtr
  1313. CIDRenderGlyph(FontPtr pFont, psobj *charstringP, psobj *subarrayP,
  1314. struct blues_struct *bluesP, CharInfoPtr pci, int *mode)
  1315. {
  1316. int bit,
  1317. byte,
  1318. glyph,
  1319. scan,
  1320. image;
  1321. int pad,wordsize; /* scan & image in bits */
  1322. long *pool; /* memory pool for ximager objects */
  1323. int size; /* for memory size calculations */
  1324. struct XYspace *S; /* coordinate space for character */
  1325. struct region *area;
  1326. CharInfoRec *glyphs;
  1327. int len, rc;
  1328. long x0;
  1329. double x1, y1, t1 = .001, t2 = 0.0, t3 = 0.0, t4 = .001;
  1330. double sxmult;
  1331. long h,w;
  1332. long paddedW;
  1333. cidglyphs *cid;
  1334. fsBitmapFormat format = 0;
  1335. fsBitmapFormatMask fmask = 0;
  1336. cid = (cidglyphs *)pFont->fontPrivate;
  1337. /* set up default values */
  1338. FontDefaultFormat(&bit, &byte, &glyph, &scan);
  1339. /* get any changes made from above */
  1340. rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  1341. if (rc != Successful) {
  1342. *mode = rc;
  1343. return(NULL);
  1344. }
  1345. pad = glyph * 8;
  1346. wordsize = scan * 8;
  1347. #define PAD(bits, pad) (((bits)+(pad)-1)&-(pad))
  1348. /* heuristic for "maximum" size of pool we'll need: */
  1349. size = 200000 + 600 *
  1350. (int)hypot(cid->pixel_matrix[2], cid->pixel_matrix[3])
  1351. * sizeof(short);
  1352. if (size < 0 || NULL == (pool = (long *) xalloc(size))) {
  1353. *mode = AllocError;
  1354. return(NULL);
  1355. }
  1356. addmemory(pool, size);
  1357. if (pci && (long)pci->bits == CID_BITMAP_UNDEFINED)
  1358. glyphs = pci;
  1359. else {
  1360. if (!(glyphs = (CharInfoRec *)xalloc(sizeof(CharInfoRec)))) {

Large files files are truncated, but you can click here to view the full file