if (retval > 0) retval -= desc.getDescent();
@Override public Double getDescent() { return Double.valueOf(descriptor.getDescent()); }
-font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0)
private static float getDescent(PDFont font, float fontSize) { try { return (font.getFontDescriptor().getDescent() / 1000) * fontSize; } catch (Exception e) { } return 0.0f; }
float fontBoundingBoxAtSize = font.getBoundingBox().getHeight() * fontScaleY; float fontCapAtSize = font.getFontDescriptor().getCapHeight() * fontScaleY; float fontDescentAtSize = font.getFontDescriptor().getDescent() * fontScaleY;
public static float findMaxFontHeigth(PDFont font, int fontSize) { return (font.getFontDescriptor().getAscent() / 1000 * fontSize) - (font.getFontDescriptor().getDescent() / 1000 * fontSize); }
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; }
private void drawUnderline(String text, Color color) { if (underline != Font.U_NONE && !StringUtils.isEmpty(text)) { int fontSize = (int) stream.getFontSize(); PDFont font = stream.getFont(); float descend = font.getFontDescriptor().getDescent() / 1000 * fontSize; drawUnderline(text,color, descend); if (underline == Font.U_DOUBLE || underline == Font.U_DOUBLE_ACCOUNTING) { drawUnderline(text,color, descend / 2); } } }
/** * <p> * Create basic {@link FontMetrics} for current font. * <p> * * @param font * The font from which calculation will be applied <<<<<<< HEAD * @throws IOException * If reading the font file fails ======= >>>>>>> using FreeSans * as default font and added new free fonts */ private static void createFontMetrics(final PDFont font) { final float base = font.getFontDescriptor().getXHeight() / 1000; final float ascent = font.getFontDescriptor().getAscent() / 1000 - base; final float descent = font.getFontDescriptor().getDescent() / 1000; fontMetrics.put(font.getName(), new FontMetrics(base + ascent - descent, ascent, descent)); }
public static PdfBoxRawPDFontMetrics fromPdfBox(PDFont font, PDFontDescriptor descriptor) throws IOException { return new PdfBoxRawPDFontMetrics( font.getBoundingBox().getUpperRightY(), // Ascent -font.getBoundingBox().getLowerLeftY(), // Descent -descriptor.getFontBoundingBox().getUpperRightY() / 3f, // Strikethrough offset 100f, // FIXME: Strikethrough thickness -descriptor.getDescent(), // Underline position 50f); // FIXME: Underline thickness }
public static PdfBoxRawPDFontMetrics fromPdfBox(PDFont font, PDFontDescriptor descriptor) throws IOException { return new PdfBoxRawPDFontMetrics( font.getBoundingBox().getUpperRightY(), // Ascent -font.getBoundingBox().getLowerLeftY(), // Descent -descriptor.getFontBoundingBox().getUpperRightY() / 3f, // Strikethrough offset 100f, // FIXME: Strikethrough thickness -descriptor.getDescent(), // Underline position 50f); // FIXME: Underline thickness }
if (retval > 0) retval -= desc.getDescent();
if (retval > 0) retval -= desc.getDescent();
-font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0)
-font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0)
float fontBoundingBoxAtSize = font.getBoundingBox().getHeight() * fontScaleY; float fontCapAtSize = font.getFontDescriptor().getCapHeight() * fontScaleY; float fontDescentAtSize = font.getFontDescriptor().getDescent() * fontScaleY;
float fontBoundingBoxAtSize = font.getBoundingBox().getHeight() * fontScaleY; float fontCapAtSize = font.getFontDescriptor().getCapHeight() * fontScaleY; float fontDescentAtSize = font.getFontDescriptor().getDescent() * fontScaleY;