Java Code Examples for sun.font.FontUtilities#isComplexText()

The following examples show how to use sun.font.FontUtilities#isComplexText() . 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: WPathGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private boolean strNeedsTextLayout(String str, Font font) {
    char[] chars = str.toCharArray();
    boolean isComplex = FontUtilities.isComplexText(chars, 0, chars.length);
    if (!isComplex) {
        return false;
    } else if (!useGDITextLayout) {
        return true;
    } else {
        if (preferGDITextLayout ||
            (isXP() && FontUtilities.textLayoutIsCompatible(font))) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 2
Source File: WPathGraphics.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private boolean strNeedsTextLayout(String str, Font font) {
    char[] chars = str.toCharArray();
    boolean isComplex = FontUtilities.isComplexText(chars, 0, chars.length);
    if (!isComplex) {
        return false;
    } else if (!useGDITextLayout) {
        return true;
    } else {
        if (preferGDITextLayout ||
            (isXP() && FontUtilities.textLayoutIsCompatible(font))) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 3
Source File: WPathGraphics.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean strNeedsTextLayout(String str, Font font) {
    char[] chars = str.toCharArray();
    boolean isComplex = FontUtilities.isComplexText(chars, 0, chars.length);
    if (!isComplex) {
        return false;
    } else if (!useGDITextLayout) {
        return true;
    } else {
        if (preferGDITextLayout ||
            (isXP() && FontUtilities.textLayoutIsCompatible(font))) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 4
Source File: Font.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 5
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 6
Source File: Font.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 7
Source File: Font.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified {@code FontRenderContext}.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * specified array of characters in the specified
 * {@code FontRenderContext}.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than zero, or {@code limit} is greater than the
 *         length of {@code chars}, or {@code beginIndex}
 *         is greater than {@code limit}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc);
        return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex);
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 8
Source File: Font.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 9
Source File: Font.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example 10
Source File: WPathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     double scaleFactorX, double scaleFactorY,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
           AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 11
Source File: WPathGraphics.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     AffineTransform deviceTransform,
                     double scaleFactorX,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
          new AffineTransform(deviceTransform);
        advanceTransform.rotate(rotation*Math.PI/1800.0);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 12
Source File: WPathGraphics.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     AffineTransform deviceTransform,
                     double scaleFactorX,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
          new AffineTransform(deviceTransform);
        advanceTransform.rotate(rotation*Math.PI/1800.0);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 13
Source File: WPathGraphics.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     double scaleFactorX, double scaleFactorY,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
           AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 14
Source File: WPathGraphics.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     double scaleFactorX, double scaleFactorY,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
           AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 15
Source File: WPathGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     double scaleFactorX, double scaleFactorY,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
           AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
Example 16
Source File: SwingUtilities2.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * checks whether TextLayout is required to handle characters.
 *
 * @param text characters to be tested
 * @param start start
 * @param limit limit
 * @return <tt>true</tt>  if TextLayout is required
 *         <tt>false</tt> if TextLayout is not required
 */
public static final boolean isComplexLayout(char[] text, int start, int limit) {
    return FontUtilities.isComplexText(text, start, limit);
}
 
Example 17
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * checks whether TextLayout is required to handle characters.
 *
 * @param text characters to be tested
 * @param start start
 * @param limit limit
 * @return {@code true}  if TextLayout is required
 *         {@code false} if TextLayout is not required
 */
public static final boolean isComplexLayout(char[] text, int start, int limit) {
    return FontUtilities.isComplexText(text, start, limit);
}
 
Example 18
Source File: SwingUtilities2.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * checks whether TextLayout is required to handle characters.
 *
 * @param text characters to be tested
 * @param start start
 * @param limit limit
 * @return <tt>true</tt>  if TextLayout is required
 *         <tt>false</tt> if TextLayout is not required
 */
public static final boolean isComplexLayout(char[] text, int start, int limit) {
    return FontUtilities.isComplexText(text, start, limit);
}
 
Example 19
Source File: SwingUtilities2.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * checks whether TextLayout is required to handle characters.
 *
 * @param text characters to be tested
 * @param start start
 * @param limit limit
 * @return <tt>true</tt>  if TextLayout is required
 *         <tt>false</tt> if TextLayout is not required
 */
public static final boolean isComplexLayout(char[] text, int start, int limit) {
    return FontUtilities.isComplexText(text, start, limit);
}
 
Example 20
Source File: SwingUtilities2.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * checks whether TextLayout is required to handle characters.
 *
 * @param text characters to be tested
 * @param start start
 * @param limit limit
 * @return <tt>true</tt>  if TextLayout is required
 *         <tt>false</tt> if TextLayout is not required
 */
public static final boolean isComplexLayout(char[] text, int start, int limit) {
    return FontUtilities.isComplexText(text, start, limit);
}