Example usage for com.lowagie.text.pdf PdfContentByte resetRGBColorStroke

List of usage examples for com.lowagie.text.pdf PdfContentByte resetRGBColorStroke

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte resetRGBColorStroke.

Prototype


public void resetRGBColorStroke() 

Source Link

Document

Changes the current color for stroking paths to black.

Usage

From source file:net.sf.jasperreports.engine.export.PdfGlyphGraphics2D.java

License:Open Source License

@Override
public void drawGlyphVector(GlyphVector glyphVector, float x, float y) {
    Font awtFont = glyphVector.getFont();
    Map<Attribute, Object> fontAttrs = new HashMap<Attribute, Object>();
    Map<TextAttribute, ?> awtFontAttributes = awtFont.getAttributes();
    fontAttrs.putAll(awtFontAttributes);

    //the following relies on FontInfo.getFontInfo matching the face/font name
    com.lowagie.text.Font currentFont = pdfExporter.getFont(fontAttrs, locale, false);
    boolean bold = (currentFont.getStyle() & com.lowagie.text.Font.BOLD) != 0;
    boolean italic = (currentFont.getStyle() & com.lowagie.text.Font.ITALIC) != 0;

    PdfContentByte text = pdfContentByte.getDuplicate();
    text.beginText();//w w w . jav  a 2s.co  m

    float[] originalCoords = new float[] { x, y };
    float[] transformedCoors = new float[2];
    getTransform().transform(originalCoords, 0, transformedCoors, 0, 1);
    text.setTextMatrix(1, 0, italic ? ITALIC_ANGLE : 0f, 1, transformedCoors[0],
            pdfExporter.getCurrentPageFormat().getPageHeight() - transformedCoors[1]);

    double scaleX = awtFont.getTransform().getScaleX();
    double scaleY = awtFont.getTransform().getScaleY();
    double minScale = Math.min(scaleX, scaleY);
    text.setFontAndSize(currentFont.getBaseFont(), (float) (minScale * awtFont.getSize2D()));

    if (bold) {
        text.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
        text.setLineWidth(currentFont.getSize() * BOLD_STRIKE_FACTOR);
        text.setColorStroke(getColor());
    }

    text.setColorFill(getColor());
    //FIXME find a way to determine the characters that correspond to this glyph vector
    // so that we can map the font glyphs that do not directly map to a character
    text.showText(glyphVector);
    text.resetRGBColorFill();

    if (bold) {
        text.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
        text.setLineWidth(1f);
        text.resetRGBColorStroke();
    }

    text.endText();
    pdfContentByte.add(text);
}