protected internal virtual void FillNamedEncoding() { PdfEncodings.ConvertToBytes(" ", baseEncoding); // check if the encoding exists bool stdEncoding = PdfEncodings.WINANSI.Equals(baseEncoding) || PdfEncodings.MACROMAN.Equals(baseEncoding); if (!stdEncoding && differences == null) { differences = new String[256]; } byte[] b = new byte[256]; for (int k = 0; k < 256; ++k) { b[k] = (byte)k; } String str = PdfEncodings.ConvertToString(b, baseEncoding); char[] encoded = str.ToCharArray(); for (int ch = 0; ch < 256; ++ch) { char uni = encoded[ch]; String name = AdobeGlyphList.UnicodeToName(uni); if (name == null) { name = FontConstants.notdef; } else { unicodeToCode.Put(uni, ch); codeToUnicode[ch] = (int)uni; unicodeDifferences.Put(uni, uni); } if (differences != null) { differences[ch] = name; } } }
static AdobeGlyphList() { Stream resource = null; try { resource = ResourceUtil.GetResourceStream(FontResources.ADOBE_GLYPH_LIST); if (resource == null) { throw new Exception(FontResources.ADOBE_GLYPH_LIST + " not found as resource."); } byte[] buf = new byte[1024]; MemoryStream stream = new MemoryStream(); while (true) { int size = resource.Read(buf); if (size < 0) { break; } stream.Write(buf, 0, size); } resource.Dispose(); resource = null; String s = PdfEncodings.ConvertToString(stream.ToArray(), null); StringTokenizer tk = new StringTokenizer(s, "\r\n"); while (tk.HasMoreTokens()) { String line = tk.NextToken(); if (line.StartsWith("#")) { continue; } StringTokenizer t2 = new StringTokenizer(line, " ;\r\n\t\f"); if (!t2.HasMoreTokens()) { continue; } String name = t2.NextToken(); if (!t2.HasMoreTokens()) { continue; } String hex = t2.NextToken(); // AdobeGlyphList could contains symbols with marks, e.g.: // resh;05E8 // reshhatafpatah;05E8 05B2 // So in this case we will just skip this nam if (t2.HasMoreTokens()) { continue; } int num = Convert.ToInt32(hex, 16); unicode2names.Put(num, name); names2unicode.Put(name, num); } } catch (Exception e) { System.Console.Error.WriteLine("AdobeGlyphList.txt loading error: " + e.Message); } finally { if (resource != null) { try { resource.Dispose(); } catch (Exception) { } } } }
static AdobeGlyphList() { Stream resource = null; try { resource = ResourceUtil.GetResourceStream(FontConstants.RESOURCE_PATH + "AdobeGlyphList.txt"); if (resource == null) { String msg = "AdobeGlyphList.txt not found as resource. (It must exist as resource in the package com.itextpdf.text.pdf.fonts)"; throw new Exception(msg); } byte[] buf = new byte[1024]; MemoryStream stream = new MemoryStream(); while (true) { int size = resource.Read(buf); if (size < 0) { break; } stream.Write(buf, 0, size); } resource.Close(); resource = null; String s = PdfEncodings.ConvertToString(stream.ToArray(), null); StringTokenizer tk = new StringTokenizer(s, "\r\n"); while (tk.HasMoreTokens()) { String line = tk.NextToken(); if (line.StartsWith("#")) { continue; } StringTokenizer t2 = new StringTokenizer(line, " ;\r\n\t\f"); if (!t2.HasMoreTokens()) { continue; } String name = t2.NextToken(); if (!t2.HasMoreTokens()) { continue; } String hex = t2.NextToken(); // AdobeGlyphList could contains symbols with marks, e.g.: // resh;05E8 // reshhatafpatah;05E8 05B2 // So in this case we will just skip this nam if (t2.HasMoreTokens()) { continue; } int num = System.Convert.ToInt32(hex, 16); unicode2names[num] = name; names2unicode[name] = num; } } catch (Exception e) { System.Console.Error.WriteLine("AdobeGlyphList.txt loading error: " + e.Message); } finally { if (resource != null) { try { resource.Close(); } catch (Exception) { } } } }