1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.render.awt;
/*
* originally contributed by
* Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
* Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
* Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
*/
import org.apache.fop.layout.*;
import org.apache.fop.layout.inline.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.image.*;
import org.apache.fop.svg.*;
import org.apache.fop.render.pdf.*;
import org.apache.fop.viewer.*;
import org.apache.fop.apps.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.gvt.*;
import org.apache.batik.gvt.renderer.*;
import org.apache.batik.gvt.filter.*;
import org.apache.batik.gvt.event.*;
import java.awt.*;
import java.awt.Image;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.util.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
import java.beans.*;
import javax.swing.*;
import java.awt.print.*;
import java.awt.image.BufferedImage;
import java.text.*;
import org.apache.fop.render.AbstractRenderer;
/**
Modified by Mark Lillywhite mark-fop@inomial.com. Did lots of
cleaning up and made the class implement the new Renderer
interface. This class could also do with a general audit,
and I suspect it's not swing-thread-safe either.
*/
public class AWTRenderer extends AbstractRenderer implements Printable, Pageable {
protected int pageWidth = 0;
protected int pageHeight = 0;
protected double scaleFactor = 100.0;
protected int pageNumber = 0;
protected Vector pageList = new Vector();
protected ProgressListener progressListener = null;
protected Translator res = null;
protected Hashtable fontNames = new Hashtable();
protected Hashtable fontStyles = new Hashtable();
protected Color saveColor = null;
protected IDReferences idReferences = null;
/**
* Image Object and Graphics Object. The Graphics Object is the Graphics
* object that is contained withing the Image Object.
*/
private BufferedImage pageImage = null;
private Graphics2D graphics = null;
/**
* The current (internal) font name
*/
protected String currentFontName;
/**
* The current font size in millipoints
*/
protected int currentFontSize;
/**
* The current colour's red, green and blue component
*/
protected float currentRed = 0;
protected float currentGreen = 0;
protected float currentBlue = 0;
/**
* The parent component, used to set up the font.
* This is needed as FontSetup needs a live AWT component
* in order to generate valid font measures.
*/
protected Component parent;
/**
* options
*/
protected Hashtable options;
/**
* set up renderer options
*/
public void setOptions(Hashtable options) {
this.options = options;
}
public AWTRenderer(Translator aRes) {
res = aRes;
}
/**
* Sets parent component which is used to set up the font.
* This is needed as FontSetup needs a live AWT component
* in order to generate valid font measures.
* @param parent the live AWT component reference
*/
public void setComponent(Component parent) {
this.parent = parent;
}
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int aValue) {
pageNumber = aValue;
}
public void setScaleFactor(double newScaleFactor) {
scaleFactor = newScaleFactor;
}
public double getScaleFactor() {
return scaleFactor;
}
public BufferedImage getLastRenderedPage() {
return pageImage;
}
/**
* add a line to the current stream
*
* @param x1 the start x location in millipoints
* @param y1 the start y location in millipoints
* @param x2 the end x location in millipoints
* @param y2 the end y location in millipoints
* @param th the thickness in millipoints
* @param r the red component
* @param g the green component
* @param b the blue component
*/
// corrected 7/13/01 aml,rlc to properly handle thickness
//
protected void addLine(int x1, int y1, int x2, int y2, int th, float r,
float g, float b) {
graphics.setColor(new Color(r, g, b));
int x = x1;
int y = y1;
int height, width;
if (x1 == x2) // vertical line
{
height = y2 - y1;
if (height > 0) // y coordinates are reversed between fo and AWT
{
height = -height;
y = y2;
}
width = th;
if (width < 0) {
width = -width;
x -= width;
}
} else // horizontal line
{
width = x2 - x1;
if (width < 0) {
width = -width;
x = x2;
}
height = th;
if (height > 0) // y coordinates are reversed between fo and AWT
{
height = -height;
y -= height;
}
}
addRect(x, y, width, height, false);
// // graphics.setColor(Color.red);
// graphics.drawLine((int)(x1 / 1000f),
// pageHeight - (int)(y1 / 1000f), (int)(x2 / 1000f),
// pageHeight - (int)(y2 / 1000f));
}
/**
* draw a rectangle
*
* @param x the x position of left edge in millipoints
* @param y the y position of top edge in millipoints
* @param w the width in millipoints
* @param h the height in millipoints
* @param r the red component
* @param g the green component
* @param b the blue component
*/
// changed by aml/rlc to use helper function that
// corrects for integer roundoff, and to remove 3D effect
protected void addRect(int x, int y, int w, int h, float r, float g,
float b) {
graphics.setColor(new Color(r, g, b));
// graphics.setColor(Color.green);
addRect(x, y, w, h, true);
}
/**
* draw a filled rectangle
*
* @param x the x position of left edge in millipoints
* @param y the y position of top edge in millipoints
* @param w the width in millipoints
* @param h the height in millipoints
* @param r the red component of edges
* @param g the green component of edges
* @param b the blue component of edges
* @param fr the red component of the fill
* @param fg the green component of the fill
* @param fb the blue component of the fill
*/
// changed by aml/rlc to use helper function that
// corrects for integer roundoff
protected void addRect(int x, int y, int w, int h, float r, float g,
float b, float fr, float fg, float fb) {
graphics.setColor(new Color(r, g, b));
addRect(x, y, w, h, true);
graphics.setColor(new Color(fr, fg, fb));
addRect(x, y, w, h, false);
}
/**
* draw a filled rectangle in the current color
*
* @param x the x position of left edge in millipoints
* @param y the y position of top edge in millipoints
* @param w the width in millipoints
* @param h the height in millipoints
* @param drawAsOutline true for draw, false for fill
*/
// helper function by aml/rlc to correct integer roundoff problems
//
protected void addRect(int x, int y, int w, int h,
boolean drawAsOutline) {
int startx = (x + 500) / 1000;
int starty = pageHeight - ((y + 500) / 1000);
int endx = (x + w + 500) / 1000;
int endy = pageHeight - ((y + h + 500) / 1000);
if (drawAsOutline)
graphics.drawRect(startx, starty, endx - startx, endy - starty);
else
graphics.fillRect(startx, starty, endx - startx, endy - starty);
}
protected void addFilledRect(int x, int y, int w, int h,
ColorType col) {
float r = col.red();
float g = col.green();
float b = col.blue();
addRect(x, y, w, h, r, g, b, r, g, b);
}
/**
* To configure before print.
*
* Choose pages
* Zoom factor
* Page format / Landscape or Portrait
*/
public void transform(Graphics2D g2d, double zoomPercent, double angle) {
AffineTransform at = g2d.getTransform();
at.rotate(angle);
at.scale(zoomPercent / 100.0, zoomPercent / 100.0);
g2d.setTransform(at);
}
protected void drawFrame() {
int width = pageWidth;
int height = pageHeight;
graphics.setColor(Color.white);
graphics.fillRect(0, 0, width, height);
graphics.setColor(Color.black);
graphics.drawRect(-1, -1, width + 2, height + 2);
graphics.drawLine(width + 2, 0, width + 2, height + 2);
graphics.drawLine(width + 3, 1, width + 3, height + 3);
graphics.drawLine(0, height + 2, width + 2, height + 2);
graphics.drawLine(1, height + 3, width + 3, height + 3);
}
/**
* Retrieve the number of pages in this document.
*
* @return the number of pages
*/
public int getPageCount() {
return pageList.size();
}
public void removePage(int page) {
pageList.removeElementAt(page);
}
public void render(int aPageNumber) {
if(aPageNumber >= pageList.size())
return;
try {
render((Page) pageList.elementAt(aPageNumber));
} catch(IOException e) {
e.printStackTrace();
// This exception can't occur because we are not dealing with
// any files
}
}
public void render(Page page, OutputStream stream)
throws IOException {
pageList.addElement(page);
}
public void render(Page page)
throws IOException {
idReferences = page.getIDReferences();
pageWidth = (int)((float)page.getWidth() / 1000f + .5);
pageHeight = (int)((float)page.getHeight() / 1000f + .5);
pageImage =
new BufferedImage((int)((pageWidth * (int)scaleFactor) / 100),
(int)((pageHeight * (int)scaleFactor) / 100),
BufferedImage.TYPE_INT_RGB);
graphics = pageImage.createGraphics();
transform(graphics, scaleFactor, 0);
drawFrame();
renderPage(page);
}
public void renderPage(Page page) {
BodyAreaContainer body;
AreaContainer before, after;
body = page.getBody();
before = page.getBefore();
after = page.getAfter();
this.currentFontName = "";
this.currentFontSize = 0;
renderBodyAreaContainer(body);
if (before != null) {
renderAreaContainer(before);
}
if (after != null) {
renderAreaContainer(after);
}
// SG: Wollen wir Links abbilden?
/*
* if (page.hasLinks()) {
* ....
* }
*/
}
protected void doFrame(org.apache.fop.layout.Area area) {
int w, h;
int rx = this.currentAreaContainerXPosition;
w = area.getContentWidth();
if (area instanceof BlockArea) {
rx += ((BlockArea)area).getStartIndent();
}
h = area.getContentHeight();
int ry = this.currentYPosition;
ColorType bg = area.getBackgroundColor();
rx = rx - area.getPaddingLeft();
ry = ry + area.getPaddingTop();
w = w + area.getPaddingLeft() + area.getPaddingRight();
h = h + area.getPaddingTop() + area.getPaddingBottom();
// I'm not sure I should have to check for bg being null
// but I do
if ((bg != null) && (bg.alpha() == 0)) {
this.addRect(rx, ry, w, -h, bg.red(), bg.green(), bg.blue(),
bg.red(), bg.green(), bg.blue());
}
rx = rx - area.getBorderLeftWidth();
ry = ry + area.getBorderTopWidth();
w = w + area.getBorderLeftWidth() + area.getBorderRightWidth();
h = h + area.getBorderTopWidth() + area.getBorderBottomWidth();
BorderAndPadding bp = area.getBorderAndPadding();
ColorType borderColor;
if (area.getBorderTopWidth() != 0) {
borderColor = bp.getBorderColor(BorderAndPadding.TOP);
// addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(), // corrected aml/rlc
addLine(rx, ry, rx + w, ry, -area.getBorderTopWidth(),
borderColor.red(), borderColor.green(),
borderColor.blue());
}
if (area.getBorderLeftWidth() != 0) {
borderColor = bp.getBorderColor(BorderAndPadding.LEFT);
addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(),
borderColor.red(), borderColor.green(),
borderColor.blue());
}
if (area.getBorderRightWidth() != 0) {
borderColor = bp.getBorderColor(BorderAndPadding.RIGHT);
addLine(rx + w, ry, rx + w, ry - h,
// area.getBorderRightWidth(), borderColor.red(), // corrected aml/rlc
-area.getBorderRightWidth(), borderColor.red(),
borderColor.green(),
borderColor.blue());
}
if (area.getBorderBottomWidth() != 0) {
borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM);
addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(),
borderColor.red(), borderColor.green(),
borderColor.blue());
}
}
protected Rectangle2D getBounds(org.apache.fop.layout.Area a) {
return new Rectangle2D.Double(currentAreaContainerXPosition,
currentYPosition,
a.getAllocationWidth(), a.getHeight());
}
public void setupFontInfo(FontInfo fontInfo) {
// create a temp Image to test font metrics on
BufferedImage fontImage =
new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
FontSetup.setup(fontInfo, fontImage.createGraphics());
}
public void renderDisplaySpace(DisplaySpace space) {
int d = space.getSize();
this.currentYPosition -= d;
}
// correct integer roundoff (aml/rlc)
public void renderImageArea(ImageArea area) {
int x = currentAreaContainerXPosition + area.getXOffset();
int y = currentYPosition;
int w = area.getContentWidth();
int h = area.getHeight();
FopImage img = area.getImage();
if (img == null) {
log.error("Error while loading image : area.getImage() is null");
// correct integer roundoff
// graphics.drawRect(x / 1000, pageHeight - y / 1000,
// w / 1000, h / 1000);
addRect(x, y, w, h, true); // use helper function
java.awt.Font f = graphics.getFont();
java.awt.Font smallFont = new java.awt.Font(f.getFontName(),
f.getStyle(), 8);
graphics.setFont(smallFont);
// correct integer roundoff // aml/rlc
// graphics.drawString("area.getImage() is null", x / 1000,
// pageHeight - y / 1000);
graphics.drawString("area.getImage() is null", (x + 500) / 1000,
pageHeight - (y + 500) / 1000);
graphics.setFont(f);
} else {
if (img instanceof SVGImage) {
try {
SVGDocument svg = ((SVGImage)img).getSVGDocument();
renderSVGDocument(svg, (int)x, (int)y);
} catch (FopImageException e) {}
} else {
String urlString = img.getURL();
try {
URL url = new URL(urlString);
ImageIcon icon = new ImageIcon(url);
Image image = icon.getImage();
// correct integer roundoff aml/rlc
// graphics.drawImage(image, x / 1000,
// pageHeight - y / 1000, w / 1000, h / 1000,
// null);
int startx = (x + 500) / 1000;
int starty = pageHeight - ((y + 500) / 1000);
int endx = (x + w + 500) / 1000;
int endy = pageHeight - ((y + h + 500) / 1000);
// reverse start and end y because h is positive
graphics.drawImage(image, startx, starty, endx - startx,
starty - endy, null);
} catch (MalformedURLException mue) {
// cannot normally occur because, if URL is wrong, constructing FopImage
// will already have failed earlier on
}
}
}
currentYPosition -= h;
}
public void renderWordArea(WordArea area) {
char ch;
StringBuffer pdf = new StringBuffer();
String name = area.getFontState().getFontName();
int size = area.getFontState().getFontSize();
boolean underlined = area.getUnderlined();
float red = area.getRed();
float green = area.getGreen();
float blue = area.getBlue();
FontMetricsMapper mapper;
try {
mapper =
(FontMetricsMapper)area.getFontState().getFontInfo().getMetricsFor(name);
} catch (FOPException iox) {
mapper = new FontMetricsMapper("MonoSpaced", java.awt.Font.PLAIN,
graphics);
}
if ((!name.equals(this.currentFontName))
|| (size != this.currentFontSize)) {
this.currentFontName = name;
this.currentFontSize = size;
}
if ((red != this.currentRed) || (green != this.currentGreen)
|| (blue != this.currentBlue)) {
this.currentRed = red;
this.currentGreen = green;
this.currentBlue = blue;
}
int rx = this.currentXPosition;
int bl = this.currentYPosition;
String s; // = area.getText();
if (area.getPageNumberID()
!= null) { // this text is a page number, so resolve it
s = idReferences.getPageNumber(area.getPageNumberID());
if (s == null) {
s = "";
}
} else {
s = area.getText();
}
Color oldColor = graphics.getColor();
java.awt.Font oldFont = graphics.getFont();
java.awt.Font f = mapper.getFont(size);
if (saveColor != null) {
if (saveColor.getRed() != red || saveColor.getGreen() != green
|| saveColor.getBlue() != blue) {
saveColor = new Color(red, green, blue);
}
} else {
saveColor = new Color(red, green, blue);
}
graphics.setColor(saveColor);
AttributedString ats = new AttributedString(s);
ats.addAttribute(TextAttribute.FONT, f);
if (underlined) {
ats.addAttribute(TextAttribute.UNDERLINE,
TextAttribute.UNDERLINE_ON);
}
AttributedCharacterIterator iter = ats.getIterator();
// correct integer roundoff
// graphics.drawString(iter, rx / 1000f,
// (int)(pageHeight - bl / 1000f));
graphics.drawString(iter, (rx + 500) / 1000,
(int)(pageHeight - (bl + 500) / 1000));
graphics.setColor(oldColor);
this.currentXPosition += area.getContentWidth();
}
public void renderInlineSpace(InlineSpace space) {
this.currentXPosition += space.getSize();
}
/**
* render leader area into AWT
*
* @param area area to render
*/
// call to addRect corrected by aml/rlc
public void renderLeaderArea(LeaderArea area) {
int rx = this.currentXPosition;
int ry = this.currentYPosition;
int w = area.getLeaderLength();
int h = area.getHeight();
int th = area.getRuleThickness();
int st = area.getRuleStyle(); // not used at the moment
float r = area.getRed();
float g = area.getGreen();
float b = area.getBlue();
Color oldColor = graphics.getColor();
graphics.setColor(new Color(r, g, b));
// use helper function to correct integer roundoff - aml/rlc
// graphics.fillRect((int)(rx / 1000f),
// (int)(pageHeight - ry / 1000f), (int)(w / 1000f),
// (int)(th / 1000f));
addRect(rx, ry, w, -th, false); // NB addRect expects negative height
graphics.setColor(oldColor);
this.currentXPosition += area.getContentWidth();
}
public void renderSVGArea(SVGArea area) {
int x = this.currentXPosition;
int y = this.currentYPosition;
int w = area.getContentWidth();
int h = area.getHeight();
Document doc = area.getSVGDocument();
renderSVGDocument(doc, x, y);
this.currentXPosition += area.getContentWidth();
}
protected void renderSVGDocument(Document doc, int x, int y) {
MUserAgent userAgent = new MUserAgent(new AffineTransform());
userAgent.setLogger(log);
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
GraphicsNode root;
// correct integer roundoff aml/rlc
// graphics.translate(x / 1000f, pageHeight - y / 1000f);
graphics.translate((x + 500) / 1000, pageHeight - (y + 500) / 1000);
try {
root = builder.build(ctx, doc);
root.paint(graphics);
} catch (Exception e) {
e.printStackTrace();
}
// correct integer roundoff aml/rlc
// graphics.translate(-x / 1000f, y / 1000f - pageHeight);
graphics.translate(-(x + 500) / 1000, (y + 500) / 1000 - pageHeight);
}
public void setProducer(String producer) {
// defined in Renderer Interface
}
public int print(Graphics g, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if (pageIndex >= pageList.size())
return NO_SUCH_PAGE;
Graphics2D oldGraphics = graphics;
int oldPageNumber = pageNumber;
graphics = (Graphics2D)g;
Page aPage = (Page)pageList.elementAt(pageIndex);
renderPage(aPage);
graphics = oldGraphics;
return PAGE_EXISTS;
}
public int getNumberOfPages() {
return pageList.size();
}
public PageFormat getPageFormat(int pageIndex)
throws IndexOutOfBoundsException {
if (pageIndex >= pageList.size())
return null;
Page page = (Page)pageList.elementAt(pageIndex);
PageFormat pageFormat = new PageFormat();
Paper paper = new Paper();
double width = page.getWidth();
double height = page.getHeight();
// if the width is greater than the height assume lanscape mode
// and swap the width and height values in the paper format
if (width > height) {
paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
paper.setSize(height / 1000d, width / 1000d);
pageFormat.setOrientation(PageFormat.LANDSCAPE);
} else {
paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
paper.setSize(width / 1000d, height / 1000d);
pageFormat.setOrientation(PageFormat.PORTRAIT);
}
pageFormat.setPaper(paper);
return pageFormat;
}
public Printable getPrintable(int pageIndex)
throws IndexOutOfBoundsException {
return this;
}
public void setProgressListener(ProgressListener l) {
progressListener = l;
}
public static Color colorType2Color(ColorType ct) {
if (ct == null) {
return null;
}
return new Color(ct.red(), ct.green(), ct.blue());
}
/**
* Draws an image.
* TODO: protect other image formats (JIMI)
*/
/*
* public void renderImage(String href, float x, float y, float width,
* float height, Vector transform) {
* // What is with transformations?
* try {
* URL url = new URL(href);
* ImageIcon imageIcon = new ImageIcon(url);
* AffineTransform fullTransform = new AffineTransform();
* AffineTransform aTransform;
* transform = (transform == null) ? new Vector() : transform;
* for (int i = 0; i < transform.size(); i++) {
* org.w3c.dom.svg.SVGTransform t =
* (org.w3c.dom.svg.SVGTransform)
* transform.elementAt(i);
* SVGMatrix matrix = t.getMatrix();
* aTransform = new AffineTransform(matrix.getA(),
* matrix.getB(), matrix.getC(), matrix.getD(),
* matrix.getE(), matrix.getF());
* fullTransform.concatenate(aTransform);
* }
* BufferedImage bi = new BufferedImage((int) width, (int) height,
* BufferedImage.TYPE_INT_RGB);
* Graphics2D g2d = bi.createGraphics();
* BufferedImageOp bop = new AffineTransformOp(fullTransform,
* AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
* g2d.drawImage(imageIcon.getImage(), 0, 0, (int) width,
* (int) height, imageIcon.getImageObserver());
* graphics.drawImage(bi, bop, (int) x, (int) y);
* } catch (Exception ex) {
* log.error("AWTRenderer: renderImage(): " +
* ex.getMessage(), ex);
* }
* }
*/
public void renderForeignObjectArea(ForeignObjectArea area) {
area.getObject().render(this);
}
protected class MUserAgent extends org.apache.fop.svg.SVGUserAgent {
/**
* Creates a new SVGUserAgent.
*/
protected MUserAgent(AffineTransform at) {
super(at);
}
/**
* Opens a link in a new component.
* @param doc The current document.
* @param uri The document URI.
*/
public void openLink(SVGAElement elt) {
// application.openLink(uri);
}
public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}
public void setSVGCursor(java.awt.Cursor cursor) {}
public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}
public EventDispatcher getEventDispatcher() {
return null;
}
}
public void startRenderer(OutputStream outputStream)
throws IOException {}
public void stopRenderer(OutputStream outputStream)
throws IOException {
render(0);
}
}
|