@Override public float getHeight(int code) throws IOException { String name = codeToName(code); if (getStandard14AFM() != null) { String afmName = getEncoding().getName(code); return getStandard14AFM().getCharacterHeight(afmName); // todo: isn't this the y-advance, not the height? } else { // todo: should be scaled by font matrix return (float) genericFont.getPath(name).getBounds().getHeight(); } }
codeToBytesMap = new HashMap<>(); PDFontDescriptor fd = getFontDescriptor(); Type1Font t1 = null; boolean fontIsDamaged = false; length1 = repairLength1(bytes, length1); length2 = repairLength2(bytes, length1, length2); .getFontBoxFont(getBaseFont(), fd); genericFont = mapping.getFont(); LOG.warn("Using fallback font " + genericFont.getName() + " for " + getBaseFont()); readEncoding(); fontMatrixTransform = getFontMatrix().createAffineTransform(); fontMatrixTransform.scale(1000, 1000);
String name = getGlyphList().codePointToName(unicode); if (isStandard14()) unicode, name, getName(), encoding.getEncodingName())); String.format("No glyph for U+%04X in font %s", unicode, getName())); unicode, name, getName(), genericFont.getName(), encoding.getEncodingName())); String nameInFont = getNameInFont(name); String.format("No glyph for U+%04X in font %s (generic: %s)", unicode, getName(), genericFont.getName()));
@Override public GeneralPath getNormalizedPath(int code) throws IOException { String name = getEncoding().getName(code); GeneralPath path = getPath(name); if (path == null) { return getPath(".notdef"); } return path; }
public String codeToName(int code) throws IOException { String name = getEncoding().getName(code); return getNameInFont(name); }
offset = findBinaryOffsetAfterExec(bytes, offset); if (offset == 0 && length1 > 0) offset = findBinaryOffsetAfterExec(bytes, bytes.length - 4); LOG.warn("Ignored invalid Length1 " + length1 + " for Type 1 font " + getName());
.getFontBoxFont(getBaseFont(), getFontDescriptor()); genericFont = mapping.getFont(); fontName = "?"; LOG.warn("Using fallback font " + fontName + " for base font " + getBaseFont());
String name = PDType1Font.ZAPF_DINGBATS.codeToName(normalCaption.codePointAt(0)); String unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode(name); Rectangle2D bounds = PDType1Font.ZAPF_DINGBATS.getPath(name).getBounds2D(); float size = (float) Math.min(bounds.getWidth(), bounds.getHeight()) / 1000;
doc.addPage(page); PDFont font = new PDType1Font(doc, new FileInputStream(pfbPath));
if (isEmbedded() || genericFont.hasGlyph(name)) String unicodes = getGlyphList().toUnicode(name); if (unicodes != null && unicodes.length() == 1)
private void drawStar(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException { PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19); float min = Math.min(bbox.getWidth(), bbox.getHeight()); contentStream.setMiterLimit(4); contentStream.setLineJoinStyle(1); contentStream.setLineCapStyle(0); contentStream.setLineWidth(0.59f); // value from Adobe contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f)); // we get the shape of a Zapf Dingbats star (0x2605) and use that one. // Adobe uses a different font (which one?), or created the shape from scratch. GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a35"); addPath(contentStream, path); contentStream.fillAndStroke(); }
@Override public String getName() { return getBaseFont(); }
font = PDType1Font.HELVETICA; } else { font = PDType1Font.getStandardFont(inFontName); if (font == null) { font = new PDType1Font(inFontName);
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (isNonZeroBoundingBox(bbox)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return genericFont.getFontBBox(); }
@Override public float getWidthFromFont(int code) throws IOException { String name = codeToName(code); // width of .notdef is ignored for substitutes, see PDFBOX-1900 if (!isEmbedded && name.equals(".notdef")) { return 250; } float width = genericFont.getWidth(name); Point2D p = new Point2D.Float(width, 0); fontMatrixTransform.transform(p, p); return (float)p.getX(); }
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 || bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return genericFont.getFontBBox(); }
private TextStyle(PDType1Font f, double sz, Color tc, double leadingFactor) { if (f == null) { throw new IllegalArgumentException("Font must not be null"); } if (tc == null) { tc = Color.BLACK; } font = f; textColor = tc; fontSize = sz; // Somewhere it says that font units are 1000 times page units, but my tests with // PDType1Font.HELVETICA and PDType1Font.HELVETICA_BOLD from size 5-200 show that 960x is // pretty darn good. // TODO: Fix font-size for other fonts. factor = fontSize / 960; PDFontDescriptor fontDescriptor = font.getFontDescriptor(); double rawAscent = fontDescriptor.getAscent(); double rawDescent = fontDescriptor.getDescent(); // Characters look best with the descent size both above and below. Also acts as a good // default leading. ascent = rawAscent * factor; descent = rawDescent * -factor; leading = descent * leadingFactor; // height = ascent + descent + leading; double avgFontWidth = 500; try { avgFontWidth = font.getAverageFontWidth(); } catch (Exception ioe) { //throw new IllegalStateException("IOException probably means an issue reading font metrics from the underlying font file used in this PDF", ioe); ; // just use default if there's an exception. } avgCharWidth = avgFontWidth * fontSize; }
if (PDType1Font.COURIER.isStandard14())
@Override public BoundingBox getBoundingBox() throws IOException { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
@Override public boolean hasGlyph(int code) throws IOException { return !getEncoding().getName(code).equals(".notdef"); }