1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import org.apache.fop.fo.flow.PageNumber; 23 import org.apache.fop.area.inline.InlineArea; 24 import org.apache.fop.area.inline.TextArea; 25 import org.apache.fop.area.Trait; 26 import org.apache.fop.fonts.Font; 27 import org.apache.fop.layoutmgr.LayoutContext; 28 import org.apache.fop.layoutmgr.TraitSetter; 29 import org.apache.fop.traits.MinOptMax; 30 31 34 public class PageNumberLayoutManager extends LeafNodeLayoutManager { 35 36 private PageNumber fobj; 37 private Font font; 38 39 45 public PageNumberLayoutManager(PageNumber node) { 46 super(node); 47 fobj = node; 48 } 49 50 51 public void initialize() { 52 font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this); 53 setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground()); 54 } 55 56 60 protected AlignmentContext makeAlignmentContext(LayoutContext context) { 61 return new AlignmentContext( 62 font 63 , fobj.getLineHeight().getOptimum(this).getLength().getValue(this) 64 , fobj.getAlignmentAdjust() 65 , fobj.getAlignmentBaseline() 66 , fobj.getBaselineShift() 67 , fobj.getDominantBaseline() 68 , context.getAlignmentContext() 69 ); 70 } 71 72 73 public InlineArea get(LayoutContext context) { 74 TextArea text = new TextArea(); 76 String str = getCurrentPV().getPageNumberString(); 77 int width = getStringWidth(str); 78 text.addWord(str, 0); 79 text.setIPD(width); 80 text.setBPD(font.getAscender() - font.getDescender()); 81 text.setBaselineOffset(font.getAscender()); 82 TraitSetter.addFontTraits(text, font); 83 text.addTrait(Trait.COLOR, fobj.getColor()); 84 85 TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); 86 87 return text; 88 } 89 90 91 protected InlineArea getEffectiveArea() { 92 TextArea baseArea = (TextArea)curArea; 93 TextArea ta = new TextArea(); 97 TraitSetter.setProducerID(ta, fobj.getId()); 98 ta.setIPD(baseArea.getIPD()); 99 ta.setBPD(baseArea.getBPD()); 100 ta.setOffset(baseArea.getOffset()); 101 ta.setBaselineOffset(baseArea.getBaselineOffset()); 102 ta.addTrait(Trait.COLOR, fobj.getColor()); ta.getTraits().putAll(baseArea.getTraits()); 104 updateContent(ta); 105 return ta; 106 } 107 108 private void updateContent(TextArea area) { 109 area.removeText(); 111 area.addWord(getCurrentPV().getPageNumberString(), 0); 112 area.handleIPDVariation(getStringWidth(area.getText()) - area.getIPD()); 114 areaInfo.ipdArea = new MinOptMax(area.getIPD()); 116 } 117 118 122 private int getStringWidth(String str) { 123 int width = 0; 124 for (int count = 0; count < str.length(); count++) { 125 width += font.getCharWidth(str.charAt(count)); 126 } 127 return width; 128 } 129 130 131 protected void addId() { 132 getPSLM().addIDToPage(fobj.getId()); 133 } 134 } 135 136 | Popular Tags |