1 17 18 19 20 package org.apache.fop.fo.properties; 21 import org.apache.fop.fo.Constants; 22 import org.apache.fop.fo.FObj; 23 import org.apache.fop.fo.PropertyList; 24 import org.apache.fop.fo.expr.PropertyException; 25 26 30 public class FontSizePropertyMaker 31 extends LengthProperty.Maker implements Constants { 32 33 34 private static final int FONT_SIZE_NORMAL = 12000; 35 36 private static final double FONT_SIZE_GROWTH_FACTOR = 1.2; 37 38 42 public FontSizePropertyMaker(int propId) { 43 super(propId); 44 } 45 46 50 public Property convertProperty(Property p, 51 PropertyList propertyList, 52 FObj fo) throws PropertyException { 53 if (p.getEnum() == EN_LARGER || p.getEnum() == EN_SMALLER) { 54 Property pp = propertyList.getFromParent(this.getPropId()); 56 int baseFontSize = computeClosestAbsoluteFontSize(pp.getLength().getValue()); 57 if (p.getEnum() == EN_LARGER) { 58 return new FixedLength((int)Math.round((baseFontSize * FONT_SIZE_GROWTH_FACTOR))); 59 } else { 60 return new FixedLength((int)Math.round((baseFontSize / FONT_SIZE_GROWTH_FACTOR))); 61 } 62 } 63 return super.convertProperty(p, propertyList, fo); 64 } 65 66 72 private int computeClosestAbsoluteFontSize(int baseFontSize) { 73 double scale = FONT_SIZE_GROWTH_FACTOR; 74 int lastStepFontSize = FONT_SIZE_NORMAL; 75 if (baseFontSize < FONT_SIZE_NORMAL) { 76 scale = 1 / FONT_SIZE_GROWTH_FACTOR; 78 } 79 int nextStepFontSize = (int)Math.round(lastStepFontSize * scale); 81 while (scale < 1 && nextStepFontSize > baseFontSize 82 || scale > 1 && nextStepFontSize < baseFontSize) { 83 lastStepFontSize = nextStepFontSize; 86 nextStepFontSize = (int)Math.round(lastStepFontSize * scale); 87 } 88 if (Math.abs(lastStepFontSize - baseFontSize) 91 <= Math.abs(baseFontSize - nextStepFontSize)) { 92 return lastStepFontSize; 93 } 94 return nextStepFontSize; 95 } 96 97 } 98 | Popular Tags |