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

The following are Jave code examples for showing how to use getOutline() of the java.awt.font.TextLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: alevin-svn2   File: LayerViewer.java   Source Code and License Vote up 6 votes
@Override
public void paint(Graphics g) {
	Dimension d = vv.getSize();
	FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
	Font f = new Font("Times", Font.BOLD, 30);

	TextLayout tl = new TextLayout(str, f, frc);
	AffineTransform transform = new AffineTransform();
	transform.setToTranslation(d.width / 2, d.height / 2);
	transform.rotate(Math.toRadians(315));
	Shape shape = tl.getOutline(transform);
	g.translate(-shape.getBounds().width / 2,
			shape.getBounds().height / 2);
	g.setColor(Color.lightGray);
	((Graphics2D) g).draw(shape);
}
 
Example 2
Project: hearthstone   File: Custo.java   Source Code and License Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    atualizar();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(FONT);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
    g2.setPaint(textColor);
    AffineTransform at = AffineTransform.getTranslateInstance(20, 30);
    Shape outline = textLayout.getOutline(at);
    g2.fill(outline);
    g2.setPaint(BLACK);
    g2.draw(outline);
}
 
Example 3
Project: hearthstone   File: TextoComBorda.java   Source Code and License Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    //super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(font);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(text, font, frc);
    g2.setPaint(color);
    g2.setStroke(new BasicStroke(((float) font.getSize()) * (font.getStyle() == Font.BOLD ? 0.05f : 0.025f), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    AffineTransform at = AffineTransform.getTranslateInstance(5, font.getSize());
    Shape outline = textLayout.getOutline(at);
    g2.fill(outline);
    g2.setPaint(border);
    g2.draw(outline);
    g2.dispose();
    setSize(getFontMetrics(font).stringWidth(text) + 10, font.getSize() + 5);
    setPreferredSize(getSize());
}
 
Example 4
Project: OpenJSharp   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
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 5
Project: OpenJSharp   File: OutlineTextRenderer.java   Source Code and License Vote up 5 votes
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
Project: OpenJSharp   File: PathGraphics.java   Source Code and License Vote up 5 votes
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 7
Project: hearthstone   File: JLabelAtributos.java   Source Code and License Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    atualizar();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(FONT);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
    g2.setPaint(textColor);
    Shape outline = textLayout.getOutline(AffineTransform.getTranslateInstance(value < 10 ? 20 : 10, 30));
    g2.fill(outline);
    g2.setPaint(BLACK);
    g2.draw(outline);
}
 
Example 8
Project: hearthstone   File: JLabelAtributos.java   Source Code and License Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    atualizar();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(FONT);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
    g2.setPaint(textColor);
    Shape outline = textLayout.getOutline(AffineTransform.getTranslateInstance(value < 10 ? 20 : type == SHIELD ? 10 : 14, 30));
    g2.fill(outline);
    g2.setPaint(BLACK);
    g2.draw(outline);
}
 
Example 9
Project: jdk8u-jdk   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
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
Project: jdk8u-jdk   File: OutlineTextRenderer.java   Source Code and License Vote up 5 votes
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 11
Project: jdk8u-jdk   File: PathGraphics.java   Source Code and License Vote up 5 votes
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
Project: openjdk-jdk10   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
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
Project: openjdk-jdk10   File: OutlineTextRenderer.java   Source Code and License Vote up 5 votes
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 14
Project: openjdk-jdk10   File: PathGraphics.java   Source Code and License Vote up 5 votes
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);
}