retval = desc.getAscent();
float ascentAtFontSize = font.getFontDescriptor().getAscent() / FONTSCALE * fontSize; float baselineOffset = paddingEdge.getLowerLeftY() + (appearanceStream.getBBox().getHeight() - ascentAtFontSize)/2;
yTextPos = yTextPos - font.getFontDescriptor().getAscent() / FONTSCALE * fontSize;
@Override public Double getAscent() { return Double.valueOf(descriptor.getAscent()); }
private static float getAscent(PDFont font, float fontSize) { try { return (font.getFontDescriptor().getAscent() / 1000) * fontSize; } catch (Exception e) { } return 0.0f; }
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; }
/** * <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)); }
float ascentAtFontSize = font.getFontDescriptor().getAscent() / FONTSCALE * fontSize; float baselineOffset = paddingEdge.getLowerLeftY() + (appearanceStream.getBBox().getHeight() - ascentAtFontSize)/2;
float ascentAtFontSize = font.getFontDescriptor().getAscent() / FONTSCALE * fontSize; float baselineOffset = paddingEdge.getLowerLeftY() + (appearanceStream.getBBox().getHeight() - ascentAtFontSize)/2;
retval = desc.getAscent();
retval = desc.getAscent();
yTextPos = yTextPos - font.getFontDescriptor().getAscent() / FONTSCALE * fontSize;
yTextPos = yTextPos - font.getFontDescriptor().getAscent() / FONTSCALE * fontSize;