Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

601 lines
22 KiB

  1. /*
  2. * Adobe Universal Font Libary
  3. *
  4. * Copyright (c) 1996 Adobe Systems Inc.
  5. * All Rights Reserved
  6. *
  7. * UFL -- UFL APIs.
  8. *
  9. *
  10. *
  11. * $Header:
  12. */
  13. #ifndef _H_UFL
  14. #define _H_UFL
  15. /*=============================================================================*
  16. * Include files used by this interface *
  17. *=============================================================================*/
  18. #include "UFLTypes.h"
  19. #include "UFLClien.h"
  20. /*=============================================================================*
  21. Theory of Operation
  22. Universal Font Library allows its client to download a font incrementally or a
  23. font subset. It has the following functionalities.
  24. 1. Depending on the downloading type, UFL requests its client to download a
  25. procset in order for it to create a font.
  26. 2. The type of font downloading that UFL currently supports are:
  27. Font Type Method DownLoad Type Comment
  28. =============================================================================
  29. TrueType Subset Unhinted Outline Font T1.
  30. TrueType Subset Hinted Bitmap Font T3.
  31. TrueType Subset Type 42 Only works on 2013+.
  32. TrueType Subset CID
  33. TrueTypeOpen Subset Type 1 Use XCF
  34. TrueTypeOpen Subset Type 2 Use XCF
  35. TrueTypeOpen Subset CID Use XCF
  36. 3. UFL only supports glyph index string.
  37. 4. For CFF font, it determines SEAC characters and downloads required
  38. characters.
  39. 5. It keeps track of glyphs that have been downloaded in a font.
  40. 6. Provides VM usage of a downloaded font to the client.
  41. 7. UFL does not know how to rendering a font. If the client wishes to download
  42. a TT font as a T1 or T3 font, then the client needs to provide callback
  43. functions that UFL uses to get the outline or bitmap of a character.
  44. The following functions are not part of UFL.
  45. 1. Memory management: UFL does not check for VM, allocates VM usage, or takes
  46. care of save/restore level. Instead, a client can request the amount of VM
  47. needed for an incremental download request. UFL also returns the amount of
  48. VM usage for the request.
  49. 2. Font managements: UFL does not keep track of the fonts that have been
  50. downloaded. Its client keeps this information so DSC %%IncludeFont and
  51. %%DocumentNeededFont should be generated by the client.
  52. 3. UFL does not do anything else with the base font that it has created: it
  53. does not flip to match the platform's x and y directions, it does not apply
  54. synthetic emboldening or obliquing, and it does not scale the font.
  55. In order to use the UFL, the following sequences need to be performed.
  56. 1. Initialize the library by calling UFLInit().
  57. 2. Create a Universal Font Object (UFO) by calling UFLNewFont(). The UFO is an
  58. opaque object that does the real work in a font downloading process.
  59. 3. Download a base font (a font with only .notdef character) or a font subset
  60. by calling UFLDownloadIncr().
  61. 4. To add more CharStrings into an already downloaded font, a client would call
  62. the same UFLDownloadIncr().
  63. 5. Once a font is no longer needed, delete the font in the printer by calling
  64. UFLUndefineFont() and delete its UFO object by calling UFLDeleteFont().
  65. 6. Terminate the library by calling UFLCleanUp()
  66. ===============================================================================*/
  67. /*=============================================================================*
  68. * Constants *
  69. *=============================================================================*/
  70. /* this string is shared among all T1/T3/T42 downloading */
  71. extern const char *gnotdefArray;
  72. extern const char *Notdef;
  73. extern const char *Hyphen;
  74. extern const char *Minus;
  75. extern const char *SftHyphen;
  76. extern const char *UFLSpace;
  77. extern const char *Bullet;
  78. extern const char *nilStr;
  79. /*=============================================================================*
  80. * Scalar Types *
  81. *=============================================================================*/
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /*
  86. * The Metrowerks 68k Mac compiler expects functions to return pointers in A0
  87. * instead of D0. This pragma tells it they are in D0.
  88. */
  89. #if defined(MAC_ENV) && defined(__MWERKS__) && !defined(powerc)
  90. #pragma pointers_in_D0
  91. #endif
  92. /*
  93. * If the fontIndex in UFLFontDataInfo is set to Unknown, UFL will try to find
  94. * it in TTC In the later case, client shoudl provide either UniqueNameA or
  95. * UniqueNameW.
  96. */
  97. #define FONTINDEX_UNKNOWN 0xFFFF
  98. typedef struct _t_UFLXUID {
  99. unsigned long sSize; /* Number of longs in the XUID array */
  100. unsigned long *pXUID;
  101. } UFLXUID;
  102. /*
  103. * FontData info. If the font is a TT font and we want to access some data
  104. * from the TT file, we use this structure - it is common for T1/T3/T42 - it's
  105. * part of info provided in the UFLRequest structure by client.
  106. */
  107. typedef struct _t_UFLFontDataInfo {
  108. unsigned long maxGlyphs; /* # of glyphs in this PS font to create */
  109. /* This may be initialized by UFL even though the client may provide it. */
  110. unsigned long cNumGlyphs; /* # of glyphs in this TT font file: we may use only part of them. */
  111. /* stuff to handle TTC - provided by client */
  112. char *pUniqueNameA; /* an ANSI string to uniquely identify this font in a TTC */
  113. unsigned short *pUniqueNameW; /* a Unicode string to uniquely identify this font */
  114. /* stuff to handle TTC - UFL may initialize this using UniqueName provided by client. */
  115. unsigned long offsetToTableDir ; /* offset to the TableDirectory - non-zero in TTC files */
  116. UFLXUID xuid; /* number of longs in the XUID array and the XUID array */
  117. unsigned short fontIndex ; /* font index in a TTC file */
  118. char reserved[2]; /* make this structure's size as multiple of DWORD */
  119. } UFLFontDataInfo;
  120. typedef struct tagUFLCMapInfo {
  121. char CMapName[32]; /* Our names are limited to 30 chars. */
  122. short int CMapVersion; /* This is an integer. See CMAP doc. */
  123. short int CMapType;
  124. char Registry[20]; /* Ours are limited to 20 chars. */
  125. char Ordering[20]; /* Ours are limited to 20 chars. */
  126. short int Supplement;
  127. char reserved[2]; /* make this structure's size as multiple of DWORD */
  128. } UFLCMapInfo;
  129. /*
  130. * UFL TT Font infos. If the font is a TT font downloaded as Type 42, then this
  131. * structure needs to be provided in the UFLRequest structure.
  132. */
  133. typedef struct _t_UFLTTFontInfo {
  134. UFLFontDataInfo fData;
  135. unsigned short int bUseIdentityCMap; /* If this is non-zero, CMap, CIDCount, BUpdateCIDMap are ignored. */
  136. UFLCMapInfo CMap; /* used only if bUseIdentityCMap is 0. */
  137. unsigned short int CIDCount; /* (max) number of glyphs */
  138. unsigned short int bUpdateCIDMap; /* initialize/update CIDMap when non-zero */
  139. char CIDFontName[256]; /* used when the font is a FE CID font */
  140. char reserved[2]; /* make this structure's size as multiple of DWORD */
  141. } UFLTTFontInfo;
  142. /*
  143. * UFLTTT1FontInfo structure. If the font is a TT font downloaded as type 1,
  144. * then this structure needs to be provided in the UFLRequest structure.
  145. */
  146. typedef struct _t_UFLTTT1FontInfo {
  147. UFLFontDataInfo fData;
  148. UFLBool bEExec; /* To be used when download a TT as a type 1 font. */
  149. UFLFixedMatrix matrix; /* font matrix that the TT font is rendering */
  150. long lNumNT4SymGlyphs; /* NT4 use only: number of symbol glyphs */
  151. } UFLTTT1FontInfo;
  152. /*
  153. * UFLTTT3FontInfo structure. If the font is a TT font downloaded as type 3,
  154. * then this structure needs to be provided in the UFLRequest structure.
  155. */
  156. typedef struct _t_UFLTTT3FontInfo {
  157. UFLFontDataInfo fData;
  158. unsigned long cbMaxGlyphs; /* Size of the largest glyphs */
  159. UFLFixedMatrix matrix; /* Font matrix that the TT font is rendering. */
  160. UFLFixed bbox[4];
  161. long lNumNT4SymGlyphs; /* NT4 use only: number of symbol glyphs */
  162. } UFLTTT3FontInfo;
  163. /*===============================================================================*
  164. * UFL CFF Infos *
  165. *===============================================================================*/
  166. /* uniqueIDMethod options */
  167. enum {
  168. kKeepUID, /* Define UID with the one in the font. */
  169. kUndefineUID, /* Don't define UID in the font */
  170. kUserID /* Replace UID with the one in StreamerOpts */
  171. };
  172. /* Subroutine flattening options: */
  173. enum {
  174. kKeepSubrs, /* Keep all subroutines intact */
  175. kFlattenSubrs /* Flatten/unwind all the subroutines */
  176. };
  177. typedef struct _t_UFLCFFReadBuf {
  178. unsigned long cbBuf;
  179. unsigned char *pBuf;
  180. } UFLCFFReadBuf;
  181. typedef struct _t_UFLCFFFontInfo {
  182. unsigned long uniqueID;
  183. UFLFontDataInfo fData; /* need to use some of the data here intelligently */
  184. unsigned long fontLength; /* Size of 'CFF ' table */
  185. void PTR_PREFIX **ppFontData; /* pointer to 'CFF ' table pointer. Nil if read from the file. */
  186. unsigned short int maxBlockSize; /* max data size that client's stream output function can handle
  187. at a time. XCF requires this info optionally. */
  188. unsigned short int uniqueIDMethod:2, /* UniqueID method */
  189. subrFlatten:1, /* Flatten subrs */
  190. usePSName:1, /* Use correct PostScript Name for the downloaded characters */
  191. useSpecialEncoding:1, /* Use special encoding */
  192. escDownloadFace:1, /* set when requested thru Esc(DOWNLOADFACE) */
  193. type1:1; /* set when the font is a Type 1 font. */
  194. char baseName[256]; /* used to create a PS name with prefix */
  195. UFLCFFReadBuf readBuf; /* 'CFF ' table read buffer object: used if ppFontData is nil. */
  196. } UFLCFFFontInfo;
  197. /*
  198. * Extra information for support of vertical proportional font
  199. * Fix #287084, #309104, and #309482
  200. */
  201. typedef struct _t_UFLVPFInfo {
  202. int nPlatformID; /* 0:9x 1:NT4 2:W2K */
  203. int nSkewElement; /* 2:9x 3:NT4/W2K */
  204. char* pszTangentTheta; /* tan(18deg):9x/NT4 tan(20deg):W2K */
  205. } UFLVPFInfo;
  206. typedef struct _t_UFLRequest {
  207. UFLDownloadType lDownloadFormat; /* Client request download method. */
  208. UFLHANDLE hFontInfo; /* Special info based on Download font format. For example,
  209. if the downloaded font is a true type font then this would
  210. point to a UFLTTFontInfo data structure. */
  211. char *pszFontName; /* font name */
  212. UFLHANDLE hData; /* Client's private data. When UFL calls the client's callback
  213. routine, it returns this handle to the client. */
  214. short subfontNumber; /* subfont number of this font */
  215. long useMyGlyphName; /* If 1, use the glyph names passed in by client */
  216. char *pszEncodeName; /* Font encoding. If this field is NULL, then creat a font
  217. with names UFL likes. */
  218. unsigned char *pEncodeNameList; /* Fix bug #274008 */
  219. unsigned short *pwCommonEncode;
  220. unsigned short *pwExtendEncode;
  221. unsigned char *pMacGlyphNameList; /* mac Glyph Names */
  222. UFLVPFInfo vpfinfo; /* Fix bug #287084, #309104, and #309482 */
  223. UFLHANDLE hHostFontData; /* %hostfont% support */
  224. UFLBool bPatchQXPCFFCID; /* Fix bug #341904 */
  225. } UFLRequest;
  226. /*
  227. * A structure to pass information between Client and UFL for incremental
  228. * downloading.
  229. */
  230. typedef struct _t_UFLGlyphsInfo {
  231. short int sCount; /* number of Glyphs in pGlyphIndices */
  232. UFLGlyphID *pGlyphIndices; /* list of Glyphs IDs */
  233. unsigned short *pCharIndex; /* corresponding Character-codes/indices in this font */
  234. unsigned char **ppGlyphNames; /* corresponding Glyphs Names */
  235. unsigned short *pCode; /* corresponding Unicode or Script-Code points */
  236. char reserved[2]; /* make this structure's size as multiple of DWORD */
  237. }UFLGlyphsInfo;
  238. /*
  239. * Prefix and the font instance name generator macros using it. These prefix
  240. * are used when downloading an OpenType font (cheifly to tell Distiller its
  241. * real font name).
  242. */
  243. #define CFFPREFIX "ADBCFF+"
  244. /* Fix for #507985: need to use different prefixes for H and V (9x only) */
  245. #define CFFPREFIX_H "ADBCFA+"
  246. #define CFFPREFIX_V "ADBCFB+"
  247. #define CREATE_ADCFXX_FONTNAME(fmtfn, dest, cchDest, num, basename) \
  248. (fmtfn)((dest), (cchDest), "ADCF%c%c+%s", \
  249. (char)((((num)&0x00F0)>>4)+'A'), \
  250. (char)((((num)&0x000F) )+'A'), \
  251. (basename))
  252. #define CREATE_ADXXXX_FONTNAME(fmtfn, dest, cchDest, num, basename) \
  253. (fmtfn)((dest), (cchDest), "AD%c%c%c%c+%s", \
  254. (char)((((num)&0xF000)>>12)+'A'), \
  255. (char)((((num)&0x0F00)>> 8)+'A'), \
  256. (char)((((num)&0x00F0)>> 4)+'A'), \
  257. (char)((((num)&0x000F) )+'A'), \
  258. (basename))
  259. /*
  260. * %hostfont% support
  261. */
  262. typedef enum
  263. {
  264. HOSTFONT_UFLREQUEST_GET_NAME,
  265. HOSTFONT_UFLREQUEST_IS_ALLOWED,
  266. HOSTFONT_UFLREQUEST_SET_CURRENTNAME,
  267. } HOSTFONT_UFLREQUEST;
  268. /*
  269. * Special definition to work around %hostfont% RIP bug #388111
  270. * Change the value to 0 when the bug is fixed.
  271. */
  272. #define HOSTFONT_REQUIRE_VMTX 1
  273. /*=============================================================================
  274. UFLInit
  275. Initialize UFL library. Typically, a client would call UFLInit at the
  276. beginning of a session. It calls UFLTerminate to end a session.
  277. bDLGlyphTracking (in) -- TRUE if UFL keeps track of downloaded glyphs
  278. pMemObj (in) -- points to UFLMemObj structure. UFL uses this
  279. object to allocate and free memory.
  280. pFontProcs (in) -- points to the data structure that contains the
  281. font related callback functions.
  282. pStdProcs (in) -- points to the data structure that contains the
  283. standard library callback functions.
  284. THIS IS CURRENTLY NOT USED.
  285. pOutDev (in) -- points to printer specific data.
  286. If the function succeeds, it returns a handle to the client. If it fails,
  287. it returns nil.
  288. ===============================================================================*/
  289. UFLHANDLE
  290. UFLInit(
  291. const UFLBool bDLGlyphTracking,
  292. const UFLMemObj *pMemObj,
  293. const UFLFontProcs *pFontProcs,
  294. const UFLOutputDevice *pOutDev
  295. );
  296. /*=============================================================================
  297. UFLCleanUp
  298. Terminate a UFL session.
  299. handle (in) -- UFL handle that is obtained when UFLInit is called.
  300. ===============================================================================*/
  301. void
  302. UFLCleanUp(
  303. UFLHANDLE handle
  304. );
  305. /*=============================================================================
  306. UFLNewFont
  307. Initialize a font and validate a UFL request. This function needs to be
  308. called before a client makes a call to any other font handling APIs.
  309. If the request is valid, the function sets up the font global data structure.
  310. session (in) -- UFL handle that is obtained when UFLInit is called.
  311. pRequest (in) -- points to the UFLRequest data structure.
  312. returns -- Handle to data stored for this font, or nil if unsuccessful
  313. ===============================================================================*/
  314. UFO
  315. UFLNewFont(
  316. const UFLHANDLE session,
  317. const UFLRequest* pRequest
  318. );
  319. /*=============================================================================
  320. UFLTestRestricted
  321. ===============================================================================*/
  322. UFLBool
  323. bUFLTestRestricted(
  324. const UFLHANDLE h,
  325. const UFLRequest *pRequest
  326. );
  327. /*=============================================================================
  328. UFLVMNeeded
  329. Get a guestimate of VM needed for a download request.
  330. aFont (in) -- UFL handle that is obtained when UFLBeginFont is called.
  331. pGlyphs (in) -- pointer to a UFLGlyphsInfo - has all the information
  332. about this updating, including:
  333. Number of glyphs to be output
  334. List of output glyphs, each glyph is 2 bytes long
  335. List of glyph names. This list can be NULL. If this is
  336. the case, UFL uses the name defined in the font
  337. A list of indices to be used to index the ppGlyphNames list.
  338. A List of Unicode or Script-code points
  339. ... and ... depends on the extension to UFLGlyphsInfo
  340. structure ....
  341. pVMNeeded (out) -- Amount of VM needed.
  342. pFCNeeded (out) -- Amount of FC needed.
  343. returns:
  344. noErr or error code if unsuccessful
  345. ===============================================================================*/
  346. UFLErrCode
  347. UFLVMNeeded(
  348. const UFO aFont,
  349. const UFLGlyphsInfo *pGlyphs,
  350. unsigned long *pVMNeeded,
  351. unsigned long *pFCNeeded
  352. );
  353. /*=============================================================================
  354. UFLDownloadIncr
  355. Downloads a font incrementally. The first time this is called for a
  356. particular font, it will create a base font, and download a set of
  357. requested characters. Subsequent calls on the same font will download
  358. additional characters.
  359. aFont (in) -- UFL handle that is obtained when UFLBeginFont is called.
  360. pGlyphs (in) -- pointer to a UFLGlyphsInfo - has all the information
  361. about this updating, including:
  362. Number of glyphs to be output
  363. List of output glyphs, each glyph is 2 bytes long
  364. List of glyph names. This list can be NULL. If this is
  365. the case, UFL uses the name defined in the font
  366. A list of indices to be used to index the ppGlyphNames list.
  367. A List of Unicode or Script-code points
  368. ... and ... depends on the extension to UFLGlyphsInfo
  369. structure ....
  370. pVMUsage (out) -- pointer to the amount of VM used by this request.
  371. returns:
  372. noErr or error code if unsuccessful
  373. ===============================================================================*/
  374. UFLErrCode
  375. UFLDownloadIncr(
  376. const UFO aFont,
  377. const UFLGlyphsInfo *pGlyphs,
  378. unsigned long *pVMUsage,
  379. unsigned long *pFCUsage
  380. );
  381. /*=============================================================================
  382. UFLDeleteFont
  383. Delete UFL internal data. UFL does not output any PostScript to delete
  384. the font on the printer since this has to do with how its client manages
  385. printer resources.
  386. aFont (in) -- UFL handle that is obtained when UFLBeginFont is called.
  387. ===============================================================================*/
  388. void
  389. UFLDeleteFont(
  390. UFO aFont
  391. );
  392. /*===========================================================================
  393. UFLUndefineFont
  394. Undefine a font on the printer.
  395. aFont (in) -- UFL handle that is obtained when UFLBeginFont is called.
  396. returns:
  397. noErr or error code if unsuccessful
  398. ==============================================================================*/
  399. UFLErrCode
  400. UFLUndefineFont(
  401. const UFO aFont
  402. );
  403. /*=============================================================================
  404. UFLCopyFont
  405. Copy a font on the printer - with new Encoding vector
  406. aFont (in) -- UFL handle to a UFObj created earlier
  407. request -- has pszFontName, new hData, and new Encoding for this copy.
  408. returns:
  409. Handle to data stored for this font, or nil if unsuccessful.
  410. ===============================================================================*/
  411. UFO
  412. UFLCopyFont(
  413. const UFO h,
  414. const UFLRequest* pRequest
  415. );
  416. /*=============================================================================
  417. UFLGIDsToCIDs
  418. This function can only be used with a CID CFF font. It is used to obtain
  419. CIDs from a list of GIDs.
  420. aFont (in) -- UFL handle that is obtained when UFLBeginFont is called.
  421. cGlyphs (in) -- Number of glyhs (GIDs) to be converted.
  422. pGIDs (in) -- GID list.
  423. pCIDs (out) -- Result CIDs.
  424. returns:
  425. noErr or error code if unsuccessful
  426. ===============================================================================*/
  427. UFLErrCode
  428. UFLGIDsToCIDs(
  429. const UFO aFont,
  430. const short cGlyphs,
  431. const UFLGlyphID *pGIDs,
  432. unsigned short *pCIDs
  433. );
  434. /* undo the Metrowerks pragma. */
  435. #if defined(MAC_ENV) && defined(__MWERKS__) && !defined(powerc)
  436. #pragma pointers_in_A0
  437. #endif
  438. #ifdef __cplusplus
  439. }
  440. #endif
  441. #endif