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

org.jpedal.render.GUIDisplay Maven / Gradle / Ivy

There is a newer version: 20151002
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-2016 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
     This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 *
 * ---------------
 * GUIDisplay.java
 * ---------------
 */

package org.jpedal.render;

import java.awt.Color;
import java.awt.Shape;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Arrays;
import org.jpedal.color.PdfColor;
import org.jpedal.examples.handlers.DefaultImageHelper;
import org.jpedal.exception.PdfException;
import org.jpedal.io.ColorSpaceConvertor;
import org.jpedal.objects.GraphicsState;
import org.jpedal.objects.SwingShape;
import org.jpedal.objects.raw.PdfDictionary;
import org.jpedal.parser.Cmd;
import org.jpedal.utils.LogWriter;

/**
 *
 * functions shared by Swing and FX but not lower level Display implementations
 */
abstract class GUIDisplay extends G2Display implements DynamicVectorRenderer{

    
    private boolean needsHorizontalInvert;

    private boolean needsVerticalInvert;
    

    public void saveImage(final int id, final String des, final String type) {
        final String name = imageIDtoName.get(id);
        BufferedImage image=objectStoreRef.loadStoredImage(name);

        //if not stored, try in memory
        if(image==null) {
            image = (BufferedImage) pageObjects.elementAt(id);
        }
        
        if(image!=null){

            if(image.getType()==BufferedImage.TYPE_CUSTOM || (type.equals("jpg") && image.getType()==BufferedImage.TYPE_INT_ARGB)){
                image=ColorSpaceConvertor.convertToRGB(image);
            }

            if(needsHorizontalInvert){
                image = RenderUtils.invertImageBeforeSave(image, true);
            }

            if(needsVerticalInvert){
                image = RenderUtils.invertImageBeforeSave(image, false);
            }

            try {
                DefaultImageHelper.write(image, type, des);
            } catch (IOException ex) {
                LogWriter.writeLog("Exception in writing image "+ex);
            }
        }
    }
    
    public void setneedsVerticalInvert(final boolean b) {
        needsVerticalInvert = b;
    }

    public void setneedsHorizontalInvert(final boolean b) {
        needsHorizontalInvert=b;
    }
    
    

    /**
     * return number of image in display queue or -1 if none.
     *
     * @return
     */
    public int getObjectUnderneath(final int x, final int y) {
        int typeFound = -1;
        final int[][] areas = this.areas.get();
        //Rectangle possArea = null;
        final int count = areas.length;

        if(objectType!=null){
            final int[] types = objectType.get();
            boolean nothing = true;
            for (int i = count - 1; i > -1; i--) {
                if ((areas[i] != null && RenderUtils.rectangleContains(areas[i], x, y)) &&
                         (types[i] != DynamicVectorRenderer.SHAPE && types[i] != DynamicVectorRenderer.CLIP)) {
                            nothing = false;
                            typeFound = types[i];
                            i = -1;
                        }
                    }



            if (nothing) {
                return -1;
            }
        }
        return typeFound;
    }

    
    /**
     * Returns a Rectangles X,Y,W,H as an Array of integers
     * Where 0 = x, 1 = y, 2 = w, 3 = h.
     */
    public int[] getAreaAsArray(final int i){

        return areas.elementAt(i);
    }

    /**
     * return number of image in display queue
     * or -1 if none
     * @return
     */
    public int isInsideImage(final int x, final int y){
        int outLine=-1;

        final int[][] areas=this.areas.get();
        int[] possArea = null;
        final int count=areas.length;

        if(objectType!=null){
            final int[] types=objectType.get();
            for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy