1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.Font ; 22 import java.awt.Graphics2D ; 23 import java.awt.font.TextAttribute ; 24 import java.text.AttributedString ; 25 26 27 35 public class AttributedCharacterIterator implements Painter { 36 public void paint(Graphics2D g) { 37 String fontName = "Arial"; 38 int fontSize = 15; 39 40 String text = "Attributed Strings are fun !"; 41 AttributedString styledText = new AttributedString (text); 42 43 Font font = new Font (fontName, Font.PLAIN, fontSize); 47 styledText.addAttribute(TextAttribute.FAMILY, font.getFamily()); 48 styledText.addAttribute(TextAttribute.SIZE, new Float (font.getSize())); 49 styledText.addAttribute(TextAttribute.FOREGROUND, Color.black); 50 51 55 styledText.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, 0, 10); 57 58 61 styledText.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 23, 28); 63 66 110 111 115 styledText.addAttribute(TextAttribute.FOREGROUND, new Color (128, 0, 0), 0, 10); 117 118 styledText.addAttribute(TextAttribute.FOREGROUND, new Color (70, 107, 132), 11, 18); 120 121 styledText.addAttribute(TextAttribute.FOREGROUND, new Color (236, 214, 70), 23, 28); 123 styledText.addAttribute(TextAttribute.BACKGROUND, new Color (70, 107, 132), 23, 28); 124 125 java.text.AttributedCharacterIterator iter = styledText.getIterator(); 126 133 g.drawString(iter, 10, 100); 134 } 135 } 136 | Popular Tags |