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