1 51 package org.apache.fop.layout; 52 53 import org.apache.fop.render.Renderer; 55 import org.apache.fop.fo.flow.*; 56 57 import java.util.ArrayList ; 59 60 70 public class BlockArea extends Area { 71 72 73 protected int startIndent; 74 protected int endIndent; 75 76 77 protected int textIndent; 78 79 protected int lineHeight; 80 81 protected int halfLeading; 82 83 84 85 protected int align; 86 87 88 protected int alignLastLine; 89 90 protected LineArea currentLineArea; 91 protected LinkSet currentLinkSet; 92 93 94 protected HyphenationProps hyphProps; 95 96 protected ArrayList pendingFootnotes = null; 97 98 public BlockArea(FontState fontState, int allocationWidth, int maxHeight, 99 int startIndent, int endIndent, int textIndent, 100 int align, int alignLastLine, int lineHeight) { 101 super(fontState, allocationWidth, maxHeight); 102 103 this.startIndent = startIndent; 104 this.endIndent = endIndent; 105 this.textIndent = textIndent; 106 this.contentRectangleWidth = allocationWidth - startIndent 107 - endIndent; 108 this.align = align; 109 this.alignLastLine = alignLastLine; 110 this.lineHeight = lineHeight; 111 112 if (fontState != null) 113 this.halfLeading = (lineHeight - fontState.getFontSize()) / 2; 114 } 115 116 public void render(Renderer renderer) { 117 renderer.renderBlockArea(this); 118 } 119 120 128 protected void addLineArea(LineArea la) { 129 if (!la.isEmpty()) { 130 la.verticalAlign(); 131 this.addDisplaySpace(this.halfLeading); 132 int size = la.getHeight(); 133 this.addChild(la); 134 this.increaseHeight(size); 135 this.addDisplaySpace(this.halfLeading); 136 } 137 if (pendingFootnotes != null) { 139 for (int i = 0; i< pendingFootnotes.size(); i++) { 140 FootnoteBody fb = (FootnoteBody)pendingFootnotes.get(i); 141 Page page = getPage(); 142 if (!Footnote.layoutFootnote(page, fb, this)) { 143 page.addPendingFootnote(fb); 144 } 145 } 146 pendingFootnotes = null; 147 } 148 } 149 150 159 public LineArea getCurrentLineArea() { 160 if (currentHeight + lineHeight > maxHeight) { 161 return null; 162 } 163 if (this.currentLineArea==null ) { 164 this.currentLineArea = new LineArea(fontState, lineHeight, 165 halfLeading, allocationWidth, 166 startIndent + textIndent, 167 endIndent, null); 168 this.currentLineArea.changeHyphenation(hyphProps); 169 } 170 return this.currentLineArea; 171 } 172 173 183 public LineArea createNextLineArea() { 184 if (this.currentLineArea!=null) { 185 this.currentLineArea.align(this.align); 186 this.addLineArea(this.currentLineArea); 187 } 188 if (currentHeight + lineHeight > maxHeight) { 189 return null; 190 } 191 this.currentLineArea = new LineArea(fontState, lineHeight, 192 halfLeading, allocationWidth, 193 startIndent, endIndent, 194 currentLineArea); 195 this.currentLineArea.changeHyphenation(hyphProps); 196 return this.currentLineArea; 197 } 198 199 public void setupLinkSet(LinkSet ls) { 200 if (ls != null) { 201 this.currentLinkSet = ls; 202 ls.setYOffset(currentHeight); 203 } 204 } 205 206 211 public void end() { 212 if (this.currentLineArea!=null) { 213 this.currentLineArea.addPending(); 214 this.currentLineArea.align(this.alignLastLine); 215 this.addLineArea(this.currentLineArea); 216 this.currentLineArea = null; 217 } 218 } 219 220 public void start() { 221 } 222 223 public int getEndIndent() { 224 return endIndent; 225 } 226 227 public int getStartIndent() { 229 return startIndent; 231 } 232 233 public void setIndents(int startIndent, int endIndent) { 234 this.startIndent = startIndent; 235 this.endIndent = endIndent; 236 this.contentRectangleWidth = allocationWidth - startIndent 237 - endIndent; 238 } 239 240 247 public int spaceLeft() { 248 return maxHeight - currentHeight 250 - (getPaddingTop() + getPaddingBottom() 251 + getBorderTopWidth() + getBorderBottomWidth()); 252 } 253 254 public int getHalfLeading() { 255 return halfLeading; 256 } 257 258 public void setHyphenation(HyphenationProps hyphProps) { 259 this.hyphProps = hyphProps; 260 } 261 262 public void addFootnote(FootnoteBody fb) { 263 if (pendingFootnotes == null) { 264 pendingFootnotes = new ArrayList (); 265 } 266 pendingFootnotes.add(fb); 267 } 268 269 } 270 | Popular Tags |