1 17 18 19 20 package org.apache.fop.area; 21 22 import org.apache.fop.area.inline.InlineArea; 23 import org.apache.fop.fo.Constants; 24 25 import java.io.Serializable ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 33 public class LineArea extends Area { 34 35 40 private class LineAdjustingInfo implements Serializable { 41 private int lineAlignment; 42 private int difference; 43 private int availableStretch; 44 private int availableShrink; 45 private double variationFactor; 46 private boolean bAddedToAreaTree; 47 48 private LineAdjustingInfo(int alignment, int diff, 49 int stretch, int shrink) { 50 lineAlignment = alignment; 51 difference = diff; 52 availableStretch = stretch; 53 availableShrink = shrink; 54 variationFactor = 1.0; 55 bAddedToAreaTree = false; 56 } 57 } 58 59 private LineAdjustingInfo adjustingInfo = null; 60 61 64 private List inlineAreas = new ArrayList (); 65 66 70 public LineArea() { 71 } 72 73 81 public LineArea(int alignment, int diff, 82 int stretch, int shrink) { 83 adjustingInfo = new LineAdjustingInfo(alignment, diff, stretch, shrink); 84 } 85 86 91 public void addChildArea(Area childArea) { 92 if (childArea instanceof InlineArea) { 93 addInlineArea((InlineArea)childArea); 94 ((InlineArea) childArea).setParentArea(this); 96 } 97 } 98 99 104 public void addInlineArea(InlineArea area) { 105 inlineAreas.add(area); 106 } 107 108 113 public List getInlineAreas() { 114 return inlineAreas; 115 } 116 117 124 public int getStartIndent() { 125 if (hasTrait(Trait.START_INDENT)) { 126 return getTraitAsInteger(Trait.START_INDENT); 127 } else { 128 return 0; 129 } 130 } 131 132 135 public void updateExtentsFromChildren() { 136 int ipd = 0; 137 int bpd = 0; 138 for (int i = 0, len = inlineAreas.size(); i < len; i++) { 139 ipd = Math.max(ipd, ((InlineArea)inlineAreas.get(i)).getAllocIPD()); 140 bpd += ((InlineArea)inlineAreas.get(i)).getAllocBPD(); 141 } 142 setIPD(ipd); 143 setBPD(bpd); 144 } 145 146 161 public void handleIPDVariation(int ipdVariation) { 162 switch (adjustingInfo.lineAlignment) { 163 case Constants.EN_START: 164 break; 166 case Constants.EN_CENTER: 167 addTrait(Trait.START_INDENT, new Integer (getStartIndent() - ipdVariation / 2)); 169 break; 170 case Constants.EN_END: 171 addTrait(Trait.START_INDENT, new Integer (getStartIndent() - ipdVariation)); 173 break; 174 case Constants.EN_JUSTIFY: 175 adjustingInfo.variationFactor *= (float) (adjustingInfo.difference - ipdVariation) 177 / adjustingInfo.difference; 178 adjustingInfo.difference -= ipdVariation; 179 if (adjustingInfo.bAddedToAreaTree) { 182 finalise(); 183 } 184 break; 185 default: 186 throw new RuntimeException (); 187 } 188 } 189 190 195 public void finalise() { 196 if (adjustingInfo.lineAlignment == Constants.EN_JUSTIFY) { 197 boolean bUnresolvedAreasPresent = false; 199 for (int i = 0, len = inlineAreas.size(); i < len; i++) { 201 bUnresolvedAreasPresent |= ((InlineArea) inlineAreas.get(i)) 202 .applyVariationFactor(adjustingInfo.variationFactor, 203 adjustingInfo.availableStretch, 204 adjustingInfo.availableShrink); 205 } 206 if (!bUnresolvedAreasPresent) { 207 adjustingInfo = null; 210 } else { 211 if (!adjustingInfo.bAddedToAreaTree) { 215 adjustingInfo.bAddedToAreaTree = true; 216 } 217 adjustingInfo.variationFactor = 1.0; 219 } 220 } else { 221 } 224 } 225 } 226 227 | Popular Tags |