View | Details | Raw Unified | Return to bug 24438
Collapse All | Expand All

(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\apps\PrintStarter.java (-2 / +2 lines)
Lines 194-201 Link Here
194
        }
194
        }
195
195
196
        public void renderPage(Page page) {
196
        public void renderPage(Page page) {
197
            pageWidth = (int)((float)page.getWidth() / 1000f);
197
            pageWidth = page.getWidth() / 1000f;
198
            pageHeight = (int)((float)page.getHeight() / 1000f);
198
            pageHeight = page.getHeight() / 1000f;
199
            super.renderPage(page);
199
            super.renderPage(page);
200
        }
200
        }
201
201
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\awt\AWTRenderer.java (-208 / +70 lines)
Lines 94-101 Link Here
94
*/
94
*/
95
public class AWTRenderer extends AbstractRenderer implements Printable, Pageable {
95
public class AWTRenderer extends AbstractRenderer implements Printable, Pageable {
96
96
97
    protected int pageWidth = 0;
97
    protected float pageWidth = 0;
98
    protected int pageHeight = 0;
98
    protected float pageHeight = 0;
99
    protected double scaleFactor = 100.0;
99
    protected double scaleFactor = 100.0;
100
    protected int pageNumber = 0;
100
    protected int pageNumber = 0;
101
    protected Vector pageList = new Vector();
101
    protected Vector pageList = new Vector();
Lines 191-298 Link Here
191
    }
191
    }
192
192
193
    /**
193
    /**
194
     * add a line to the current stream
195
     *
196
     * @param x1 the start x location in millipoints
197
     * @param y1 the start y location in millipoints
198
     * @param x2 the end x location in millipoints
199
     * @param y2 the end y location in millipoints
200
     * @param th the thickness in millipoints
201
     * @param r the red component
202
     * @param g the green component
203
     * @param b the blue component
204
     */
205
206
    // corrected 7/13/01 aml,rlc to properly handle thickness
207
    //
208
    protected void addLine(int x1, int y1, int x2, int y2, int th, float r,
209
                           float g, float b) {
210
        graphics.setColor(new Color(r, g, b));
211
        int x = x1;
212
        int y = y1;
213
        int height, width;
214
        if (x1 == x2)    // vertical line
215
        {
216
            height = y2 - y1;
217
            if (height > 0)    // y coordinates are reversed between fo and AWT
218
            {
219
                height = -height;
220
                y = y2;
221
            }
222
            width = th;
223
            if (width < 0) {
224
                width = -width;
225
                x -= width;
226
            }
227
        } else           // horizontal line
228
        {
229
            width = x2 - x1;
230
            if (width < 0) {
231
                width = -width;
232
                x = x2;
233
            }
234
            height = th;
235
            if (height > 0)    // y coordinates are reversed between fo and AWT
236
            {
237
                height = -height;
238
                y -= height;
239
            }
240
        }
241
        addRect(x, y, width, height, false);
242
243
        // // graphics.setColor(Color.red);
244
        // graphics.drawLine((int)(x1 / 1000f),
245
        // pageHeight - (int)(y1 / 1000f), (int)(x2 / 1000f),
246
        // pageHeight - (int)(y2 / 1000f));
247
    }
248
249
250
    /**
251
     * draw a rectangle
252
     *
253
     * @param x the x position of left edge in millipoints
254
     * @param y the y position of top edge in millipoints
255
     * @param w the width in millipoints
256
     * @param h the height in millipoints
257
     * @param r the red component
258
     * @param g the green component
259
     * @param b the blue component
260
     */
261
    // changed by aml/rlc to use helper function that
262
    // corrects for integer roundoff, and to remove 3D effect
263
    protected void addRect(int x, int y, int w, int h, float r, float g,
264
                           float b) {
265
        graphics.setColor(new Color(r, g, b));
266
        // graphics.setColor(Color.green);
267
        addRect(x, y, w, h, true);
268
    }
269
270
    /**
271
     * draw a filled rectangle
272
     *
273
     * @param x the x position of left edge in millipoints
274
     * @param y the y position of top edge in millipoints
275
     * @param w the width in millipoints
276
     * @param h the height in millipoints
277
     * @param r the red component of edges
278
     * @param g the green component of edges
279
     * @param b the blue component of edges
280
     * @param fr the red component of the fill
281
     * @param fg the green component of the fill
282
     * @param fb the blue component of the fill
283
     */
284
285
    // changed by aml/rlc to use helper function that
286
    // corrects for integer roundoff
287
    protected void addRect(int x, int y, int w, int h, float r, float g,
288
                           float b, float fr, float fg, float fb) {
289
        graphics.setColor(new Color(r, g, b));
290
        addRect(x, y, w, h, true);
291
        graphics.setColor(new Color(fr, fg, fb));
292
        addRect(x, y, w, h, false);
293
    }
294
295
    /**
296
     * draw a filled rectangle in the current color
194
     * draw a filled rectangle in the current color
297
     *
195
     *
298
     * @param x the x position of left edge in millipoints
196
     * @param x the x position of left edge in millipoints
Lines 305-323 Link Here
305
    // helper function by aml/rlc to correct integer roundoff problems
203
    // helper function by aml/rlc to correct integer roundoff problems
306
    //
204
    //
307
    protected void addRect(int x, int y, int w, int h,
205
    protected void addRect(int x, int y, int w, int h,
308
                           boolean drawAsOutline) {
206
                           float r, float g, float b) {
309
        int startx = (x + 500) / 1000;
207
        graphics.setColor(new Color(r, g, b));
310
        int starty = pageHeight - ((y + 500) / 1000);
208
        
311
        int endx = (x + w + 500) / 1000;
209
        if ( h < 0 ) {
312
        int endy = pageHeight - ((y + h + 500) / 1000);
210
             y += h;
313
        if (drawAsOutline) {
211
             h = -h;
314
            graphics.drawRect(startx, starty, endx - startx, endy - starty);
315
        } else {
316
            //don't round down to zero
317
            if (w != 0 && endx == startx) endx++;
318
            if (h != 0 && endy == starty) endy++;
319
            graphics.fillRect(startx, starty, endx - startx, endy - starty);
320
        }
212
        }
213
        
214
        Shape rect = new Rectangle2D.Double(x / 1000d,
215
                pageHeight - ( y + h ) / 1000d,
216
                w / 1000d,
217
                h / 1000d );
218
        
219
        graphics.fill(rect);
321
    }
220
    }
322
221
323
    protected void addFilledRect(int x, int y, int w, int h,
222
    protected void addFilledRect(int x, int y, int w, int h,
Lines 325-331 Link Here
325
        float r = col.red();
224
        float r = col.red();
326
        float g = col.green();
225
        float g = col.green();
327
        float b = col.blue();
226
        float b = col.blue();
328
        addRect(x, y, w, h, r, g, b, r, g, b);
227
        addRect(x, y, w, h, r, g, b);
329
    }
228
    }
330
229
331
    /**
230
    /**
Lines 344-351 Link Here
344
243
345
    protected void drawFrame() {
244
    protected void drawFrame() {
346
245
347
        int width = pageWidth;
246
        int width = (int)pageWidth;
348
        int height = pageHeight;
247
        int height = (int)pageHeight;
349
248
350
        graphics.setColor(Color.white);
249
        graphics.setColor(Color.white);
351
        graphics.fillRect(0, 0, width, height);
250
        graphics.fillRect(0, 0, width, height);
Lines 394-401 Link Here
394
    throws IOException {
293
    throws IOException {
395
        idReferences = page.getIDReferences();
294
        idReferences = page.getIDReferences();
396
295
397
        pageWidth = (int)((float)page.getWidth() / 1000f + .5);
296
        pageWidth = page.getWidth() / 1000f;
398
        pageHeight = (int)((float)page.getHeight() / 1000f + .5);
297
        pageHeight = page.getHeight() / 1000;
399
298
400
299
401
        pageImage =
300
        pageImage =
Lines 447-496 Link Here
447
        w = w + area.getPaddingLeft() + area.getPaddingRight();
346
        w = w + area.getPaddingLeft() + area.getPaddingRight();
448
        h = h + area.getPaddingTop() + area.getPaddingBottom();
347
        h = h + area.getPaddingTop() + area.getPaddingBottom();
449
348
450
    doBackground(area, rx, ry, w, h);
349
        doBackground(area, rx, ry, w, h);
451
350
452
        rx = rx - area.getBorderLeftWidth();
351
        int left = area.getBorderLeftWidth();
453
        ry = ry + area.getBorderTopWidth();
352
        int right = area.getBorderRightWidth();
454
        w = w + area.getBorderLeftWidth() + area.getBorderRightWidth();
353
        int top = area.getBorderTopWidth();
455
        h = h + area.getBorderTopWidth() + area.getBorderBottomWidth();
354
        int bottom = area.getBorderBottomWidth();
456
355
457
        BorderAndPadding bp = area.getBorderAndPadding();
356
        BorderAndPadding bp = area.getBorderAndPadding();
458
        ColorType borderColor;
459
357
460
        if (area.getBorderTopWidth() != 0) {
358
        if (top != 0)
461
            borderColor = bp.getBorderColor(BorderAndPadding.TOP);
359
            addFilledRect(rx, ry, w, top,
462
            // addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(),   // corrected aml/rlc
360
                          bp.getBorderColor(BorderAndPadding.TOP));
463
            addLine(rx, ry, rx + w, ry, -area.getBorderTopWidth(),
361
        if (left != 0)
464
                    borderColor.red(), borderColor.green(),
362
            addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom,
465
                    borderColor.blue());
363
                          bp.getBorderColor(BorderAndPadding.LEFT));
466
        }
364
        if (right != 0)
467
365
            addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom,
468
        if (area.getBorderLeftWidth() != 0) {
366
                          bp.getBorderColor(BorderAndPadding.RIGHT));
469
            borderColor = bp.getBorderColor(BorderAndPadding.LEFT);
367
        if (bottom != 0)
470
            addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(),
368
            addFilledRect(rx, ry - h - bottom, w, bottom,
471
                    borderColor.red(), borderColor.green(),
369
                          bp.getBorderColor(BorderAndPadding.BOTTOM));
472
                    borderColor.blue());
473
        }
474
475
        if (area.getBorderRightWidth() != 0) {
476
            borderColor = bp.getBorderColor(BorderAndPadding.RIGHT);
477
            addLine(rx + w, ry, rx + w, ry - h,
478
                    // area.getBorderRightWidth(), borderColor.red(), // corrected aml/rlc
479
                    -area.getBorderRightWidth(), borderColor.red(),
480
                    borderColor.green(),
481
                    borderColor.blue());
482
        }
483
484
        if (area.getBorderBottomWidth() != 0) {
485
            borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM);
486
            addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(),
487
                    borderColor.red(), borderColor.green(),
488
                    borderColor.blue());
489
        }
490
    }
370
    }
491
371
492
493
494
    protected Rectangle2D getBounds(org.apache.fop.layout.Area a) {
372
    protected Rectangle2D getBounds(org.apache.fop.layout.Area a) {
495
        return new Rectangle2D.Double(currentAreaContainerXPosition,
373
        return new Rectangle2D.Double(currentAreaContainerXPosition,
496
                                      currentYPosition,
374
                                      currentYPosition,
Lines 552-557 Link Here
552
430
553
    // correct integer roundoff    (aml/rlc)
431
    // correct integer roundoff    (aml/rlc)
554
432
433
    private final static ColorType ABSENT_IMAGE_COLOR =
434
            new ColorType(0.3f, 0.3f, 0.3f);
435
    
555
    public void renderImageArea(ImageArea area) {
436
    public void renderImageArea(ImageArea area) {
556
437
557
        int x = currentXPosition + area.getXOffset();
438
        int x = currentXPosition + area.getXOffset();
Lines 568-574 Link Here
568
            // correct integer roundoff
449
            // correct integer roundoff
569
            // graphics.drawRect(x / 1000, pageHeight - y / 1000,
450
            // graphics.drawRect(x / 1000, pageHeight - y / 1000,
570
            // w / 1000, h / 1000);
451
            // w / 1000, h / 1000);
571
            addRect(x, y, w, h, true);    // use helper function
452
            addFilledRect(x, y, w, h, ABSENT_IMAGE_COLOR);    // use helper function
572
453
573
454
574
            java.awt.Font f = graphics.getFont();
455
            java.awt.Font f = graphics.getFont();
Lines 581-588 Link Here
581
            // graphics.drawString("area.getImage() is null", x / 1000,
462
            // graphics.drawString("area.getImage() is null", x / 1000,
582
            // pageHeight - y / 1000);
463
            // pageHeight - y / 1000);
583
464
584
            graphics.drawString("area.getImage() is null", (x + 500) / 1000,
465
            graphics.drawString("area.getImage() is null", x / 1000f,
585
                                pageHeight - (y + 500) / 1000);
466
                                pageHeight - y / 1000f);
586
467
587
468
588
            graphics.setFont(f);
469
            graphics.setFont(f);
Lines 602-620 Link Here
602
                    ImageIcon icon = new ImageIcon(url);
483
                    ImageIcon icon = new ImageIcon(url);
603
                    Image image = icon.getImage();
484
                    Image image = icon.getImage();
604
485
605
                    // correct integer roundoff      aml/rlc
486
                    int imageWidth = image.getWidth(null);
606
                    // graphics.drawImage(image, x / 1000,
487
                    int imageHeight = image.getHeight(null);
607
                    // pageHeight - y / 1000, w / 1000, h / 1000,
488
                    
608
                    // null);
489
                    AffineTransform imageTr = graphics.getTransform();
609
490
                    imageTr.translate(x, pageHeight - y);
610
                    int startx = (x + 500) / 1000;
491
                    imageTr.scale((double)w / imageWidth,
611
                    int starty = pageHeight - ((y + 500) / 1000);
492
                            (double)h / imageHeight);
612
                    int endx = (x + w + 500) / 1000;
613
                    int endy = pageHeight - ((y + h + 500) / 1000);
614
493
615
                    // reverse start and end y because h is positive
494
                    // reverse start and end y because h is positive
616
                    graphics.drawImage(image, startx, starty, endx - startx,
495
                    graphics.drawImage(image, imageTr, null);
617
                                       starty - endy, null);
618
496
619
                } catch (MalformedURLException mue) {
497
                } catch (MalformedURLException mue) {
620
                    // cannot normally occur because, if URL is wrong, constructing FopImage
498
                    // cannot normally occur because, if URL is wrong, constructing FopImage
Lines 689-696 Link Here
689
        graphics.setFont(f);
567
        graphics.setFont(f);
690
568
691
        // correct starting location for integer roundoff
569
        // correct starting location for integer roundoff
692
        int newx = (int)(rx + 500) / 1000;
570
        float newx = rx / 1000f;
693
        int newy = (int)(pageHeight - (bl + 500) / 1000);
571
        float newy = pageHeight - bl / 1000f;
694
572
695
        // draw text, corrected for integer roundoff
573
        // draw text, corrected for integer roundoff
696
        graphics.drawString(s, newx, newy);
574
        graphics.drawString(s, newx, newy);
Lines 730-736 Link Here
730
                graphics.setColor(this.lastColor);
608
                graphics.setColor(this.lastColor);
731
            }
609
            }
732
610
733
            int width = (int)(space.getSize() + 500) / 1000;
611
            double width = space.getSize() / 1000d;
734
            renderTextDecoration(rx, bl, width, graphics.getFont(), " ",
612
            renderTextDecoration(rx, bl, width, graphics.getFont(), " ",
735
                    space.getUnderlined(),
613
                    space.getUnderlined(),
736
                    space.getOverlined(),
614
                    space.getOverlined(),
Lines 744-782 Link Here
744
    }
622
    }
745
623
746
624
747
    protected void renderTextDecoration(int x, int bl, int width,
625
    protected void renderTextDecoration(int x, int bl, double width,
748
                    java.awt.Font font, String text,
626
                    java.awt.Font font, String text,
749
                    boolean underline,
627
                    boolean underline,
750
                    boolean overline,
628
                    boolean overline,
751
                    boolean linethrough) {
629
                    boolean linethrough) {
752
        if (!(underline || overline || linethrough)) return;
630
        if (!(underline || overline || linethrough)) return;
753
        int newx = (int)(x + 500) / 1000;
631
        double newx = x / 1000d;
754
        int newy = (int)(pageHeight - (bl + 500) / 1000);
632
        double newy = pageHeight - bl / 1000d;
755
633
756
        // text decorations
634
        // text decorations
757
        FontMetrics fm = graphics.getFontMetrics(font);
635
        FontMetrics fm = graphics.getFontMetrics(font);
758
        LineMetrics lm = fm.getLineMetrics(text, graphics);
636
        LineMetrics lm = fm.getLineMetrics(text, graphics);
759
637
760
        int ulthick = (int)lm.getUnderlineThickness();
638
        double ulthick = lm.getUnderlineThickness();
761
        if (ulthick < 1)
762
            ulthick = 1;   // don't allow it to disappear
763
        if (underline) {
639
        if (underline) {
764
            // nothing in awt specifies underline location,
640
            // nothing in awt specifies underline location,
765
            // descent/2 seems to match my word processor
641
            // descent/2 seems to match my word processor
766
            int deltay = fm.getDescent() / 2;
642
            int deltay = fm.getDescent() / 2;
767
            graphics.fillRect(newx, newy + deltay, width, ulthick);
643
            graphics.fill(new Rectangle2D.Double(
644
                    newx, newy + deltay, width, ulthick));
768
        }
645
        }
769
        if (overline) {
646
        if (overline) {
770
            // todo: maybe improve positioning of overline
647
            // todo: maybe improve positioning of overline
771
            int deltay = -(int)(lm.getAscent() * 0.8);
648
            int deltay = -(int)(lm.getAscent() * 0.8);
772
            graphics.fillRect(newx, newy + deltay, width, ulthick);
649
            graphics.fill(new Rectangle2D.Double(
650
                    newx, newy + deltay, width, ulthick));
773
        }
651
        }
774
        if (linethrough) {
652
        if (linethrough) {
775
            int ltthick = (int)lm.getStrikethroughThickness();
653
            int ltthick = (int)lm.getStrikethroughThickness();
776
            if (ltthick < 1)
654
            if (ltthick < 1)
777
                ltthick = 1;   // don't allow it to disappear
655
                ltthick = 1;   // don't allow it to disappear
778
            int deltay = (int)lm.getStrikethroughOffset();
656
            int deltay = (int)lm.getStrikethroughOffset();
779
            graphics.fillRect(newx, newy + deltay, width, ltthick);
657
            graphics.fill(new Rectangle2D.Double(
658
                    newx, newy + deltay, width, ltthick));
780
        }
659
        }
781
    }
660
    }
782
661
Lines 795-815 Link Here
795
        int ry = this.currentYPosition;
674
        int ry = this.currentYPosition;
796
        int w = area.getLeaderLength();
675
        int w = area.getLeaderLength();
797
        int h = area.getHeight();
676
        int h = area.getHeight();
798
        int th = area.getRuleThickness();
799
        int st = area.getRuleStyle();    // not used at the moment
677
        int st = area.getRuleStyle();    // not used at the moment
800
        float r = area.getRed();
678
        float r = area.getRed();
801
        float g = area.getGreen();
679
        float g = area.getGreen();
802
        float b = area.getBlue();
680
        float b = area.getBlue();
803
        Color oldColor = graphics.getColor();
681
        Color oldColor = graphics.getColor();
804
682
805
        graphics.setColor(new Color(r, g, b));
806
807
        // use helper function to correct integer roundoff   - aml/rlc
683
        // use helper function to correct integer roundoff   - aml/rlc
808
        // graphics.fillRect((int)(rx / 1000f),
684
        // graphics.fillRect((int)(rx / 1000f),
809
        // (int)(pageHeight - ry / 1000f), (int)(w / 1000f),
685
        // (int)(pageHeight - ry / 1000f), (int)(w / 1000f),
810
        // (int)(th / 1000f));
686
        // (int)(th / 1000f));
811
687
812
        addRect(rx, ry, w, -th, false);    // NB addRect expects negative height
688
        // NB addRect expects negative height
689
        addRect(rx, ry, w, h, r, g, b);
813
690
814
        graphics.setColor(oldColor);
691
        graphics.setColor(oldColor);
815
        this.currentXPosition += area.getContentWidth();
692
        this.currentXPosition += area.getContentWidth();
Lines 844-876 Link Here
844
        float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
721
        float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
845
        float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
722
        float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
846
723
847
        // correct integer roundoff     aml/rlc
724
        Graphics2D newGraphics = (Graphics2D)graphics.create();
848
        // graphics.translate(x / 1000f, pageHeight - y / 1000f);
725
        newGraphics.translate(x / 1000d, pageHeight - y / 1000d);
849
        graphics.translate((x + 500) / 1000, pageHeight - (y + 500) / 1000);
850
726
851
        SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
727
        SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
852
        AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f);
728
        AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f);
853
        AffineTransform inverse = null;
729
        newGraphics.transform(at);
854
        try {
855
            inverse = at.createInverse();
856
        } catch(NoninvertibleTransformException e) {
857
        }
858
        if(!at.isIdentity()) {
859
            graphics.transform(at);
860
        }
861
730
862
        try {
731
        try {
863
            root.paint(graphics);
732
            root.paint(newGraphics);
864
        } catch (Exception e) {
733
        } catch (Exception e) {
865
            e.printStackTrace();
734
            e.printStackTrace();
866
        }
735
        }
867
868
        if(inverse != null && !inverse.isIdentity()) {
869
            graphics.transform(inverse);
870
        }
871
        // correct integer roundoff     aml/rlc
872
        // graphics.translate(-x / 1000f, y / 1000f - pageHeight);
873
        graphics.translate(-(x + 500) / 1000, (y + 500) / 1000 - pageHeight);
874
736
875
    }
737
    }
876
738
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pcl\PCLRenderer.java (-55 / +8 lines)
Lines 132-140 Link Here
132
    protected void addLine(int x1, int y1, int x2, int y2, int th,
132
    protected void addLine(int x1, int y1, int x2, int y2, int th,
133
                           PDFPathPaint stroke) {
133
                           PDFPathPaint stroke) {
134
        if (x1 == x2)
134
        if (x1 == x2)
135
            addRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke, stroke);
135
            addFilledRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke);
136
        else if (y1 == y2)
136
        else if (y1 == y2)
137
            addRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke, stroke);
137
            addFilledRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke);
138
    }
138
    }
139
139
140
    /**
140
    /**
Lines 174-184 Link Here
174
                while (start < y2) {
174
                while (start < y2) {
175
                    if (start + len > y2)
175
                    if (start + len > y2)
176
                        len = y2 - start;
176
                        len = y2 - start;
177
                    addRect(x1 - (th / 2), start, th, len, stroke, stroke);
177
                    addFilledRect(x1 - (th / 2), start, th, len, stroke);
178
                    start += (len + dashoff * th);
178
                    start += (len + dashoff * th);
179
                }
179
                }
180
            } else
180
            } else
181
                addRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke, stroke);
181
                addFilledRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke);
182
        } else if (y1 == y2) {
182
        } else if (y1 == y2) {
183
            if (dashon > 0 && dashoff > 0) {
183
            if (dashon > 0 && dashoff > 0) {
184
                int start = x1;
184
                int start = x1;
Lines 186-225 Link Here
186
                while (start < x2) {
186
                while (start < x2) {
187
                    if (start + len > x2)
187
                    if (start + len > x2)
188
                        len = x2 - start;
188
                        len = x2 - start;
189
                    addRect(start, y1 + (th / 2), len, th, stroke, stroke);
189
                    addFilledRect(start, y1 + (th / 2), len, th, stroke);
190
                    start += (len + dashoff * th);
190
                    start += (len + dashoff * th);
191
                }
191
                }
192
            } else
192
            } else
193
                addRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke, stroke);
193
                addFilledRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke);
194
        }
195
    }
196
197
    /**
198
     * add a rectangle to the current stream
199
     *
200
     * @param x the x position of left edge in millipoints
201
     * @param y the y position of top edge in millipoints
202
     * @param w the width in millipoints
203
     * @param h the height in millipoints
204
     * @param stroke the stroke color/gradient
205
     */
206
    protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) {
207
        //if (h < 0)
208
        //    h *= -1;
209
210
        if ((h >= 0 && h < 720) || (h < 0 && h > -720) || w < 720) {
211
            if (w < 720)
212
                w = 720;
213
            if (h > 0 && h < 720)
214
                h = 720;
215
            else if (h < 0 && h > -720)
216
                h = -720;
217
            addRect(x, y, w, h, stroke, stroke);
218
        } else {
219
            addRect(x, y, w, 720, stroke, stroke);
220
            addRect(x, y, 720, h, stroke, stroke);
221
            addRect(x + w - 720, y, 720, h, stroke, stroke);
222
            addRect(x, y - h + 720, w, 720, stroke, stroke);
223
        }
194
        }
224
    }
195
    }
225
196
Lines 233-239 Link Here
233
     * @param fill the fill color/gradient
204
     * @param fill the fill color/gradient
234
     * @param stroke the stroke color/gradient
205
     * @param stroke the stroke color/gradient
235
     */
206
     */
236
    protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke,
207
    protected void addFilledRect(int x, int y, int w, int h,
237
                           PDFPathPaint fill) {
208
                           PDFPathPaint fill) {
238
        if ((w == 0) || (h == 0))
209
        if ((w == 0) || (h == 0))
239
            return;
210
            return;
Lines 243-258 Link Here
243
            y += h;
214
            y += h;
244
215
245
216
246
        PDFColor sc = (PDFColor)stroke;
247
        PDFColor fc = (PDFColor)fill;
217
        PDFColor fc = (PDFColor)fill;
248
218
249
        sc.setColorSpace(ColorSpace.DEVICE_RGB);
250
        fc.setColorSpace(ColorSpace.DEVICE_RGB);
219
        fc.setColorSpace(ColorSpace.DEVICE_RGB);
251
220
252
        int lineshade =
253
            (int)(100
254
                  - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue())
255
                     * 100f));
256
        int fillshade =
221
        int fillshade =
257
            (int)(100
222
            (int)(100
258
                  - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue())
223
                  - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue())
Lines 267-285 Link Here
267
        currentStream.add("\033*v1O\033&a" + xpos + "h"
232
        currentStream.add("\033*v1O\033&a" + xpos + "h"
268
                          + (pageHeight - (y / 100)) + "V" + "\033*c"
233
                          + (pageHeight - (y / 100)) + "V" + "\033*c"
269
                          + (w / 100) + "h" + (h / 100) + "V" + "\033*c"
234
                          + (w / 100) + "h" + (h / 100) + "V" + "\033*c"
270
                          + lineshade + "G" + "\033*c2P");
235
                          + fillshade + "G" + "\033*c2P");
271
        if (fillshade != lineshade && (w >= 720 || h >= 720)) {
272
            xpos = xoffset + ((x + 240) / 100);
273
            if (xpos < 0) {
274
                xpos = 0;
275
                log.warn("Horizontal position out of bounds.");
276
            }
277
            currentStream.add("\033&a" + xpos + "h"
278
                              + (pageHeight - ((y + 240)) / 100) + "V"
279
                              + "\033*c" + ((w - 480) / 100) + "h"
280
                              + ((h - 480) / 100) + "V" + "\033*c"
281
                              + fillshade + "G" + "\033*c2P");
282
        }
283
        // Reset pattern transparency mode.
236
        // Reset pattern transparency mode.
284
        currentStream.add("\033*v0O");
237
        currentStream.add("\033*v0O");
285
    }
238
    }
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pdf\PDFRenderer.java (-36 lines)
Lines 302-343 Link Here
302
    }
302
    }
303
303
304
    /**
304
    /**
305
     * add a rectangle to the current stream
306
     *
307
     * @param x       the x position of left edge in millipoints
308
     * @param y       the y position of top edge in millipoints
309
     * @param w       the width in millipoints
310
     * @param h       the height in millipoints
311
     * @param stroke  the stroke color/gradient
312
     */
313
    protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) {
314
        closeText();
315
        currentStream.add("ET\nq\n" + stroke.getColorSpaceOut(false)
316
                + (x / 1000f) + " " + (y / 1000f) + " "
317
                + (w / 1000f) + " " + (h / 1000f) + " re s\n"
318
                + "Q\nBT\n");
319
    }
320
321
    /**
322
     * add a filled rectangle to the current stream
323
     *
324
     * @param x       the x position of left edge in millipoints
325
     * @param y       the y position of top edge in millipoints
326
     * @param w       the width in millipoints
327
     * @param h       the height in millipoints
328
     * @param fill    the fill color/gradient
329
     * @param stroke  the stroke color/gradient
330
     */
331
    protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke,
332
            PDFPathPaint fill) {
333
        closeText();
334
        currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true)
335
                + stroke.getColorSpaceOut(false) + (x / 1000f)
336
                + " " + (y / 1000f) + " " + (w / 1000f) + " "
337
                + (h / 1000f) + " re b\n" + "Q\nBT\n");
338
    }
339
340
    /**
341
     * add a filled rectangle to the current stream
305
     * add a filled rectangle to the current stream
342
     *
306
     *
343
     * @param x     the x position of left edge in millipoints
307
     * @param x     the x position of left edge in millipoints
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\PrintRenderer.java (-32 / +4 lines)
Lines 173-191 Link Here
173
                                    int rs, PDFPathPaint stroke);
173
                                    int rs, PDFPathPaint stroke);
174
174
175
    /**
175
    /**
176
     * add a rectangle to the current stream
176
     * Add a filled rectangle to the current stream.
177
     * 
178
     * @param x the x position of left edge in millipoints
179
     * @param y the y position of top edge in millipoints
180
     * @param w the width in millipoints
181
     * @param h the height in millipoints
182
     * @param stroke the stroke color/gradient
183
     */
184
    protected abstract void addRect(int x, int y, int w, int h,
185
                                    PDFPathPaint stroke);
186
187
    /**
188
     * add a filled and stroked rectangle to the current stream
189
     * 
177
     * 
190
     * @param x the x position of left edge in millipoints
178
     * @param x the x position of left edge in millipoints
191
     * @param y the y position of top edge in millipoints
179
     * @param y the y position of top edge in millipoints
Lines 194-222 Link Here
194
     * @param fill the fill color/gradient
182
     * @param fill the fill color/gradient
195
     * @param stroke the stroke color/gradient
183
     * @param stroke the stroke color/gradient
196
     */
184
     */
197
    protected abstract void addRect(int x, int y, int w, int h,
185
    protected abstract void addFilledRect(int x, int y, int w, int h,
198
                                    PDFPathPaint stroke, PDFPathPaint fill);
186
                                    PDFPathPaint fill);
199
200
    /**
201
     * Add a filled rectangle to the current stream
202
     * This default implementation calls addRect
203
     * using the same color for fill and border.
204
     * 
205
     * @param x the x position of left edge in millipoints
206
     * @param y the y position of top edge in millipoints
207
     * @param w the width in millipoints
208
     * @param h the height in millipoints
209
     * @param fill the fill color/gradient
210
     */
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
187
216
    protected void addFilledRect(int x, int y, int w, int h,
188
    protected void addFilledRect(int x, int y, int w, int h,
217
                                 ColorType col) {
189
                                 ColorType col) {
218
        PDFColor pdfcol = new PDFColor(col);
190
        PDFColor pdfcol = new PDFColor(col);
219
        addRect(x, y, w, h, pdfcol, pdfcol);
191
        addFilledRect(x, y, w, h, pdfcol);
220
    }
192
    }
221
193
222
    protected void doFrame(Area area) {
194
    protected void doFrame(Area area) {
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\svg\SVGRenderer.java (-62 / +42 lines)
Lines 159-224 Link Here
159
    }
159
    }
160
160
161
    /**
161
    /**
162
     * draw a rectangle
163
     *
164
     * @param x the x position of left edge in millipoints
165
     * @param y the y position of top edge in millipoints
166
     * @param w the width in millipoints
167
     * @param h the height in millipoints
168
     * @param r the red component
169
     * @param g the green component
170
     * @param b the blue component
171
     */
172
    protected void addRect(int x, int y, int w, int h, float r, float g,
173
                           float b) {
174
        Element rect = SVGUtilities.createRect(svgDocument, x / 1000f, pageHeight - (y / 1000f), w / 1000f, h / 1000f);
175
        rect.setAttributeNS(null, "style", "stroke:rgb(" + ((int)(255 * r)) + "," + ((int)(255 * g)) + "," + ((int)(255 * b)) + ")");
176
        currentPageG.appendChild(rect);
177
    }
178
179
    /**
180
     * draw a filled rectangle
181
     *
182
     * @param x the x position of left edge in millipoints
183
     * @param y the y position of top edge in millipoints
184
     * @param w the width in millipoints
185
     * @param h the height in millipoints
186
     * @param r the red component of edges
187
     * @param g the green component of edges
188
     * @param b the blue component of edges
189
     * @param fr the red component of the fill
190
     * @param fg the green component of the fill
191
     * @param fb the blue component of the fill
192
     */
193
    protected void addRect(int x, int y, int w, int h, float r, float g,
194
                           float b, float fr, float fg, float fb) {
195
        Element rect = SVGUtilities.createRect(svgDocument, x / 1000f, pageHeight - (y / 1000f), w / 1000f, h / 1000f);
196
        rect.setAttributeNS(null, "style", "stroke:rgb(" + ((int)(255 * r)) + "," + ((int)(255 * g)) + "," + ((int)(255 * b)) + ");fill:rgb(" + ((int)(255 * fr)) + "," + ((int)(255 * fg)) + "," + ((int)(255 * fb)) + ")");
197
        currentPageG.appendChild(rect);
198
    }
199
200
    /**
201
     * draw a filled rectangle in the current color
162
     * draw a filled rectangle in the current color
202
     *
163
     *
203
     * @param x the x position of left edge in millipoints
164
     * @param x the x position of left edge in millipoints
204
     * @param y the y position of top edge in millipoints
165
     * @param y the y position of top edge in millipoints
205
     * @param w the width in millipoints
166
     * @param w the width in millipoints
206
     * @param h the height in millipoints
167
     * @param h the height in millipoints
168
     * @param r the red component of edges/fill
169
     * @param g the green component of edges/fill
170
     * @param b the blue component of edges/fill
207
     * @param drawAsOutline true for draw, false for fill
171
     * @param drawAsOutline true for draw, false for fill
208
     */
172
     */
209
    protected void addRect(int x, int y, int w, int h,
173
    protected void addRect(int x, int y, int w, int h,
174
    		               float r, float g, float b,
210
                           boolean drawAsOutline) {
175
                           boolean drawAsOutline) {
211
        int startx = (x + 500) / 1000;
176
        float startx = x / 1000f;
212
        int starty = pageHeight - ((y + 500) / 1000);
177
        float starty = pageHeight - (y / 1000f);
213
        int endx = (x + w + 500) / 1000;
178
        float endx = (x + w) / 1000f;
214
        int endy = pageHeight - ((y + h + 500) / 1000);
179
        float endy = pageHeight - ((y + h) / 1000f);
215
        if (drawAsOutline) {
180
        if (drawAsOutline) {
216
            Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, endy - starty);
181
            Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, endy - starty);
217
            rect.setAttributeNS(null, "style", "fill:none");
182
            rect.setAttributeNS(null, "style",
183
            		"stroke:rgb(" +
184
					((int)(255 * r)) + "," +
185
					((int)(255 * g)) + "," +
186
					((int)(255 * b)) + ");" +
187
                    "fill:none");
218
            currentPageG.appendChild(rect);
188
            currentPageG.appendChild(rect);
219
        } else {
189
        } else {
220
            Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, starty - endy);
190
            Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, starty - endy);
221
            rect.setAttributeNS(null, "style", "stroke:none");
191
            rect.setAttributeNS(null, "style",
192
            		"fill:rgb(" +
193
					((int)(255 * r)) + "," +
194
					((int)(255 * g)) + "," +
195
					((int)(255 * b)) + ");" + 
196
            		"stroke:none ");
222
            currentPageG.appendChild(rect);
197
            currentPageG.appendChild(rect);
223
        }
198
        }
224
    }
199
    }
Lines 228-234 Link Here
228
        float r = col.red();
203
        float r = col.red();
229
        float g = col.green();
204
        float g = col.green();
230
        float b = col.blue();
205
        float b = col.blue();
231
        addRect(x, y, w, h, r, g, b, r, g, b);
206
        addRect(x, y, w, -h, r, g, b, false);
232
    }
207
    }
233
208
234
    protected void drawFrame() {
209
    protected void drawFrame() {
Lines 327-357 Link Here
327
302
328
    doBackground(area, rx, ry, w, h);
303
    doBackground(area, rx, ry, w, h);
329
304
330
        rx = rx - area.getBorderLeftWidth();
305
        int outerLeft = rx - area.getBorderLeftWidth();
331
        ry = ry + area.getBorderTopWidth();
306
        int middleLeft = rx - area.getBorderLeftWidth() / 2;
332
        w = w + area.getBorderLeftWidth() + area.getBorderRightWidth();
307
        int outerTop = ry + area.getBorderTopWidth();
333
        h = h + area.getBorderTopWidth() + area.getBorderBottomWidth();
308
        int middleTop = ry + area.getBorderTopWidth() / 2;
309
        int outerRight = rx + w + area.getBorderRightWidth();
310
        int middleRight = rx + w + area.getBorderRightWidth() / 2;
311
        int outerBottom = ry - h - area.getBorderBottomWidth();
312
        int middleBottom = ry - h - area.getBorderBottomWidth() / 2;
334
313
335
        BorderAndPadding bp = area.getBorderAndPadding();
314
        BorderAndPadding bp = area.getBorderAndPadding();
336
        ColorType borderColor;
315
        ColorType borderColor;
337
316
338
        if (area.getBorderTopWidth() != 0) {
317
        if (area.getBorderTopWidth() != 0) {
339
            borderColor = bp.getBorderColor(BorderAndPadding.TOP);
318
            borderColor = bp.getBorderColor(BorderAndPadding.TOP);
340
            addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(),
319
            addLine(outerLeft, middleTop, outerRight, middleTop,
320
                    area.getBorderTopWidth(),
341
                    borderColor.red(), borderColor.green(),
321
                    borderColor.red(), borderColor.green(),
342
                    borderColor.blue());
322
                    borderColor.blue());
343
        }
323
        }
344
324
345
        if (area.getBorderLeftWidth() != 0) {
325
        if (area.getBorderLeftWidth() != 0) {
346
            borderColor = bp.getBorderColor(BorderAndPadding.LEFT);
326
            borderColor = bp.getBorderColor(BorderAndPadding.LEFT);
347
            addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(),
327
            addLine(middleLeft, outerTop, middleLeft, outerBottom,
328
                    area.getBorderLeftWidth(),
348
                    borderColor.red(), borderColor.green(),
329
                    borderColor.red(), borderColor.green(),
349
                    borderColor.blue());
330
                    borderColor.blue());
350
        }
331
        }
351
332
352
        if (area.getBorderRightWidth() != 0) {
333
        if (area.getBorderRightWidth() != 0) {
353
            borderColor = bp.getBorderColor(BorderAndPadding.RIGHT);
334
            borderColor = bp.getBorderColor(BorderAndPadding.RIGHT);
354
            addLine(rx + w, ry, rx + w, ry - h,
335
            addLine(middleRight, outerTop, middleRight, outerBottom,
355
                    area.getBorderRightWidth(), borderColor.red(),
336
                    area.getBorderRightWidth(), borderColor.red(),
356
                    borderColor.green(),
337
                    borderColor.green(),
357
                    borderColor.blue());
338
                    borderColor.blue());
Lines 359-365 Link Here
359
340
360
        if (area.getBorderBottomWidth() != 0) {
341
        if (area.getBorderBottomWidth() != 0) {
361
            borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM);
342
            borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM);
362
            addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(),
343
            addLine(outerLeft, middleBottom, outerRight, middleBottom,
344
                    area.getBorderBottomWidth(),
363
                    borderColor.red(), borderColor.green(),
345
                    borderColor.red(), borderColor.green(),
364
                    borderColor.blue());
346
                    borderColor.blue());
365
        }
347
        }
Lines 436-442 Link Here
436
        if (img == null) {
418
        if (img == null) {
437
            log.error("Error while loading image : area.getImage() is null");
419
            log.error("Error while loading image : area.getImage() is null");
438
420
439
            addRect(x, y, w, h, true);    // use helper function
421
            addRect(x, y, w, h, 0, 0, 0, true);    // use helper function
440
422
441
        } else {
423
        } else {
442
            if (img instanceof SVGImage) {
424
            if (img instanceof SVGImage) {
Lines 454-463 Link Here
454
                    ImageIcon icon = new ImageIcon(url);
436
                    ImageIcon icon = new ImageIcon(url);
455
                    Image image = icon.getImage();
437
                    Image image = icon.getImage();
456
438
457
                    int startx = (x + 500) / 1000;
439
                    float startx = x / 1000f;
458
                    int starty = pageHeight - ((y + 500) / 1000);
440
                    float starty = pageHeight - y / 1000f;
459
                    int endx = (x + w + 500) / 1000;
441
                    float endx = (x + w) / 1000f;
460
                    int endy = pageHeight - ((y + h + 500) / 1000);
442
                    float endy = pageHeight - (y + h) / 1000f;
461
443
462
                    // reverse start and end y because h is positive
444
                    // reverse start and end y because h is positive
463
                    //graphics.drawImage(image, startx, starty, endx - startx,
445
                    //graphics.drawImage(image, startx, starty, endx - startx,
Lines 580-588 Link Here
580
        float g = area.getGreen();
562
        float g = area.getGreen();
581
        float b = area.getBlue();
563
        float b = area.getBlue();
582
564
583
        //graphics.setColor(new Color(r, g, b));
565
        addRect(rx, ry, w, th, r, g, b, false);
584
585
        addRect(rx, ry, w, th, false);
586
566
587
        this.currentXPosition += area.getContentWidth();
567
        this.currentXPosition += area.getContentWidth();
588
    }
568
    }
(-)C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\txt\TXTRenderer.java (-437 / +9 lines)
Lines 197-205 Link Here
197
    protected void addLine(int x1, int y1, int x2, int y2, int th,
197
    protected void addLine(int x1, int y1, int x2, int y2, int th,
198
                           PDFPathPaint stroke) {
198
                           PDFPathPaint stroke) {
199
        if (x1 == x2) {
199
        if (x1 == x2) {
200
            addRect(x1, y1, th, y2 - y1 + 1, stroke, stroke);
200
            addFilledRect(x1, y1, th, y2 - y1 + 1, stroke);
201
        } else if (y1 == y2) {
201
        } else if (y1 == y2) {
202
            addRect(x1, y1, x2 - x1 + 1, th, stroke, stroke);
202
            addFilledRect(x1, y1, x2 - x1 + 1, th, stroke);
203
        }
203
        }
204
    }
204
    }
205
205
Lines 222-482 Link Here
222
        else
222
        else
223
            lstroke = (PDFColor)stroke;
223
            lstroke = (PDFColor)stroke;
224
        if (x1 == x2) {
224
        if (x1 == x2) {
225
            addRect(x1, y1, th, y2 - y1 + 1, lstroke, lstroke);
225
            addFilledRect(x1, y1, th, y2 - y1 + 1, lstroke);
226
        } else if (y1 == y2) {
226
        } else if (y1 == y2) {
227
            addRect(x1, y1, x2 - x1 + 1, th, lstroke, lstroke);
227
            addFilledRect(x1, y1, x2 - x1 + 1, th, lstroke);
228
        }
228
        }
229
    }
229
    }
230
230
231
    protected void addLine(float x1, float y1, float x2, float y2,
232
                           PDFColor sc, float sw) {
233
        /*
234
         * SVG - Not yet implemented
235
         * if ( debug )
236
         * System.out.println("TXTRenderer.addLine(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ", " + sc + ", " + sw + ")");
237
         * if ( x1 == x2 )
238
         * {
239
         * addRect(x1 - sw/2, y1, sw, y2 - y1 + 1, 0, 0, sc, null, 0);
240
         * }
241
         * else if ( y1 == y2 || (Math.abs(y1 - y2) <= 0.24) ) // 72/300=0.24
242
         * {
243
         * addRect(x1, y1 - sw/2, x2 - x1 + 1, sw, 0, 0, sc, null, 0);
244
         * }
245
         * else if ( sc != null )
246
         * {
247
         * // Convert dimensions to characters.
248
         * //float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in
249
         * int ix1 = (int)(x1 * xFactor);
250
         * int iy1 = (int)(y1 * yFactor);
251
         * int ix2 = (int)(x2 * xFactor);
252
         * int iy2 = (int)(y2 * yFactor);
253
         * int isw = (int)(sw * xFactor);
254
         * int origix;
255
         * // Normalize
256
         * if ( iy1 > iy2 )
257
         * {
258
         * int tmp = ix1;
259
         * ix1 = ix2;
260
         * ix2 = tmp;
261
         * tmp = iy1;
262
         * iy1 = iy2;
263
         * iy2 = tmp;
264
         * }
265
         * if ( ix1 > ix2 )
266
         * {
267
         * origix = ix2;
268
         * ix1 -=ix2;
269
         * ix2 = 0;
270
         * }
271
         * else
272
         * {
273
         * origix = ix1;
274
         * ix2 -= ix1;
275
         * ix1 = 0;
276
         * }
277
         * // Convert line width to a pixel run length.
278
         * //System.out.println("TXTRenderer.addLine(" + ix1 + ", " + iy1 + ", " + ix2 + ", " + iy2 + ", " + isw + ")");
279
         * int runlen = (int)Math.sqrt(Math.pow(isw, 2) * (1 + Math.pow((ix1 - ix2) / (iy1 - iy2), 2)));
280
         * if ( runlen < 1 )
281
         * runlen = 1;
282
         * StringBuffer rlbuff = new StringBuffer();
283
         * for ( int countr = 0 ; countr < runlen ; countr++ )
284
         * rlbuff.append('*');
285
         * String rlstr = rlbuff.toString();
286
         * //System.out.println("TXTRenderer.addLine: runlen = " + runlen);
287
         * // Draw the line.
288
         * int d, dx, dy;
289
         * int Aincr, Bincr;
290
         * int xincr = 1;
291
         * int x, y;
292
         * dx = Math.abs(ix2 - ix1);
293
         * dy = iy2 - iy1;
294
         * if ( dx > dy )
295
         * {
296
         * xincr = dx / dy;
297
         * // Move to starting position.
298
         * //currentStream.add("\033*p" + origix + "x" + iy1 + "Y");
299
         * x = ix1 - runlen / 2;
300
         * iy2 += (isw / 2);
301
         * // Start raster graphics
302
         * //currentStream.add("\033*t300R\033*r" + dx + "s1A\033*b1M");
303
         * }
304
         * else
305
         * {
306
         * // Move to starting position.
307
         * //currentStream.add("\033*p" + (origix - runlen / 2) + "x" + iy1 + "Y");
308
         * x = ix1;
309
         * // Start raster graphics
310
         * //currentStream.add("\033*t300R\033*r1A\033*b1M");
311
         * }
312
         * if ( ix1 > ix2 )
313
         * xincr *= -1;
314
         * d = 2 * dx - dy;
315
         * Aincr = 2 * (dx - dy);
316
         * Bincr = 2 * dx;
317
         * y = iy1;
318
         * xferLineBytes(x, runlen, null, -1);
319
         *
320
         * for ( y = iy1 + 1 ; y <= iy2 ; y++ )
321
         * {
322
         * if ( d >= 0 )
323
         * {
324
         * x += xincr;
325
         * d += Aincr;
326
         * }
327
         * else
328
         * d += Bincr;
329
         * xferLineBytes(x, runlen, null, -1);
330
         * }
331
         * // End raster graphics
332
         * //currentStream.add("\033*rB");
333
         * // Return to regular print mode.
334
         * //currentStream.add("\033*v0t0n0O");
335
         * }
336
         */
337
    }
338
339
    private void xferLineBytes(int startpos, int bitcount, List save,
340
                               int start2) {
341
        /*
342
         * Not yet implemented
343
         * //System.out.println("TXTRenderer.xferLineBytes(" + startpos + ", " + bitcount + ")");
344
         * int curbitpos = 0;
345
         * if ( start2 > 0 && start2 <= (startpos + bitcount) )
346
         * {
347
         * bitcount += (start2 - startpos);
348
         * start2 = 0;
349
         * }
350
         * char bytes[] = new char[((start2>startpos?start2:startpos) + bitcount) / 4 + 2];
351
         * int dlen = 0;
352
         * byte dbyte = 0;
353
         * int bytepos = 0;
354
         * do
355
         * {
356
         * int bits2set;
357
         * if ( startpos < 0 )
358
         * {
359
         * bits2set = bitcount + startpos;
360
         * startpos = 0;
361
         * }
362
         * else
363
         * bits2set = bitcount;
364
         * byte bittype = 0;
365
         * do
366
         * {
367
         * if ( bytepos > 0 )
368
         * {
369
         * int inc = startpos - curbitpos;
370
         * if ( (inc) >=  (8 - bytepos) )
371
         * {
372
         * curbitpos += (8 - bytepos);
373
         * bytepos = 0;
374
         * bytes[dlen++] = (char)0;
375
         * bytes[dlen++] = (char)dbyte;
376
         * dbyte = 0;
377
         * }
378
         * else
379
         * {
380
         * bytepos += inc;
381
         * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1));
382
         * curbitpos += inc;
383
         * }
384
         * }
385
         * // Set runs of whole bytes.
386
         * int setbytes = (startpos - curbitpos) / 8;
387
         * if ( setbytes > 0 )
388
         * {
389
         * curbitpos += setbytes * 8;
390
         * while ( setbytes > 0 )
391
         * {
392
         * if ( setbytes > 256 )
393
         * {
394
         * bytes[dlen++] = 0xFF;
395
         * setbytes -= 256;
396
         * }
397
         * else
398
         * {
399
         * bytes[dlen++] = (char)((setbytes - 1) & 0xFF);
400
         * setbytes = 0;
401
         * }
402
         * bytes[dlen++] = (char)bittype;
403
         * }
404
         * }
405
         * // move to position in the first byte.
406
         * if ( curbitpos < startpos )
407
         * {
408
         * if ( bytepos == 0 )
409
         * dbyte = bittype;
410
         * bytepos += startpos - curbitpos;
411
         * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1));
412
         * curbitpos += bytepos;
413
         * startpos += bits2set;
414
         * }
415
         * else
416
         * {
417
         * startpos += bits2set;
418
         * }
419
         * if ( bittype == 0 )
420
         * bittype = (byte)0xFF;
421
         * else
422
         * bittype = 7;
423
         * } while ( bittype != 7 );
424
         * if ( start2 > 0 )
425
         * {
426
         * startpos = start2;
427
         * start2 = -1;
428
         * }
429
         * else
430
         * startpos = -1;
431
         * } while ( startpos >= 0 );
432
         * if ( bytepos > 0 )
433
         * {
434
         * bytes[dlen++] = (char)0;
435
         * bytes[dlen++] = (char)dbyte;
436
         * }
437
         * if ( save == null )
438
         * {
439
         * //currentStream.add("\033*b" + dlen + "W");
440
         * //currentStream.add(new String(bytes, 0, dlen));
441
         * }
442
         * else
443
         * {
444
         * String line = "\033*b" + dlen + "W" + new String(bytes, 0, dlen);
445
         * //currentStream.add(line);
446
         * save.add(line);
447
         * }
448
         */
449
    }
450
451
    /**
231
    /**
452
     * add a rectangle to the current stream
232
     * Add a filled rectangle to the current stream
453
     *
454
     * @param x the x position of left edge in millipoints
455
     * @param y the y position of top edge in millipoints
456
     * @param w the width in millipoints
457
     * @param h the height in millipoints
458
     * @param stroke the stroke color/gradient
459
     */
233
     */
460
    protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) {
234
    protected void addFilledRect(int x, int y, int w, int h, PDFPathPaint fill) {
461
        if (h < 0)
235
    	addRect(x, y, w, h, fill, fill);
462
            h *= -1;
463
464
        if (h < 720 || w < 720) {
465
            if (w < 720)
466
                w = 720;
467
            if (h < 720)
468
                h = 720;
469
            addRect(x, y, w, h, stroke, stroke);
470
        } else {
471
            addRect(x, y, w, 720, stroke, stroke);
472
            addRect(x, y, 720, h, stroke, stroke);
473
            addRect(x + w - 720, y, 720, h, stroke, stroke);
474
            addRect(x, y - h + 720, w, 720, stroke, stroke);
475
        }
476
    }
236
    }
477
237
    
478
    /**
238
    /**
479
     * add a filled rectangle to the current stream
239
     * Add a filled stroked rectangle to the current stream
480
     *
240
     *
481
     * @param x the x position of left edge in millipoints
241
     * @param x the x position of left edge in millipoints
482
     * @param y the y position of top edge in millipoints
242
     * @param y the y position of top edge in millipoints
Lines 588-781 Link Here
588
            }
348
            }
589
        }
349
        }
590
    }
350
    }
591
592
593
    /**
594
     * add a filled rectangle to the current stream
595
     *
596
     * @param x the x position of left edge in millipoints
597
     * @param y the y position of top edge in millipoints
598
     * @param w the width in millipoints
599
     * @param h the height in millipoints
600
     * @param r the red component of edges
601
     * @param g the green component of edges
602
     * @param b the blue component of edges
603
     * @param fr the red component of the fill
604
     * @param fg the green component of the fill
605
     * @param fb the blue component of the fill
606
     */
607
    protected void addRect(float x, float y, float w, float h, float rx,
608
                           float ry, PDFColor fc, PDFColor sc, float sw) {
609
        /*
610
         * SVG - Not yet implemented
611
         * if ( debug )
612
         * System.out.println("TXTRenderer.addRect(" + x + ", " + y + ", " + w + ", " + h + ", " + rx + ", " + ry + ", " + fc + ", " + sc + ", " + sw + ")");
613
         * float sr = 1;
614
         * float sg = 1;
615
         * float sb = 1;
616
         * float fr = 1;
617
         * float fg = 1;
618
         * float fb = 1;
619
         * if ( sc != null && sw > 0 )
620
         * {
621
         * sr = (float)sc.red();
622
         * sg = (float)sc.green();
623
         * sb = (float)sc.blue();
624
         * }
625
         * if ( fc != null )
626
         * {
627
         * fr = (float)fc.red();
628
         * fg = (float)fc.green();
629
         * fb = (float)fc.blue();
630
         * }
631
         * addRect((int)(x * 1000), (int)(pageHeight * 100 - y * 1000), (int)(w * 1000), (int)(h * 1000), sr, sg, sb, fr, fg, fb);
632
         * fc = null;
633
         * sc = null;
634
         * if ( rx == 0 || ry == 0 )
635
         * {
636
         * if ( fc != null )
637
         * {
638
         * int fillshade = (int)(100 - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue()) * 100f));
639
         * currentStream.add("\033*v0n1O\033&a" + (x * 10) + "h" + ((y * 10)) + "V"
640
         * + "\033*c" + (w * 10) + "h" + (h * 10) + "v" + fillshade + "g2P\033*v0n0O");
641
         * }
642
         * if ( sc != null && sw > 0 )
643
         * {
644
         * String lend = "v" + String.valueOf((int)(100 - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue()) * 100f))) + "g2P";
645
         * currentStream.add("\033*v0n1O");
646
         * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V"
647
         * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend);
648
         * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V"
649
         * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend);
650
         * currentStream.add("\033&a" + ((x + w - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V"
651
         * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend);
652
         * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y + h - sw/2)) * 10) + "V"
653
         * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend);
654
         * currentStream.add("\033*v0n0O");
655
         * }
656
         * }
657
         * else
658
         * {
659
         * // Convert dimensions to pixels.
660
         * float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in
661
         * int ix = (int)(x * cfact);
662
         * int iy = (int)(y * cfact);
663
         * int iw = (int)(w * cfact);
664
         * int ih = (int)(h * cfact);
665
         * int irx = (int)(rx * cfact);
666
         * int iry = (int)(ry * cfact);
667
         * int isw = (int)(sw * cfact);
668
         * int longwidth = 0;
669
         * int pass = 0;
670
         * PDFColor thecolor = null;
671
         * do
672
         * {
673
         * if ( pass == 0 && fc != null )
674
         * {
675
         * thecolor = fc;
676
         * }
677
         * else if ( pass == 1 && sc != null )
678
         * {
679
         * int iswdiv2 = isw / 2;
680
         * thecolor = sc;
681
         * ix -= iswdiv2;
682
         * iy -= iswdiv2;
683
         * irx += iswdiv2;
684
         * iry += iswdiv2;
685
         * iw += isw;
686
         * ih += isw;
687
         * longwidth = (int)(isw * 1.414);
688
         * }
689
         * else
690
         * thecolor = null;
691
         * if ( thecolor != null )
692
         * {
693
         * int tx = 0;
694
         * int ty = iry;
695
         * long a = irx;
696
         * long b = iry;
697
         * long Asquared = (long)Math.pow(a, 2);
698
         * long TwoAsquared = 2 * Asquared;
699
         * long Bsquared = (long)Math.pow(b, 2);
700
         * long TwoBsquared = 2 * Bsquared;
701
         * long d = Bsquared - Asquared * b + Asquared / 4;
702
         * long dx = 0;
703
         * long dy = TwoAsquared * b;
704
         * int rectlen = iw - 2 * irx;
705
         * List bottomlines = new java.util.ArrayList();
706
         * int x0 = tx;
707
         * // Set Transparency modes and select shading.
708
         * currentStream.add("\033*v0n1O\033*c" + (int)(100 - ((0.3f * thecolor.red() + 0.59f * thecolor.green() + 0.11f * thecolor.blue()) * 100f)) + "G\033*v2T");
709
         * // Move to starting position.
710
         * currentStream.add("\033*p" + ix + "x" + iy + "Y");
711
         * // Start raster graphics
712
         * currentStream.add("\033*t300R\033*r" + iw + "s1A\033*b1M");
713
         * while ( dx < dy )
714
         * {
715
         * if ( d > 0 )
716
         * {
717
         * if ( pass == 0 || ty > (iry - isw) )
718
         * xferLineBytes(irx - x0, rectlen + 2 * x0, bottomlines, -1);
719
         * else
720
         * xferLineBytes(irx - x0, longwidth, bottomlines, iw - irx + x0 - longwidth);
721
         * x0 = tx + 1;
722
         * ty--;
723
         * dy -= TwoAsquared;
724
         * d -= dy;
725
         * }
726
         * tx++;
727
         * dx += TwoBsquared;
728
         * d += Bsquared + dx;
729
         * }
730
         * d += (3 * (Asquared - Bsquared) / 2 - (dx + dy)) / 2;
731
         * while ( ty > 0 )
732
         * {
733
         * if ( pass == 0 || ty >= (iry - isw) )
734
         * xferLineBytes(irx - tx, rectlen + 2 * tx, bottomlines, -1);
735
         * else
736
         * xferLineBytes(irx - tx, isw, bottomlines, iw - irx + tx - isw);
737
         *
738
         * if ( d < 0 )
739
         * {
740
         * tx++;
741
         * dx += TwoBsquared;
742
         * d += dx;
743
         * }
744
         * ty--;
745
         * dy -= TwoAsquared;
746
         * d += Asquared - dy;
747
         * }
748
         * // Draw the middle part of the rectangle
749
         * int midlen = ih - 2 * iry;
750
         * if ( midlen > 0 )
751
         * {
752
         * if ( pass == 0 )
753
         * xferLineBytes(0, iw, null, -1);
754
         * else
755
         * xferLineBytes(0, isw, null, iw - isw);
756
         * currentStream.add("\033*b3M");
757
         * for ( int countr = midlen - 1 ; countr > 0 ; countr-- )
758
         * currentStream.add("\033*b0W");
759
         * currentStream.add("\033*b1M");
760
         * }
761
         * // Draw the bottom.
762
         * for ( int countr = bottomlines.size() - 1 ; countr >= 0 ; countr-- )
763
         * currentStream.add((String)bottomlines.get(countr));
764
         * // End raster graphics
765
         * currentStream.add("\033*rB");
766
         * // Return to regular print mode.
767
         * currentStream.add("\033*v0t0n0O");
768
         * }
769
         * pass++;
770
         * } while ( pass < 2 );
771
         * }
772
         */
773
    }
774
775
    // Add a polyline or polygon. Does not support fills yet!!!
776
    protected void addPolyline(List points, int posx, int posy,
777
                               PDFColor fc, PDFColor sc, float sw,
778
                               boolean close) {}
779
351
780
    /**
352
    /**
781
     * Renders an image, scaling it to the given width and height.
353
     * Renders an image, scaling it to the given width and height.

Return to bug 24438