Java Code Examples for java.awt.geom.AffineTransform#isIdentity()

The following examples show how to use java.awt.geom.AffineTransform#isIdentity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardGlyphVector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void setGlyphTransform(int ix, AffineTransform newTX) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    if (gti == null) {
        if (newTX == null || newTX.isIdentity()) {
            return;
        }
        gti = new GlyphTransformInfo(this);
    }
    gti.setGlyphTransform(ix, newTX); // sets flags
    if (gti.transformCount() == 0) {
        gti = null;
    }
}
 
Example 2
Source File: GetTypeOptimization.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void checkBug4418285() {
    AffineTransform id =
        new AffineTransform ();
    AffineTransform translate0 =
        AffineTransform.getTranslateInstance (0, 0);
    if (id.isIdentity() != translate0.isIdentity() ||
        id.getType() != translate0.getType())
    {
        numerrors++;
        if (verbose) {
            System.err.println("id=        " + id         +
                               ", isIdentity()=" +
                               id.isIdentity());
            System.err.println("translate0=" + translate0 +
                               ", isIdentity()=" +
                               translate0.isIdentity());
            System.err.println("equals="     + id.equals (translate0));
            System.err.println();
        }
    }
}
 
Example 3
Source File: StandardGlyphVector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void setGlyphTransform(int ix, AffineTransform newTX) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    if (gti == null) {
        if (newTX == null || newTX.isIdentity()) {
            return;
        }
        gti = new GlyphTransformInfo(this);
    }
    gti.setGlyphTransform(ix, newTX); // sets flags
    if (gti.transformCount() == 0) {
        gti = null;
    }
}
 
Example 4
Source File: AttributeValues.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setTransform(AffineTransform f) {
    this.transform = (f == null || f.isIdentity())
        ? DEFAULT.transform
        : new AffineTransform(f);
    updateDerivedTransforms();
    update(ETRANSFORM);
}
 
Example 5
Source File: SunGraphics2D.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Rectangle transformBounds(Rectangle rect,
                                    AffineTransform tx) {
    if (tx.isIdentity()) {
        return rect;
    }

    Shape s = transformShape(tx, rect);
    return s.getBounds();
}
 
Example 6
Source File: SunGraphics2D.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected Rectangle transformBounds(Rectangle rect,
                                    AffineTransform tx) {
    if (tx.isIdentity()) {
        return rect;
    }

    Shape s = transformShape(tx, rect);
    return s.getBounds();
}
 
Example 7
Source File: SunGraphics2D.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the given AffineTransform is an integer
 * translation.
 */
private static boolean isIntegerTranslation(AffineTransform xform) {
    if (xform.isIdentity()) {
        return true;
    }
    if (xform.getType() == AffineTransform.TYPE_TRANSLATION) {
        double tx = xform.getTranslateX();
        double ty = xform.getTranslateY();
        return (tx == (int)tx && ty == (int)ty);
    }
    return false;
}
 
Example 8
Source File: AreaTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Collection<Displayable> findLinkTargets(final AffineTransform aff) {
	if (null == aw) return super.findLinkTargets(aff);
	Area a = aw.getArea();
	if (!aff.isIdentity()) {
		a = a.createTransformedArea(aff);
	}
	return this.la.getDisplayables(Patch.class, a, true);
}
 
Example 9
Source File: SunGraphics2D.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the given AffineTransform is an integer
 * translation.
 */
private static boolean isIntegerTranslation(AffineTransform xform) {
    if (xform.isIdentity()) {
        return true;
    }
    if (xform.getType() == AffineTransform.TYPE_TRANSLATION) {
        double tx = xform.getTranslateX();
        double ty = xform.getTranslateY();
        return (tx == (int)tx && ty == (int)ty);
    }
    return false;
}
 
Example 10
Source File: AttributeValues.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setTransform(AffineTransform f) {
    this.transform = (f == null || f.isIdentity())
        ? DEFAULT.transform
        : new AffineTransform(f);
    updateDerivedTransforms();
    update(ETRANSFORM);
}
 
Example 11
Source File: SunGraphics2D.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected Rectangle transformBounds(Rectangle rect,
                                    AffineTransform tx) {
    if (tx.isIdentity()) {
        return rect;
    }

    Shape s = transformShape(tx, rect);
    return s.getBounds();
}
 
Example 12
Source File: SunGraphics2D.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected Rectangle transformBounds(Rectangle rect,
                                    AffineTransform tx) {
    if (tx.isIdentity()) {
        return rect;
    }

    Shape s = transformShape(tx, rect);
    return s.getBounds();
}
 
Example 13
Source File: SunGraphics2D.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the given AffineTransform is an integer
 * translation.
 */
private static boolean isIntegerTranslation(AffineTransform xform) {
    if (xform.isIdentity()) {
        return true;
    }
    if (xform.getType() == AffineTransform.TYPE_TRANSLATION) {
        double tx = xform.getTranslateX();
        double ty = xform.getTranslateY();
        return (tx == (int)tx && ty == (int)ty);
    }
    return false;
}
 
Example 14
Source File: LayerUtility.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Places the given form over the existing content of the indicated page (like an overlay).
 * The form is enveloped in a marked content section to indicate that it's part of an
 * optional content group (OCG), here used as a layer. This optional group is returned and
 * can be enabled and disabled through methods on {@link PDOptionalContentProperties}.
 * <p>
 * You may want to call {@link #wrapInSaveRestore(PDPage) wrapInSaveRestore(PDPage)} before calling this method to make
 * sure that the graphics state is reset.
 *
 * @param targetPage the target page
 * @param form the form to place
 * @param transform the transformation matrix that controls the placement of your form. You'll
 * need this if your page has a crop box different than the media box, or if these have negative
 * coordinates, or if you want to scale or adjust your form.
 * @param layerName the name for the layer/OCG to produce
 * @return the optional content group that was generated for the form usage
 * @throws IOException if an I/O error occurs
 */
public PDOptionalContentGroup appendFormAsLayer(PDPage targetPage,
        PDFormXObject form, AffineTransform transform,
        String layerName) throws IOException
{
    PDDocumentCatalog catalog = targetDoc.getDocumentCatalog();
    PDOptionalContentProperties ocprops = catalog.getOCProperties();
    if (ocprops == null)
    {
        ocprops = new PDOptionalContentProperties();
        catalog.setOCProperties(ocprops);
    }
    if (ocprops.hasGroup(layerName))
    {
        throw new IllegalArgumentException("Optional group (layer) already exists: " + layerName);
    }

    PDRectangle cropBox = targetPage.getCropBox();
    if ((cropBox.getLowerLeftX() < 0 || cropBox.getLowerLeftY() < 0) && transform.isIdentity())
    {
        // PDFBOX-4044 
        LOG.warn("Negative cropBox " + cropBox + 
                 " and identity transform may make your form invisible");
    }

    PDOptionalContentGroup layer = new PDOptionalContentGroup(layerName);
    ocprops.addGroup(layer);

    PDPageContentStream contentStream = new PDPageContentStream(
            targetDoc, targetPage, AppendMode.APPEND, !DEBUG);
    contentStream.beginMarkedContent(COSName.OC, layer);
    contentStream.saveGraphicsState();
    contentStream.transform(new Matrix(transform));
    contentStream.drawForm(form);
    contentStream.restoreGraphicsState();
    contentStream.endMarkedContent();
    contentStream.close();

    return layer;
}
 
Example 15
Source File: FontStrikeDesc.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static int getAAHintIntVal(Font2D font2D, Font font,
                                  FontRenderContext frc) {
    Object aa = frc.getAntiAliasingHint();
    if (aa == VALUE_TEXT_ANTIALIAS_OFF ||
        aa == VALUE_TEXT_ANTIALIAS_DEFAULT) {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    } else if (aa == VALUE_TEXT_ANTIALIAS_ON) {
        return INTVAL_TEXT_ANTIALIAS_ON;
    } else if (aa == VALUE_TEXT_ANTIALIAS_GASP) {
        /* FRC.isIdentity() would have been useful */
        int ptSize;
        AffineTransform tx = frc.getTransform();
        if (tx.isIdentity() && !font.isTransformed()) {
            ptSize = font.getSize();
        } else {
            /* one or both transforms is not identity */
            float size = font.getSize2D();
            if (tx.isIdentity()) {
                tx = font.getTransform();
                tx.scale(size, size);
            } else {
                tx.scale(size, size);
                if (font.isTransformed()) {
                    tx.concatenate(font.getTransform());
                }
            }
            double shearx = tx.getShearX();
            double scaley = tx.getScaleY();
            if (shearx != 0) {
                scaley = Math.sqrt(shearx * shearx + scaley * scaley);
            }
            ptSize = (int)(Math.abs(scaley)+0.5);
        }
        if (font2D.useAAForPtSize(ptSize)) {
            return INTVAL_TEXT_ANTIALIAS_ON;
        } else {
            return INTVAL_TEXT_ANTIALIAS_OFF;
        }
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_HRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_HBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_VRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_VBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_VRGB;
    } else {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    }
}
 
Example 16
Source File: FontStrikeDesc.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static int getAAHintIntVal(Font2D font2D, Font font,
                                  FontRenderContext frc) {
    Object aa = frc.getAntiAliasingHint();
    if (aa == VALUE_TEXT_ANTIALIAS_OFF ||
        aa == VALUE_TEXT_ANTIALIAS_DEFAULT) {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    } else if (aa == VALUE_TEXT_ANTIALIAS_ON) {
        return INTVAL_TEXT_ANTIALIAS_ON;
    } else if (aa == VALUE_TEXT_ANTIALIAS_GASP) {
        /* FRC.isIdentity() would have been useful */
        int ptSize;
        AffineTransform tx = frc.getTransform();
        if (tx.isIdentity() && !font.isTransformed()) {
            ptSize = font.getSize();
        } else {
            /* one or both transforms is not identity */
            float size = font.getSize2D();
            if (tx.isIdentity()) {
                tx = font.getTransform();
                tx.scale(size, size);
            } else {
                tx.scale(size, size);
                if (font.isTransformed()) {
                    tx.concatenate(font.getTransform());
                }
            }
            double shearx = tx.getShearX();
            double scaley = tx.getScaleY();
            if (shearx != 0) {
                scaley = Math.sqrt(shearx * shearx + scaley * scaley);
            }
            ptSize = (int)(Math.abs(scaley)+0.5);
        }
        if (font2D.useAAForPtSize(ptSize)) {
            return INTVAL_TEXT_ANTIALIAS_ON;
        } else {
            return INTVAL_TEXT_ANTIALIAS_OFF;
        }
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_HRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_HBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_VRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_VBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_VRGB;
    } else {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    }
}
 
Example 17
Source File: LayerUtility.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Imports a page from some PDF file as a Form XObject so it can be placed on another page
 * in the target document.
 * <p>
 * You may want to call {@link #wrapInSaveRestore(PDPage) wrapInSaveRestore(PDPage)} before invoking the Form XObject to
 * make sure that the graphics state is reset.
 * 
 * @param sourceDoc the source PDF document that contains the page to be copied
 * @param page the page in the source PDF document to be copied
 * @return a Form XObject containing the original page's content
 * @throws IOException if an I/O error occurs
 */
public PDFormXObject importPageAsForm(PDDocument sourceDoc, PDPage page) throws IOException
{
    importOcProperties(sourceDoc);

    PDStream newStream = new PDStream(targetDoc, page.getContents(), COSName.FLATE_DECODE);
    PDFormXObject form = new PDFormXObject(newStream);

    //Copy resources
    PDResources pageRes = page.getResources();
    PDResources formRes = new PDResources();
    cloner.cloneMerge(pageRes, formRes);
    form.setResources(formRes);

    //Transfer some values from page to form
    transferDict(page.getCOSObject(), form.getCOSObject(), PAGE_TO_FORM_FILTER, true);

    Matrix matrix = form.getMatrix();
    AffineTransform at = matrix.createAffineTransform();
    PDRectangle mediaBox = page.getMediaBox();
    PDRectangle cropBox = page.getCropBox();
    PDRectangle viewBox = (cropBox != null ? cropBox : mediaBox);

    //Handle the /Rotation entry on the page dict
    int rotation = page.getRotation();

    //Transform to FOP's user space
    //at.scale(1 / viewBox.getWidth(), 1 / viewBox.getHeight());
    at.translate(mediaBox.getLowerLeftX() - viewBox.getLowerLeftX(),
            mediaBox.getLowerLeftY() - viewBox.getLowerLeftY());
    switch (rotation)
    {
    case 90:
        at.scale(viewBox.getWidth() / viewBox.getHeight(), viewBox.getHeight() / viewBox.getWidth());
        at.translate(0, viewBox.getWidth());
        at.rotate(-Math.PI / 2.0);
        break;
    case 180:
        at.translate(viewBox.getWidth(), viewBox.getHeight());
        at.rotate(-Math.PI);
        break;
    case 270:
        at.scale(viewBox.getWidth() / viewBox.getHeight(), viewBox.getHeight() / viewBox.getWidth());
        at.translate(viewBox.getHeight(), 0);
        at.rotate(-Math.PI * 1.5);
        break;
    default:
        //no additional transformations necessary
    }
    //Compensate for Crop Boxes not starting at 0,0
    at.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY());
    if (!at.isIdentity())
    {
        form.setMatrix(at);
    }

    BoundingBox bbox = new BoundingBox();
    bbox.setLowerLeftX(viewBox.getLowerLeftX());
    bbox.setLowerLeftY(viewBox.getLowerLeftY());
    bbox.setUpperRightX(viewBox.getUpperRightX());
    bbox.setUpperRightY(viewBox.getUpperRightY());
    form.setBBox(new PDRectangle(bbox));

    return form;
}
 
Example 18
Source File: FontRenderContext.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Constructs a <code>FontRenderContext</code> object from an
 * optional {@link AffineTransform} and two <code>boolean</code>
 * values that determine if the newly constructed object has
 * anti-aliasing or fractional metrics.
 * In each case the boolean values <CODE>true</CODE> and <CODE>false</CODE>
 * correspond to the rendering hint values <CODE>ON</CODE> and
 * <CODE>OFF</CODE> respectively.
 * <p>
 * To specify other hint values, use the constructor which
 * specifies the rendering hint values as parameters :
 * {@link #FontRenderContext(AffineTransform, Object, Object)}.
 * @param tx the transform which is used to scale typographical points
 * to pixels in this <code>FontRenderContext</code>.  If null, an
 * identity transform is used.
 * @param isAntiAliased determines if the newly constructed object
 * has anti-aliasing.
 * @param usesFractionalMetrics determines if the newly constructed
 * object has fractional metrics.
 */
public FontRenderContext(AffineTransform tx,
                        boolean isAntiAliased,
                        boolean usesFractionalMetrics) {
    if (tx != null && !tx.isIdentity()) {
        this.tx = new AffineTransform(tx);
    }
    if (isAntiAliased) {
        aaHintValue = VALUE_TEXT_ANTIALIAS_ON;
    } else {
        aaHintValue = VALUE_TEXT_ANTIALIAS_OFF;
    }
    if (usesFractionalMetrics) {
        fmHintValue = VALUE_FRACTIONALMETRICS_ON;
    } else {
        fmHintValue = VALUE_FRACTIONALMETRICS_OFF;
    }
}
 
Example 19
Source File: TextTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void init(TestEnvironment env, Result result) {
    // graphics
    graphics = env.getGraphics();

    // text
    String sname = (String)env.getModifier(tscriptList);
    int slen = env.getIntValue(tlengthList);
    text = getString(sname, slen);

    // chars
    chars = text.toCharArray();

    // font
    String fname = (String)env.getModifier(fnameList);
    if ("Physical".equals(fname)) {
        fname = physicalFontNameFor(sname, slen, text);
    }
    int fstyle = env.getIntValue(fstyleList);
    float fsize = ((Float)env.getModifier(fsizeList)).floatValue();
    AffineTransform ftx = (AffineTransform)env.getModifier(ftxList);
    font = new Font(fname, fstyle, (int)fsize);
    if (hasGraphics2D) {
        if (fsize != Math.floor(fsize)) {
            font = font.deriveFont(fsize);
        }
        if (!ftx.isIdentity()) {
            font = font.deriveFont(ftx);
        }
    }

    // graphics
    if (hasGraphics2D) {
        Graphics2D g2d = (Graphics2D)graphics;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                             env.getModifier(taaList));
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                             env.isEnabled(tfmTog)
                             ? RenderingHints.VALUE_FRACTIONALMETRICS_ON
                             : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             env.isEnabled(gaaTog)
                             ? RenderingHints.VALUE_ANTIALIAS_ON
                             : RenderingHints.VALUE_ANTIALIAS_OFF);
        g2d.transform((AffineTransform)env.getModifier(gtxList));
    }

    // set result
    result.setUnits(text.length());
    result.setUnitName("char");
}
 
Example 20
Source File: TransformAttribute.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Wraps the specified transform.  The transform is cloned and a
 * reference to the clone is kept.  The original transform is unchanged.
 * If null is passed as the argument, this constructor behaves as though
 * it were the identity transform.  (Note that it is preferable to use
 * {@link #IDENTITY} in this case.)
 * @param transform the specified {@link AffineTransform} to be wrapped,
 * or null.
 */
public TransformAttribute(AffineTransform transform) {
    if (transform != null && !transform.isIdentity()) {
        this.transform = new AffineTransform(transform);
    }
}