1 51 package org.apache.fop.render; 52 53 import org.apache.fop.pdf.PDFPathPaint; 55 import org.apache.fop.pdf.PDFColor; 56 import org.apache.fop.apps.FOPException; 57 import org.apache.fop.layout.*; 58 import org.apache.fop.layout.inline.*; 59 import org.apache.fop.datatypes.*; 60 import org.apache.fop.render.pdf.FontSetup; 61 import org.apache.fop.apps.FOPException; 62 63 import org.apache.fop.svg.SVGArea; 64 65 import java.io.IOException ; 67 import java.io.OutputStream ; 68 69 72 82 public abstract class PrintRenderer extends AbstractRenderer { 83 85 88 protected String currentFontName; 89 90 93 protected int currentFontSize; 94 95 98 protected PDFPathPaint currentStroke = null; 99 100 103 protected PDFPathPaint currentFill = null; 104 105 108 110 113 115 118 121 protected int prevUnderlineXEndPos; 123 protected int prevUnderlineYEndPos; 124 protected int prevUnderlineSize; 125 protected PDFColor prevUnderlineColor; 126 protected int prevOverlineXEndPos; 127 protected int prevOverlineYEndPos; 128 protected int prevOverlineSize; 129 protected PDFColor prevOverlineColor; 130 protected int prevLineThroughXEndPos; 131 protected int prevLineThroughYEndPos; 132 protected int prevLineThroughSize; 133 protected PDFColor prevLineThroughColor; 134 135 protected FontInfo fontInfo; 136 137 142 public abstract void setProducer(String producer); 143 144 156 protected abstract void addLine(int x1, int y1, int x2, int y2, int th, 157 PDFPathPaint stroke); 158 159 172 protected abstract void addLine(int x1, int y1, int x2, int y2, int th, 173 int rs, PDFPathPaint stroke); 174 175 184 protected abstract void addRect(int x, int y, int w, int h, 185 PDFPathPaint stroke); 186 187 197 protected abstract void addRect(int x, int y, int w, int h, 198 PDFPathPaint stroke, PDFPathPaint fill); 199 200 211 protected void addFilledRect(int x, int y, int w, int h, 212 PDFPathPaint fill) { 213 addRect(x, y, w, h, fill, fill); 214 } 215 216 protected void addFilledRect(int x, int y, int w, int h, 217 ColorType col) { 218 PDFColor pdfcol = new PDFColor(col); 219 addRect(x, y, w, h, pdfcol, pdfcol); 220 } 221 222 protected void doFrame(Area area) { 223 int w, h; 224 int rx = this.currentAreaContainerXPosition; 225 w = area.getContentWidth(); 226 if (area instanceof BlockArea) 227 rx += ((BlockArea)area).getStartIndent(); 228 h = area.getContentHeight(); 229 int ry = this.currentYPosition; 230 231 rx = rx - area.getPaddingLeft(); 232 ry = ry + area.getPaddingTop(); 233 w = w + area.getPaddingLeft() + area.getPaddingRight(); 234 h = h + area.getPaddingTop() + area.getPaddingBottom(); 235 236 doBackground(area, rx, ry, w, h); 237 238 243 BorderAndPadding bp = area.getBorderAndPadding(); 246 int left = area.getBorderLeftWidth(); 265 int right = area.getBorderRightWidth(); 266 int top = area.getBorderTopWidth(); 267 int bottom = area.getBorderBottomWidth(); 268 if (top != 0) 270 addFilledRect(rx, ry, w, top, 271 new PDFColor(bp.getBorderColor(BorderAndPadding.TOP))); 272 if (left != 0) 273 addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom, 274 new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT))); 275 if (right != 0) 276 addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom, 277 new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT))); 278 if (bottom != 0) 279 addFilledRect(rx, ry - h - bottom, w, bottom, 280 new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM))); 281 } 282 283 288 public void renderDisplaySpace(DisplaySpace space) { 289 int d = space.getSize(); 290 this.currentYPosition -= d; 291 } 292 293 296 public abstract void renderForeignObjectArea(ForeignObjectArea area); 297 298 303 public abstract void renderSVGArea(SVGArea area); 304 305 310 public abstract void renderWordArea(WordArea area); 311 312 protected void addWordLines(WordArea area, int rx, int bl, int size, 313 PDFColor theAreaColor) { 314 if (area.getUnderlined()) { 315 int yPos = bl - size / 10; 316 addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, 317 theAreaColor); 318 prevUnderlineXEndPos = rx + area.getContentWidth(); 320 prevUnderlineYEndPos = yPos; 321 prevUnderlineSize = size / 14; 322 prevUnderlineColor = theAreaColor; 323 } 324 325 if (area.getOverlined()) { 326 int yPos = bl + area.getFontState().getAscender() + size / 10; 327 addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, 328 theAreaColor); 329 prevOverlineXEndPos = rx + area.getContentWidth(); 330 prevOverlineYEndPos = yPos; 331 prevOverlineSize = size / 14; 332 prevOverlineColor = theAreaColor; 333 } 334 335 if (area.getLineThrough()) { 336 int yPos = bl + area.getFontState().getAscender() * 3 / 8; 337 addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, 338 theAreaColor); 339 prevLineThroughXEndPos = rx + area.getContentWidth(); 340 prevLineThroughYEndPos = yPos; 341 prevLineThroughSize = size / 14; 342 prevLineThroughColor = theAreaColor; 343 } 344 } 345 346 351 public void renderInlineSpace(InlineSpace space) { 352 this.currentXPosition += space.getSize(); 353 if (space.getUnderlined()) { 354 if (prevUnderlineColor != null) { 355 addLine(prevUnderlineXEndPos, prevUnderlineYEndPos, 356 prevUnderlineXEndPos + space.getSize(), 357 prevUnderlineYEndPos, prevUnderlineSize, 358 prevUnderlineColor); 359 prevUnderlineXEndPos = prevUnderlineXEndPos + space.getSize(); 361 } 362 } 363 if (space.getOverlined()) { 364 if (prevOverlineColor != null) { 365 addLine(prevOverlineXEndPos, prevOverlineYEndPos, 366 prevOverlineXEndPos + space.getSize(), 367 prevOverlineYEndPos, prevOverlineSize, 368 prevOverlineColor); 369 prevOverlineXEndPos = prevOverlineXEndPos + space.getSize(); 370 } 371 } 372 if (space.getLineThrough()) { 373 if (prevLineThroughColor != null) { 374 addLine(prevLineThroughXEndPos, prevLineThroughYEndPos, 375 prevLineThroughXEndPos + space.getSize(), 376 prevLineThroughYEndPos, prevLineThroughSize, 377 prevLineThroughColor); 378 prevLineThroughXEndPos = prevLineThroughXEndPos + space.getSize(); 379 } 380 } 381 } 382 383 388 public abstract void renderPage(Page page); 389 390 395 public void renderLeaderArea(LeaderArea area) { 396 int rx = this.currentXPosition; 397 int ry = this.currentYPosition; 398 int w = area.getContentWidth(); 399 int h = area.getHeight(); 400 int th = area.getRuleThickness(); 401 int st = area.getRuleStyle(); 402 403 if (th != 0) { 406 switch (st) { 407 case org.apache.fop.fo.properties.RuleStyle.DOUBLE: 408 addLine(rx, ry, rx + w, ry, th / 3, st, 409 new PDFColor(area.getRed(), area.getGreen(), 410 area.getBlue())); 411 addLine(rx, ry + (2 * th / 3), rx + w, ry + (2 * th / 3), 412 th / 3, st, 413 new PDFColor(area.getRed(), area.getGreen(), 414 area.getBlue())); 415 break; 416 case org.apache.fop.fo.properties.RuleStyle.GROOVE: 417 addLine(rx, ry, rx + w, ry, th / 2, st, 418 new PDFColor(area.getRed(), area.getGreen(), 419 area.getBlue())); 420 addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, 421 new PDFColor(255, 255, 255)); 422 break; 423 case org.apache.fop.fo.properties.RuleStyle.RIDGE: 424 addLine(rx, ry, rx + w, ry, th / 2, st, 425 new PDFColor(255, 255, 255)); 426 addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, 427 new PDFColor(area.getRed(), area.getGreen(), 428 area.getBlue())); 429 break; 430 default: 431 addLine(rx, ry, rx + w, ry, th, st, 432 new PDFColor(area.getRed(), area.getGreen(), 433 area.getBlue())); 434 } 435 this.currentXPosition += area.getContentWidth(); 436 this.currentYPosition += th; 437 } 438 } 439 440 445 public void setupFontInfo(FontInfo fontInfo) throws FOPException { 446 this.fontInfo = fontInfo; 447 FontSetup.setup(fontInfo); 448 } 449 450 454 public void startRenderer(OutputStream outputStream) 455 throws IOException {} 456 457 461 public void stopRenderer(OutputStream outputStream) 462 throws IOException 463 { 464 this.idReferences = null; 465 currentFontName = ""; 466 currentStroke = null; 467 currentFill = null; 468 prevUnderlineColor = null; 469 prevOverlineColor = null; 470 prevLineThroughColor = null; 471 fontInfo = null; 472 } 473 474 } 475 | Popular Tags |