com.pdfjet.OTF Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.io.ByteArrayOutputStream;
/* */ import java.io.IOException;
/* */ import java.io.InputStream;
/* */ import java.util.Arrays;
/* */ import java.util.zip.Deflater;
/* */ import java.util.zip.DeflaterOutputStream;
/* */
/* */ class OTF
/* */ {
/* */ protected String fontName;
/* */ protected String fontInfo;
/* 19 */ protected StringBuilder macFontInfo = null;
/* 20 */ protected StringBuilder winFontInfo = null;
/* 21 */ protected boolean cff = false;
/* */ protected ByteArrayOutputStream baos;
/* */ protected byte[] buf;
/* */ protected int unitsPerEm;
/* */ protected short bBoxLLx;
/* */ protected short bBoxLLy;
/* */ protected short bBoxURx;
/* */ protected short bBoxURy;
/* */ protected short ascent;
/* */ protected short descent;
/* */ protected int[] advanceWidth;
/* */ protected int firstChar;
/* */ protected int lastChar;
/* */ protected int capHeight;
/* */ protected int[] glyphWidth;
/* */ protected long postVersion;
/* */ protected long italicAngle;
/* */ protected short underlinePosition;
/* */ protected short underlineThickness;
/* */ private InputStream stream;
/* */ private DeflaterOutputStream dos;
/* */ private int cff_off;
/* */ private int cff_len;
/* 45 */ private int index = 0;
/* */
/* 47 */ protected int[] unicodeToGID = new int[65536];
/* */
/* */ public OTF(InputStream paramInputStream) throws Exception
/* */ {
/* 51 */ this.stream = paramInputStream;
/* 52 */ this.baos = new ByteArrayOutputStream();
/* */
/* 54 */ byte[] arrayOfByte1 = new byte[65536];
/* */ int i;
/* 56 */ while ((i = paramInputStream.read(arrayOfByte1, 0, arrayOfByte1.length)) > 0) {
/* 57 */ this.baos.write(arrayOfByte1, 0, i);
/* */ }
/* 59 */ paramInputStream.close();
/* 60 */ this.buf = this.baos.toByteArray();
/* */
/* 62 */ this.baos = new ByteArrayOutputStream();
/* 63 */ this.dos = new DeflaterOutputStream(this.baos, new Deflater(1));
/* */
/* 66 */ long l = readUInt32();
/* 67 */ if ((l != 65536L) && (l != 1953658213L) && (l != 1330926671L))
/* */ {
/* 73 */ throw new Exception("OTF version == " + l + " is not supported.");
/* */ }
/* */
/* 77 */ int j = readUInt16();
/* 78 */ int k = readUInt16();
/* 79 */ int m = readUInt16();
/* 80 */ int n = readUInt16();
/* */
/* 82 */ Object localObject = null;
/* 83 */ for (int i1 = 0; i1 < j; i1++) {
/* 84 */ byte[] arrayOfByte2 = new byte[4];
/* 85 */ for (int i2 = 0; i2 < 4; i2++) {
/* 86 */ arrayOfByte2[i2] = readByte();
/* */ }
/* 88 */ FontTable localFontTable = new FontTable();
/* 89 */ localFontTable.name = new String(arrayOfByte2);
/* 90 */ localFontTable.checkSum = readUInt32();
/* 91 */ localFontTable.offset = ((int)readUInt32());
/* 92 */ localFontTable.length = ((int)readUInt32());
/* */
/* 94 */ int i3 = this.index;
/* 95 */ if (localFontTable.name.equals("head")) head(localFontTable);
/* 96 */ else if (localFontTable.name.equals("hhea")) hhea(localFontTable);
/* 97 */ else if (localFontTable.name.equals("OS/2")) OS_2(localFontTable);
/* 98 */ else if (localFontTable.name.equals("name")) name(localFontTable);
/* 99 */ else if (localFontTable.name.equals("hmtx")) hmtx(localFontTable);
/* 100 */ else if (localFontTable.name.equals("post")) post(localFontTable);
/* 101 */ else if (localFontTable.name.equals("CFF ")) CFF_(localFontTable);
/* 102 */ else if (localFontTable.name.equals("cmap")) localObject = localFontTable;
/* 103 */ this.index = i3;
/* */ }
/* */
/* 107 */ cmap(localObject);
/* */
/* 109 */ if (this.cff) {
/* 110 */ this.dos.write(this.buf, this.cff_off, this.cff_len);
/* */ }
/* */ else {
/* 113 */ this.dos.write(this.buf, 0, this.buf.length);
/* */ }
/* 115 */ this.dos.finish();
/* */ }
/* */
/* */ private void head(FontTable paramFontTable) throws IOException {
/* 119 */ this.index = (paramFontTable.offset + 16);
/* 120 */ int i = readUInt16();
/* 121 */ this.unitsPerEm = readUInt16();
/* 122 */ this.index += 16;
/* 123 */ this.bBoxLLx = ((short)readUInt16());
/* 124 */ this.bBoxLLy = ((short)readUInt16());
/* 125 */ this.bBoxURx = ((short)readUInt16());
/* 126 */ this.bBoxURy = ((short)readUInt16());
/* */ }
/* */
/* */ private void hhea(FontTable paramFontTable) throws IOException {
/* 130 */ this.index = (paramFontTable.offset + 4);
/* 131 */ this.ascent = ((short)readUInt16());
/* 132 */ this.descent = ((short)readUInt16());
/* 133 */ this.index += 26;
/* 134 */ this.advanceWidth = new int[readUInt16()];
/* */ }
/* */
/* */ private void OS_2(FontTable paramFontTable) throws IOException {
/* 138 */ this.index = (paramFontTable.offset + 64);
/* 139 */ this.firstChar = readUInt16();
/* 140 */ this.lastChar = readUInt16();
/* 141 */ this.index += 20;
/* 142 */ this.capHeight = ((short)readUInt16());
/* */ }
/* */
/* */ private void name(FontTable paramFontTable) throws IOException {
/* 146 */ this.index = paramFontTable.offset;
/* 147 */ int i = readUInt16();
/* 148 */ int j = readUInt16();
/* 149 */ int k = readUInt16();
/* */
/* 151 */ for (int m = 0; m < j; m++) {
/* 152 */ int n = readUInt16();
/* 153 */ int i1 = readUInt16();
/* 154 */ int i2 = readUInt16();
/* 155 */ int i3 = readUInt16();
/* 156 */ int i4 = readUInt16();
/* 157 */ int i5 = readUInt16();
/* */ String str;
/* 159 */ if ((n == 1) && (i1 == 0) && (i2 == 0))
/* */ {
/* 161 */ str = new String(this.buf, paramFontTable.offset + k + i5, i4, "UTF8");
/* */
/* 163 */ if (i3 == 6) {
/* 164 */ this.fontName = str;
/* */ }
/* */ else {
/* 167 */ if (this.macFontInfo == null) {
/* 168 */ this.macFontInfo = new StringBuilder();
/* */ }
/* 170 */ this.macFontInfo.append(str);
/* 171 */ this.macFontInfo.append('\n');
/* */ }
/* */ }
/* 174 */ else if ((n == 3) && (i1 == 1) && (i2 == 1033))
/* */ {
/* 176 */ str = new String(this.buf, paramFontTable.offset + k + i5, i4, "UTF16");
/* */
/* 178 */ if (i3 == 6) {
/* 179 */ this.fontName = str;
/* */ }
/* */ else {
/* 182 */ if (this.winFontInfo == null) {
/* 183 */ this.winFontInfo = new StringBuilder();
/* */ }
/* 185 */ this.winFontInfo.append(str);
/* 186 */ this.winFontInfo.append('\n');
/* */ }
/* */ }
/* */ }
/* 190 */ this.fontInfo = (this.winFontInfo != null ? this.winFontInfo.toString() : this.macFontInfo.toString());
/* */ }
/* */
/* */ private void cmap(FontTable paramFontTable) throws Exception {
/* 194 */ this.index = paramFontTable.offset;
/* 195 */ int i = this.index;
/* 196 */ this.index += 2;
/* 197 */ int j = readUInt16();
/* */
/* 200 */ int k = 0;
/* 201 */ int m = 0;
/* 202 */ for (int n = 0; n < j; n++) {
/* 203 */ i1 = readUInt16();
/* 204 */ i2 = readUInt16();
/* 205 */ m = (int)readUInt32();
/* 206 */ if ((i1 == 3) && (i2 == 1)) {
/* 207 */ k = 1;
/* 208 */ break;
/* */ }
/* */ }
/* 211 */ if (k == 0) {
/* 212 */ throw new Exception("Format 4 subtable not found in this font.");
/* */ }
/* */
/* 215 */ this.index = (i + m);
/* */
/* 217 */ n = readUInt16();
/* 218 */ int i1 = readUInt16();
/* 219 */ int i2 = readUInt16();
/* 220 */ int i3 = readUInt16() / 2;
/* */
/* 222 */ this.index += 6;
/* 223 */ int[] arrayOfInt1 = new int[i3];
/* 224 */ for (int i4 = 0; i4 < i3; i4++) {
/* 225 */ arrayOfInt1[i4] = readUInt16();
/* */ }
/* */
/* 228 */ this.index += 2;
/* 229 */ int[] arrayOfInt2 = new int[i3];
/* 230 */ for (int i5 = 0; i5 < i3; i5++) {
/* 231 */ arrayOfInt2[i5] = readUInt16();
/* */ }
/* */
/* 234 */ short[] arrayOfShort = new short[i3];
/* 235 */ for (int i6 = 0; i6 < i3; i6++) {
/* 236 */ arrayOfShort[i6] = ((short)readUInt16());
/* */ }
/* */
/* 239 */ int[] arrayOfInt3 = new int[i3];
/* 240 */ for (int i7 = 0; i7 < i3; i7++) {
/* 241 */ arrayOfInt3[i7] = readUInt16();
/* */ }
/* */
/* 244 */ int[] arrayOfInt4 = new int[(i1 - (16 + 8 * i3)) / 2];
/* 245 */ for (int i8 = 0; i8 < arrayOfInt4.length; i8++) {
/* 246 */ arrayOfInt4[i8] = readUInt16();
/* */ }
/* */
/* 249 */ this.glyphWidth = new int[this.lastChar + 1];
/* 250 */ Arrays.fill(this.glyphWidth, this.advanceWidth[0]);
/* */
/* 252 */ for (i8 = this.firstChar; i8 <= this.lastChar; i8++) {
/* 253 */ int i9 = getSegmentFor(i8, arrayOfInt2, arrayOfInt1, i3);
/* 254 */ if (i9 != -1)
/* */ {
/* 256 */ int i11 = arrayOfInt3[i9];
/* */ int i10;
/* 257 */ if (i11 == 0) {
/* 258 */ i10 = (arrayOfShort[i9] + i8) % 65536;
/* */ }
/* */ else {
/* 261 */ i11 /= 2;
/* 262 */ i11 -= i3 - i9;
/* 263 */ i10 = arrayOfInt4[(i11 + (i8 - arrayOfInt2[i9]))];
/* 264 */ if (i10 != 0) {
/* 265 */ i10 += arrayOfShort[i9] % 65536;
/* */ }
/* */ }
/* */
/* 269 */ if (i10 < this.advanceWidth.length) {
/* 270 */ this.glyphWidth[i8] = this.advanceWidth[i10];
/* */ }
/* */
/* 273 */ this.unicodeToGID[i8] = i10;
/* */ }
/* */ }
/* */ }
/* */
/* */ private void hmtx(FontTable paramFontTable) throws IOException {
/* 279 */ this.index = paramFontTable.offset;
/* 280 */ for (int i = 0; i < this.advanceWidth.length; i++) {
/* 281 */ this.advanceWidth[i] = readUInt16();
/* 282 */ this.index += 2;
/* */ }
/* */ }
/* */
/* */ private void post(FontTable paramFontTable) throws IOException {
/* 287 */ this.index = paramFontTable.offset;
/* 288 */ this.postVersion = readUInt32();
/* 289 */ this.italicAngle = readUInt32();
/* 290 */ this.underlinePosition = ((short)readUInt16());
/* 291 */ this.underlineThickness = ((short)readUInt16());
/* */ }
/* */
/* */ private void CFF_(FontTable paramFontTable) throws IOException {
/* 295 */ this.cff = true;
/* 296 */ this.cff_off = paramFontTable.offset;
/* 297 */ this.cff_len = paramFontTable.length;
/* */ }
/* */
/* */ private int getSegmentFor(int paramInt1, int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt2)
/* */ {
/* 302 */ int i = -1;
/* 303 */ for (int j = 0; j < paramInt2; j++) {
/* 304 */ if ((paramInt1 <= paramArrayOfInt2[j]) && (paramInt1 >= paramArrayOfInt1[j])) {
/* 305 */ i = j;
/* 306 */ break;
/* */ }
/* */ }
/* 309 */ return i;
/* */ }
/* */
/* */ private byte readByte() {
/* 313 */ return this.buf[(this.index++)];
/* */ }
/* */
/* */ private int readUInt16() {
/* 317 */ int i = 0;
/* 318 */ i |= this.buf[(this.index++)] << 8 & 0xFF00;
/* 319 */ i |= this.buf[(this.index++)] & 0xFF;
/* 320 */ return i;
/* */ }
/* */
/* */ private long readUInt32() {
/* 324 */ long l = 0L;
/* 325 */ l |= this.buf[(this.index++)] << 24 & 0xFF000000;
/* 326 */ l |= this.buf[(this.index++)] << 16 & 0xFF0000;
/* 327 */ l |= this.buf[(this.index++)] << 8 & 0xFF00;
/* 328 */ l |= this.buf[(this.index++)] & 0xFF;
/* 329 */ return l;
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.OTF
* JD-Core Version: 0.6.2
*/