Examples of Encoding


Examples of nu.validator.htmlparser.io.Encoding

        // revised -- 2008-03-17 hsivonen
        sourceType = INPUT_READER;
        characterEncoding = Encoding.toAsciiLowerCase(actualName);
        encoding = Encoding.toAsciiLowerCase(encoding);
        try {
            Encoding cs = Encoding.forName(encoding);
            String canonName = cs.getCanonName();
            if (requireAsciiSuperset) {
                if (!cs.isAsciiSuperset()) {
                    fatal("The encoding \u201C"
                            + actualName
                            + "\u201D is not an ASCII superset and, therefore, cannot be used in an internal encoding declaration.");
                }
            }
            if (!cs.isRegistered()) {
                if (encoding.startsWith("x-")) {
                    err("The encoding \u201C"
                            + actualName
                            + "\u201D is not an IANA-registered encoding. (Charmod C022)");                   
                } else {
                    err("The encoding \u201C"
                            + actualName
                            + "\u201D is not an IANA-registered encoding and did not use the \u201Cx-\u201D prefix. (Charmod C023)");
                }
            } else if (!canonName.equals(encoding)) {
                err("The encoding \u201C"
                        + actualName
                        + "\u201D is not the preferred name of the character encoding in use. The preferred name is \u201C"
                        + canonName + "\u201D. (Charmod C024)");
            }
            if (!("utf-8".equals(encoding) || "utf-16".equals(encoding)
                    || "utf-16be".equals(encoding)
                    || "utf-16le".equals(encoding)
                    || "iso-8859-1".equals(encoding) || "us-ascii".equals(encoding))) {
                handler.warn("XML processors are required to support the UTF-8 and UTF-16 character encodings. The encoding was \u201C"
                        + actualName
                        + "\u201D instead, which is an incompatibility risk.");
            }
            Encoding htmlActual = cs.getActualHtmlEncoding();
            if (htmlActual != null) {
                handler.warn("Documents encoded as \u201C"
                        + htmlActual.getCanonName()
                        + "\u201D are often mislabeled as \u201C"
                        + actualName
                        + "\u201D, which is the declared encoding of this document.");
            }
            CharsetDecoder decoder = cs.newDecoder();
View Full Code Here

Examples of org.apache.fontbox.encoding.Encoding

        List<String> additionalNames = new ArrayList<String>();
        Map<String,Integer> additionalNamesIndices = new HashMap<String,Integer>();
       
        if (glyphNames == null)
        {
            Encoding enc = MacRomanEncoding.INSTANCE;
            int[] gidToUC = this.baseCmap.getGlyphIdToCharacterCode();
            for (Integer glyphId : this.glyphIds)
            {
                int uc = gidToUC[glyphId.intValue()];
                String name = null;
                if (uc < 0x8000)
                {
                    try
                    {
                        name = enc.getNameFromCharacter((char)uc);
                    }
                    catch (IOException e)
                    {
                        // TODO
                    }
View Full Code Here

Examples of org.apache.pdfbox.encoding.Encoding

    {
        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

Examples of org.apache.pdfbox.encoding.Encoding

                        }
                    }
                    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

Examples of org.apache.pdfbox.encoding.Encoding

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

Examples of org.apache.pdfbox.encoding.Encoding

    {
        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

Examples of org.apache.pdfbox.encoding.Encoding

                        }
                    }
                    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 );
        }
        //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

Examples of org.apache.pdfbox.encoding.Encoding

            /*
             * only MacRomanEncoding or WinAnsiEncoding are allowed for a non symbolic font.
             */
            if (fd.isNonSymbolic())
            {
                Encoding encodingValue = this.font.getFontEncoding();
                if (encodingValue == null
                        || !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding))
                {
                    this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                            "The Encoding is invalid for the NonSymbolic TTF"));
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.encoding.Encoding

        int firstchar = 255;
        int lastchar = 0;

        // widths
        List<CharMetric> listmetric = metrics.getCharMetrics();
        Encoding encoding = getFontEncoding();
        int maxWidths = 256;
        List<Integer> widths = new ArrayList<Integer>(maxWidths);
        int zero = 250;

        Iterator<CharMetric> iter = listmetric.iterator();
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.encoding.Encoding

            /*
             * only MacRomanEncoding or WinAnsiEncoding are allowed for a non symbolic font.
             */
            if (fd.isNonSymbolic())
            {
                Encoding encodingValue = ttFont.getEncoding();
                if (encodingValue == null
                        || !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding))
                {
                    this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                            "The Encoding is invalid for the NonSymbolic TTF"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.