1 28 package net.sf.jasperreports.engine.util; 29 30 import java.awt.font.TextAttribute ; 31 import java.text.AttributedCharacterIterator ; 32 33 34 38 public abstract class MaxFontSizeFinder 39 { 40 41 44 public static final MaxFontSizeFinder STYLED_TEXT_MAX_FONT_FINDER = 45 new MaxFontSizeFinder() 46 { 47 50 private final Float ZERO = new Float (0); 51 52 55 public int findMaxFontSize(AttributedCharacterIterator line, int defaultFontSize) 56 { 57 line.setIndex(0); 58 Float maxFontSize = ZERO; 59 int runLimit = 0; 60 61 while(runLimit < line.getEndIndex() && (runLimit = line.getRunLimit(TextAttribute.SIZE)) <= line.getEndIndex()) 62 { 63 Float size = (Float )line.getAttribute(TextAttribute.SIZE); 64 if (maxFontSize.compareTo(size) < 0) 65 { 66 maxFontSize = size; 67 } 68 line.setIndex(runLimit); 69 } 70 71 return maxFontSize.intValue(); 72 } 73 }; 74 75 76 79 public static final MaxFontSizeFinder DEFAULT_MAX_FONT_FINDER = 80 new MaxFontSizeFinder() 81 { 82 85 public int findMaxFontSize(AttributedCharacterIterator line, int defaultFontSize) 86 { 87 return defaultFontSize; 88 } 89 }; 90 91 92 95 public static MaxFontSizeFinder getInstance(boolean isStyledText) 96 { 97 if (isStyledText) 98 { 99 return MaxFontSizeFinder.STYLED_TEXT_MAX_FONT_FINDER; 100 } 101 return MaxFontSizeFinder.DEFAULT_MAX_FONT_FINDER; 102 } 103 104 105 108 public abstract int findMaxFontSize(AttributedCharacterIterator line, int defaultFontSize); 109 } 110 | Popular Tags |