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.RenderingHints ; 24 import java.awt.font.FontRenderContext ; 25 26 37 public class Font2 implements Painter { 38 public void paint(Graphics2D g) { 39 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 40 RenderingHints.VALUE_ANTIALIAS_ON); 41 42 g.setFont(new Font ("Arial", Font.BOLD, 12)); 44 45 Color labelColor = new Color (0x666699); 47 Color fontColor = Color.black; 48 49 java.awt.geom.AffineTransform defaultTransform = g.getTransform(); 53 Font defaultFont = new Font ("Arial", Font.BOLD, 16); 54 g.setFont(defaultFont); 55 FontRenderContext frc = g.getFontRenderContext(); 56 g.setPaint(labelColor); 57 58 g.drawString("Font size", 10, 30); 59 g.setPaint(fontColor); 60 g.translate(0, 20); 61 int fontSizes[] = { 6, 8, 10, 12, 18, 36, 48 }; 62 for(int i=0; i<fontSizes.length; i++){ 63 Font font = new Font (defaultFont.getFamily(), 64 Font.PLAIN, 65 fontSizes[i]); 66 g.setFont(font); 67 g.drawString("aA", 10, 40); 68 double width = font.createGlyphVector(frc, "aA").getVisualBounds().getWidth(); 69 g.translate(width*1.2, 0); 70 } 71 72 g.setTransform(defaultTransform); 73 g.translate(0, 60); 74 75 int fontStyles[] = { Font.PLAIN, 79 Font.BOLD, 80 Font.ITALIC, 81 Font.BOLD | Font.ITALIC }; 82 String fontStyleStrings[] = { "Plain", "Bold", "Italic", "Bold Italic" }; 83 84 g.setFont(defaultFont); 85 g.setPaint(labelColor); 86 g.drawString("Font Styles", 10, 30); 87 g.translate(0, 20); 88 g.setPaint(fontColor); 89 90 for(int i=0; i<fontStyles.length; i++){ 91 Font font = new Font (defaultFont.getFamily(), 92 fontStyles[i], 20); 93 g.setFont(font); 94 g.drawString(fontStyleStrings[i], 10, 40); 95 double width = font.createGlyphVector(frc, fontStyleStrings[i]).getVisualBounds().getWidth(); 96 g.translate(width*1.2, 0); 97 } 98 99 g.setTransform(defaultTransform); 100 g.translate(0, 120); 101 102 String fontFamilies[] = { "Arial", 106 "Times New Roman", 107 "Courier New", 108 "Verdana" }; 109 110 g.setFont(defaultFont); 111 g.setPaint(labelColor); 112 g.drawString("Font Families", 10, 30); 113 g.setPaint(fontColor); 114 115 for(int i=0; i<fontFamilies.length; i++){ 116 Font font = new Font (fontFamilies[i], Font.PLAIN, 18); 117 g.setFont(font); 118 double height = font.createGlyphVector(frc, fontFamilies[i]).getVisualBounds().getHeight(); 119 g.translate(0, height*1.4); 120 g.drawString(fontFamilies[i], 10, 40); 121 } 122 123 Font logicalFonts[] = { new Font ("dialog", Font.PLAIN, 14), 127 new Font ("dialoginput", Font.BOLD, 14), 128 new Font ("monospaced", Font.ITALIC, 14), 129 new Font ("serif", Font.PLAIN, 14), 130 new Font ("sansserif", Font.BOLD, 14)}; 131 132 g.translate(0, 70); 133 g.setFont(defaultFont); 134 g.setPaint(labelColor); 135 g.drawString("Logical Fonts", 10, 0); 136 g.setPaint(fontColor); 137 138 for(int i=0; i<logicalFonts.length; i++){ 139 Font font = logicalFonts[i]; 140 g.setFont(font); 141 double height = font.createGlyphVector(frc, font.getName()).getVisualBounds().getHeight(); 142 g.translate(0, height*1.4); 143 g.drawString(font.getName(), 10, 0); 144 } 145 } 146 } 147 | Popular Tags |