Java Code Examples for java.awt.font.TextLayout#getOutline()

The following examples show how to use java.awt.font.TextLayout#getOutline() . 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: BasicMercuryIconTrackerUI.java    From MercuryTrade with MIT License 5 votes vote down vote up
protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull) {

        if (descriptor.isTextEnable() && tracker.isStringPainted()) {
            float value = tracker.getValue() / 1000f;

            Graphics2D g2 = this.prepareAdapter(g);
            DecimalFormat decimalFormat = new DecimalFormat(descriptor.getTextFormat());
            String progressString = String.valueOf(decimalFormat.format(value));
            if (descriptor.isCustomTextEnable()) {
                progressString = String.valueOf(descriptor.getCustomText());
            }
            g2.setFont(tracker.getFont());
            Point renderLocation = getStringPlacement(g2, progressString,
                    x, y, width, height);
            g2.setColor(this.getColorByValue());
            SwingUtilities2.drawString(tracker, g2, progressString,
                    renderLocation.x, renderLocation.y);
            if (this.descriptor.getOutlineThickness() > 0) {
                FontRenderContext frc = g2.getFontRenderContext();
                TextLayout textTl = new TextLayout(progressString, tracker.getFont(), frc);
                Shape outline = textTl.getOutline(null);
                g2.translate(renderLocation.x, renderLocation.y);
                Stroke oldStroke = g2.getStroke();
                g2.setStroke(new BasicStroke(this.descriptor.getOutlineThickness()));
                Color oldColor = g2.getColor();
                g2.setColor(this.descriptor.getOutlineColor());
                g2.draw(outline);
                g2.setColor(oldColor);
                g2.setStroke(oldStroke);
            }
        }
    }
 
Example 2
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 3
Source File: PathGraphics.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}
 
Example 4
Source File: TemplatePreviewPanel.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
private void drawText(Graphics2D g2, BandElement band, FontRenderContext frc,
                      int w, int rowHeight, int titleDelta, int rowPos, String text) {

    TextLayout detailLayout = new TextLayout(text, band.getFont(), frc);
    float detailHeight = detailLayout.getAscent() + detailLayout.getDescent();
    int detailWidth = g2.getFontMetrics(band.getFont()).stringWidth(text);
    for (int i = 0; i < columns; i++) {

        int alignH = band.getHorizontalAlign();
        //System.out.println("alignH=" + alignH);
        int x0H;
        // left
        if (alignH == 2) {
            x0H = i * w / columns + 5;
            // right
        } else if (alignH == 4) {
            x0H = (i + 1) * w / columns - detailWidth - 5;
            // center
        } else {
            x0H = i * w / columns + (w / columns - detailWidth) / 2;
        }
        int y0H = titleDelta + (int) ((rowPos * rowHeight + detailHeight) / 2);

        //System.out.println("x0H=" + x0H + "  y0H=" + y0H);
        AffineTransform atH = AffineTransform.getTranslateInstance(x0H, y0H);
        Shape outlineH = detailLayout.getOutline(atH);
        g2.setColor(band.getForeground());
        g2.fill(outlineH);

    }
}
 
Example 5
Source File: OutlineTextRenderer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void drawString(SunGraphics2D g2d, String str, double x, double y) {

        if ("".equals(str)) {
            return; // TextLayout constructor throws IAE on "".
        }
        TextLayout tl = new TextLayout(str, g2d.getFont(),
                                       g2d.getFontRenderContext());
        Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));

        int textAAHint = g2d.getFontInfo().aaHint;

        int prevaaHint = - 1;
        if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
            g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
            g2d.validatePipe();
        } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
            && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
            g2d.validatePipe();
        }

        g2d.fill(s);

        if (prevaaHint != -1) {
             g2d.antialiasHint = prevaaHint;
             g2d.validatePipe();
        }
    }
 
Example 6
Source File: TextMeasureTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 7
Source File: OutlineTextRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void drawString(SunGraphics2D g2d, String str, double x, double y) {

        if ("".equals(str)) {
            return; // TextLayout constructor throws IAE on "".
        }
        TextLayout tl = new TextLayout(str, g2d.getFont(),
                                       g2d.getFontRenderContext());
        Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));

        int textAAHint = g2d.getFontInfo().aaHint;

        int prevaaHint = - 1;
        if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
            g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
            g2d.validatePipe();
        } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
            && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
            g2d.validatePipe();
        }

        g2d.fill(s);

        if (prevaaHint != -1) {
             g2d.antialiasHint = prevaaHint;
             g2d.validatePipe();
        }
    }
 
Example 8
Source File: TextMeasureTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 9
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 10
Source File: PathGraphics.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}
 
Example 11
Source File: PathGraphics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}
 
Example 12
Source File: TextMeasureTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 13
Source File: PathGraphics.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}
 
Example 14
Source File: OutlineTextRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawString(SunGraphics2D g2d, String str, double x, double y) {

        if ("".equals(str)) {
            return; // TextLayout constructor throws IAE on "".
        }
        TextLayout tl = new TextLayout(str, g2d.getFont(),
                                       g2d.getFontRenderContext());
        Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));

        int textAAHint = g2d.getFontInfo().aaHint;

        int prevaaHint = - 1;
        if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
            g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
            g2d.validatePipe();
        } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
            && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
            g2d.validatePipe();
        }

        g2d.fill(s);

        if (prevaaHint != -1) {
             g2d.antialiasHint = prevaaHint;
             g2d.validatePipe();
        }
    }
 
Example 15
Source File: TextMeasureTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    Shape s;
    do {
        s = tl.getOutline(null);
    } while (--numReps >= 0);
}
 
Example 16
Source File: PathGraphics.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}
 
Example 17
Source File: OutlineTextRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawString(SunGraphics2D g2d, String str, double x, double y) {

        if ("".equals(str)) {
            return; // TextLayout constructor throws IAE on "".
        }
        TextLayout tl = new TextLayout(str, g2d.getFont(),
                                       g2d.getFontRenderContext());
        Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));

        int textAAHint = g2d.getFontInfo().aaHint;

        int prevaaHint = - 1;
        if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
            g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
            g2d.validatePipe();
        } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
            && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
            g2d.validatePipe();
        }

        g2d.fill(s);

        if (prevaaHint != -1) {
             g2d.antialiasHint = prevaaHint;
             g2d.validatePipe();
        }
    }
 
Example 18
Source File: OutlineTextRenderer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void drawString(SunGraphics2D g2d, String str, double x, double y) {

        if ("".equals(str)) {
            return; // TextLayout constructor throws IAE on "".
        }
        TextLayout tl = new TextLayout(str, g2d.getFont(),
                                       g2d.getFontRenderContext());
        Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));

        int textAAHint = g2d.getFontInfo().aaHint;

        int prevaaHint = - 1;
        if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
            g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
            g2d.validatePipe();
        } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
            && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
            prevaaHint = g2d.antialiasHint;
            g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
            g2d.validatePipe();
        }

        g2d.fill(s);

        if (prevaaHint != -1) {
             g2d.antialiasHint = prevaaHint;
             g2d.validatePipe();
        }
    }
 
Example 19
Source File: Tachometer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public void paint(Graphics g) {
        try {
            Border border = getBorder();
            Insets insets = new Insets(0, 0, 0, 0);
            if (border != null) {
                insets = border.getBorderInsets(this);
            }
            
            int diameter = Math.min(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom)) - 4;
            VolatileImage img = createVolatileImage(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom), new ImageCapabilities(true));
            Graphics2D gr = img.createGraphics();

            gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            gr.drawOval(insets.left, insets.top, diameter, diameter);
            TextLayout textTl = new TextLayout("fERRARI", getFont(), gr.getFontRenderContext());
            AffineTransform at = new AffineTransform();
            at.translate(0, (float)getBounds().getHeight() - (insets.top + insets.bottom) - (float)textTl.getBounds().getHeight());
            at.scale(2d, 2d);
//            at.shear(1.3d, 0.8d);
            Shape textShape  = textTl.getOutline(at);
            gr.fill(textShape);
//            GlyphVector gv = getFont().createGlyphVector(gr.getFontRenderContext(), "fERRARI");
//            Rectangle bounds = gv.getPixelBounds(gr.getFontRenderContext(), 0, 0);
//            double scale = (double)(getBounds().width - (insets.left + insets.right)) / (double)bounds.width;
//            for(int i=0;i<gv.getNumGlyphs();i++) {
//                gv.setGlyphTransform(i, AffineTransform.getScaleInstance(scale, 1d));
//                gv.
//            }
//            gr.drawGlyphVector(gv, insets.left + 2, getBounds().height - (insets.top + insets.bottom) - 2 - bounds.height);
            int lineLenght = diameter / 2 - 10;
            gr.drawLine(diameter / 2, diameter / 2, diameter / 2 - getXOnArc(lineLenght, getAngle()), diameter / 2 - getYOnArc(lineLenght, getAngle()));
            gr.dispose();
            
            g.drawImage(img, insets.left, insets.top, this);
            if (border != null) {
                border.paintBorder(this, g, 0, 0, getBounds().width, getBounds().height);
            }
        } catch (AWTException e) {}
    }
 
Example 20
Source File: PathGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    TextLayout layout =
        new TextLayout(str, font, frc);
    Shape textShape =
        layout.getOutline(AffineTransform.getTranslateInstance(x, y));
    fill(textShape);
}