Inheritance: AbstractCMap
コード例 #1
0
ファイル: CMapTest.cs プロジェクト: yu0410aries/itextsharp
 private void CheckInsertAndRetrieval(byte[] bytes, string uni)
 {
     CMapToUnicode c = new CMapToUnicode();
     c.AddChar(new PdfString(bytes), new PdfString(uni, "UTF-16BE"));
     string lookupResult = c.Lookup(bytes, 0, bytes.Length);
     Assert.AreEqual(uni, lookupResult);
 }
コード例 #2
0
 public void TestCMapWithDefDictionaryKey()
 {
     byte[] touni = TestResourceUtils.GetResourceAsByteArray(TEST_RESOURCES_PATH, "cmap_with_def_dictionary_key.txt");
     CidLocationFromByte lb = new CidLocationFromByte(touni);
     CMapToUnicode cmapRet = new CMapToUnicode();
     CMapParserEx.ParseCid("", cmapRet, lb);
 }
コード例 #3
0
ファイル: CMapUniCid.cs プロジェクト: jagruti23/itextsharp
 virtual public CMapToUnicode ExportToUnicode() {
     CMapToUnicode uni = new CMapToUnicode();
     int[] keys = map.GetKeys();
     foreach (int key in keys) {
         uni.AddChar(map[key], Utilities.ConvertFromUtf32(key));
     }
     return uni;
 }
コード例 #4
0
 public static CMapToUnicode GetMapFromOrdering(String ordering)
 {
     if (ordering.Equals("CNS1"))
     {
         if (identityCNS == null)
         {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniCNS-UTF16-H");
             if (uni == null)
             {
                 return(null);
             }
             identityCNS = uni.ExportToUnicode();
         }
         return(identityCNS);
     }
     else if (ordering.Equals("Japan1"))
     {
         if (identityJapan == null)
         {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniJIS-UTF16-H");
             if (uni == null)
             {
                 return(null);
             }
             identityJapan = uni.ExportToUnicode();
         }
         return(identityJapan);
     }
     else if (ordering.Equals("Korea1"))
     {
         if (identityKorea == null)
         {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniKS-UTF16-H");
             if (uni == null)
             {
                 return(null);
             }
             identityKorea = uni.ExportToUnicode();
         }
         return(identityKorea);
     }
     else if (ordering.Equals("GB1"))
     {
         if (identityGB == null)
         {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniGB-UTF16-H");
             if (uni == null)
             {
                 return(null);
             }
             identityGB = uni.ExportToUnicode();
         }
         return(identityGB);
     }
     return(null);
 }
コード例 #5
0
ファイル: CMapToUnicode.cs プロジェクト: EnergonV/BestCS
        public static CMapToUnicode GetIdentity()
        {
            CMapToUnicode uni = new CMapToUnicode();

            for (int i = 0; i < 65537; i++)
            {
                uni.AddChar(i, Utilities.ConvertFromUtf32(i));
            }
            return(uni);
        }
コード例 #6
0
        virtual public CMapToUnicode ExportToUnicode()
        {
            CMapToUnicode uni = new CMapToUnicode();

            int[] keys = map.GetKeys();
            foreach (int key in keys)
            {
                uni.AddChar(map[key], Utilities.ConvertFromUtf32(key));
            }
            return(uni);
        }
コード例 #7
0
 public static CMapToUnicode GetMapFromOrdering(String ordering){
     if (ordering.Equals("CNS1")) {
         if (identityCNS == null) {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniCNS-UTF16-H");
             if (uni == null)
                 return null;
             identityCNS = uni.ExportToUnicode();
         }
         return identityCNS;
     }
     else if (ordering.Equals("Japan1")) {
         if (identityJapan == null) {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniJIS-UTF16-H");
             if (uni == null)
                 return null;
             identityJapan = uni.ExportToUnicode();
         }
         return identityJapan;
     }
     else if (ordering.Equals("Korea1")) {
         if (identityKorea == null) {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniKS-UTF16-H");
             if (uni == null)
                 return null;
             identityKorea = uni.ExportToUnicode();
         }
         return identityKorea;
     }
     else if (ordering.Equals("GB1")) {
         if (identityGB == null) {
             CMapUniCid uni = CMapCache.GetCachedCMapUniCid("UniGB-UTF16-H");
             if (uni == null)
                 return null;
             identityGB = uni.ExportToUnicode();
         }
         return identityGB;
     }
     else if (ordering.Equals("Identity")) {
         if (identityH == null) {
             identityH = CMapToUnicode.GetIdentity();
         }
         return identityH;
     }
     return null;
 }
コード例 #8
0
 /**
  * Parses the ToUnicode entry, if present, and constructs a CMap for it
  * @since 2.1.7
  */
 private void ProcessToUnicode(){
     PdfObject toUni = PdfReader.GetPdfObjectRelease(fontDic.Get(PdfName.TOUNICODE));
     if (toUni is PRStream) {
         try {
             byte[] touni = PdfReader.GetStreamBytes((PRStream)toUni);
             CidLocationFromByte lb = new CidLocationFromByte(touni);
             toUnicodeCmap = new CMapToUnicode();
             CMapParserEx.ParseCid("", toUnicodeCmap, lb);
             uni2cid = toUnicodeCmap.CreateReverseMapping();
         } catch {
             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[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) {
             toUnicodeCmap = null;
             uni2cid = null;
         }
     }
 }
コード例 #9
0
ファイル: DocumentFont.cs プロジェクト: Gianluigi/dssnet
 private CMapToUnicode ProcessToUnicode() {
     CMapToUnicode cmapRet = null;
     PdfObject toUni = PdfReader.GetPdfObjectRelease(this.font.Get(PdfName.TOUNICODE));
     if (toUni is PRStream) {
         try {
             byte[] touni = PdfReader.GetStreamBytes((PRStream)toUni);
             CidLocationFromByte lb = new CidLocationFromByte(touni);
             cmapRet = new CMapToUnicode();
             CMapParserEx.ParseCid("", cmapRet, lb);
         } catch {
             cmapRet = null;
         }
     }
     return cmapRet;
 }
コード例 #10
0
ファイル: DocumentFont.cs プロジェクト: Gianluigi/dssnet
 private void DoType1TT() {
     CMapToUnicode toUnicode = null;
     PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING));
     if (enc == null) {
         FillEncoding(null);
         toUnicode = ProcessToUnicode();
         if (toUnicode != null) {
             IDictionary<int, int> rm = toUnicode.CreateReverseMapping();
             foreach (KeyValuePair<int,int> kv in rm) {
                 uni2byte[kv.Key] = kv.Value;
                 byte2uni[kv.Value] = kv.Key;
             }
         }
     }
     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[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[c[0]] = currentNumber;
                             byte2uni[currentNumber] = c[0];
                             diffmap[c[0]] = currentNumber;
                         }
                         else {
                             if (toUnicode == null) {
                                 toUnicode = ProcessToUnicode();
                                 if (toUnicode == null) {
                                     toUnicode = new CMapToUnicode();
                                 }
                             }
                             string unicode = toUnicode.Lookup(new byte[]{(byte) currentNumber}, 0, 1);
                             if ((unicode != null) && (unicode.Length == 1)) {
                                 this.uni2byte[unicode[0]] = currentNumber;
                                 this.byte2uni[currentNumber] = unicode[0];
                                 this.diffmap[unicode[0]] = currentNumber;
                             }
                         }
                         ++currentNumber;
                     }
                 }
             }
         }
     }
     PdfArray newWidths = font.GetAsArray(PdfName.WIDTHS);
     PdfNumber first = font.GetAsNumber(PdfName.FIRSTCHAR);
     PdfNumber last = font.GetAsNumber(PdfName.LASTCHAR);
     if (BuiltinFonts14.ContainsKey(fontName)) {
         BaseFont bf = BaseFont.CreateFont(fontName, WINANSI, false);
         int[] e = uni2byte.ToOrderedKeys();
         for (int k = 0; k < e.Length; ++k) {
             int n = uni2byte[e[k]];
             widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k]));
         }
         if (diffmap != null) { //widths for differences must override existing ones
             e = diffmap.ToOrderedKeys();
             for (int k = 0; k < e.Length; ++k) {
                 int n = diffmap[e[k]];
                 widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k]));
             }
             diffmap = null;
         }
         Ascender = bf.GetFontDescriptor(ASCENT, 1000);
         CapHeight = bf.GetFontDescriptor(CAPHEIGHT, 1000);
         Descender = bf.GetFontDescriptor(DESCENT, 1000);
         ItalicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000);
         fontWeight = bf.GetFontDescriptor(FONT_WEIGHT, 1000);
         llx = bf.GetFontDescriptor(BBOXLLX, 1000);
         lly = bf.GetFontDescriptor(BBOXLLY, 1000);
         urx = bf.GetFontDescriptor(BBOXURX, 1000);
         ury = bf.GetFontDescriptor(BBOXURY, 1000);
     }
     if (first != null && last != null && newWidths != null) {
         int f = first.IntValue;
         int nSize = f + newWidths.Size;
         if (widths.Length < nSize) {
             int[] tmp = new int[nSize];
             System.Array.Copy(widths, 0, tmp, 0, f);
             widths = tmp;
         }
         for (int k = 0; k < newWidths.Size; ++k) {
             widths[f + k] = newWidths.GetAsNumber(k).IntValue;
         }
     }
     FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR));
 }
コード例 #11
0
 private void FillDiffMap(PdfDictionary encDic, CMapToUnicode toUnicode) {
     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[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[c[0]] = currentNumber;
                     byte2uni[currentNumber] = c[0];
                     diffmap[c[0]] = currentNumber;
                 }
                 else {
                     if (toUnicode == null) {
                         toUnicode = ProcessToUnicode();
                         if (toUnicode == null) {
                             toUnicode = new CMapToUnicode();
                         }
                     }
                     string unicode = toUnicode.Lookup(new byte[]{(byte) currentNumber}, 0, 1);
                     if ((unicode != null) && (unicode.Length == 1)) {
                         this.uni2byte[unicode[0]] = currentNumber;
                         this.byte2uni[currentNumber] = unicode[0];
                         this.diffmap[unicode[0]] = currentNumber;
                     }
                 }
                 ++currentNumber;
             }
         }
     }
 }
コード例 #12
0
 /**
  * Parses the ToUnicode entry, if present, and constructs a CMap for it
  * @since 2.1.7
  */
 private void ProcessToUnicode(){
     PdfObject toUni = PdfReader.GetPdfObjectRelease(fontDic.Get(PdfName.TOUNICODE));
     if (toUni is PRStream){
         try {
             byte[] touni = PdfReader.GetStreamBytes((PRStream)toUni);
             CidLocationFromByte lb = new CidLocationFromByte(touni);
             toUnicodeCmap = new CMapToUnicode();
             CMapParserEx.ParseCid("", toUnicodeCmap, lb);
             uni2cid = toUnicodeCmap.CreateReverseMapping();
         } catch {
             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);
         }
     }
 }
コード例 #13
0
 public static CMapToUnicode GetIdentity() {
     CMapToUnicode uni = new CMapToUnicode();
     for (int i = 0; i < 65537; i++) {
         uni.AddChar(i, Utilities.ConvertFromUtf32(i));
     }
     return uni;
 }