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 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "Fop" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.pdf;
  41. /**
  42. * class representing the CMap encodings.
  43. *
  44. * CMaps are defined on page 215 and onwards.
  45. * The predefined CMap names are drawn from Table 7.20
  46. * on pages 215, 216 and 217 .
  47. */
  48. public class PDFCMap extends PDFStream {
  49. /** Chinese (simplified) */
  50. public static final String GB_EUC_H= "GB-EUC-H";
  51. public static final String GB_EUC_V= "GB_EUC_V";
  52. public static final String GBpc_EUC_H= "GBpc-EUC-H";
  53. public static final String GBpc_EUC_V= "GBpc-EUC-V";
  54. public static final String GBK_EUC_H= "GBK-EUC-H";
  55. public static final String GBK_EUC_V= "GBK-EUC-V";
  56. public static final String UniGB_UCS2_H= "UniGB-UCS2-H";
  57. public static final String UniGB_UCS2_V= "UniGB-UCS2-V";
  58. /** Chinese (traditional) */
  59. public static final String B5pc_H= "B5pc-H";
  60. public static final String B5pc_V= "B5pc-V";
  61. public static final String ETen_B5_H= "ETen-B5-H";
  62. public static final String ETen_B5_V= "ETen-B5-V";
  63. public static final String ETenms_B5_H= "ETenms-B5-H";
  64. public static final String ETenms_B5_V= "ETenms-B5-V";
  65. public static final String CNS_EUC_H= "CNS-EUC-H";
  66. public static final String CNS_EUC_V= "CNS-EUC-V";
  67. public static final String UniCNS_UCS2_H= "UniCNS-UCS2-H";
  68. public static final String UniCNS_UCS2_V= "UniCNS-UCS2-V";
  69. /** Japanese */
  70. public static final String _83pv_RKSJ_H= "83pv-RKSJ-H"; // no V version
  71. public static final String _90ms_RKSJ_H= "90ms-RKSJ-H";
  72. public static final String _90ms_RKSJ_V= "90ms-RKSJ-V";
  73. public static final String _90msp_RKSJ_H= "90msp-RKSJ-H";
  74. public static final String _90msp_RKSJ_V= "90msp-RKSJ-V";
  75. public static final String _90pv_RKSJ_H= "90pv-RKSJ-H"; // no V version
  76. public static final String Add_RKSJ_H= "Add-RKSJ-H";
  77. public static final String Add_RKSJ_V= "Add-RKSJ-V";
  78. public static final String EUC_H= "EUC-H";
  79. public static final String EUC_V= "EUC-V";
  80. public static final String Ext_RKSJ_H= "Ext-RKSJ-H";
  81. public static final String Ext_RKSJ_V= "Ext-RKSJ-V";
  82. public static final String H= "H";
  83. public static final String V= "V";
  84. public static final String UniJIS_UCS2_H= "UniJIS-UCS2-H";
  85. public static final String UniJIS_UCS2_V= "UniJIS-UCS2-V";
  86. public static final String UniJIS_UCS2_HW_H= "UniJIS-UCS2-HW-H";
  87. public static final String UniJIS_UCS2_HW_V= "UniJIS-UCS2-HW-V";
  88. /** Korean */
  89. public static final String KSC_EUC_H= "KSC-EUC-H";
  90. public static final String KSC_EUC_V= "KSC-EUC-V";
  91. public static final String KSCms_UHC_H= "KSCms-UHC-H";
  92. public static final String KSCms_UHC_V= "KSCms-UHC-V";
  93. public static final String KSCms_UHC_HW_H= "KSCms-UHC-HW-H";
  94. public static final String KSCms_UHC_HW_V= "KSCms-UHC-HW-V";
  95. public static final String KSCpc_EUC_H= "KSCpc-EUC-H"; // no V version
  96. public static final String UniKSC_UCS2_H= "UniKSC-UCS2-H";
  97. public static final String UniKSC_UCS2_V= "UniKSC-UCS2-V";
  98. /** Generic */
  99. public static final String Identity_H= "Identity-H";
  100. public static final String Identity_V= "Identity-V";
  101. /** /CMapName attribute, one of the predefined constants */
  102. protected String name;
  103. /** /CIDSystemInfo attribute */
  104. protected PDFCIDSystemInfo sysInfo;
  105. /** horizontal writing direction */
  106. public static final byte WMODE_HORIZONTAL = 0;
  107. /** vertical writing direction */
  108. public static final byte WMODE_VERTICAL = 1;
  109. /** font's writing direction */
  110. protected byte wMode = WMODE_HORIZONTAL;
  111. /** base CMap (String or PDFStream) */
  112. protected Object base;
  113. /**
  114. * create the /CMap object
  115. *
  116. * @param name one the registered names (see Table 7.20 on p 215)
  117. * @param sysInfo the attributes of the character collection of the CIDFont
  118. */
  119. public PDFCMap(int number, String name, PDFCIDSystemInfo sysInfo) {
  120. super(number);
  121. this.name = name;
  122. this.sysInfo = sysInfo;
  123. this.base = null;
  124. }
  125. /**
  126. * set the writing direction
  127. *
  128. * @param mode is either <code>WMODE_HORIZONTAL</code>
  129. * or <code>WMODE_VERTICAL</code>
  130. */
  131. public void setWMode(byte mode) {
  132. this.wMode = mode;
  133. }
  134. public void addContents() {
  135. StringBuffer p=new StringBuffer();
  136. fillInPDF(p);
  137. add(p.toString());
  138. }
  139. /**
  140. * set the base CMap
  141. *
  142. * @param base the name of the base CMap (see Table 7.20)
  143. */
  144. public void setUseCMap(String base) {
  145. this.base = base;
  146. }
  147. /**
  148. * set the base CMap
  149. *
  150. * @param base the stream to be used as base CMap
  151. */
  152. public void setUseCMap(PDFStream base) {
  153. this.base = base;
  154. }
  155. public void fillInPDF(StringBuffer p) {
  156. //p.append("/Type /CMap\n");
  157. //p.append(sysInfo.toPDFString());
  158. //p.append("/CMapName /" + name);
  159. //p.append("\n");
  160. p.append("%!PS-Adobe-3.0 Resource-CMap\n");
  161. p.append("%%DocumentNeededResources: ProcSet (CIDInit)\n");
  162. p.append("%%IncludeResource: ProcSet (CIDInit)\n");
  163. p.append("%%BeginResource: CMap (" + name + ")\n");
  164. p.append("%%EndComments\n");
  165. p.append("/CIDInit /ProcSet findresource begin\n");
  166. p.append("12 dict begin\n");
  167. p.append("begincmap\n");
  168. p.append("/CIDSystemInfo 3 dict dup begin\n");
  169. p.append(" /Registry (Adobe) def\n");
  170. p.append(" /Ordering (Identity) def\n");
  171. p.append(" /Supplement 0 def\n");
  172. p.append("end def\n");
  173. p.append("/CMapVersion 1 def\n");
  174. p.append("/CMapType 1 def\n");
  175. p.append("/CMapName /" + name + " def\n");
  176. p.append("1 begincodespacerange\n");
  177. p.append("<0000> <FFFF>\n");
  178. p.append("endcodespacerange\n");
  179. p.append("1 begincidrange\n");
  180. p.append("<0000> <FFFF> 0\n");
  181. p.append("endcidrange\n");
  182. //p.append("1 beginbfrange\n");
  183. //p.append("<0020> <0100> <0000>\n");
  184. //p.append("endbfrange\n");
  185. p.append("endcmap\n");
  186. p.append("CMapName currentdict /CMap defineresource pop\n");
  187. p.append("end\n");
  188. p.append("end\n");
  189. p.append("%%EndResource\n");
  190. p.append("%%EOF\n");
  191. /*
  192. p.append(" /Type /CMap\n/CMapName /" + name);
  193. p.append("\n");
  194. p.append("\n/WMode "); p.append(wMode);
  195. if (base != null) {
  196. p.append("\n/UseCMap ");
  197. if (base instanceof String) {
  198. p.append("/"+base);
  199. } else { // base instanceof PDFStream
  200. p.append(((PDFStream)base).referencePDF());
  201. }
  202. }
  203. */
  204. }
  205. }