Package org.apache.pdfbox.encoding

Examples of org.apache.pdfbox.encoding.Encoding


    }

    private Map<Integer,String> loadEncoding(COSName name) throws IOException
    {
        Map<Integer,String> result = new LinkedHashMap<Integer,String>();
        Encoding encoding = EncodingManager.INSTANCE.getEncoding(name);
        for( Iterator<Map.Entry<Integer,String>> it = (encoding.getCodeToNameMap().entrySet()).iterator();
                    it.hasNext();)
        {
            Map.Entry<Integer,String> entry = it.next();
            result.put(entry.getKey(), (entry.getValue()));
        }
View Full Code Here


        int firstchar = 255;
        int lastchar = 0;

        // widths
        List<CharMetric> listmetric = metric.getCharMetrics();
        Encoding encoding = getEncoding();
        int maxWidths = 256;
        List<Number> widths = new ArrayList(maxWidths);
        Integer zero = new Integer(250);
        Iterator<CharMetric> iter = listmetric.iterator();
        for( int i=0; i<maxWidths; i++ )
        {
            widths.add(zero);
        }
        while (iter.hasNext())
        {
            CharMetric m = iter.next();
            int n = m.getCharacterCode();
            if (n > 0)
            {
                firstchar = Math.min(firstchar, n);
                lastchar = Math.max(lastchar, n);
                if (m.getWx() > 0)
                {
                    float width = m.getWx();
                    widths.set(n,new Float(width));
                    // germandbls has 2 character codes !! Don't ask me why .....
                    // StandardEncoding = 0373 = 251
                    // WinANSIEncoding = 0337 = 223
                    if (m.getName().equals("germandbls") && n != 223)
                    {
                        widths.set(0337,new Float(width));
                    }
                }
            }
            else
            {
                // my AFMPFB-Fonts has no character-codes for german umlauts
                // so that I've to add them here by hand
                if (m.getName().equals("adieresis"))
                {
                    widths.set(0344,(Float)widths.get(encoding.getCode("a")));
                }
                else if (m.getName().equals("odieresis"))
                {
                    widths.set(0366,(Float)widths.get(encoding.getCode("o")));
                }
                else if (m.getName().equals("udieresis"))
                {
                    widths.set(0374,(Float)widths.get(encoding.getCode("u")));
                }
                else if (m.getName().equals("Adieresis"))
                {
                    widths.set(0304,(Float)widths.get(encoding.getCode("A")));
                }
                else if (m.getName().equals("Odieresis"))
                {
                    widths.set(0326,(Float)widths.get(encoding.getCode("O")));
                }
                else if (m.getName().equals("Udieresis"))
                {
                    widths.set(0334,(Float)widths.get(encoding.getCode("U")));
                }
            }
        }
        setFirstChar(0);
        setLastChar(255);
View Full Code Here

        float retval = 0;
        int code = getCodeFromArray( c, offset, length );
        FontMetric metric = getAFM();
        if( metric != null )
        {
            Encoding encoding = getEncoding();
            String characterName = encoding.getName( code );
            retval = metric.getCharacterHeight( characterName );
        }
        else
        {
            PDFontDescriptor desc = getFontDescriptor();
View Full Code Here

        int firstchar = 255;
        int lastchar = 0;

        // widths
        List listmetric = metric.getCharMetrics();
        Encoding encoding = getEncoding();
        int maxWidths = 256;
        List widths = new ArrayList(maxWidths);
        Integer zero = new Integer(250);
        Iterator iter = listmetric.iterator();
        for( int i=0; i<maxWidths; i++ )
        {
            widths.add(zero);
        }
        while (iter.hasNext())
        {
            CharMetric m = (CharMetric) iter.next();
            int n = m.getCharacterCode();
            if (n > 0)
            {
                firstchar = Math.min(firstchar, n);
                lastchar = Math.max(lastchar, n);
                if (m.getWx() > 0)
                {
                    float width = m.getWx();
                    widths.set(n,new Float(width));
                    // germandbls has 2 character codes !! Don't ask me why .....
                    // StandardEncoding = 0373 = 251
                    // WinANSIEncoding = 0337 = 223
                    if (m.getName().equals("germandbls") && n != 223)
                    {
                        widths.set(0337,new Float(width));
                    }
                }
            }
            else
            {
                // my AFMPFB-Fonts has no character-codes for german umlauts
                // so that I've to add them here by hand
                if (m.getName().equals("adieresis"))
                {
                    widths.set(0344,(Float)widths.get(encoding.getCode(COSName.getPDFName( "a" ))));
                }
                else if (m.getName().equals("odieresis"))
                {
                    widths.set(0366,(Float)widths.get(encoding.getCode(COSName.getPDFName( "o" ))));
                }
                else if (m.getName().equals("udieresis"))
                {
                    widths.set(0374,(Float)widths.get(encoding.getCode(COSName.getPDFName( "u" ))));
                }
                else if (m.getName().equals("Adieresis"))
                {
                    widths.set(0304,(Float)widths.get(encoding.getCode(COSName.getPDFName( "A" ))));
                }
                else if (m.getName().equals("Odieresis"))
                {
                    widths.set(0326,(Float)widths.get(encoding.getCode(COSName.getPDFName( "O" ))));
                }
                else if (m.getName().equals("Udieresis"))
                {
                    widths.set(0334,(Float)widths.get(encoding.getCode(COSName.getPDFName( "U" ))));
                }
            }
        }
        setFirstChar(0);
        setLastChar(255);
View Full Code Here

        float retval = 0;
        int code = getCodeFromArray( c, offset, length );
        FontMetric metric = getAFM();
        if( metric != null )
        {
            Encoding encoding = getEncoding();
            COSName characterName = encoding.getName( code );
            retval = metric.getCharacterHeight( characterName.getName() );
        }
        else
        {
            PDFontDescriptor desc = getFontDescriptor();
View Full Code Here

    {
        float retval = 0;
        FontMetric metric = getAFM();
        if( metric != null )
        {
            Encoding encoding = getEncoding();
            COSName characterName = encoding.getName( code );
            retval = metric.getCharacterWidth( characterName.getName() );
        }
        return retval;
    }
View Full Code Here

                        }
                    }
                    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( fontSubtypeName.equals( "TrueType" ) &&
                            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 );
        }
        //if we havn't found a value yet and
        //we are still on the first byte and
        //there is no cmap or the cmap does not have 2 byte mappings then try to encode
        //using fallback methods.
        if( retval == null &&
            length == 1 &&
            (cmap == null || !cmap.hasTwoByteMappings()))
        {
            Encoding encoding = getEncoding();
            if( encoding != null )
            {
                retval = encoding.getCharacter( getCodeFromArray( c, offset, length ) );
            }
            if( retval == null )
            {
                retval = getStringFromArray( c, offset, length );
            }
View Full Code Here

        float retval = 0;
        int code = getCodeFromArray( c, offset, length );
        FontMetric metric = getAFM();
        if( metric != null )
        {
            Encoding encoding = getEncoding();
            String characterName = encoding.getName( code );
            retval = metric.getCharacterHeight( characterName );
        }
        else
        {
            PDFontDescriptor desc = getFontDescriptor();
View Full Code Here

    {
        float retval = 0;
        FontMetric metric = getAFM();
        if( metric != null )
        {
            Encoding encoding = getEncoding();
            String characterName = encoding.getName( code );
            retval = metric.getCharacterWidth( characterName );
        }
        return retval;
    }
View Full Code Here

                        }
                    }
                    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 )
            {
                if ( retval != null )
                {
                    retval = converter.convertString(retval);
                }
                else
                {
                    retval = converter.convertBytes(c, offset, length, cmap);
                }
                return retval;
            }
        }
       
        //if we havn't found a value yet and
        //we are still on the first byte and
        //there is no cmap or the cmap does not have 2 byte mappings then try to encode
        //using fallback methods.
        if( retval == null &&
            length == 1 &&
            (cmap == null || !cmap.hasTwoByteMappings()))
        {
            Encoding encoding = getEncoding();
            if( encoding != null )
            {
                retval = encoding.getCharacter( getCodeFromArray( c, offset, length ) );
            }
            if( retval == null )
            {
                retval = getStringFromArray( c, offset, length );
            }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.encoding.Encoding

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.