Package com.sun.pdfview

Examples of com.sun.pdfview.PDFObject


  }


  protected static byte[] decode(PDFObject dict, byte[] source) throws IOException {
    int width = 1728;
    PDFObject widthDef = dict.getDictRef("Width");
    if (widthDef == null) {
      widthDef = dict.getDictRef("W");
    }
    if (widthDef != null) {
      width = widthDef.getIntValue();
    }
    int height = 0;
    PDFObject heightDef = dict.getDictRef("Height");
    if (heightDef == null) {
      heightDef = dict.getDictRef("H");
    }
    if (heightDef != null) {
      height = heightDef.getIntValue();
    }

    //
    int columns = getOptionFieldInt(dict, "Columns", width);
    int rows = getOptionFieldInt(dict, "Rows", height);
View Full Code Here


    return destination;
  }

  public static int getOptionFieldInt(PDFObject dict, String name, int defaultValue) throws IOException {

    PDFObject dictParams =  dict.getDictRef("DecodeParms");

    if (dictParams == null) {
      return defaultValue;
    }
    PDFObject value = dictParams.getDictRef(name);
    if (value == null) {
      return defaultValue;
    }
    return value.getIntValue();
  }
View Full Code Here

    return value.getIntValue();
  }

  public static boolean getOptionFieldBoolean(PDFObject dict, String name, boolean defaultValue) throws IOException {

    PDFObject dictParams =  dict.getDictRef("DecodeParms");

    if (dictParams == null) {
      return defaultValue;
    }
    PDFObject value = dictParams.getDictRef(name);
    if (value == null) {
      return defaultValue;
    }
    return value.getBooleanValue();
  }
View Full Code Here

     */
    public static Predictor getPredictor(PDFObject params)
        throws IOException
    {
        // get the algorithm (required)
        PDFObject algorithmObj = params.getDictRef("Predictor");
        if (algorithmObj == null) {
            // no predictor
            return null;
        }
        int algorithm = algorithmObj.getIntValue();
   
        // create the predictor object
        Predictor predictor = null;
        switch (algorithm) {
            case 1:
                // no predictor
                return null;
            case 2:
                predictor = new TIFFPredictor();
                break;               
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
                predictor = new PNGPredictor();
                break;
            default:
                throw new PDFParseException("Unknown predictor: " + algorithm);
        }
       
        // read the colors (optional)
        PDFObject colorsObj = params.getDictRef("Colors");
        if (colorsObj != null) {
            predictor.setColors(colorsObj.getIntValue());
        }
       
        // read the bits per component (optional)
        PDFObject bpcObj = params.getDictRef("BitsPerComponent");
        if (bpcObj != null) {
            predictor.setBitsPerComponent(bpcObj.getIntValue());
        }
       
        // read the columns (optional)
        PDFObject columnsObj = params.getDictRef("Columns");
        if (columnsObj != null) {
            predictor.setColumns(columnsObj.getIntValue());
        }
       
        // all set
        return predictor;
    }
View Full Code Here

                    PDFFontDescriptor descriptor, File fontFile)
            throws IOException {
        super (baseFont, fontObj, descriptor);

        String fontName = descriptor.getFontName ();
        PDFObject ttfObj = descriptor.getFontFile2 ();

        // try {
        //    byte[] fontData = ttfObj.getStream();
        //    java.io.FileOutputStream fis = new java.io.FileOutputStream("/tmp/" + fontName + ".ttf");
        //    fis.write(fontData);
        //    fis.flush();
        //    fis.close();
        // } catch (Exception ex) {
        //    ex.printStackTrace();
        // }
        if (ttfObj != null || fontFile != null) {
            if (ttfObj != null) {
                font = TrueTypeFont.parseFont (ttfObj.getStreamBuffer ());
            } else {
                final RandomAccessFile raFile = fontFile != null ? new RandomAccessFile(fontFile, "r") : null;
                final FileChannel fc = raFile.getChannel();
                try {
                    MappedByteBuffer mappedFont = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
View Full Code Here

    /** Parse the Widths array and DW object */
    private void parseWidths(PDFObject fontObj)
            throws IOException {
        // read the default width (otpional)
        PDFObject defaultWidthObj = fontObj.getDictRef("DW");
        if (defaultWidthObj != null) {
            defaultWidth = defaultWidthObj.getIntValue();
        }

        int entryIdx = 0;
        int first = 0;
        int last = 0;
        PDFObject[] widthArray;

        // read the widths table
        PDFObject widthObj = fontObj.getDictRef("W");
        if (widthObj != null) {

            // initialize the widths array
            widths = new HashMap<Character, Float>();

            // parse the width array
            widthArray = widthObj.getArray();

            /* an entry can be in one of two forms:
             *   <startIndex> <endIndex> <value> or
             *   <startIndex> [ array of values ]
             * we use the entryIdx to differentitate between them
             */
            for (int i = 0; i < widthArray.length; i++) {
                if (entryIdx == 0) {
                    // first value in an entry.  Just store it
                    first = widthArray[i].getIntValue();
                } else if (entryIdx == 1) {
                    // second value -- is it an int or array?
                    if (widthArray[i].getType() == PDFObject.ARRAY) {
                        // add all the entries in the array to the width array
                        PDFObject[] entries = widthArray[i].getArray();
                        for (int c = 0; c < entries.length; c++) {
                            Character key = new Character((char) (c + first));

                            // value is width / default width
                            float value = entries[c].getIntValue();
                            widths.put(key, new Float(value));
                        }
                        // all done
                        entryIdx = -1;
                    } else {
                        last = widthArray[i].getIntValue();
                    }
                } else {
                    // third value.  Set a range
                    int value = widthArray[i].getIntValue();

                    // set the range
                    for (int c = first; c <= last; c++) {
                        widths.put(new Character((char) c), new Float(value));
                    }

                    // all done
                    entryIdx = -1;
                }

                entryIdx++;
            }
        }

        // read the optional vertical default width
        defaultWidthObj = fontObj.getDictRef("DW2");
        if (defaultWidthObj != null) {
            defaultWidthVertical = defaultWidthObj.getIntValue();
        }

        // read the vertical widths table
        widthObj = fontObj.getDictRef("W2");
        if (widthObj != null) {

            // initialize the widths array
            widthsVertical = new HashMap<Character, Float>();

            // parse the width2 array
            widthArray = widthObj.getArray();

            /* an entry can be in one of two forms:
             *   <startIndex> <endIndex> <value> or
             *   <startIndex> [ array of values ]
             * we use the entryIdx to differentitate between them
View Full Code Here

            throws IOException {
        super (baseFont, fontObj, descriptor);

        String fontName = descriptor.getFontName ();

        PDFObject ttf = descriptor.getFontFile2 ();
        if (ttf != null) {
            byte[] fontdata = ttf.getStream ();

            try {
                setFont (fontdata);
            } catch (FontFormatException ffe) {
                throw new PDFParseException ("Font format exception: " + ffe);
View Full Code Here

     * Parse the shader-specific data
     */
    public void parse(PDFObject shaderObj) throws IOException
    {
        // read the axis coordinates (required)
        PDFObject coordsObj = shaderObj.getDictRef("Coords");
        if (coordsObj == null) {
            throw new PDFParseException("No coordinates found!");
        }
        PDFObject[] coords = coordsObj.getArray();
        Point2D start = new Point2D.Float(coords[0].getFloatValue(),
                                          coords[1].getFloatValue());
        Point2D end   = new Point2D.Float(coords[2].getFloatValue(),
                                          coords[3].getFloatValue());
        setAxisStart(start);
        setAxisEnd(end);
       
        // read the domain (optional)
        PDFObject domainObj = shaderObj.getDictRef("Domain");
        if (domainObj != null) {
            PDFObject[] domain = domainObj.getArray();
            setMinT(domain[0].getFloatValue());
            setMaxT(domain[1].getFloatValue());
        }
       
        // read the functions (required)
        PDFObject functionObj = shaderObj.getDictRef("Function");
        if (functionObj == null) {
            throw new PDFParseException("No function defined for shader!");
        }
        PDFObject[] functionArray = functionObj.getArray();
        PDFFunction[] functions = new PDFFunction[functionArray.length];
        for (int i = 0; i < functions.length; i++) {
            functions[i] = PDFFunction.getFunction(functionArray[i]);
        }
        setFunctions(functions);
       
        // read the extend array (optional)
        PDFObject extendObj = shaderObj.getDictRef("Extend");
        if (extendObj != null) {
            PDFObject[] extendArray = extendObj.getArray();
            setExtendStart(extendArray[0].getBooleanValue());
            setExtendEnd(extendArray[1].getBooleanValue());
        }
       
    }
View Full Code Here

       
        // get the pattern type
        int type = patternObj.getDictRef("PatternType").getIntValue();
        
        // read the pattern transform matrix
        PDFObject matrix = patternObj.getDictRef("Matrix");
  AffineTransform xform = null;
        if (matrix == null) {
            xform = new AffineTransform();
        } else {
            float elts[]= new float[6];
            for (int i = 0; i < elts.length; i++) {
                elts[i] = ((PDFObject) matrix.getAt(i)).getFloatValue();
            }
       
            xform = new AffineTransform(elts);
        }   
       
View Full Code Here

    super(annotObject, ANNOTATION_TYPE.WIDGET);
   
    // The type of field that this dictionary describes. Field type is
    // present for terminal fields but is inherited from parent if absent
    // (see PDF Reference 1.7 table 8.69)
    PDFObject fieldTypeRef = annotObject.getDictRef("FT");
    if (fieldTypeRef != null) {
      // terminal field
      this.fieldType = FieldType.getByCode(fieldTypeRef.getStringValue());
    }
    else {
      // must check parent since field type is inherited
      PDFObject parent = annotObject.getDictRef("Parent");
      while (parent != null && parent.isIndirect()) {
        parent = parent.dereference();
      }
      if (parent != null) {
        fieldTypeRef = parent.getDictRef("FT");
        this.fieldType = FieldType.getByCode(fieldTypeRef.getStringValue());
      }
    }
   
    // Name defined for the field
    PDFObject fieldNameRef = annotObject.getDictRef("T");
    if (fieldNameRef != null) {
      this.fieldName = fieldNameRef.getTextStringValue();
    }
    this.fieldValueRef = annotObject.getDictRef("V");
    if (this.fieldValueRef != null) {
      this.fieldValue = this.fieldValueRef.getTextStringValue();
    }
View Full Code Here

TOP

Related Classes of com.sun.pdfview.PDFObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.