Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/PDF2Writer.java

    r919 r1102  
    1919package org.expeditee.io;
    2020
    21 import java.awt.Color;
    22 import java.awt.Dimension;
    23 import java.awt.Image;
    24 import java.awt.Polygon;
    25 import java.awt.geom.AffineTransform;
    2621import java.io.FileOutputStream;
    2722import java.io.IOException;
     
    3429import java.util.Set;
    3530
     31import org.expeditee.core.Colour;
     32import org.expeditee.core.Dimension;
     33import org.expeditee.core.Image;
     34import org.expeditee.core.bounds.PolygonBounds;
     35import org.expeditee.gio.swing.SwingConversions;
     36import org.expeditee.gio.swing.SwingMiscManager;
     37import org.expeditee.gui.DisplayController;
    3638import org.expeditee.gui.Frame;
    3739import org.expeditee.gui.FrameGraphics;
     
    145147
    146148        public PDF2Writer() {
    147                 _pageSize = FrameGraphics.getMaxSize();
     149                _pageSize = DisplayController.getFramePaintArea().getSize();
    148150                _pdfDocument = new Document(new Rectangle(_pageSize.width, _pageSize.height));
    149151        }
     
    233235                // set bg color
    234236                PdfContentByte cb = _pdfWriter.getDirectContent();
    235                 cb.setColorFill(starting.getPaintBackgroundColor());
     237                cb.setColorFill(SwingConversions.toSwingColor(starting.getPaintBackgroundColor()));
    236238                cb.rectangle(0, 0, _pageSize.width, _pageSize.height);
    237239                cb.fill();
     
    239241        }
    240242       
    241         private void drawPolygon(PdfContentByte cb, Polygon poly, Color fill, Color line, float lineThickness) {
     243        private void drawPolygon(PdfContentByte cb, PolygonBounds poly, Colour fill, Colour line, float lineThickness) {
    242244                if(poly != null) {
    243                         cb.moveTo(poly.xpoints[0], _height - poly.ypoints[0]);
    244                         for(int i = 1; i < poly.npoints; i++) {
    245                                 cb.lineTo(poly.xpoints[i], _height - poly.ypoints[i]);
     245                        cb.moveTo(poly.toArray()[0].x, _height - poly.toArray()[0].y);
     246                        for(int i = 1; i < poly.toArray().length; i++) {
     247                                cb.lineTo(poly.toArray()[i].x, _height - poly.toArray()[i].y);
    246248                        }
    247249                        cb.closePath();
    248250                        if(fill != null) {
    249                                 cb.setColorFill(fill);
     251                                cb.setColorFill(SwingConversions.toSwingColor(fill));
    250252                                if(lineThickness > 0) {
    251253                                cb.setLineWidth(lineThickness);
    252                                 cb.setColorStroke(line);
     254                                cb.setColorStroke(SwingConversions.toSwingColor(line));
    253255                                cb.fillStroke();
    254256                        } else {
     
    257259                        } else {
    258260                                cb.setLineWidth(lineThickness);
    259                                 cb.setColorStroke(line);
     261                                cb.setColorStroke(SwingConversions.toSwingColor(line));
    260262                                cb.stroke();
    261263                        }
     
    269271                if (hasLink) {
    270272                       
    271                         Color lineColor = Color.BLACK, fillColor = null;
    272                         Polygon poly = i.getLinkPoly();
    273                         poly = new Polygon(poly.xpoints, poly.ypoints, poly.npoints);
     273                        Colour lineColor = Colour.BLACK, fillColor = null;
     274                        PolygonBounds poly = new PolygonBounds(i.getLinkBounds().getPolygon(16));
    274275                        poly.translate((int) (x - Item.LEFT_MARGIN), (int) (_height - y - i.getBoundsHeight() / 2));
    275276                       
     
    298299        protected void writeText(Text text) throws IOException {
    299300                PdfContentByte cb = _pdfWriter.getDirectContent();
    300                 Font font = FontFactory.getFont(
    301                                 Conversion.getPdfFont(text.getFamily()), text.getSize(), text
    302                                                 .getPaintFont().getStyle(), text.getPaintColor());
     301                Font font = FontFactory.getFont(Conversion.getPdfFont(text.getFamily()),
     302                                                                                text.getSize(),
     303                                                                                SwingConversions.toSwingFontStyle(text.getPaintFont().getStyle()),
     304                                                                                SwingConversions.toSwingColor(text.getPaintColor()));
    303305               
    304306                // we draw some text on a certain position
     
    318320                try {
    319321                        PdfContentByte cb = _pdfWriter.getDirectContent();
    320                         com.lowagie.text.Image iTextImage = com.lowagie.text.Image.getInstance(image, null);
     322                        com.lowagie.text.Image iTextImage = com.lowagie.text.Image.getInstance(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(image), null);
    321323                        float angle = (float) (pic.getRotate() * Math.PI / 180);
    322324                        double sin = Math.sin(angle), cos = Math.cos(angle);
     
    339341                PdfContentByte cb = _pdfWriter.getDirectContent();
    340342                cb.circle(circle.getCenter().getX(), _pdfWriter.getPageSize().getHeight() - circle.getCenter().getY(), (float) circle.getRadius());
    341                 cb.setColorFill(circle.getFillColor());
     343                cb.setColorFill(SwingConversions.toSwingColor(circle.getFillColor()));
    342344                if(circle.getThickness() > 0) {
    343345                        cb.setLineWidth(circle.getThickness());
    344                         cb.setColorStroke(circle.getPaintColor());
     346                        cb.setColorStroke(SwingConversions.toSwingColor(circle.getPaintColor()));
    345347                        cb.fillStroke();
    346348                } else {
     
    377379                        }
    378380                        cb.closePath();
    379                         Color fill = currentItem.getFillColor();
     381                        Colour fill = currentItem.getFillColor();
    380382                        if(fill != null) {
    381                         cb.setColorFill(fill);
     383                        cb.setColorFill(SwingConversions.toSwingColor(fill));
    382384                        if(currentItem.getThickness() > 0) {
    383385                                cb.setLineWidth(currentItem.getThickness());
    384                                 cb.setColorStroke(currentLine.getPaintColor());
     386                                cb.setColorStroke(SwingConversions.toSwingColor(currentLine.getPaintColor()));
    385387                                cb.fillStroke();
    386388                        } else {
     
    389391                        } else if(currentItem.getThickness() > 0) {
    390392                                cb.setLineWidth(currentItem.getThickness());
    391                                 cb.setColorStroke(currentLine.getPaintColor());
     393                                cb.setColorStroke(SwingConversions.toSwingColor(currentLine.getPaintColor()));
    392394                                cb.stroke();
    393395                        }
     
    403405                                        if(l.getThickness() >= 0) {
    404406                                                cb.setLineWidth(l.getThickness());
    405                                                 cb.setColorStroke(l.getPaintColor());
     407                                                cb.setColorStroke(SwingConversions.toSwingColor(l.getPaintColor()));
    406408                                                cb.stroke();
    407409                                        }
Note: See TracChangeset for help on using the changeset viewer.