Exemple #1
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var widths = new List <PdfObject>();

            for (int i = FirstChar; i < LastChar + 1; i++)
            {
                if (!hashChar.Contains(i))
                {
                    widths.Add(new IntegerObject(0));
                }
                else if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var entries = new Dictionary <string, PdfObject> {
                { "Encoding", new NameObject("WinAnsiEncoding") },
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(FirstChar) },
                { "LastChar", new IntegerObject(LastChar) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            // a good guide: http://www.4real.gr/technical-documents-ttf-subset.html
            SubsetTTFFont = Subset(TTFFont);

            File.WriteAllBytes("file.ttf", SubsetTTFFont);

            var widths = new List <PdfObject>();

            widths.Add(new IntegerObject(this.Width));
            foreach (int i in hashChar)
            {
                if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var descriptor = new DocumentTtfDescriptorFont(this);
            var cmap       = new DocumentCmapFont(this);

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(0) },
                { "LastChar", new IntegerObject(hashChar.Count) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
                { "ToUnicode", cmap.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }