private static void AddToUnicodeCMapObject(List <PDFobj> objects, Font font) { StringBuilder sb = new StringBuilder(); sb.Append("/CIDInit /ProcSet findresource begin\n"); sb.Append("12 dict begin\n"); sb.Append("begincmap\n"); sb.Append("/CIDSystemInfo <</Registry (Adobe) /Ordering (Identity) /Supplement 0>> def\n"); sb.Append("/CMapName /Adobe-Identity def\n"); sb.Append("/CMapType 2 def\n"); sb.Append("1 begincodespacerange\n"); sb.Append("<0000> <FFFF>\n"); sb.Append("endcodespacerange\n"); List <String> list = new List <String>(); StringBuilder buf = new StringBuilder(); for (int cid = 0; cid <= 0xffff; cid++) { int gid = font.unicodeToGID[cid]; if (gid > 0) { buf.Append('<'); buf.Append(FontStream1.ToHexString(gid)); buf.Append("> <"); buf.Append(FontStream1.ToHexString(cid)); buf.Append(">\n"); list.Add(buf.ToString()); buf.Length = 0; if (list.Count == 100) { FontStream1.WriteListToBuffer(sb, list); } } } if (list.Count > 0) { FontStream1.WriteListToBuffer(sb, list); } sb.Append("endcmap\n"); sb.Append("CMapName currentdict /CMap defineresource pop\n"); sb.Append("end\nend"); PDFobj obj = new PDFobj(); obj.dict.Add("<<"); obj.dict.Add("/Length"); obj.dict.Add(sb.Length.ToString()); obj.dict.Add(">>"); obj.SetStream((new System.Text.UTF8Encoding()).GetBytes(sb.ToString())); obj.number = objects.Count + 1; objects.Add(obj); font.toUnicodeCMapObjNumber = obj.number; }
internal static void Register(List <PDFobj> objects, Font font, Stream inputStream) { FontStream1.GetFontData(font, inputStream); EmbedFontFile(objects, font, inputStream); AddFontDescriptorObject(objects, font); AddCIDFontDictionaryObject(objects, font); AddToUnicodeCMapObject(objects, font); // Type0 Font Dictionary PDFobj obj = new PDFobj(); obj.dict.Add("<<"); obj.dict.Add("/Type"); obj.dict.Add("/Font"); obj.dict.Add("/Subtype"); obj.dict.Add("/Type0"); obj.dict.Add("/BaseFont"); obj.dict.Add("/" + font.name); obj.dict.Add("/Encoding"); obj.dict.Add("/Identity-H"); obj.dict.Add("/DescendantFonts"); obj.dict.Add("["); obj.dict.Add(font.cidFontDictObjNumber.ToString()); obj.dict.Add("0"); obj.dict.Add("R"); obj.dict.Add("]"); obj.dict.Add("/ToUnicode"); obj.dict.Add(font.toUnicodeCMapObjNumber.ToString()); obj.dict.Add("0"); obj.dict.Add("R"); obj.dict.Add(">>"); obj.number = objects.Count + 1; font.objNumber = obj.number; objects.Add(obj); }
// Constructor for .ttf.stream fonts: public Font(PDF pdf, Stream inputStream, bool flag) { FontStream1.Register(pdf, this, inputStream); SetSize(size); }