protected FontEncoding() { unicodeToCode = new IntHashtable(256); codeToUnicode = ArrayUtil.fillWithValue(new int[256], -1); unicodeDifferences = new IntHashtable(256); fontSpecific = false; }
/** * Converts a {@code String} to a {@code byte} array according to the encoding. * String could contain a unicode symbols or font specific codes. * * @param text the {@code String} to be converted. * @return an array of {@code byte} representing the conversion according to the encoding */ public byte[] convertToBytes(String text) { if (text == null || text.length() == 0) { return emptyBytes; } int ptr = 0; byte[] bytes = new byte[text.length()]; for (int i = 0; i < text.length(); i++) { if (unicodeToCode.containsKey(text.charAt(i))) { bytes[ptr++] = (byte) convertToByte(text.charAt(i)); } } return ArrayUtil.shortenArray(bytes, ptr); }
public static int[] convertToUtf32(String text) { if (text == null) { return null; } List<Integer> charCodes = new ArrayList<>(text.length()); int pos = 0; while (pos < text.length()) { if (isSurrogatePair(text, pos)) { charCodes.add(convertToUtf32(text, pos)); pos += 2; } else { charCodes.add((int) text.charAt(pos)); pos++; } } return ArrayUtil.toIntArray(charCodes); }
private static int calculateHashCode(String fontName, byte[] bytes, String encoding, Range range) { int result = fontName != null ? fontName.hashCode() : 0; result = 31 * result + ArrayUtil.hashCode(bytes); result = 31 * result + (encoding != null ? encoding.hashCode() : 0); result = 31 * result + range.hashCode(); return result; }
fontDescriptor.put(PdfName.CapHeight, new PdfNumber(fontMetrics.getCapHeight())); fontDescriptor.put(PdfName.Descent, new PdfNumber(fontMetrics.getTypoDescender())); fontDescriptor.put(PdfName.FontBBox, new PdfArray(ArrayUtil.cloneArray(fontMetrics.getBbox()))); fontDescriptor.put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.getItalicAngle())); fontDescriptor.put(PdfName.StemV, new PdfNumber(fontMetrics.getStemV()));
private static int calculateHashCode(String fontName, byte[] bytes, String encoding, Range range) { int result = fontName != null ? fontName.hashCode() : 0; result = 31 * result + ArrayUtil.hashCode(bytes); result = 31 * result + (encoding != null ? encoding.hashCode() : 0); result = 31 * result + range.hashCode(); return result; }
protected FontEncoding() { unicodeToCode = new IntHashtable(256); codeToUnicode = ArrayUtil.fillWithValue(new int[256], -1); unicodeDifferences = new IntHashtable(256); fontSpecific = false; }
public static int[] convertToUtf32(String text) { if (text == null) { return null; } List<Integer> charCodes = new ArrayList<>(text.length()); int pos = 0; while (pos < text.length()) { if (isSurrogatePair(text, pos)) { charCodes.add(convertToUtf32(text, pos)); pos += 2; } else { charCodes.add((int) text.charAt(pos)); pos++; } } return ArrayUtil.toIntArray(charCodes); }
/** * Converts a {@code String} to a {@code byte} array according to the encoding. * String could contain a unicode symbols or font specific codes. * * @param text the {@code String} to be converted. * @return an array of {@code byte} representing the conversion according to the encoding */ public byte[] convertToBytes(String text) { if (text == null || text.length() == 0) { return emptyBytes; } int ptr = 0; byte[] bytes = new byte[text.length()]; for (int i = 0; i < text.length(); i++) { if (unicodeToCode.containsKey(text.charAt(i))) { bytes[ptr++] = (byte) convertToByte(text.charAt(i)); } } return ArrayUtil.shortenArray(bytes, ptr); }
int[] flexibleColIndexes = ArrayUtil.fillWithValue(new int[cell.getColspan()], -1); if (flexibleCols > 0) {
private void updateBidiLevels(int totalNumberOfTrimmedGlyphs, BaseDirection baseDirection) { if (totalNumberOfTrimmedGlyphs != 0 && levels != null) { levels = Arrays.copyOfRange(levels, totalNumberOfTrimmedGlyphs, levels.length); } List<Integer> unicodeIdsReorderingList = null; if (levels == null && baseDirection != null && baseDirection != BaseDirection.NO_BIDI) { unicodeIdsReorderingList = new ArrayList<>(); boolean newLineFound = false; for (IRenderer child : childRenderers) { if (newLineFound) { break; } if (child instanceof TextRenderer) { GlyphLine text = ((TextRenderer) child).getText(); for (int i = text.start; i < text.end; i++) { Glyph glyph = text.get(i); if (TextUtil.isNewLine(glyph)) { newLineFound = true; break; } // we assume all the chars will have the same bidi group // we also assume pairing symbols won't get merged with other ones int unicode = glyph.hasValidUnicode() ? glyph.getUnicode() : glyph.getUnicodeChars()[0]; unicodeIdsReorderingList.add(unicode); } } } levels = unicodeIdsReorderingList.size() > 0 ? TypographyUtils.getBidiLevels(baseDirection, ArrayUtil.toIntArray(unicodeIdsReorderingList)) : null; } }
@Override public void writeText(GlyphLine text, int from, int to, PdfOutputStream stream) { byte[] bytes = new byte[to - from + 1]; int ptr = 0; if (fontEncoding.isFontSpecific()) { for (int i = from; i <= to; i++) { bytes[ptr++] = (byte) text.get(i).getCode(); } } else { for (int i = from; i <= to; i++) { if (fontEncoding.canEncode(text.get(i).getUnicode())) { bytes[ptr++] = (byte) fontEncoding.convertToByte(text.get(i).getUnicode()); } } } bytes = ArrayUtil.shortenArray(bytes, ptr); for (byte b : bytes) { shortTag[b & 0xff] = 1; } StreamUtil.writeEscapedString(stream, bytes); }
int[] flexibleColIndexes = ArrayUtil.fillWithValue(new int[cell.getColspan()], -1); if (flexibleCols > 0) {
private void updateBidiLevels(int totalNumberOfTrimmedGlyphs, BaseDirection baseDirection) { if (totalNumberOfTrimmedGlyphs != 0 && levels != null) { levels = Arrays.copyOfRange(levels, totalNumberOfTrimmedGlyphs, levels.length); } List<Integer> unicodeIdsReorderingList = null; if (levels == null && baseDirection != null && baseDirection != BaseDirection.NO_BIDI) { unicodeIdsReorderingList = new ArrayList<>(); boolean newLineFound = false; for (IRenderer child : childRenderers) { if (newLineFound) { break; } if (child instanceof TextRenderer) { GlyphLine text = ((TextRenderer) child).getText(); for (int i = text.start; i < text.end; i++) { Glyph glyph = text.get(i); if (TextUtil.isNewLine(glyph)) { newLineFound = true; break; } // we assume all the chars will have the same bidi group // we also assume pairing symbols won't get merged with other ones int unicode = glyph.hasValidUnicode() ? glyph.getUnicode() : glyph.getUnicodeChars()[0]; unicodeIdsReorderingList.add(unicode); } } } levels = unicodeIdsReorderingList.size() > 0 ? TypographyUtils.getBidiLevels(baseDirection, ArrayUtil.toIntArray(unicodeIdsReorderingList)) : null; } }
@Override public byte[] convertToBytes(GlyphLine glyphLine) { if (glyphLine != null) { byte[] bytes = new byte[glyphLine.size()]; int ptr = 0; if (fontEncoding.isFontSpecific()) { for (int i = 0; i < glyphLine.size(); i++) { bytes[ptr++] = (byte) glyphLine.get(i).getCode(); } } else { for (int i = 0; i < glyphLine.size(); i++) { if (fontEncoding.canEncode(glyphLine.get(i).getUnicode())) { bytes[ptr++] = (byte) fontEncoding.convertToByte(glyphLine.get(i).getUnicode()); } } } bytes = ArrayUtil.shortenArray(bytes, ptr); for (byte b : bytes) { shortTag[b & 0xff] = 1; } return bytes; } else { return EMPTY_BYTES; } }