com.pdfjet.Font Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.io.InputStream;
/* */ import java.util.List;
/* */
/* */ public class Font
/* */ {
/* */ public static final String AdobeMingStd_Light = "AdobeMingStd-Light";
/* */ public static final String STHeitiSC_Light = "STHeitiSC-Light";
/* */ public static final String KozMinProVI_Regular = "KozMinProVI-Regular";
/* */ public static final String AdobeMyungjoStd_Medium = "AdobeMyungjoStd-Medium";
/* */ public static final boolean STREAM = true;
/* */ protected String name;
/* */ protected String info;
/* */ protected int objNumber;
/* 64 */ protected int fileObjNumber = -1;
/* */
/* 67 */ protected int unitsPerEm = 1000;
/* 68 */ protected float size = 12.0F;
/* */ protected float ascent;
/* */ protected float descent;
/* */ protected float capHeight;
/* */ protected float body_height;
/* 75 */ protected int[][] metrics = (int[][])null;
/* */
/* 78 */ protected boolean isCoreFont = false;
/* 79 */ protected boolean isCJK = false;
/* 80 */ protected int firstChar = 32;
/* 81 */ protected int lastChar = 255;
/* 82 */ protected boolean skew15 = false;
/* 83 */ protected boolean kernPairs = false;
/* 84 */ public boolean isDevanagari = false;
/* */ protected float bBoxLLx;
/* */ protected float bBoxLLy;
/* */ protected float bBoxURx;
/* */ protected float bBoxURy;
/* */ protected float underlinePosition;
/* */ protected float underlineThickness;
/* */ protected int compressed_size;
/* */ protected int uncompressed_size;
/* 97 */ protected int[] advanceWidth = null;
/* 98 */ protected int[] glyphWidth = null;
/* */ protected int[] unicodeToGID;
/* */ protected boolean cff;
/* */ protected String fontID;
/* 104 */ private int fontDescriptorObjNumber = -1;
/* 105 */ private int cMapObjNumber = -1;
/* 106 */ private int cidFontDictObjNumber = -1;
/* 107 */ private int toUnicodeCMapObjNumber = -1;
/* 108 */ private int widthsArrayObjNumber = -1;
/* 109 */ private int encodingObjNumber = -1;
/* 110 */ private int codePage = -1;
/* 111 */ private int fontUnderlinePosition = 0;
/* 112 */ private int fontUnderlineThickness = 0;
/* */
/* */ public Font(PDF paramPDF, CoreFont paramCoreFont)
/* */ throws Exception
/* */ {
/* 131 */ this.isCoreFont = true;
/* 132 */ StandardFont localStandardFont = StandardFont.getInstance(paramCoreFont);
/* 133 */ this.name = localStandardFont.name;
/* 134 */ this.bBoxLLx = localStandardFont.bBoxLLx;
/* 135 */ this.bBoxLLy = localStandardFont.bBoxLLy;
/* 136 */ this.bBoxURx = localStandardFont.bBoxURx;
/* 137 */ this.bBoxURy = localStandardFont.bBoxURy;
/* 138 */ this.metrics = localStandardFont.metrics;
/* 139 */ this.ascent = (this.bBoxURy * this.size / this.unitsPerEm);
/* 140 */ this.descent = (this.bBoxLLy * this.size / this.unitsPerEm);
/* 141 */ this.body_height = (this.ascent - this.descent);
/* 142 */ this.fontUnderlinePosition = localStandardFont.underlinePosition;
/* 143 */ this.fontUnderlineThickness = localStandardFont.underlineThickness;
/* 144 */ this.underlineThickness = (this.fontUnderlineThickness * this.size / this.unitsPerEm);
/* 145 */ this.underlinePosition = (this.fontUnderlinePosition * this.size / -this.unitsPerEm + this.underlineThickness / 2.0F);
/* */
/* 147 */ paramPDF.newobj();
/* 148 */ paramPDF.append("<<\n");
/* 149 */ paramPDF.append("/Type /Font\n");
/* 150 */ paramPDF.append("/Subtype /Type1\n");
/* 151 */ paramPDF.append("/BaseFont /");
/* 152 */ paramPDF.append(this.name);
/* 153 */ paramPDF.append('\n');
/* 154 */ if ((!this.name.equals("Symbol")) && (!this.name.equals("ZapfDingbats"))) {
/* 155 */ paramPDF.append("/Encoding /WinAnsiEncoding\n");
/* */ }
/* 157 */ paramPDF.append(">>\n");
/* 158 */ paramPDF.endobj();
/* 159 */ this.objNumber = paramPDF.objNumber;
/* */
/* 161 */ paramPDF.fonts.add(this);
/* */ }
/* */
/* */ protected Font(CoreFont paramCoreFont)
/* */ {
/* 167 */ this.isCoreFont = true;
/* 168 */ StandardFont localStandardFont = StandardFont.getInstance(paramCoreFont);
/* 169 */ this.name = localStandardFont.name;
/* 170 */ this.bBoxLLx = localStandardFont.bBoxLLx;
/* 171 */ this.bBoxLLy = localStandardFont.bBoxLLy;
/* 172 */ this.bBoxURx = localStandardFont.bBoxURx;
/* 173 */ this.bBoxURy = localStandardFont.bBoxURy;
/* 174 */ this.metrics = localStandardFont.metrics;
/* 175 */ this.ascent = (this.bBoxURy * this.size / this.unitsPerEm);
/* 176 */ this.descent = (this.bBoxLLy * this.size / this.unitsPerEm);
/* 177 */ this.body_height = (this.ascent - this.descent);
/* 178 */ this.fontUnderlinePosition = localStandardFont.underlinePosition;
/* 179 */ this.fontUnderlineThickness = localStandardFont.underlineThickness;
/* 180 */ this.underlineThickness = (this.fontUnderlineThickness * this.size / this.unitsPerEm);
/* 181 */ this.underlinePosition = (this.fontUnderlinePosition * this.size / -this.unitsPerEm + this.underlineThickness / 2.0F);
/* */ }
/* */
/* */ public Font(PDF paramPDF, String paramString) throws Exception
/* */ {
/* 186 */ this(paramPDF, paramString, -1);
/* */ }
/* */
/* */ public Font(PDF paramPDF, String paramString, int paramInt)
/* */ throws Exception
/* */ {
/* 199 */ this.name = paramString;
/* 200 */ this.isCJK = true;
/* */
/* 202 */ this.firstChar = 32;
/* 203 */ this.lastChar = 65518;
/* */
/* 206 */ paramPDF.newobj();
/* 207 */ paramPDF.append("<<\n");
/* 208 */ paramPDF.append("/Type /FontDescriptor\n");
/* 209 */ paramPDF.append("/FontName /");
/* 210 */ paramPDF.append(paramString);
/* 211 */ paramPDF.append('\n');
/* 212 */ paramPDF.append("/Flags 4\n");
/* 213 */ paramPDF.append("/FontBBox [0 0 0 0]\n");
/* 214 */ paramPDF.append(">>\n");
/* 215 */ paramPDF.endobj();
/* */
/* 218 */ paramPDF.newobj();
/* 219 */ paramPDF.append("<<\n");
/* 220 */ paramPDF.append("/Type /Font\n");
/* 221 */ paramPDF.append("/Subtype /CIDFontType0\n");
/* 222 */ paramPDF.append("/BaseFont /");
/* 223 */ paramPDF.append(paramString);
/* 224 */ paramPDF.append('\n');
/* 225 */ paramPDF.append("/FontDescriptor ");
/* 226 */ paramPDF.append(paramPDF.objNumber - 1);
/* 227 */ paramPDF.append(" 0 R\n");
/* 228 */ paramPDF.append("/CIDSystemInfo <<\n");
/* 229 */ paramPDF.append("/Registry (Adobe)\n");
/* 230 */ if (paramString.startsWith("AdobeMingStd")) {
/* 231 */ paramPDF.append("/Ordering (CNS1)\n");
/* 232 */ paramPDF.append("/Supplement 4\n");
/* 233 */ } else if ((paramString.startsWith("AdobeSongStd")) || (paramString.startsWith("STHeitiSC")))
/* */ {
/* 235 */ paramPDF.append("/Ordering (GB1)\n");
/* 236 */ paramPDF.append("/Supplement 4\n");
/* 237 */ } else if (paramString.startsWith("KozMinPro")) {
/* 238 */ paramPDF.append("/Ordering (Japan1)\n");
/* 239 */ paramPDF.append("/Supplement 4\n");
/* 240 */ } else if (paramString.startsWith("AdobeMyungjoStd")) {
/* 241 */ paramPDF.append("/Ordering (Korea1)\n");
/* 242 */ paramPDF.append("/Supplement 1\n");
/* */ } else {
/* 244 */ throw new Exception("Unsupported font: " + paramString);
/* */ }
/* 246 */ paramPDF.append(">>\n");
/* 247 */ paramPDF.append(">>\n");
/* 248 */ paramPDF.endobj();
/* */
/* 251 */ paramPDF.newobj();
/* 252 */ paramPDF.append("<<\n");
/* 253 */ paramPDF.append("/Type /Font\n");
/* 254 */ paramPDF.append("/Subtype /Type0\n");
/* 255 */ paramPDF.append("/BaseFont /");
/* 256 */ if (paramString.startsWith("AdobeMingStd")) {
/* 257 */ paramPDF.append(paramString + "-UniCNS-UTF16-H\n");
/* 258 */ paramPDF.append("/Encoding /UniCNS-UTF16-H\n");
/* 259 */ } else if ((paramString.startsWith("AdobeSongStd")) || (paramString.startsWith("STHeitiSC")))
/* */ {
/* 261 */ paramPDF.append(paramString + "-UniGB-UTF16-H\n");
/* 262 */ paramPDF.append("/Encoding /UniGB-UTF16-H\n");
/* 263 */ } else if (paramString.startsWith("KozMinPro")) {
/* 264 */ paramPDF.append(paramString + "-UniJIS-UCS2-H\n");
/* 265 */ paramPDF.append("/Encoding /UniJIS-UCS2-H\n");
/* 266 */ } else if (paramString.startsWith("AdobeMyungjoStd")) {
/* 267 */ paramPDF.append(paramString + "-UniKS-UCS2-H\n");
/* 268 */ paramPDF.append("/Encoding /UniKS-UCS2-H\n");
/* */ } else {
/* 270 */ throw new Exception("Unsupported font: " + paramString);
/* */ }
/* 272 */ paramPDF.append("/DescendantFonts [");
/* 273 */ paramPDF.append(paramPDF.objNumber - 1);
/* 274 */ paramPDF.append(" 0 R]\n");
/* 275 */ paramPDF.append(">>\n");
/* 276 */ paramPDF.endobj();
/* 277 */ this.objNumber = paramPDF.objNumber;
/* */
/* 279 */ this.ascent = this.size;
/* 280 */ this.descent = (-this.ascent / 4.0F);
/* 281 */ this.body_height = (this.ascent - this.descent);
/* */
/* 283 */ paramPDF.fonts.add(this);
/* */ }
/* */
/* */ public Font(PDF paramPDF, InputStream paramInputStream, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 289 */ FastFont.register(paramPDF, this, paramInputStream);
/* */
/* 291 */ this.ascent = (this.bBoxURy * this.size / this.unitsPerEm);
/* 292 */ this.descent = (this.bBoxLLy * this.size / this.unitsPerEm);
/* 293 */ this.body_height = (this.ascent - this.descent);
/* 294 */ this.underlineThickness = (this.fontUnderlineThickness * this.size / this.unitsPerEm);
/* 295 */ this.underlinePosition = (this.fontUnderlinePosition * this.size / -this.unitsPerEm + this.underlineThickness / 2.0F);
/* */
/* 297 */ paramPDF.fonts.add(this);
/* */ }
/* */
/* */ public Font(PDF paramPDF, InputStream paramInputStream)
/* */ throws Exception
/* */ {
/* 304 */ this(paramPDF, paramInputStream, -1, true);
/* */ }
/* */
/* */ public Font(PDF paramPDF, InputStream paramInputStream, int paramInt, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 325 */ OpenTypeFont localOpenTypeFont = new OpenTypeFont();
/* 326 */ if (paramInt == -1) {
/* 327 */ localOpenTypeFont.register(paramPDF, this, paramInputStream);
/* 328 */ this.firstChar = localOpenTypeFont.otf.firstChar;
/* 329 */ this.lastChar = localOpenTypeFont.otf.lastChar;
/* */ }
/* */ else {
/* 332 */ throw new Exception("The code page must be UNICODE.");
/* */ }
/* */
/* 335 */ this.name = localOpenTypeFont.otf.fontName;
/* 336 */ this.unicodeToGID = localOpenTypeFont.otf.unicodeToGID;
/* 337 */ this.unitsPerEm = localOpenTypeFont.otf.unitsPerEm;
/* 338 */ this.bBoxLLx = localOpenTypeFont.otf.bBoxLLx;
/* 339 */ this.bBoxLLy = localOpenTypeFont.otf.bBoxLLy;
/* 340 */ this.bBoxURx = localOpenTypeFont.otf.bBoxURx;
/* 341 */ this.bBoxURy = localOpenTypeFont.otf.bBoxURy;
/* 342 */ this.advanceWidth = localOpenTypeFont.otf.advanceWidth;
/* 343 */ this.glyphWidth = localOpenTypeFont.otf.glyphWidth;
/* 344 */ this.ascent = (this.bBoxURy * this.size / this.unitsPerEm);
/* 345 */ this.descent = (this.bBoxLLy * this.size / this.unitsPerEm);
/* 346 */ this.body_height = (this.ascent - this.descent);
/* 347 */ this.fontUnderlineThickness = localOpenTypeFont.otf.underlineThickness;
/* 348 */ this.fontUnderlinePosition = localOpenTypeFont.otf.underlinePosition;
/* 349 */ this.underlineThickness = (this.fontUnderlineThickness * this.size / this.unitsPerEm);
/* 350 */ this.underlinePosition = (this.fontUnderlinePosition * this.size / -this.unitsPerEm + this.underlineThickness / 2.0F);
/* */
/* 352 */ paramPDF.fonts.add(this);
/* */
/* 354 */ paramInputStream.close();
/* */ }
/* */
/* */ protected int getFontDescriptorObjNumber()
/* */ {
/* 360 */ return this.fontDescriptorObjNumber;
/* */ }
/* */
/* */ protected int getCMapObjNumber()
/* */ {
/* 365 */ return this.cMapObjNumber;
/* */ }
/* */
/* */ protected int getCidFontDictObjNumber()
/* */ {
/* 370 */ return this.cidFontDictObjNumber;
/* */ }
/* */
/* */ protected int getToUnicodeCMapObjNumber()
/* */ {
/* 375 */ return this.toUnicodeCMapObjNumber;
/* */ }
/* */
/* */ protected int getWidthsArrayObjNumber()
/* */ {
/* 380 */ return this.widthsArrayObjNumber;
/* */ }
/* */
/* */ protected int getEncodingObjNumber()
/* */ {
/* 385 */ return this.encodingObjNumber;
/* */ }
/* */
/* */ public float getUnderlinePosition()
/* */ {
/* 390 */ return this.underlinePosition;
/* */ }
/* */
/* */ public float getUnderlineThickness()
/* */ {
/* 395 */ return this.underlineThickness;
/* */ }
/* */
/* */ protected void setFontDescriptorObjNumber(int paramInt)
/* */ {
/* 400 */ this.fontDescriptorObjNumber = paramInt;
/* */ }
/* */
/* */ protected void setCMapObjNumber(int paramInt)
/* */ {
/* 405 */ this.cMapObjNumber = paramInt;
/* */ }
/* */
/* */ protected void setCidFontDictObjNumber(int paramInt)
/* */ {
/* 410 */ this.cidFontDictObjNumber = paramInt;
/* */ }
/* */
/* */ protected void setToUnicodeCMapObjNumber(int paramInt)
/* */ {
/* 415 */ this.toUnicodeCMapObjNumber = paramInt;
/* */ }
/* */
/* */ protected void setWidthsArrayObjNumber(int paramInt)
/* */ {
/* 420 */ this.widthsArrayObjNumber = paramInt;
/* */ }
/* */
/* */ protected void setEncodingObjNumber(int paramInt)
/* */ {
/* 425 */ this.encodingObjNumber = paramInt;
/* */ }
/* */
/* */ public Font setSize(double paramDouble)
/* */ {
/* 436 */ return setSize((float)paramDouble);
/* */ }
/* */
/* */ public Font setSize(float paramFloat)
/* */ {
/* 447 */ this.size = paramFloat;
/* 448 */ if (this.isCJK) {
/* 449 */ this.ascent = this.size;
/* 450 */ this.descent = (-this.ascent / 4.0F);
/* 451 */ return this;
/* */ }
/* 453 */ this.ascent = (this.bBoxURy * this.size / this.unitsPerEm);
/* 454 */ this.descent = (this.bBoxLLy * this.size / this.unitsPerEm);
/* 455 */ this.body_height = (this.ascent - this.descent);
/* 456 */ this.underlineThickness = (this.fontUnderlineThickness * this.size / this.unitsPerEm);
/* 457 */ this.underlinePosition = (this.fontUnderlinePosition * this.size / -this.unitsPerEm + this.underlineThickness / 2.0F);
/* 458 */ return this;
/* */ }
/* */
/* */ public float getSize()
/* */ {
/* 468 */ return this.size;
/* */ }
/* */
/* */ public void setKernPairs(boolean paramBoolean)
/* */ {
/* 479 */ this.kernPairs = paramBoolean;
/* */ }
/* */
/* */ public float stringWidth(String paramString)
/* */ {
/* 491 */ if (paramString == null) {
/* 492 */ return 0.0F;
/* */ }
/* */
/* 495 */ if (this.isCJK) {
/* 496 */ return paramString.length() * this.ascent;
/* */ }
/* */
/* 499 */ int i = 0;
/* 500 */ for (int j = 0; j < paramString.length(); j++) {
/* 501 */ int k = paramString.charAt(j);
/* 502 */ if (this.isCoreFont) {
/* 503 */ if ((k < this.firstChar) || (k > this.lastChar)) {
/* 504 */ k = 32;
/* */ }
/* 506 */ k -= 32;
/* */
/* 508 */ i += this.metrics[k][1];
/* */
/* 510 */ if ((this.kernPairs) && (j < paramString.length() - 1)) {
/* 511 */ int m = paramString.charAt(j + 1);
/* 512 */ if ((m < this.firstChar) || (m > this.lastChar)) {
/* 513 */ m = 32;
/* */ }
/* 515 */ for (int n = 2; n < this.metrics[k].length; n += 2) {
/* 516 */ if (this.metrics[k][n] == m) {
/* 517 */ i += this.metrics[k][(n + 1)];
/* 518 */ break;
/* */ }
/* */ }
/* */ }
/* */
/* */ }
/* 524 */ else if ((k < this.firstChar) || (k > this.lastChar)) {
/* 525 */ i += this.advanceWidth[0];
/* */ } else {
/* 527 */ i += this.glyphWidth[k];
/* */ }
/* */
/* */ }
/* */
/* 532 */ return i * this.size / this.unitsPerEm;
/* */ }
/* */
/* */ public float getAscent()
/* */ {
/* 542 */ return this.ascent;
/* */ }
/* */
/* */ public float getDescent()
/* */ {
/* 552 */ return -this.descent;
/* */ }
/* */
/* */ public float getHeight()
/* */ {
/* 562 */ return this.ascent - this.descent;
/* */ }
/* */
/* */ public float getBodyHeight()
/* */ {
/* 572 */ return this.body_height;
/* */ }
/* */
/* */ public int getFitChars(String paramString, double paramDouble)
/* */ {
/* 585 */ return getFitChars(paramString, (float)paramDouble);
/* */ }
/* */
/* */ public int getFitChars(String paramString, float paramFloat)
/* */ {
/* 599 */ float f = paramFloat * this.unitsPerEm / this.size;
/* */
/* 601 */ if (this.isCJK) {
/* 602 */ return (int)(f / this.ascent);
/* */ }
/* */
/* 605 */ if (this.isCoreFont) {
/* 606 */ return getStandardFontFitChars(paramString, f);
/* */ }
/* */
/* 610 */ for (int i = 0; i < paramString.length(); i++) {
/* 611 */ int j = paramString.charAt(i);
/* */
/* 613 */ if ((j < this.firstChar) || (j > this.lastChar)) {
/* 614 */ f -= this.advanceWidth[0];
/* */ }
/* */ else {
/* 617 */ f -= this.glyphWidth[j];
/* */ }
/* */
/* 620 */ if (f < 0.0F)
/* */ break;
/* */ }
/* 623 */ return i;
/* */ }
/* */
/* */ private int getStandardFontFitChars(String paramString, float paramFloat)
/* */ {
/* 628 */ float f = paramFloat;
/* */
/* 630 */ int i = 0;
/* 631 */ while (i < paramString.length())
/* */ {
/* 633 */ int j = paramString.charAt(i);
/* */
/* 635 */ if ((j < this.firstChar) || (j > this.lastChar)) {
/* 636 */ j = 32;
/* */ }
/* */
/* 639 */ j -= 32;
/* 640 */ f -= this.metrics[j][1];
/* */
/* 642 */ if (f < 0.0F) {
/* 643 */ return i;
/* */ }
/* */
/* 646 */ if ((this.kernPairs) && (i < paramString.length() - 1)) {
/* 647 */ int k = paramString.charAt(i + 1);
/* 648 */ if ((k < this.firstChar) || (k > this.lastChar)) {
/* 649 */ k = 32;
/* */ }
/* */
/* 652 */ for (int m = 2; m < this.metrics[j].length; m += 2) {
/* 653 */ if (this.metrics[j][m] == k) {
/* 654 */ f -= this.metrics[j][(m + 1)];
/* 655 */ if (f >= 0.0F) break;
/* 656 */ return i;
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 663 */ i++;
/* */ }
/* */
/* 666 */ return i;
/* */ }
/* */
/* */ public void setItalic(boolean paramBoolean)
/* */ {
/* 681 */ this.skew15 = paramBoolean;
/* */ }
/* */
/* */ public float stringWidth(Font paramFont, String paramString)
/* */ {
/* 693 */ if (paramFont == null) {
/* 694 */ return stringWidth(paramString);
/* */ }
/* 696 */ float f = 0.0F;
/* */
/* 698 */ Font localFont = this;
/* 699 */ StringBuilder localStringBuilder = new StringBuilder();
/* 700 */ for (int i = 0; i < paramString.length(); i++) {
/* 701 */ int j = paramString.charAt(i);
/* 702 */ if (((this.isCJK) && (j >= 19968) && (j <= 40908)) || ((!this.isCJK) && (this.unicodeToGID[j] != 0)))
/* */ {
/* 704 */ if (this != localFont) {
/* 705 */ f += localFont.stringWidth(localStringBuilder.toString());
/* 706 */ localStringBuilder.setLength(0);
/* 707 */ localFont = this;
/* */ }
/* */
/* */ }
/* 711 */ else if (paramFont != localFont) {
/* 712 */ f += localFont.stringWidth(localStringBuilder.toString());
/* 713 */ localStringBuilder.setLength(0);
/* 714 */ localFont = paramFont;
/* */ }
/* */
/* 717 */ localStringBuilder.append((char)j);
/* */ }
/* 719 */ f += localFont.stringWidth(localStringBuilder.toString());
/* */
/* 721 */ return f;
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.Font
* JD-Core Version: 0.6.2
*/