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);
}
}
}
Aggregations