1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import org.apache.fop.fo.flow.PageNumberCitation; 23 import org.apache.fop.area.PageViewport; 24 import org.apache.fop.area.Resolvable; 25 import org.apache.fop.area.Trait; 26 import org.apache.fop.area.inline.InlineArea; 27 import org.apache.fop.area.inline.UnresolvedPageNumber; 28 import org.apache.fop.area.inline.TextArea; 29 import org.apache.fop.fonts.Font; 30 import org.apache.fop.layoutmgr.LayoutContext; 31 import org.apache.fop.layoutmgr.LayoutManager; 32 import org.apache.fop.layoutmgr.PositionIterator; 33 import org.apache.fop.layoutmgr.TraitSetter; 34 35 38 public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { 39 40 private PageNumberCitation fobj; 41 42 protected Font font; 43 44 45 protected boolean resolved = false; 46 47 53 public PageNumberCitationLayoutManager(PageNumberCitation node) { 54 super(node); 55 fobj = node; 56 } 57 58 59 public void initialize() { 60 font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this); 61 setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground()); 62 } 63 64 67 protected AlignmentContext makeAlignmentContext(LayoutContext context) { 68 return new AlignmentContext( 69 font 70 , fobj.getLineHeight().getOptimum(this).getLength().getValue(this) 71 , fobj.getAlignmentAdjust() 72 , fobj.getAlignmentBaseline() 73 , fobj.getBaselineShift() 74 , fobj.getDominantBaseline() 75 , context.getAlignmentContext() 76 ); 77 } 78 79 80 public InlineArea get(LayoutContext context) { 81 curArea = getPageNumberCitationInlineArea(parentLM); 82 return curArea; 83 } 84 85 89 public void addAreas(PositionIterator posIter, LayoutContext context) { 90 super.addAreas(posIter, context); 91 if (!resolved) { 92 getPSLM().addUnresolvedArea(fobj.getRefId(), (Resolvable) curArea); 93 } 94 } 95 96 100 private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) { 101 PageViewport page = getPSLM().getFirstPVWithID(fobj.getRefId()); 102 TextArea text = null; 103 if (page != null) { 104 String str = page.getPageNumberString(); 105 text = new TextArea(); 107 int width = getStringWidth(str); 108 text.addWord(str, 0); 109 text.setIPD(width); 110 resolved = true; 111 } else { 112 resolved = false; 113 text = new UnresolvedPageNumber(fobj.getRefId(), font); 114 String str = "MMM"; int width = getStringWidth(str); 116 text.setIPD(width); 117 } 118 updateTextAreaTraits(text); 119 120 return text; 121 } 122 123 127 protected void updateTextAreaTraits(TextArea text) { 128 TraitSetter.setProducerID(text, fobj.getId()); 129 text.setBPD(font.getAscender() - font.getDescender()); 130 text.setBaselineOffset(font.getAscender()); 131 TraitSetter.addFontTraits(text, font); 132 text.addTrait(Trait.COLOR, fobj.getColor()); 133 TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); 134 } 135 136 140 protected int getStringWidth(String str) { 141 int width = 0; 142 for (int count = 0; count < str.length(); count++) { 143 width += font.getCharWidth(str.charAt(count)); 144 } 145 return width; 146 } 147 148 149 protected void addId() { 150 getPSLM().addIDToPage(fobj.getId()); 151 } 152 } 153 154 | Popular Tags |