@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); angle = (angle + 360) % 360; angles.add(angle); } }
@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); angle = (angle + 360) % 360; angles.add(angle); } }
@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); if (angle == 0) { super.processTextPosition(text); } } }
@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); if (angle == 0) { super.processTextPosition(text); } } }
@Override protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement) throws IOException { AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); // create cache if it does not exist PDVectorFont vectorFont = ((PDVectorFont)font); GlyphCache cache = glyphCaches.get(font); if (cache == null) { cache = new GlyphCache(vectorFont); glyphCaches.put(font, cache); } GeneralPath path = cache.getPathForCharacterCode(code); drawGlyph(path, font, code, displacement, at); }
float yScalingFactor = FONTSCALE * font.getFontMatrix().getScaleY(); float xScalingFactor = FONTSCALE * font.getFontMatrix().getScaleX(); float width = font.getStringWidth(value) * font.getFontMatrix().getScaleX(); float widthBasedFontSize = contentRect.getWidth() / width * xScalingFactor; -font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0) height = font.getBoundingBox().getHeight() * font.getFontMatrix().getScaleY();
at.concatenate(font.getFontMatrix().createAffineTransform());
at.concatenate(font.getFontMatrix().createAffineTransform());
at.concatenate(font.getFontMatrix().createAffineTransform());
at.concatenate(font.getFontMatrix().createAffineTransform()); if (font instanceof PDType3Font)
if (font instanceof PDType3Font) height = font.getFontMatrix().transformPoint(0, glyphHeight).y; if (font instanceof PDType3Font) glyphSpaceToTextSpaceFactor = font.getFontMatrix().getScaleX();
@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); angle = (angle + 360) % 360; angles.add(angle); } }
@Override protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement) throws IOException { AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); Glyph2D glyph2D = createGlyph2D(font); drawGlyph2D(glyph2D, font, code, displacement, at); }
@Override protected void processTextPosition(TextPosition text) { Matrix m = text.getTextMatrix(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY()))); if (angle == 0) { super.processTextPosition(text); } } }
@Override protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement) throws IOException { AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); // create cache if it does not exist PDVectorFont vectorFont = ((PDVectorFont)font); GlyphCache cache = glyphCaches.get(font); if (cache == null) { cache = new GlyphCache(vectorFont); glyphCaches.put(font, cache); } GeneralPath path = cache.getPathForCharacterCode(code); drawGlyph(path, font, code, displacement, at); }
/** * Create the transform for rendering items onto the page. * <p> * This applies a translation and a scale of (-1,1) so that the origin is top left not bottom * left, and applies rotation if the page is declared rotated. * </p> * * @param matrix * the current PDF transformational matrix * @param page * the page * @param font * an optional font (if present, the matrix is concatenated at the right point) * @return an {@link AffineTransform} for the current rendering matrices. */ public static AffineTransform createTransform(Matrix matrix, PDPage page, Optional<PDFont> font) { AffineTransform at = createPageTranslationTransform(page); at.concatenate(matrix.createAffineTransform()); if (font.isPresent()) { at.concatenate(font.get().getFontMatrix().createAffineTransform()); } if (page.getRotation() != 0) { AffineTransform transform = createPageRotationTransform(page); transform.concatenate(at); at = transform; } return at; }
Shape calculateFontBounds(TextPosition text) throws IOException { // glyph space -> user space // note: text.getTextMatrix() is *not* the Text Matrix, it's the Text Rendering Matrix AffineTransform at = text.getTextMatrix().createAffineTransform(); // show rectangle with the real vertical bounds, based on the font bounding box y values // usually, the height is identical to what you see when marking text in Adobe Reader PDFont font = text.getFont(); BoundingBox bbox = font.getBoundingBox(); // advance width, bbox height (glyph space) float xadvance = font.getWidth(text.getCharacterCodes()[0]); // todo: should iterate all chars Rectangle2D.Float rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), xadvance, bbox.getHeight()); if (font instanceof PDType3Font) { // bbox and font matrix are unscaled at.concatenate(font.getFontMatrix().createAffineTransform()); } else { // bbox and font matrix are already scaled to 1000 at.scale(1/1000f, 1/1000f); } Shape s = at.createTransformedShape(rect); s = flipAT.createTransformedShape(s); s = rotateAT.createTransformedShape(s); return s; }
float yScalingFactor = FONTSCALE * font.getFontMatrix().getScaleY(); float xScalingFactor = FONTSCALE * font.getFontMatrix().getScaleX(); float width = font.getStringWidth(value) * font.getFontMatrix().getScaleX(); float widthBasedFontSize = contentRect.getWidth() / width * xScalingFactor; -font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0) height = font.getBoundingBox().getHeight() * font.getFontMatrix().getScaleY();
float yScalingFactor = FONTSCALE * font.getFontMatrix().getScaleY(); float xScalingFactor = FONTSCALE * font.getFontMatrix().getScaleX(); float width = font.getStringWidth(value) * font.getFontMatrix().getScaleX(); float widthBasedFontSize = contentRect.getWidth() / width * xScalingFactor; -font.getFontDescriptor().getDescent()) * font.getFontMatrix().getScaleY(); if (height <= 0) height = font.getBoundingBox().getHeight() * font.getFontMatrix().getScaleY();
at.concatenate(font.getFontMatrix().createAffineTransform());