com.pdfjet.OpenTypeFont Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.io.ByteArrayOutputStream;
/* */ import java.io.InputStream;
/* */ import java.util.ArrayList;
/* */ import java.util.List;
/* */
/* */ class OpenTypeFont
/* */ {
/* 17 */ protected OTF otf = null;
/* */
/* */ protected void register(PDF paramPDF, Font paramFont, InputStream paramInputStream)
/* */ throws Exception
/* */ {
/* 23 */ this.otf = new OTF(paramInputStream);
/* 24 */ embedFontFile(paramPDF, paramFont, this.otf);
/* 25 */ addFontDescriptorObject(paramPDF, paramFont, this.otf);
/* 26 */ addCIDFontDictionaryObject(paramPDF, paramFont, this.otf);
/* 27 */ addToUnicodeCMapObject(paramPDF, paramFont, this.otf);
/* */
/* 30 */ paramPDF.newobj();
/* 31 */ paramPDF.append("<<\n");
/* 32 */ paramPDF.append("/Type /Font\n");
/* 33 */ paramPDF.append("/Subtype /Type0\n");
/* 34 */ paramPDF.append("/BaseFont /");
/* 35 */ paramPDF.append(this.otf.fontName);
/* 36 */ paramPDF.append('\n');
/* 37 */ paramPDF.append("/Encoding /Identity-H\n");
/* 38 */ paramPDF.append("/DescendantFonts [");
/* 39 */ paramPDF.append(paramFont.getCidFontDictObjNumber());
/* 40 */ paramPDF.append(" 0 R]\n");
/* */
/* 42 */ paramPDF.append("/ToUnicode ");
/* 43 */ paramPDF.append(paramFont.getToUnicodeCMapObjNumber());
/* 44 */ paramPDF.append(" 0 R\n");
/* */
/* 46 */ paramPDF.append(">>\n");
/* 47 */ paramPDF.endobj();
/* */
/* 49 */ paramFont.objNumber = paramPDF.objNumber;
/* */ }
/* */
/* */ private void embedFontFile(PDF paramPDF, Font paramFont, OTF paramOTF)
/* */ throws Exception
/* */ {
/* 56 */ for (int i = 0; i < paramPDF.fonts.size(); i++) {
/* 57 */ Font localFont = (Font)paramPDF.fonts.get(i);
/* 58 */ if ((localFont.name.equals(paramOTF.fontName)) && (localFont.fileObjNumber != -1)) {
/* 59 */ paramFont.fileObjNumber = localFont.fileObjNumber;
/* 60 */ return;
/* */ }
/* */ }
/* */
/* 64 */ i = paramPDF.addMetadataObject(paramOTF.fontInfo, true);
/* */
/* 66 */ paramPDF.newobj();
/* 67 */ paramPDF.append("<<\n");
/* 68 */ if (paramOTF.cff) {
/* 69 */ paramPDF.append("/Subtype /CIDFontType0C\n");
/* */ }
/* 71 */ paramPDF.append("/Filter /FlateDecode\n");
/* */
/* 73 */ paramPDF.append("/Length ");
/* 74 */ paramPDF.append(paramOTF.baos.size());
/* 75 */ paramPDF.append("\n");
/* */
/* 77 */ if (!paramOTF.cff) {
/* 78 */ paramPDF.append("/Length1 ");
/* 79 */ paramPDF.append(paramOTF.buf.length);
/* 80 */ paramPDF.append('\n');
/* */ }
/* */
/* 83 */ if (i != -1) {
/* 84 */ paramPDF.append("/Metadata ");
/* 85 */ paramPDF.append(i);
/* 86 */ paramPDF.append(" 0 R\n");
/* */ }
/* */
/* 89 */ paramPDF.append(">>\n");
/* 90 */ paramPDF.append("stream\n");
/* 91 */ paramPDF.append(paramOTF.baos);
/* 92 */ paramPDF.append("\nendstream\n");
/* 93 */ paramPDF.endobj();
/* */
/* 95 */ paramFont.fileObjNumber = paramPDF.objNumber;
/* */ }
/* */
/* */ private void addFontDescriptorObject(PDF paramPDF, Font paramFont, OTF paramOTF)
/* */ throws Exception
/* */ {
/* 102 */ float f = 1000.0F / paramOTF.unitsPerEm;
/* */
/* 104 */ for (int i = 0; i < paramPDF.fonts.size(); i++) {
/* 105 */ Font localFont = (Font)paramPDF.fonts.get(i);
/* 106 */ if ((localFont.name.equals(paramOTF.fontName)) && (localFont.getFontDescriptorObjNumber() != -1)) {
/* 107 */ paramFont.setFontDescriptorObjNumber(localFont.getFontDescriptorObjNumber());
/* 108 */ return;
/* */ }
/* */ }
/* */
/* 112 */ paramPDF.newobj();
/* 113 */ paramPDF.append("<<\n");
/* 114 */ paramPDF.append("/Type /FontDescriptor\n");
/* 115 */ paramPDF.append("/FontName /");
/* 116 */ paramPDF.append(paramOTF.fontName);
/* 117 */ paramPDF.append('\n');
/* 118 */ if (paramOTF.cff) {
/* 119 */ paramPDF.append("/FontFile3 ");
/* */ }
/* */ else {
/* 122 */ paramPDF.append("/FontFile2 ");
/* */ }
/* 124 */ paramPDF.append(paramFont.fileObjNumber);
/* 125 */ paramPDF.append(" 0 R\n");
/* 126 */ paramPDF.append("/Flags 32\n");
/* 127 */ paramPDF.append("/FontBBox [");
/* 128 */ paramPDF.append(paramOTF.bBoxLLx * f);
/* 129 */ paramPDF.append(' ');
/* 130 */ paramPDF.append(paramOTF.bBoxLLy * f);
/* 131 */ paramPDF.append(' ');
/* 132 */ paramPDF.append(paramOTF.bBoxURx * f);
/* 133 */ paramPDF.append(' ');
/* 134 */ paramPDF.append(paramOTF.bBoxURy * f);
/* 135 */ paramPDF.append("]\n");
/* 136 */ paramPDF.append("/Ascent ");
/* 137 */ paramPDF.append(paramOTF.ascent * f);
/* 138 */ paramPDF.append('\n');
/* 139 */ paramPDF.append("/Descent ");
/* 140 */ paramPDF.append(paramOTF.descent * f);
/* 141 */ paramPDF.append('\n');
/* 142 */ paramPDF.append("/ItalicAngle 0\n");
/* 143 */ paramPDF.append("/CapHeight ");
/* 144 */ paramPDF.append(paramOTF.capHeight * f);
/* 145 */ paramPDF.append('\n');
/* 146 */ paramPDF.append("/StemV 79\n");
/* 147 */ paramPDF.append(">>\n");
/* 148 */ paramPDF.endobj();
/* */
/* 150 */ paramFont.setFontDescriptorObjNumber(paramPDF.objNumber);
/* */ }
/* */
/* */ private void addToUnicodeCMapObject(PDF paramPDF, Font paramFont, OTF paramOTF)
/* */ throws Exception
/* */ {
/* 159 */ for (int i = 0; i < paramPDF.fonts.size(); i++) {
/* 160 */ localObject = (Font)paramPDF.fonts.get(i);
/* 161 */ if ((((Font)localObject).name.equals(paramOTF.fontName)) && (((Font)localObject).getToUnicodeCMapObjNumber() != -1)) {
/* 162 */ paramFont.setToUnicodeCMapObjNumber(((Font)localObject).getToUnicodeCMapObjNumber());
/* 163 */ return;
/* */ }
/* */ }
/* */
/* 167 */ StringBuilder localStringBuilder1 = new StringBuilder();
/* */
/* 169 */ localStringBuilder1.append("/CIDInit /ProcSet findresource begin\n");
/* 170 */ localStringBuilder1.append("12 dict begin\n");
/* 171 */ localStringBuilder1.append("begincmap\n");
/* 172 */ localStringBuilder1.append("/CIDSystemInfo <> def\n");
/* 173 */ localStringBuilder1.append("/CMapName /Adobe-Identity def\n");
/* 174 */ localStringBuilder1.append("/CMapType 2 def\n");
/* */
/* 176 */ localStringBuilder1.append("1 begincodespacerange\n");
/* 177 */ localStringBuilder1.append("<0000> \n");
/* 178 */ localStringBuilder1.append("endcodespacerange\n");
/* */
/* 180 */ Object localObject = new ArrayList();
/* 181 */ StringBuilder localStringBuilder2 = new StringBuilder();
/* 182 */ for (int j = 0; j <= 65535; j++) {
/* 183 */ int k = paramOTF.unicodeToGID[j];
/* 184 */ if (k > 0) {
/* 185 */ localStringBuilder2.append('<');
/* 186 */ localStringBuilder2.append(toHexString(k));
/* 187 */ localStringBuilder2.append("> <");
/* 188 */ localStringBuilder2.append(toHexString(j));
/* 189 */ localStringBuilder2.append(">\n");
/* 190 */ ((List)localObject).add(localStringBuilder2.toString());
/* 191 */ localStringBuilder2.setLength(0);
/* 192 */ if (((List)localObject).size() == 100) {
/* 193 */ writeListToBuffer((List)localObject, localStringBuilder1);
/* */ }
/* */ }
/* */ }
/* 197 */ if (((List)localObject).size() > 0) {
/* 198 */ writeListToBuffer((List)localObject, localStringBuilder1);
/* */ }
/* */
/* 201 */ localStringBuilder1.append("endcmap\n");
/* 202 */ localStringBuilder1.append("CMapName currentdict /CMap defineresource pop\n");
/* 203 */ localStringBuilder1.append("end\nend");
/* */
/* 205 */ paramPDF.newobj();
/* 206 */ paramPDF.append("<<\n");
/* 207 */ paramPDF.append("/Length ");
/* 208 */ paramPDF.append(localStringBuilder1.length());
/* 209 */ paramPDF.append("\n");
/* 210 */ paramPDF.append(">>\n");
/* 211 */ paramPDF.append("stream\n");
/* 212 */ paramPDF.append(localStringBuilder1.toString());
/* 213 */ paramPDF.append("\nendstream\n");
/* 214 */ paramPDF.endobj();
/* */
/* 216 */ paramFont.setToUnicodeCMapObjNumber(paramPDF.objNumber);
/* */ }
/* */
/* */ private void addCIDFontDictionaryObject(PDF paramPDF, Font paramFont, OTF paramOTF)
/* */ throws Exception
/* */ {
/* 225 */ for (int i = 0; i < paramPDF.fonts.size(); i++) {
/* 226 */ Font localFont = (Font)paramPDF.fonts.get(i);
/* 227 */ if ((localFont.name.equals(paramOTF.fontName)) && (localFont.getCidFontDictObjNumber() != -1)) {
/* 228 */ paramFont.setCidFontDictObjNumber(localFont.getCidFontDictObjNumber());
/* 229 */ return;
/* */ }
/* */ }
/* */
/* 233 */ paramPDF.newobj();
/* 234 */ paramPDF.append("<<\n");
/* 235 */ paramPDF.append("/Type /Font\n");
/* 236 */ if (paramOTF.cff) {
/* 237 */ paramPDF.append("/Subtype /CIDFontType0\n");
/* */ }
/* */ else {
/* 240 */ paramPDF.append("/Subtype /CIDFontType2\n");
/* */ }
/* 242 */ paramPDF.append("/BaseFont /");
/* 243 */ paramPDF.append(paramOTF.fontName);
/* 244 */ paramPDF.append('\n');
/* 245 */ paramPDF.append("/CIDSystemInfo <>\n");
/* 246 */ paramPDF.append("/FontDescriptor ");
/* 247 */ paramPDF.append(paramFont.getFontDescriptorObjNumber());
/* 248 */ paramPDF.append(" 0 R\n");
/* 249 */ paramPDF.append("/DW ");
/* 250 */ paramPDF.append((int)(1000.0F / paramOTF.unitsPerEm * paramOTF.advanceWidth[0]));
/* */
/* 252 */ paramPDF.append('\n');
/* 253 */ paramPDF.append("/W [0[\n");
/* 254 */ for (i = 0; i < paramOTF.advanceWidth.length; i++) {
/* 255 */ paramPDF.append((int)(1000.0F / paramOTF.unitsPerEm * paramOTF.advanceWidth[i]));
/* */
/* 257 */ paramPDF.append(' ');
/* */ }
/* 259 */ paramPDF.append("]]\n");
/* 260 */ paramPDF.append("/CIDToGIDMap /Identity\n");
/* 261 */ paramPDF.append(">>\n");
/* 262 */ paramPDF.endobj();
/* */
/* 264 */ paramFont.setCidFontDictObjNumber(paramPDF.objNumber);
/* */ }
/* */
/* */ private String toHexString(int paramInt)
/* */ {
/* 269 */ String str = Integer.toHexString(paramInt);
/* 270 */ if (str.length() == 1) {
/* 271 */ return "000" + str;
/* */ }
/* 273 */ if (str.length() == 2) {
/* 274 */ return "00" + str;
/* */ }
/* 276 */ if (str.length() == 3) {
/* 277 */ return "0" + str;
/* */ }
/* 279 */ return str;
/* */ }
/* */
/* */ private void writeListToBuffer(List paramList, StringBuilder paramStringBuilder)
/* */ {
/* 284 */ paramStringBuilder.append(paramList.size());
/* 285 */ paramStringBuilder.append(" beginbfchar\n");
/* 286 */ for (String str : paramList) {
/* 287 */ paramStringBuilder.append(str);
/* */ }
/* 289 */ paramStringBuilder.append("endbfchar\n");
/* 290 */ paramList.clear();
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.OpenTypeFont
* JD-Core Version: 0.6.2
*/