All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.parser.shape.S Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * S.java
 * ---------------
 */
package org.jpedal.parser.shape;

import java.awt.Shape;
import java.awt.geom.Area;

import org.jpedal.objects.GraphicsState;
import org.jpedal.objects.PdfShape;
import org.jpedal.parser.Cmd;
import org.jpedal.parser.ParserOptions;
import org.jpedal.render.DynamicVectorRenderer;

public class S {


    public static Shape execute(final boolean isLowerCase, final GraphicsState gs, final PdfShape currentDrawShape, final DynamicVectorRenderer current, final ParserOptions parserOptions) {

        final boolean useJavaFX = parserOptions.useJavaFX();
        final boolean renderPage = parserOptions.isRenderPage();

        Shape currentShape = null;
        if (parserOptions.isLayerVisible()) {

            //close for s command
            if (isLowerCase) {
                currentDrawShape.closeShape();
            }

            Object fxPath = null;

            final float realLineWidth = -1;

            if (useJavaFX) {
                fxPath = currentDrawShape.getPath();
            } else {
                currentShape = currentDrawShape.generateShapeFromPath(gs.CTM, gs.getLineWidth(), Cmd.S);

                if (currentShape != null) {
                    /*
                    Rectangle bounds; //=currentShape.getBounds();
                    
                    // System.out.println("S bounds="+bounds+" "+" "+gs.CTM[0][0]+" "+gs.CTM[0][1]+" "+gs.CTM[1][0]+" "+gs.CTM[1][1]);
                    
                    //allow for tiny line with huge width to draw a line (see baseline_screens/14jan/Pages from FDB-B737-FRM_nowatermark.pdf)
                    if(1==2 && gs.CTM[0][0]<=1 && gs.CTM[1][1]<=1 && gs.getLineWidth()>30 && bounds.height==1 && (bounds.width==1 || bounds.width>4)){
                        
                        realLineWidth=gs.getLineWidth();
                        
                        final float scaledThickness=realLineWidth*gs.CTM[1][1];
                        
                        final Rectangle current_path = new Rectangle(bounds.x,(int)(bounds.y-(scaledThickness/2)),bounds.width,(int)(scaledThickness));
                        
                        currentShape=new Area(current_path);
                        
                         //temp code so we do not break current code functions
                    currentDrawShape.setShape(currentShape);
                    
                        // System.out.println("use "+current_path+" "+bounds.width+" "+realLineWidth);
                        
                        gs.setLineWidth(1f);
                        
                    }/**/
                }
            }

            boolean hasShape = currentShape != null || fxPath != null;

            if (hasShape) { //allow for the odd combination of crop with zero size
                final Area crop = gs.getClippingShape();

                if (crop != null && (crop.getBounds().getWidth() == 0 || crop.getBounds().getHeight() == 0)) {
                    currentShape = null;
                    fxPath = null;
                    hasShape = false;

                    //temp code so we do not break current code functions
                    currentDrawShape.setShape(currentShape);
                }
            }

            if (hasShape) { //allow for the odd combination of f then S

                //fix forSwing. (not required in HTML/SVG
                //Alter to only check bounds <1 instead of <=1 for fedexLabelAM.pdf
                if (currentShape != null && currentShape.getBounds().getWidth() < 1 && !current.isHTMLorSVG()) { // && currentGraphicsState.getLineWidth()<=1.0f){
                    currentShape = currentShape.getBounds2D();

                    //temp code so we do not break current code functions
                    currentDrawShape.setShape(currentShape);
                }

                //save for later
                if (renderPage) {

                    gs.setStrokeColor(gs.strokeColorSpace.getColor());
                    gs.setNonstrokeColor(gs.nonstrokeColorSpace.getColor());
                    gs.setFillType(GraphicsState.STROKE);

                    if (useJavaFX) {
                        current.drawShape(fxPath, gs);
                    } else {
                        current.drawShape(currentDrawShape, gs, Cmd.S);
                    }

                    if (realLineWidth != -1) {
                        gs.setLineWidth(realLineWidth);
                    }
                }
            }

            if (currentDrawShape.isClip()) {

                if (useJavaFX) {
                    gs.updateClip(fxPath);
                } else {
                    gs.updateClip(new Area(currentShape));
                }
            }
        }

        //always reset flag
        currentDrawShape.setClip(false);
        currentDrawShape.resetPath(); // flush all path ops stored

        return currentShape;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy