1 51 package org.apache.fop.render.mif; 52 53 import org.apache.fop.render.AbstractRenderer; 55 import org.apache.fop.layout.*; 56 import org.apache.fop.layout.inline.*; 57 import org.apache.fop.datatypes.*; 58 import org.apache.fop.svg.*; 59 import org.apache.fop.mif.*; 60 import org.apache.fop.image.*; 61 62 import java.io.IOException ; 64 import java.io.OutputStream ; 65 66 73 public class MIFRenderer extends AbstractRenderer { 74 75 private String currentFontName; 76 private String currentFontSize; 77 private int pageHeight; 78 private int pageWidth; 79 80 83 protected int currentYPosition = 0; 84 85 88 protected int currentXPosition = 0; 89 90 93 private int currentAreaContainerXPosition = 0; 94 95 96 99 protected MIFDocument mifDoc; 100 101 102 103 private boolean inTable = false; 104 105 108 protected java.util.Map options; 109 110 113 public MIFRenderer() { 114 this.mifDoc = new MIFDocument(); 115 } 116 117 120 public void setOptions(java.util.Map options) { 121 this.options = options; 122 } 123 124 127 public void setupFontInfo(FontInfo fontInfo) { 128 129 FontSetup.setup(fontInfo); 130 132 } 133 134 137 public void setProducer(String producer) {} 138 139 140 public void renderAreaContainer(AreaContainer area) { 141 142 if (area.foCreator != null 143 && area.foCreator.getName() == "fo:table") { 144 145 this.mifDoc.createTable(); 146 this.inTable = true; 147 } else if (area.foCreator != null 148 && area.foCreator.getName() == "fo:table-body") { 149 150 this.mifDoc.setCurrent("fo:table-body"); 151 } else if (area.foCreator != null 152 && area.foCreator.getName() == "fo:table-column") { 153 154 int colWidth = 155 ((org.apache.fop.fo.flow.TableColumn)area.foCreator).getColumnWidth(); 156 this.mifDoc.setColumnProp(colWidth); 157 } else if (area.foCreator != null 158 && area.foCreator.getName() == "fo:table-row") { 159 160 this.mifDoc.startRow(); 161 } else if (area.foCreator != null 162 && area.foCreator.getName() == "fo:table-cell") { 163 164 int rowSpan = 165 ((org.apache.fop.fo.flow.TableCell)area.foCreator).getNumRowsSpanned(); 166 int colSpan = 167 ((org.apache.fop.fo.flow.TableCell)area.foCreator).getNumColumnsSpanned(); 168 this.mifDoc.startCell(rowSpan, colSpan); 169 } else if (inTable) { 170 171 inTable = false; 172 this.mifDoc.endTable(); 173 174 } 175 super.renderAreaContainer(area); 176 } 177 178 protected void addFilledRect(int x, int y, int w, int h, 179 ColorType col) { 180 } 181 182 protected void doFrame(Area area) { 183 int w, h; 184 int rx = this.currentAreaContainerXPosition; 185 w = area.getContentWidth(); 186 187 if (area instanceof BlockArea) 188 rx += ((BlockArea)area).getStartIndent(); 189 190 h = area.getContentHeight(); 191 int ry = this.currentYPosition; 192 193 rx = rx - area.getPaddingLeft(); 194 ry = ry + area.getPaddingTop(); 195 w = w + area.getPaddingLeft() + area.getPaddingRight(); 196 h = h + area.getPaddingTop() + area.getPaddingBottom(); 197 198 doBackground(area, rx, ry, w, h); 199 200 rx = rx - area.getBorderLeftWidth(); 201 ry = ry + area.getBorderTopWidth(); 202 w = w + area.getBorderLeftWidth() + area.getBorderRightWidth(); 203 h = h + area.getBorderTopWidth() + area.getBorderBottomWidth(); 204 205 208 this.mifDoc.setTextRectProp(rx, pageHeight - ry, w, h); 209 210 225 } 226 227 public void renderSpanArea(SpanArea area) { 228 this.mifDoc.createTextRect(area.getColumnCount()); 230 super.renderSpanArea(area); 231 } 232 233 236 public void renderBlockArea(BlockArea area) { 237 this.mifDoc.setBlockProp(area.getStartIndent(), area.getEndIndent()); 238 super.renderBlockArea(area); 239 } 240 241 244 public void renderDisplaySpace(DisplaySpace space) { 245 int d = space.getSize(); 246 this.currentYPosition -= d; 247 } 248 249 252 public void renderSVGArea(SVGArea area) {} 253 254 257 public void renderForeignObjectArea(ForeignObjectArea area) {} 258 259 public void renderWordArea(WordArea area) { 260 String s; 261 s = area.getText(); 262 this.mifDoc.addToStream(s); 263 264 this.currentXPosition += area.getContentWidth(); 265 } 266 267 280 protected void drawImageScaled(int x, int y, int w, int h, 281 FopImage image, 282 FontState fs) { 283 } 285 286 299 protected void drawImageClipped(int x, int y, 300 int clipX, int clipY, 301 int clipW, int clipH, 302 FopImage image, 303 FontState fs) { 304 } 306 307 310 public void renderImageArea(ImageArea area) { 311 312 int x = this.currentAreaContainerXPosition + area.getXOffset(); 313 int y = this.currentYPosition; 314 int w = area.getContentWidth(); 315 int h = area.getHeight(); 316 317 this.currentYPosition -= h; 318 319 FopImage img = area.getImage(); 320 if (img instanceof SVGImage) { 321 334 335 log.warn("SVG images not supported in this version"); 336 } else { 337 String url = img.getURL(); 338 this.mifDoc.addImage(url, x, pageHeight - y, w, h); 339 340 } 341 } 342 343 346 public void renderInlineArea(InlineArea area) {} 347 348 351 public void renderInlineSpace(InlineSpace space) { 352 353 String s = " "; 356 this.mifDoc.addToStream(s); this.currentXPosition += space.getSize(); 358 } 359 360 363 public void renderLineArea(LineArea area) { 364 this.mifDoc.startLine(); 366 super.renderLineArea(area); 367 } 368 369 372 public void renderPage(Page page) { 373 374 AreaContainer before, after; 375 BodyAreaContainer body; 376 body = page.getBody(); 377 before = page.getBefore(); 378 after = page.getAfter(); 379 380 this.currentFontName = ""; 381 this.currentFontSize = "0"; 382 383 pageHeight = page.getHeight(); 384 pageWidth = page.getWidth(); 385 this.mifDoc.setDocumentHeightWidth(pageHeight, pageWidth); 386 387 this.mifDoc.createPage(); 388 389 body.render(this); 390 391 392 395 396 if (before != null) { 397 398 this.mifDoc.createTextRect(1); before.render(this); 400 } 401 402 if (after != null) { 403 404 this.mifDoc.createTextRect(1); after.render(this); 406 } 407 408 } 409 410 413 public void renderLeaderArea(LeaderArea area) {} 414 415 419 public void startRenderer(OutputStream outputStream) 420 throws IOException { 421 log.info("rendering areas to MIF"); 422 } 423 424 428 public void stopRenderer(OutputStream outputStream) 429 throws IOException { 430 log.info("writing out MIF"); 431 this.mifDoc.output(outputStream); 432 outputStream.flush(); 433 } 434 435 public void render(Page page, OutputStream outputStream) { 436 this.renderPage(page); 437 } 438 } 439 440 | Popular Tags |