Example usage for java.awt.geom RectangularShape getMinX

List of usage examples for java.awt.geom RectangularShape getMinX

Introduction

In this page you can find the example usage for java.awt.geom RectangularShape getMinX.

Prototype

public double getMinX() 

Source Link

Document

Returns the smallest X coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:org.docx4j.fonts.fop.fonts.type1.Type1FontLoader.java

private void handleMetrics(AFMFile afm, PFMFile pfm) {
    //Basic metrics
    if (afm != null) {
        if (afm.getCapHeight() != null) {
            returnFont.setCapHeight(afm.getCapHeight().intValue());
        }/*from w w  w  .j  ava  2  s .  c o m*/
        if (afm.getXHeight() != null) {
            returnFont.setXHeight(afm.getXHeight().intValue());
        }
        if (afm.getAscender() != null) {
            returnFont.setAscender(afm.getAscender().intValue());
        }
        if (afm.getDescender() != null) {
            returnFont.setDescender(afm.getDescender().intValue());
        }

        returnFont.setFontBBox(afm.getFontBBoxAsIntArray());
        if (afm.getStdVW() != null) {
            returnFont.setStemV(afm.getStdVW().intValue());
        } else {
            returnFont.setStemV(80); //Arbitrary value
        }
        returnFont.setItalicAngle((int) afm.getWritingDirectionMetrics(0).getItalicAngle());
    } else {
        returnFont.setFontBBox(pfm.getFontBBox());
        returnFont.setStemV(pfm.getStemV());
        returnFont.setItalicAngle(pfm.getItalicAngle());
    }
    if (pfm != null) {
        //Sometimes the PFM has these metrics while the AFM doesn't (ex. Symbol)
        if (returnFont.getCapHeight() == 0) {
            returnFont.setCapHeight(pfm.getCapHeight());
        }
        if (returnFont.getXHeight(1) == 0) {
            returnFont.setXHeight(pfm.getXHeight());
        }
        if (returnFont.getAscender() == 0) {
            returnFont.setAscender(pfm.getLowerCaseAscent());
        }
        if (returnFont.getDescender() == 0) {
            returnFont.setDescender(pfm.getLowerCaseDescent());
        }
    }

    //Fallbacks when some crucial font metrics aren't available
    //(the following are all optional in AFM, but FontBBox is always available)
    if (returnFont.getXHeight(1) == 0) {
        int xHeight = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("x");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    xHeight = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (xHeight == 0) {
            xHeight = Math.round(returnFont.getFontBBox()[3] * 0.6f);
        }
        returnFont.setXHeight(xHeight);
    }
    if (returnFont.getAscender() == 0) {
        int asc = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("d");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    asc = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (asc == 0) {
            asc = Math.round(returnFont.getFontBBox()[3] * 0.9f);
        }
        returnFont.setAscender(asc);
    }
    if (returnFont.getDescender() == 0) {
        int desc = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("p");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    desc = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (desc == 0) {
            desc = returnFont.getFontBBox()[1];
        }
        returnFont.setDescender(desc);
    }
    if (returnFont.getCapHeight() == 0) {
        returnFont.setCapHeight(returnFont.getAscender());
    }

    if (afm != null) {
        String charSet = afm.getCharacterSet();
        int flags = 0;
        if ("Special".equals(charSet)) {
            flags |= 4; //bit 3: Symbolic
        } else {
            if (singleFont.getEncoding().mapChar('A') == 'A') {
                //High likelyhood that the font is non-symbolic
                flags |= 32; //bit 6: Nonsymbolic
            } else {
                flags |= 4; //bit 3: Symbolic
            }
        }
        if (afm.getWritingDirectionMetrics(0).isFixedPitch()) {
            flags |= 1; //bit 1: FixedPitch
        }
        if (afm.getWritingDirectionMetrics(0).getItalicAngle() != 0.0) {
            flags |= 64; //bit 7: Italic
        }
        returnFont.setFlags(flags);

        returnFont.setFirstChar(afm.getFirstChar());
        returnFont.setLastChar(afm.getLastChar());
        Iterator iter = afm.getCharMetrics().iterator();
        while (iter.hasNext()) {
            AFMCharMetrics chm = (AFMCharMetrics) iter.next();
            if (chm.hasCharCode()) {
                singleFont.setWidth(chm.getCharCode(), (int) Math.round(chm.getWidthX()));
            }
        }
        if (useKerning) {
            returnFont.replaceKerningMap(afm.createXKerningMapEncoded());
        }
    } else {
        returnFont.setFlags(pfm.getFlags());
        returnFont.setFirstChar(pfm.getFirstChar());
        returnFont.setLastChar(pfm.getLastChar());
        for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
            singleFont.setWidth(i, pfm.getCharWidth(i));
        }
        if (useKerning) {
            returnFont.replaceKerningMap(pfm.getKerning());
        }
    }
}

From source file:org.squidy.designer.zoom.ActionShape.java

@Override
protected void paintShapeZoomedIn(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();
    RectangularShape r = (RectangularShape) getZoomedOutShape();
    if (r instanceof RoundRectangle2D) {

        // int width = (int)(r.getMaxX()-r.getMinX());
        // int height = (int)(r.getMaxY()-r.getMinY());
        // BufferedImage shadeStarted = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // BufferedImage shadeStopped = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // BufferedImage shadeFailure = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // shadeStarted.getGraphics().setColor(COLOR_STARTED);
        // shadeStopped.getGraphics().setColor(COLOR_STOPPED);
        // shadeFailure.getGraphics().setColor(COLOR_FAILURE);
        // shadeStarted.getGraphics().fillRect(0, 0, width, height);
        // shadeStopped.getGraphics().fillRect(0, 0, width, height);
        // shadeFailure.getGraphics().fillRect(0, 0, width, height);

        // g.setStroke(STROKE_ZOOMED_IN);
        g.setStroke(StrokeUtils.getBasicStroke(7f));

        g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED);

        if (polygonRendering) {

            if (isRenderPrimitiveRect()) {
                if (!isHierarchicalZoomInProgress()) {

                    Polygon shadeHorizontal = new Polygon();
                    Polygon shadeVertical = new Polygon();

                    double shift = 1;
                    shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    Rectangle bounds = shapeZoomedIn.getBounds();
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shift = 5;// w  ww.  j  a v  a 2s .co m
                    shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    bounds = shapeZoomedIn.getBounds();
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    g.fillPolygon(shadeHorizontal);
                    g.fillPolygon(shadeVertical);
                }

            } else {
                g.draw(shapeZoomedIn);
            }

        } else {

            for (double shift = 6.; shift >= 1.; shift -= 1.) {
                shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                        r.getMaxY() + shift);
                if (isRenderPrimitiveRect()) {
                    if (!isHierarchicalZoomInProgress()) {
                        Rectangle bounds = shapeZoomedIn.getBounds();
                        // g.drawImage(shadeStarted,null,bounds.x,
                        // bounds.y);
                        // g.fillRect(bounds.x, bounds.y, bounds.width,
                        // bounds.height);
                        g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3,
                                bounds.y + bounds.height);
                        g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width,
                                bounds.y + bounds.height - 3);
                    }
                } else {
                    g.draw(shapeZoomedIn);
                }
            }

        }

    }
    super.paintShapeZoomedIn(paintContext);
}

From source file:org.squidy.designer.zoom.ActionShape.java

@Override
protected void paintShapeZoomedOut(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();
    RectangularShape r = (RectangularShape) getZoomedOutShape();
    if (r instanceof RoundRectangle2D) {
        // g.setStroke(STROKE_ZOOMED_OUT);
        g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED);
        g.setStroke(StrokeUtils.getBasicStroke(20f));

        if (polygonRendering) {

            if (isRenderPrimitiveRect()) {
                if (!isHierarchicalZoomInProgress()) {

                    Polygon shadeHorizontal = new Polygon();
                    Polygon shadeVertical = new Polygon();

                    double shift = 1;
                    shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    Rectangle bounds = shapeZoomedOut.getBounds();
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shift = 30;// w w w.  ja  va  2  s .  c o  m
                    shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    bounds = shapeZoomedOut.getBounds();
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    g.fillPolygon(shadeHorizontal);
                    g.fillPolygon(shadeVertical);
                }

            } else {
                g.draw(shapeZoomedOut);
            }

        } else {

            for (double shift = 30.; shift >= 1.; shift -= 5.) {
                shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                        r.getMaxY() + shift);
                if (isRenderPrimitiveRect()) {
                    if (!isHierarchicalZoomInProgress()) {
                        Rectangle bounds = shapeZoomedOut.getBounds();
                        // g.fillRect(bounds.x, bounds.y, bounds.width,
                        // bounds.height);
                        g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3,
                                bounds.y + bounds.height);
                        g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width,
                                bounds.y + bounds.height - 3);
                    }
                } else {
                    g.draw(shapeZoomedOut);
                }
            }
        }
    }
    super.paintShapeZoomedOut(paintContext);
}