List of usage examples for java.awt.font TextLayout draw
public void draw(Graphics2D g2, float x, float y)
From source file:Main.java
private static BufferedImage renderRotatedObject(Object src, double angle, int width, int height, double tx, double ty) { BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) dest.getGraphics(); g2d.setColor(Color.black);/*from ww w .ja v a 2 s . c om*/ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform at = AffineTransform.getRotateInstance(angle); at.translate(tx, ty); g2d.setTransform(at); if (src instanceof TextLayout) { TextLayout tl = (TextLayout) src; tl.draw(g2d, 0, tl.getAscent()); } else if (src instanceof Image) { g2d.drawImage((Image) src, 0, 0, null); } g2d.dispose(); return dest; }
From source file:TextLayoutOne.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "Java Source and Support."; Font font = new Font("Serif", Font.PLAIN, 32); TextLayout textLayout = new TextLayout(s, font, g2.getFontRenderContext()); textLayout.draw(g2, 40, 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "www.java2s.com"; Font font = new Font("Serif", Font.PLAIN, 32); TextLayout textLayout = new TextLayout(s, font, g2.getFontRenderContext()); textLayout.draw(g2, 40, 80); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 30), 1, 2); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, 2, 3); TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, 10, 20); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2D;//from w w w . java 2s. co m g2D = (Graphics2D) g; FontRenderContext frc = g2D.getFontRenderContext(); Font font1 = new Font("Courier", Font.BOLD, 24); String str1 = new String("Java"); TextLayout tl = new TextLayout(str1, font1, frc); g2D.setColor(Color.gray); tl.draw(g2D, 70, 150); }
From source file:BasicShapes.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; int x = 10, y = 10, start = 2, end = 4; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 1), start, end); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, start, end); // Draw mixed-style text TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, x, y); }
From source file:BasicShapes.java
License:asdf
void drawParagraph(Graphics2D g, String paragraph, float width) { LineBreakMeasurer linebreaker = new LineBreakMeasurer(new AttributedString(paragraph).getIterator(), g.getFontRenderContext());//from w w w. j a va 2 s .com float y = 0.0f; while (linebreaker.getPosition() < paragraph.length()) { TextLayout tl = linebreaker.nextLayout(width); y += tl.getAscent(); tl.draw(g, 0, y); y += tl.getDescent() + tl.getLeading(); } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2D;/*from www. j a v a 2 s . co m*/ g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); FontRenderContext frc = g2D.getFontRenderContext(); Font font1 = new Font("Courier", Font.BOLD, 24); String str1 = new String("Java"); TextLayout tl = new TextLayout(str1, font1, frc); g2D.setColor(Color.gray); tl.draw(g2D, 50, 150); }
From source file:Main.java
License:asdf
void drawParagraph(Graphics2D g, String paragraph, float width) { LineBreakMeasurer linebreaker = new LineBreakMeasurer(new AttributedString(paragraph).getIterator(), g.getFontRenderContext());/*from w w w. j a v a 2s . co m*/ int y = 0; while (linebreaker.getPosition() < paragraph.length()) { TextLayout textLayout = linebreaker.nextLayout(width); y += textLayout.getAscent(); textLayout.draw(g, 0, y); y += textLayout.getDescent() + textLayout.getLeading(); } }
From source file:LineBreakMeasurerDemo.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; attribCharIterator = attribString.getIterator(); FontRenderContext frc = new FontRenderContext(null, false, false); LineBreakMeasurer lbm = new LineBreakMeasurer(attribCharIterator, frc); int x = 10, y = 20; int w = getWidth(); float wrappingWidth = w - 15; while (lbm.getPosition() < text.length()) { TextLayout layout = lbm.nextLayout(wrappingWidth); y += layout.getAscent();/*from w w w . j a v a 2 s .c o m*/ layout.draw(g2, x, y); y += layout.getDescent() + layout.getLeading(); } }