示例#1
0
        public override GlyphVector CreateGlyph(GlyphTable table)
        {
            var controlPoints = new List <Vector2>();
            var onCurves      = new List <bool>();
            var endPoints     = new List <ushort>();
            var minBounds     = new List <Vector2>();
            var maxBounds     = new List <Vector2>();
            var parts         = new List <GlyphInstance>();

            for (int resultIndex = 0; resultIndex < this.result.Length; resultIndex++)
            {
                ref Composite composite = ref this.result[resultIndex];

                GlyphVector glyph          = table.GetGlyph(composite.GlyphIndex);
                int         pointcount     = glyph.PointCount;
                ushort      endPointOffset = (ushort)controlPoints.Count;
                for (int i = 0; i < pointcount; i++)
                {
                    controlPoints.Add(Vector2.Transform(glyph.ControlPoints[i], composite.Transformation));
                    onCurves.Add(glyph.OnCurves[i]);
                }

                foreach (ushort p in glyph.EndPoints)
                {
                    endPoints.Add((ushort)(p + endPointOffset));
                }
            }
示例#2
0
        public override Glyphs.GlyphVector CreateGlyph(GlyphTable table)
        {
            List <Vector2>       controlPoints = new List <Vector2>();
            List <bool>          onCurves      = new List <bool>();
            List <ushort>        endPoints     = new List <ushort>();
            List <Vector2>       minBounds     = new List <Vector2>();
            List <Vector2>       maxBounds     = new List <Vector2>();
            List <GlyphInstance> parts         = new List <GlyphInstance>();

            foreach (Composite composite in this.result)
            {
                GlyphVector glyph          = table.GetGlyph(composite.GlyphIndex);
                int         pointcount     = glyph.PointCount;
                ushort      endPointOffset = (ushort)controlPoints.Count;
                for (int i = 0; i < pointcount; i++)
                {
                    controlPoints.Add(Vector2.Transform(glyph.ControlPoints[i], composite.Transformation));
                    onCurves.Add(glyph.OnCurves[i]);
                }

                foreach (ushort p in glyph.EndPoints)
                {
                    endPoints.Add((ushort)(p + endPointOffset));
                }
            }

            return(new Glyphs.GlyphVector(controlPoints.ToArray(), onCurves.ToArray(), endPoints.ToArray(), this.bounds));
        }
        /**
         * Builds vertical metrics with a custom CIDToGIDMap (for embedding font subset).
         */
        private void BuildVerticalMetrics(Dictionary <int, int> cidToGid)
        {
            // The "vhea" and "vmtx" tables that specify vertical metrics shall never be used by a conforming
            // reader. The only way to specify vertical metrics in PDF shall be by means of the DW2 and W2
            // entries in a CIDFont dictionary.

            if (!BuildVerticalHeader(cidFont))
            {
                return;
            }

            float scaling = 1000f / ttf.Header.UnitsPerEm;

            VerticalHeaderTable    vhea = ttf.VerticalHeader;
            VerticalMetricsTable   vmtx = ttf.VerticalMetrics;
            GlyphTable             glyf = ttf.Glyph;
            HorizontalMetricsTable hmtx = ttf.HorizontalMetrics;

            long v_y = (long)Math.Round(vhea.Ascender * scaling);
            long w1  = (long)Math.Round(-vhea.AdvanceHeightMax * scaling);

            PdfArray heights = new PdfArray();
            PdfArray w2      = new PdfArray();
            int      prev    = int.MinValue;
            // Use a sorted list to get an optimal width array
            ISet <int> keys = new HashSet <int>(cidToGid.Keys);

            foreach (int cid in keys)
            {
                // Unlike buildWidths, we look up with cid (not gid) here because this is
                // the original TTF, not the rebuilt one.
                GlyphData glyph = glyf.GetGlyph(cid);
                if (glyph == null)
                {
                    continue;
                }
                long height  = (long)Math.Round((glyph.YMaximum + vmtx.GetTopSideBearing(cid)) * scaling);
                long advance = (long)Math.Round(-vmtx.GetAdvanceHeight(cid) * scaling);
                if (height == v_y && advance == w1)
                {
                    // skip default metrics
                    continue;
                }
                // c [w1_1y v_1x v_1y w1_2y v_2x v_2y ... w1_ny v_nx v_ny]
                if (prev != cid - 1)
                {
                    w2 = new PdfArray();
                    heights.Add(PdfInteger.Get(cid)); // c
                    heights.Add(w2);
                }
                w2.Add(PdfInteger.Get(advance));   // w1_iy
                long width = (long)Math.Round(hmtx.GetAdvanceWidth(cid) * scaling);
                w2.Add(PdfInteger.Get(width / 2)); // v_ix
                w2.Add(PdfInteger.Get(height));    // v_iy
                prev = cid;
            }
            cidFont[PdfName.W2] = heights;
        }
示例#4
0
        public override Glyphs.GlyphVector CreateGlyph(GlyphTable table)
        {
            this.counter++;
            if (this.counter > 100)
            {
                throw new Fonts.Exceptions.FontException("loop detected loading glyphs");
            }

            return(table.GetGlyph(0));
        }
示例#5
0
 public override Glyphs.GlyphVector CreateGlyph(GlyphTable table)
 {
     if (this.loop)
     {
         if (this.glyph == null)
         {
             this.glyph = new GlyphVector(new Vector2[0], new bool[0], new ushort[0], this.fallbackEmptyBounds);
         }
         return(this.glyph.Value);
     }
     this.loop = true;
     return(table.GetGlyph(0));
 }
        public override GlyphVector CreateGlyph(GlyphTable table)
        {
            GlyphVector glyph = default;

            for (int resultIndex = 0; resultIndex < this.result.Length; resultIndex++)
            {
                ref Composite composite = ref this.result[resultIndex];
                glyph = GlyphVector.Append(glyph, GlyphVector.Transform(GlyphVector.DeepClone(table.GetGlyph(composite.GlyphIndex)), composite.Transformation), this.bounds);
            }