Example usage for org.apache.pdfbox.util Matrix setValue

List of usage examples for org.apache.pdfbox.util Matrix setValue

Introduction

In this page you can find the example usage for org.apache.pdfbox.util Matrix setValue.

Prototype

public void setValue(int row, int column, float value) 

Source Link

Document

This will set a value at a position.

Usage

From source file:org.xmlcml.pdf2svg.PDFPage2SVGConverter.java

License:Apache License

private void captureAndIndexGlyphVector() {
    String key = charname;/*w  w w.j av a 2 s.  c o m*/
    if (key == null) {
        key = "" + charCode;
    }
    String pathString = amiFont.getPathStringByCharnameMap().get(key);
    LOG.trace("charname: " + charname + " path: " + pathString);
    if (pathString == null) {
        ensurePageSize();
        PDFGraphics2D graphics = new PDFGraphics2D(amiFont);
        Matrix textPos = textPosition.getTextPos().copy();
        float x = textPos.getXPosition();
        // the 0,0-reference has to be moved from the lower left (PDF) to
        // the upper left (AWT-graphics)
        float y = pageSize.height - textPos.getYPosition();
        // Set translation to 0,0. We only need the scaling and shearing
        textPos.setValue(2, 0, 0);
        textPos.setValue(2, 1, 0);
        // because of the moved 0,0-reference, we have to shear in the
        // opposite direction
        textPos.setValue(0, 1, (-1) * textPos.getValue(0, 1));
        textPos.setValue(1, 0, (-1) * textPos.getValue(1, 0));
        AffineTransform at = textPos.createAffineTransform();
        PDMatrix fontMatrix = pdFont.getFontMatrix();
        // matrix is r00 r01 r10 r11 t0 t1
        double r00 = fontMatrix.getValue(0, 0) * 1000f;
        double r11 = fontMatrix.getValue(1, 1) * 1000f;
        LOG.trace("scales: " + r00 + "/" + r11);
        at.scale(r00, r11);
        // TODO setClip() is a massive performance hot spot. Investigate
        // optimization possibilities
        if (graphicsState == null) {
            LOG.debug("NULL graphics state");
            //            return;
        } else {
            graphics.setClip(graphicsState.getCurrentClippingPath());
        }
        // the fontSize is no longer needed as it is already part of the
        // transformation
        // we should remove it from the parameter list in the long run
        try {
            pdFont.drawString(textPosition.getCharacter(), textPosition.getCodePoints(), graphics, 1, at, x, y);
        } catch (IOException e) {
            throw new RuntimeException("font.drawString", e);
        }
        pathString = graphics.getCurrentPathString();
        LOG.trace(charname + ": created " + pathString);
        amiFont.getPathStringByCharnameMap().put(key, pathString);
    }
    LOG.trace("pathString: " + pathString);
}