1 17 18 19 20 package org.apache.fop.traits; 21 22 import org.apache.fop.datatypes.PercentBaseContext; 23 import org.apache.fop.fo.Constants; 24 import org.apache.fop.fo.properties.Property; 25 import org.apache.fop.fo.properties.SpaceProperty; 26 import org.apache.fop.fonts.Font; 27 28 32 public class SpaceVal { 33 34 private final MinOptMax space; 35 private final boolean bConditional; 36 private final boolean bForcing; 37 private final int iPrecedence; 39 44 public SpaceVal(SpaceProperty spaceprop, PercentBaseContext context) { 45 space = new MinOptMax(spaceprop.getMinimum(context).getLength().getValue(context), 46 spaceprop.getOptimum(context).getLength().getValue(context), 47 spaceprop.getMaximum(context).getLength().getValue(context)); 48 bConditional = 49 (spaceprop.getConditionality().getEnum() == Constants.EN_DISCARD); 50 Property precProp = spaceprop.getPrecedence(); 51 if (precProp.getNumber() != null) { 52 iPrecedence = precProp.getNumber().intValue(); 53 bForcing = false; 54 } else { 55 bForcing = (precProp.getEnum() == Constants.EN_FORCE); 56 iPrecedence = 0; 57 } 58 } 59 60 67 public SpaceVal(MinOptMax space, boolean bConditional, 68 boolean bForcing, int iPrecedence) { 69 this.space = space; 70 this.bConditional = bConditional; 71 this.bForcing = bForcing; 72 this.iPrecedence = iPrecedence; 73 } 74 75 static public SpaceVal makeWordSpacing(Property wordSpacing, 76 SpaceVal letterSpacing, 77 Font fs) { 78 if (wordSpacing.getEnum() == Constants.EN_NORMAL) { 79 int spaceCharIPD = fs.getCharWidth(' '); 82 MinOptMax space = new MinOptMax(-spaceCharIPD / 3, 0, spaceCharIPD / 2); 83 return new SpaceVal( 85 MinOptMax.add 86 (space, MinOptMax.multiply(letterSpacing.getSpace(), 2)), 87 true, true, 0); 88 } else { 89 return new SpaceVal(wordSpacing.getSpace(), null); 90 } 91 } 92 93 static public SpaceVal makeLetterSpacing(Property letterSpacing) { 94 if (letterSpacing.getEnum() == Constants.EN_NORMAL) { 95 return new SpaceVal(new MinOptMax(0), true, true, 0); 97 } else { 98 return new SpaceVal(letterSpacing.getSpace(), null); 99 } 100 } 101 102 106 public boolean isConditional() { 107 return bConditional; 108 } 109 110 114 public boolean isForcing() { 115 return bForcing; 116 } 117 118 122 public int getPrecedence() { 123 return iPrecedence; 124 } 125 126 130 public MinOptMax getSpace() { 131 return space; 132 } 133 134 public String toString() { 135 return "SpaceVal: " + getSpace().toString(); 136 } 137 } 138 139 | Popular Tags |