Search in sources :

Example 6 with RenderingMode

use of org.apache.pdfbox.pdmodel.graphics.state.RenderingMode in project pdfbox by apache.

the class PageDrawer method drawGlyph.

/**
 * Renders a glyph.
 *
 * @param path the GeneralPath for the glyph
 * @param font the font
 * @param code character code
 * @param displacement the glyph's displacement (advance)
 * @param at the transformation
 * @throws IOException if something went wrong
 */
private void drawGlyph(GeneralPath path, PDFont font, int code, Vector displacement, AffineTransform at) throws IOException {
    PDGraphicsState state = getGraphicsState();
    RenderingMode renderingMode = state.getTextState().getRenderingMode();
    if (path != null) {
        // TODO: How should vertical fonts be handled?
        if (!font.isEmbedded() && !font.isVertical() && !font.isStandard14() && font.hasExplicitWidth(code)) {
            float fontWidth = font.getWidthFromFont(code);
            if (// ignore spaces
            fontWidth > 0 && Math.abs(fontWidth - displacement.getX() * 1000) > 0.0001) {
                float pdfWidth = displacement.getX() * 1000;
                at.scale(pdfWidth / fontWidth, 1);
            }
        }
        // render glyph
        Shape glyph = at.createTransformedShape(path);
        if (renderingMode.isFill()) {
            graphics.setComposite(state.getNonStrokingJavaComposite());
            graphics.setPaint(getNonStrokingPaint());
            setClip();
            graphics.fill(glyph);
        }
        if (renderingMode.isStroke()) {
            graphics.setComposite(state.getStrokingJavaComposite());
            graphics.setPaint(getStrokingPaint());
            graphics.setStroke(getStroke());
            setClip();
            graphics.draw(glyph);
        }
        if (renderingMode.isClip()) {
            textClippings.add(glyph);
        }
    }
}
Also used : RenderingMode(org.apache.pdfbox.pdmodel.graphics.state.RenderingMode) Shape(java.awt.Shape) PDGraphicsState(org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState)

Aggregations

RenderingMode (org.apache.pdfbox.pdmodel.graphics.state.RenderingMode)6 Shape (java.awt.Shape)2 PDGraphicsState (org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState)2 GeneralPath (java.awt.geom.GeneralPath)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MissingOperandException (org.apache.pdfbox.contentstream.operator.MissingOperandException)1 SetTextRenderingMode (org.apache.pdfbox.contentstream.operator.text.SetTextRenderingMode)1 COSBase (org.apache.pdfbox.cos.COSBase)1 COSNumber (org.apache.pdfbox.cos.COSNumber)1 COSString (org.apache.pdfbox.cos.COSString)1 PDFont (org.apache.pdfbox.pdmodel.font.PDFont)1 PDColor (org.apache.pdfbox.pdmodel.graphics.color.PDColor)1 PDDeviceGray (org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray)1 PDTextState (org.apache.pdfbox.pdmodel.graphics.state.PDTextState)1 GlyphException (org.apache.pdfbox.preflight.font.util.GlyphException)1