protected float getDescender() { float sizeCoef = size / FontProgram.UNITS_NORMALIZATION; return font.getFontProgram().getFontMetrics().getTypoDescender() * sizeCoef; } }
private static FontProgramDescriptor fetchDescriptorFromFontProgram(FontProgram fontProgram) { return new FontProgramDescriptor(fontProgram.getFontNames(), fontProgram.getFontMetrics()); } }
@Override public boolean containsGlyph(int unicode) { if (fontEncoding.isFontSpecific()) { return fontProgram.getGlyphByCode(unicode) != null; } else { return fontEncoding.canEncode(unicode) && getFontProgram().getGlyph(fontEncoding.getUnicodeDifference(unicode)) != null; } }
@Override public boolean containsGlyph(int unicode) { if (cidFontType == CID_FONT_TYPE_0) { if (cmapEncoding.isDirect()) { return fontProgram.getGlyphByCode(unicode) != null; } else { return getFontProgram().getGlyph(unicode) != null; } } else if (cidFontType == CID_FONT_TYPE_2) { if (fontProgram.isFontSpecific()) { byte[] b = PdfEncodings.convertToBytes((char) unicode, "symboltt"); return b.length > 0 && fontProgram.getGlyph(b[0] & 0xff) != null; } else { return getFontProgram().getGlyph(unicode) != null; } } else { throw new PdfException("Invalid CID font type: " + cidFontType); } }
@Override protected PdfDictionary getFontDescriptor(String fontName) { if (fontName != null && fontName.length() > 0) { PdfDictionary fontDescriptor = new PdfDictionary(); makeObjectIndirect(fontDescriptor); fontDescriptor.put(PdfName.Type, PdfName.FontDescriptor); FontMetrics fontMetrics = fontProgram.getFontMetrics(); fontDescriptor.put(PdfName.CapHeight, new PdfNumber(fontMetrics.getCapHeight())); fontDescriptor.put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.getItalicAngle())); FontNames fontNames = fontProgram.getFontNames(); fontDescriptor.put(PdfName.FontWeight, new PdfNumber(fontNames.getFontWeight())); fontDescriptor.put(PdfName.FontName, new PdfName(fontName)); if (fontNames.getFamilyName() != null && fontNames.getFamilyName().length > 0 && fontNames.getFamilyName()[0].length >= 4) { fontDescriptor.put(PdfName.FontFamily, new PdfString(fontNames.getFamilyName()[0][3])); } int flags = fontProgram.getPdfFontFlags(); flags &= ~(FontDescriptorFlags.Symbolic | FontDescriptorFlags.Nonsymbolic); // reset both flags flags |= fontEncoding.isFontSpecific() ? // set based on font encoding FontDescriptorFlags.Symbolic : FontDescriptorFlags.Nonsymbolic; fontDescriptor.put(PdfName.Flags, new PdfNumber(flags)); return fontDescriptor; } else if (getPdfObject().getIndirectReference() != null && getPdfObject().getIndirectReference().getDocument().isTagged()) { Logger logger = LoggerFactory.getLogger(PdfType3Font.class); logger.warn(LogMessageConstant.TYPE3_FONT_ISSUE_TAGGED_PDF); } return null; }
@Override protected PdfDictionary getFontDescriptor(String fontName) { PdfDictionary fontDescriptor = new PdfDictionary(); makeObjectIndirect(fontDescriptor); fontDescriptor.put(PdfName.Type, PdfName.FontDescriptor); fontDescriptor.put(PdfName.FontName, new PdfName(fontName)); fontDescriptor.put(PdfName.FontBBox, new PdfArray(getFontProgram().getFontMetrics().getBbox())); fontDescriptor.put(PdfName.Ascent, new PdfNumber(getFontProgram().getFontMetrics().getTypoAscender())); fontDescriptor.put(PdfName.Descent, new PdfNumber(getFontProgram().getFontMetrics().getTypoDescender())); fontDescriptor.put(PdfName.CapHeight, new PdfNumber(getFontProgram().getFontMetrics().getCapHeight())); fontDescriptor.put(PdfName.ItalicAngle, new PdfNumber(getFontProgram().getFontMetrics().getItalicAngle())); fontDescriptor.put(PdfName.StemV, new PdfNumber(getFontProgram().getFontMetrics().getStemV())); fontDescriptor.put(PdfName.Flags, new PdfNumber(getFontProgram().getPdfFontFlags())); if (fontProgram.getFontIdentification().getPanose() != null) { PdfDictionary styleDictionary = new PdfDictionary(); styleDictionary.put(PdfName.Panose, new PdfString(fontProgram.getFontIdentification().getPanose()).setHexWriting(true)); fontDescriptor.put(PdfName.Style, styleDictionary); } return fontDescriptor; }
@Override public String toString() { String name = getFontNames().getFontName(); return name.length() > 0 ? name : super.toString(); } }
if (fontProgram.countOfGlyphs() == 0) { fontProgram.getFontMetrics().setBbox(llx, lly, urx, ury); } else { int[] bbox = fontProgram.getFontMetrics().getBbox(); int newLlx = Math.min(bbox[0], llx); int newLly = Math.min(bbox[1], lly); int newUrx = Math.max(bbox[2], urx); int newUry = Math.max(bbox[3], ury); fontProgram.getFontMetrics().setBbox(newLlx, newLly, newUrx, newUry);
byte[] bytes = font.encoding.convertToBytes(text); for (byte b : bytes) { normalizedWidth += fp.getWidth(0xff & b); float descender = fp.getFontMetrics().getTypoDescender(); float ury = fp.getFontMetrics().getBbox()[3]; cb.saveState(); cb.concatMatrix(cos, sin, -sin, cos, refX, refY);
/** * Get glyph's width. * * @param unicode a unicode symbol or FontSpecif code. * @return Gets width in normalized 1000 units. */ public int getWidth(int unicode) { Glyph glyph = getGlyph(unicode); return glyph != null ? glyph.getWidth() : 0; }
ByteBuffer buffer = new ByteBuffer(); int i = 0; if (fontProgram.isFontSpecific()) { byte[] b = PdfEncodings.convertToBytes(text, "symboltt"); len = b.length; for (int k = 0; k < len; ++k) { Glyph glyph = fontProgram.getGlyph(b[k] & 0xff); if (glyph != null) { convertToBytes(glyph, buffer);
/** * Calculates the width of a space character. If the font does not define * a width for a standard space character \u0020, we also attempt to use * the width of \u00A0 (a non-breaking space in many fonts) * * @return the width of a single space character in text space units */ private float getUnscaledFontSpaceWidth() { checkGraphicsState(); char charToUse = ' '; if (gs.getFont().getWidth(charToUse) == 0) { return gs.getFont().getFontProgram().getAvgWidth() / 1000f; } else { return getStringWidth(String.valueOf(charToUse)); } }
protected PdfDictionary getFontDescriptor(String fontName) { assert fontName != null && fontName.length() > 0; FontMetrics fontMetrics = fontProgram.getFontMetrics(); FontNames fontNames = fontProgram.getFontNames(); PdfDictionary fontDescriptor = new PdfDictionary(); makeObjectIndirect(fontDescriptor); int flags = fontProgram.getPdfFontFlags();
@Override public String toString() { String name = getFontNames().getFontName(); return name.length() > 0 ? name : super.toString(); } }
int processed = 0; for (int k = from; k <= to; k++) { Glyph glyph = fontProgram.getGlyphByCode((int) text.charAt(k)); if (glyph != null && (isAppendableGlyph(glyph))) { glyphs.add(glyph); if (fontProgram.isFontSpecific()) { int processed = 0; for (int k = from; k <= to; k++) { Glyph glyph = fontProgram.getGlyph(text.charAt(k) & 0xff); if (glyph != null && (isAppendableGlyph(glyph))) { glyphs.add(glyph);
/** * Get glyph's bbox. * * @param unicode a unicode symbol or FontSpecif code. * @return Gets bbox in normalized 1000 units. */ public int[] getCharBBox(int unicode) { Glyph glyph = getGlyph(unicode); return glyph != null ? glyph.getBbox() : null; }
/** * Gets the ascent of a char code in normalized 1000 units. The ascent will always be * greater than or equal to zero even if all the characters have a lower ascent. * * @param unicode the char code to get the ascent of * @param fontSize the font size * @return the ascent in points */ public int getAscent(int unicode, float fontSize) { int max = 0; Glyph glyph = getGlyph(unicode); if (glyph == null) { return 0; } int[] bbox = glyph.getBbox(); if (bbox != null && bbox[3] > max) { max = bbox[3]; } else if (bbox == null && getFontProgram().getFontMetrics().getTypoAscender() > max) { max = getFontProgram().getFontMetrics().getTypoAscender(); } return (int) (max * fontSize / FontProgram.UNITS_NORMALIZATION); }
private static FontProgramDescriptor fetchDescriptorFromFontProgram(FontProgram fontProgram) { return new FontProgramDescriptor(fontProgram.getFontNames(), fontProgram.getFontMetrics()); } }
if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf") || path.toLowerCase().indexOf(".ttc,") > 0) { FontProgram fontProgram = FontProgramFactory.createFont(path); Object[] allNames = new Object[]{fontProgram.getFontNames().getFontName(), fontProgram.getFontNames().getFamilyName(), fontProgram.getFontNames().getFullName()}; fontNames.put(((String) allNames[0]).toLowerCase(), path); if (alias != null) { String fullName = fontProgram.getFontNames().getFullName()[0][3].toLowerCase(); String familyName = fontProgram.getFontNames().getFamilyName()[0][3].toLowerCase(); String psName = fontProgram.getFontNames().getFontName().toLowerCase(); registerFontFamily(familyName, fullName, null); fontNames.put(psName, path);
@Override public Glyph getGlyph(int unicode) { if (fontEncoding.canEncode(unicode)) { Glyph glyph = getFontProgram().getGlyph(fontEncoding.getUnicodeDifference(unicode)); //TODO TrueType what if font is specific? if (glyph == null && (glyph = notdefGlyphs.get(unicode)) == null) { Glyph notdef = getFontProgram().getGlyphByCode(0); if (notdef != null) { glyph = new Glyph(getFontProgram().getGlyphByCode(0), unicode); notdefGlyphs.put(unicode, glyph); } } return glyph; } return null; }