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.

PDFCMap.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.pdf;
  18. /**
  19. * Class representing the CMap encodings.
  20. *
  21. * CMaps are defined in the "Predefined CJK CMap names" table.
  22. * In section 5.6.4 of PDF reference 1.4.
  23. */
  24. public class PDFCMap extends PDFStream {
  25. /*
  26. * Chinese (simplified)
  27. */
  28. /**
  29. * GB-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GB 2312-80
  30. * character set, EUC-CN encoding
  31. */
  32. public static final String ENC_GB_EUC_H = "GB-EUC-H";
  33. /**
  34. * GB-EUC-V Vertical version of GB-EUC-H
  35. */
  36. public static final String ENC_GB_EUC_V = "GB_EUC_V";
  37. /**
  38. * GBpc-EUC-H Mac OS, GB 2312-80 character set, EUC-CN encoding, Script Manager code 19
  39. */
  40. public static final String ENC_GBPC_EUC_H = "GBpc-EUC-H";
  41. /**
  42. * GBpc-EUC-V Vertical version of GBpc-EUC-H
  43. */
  44. public static final String ENC_GBPC_EUC_V = "GBpc-EUC-V";
  45. /**
  46. * GBK-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GBK character set, GBK encoding
  47. */
  48. public static final String ENC_GBK_EUC_H = "GBK-EUC-H";
  49. /**
  50. * GBK-EUC-V Vertical version of GBK-EUC-H
  51. */
  52. public static final String ENC_GBK_EUC_V = "GBK-EUC-V";
  53. /**
  54. * GBKp-EUC-H Same as GBK-EUC-H, but replaces half-width
  55. * Latin characters with proportional forms and maps character
  56. * code 0x24 to a dollar sign ($) instead of a yuan symbol
  57. */
  58. public static final String ENC_GBKP_EUC_H = "GBKp-EUC-H";
  59. /**
  60. * GBKp-EUC-V Vertical version of GBKp-EUC-H
  61. */
  62. public static final String ENC_GBKP_EUC_V = "GBKp-EUC-V";
  63. /**
  64. * GBK2K-H GB 18030-2000 character set, mixed 1-, 2-, and 4-byte encoding
  65. */
  66. public static final String ENC_GBK2K_H = "GBK2K-H";
  67. /**
  68. * GBK2K-V Vertical version of GBK2K-H
  69. */
  70. public static final String ENC_GBK2K_V = "GBK2K-V";
  71. /**
  72. * UniGB-UCS2-H Unicode (UCS-2) encoding for the Adobe-GB1 character collection
  73. */
  74. public static final String ENC_UNIGB_UCS2_H = "UniGB-UCS2-H";
  75. /**
  76. * UniGB-UCS2-V Vertical version of UniGB-UCS2-H
  77. */
  78. public static final String ENC_UNIGB_UCS2_V = "UniGB-UCS2-V";
  79. /*
  80. * Chinese (Traditional)
  81. */
  82. /**
  83. * B5pc-H Mac OS, Big Five character set, Big Five encoding, Script Manager code 2
  84. */
  85. public static final String ENC_B5PC_H = "B5pc-H";
  86. /**
  87. * B5pc-V Vertical version of B5pc-H
  88. */
  89. public static final String ENC_B5PC_V = "B5pc-V";
  90. /**
  91. * HKscs-B5-H Hong Kong SCS, an extension to the Big Five
  92. * character set and encoding
  93. */
  94. public static final String ENC_HKSCS_B5_H = "HKscs-B5-H";
  95. /**
  96. * HKscs-B5-V Vertical version of HKscs-B5-H
  97. */
  98. public static final String ENC_HKSCS_B5_V = "HKscs-B5-V";
  99. /**
  100. * ETen-B5-H Microsoft Code Page 950 (lfCharSet 0x88), Big Five
  101. * character set with ETen extensions
  102. */
  103. public static final String ENC_ETEN_B5_H = "ETen-B5-H";
  104. /**
  105. * ETen-B5-V Vertical version of ETen-B5-H
  106. */
  107. public static final String ENC_ETEN_B5_V = "ETen-B5-V";
  108. /**
  109. * ETenms-B5-H Same as ETen-B5-H, but replaces half-width
  110. * Latin characters with proportional forms
  111. */
  112. public static final String ENC_ETENMS_B5_H = "ETenms-B5-H";
  113. /**
  114. * ETenms-B5-V Vertical version of ETenms-B5-H
  115. */
  116. public static final String ENC_ETENMS_B5_V = "ETenms-B5-V";
  117. /**
  118. * CNS-EUC-H CNS 11643-1992 character set, EUC-TW encoding
  119. */
  120. public static final String ENC_CNS_EUC_H = "CNS-EUC-H";
  121. /**
  122. * CNS-EUC-V Vertical version of CNS-EUC-H
  123. */
  124. public static final String ENC_CNS_EUC_V = "CNS-EUC-V";
  125. /**
  126. * UniCNS-UCS2-H Unicode (UCS-2) encoding for the
  127. * Adobe-CNS1 character collection
  128. */
  129. public static final String ENC_UNICNS_UCS2_H = "UniCNS-UCS2-H";
  130. /**
  131. * UniCNS-UCS2-V Vertical version of UniCNS-UCS2-H
  132. */
  133. public static final String ENC_UNICNS_UCS2_V = "UniCNS-UCS2-V";
  134. /*
  135. * Japanese
  136. */
  137. /**
  138. * 83pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk6
  139. * extensions, Shift-JIS encoding, Script Manager code 1
  140. */
  141. public static final String ENC_83PV_RKSJ_H = "83pv-RKSJ-H"; // no V version
  142. /**
  143. * 90ms-RKSJ-H Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208
  144. * character set with NEC and IBM extensions
  145. */
  146. public static final String ENC_90MS_RKSJ_H = "90ms-RKSJ-H";
  147. /**
  148. * 90ms-RKSJ-V Vertical version of 90ms-RKSJ-H
  149. */
  150. public static final String ENC_90MS_RKSJ_V = "90ms-RKSJ-V";
  151. /**
  152. * 90msp-RKSJ-H Same as 90ms-RKSJ-H, but replaces half-width Latin
  153. * characters with proportional forms
  154. */
  155. public static final String ENC_90MSP_RKSJ_H = "90msp-RKSJ-H";
  156. /**
  157. * 90msp-RKSJ-V Vertical version of 90msp-RKSJ-H
  158. */
  159. public static final String ENC_90MSP_RKSJ_V = "90msp-RKSJ-V";
  160. /**
  161. * 90pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk7
  162. * extensions, Shift-JIS encoding, Script Manager code 1
  163. */
  164. public static final String ENC_90PV_RKSJ_H = "90pv-RKSJ-H"; // no V version
  165. /**
  166. * Add-RKSJ-H JIS X 0208 character set with Fujitsu FMR
  167. * extensions, Shift-JIS encoding
  168. */
  169. public static final String ENC_ADD_RKSJ_H = "Add-RKSJ-H";
  170. /**
  171. * Add-RKSJ-V Vertical version of Add-RKSJ-H
  172. */
  173. public static final String ENC_ADD_RKSJ_V = "Add-RKSJ-V";
  174. /**
  175. * EUC-H JIS X 0208 character set, EUC-JP encoding
  176. */
  177. public static final String ENC_EUC_H = "EUC-H";
  178. /**
  179. * EUC-V Vertical version of EUC-H
  180. */
  181. public static final String ENC_EUC_V = "EUC-V";
  182. /**
  183. * Ext-RKSJ-H JIS C 6226 (JIS78) character set with
  184. * NEC extensions, Shift-JIS encoding
  185. */
  186. public static final String ENC_EXT_RKSJ_H = "Ext-RKSJ-H";
  187. /**
  188. * Ext-RKSJ-V Vertical version of Ext-RKSJ-H
  189. */
  190. public static final String ENC_EXT_RKSJ_V = "Ext-RKSJ-V";
  191. /**
  192. * H JIS X 0208 character set, ISO-2022-JP encoding
  193. */
  194. public static final String ENC_H = "H";
  195. /**
  196. * V Vertical version of H
  197. */
  198. public static final String ENC_V = "V";
  199. /**
  200. * UniJIS-UCS2-H Unicode (UCS-2) encoding for the
  201. * Adobe-Japan1 character collection
  202. */
  203. public static final String ENC_UNIJIS_UCS2_H = "UniJIS-UCS2-H";
  204. /**
  205. * UniJIS-UCS2-V Vertical version of UniJIS-UCS2-H
  206. */
  207. public static final String ENC_UNIJIS_UCS2_V = "UniJIS-UCS2-V";
  208. /**
  209. * UniJIS-UCS2-HW-H Same as UniJIS-UCS2-H, but replaces proportional
  210. * Latin characters with half-width forms
  211. */
  212. public static final String ENC_UNIJIS_UCS2_HW_H = "UniJIS-UCS2-HW-H";
  213. /**
  214. * UniJIS-UCS2-HW-V Vertical version of UniJIS-UCS2-HW-H
  215. */
  216. public static final String ENC_UNIJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V";
  217. /*
  218. * Korean
  219. */
  220. /**
  221. * KSC-EUC-H KS X 1001:1992 character set, EUC-KR encoding
  222. */
  223. public static final String ENC_KSC_EUC_H = "KSC-EUC-H";
  224. /**
  225. * KSC-EUC-V Vertical version of KSC-EUC-H
  226. */
  227. public static final String ENC_KSC_EUC_V = "KSC-EUC-V";
  228. /**
  229. * KSCms-UHC-H Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992
  230. * character set plus 8822 additional hangul,
  231. * Unified Hangul Code (UHC) encoding
  232. */
  233. public static final String ENC_KSCMS_UHC_H = "KSCms-UHC-H";
  234. /**
  235. * KSCms-UHC-V Vertical version of KSCms-UHC-H
  236. */
  237. public static final String ENC_KSCMS_UHC_V = "KSCms-UHC-V";
  238. /**
  239. * KSCms-UHC-HW-H Same as KSCms-UHC-H, but replaces proportional
  240. * Latin characters with half-width forms
  241. */
  242. public static final String ENC_KSCMS_UHC_HW_H = "KSCms-UHC-HW-H";
  243. /**
  244. * KSCms-UHC-HW-V Vertical version of KSCms-UHC-HW-H
  245. */
  246. public static final String ENC_KSCMS_UHC_HW_V = "KSCms-UHC-HW-V";
  247. /**
  248. * KSCpc-EUC-H Mac OS, KS X 1001:1992 character set with
  249. * Mac OS KH extensions, Script Manager Code 3
  250. */
  251. public static final String ENC_KSCPC_EUC_H = "KSCpc-EUC-H"; // no V version
  252. /**
  253. * UniKS-UCS2-H Unicode (UCS-2) encoding for the
  254. * Adobe-Korea1 character collection
  255. */
  256. public static final String ENC_UNIKSC_UCS2_H = "UniKSC-UCS2-H";
  257. /**
  258. * UniKS-UCS2-V Vertical version of UniKS-UCS2-H
  259. */
  260. public static final String ENC_UNIKSC_UCS2_V = "UniKSC-UCS2-V";
  261. /*
  262. * Generic
  263. */
  264. /**
  265. * Identity-H The horizontal identity mapping for 2-byte CIDs;
  266. * may be used with CIDFonts using any Registry, Ordering, and
  267. * Supplement values. It maps 2-byte character codes ranging from
  268. * 0 to 65,535 to the same 2-byte CID value, interpreted
  269. * high-order byte first.
  270. */
  271. public static final String ENC_IDENTITY_H = "Identity-H";
  272. /**
  273. * Identity-V Vertical version of Identity-H. The mapping
  274. * is the same as for Identity-H.
  275. */
  276. public static final String ENC_IDENTTITY_V = "Identity-V";
  277. /**
  278. * /CMapName attribute, one of the predefined constants
  279. */
  280. protected String name;
  281. /**
  282. * /CIDSystemInfo attribute
  283. */
  284. protected PDFCIDSystemInfo sysInfo;
  285. /**
  286. * horizontal writing direction
  287. */
  288. public static final byte WMODE_HORIZONTAL = 0;
  289. /**
  290. * vertical writing direction
  291. */
  292. public static final byte WMODE_VERTICAL = 1;
  293. /**
  294. * font's writing direction
  295. */
  296. protected byte wMode = WMODE_HORIZONTAL;
  297. /**
  298. * base CMap (String or PDFStream)
  299. */
  300. protected Object base;
  301. /**
  302. * create the /CMap object
  303. *
  304. * @param name one the registered names (see Table 7.20 on p 215)
  305. * @param sysInfo the attributes of the character collection of the CIDFont
  306. */
  307. public PDFCMap(String name, PDFCIDSystemInfo sysInfo) {
  308. super();
  309. this.name = name;
  310. this.sysInfo = sysInfo;
  311. this.base = null;
  312. }
  313. /**
  314. * set the writing direction
  315. *
  316. * @param mode is either <code>WMODE_HORIZONTAL</code>
  317. * or <code>WMODE_VERTICAL</code>
  318. */
  319. public void setWMode(byte mode) {
  320. this.wMode = mode;
  321. }
  322. /**
  323. * Add the contents of this pdf object to the PDF stream.
  324. */
  325. public void addContents() {
  326. StringBuffer p = new StringBuffer();
  327. fillInPDF(p);
  328. add(p.toString());
  329. }
  330. /**
  331. * set the base CMap
  332. *
  333. * @param base the name of the base CMap
  334. */
  335. public void setUseCMap(String base) {
  336. this.base = base;
  337. }
  338. /**
  339. * set the base CMap
  340. *
  341. * @param base the stream to be used as base CMap
  342. */
  343. public void setUseCMap(PDFStream base) {
  344. this.base = base;
  345. }
  346. /**
  347. * Fill in the pdf string for this CMap.
  348. *
  349. * @param p the string buffer to add the pdf data to
  350. */
  351. public void fillInPDF(StringBuffer p) {
  352. // p.append("/Type /CMap\n");
  353. // p.append(sysInfo.toPDFString());
  354. // p.append("/CMapName /" + name);
  355. // p.append("\n");
  356. p.append("%!PS-Adobe-3.0 Resource-CMap\n");
  357. p.append("%%DocumentNeededResources: ProcSet (CIDInit)\n");
  358. p.append("%%IncludeResource: ProcSet (CIDInit)\n");
  359. p.append("%%BeginResource: CMap (" + name + ")\n");
  360. p.append("%%EndComments\n");
  361. p.append("/CIDInit /ProcSet findresource begin\n");
  362. p.append("12 dict begin\n");
  363. p.append("begincmap\n");
  364. p.append("/CIDSystemInfo 3 dict dup begin\n");
  365. p.append(" /Registry (Adobe) def\n");
  366. p.append(" /Ordering (Identity) def\n");
  367. p.append(" /Supplement 0 def\n");
  368. p.append("end def\n");
  369. p.append("/CMapVersion 1 def\n");
  370. p.append("/CMapType 1 def\n");
  371. p.append("/CMapName /" + name + " def\n");
  372. p.append("1 begincodespacerange\n");
  373. p.append("<0000> <FFFF>\n");
  374. p.append("endcodespacerange\n");
  375. p.append("1 begincidrange\n");
  376. p.append("<0000> <FFFF> 0\n");
  377. p.append("endcidrange\n");
  378. // p.append("1 beginbfrange\n");
  379. // p.append("<0020> <0100> <0000>\n");
  380. // p.append("endbfrange\n");
  381. p.append("endcmap\n");
  382. p.append("CMapName currentdict /CMap defineresource pop\n");
  383. p.append("end\n");
  384. p.append("end\n");
  385. p.append("%%EndResource\n");
  386. p.append("%%EOF\n");
  387. /*
  388. * p.append(" /Type /CMap\n/CMapName /" + name);
  389. * p.append("\n");
  390. * p.append("\n/WMode "); p.append(wMode);
  391. * if (base != null) {
  392. * p.append("\n/UseCMap ");
  393. * if (base instanceof String) {
  394. * p.append("/"+base);
  395. * } else {// base instanceof PDFStream
  396. * p.append(((PDFStream)base).referencePDF());
  397. * }
  398. * }
  399. */
  400. }
  401. }