Examples of CMapToUnicode


Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

            throw new ExceptionConverter(e);
        }
    }

    private void doType1TT() {
        CMapToUnicode toUnicode = null;
        PdfObject enc = PdfReader.getPdfObject(font.get(PdfName.ENCODING));
        if (enc == null) {
            fillEncoding(null);
            try {
                toUnicode = processToUnicode();
                if (toUnicode != null) {
                    Map<Integer, Integer> rm = toUnicode.createReverseMapping();
                    for (Map.Entry<Integer, Integer> kv : rm.entrySet()) {
                        uni2byte.put(kv.getKey().intValue(), kv.getValue().intValue());
                    }
                }
            }
            catch (Exception ex) {
                throw new ExceptionConverter(ex);
            }
        }
        else {
            if (enc.isName())
                fillEncoding((PdfName)enc);
            else if (enc.isDictionary()) {
                PdfDictionary encDic = (PdfDictionary)enc;
                enc = PdfReader.getPdfObject(encDic.get(PdfName.BASEENCODING));
                if (enc == null)
                    fillEncoding(null);
                else
                    fillEncoding((PdfName)enc);
                PdfArray diffs = encDic.getAsArray(PdfName.DIFFERENCES);
                if (diffs != null) {
                    diffmap = new IntHashtable();
                    int currentNumber = 0;
                    for (int k = 0; k < diffs.size(); ++k) {
                        PdfObject obj = diffs.getPdfObject(k);
                        if (obj.isNumber())
                            currentNumber = ((PdfNumber)obj).intValue();
                        else {
                            int c[] = GlyphList.nameToUnicode(PdfName.decodeName(((PdfName)obj).toString()));
                            if (c != null && c.length > 0) {
                                uni2byte.put(c[0], currentNumber);
                                diffmap.put(c[0], currentNumber);
                            }
                            else {
                                if (toUnicode == null) {
                                    toUnicode = processToUnicode();
                                    if (toUnicode == null) {
                                        toUnicode = new CMapToUnicode();
                                    }
                                }
                                final String unicode = toUnicode.lookup(new byte[]{(byte) currentNumber}, 0, 1);
                                if ((unicode != null) && (unicode.length() == 1)) {
                                    this.uni2byte.put(unicode.charAt(0), currentNumber);
                                    this.diffmap.put(unicode.charAt(0), currentNumber);
                                }
                            }
View Full Code Here

Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

        }
        fillFontDesc(font.getAsDict(PdfName.FONTDESCRIPTOR));
    }

    private CMapToUnicode processToUnicode() {
        CMapToUnicode cmapRet = null;
        PdfObject toUni = PdfReader.getPdfObjectRelease(this.font.get(PdfName.TOUNICODE));
        if (toUni instanceof PRStream) {
            try {
                byte[] touni = PdfReader.getStreamBytes((PRStream)toUni);
                CidLocationFromByte lb = new CidLocationFromByte(touni);
                cmapRet = new CMapToUnicode();
                CMapParserEx.parseCid("", cmapRet, lb);
            } catch (Exception e) {
                cmapRet = null;
            }
        }
View Full Code Here

Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

        PdfObject toUni = PdfReader.getPdfObjectRelease(fontDic.get(PdfName.TOUNICODE));
        if (toUni instanceof PRStream){
            try {
                byte[] touni = PdfReader.getStreamBytes((PRStream)toUni);
                CidLocationFromByte lb = new CidLocationFromByte(touni);
                toUnicodeCmap = new CMapToUnicode();
                CMapParserEx.parseCid("", toUnicodeCmap, lb);
                uni2cid = toUnicodeCmap.createReverseMapping();
            } catch (IOException e) {
                toUnicodeCmap = null;
                uni2cid = null;
                // technically, we should log this or provide some sort of feedback... but sometimes the cmap will be junk, but it's still possible to get text, so we don't want to throw an exception
                //throw new IllegalStateException("Unable to process ToUnicode map - " + e.getMessage(), e);
            }
        }
        else if (isType0) {
            // fake a ToUnicode for CJK Identity-H fonts
            try {
                PdfName encodingName = fontDic.getAsName(PdfName.ENCODING);
                if (encodingName == null)
                    return;
                String enc = PdfName.decodeName(encodingName.toString());
                if (!enc.equals("Identity-H"))
                    return;
                PdfArray df = (PdfArray)PdfReader.getPdfObjectRelease(fontDic.get(PdfName.DESCENDANTFONTS));
                PdfDictionary cidft = (PdfDictionary)PdfReader.getPdfObjectRelease(df.getPdfObject(0));
                PdfDictionary cidinfo = cidft.getAsDict(PdfName.CIDSYSTEMINFO);
                if (cidinfo == null)
                    return;
                PdfString ordering = cidinfo.getAsString(PdfName.ORDERING);
                if (ordering == null)
                    return;
                CMapToUnicode touni = IdentityToUnicode.GetMapFromOrdering(ordering.toUnicodeString());
                if (touni == null)
                    return;
                toUnicodeCmap = touni;
                uni2cid = toUnicodeCmap.createReverseMapping();
            } catch (IOException e) {
View Full Code Here

Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

            throw new ExceptionConverter(e);
        }
    }

    private void doType1TT() {
        CMapToUnicode toUnicode = null;
        PdfObject enc = PdfReader.getPdfObject(font.get(PdfName.ENCODING));
        if (enc == null) {
            fillEncoding(null);
            try {
                toUnicode = processToUnicode();
                if (toUnicode != null) {
                    Map<Integer, Integer> rm = toUnicode.createReverseMapping();
                    for (Map.Entry<Integer, Integer> kv : rm.entrySet()) {
                        uni2byte.put(kv.getKey().intValue(), kv.getValue().intValue());
                    }
                }
            }
            catch (Exception ex) {
                throw new ExceptionConverter(ex);
            }
        }
        else {
            if (enc.isName())
                fillEncoding((PdfName)enc);
            else if (enc.isDictionary()) {
                PdfDictionary encDic = (PdfDictionary)enc;
                enc = PdfReader.getPdfObject(encDic.get(PdfName.BASEENCODING));
                if (enc == null)
                    fillEncoding(null);
                else
                    fillEncoding((PdfName)enc);
                PdfArray diffs = encDic.getAsArray(PdfName.DIFFERENCES);
                if (diffs != null) {
                    diffmap = new IntHashtable();
                    int currentNumber = 0;
                    for (int k = 0; k < diffs.size(); ++k) {
                        PdfObject obj = diffs.getPdfObject(k);
                        if (obj.isNumber())
                            currentNumber = ((PdfNumber)obj).intValue();
                        else {
                            int c[] = GlyphList.nameToUnicode(PdfName.decodeName(((PdfName)obj).toString()));
                            if (c != null && c.length > 0) {
                                uni2byte.put(c[0], currentNumber);
                                diffmap.put(c[0], currentNumber);
                            }
                            else {
                                if (toUnicode == null) {
                                    toUnicode = processToUnicode();
                                    if (toUnicode == null) {
                                        toUnicode = new CMapToUnicode();
                                    }
                                }
                                final String unicode = toUnicode.lookup(new byte[]{(byte) currentNumber}, 0, 1);
                                if ((unicode != null) && (unicode.length() == 1)) {
                                    this.uni2byte.put(unicode.charAt(0), currentNumber);
                                    this.diffmap.put(unicode.charAt(0), currentNumber);
                                }
                            }
View Full Code Here

Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

        }
        fillFontDesc(font.getAsDict(PdfName.FONTDESCRIPTOR));
    }

    private CMapToUnicode processToUnicode() {
        CMapToUnicode cmapRet = null;
        PdfObject toUni = PdfReader.getPdfObjectRelease(this.font.get(PdfName.TOUNICODE));
        if (toUni instanceof PRStream) {
            try {
                byte[] touni = PdfReader.getStreamBytes((PRStream)toUni);
                CidLocationFromByte lb = new CidLocationFromByte(touni);
                cmapRet = new CMapToUnicode();
                CMapParserEx.parseCid("", cmapRet, lb);
            } catch (Exception e) {
                cmapRet = null;
            }
        }
View Full Code Here

Examples of com.itextpdf.text.pdf.fonts.cmaps.CMapToUnicode

        PdfObject toUni = PdfReader.getPdfObjectRelease(fontDic.get(PdfName.TOUNICODE));
        if (toUni instanceof PRStream){
            try {
                byte[] touni = PdfReader.getStreamBytes((PRStream)toUni);
                CidLocationFromByte lb = new CidLocationFromByte(touni);
                toUnicodeCmap = new CMapToUnicode();
                CMapParserEx.parseCid("", toUnicodeCmap, lb);
                uni2cid = toUnicodeCmap.createReverseMapping();
            } catch (IOException e) {
                toUnicodeCmap = null;
                uni2cid = null;
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.