Package org.apache.pdfbox.cos

Examples of org.apache.pdfbox.cos.COSBase


     * @throws IOException If there is an error getting the AFM object.
     */
    protected FontMetric getAFM() throws IOException
    {
        if(afm==null){
            COSBase baseFont = font.getDictionaryObject( COSName.BASE_FONT );
            String name = null;
            if( baseFont instanceof COSName )
            {
                name = ((COSName)baseFont).getName();
                if (name.indexOf("+") > -1)
View Full Code Here


        String retval = null;
        if( isTypeFont() )
        {
            if( cmap == null )
            {
                COSBase toUnicode = font.getDictionaryObject( COSName.TO_UNICODE );
                if( toUnicode instanceof COSStream )
                {
                    hasToUnicode = true;
                    parseCmap( null, ((COSStream)toUnicode).getUnfilteredStream(), null );
                }
                else
                {
                    COSBase encoding = getEncodingObject();
                    if( encoding instanceof COSStream )
                    {
                        COSStream encodingStream = (COSStream)encoding;
                        parseCmap( null, encodingStream.getUnfilteredStream(), null );
                    }
                    else if( isType0Font() && encoding instanceof COSName )
                    {
                        COSName encodingName = (COSName)encoding;
                        cmap = cmapObjects.get( encodingName );
                        if( cmap == null )
                        {
                            String cmapName = encodingName.getName();
                            if (encodingName.getName().equals( COSName.IDENTITY_H.getName() ))
                            {
                                COSArray descendantFontArray =
                                    (COSArray)font.getDictionaryObject( COSName.DESCENDANT_FONTS );
                                if (descendantFontArray != null)
                                {
                                    COSDictionary descendantFontDictionary =
                                        (COSDictionary)descendantFontArray.getObject( 0 );
                                    PDFont descendentFont = PDFontFactory.createFont( descendantFontDictionary );
                                    COSDictionary cidsysteminfo =
                                        (COSDictionary)descendentFont.font.getDictionaryObject(COSName.CIDSYSTEMINFO);
                                    if (cidsysteminfo != null)
                                    {
                                        String ordering = cidsysteminfo.getString(COSName.ORDERING);
                                        String registry = cidsysteminfo.getString(COSName.REGISTRY);
                                        cmapName = registry + "-" + ordering+"-UCS2";
                                    }
                                }
                            }
                            else
                            {
                                cmapName = CMapSubstitution.substituteCMap( cmapName );
                            }

                            String resourceRoot = "org/apache/pdfbox/resources/cmap/";
                            String resourceName = resourceRoot + cmapName;
                            parseCmap( resourceRoot, ResourceLoader.loadResource( resourceName ), encodingName );
                            if( cmap == null && !encodingName.getName().equals( COSName.IDENTITY_H.getName() ) )
                            {
                                throw new IOException( "Error: Could not find predefined " +
                                "CMAP file for '" + encodingName.getName() + "'" );
                            }
                        }
                    }
                    else if( encoding instanceof COSName ||
                             encoding instanceof COSDictionary )
                    {
                        Encoding currentFontEncoding = getEncoding();
                        if( currentFontEncoding != null )
                        {
                            retval = currentFontEncoding.getCharacter( getCodeFromArray( c, offset, length ) );
                        }
                    }
                    else
                    {
                        COSDictionary fontDescriptor =
                            (COSDictionary)font.getDictionaryObject( COSName.FONT_DESC );
                        if( isTrueTypeFont() && fontDescriptor != null &&
                            (fontDescriptor.getDictionaryObject( COSName.FONT_FILE )!= null ||
                             fontDescriptor.getDictionaryObject( COSName.FONT_FILE2 ) != null ||
                             fontDescriptor.getDictionaryObject( COSName.FONT_FILE3 ) != null ) )
                        {
                            //If we are using an embedded font then there is not much we can do besides
                            //return the same character codes.
                            //retval = new String( c,offset, length );
                            retval = getStringFromArray( c, offset, length );
                        }
                        else
                        {
                            //this case will be handled below after checking the cmap
                        }
                    }
                }


            }
        }
        if( retval == null && cmap != null )
        {
            retval = cmap.lookup( c, offset, length );
        }
       
        COSBase encodingCOS = getEncodingObject();
        // The converter isn't needed if an unicode mapping is already given by the font dictionary 
        if ( !hasToUnicode && encodingCOS instanceof COSName )
        {
            EncodingConverter converter = EncodingConversionManager.getConverter(((COSName)encodingCOS).getName());
            if ( converter != null )
View Full Code Here

    public Encoding getEncoding() throws IOException
    {
        if( fontEncoding == null )
        {
            EncodingManager manager = getEncodingManager();
            COSBase encoding = getEncodingObject(); //font.getDictionaryObject( COSName.ENCODING );
            if( encoding == null )
            {
                FontMetric metric = getAFM();
                if( metric != null )
                {
                    fontEncoding = new AFMEncoding( metric );
                }
                if( fontEncoding == null )
                {
                    fontEncoding = manager.getStandardEncoding();
                }
            }
            /**
             * Si la cl� /Encoding existe dans le dictionnaire fonte il y a deux possibilit�s :
             * 1er cas : elle est associ� � une reference contenant un dictionnaire de type encoding.
             * Ce dictionnaire PDF est repr�sent� par un DictionaryEncoding.
             * If the /Encoding Key does exist in the font dictionary, there are two cases :
             * case one : The value associated with /Encoding is a reference to a dictionary.
             * This dictionary is represented by an instance of DictionaryEncoding class
             */
            else if( encoding instanceof COSDictionary )
            {
                COSDictionary encodingDic = (COSDictionary)encoding;
                //Let's see if the encoding dictionary has a base encoding
                //If it does not then we will attempt to get it from the font
                //file
                COSName baseEncodingName = (COSName) encodingDic.getDictionaryObject(
                    COSName.BASE_ENCODING);
                //on ajoute une entr�e /BaseEncoding dans /Encoding uniquement si elle en est absente
                //if not find in Encoding dictinary target, we try to find it from else where
                if( baseEncodingName == null)
                {
                    COSName fontEncodingFromFile = getEncodingFromFont();
                    encodingDic.setItem(
                        COSName.BASE_ENCODING,
                        fontEncodingFromFile );
                }
                fontEncoding = new DictionaryEncoding( encodingDic );
            }
            else if( encoding instanceof COSName )
            {
                if( !encoding.equals( COSName.IDENTITY_H ) )
                {
                    fontEncoding = manager.getEncoding( (COSName)encoding );
                }
            }
            else
            {
                throw new IOException( "Unexpected encoding type:" + encoding.getClass().getName() );
            }
        }
        return fontEncoding;
    }
View Full Code Here

    public boolean isEncryptMetaData()
    {
        // default is true (see 7.6.3.2 Standard Encryption Dictionary PDF 32000-1:2008)
        boolean encryptMetaData = true;
       
        COSBase value = dictionary.getDictionaryObject(COSName.ENCRYPT_META_DATA);
       
        if (value instanceof COSBoolean) {
            encryptMetaData = ((COSBoolean)value).getValue();
        }
       
View Full Code Here

     * As this is a required field this null should not be passed into this function.
     * @param whitepoint the whitepoint tristimulus
     */
    public void setWhitePoint(PDTristimulus whitepoint)
    {
        COSBase wpArray = whitepoint.getCOSObject();
        if(wpArray != null)
        {
            dictionary.setItem(COSName.WHITE_POINT, wpArray);
        }
       
View Full Code Here

     * As this is a required field this null should not be passed into this function.
     * @param blackpoint the BlackPoint tristimulus
     */
    public void setBlackPoint(PDTristimulus blackpoint)
    {
        COSBase bpArray = null;
        if(blackpoint != null)
        {
            bpArray = blackpoint.getCOSObject();
        }
        dictionary.setItem(COSName.BLACK_POINT, bpArray);
View Full Code Here

            COSArray kids = (COSArray) dic.getDictionaryObject(COSName.KIDS);
            for (int i = 0; kids != null && i < kids.size(); i++)
            {
                addDictionaryAndSubDictionary(set, (COSDictionary) kids.getObject(i));
            }
            COSBase value = dic.getDictionaryObject(COSName.V);
            if (value instanceof COSDictionary)
            {
                addDictionaryAndSubDictionary(set, (COSDictionary) value);
            }
        }
View Full Code Here

     */
    private void decryptObject(COSObject object) throws IOException
    {
        long objNum = object.getObjectNumber().intValue();
        long genNum = object.getGenerationNumber().intValue();
        COSBase base = object.getObject();
        decrypt(base, objNum, genNum);
    }
View Full Code Here

     */
    private void decryptDictionary(COSDictionary dictionary, long objNum, long genNum) throws IOException
    {
        for (Map.Entry<COSName, COSBase> entry : dictionary.entrySet())
        {
            COSBase value = entry.getValue();
            // within a dictionary only the following kind of COS objects have to be decrypted
            if (value instanceof COSString || value instanceof COSStream || value instanceof COSArray || value instanceof COSDictionary)
            {
                // if we are a signature dictionary and contain a Contents entry then
                // we don't decrypt it.
View Full Code Here

     * This will either add the page passed in, or, if it's a pointer to an array
     * of pages, it'll recursivly call itself and process everything in the list.
     */
    private void parseCatalogObject(COSObject thePageOrArrayObject)
    {
        COSBase arrayCountBase = thePageOrArrayObject.getItem(COSName.COUNT);
        int arrayCount = -1;
        if(arrayCountBase instanceof COSInteger)
        {
            arrayCount = ((COSInteger)arrayCountBase).intValue();
        }
        COSBase kidsBase = thePageOrArrayObject.getItem(COSName.KIDS);
        int kidsCount = -1;
        if(kidsBase instanceof COSArray)
        {
            kidsCount = ((COSArray)kidsBase).size();
        }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.cos.COSBase

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.