Ejemplo n.º 1
0
        public SimpleGlyph Clone()
        {
            SimpleGlyph value = new SimpleGlyph();

            value.endPtsOfContours = new ushort[endPtsOfContours.Length];
            for (int i = 0; i < endPtsOfContours.Length; i++)
            {
                value.endPtsOfContours[i] = endPtsOfContours[i];
            }
            value.instructionLength = instructionLength;
            value.instructions      = new byte[instructionLength];
            for (int i = 0; i < instructionLength; i++)
            {
                value.instructions[i] = instructions[i];
            }
            value.flags = new SimpleGlyphFlags[flags.Length];
            for (int i = 0; i < flags.Length; i++)
            {
                value.flags[i] = flags[i];
            }
            value.xCoordinates = new short[xCoordinates.Length];
            for (int i = 0; i < xCoordinates.Length; i++)
            {
                value.xCoordinates[i] = xCoordinates[i];
            }
            value.yCoordinates = new short[yCoordinates.Length];
            for (int i = 0; i < yCoordinates.Length; i++)
            {
                value.yCoordinates[i] = yCoordinates[i];
            }
            return(value);
        }
Ejemplo n.º 2
0
 public static GlyphDescription Read(BinaryReaderFont reader, Glyph glyph)
 {
     if (glyph.numberOfContours >= 0)
     {
         return(SimpleGlyph.Read(reader, glyph));
     }
     return(CompositeGlyph.Read(reader, glyph));
 }
Ejemplo n.º 3
0
        public static void DrawGlyph(RendererContext context)
        {
            if (context.Glyph == null)
            {
                return;
            }
            SimpleGlyph simpleGlyph = context.Glyph.simpleGlyph;

            if (simpleGlyph == null)
            {
                return;
            }
            DrawSimpleGlyph(context, simpleGlyph);
            context.NextGlyph();
        }
Ejemplo n.º 4
0
        public static Glyph Read(BinaryReaderFont reader)
        {
            Glyph value = new Glyph {
                numberOfContours = reader.ReadInt16(),
                xMin             = reader.ReadInt16(),
                yMin             = reader.ReadInt16(),
                xMax             = reader.ReadInt16(),
                yMax             = reader.ReadInt16()
            };

            if (value.numberOfContours >= 0)
            {
                value.simpleGlyph = SimpleGlyph.Read(reader, value);
            }
            else
            {
                value.compositeGlyph = CompositeGlyph.Read(reader, value);
            }
            return(value);
        }
Ejemplo n.º 5
0
        public static new SimpleGlyph Read(BinaryReaderFont reader, Glyph glyph)
        {
            SimpleGlyph value = new SimpleGlyph {
                endPtsOfContours  = reader.ReadUInt16Array(glyph.numberOfContours),
                instructionLength = reader.ReadUInt16()
            };

            if (value.instructionLength > 0)
            {
                value.instructions = reader.ReadBytes(value.instructionLength);
            }
            int length = value.endPtsOfContours.Length;
            int count  = value.endPtsOfContours[length - 1] + 1;

            value.ReadFlags(reader, count);
            value.ReadXCoordinates(reader, count);
            value.ReadYCoordinates(reader, count);
            //Console.WriteLine("Glyph count: " + count);
            //Console.WriteLine("Glyph count2: " + value.flags.Length);
            return(value);
        }
Ejemplo n.º 6
0
        protected static void DrawSimpleGlyph(RendererContext context, SimpleGlyph simpleGlyph)
        {
            LongHorMetric hMetric = context.hMetric;
            //float unitsPerEm = font.Tables.head.unitsPerEm;
            float scale = context.Scale;
            //float scale = imageSize / unitsPerEm;
            //scale *= 0.01f;

            //float xMin = scale * (glyph.xMin + font.Tables.head.xMin);
            //float yMin = scale * (glyph.yMin + font.Tables.head.yMin);
            float xMin = context.X;            // + glyph.xMin;
            float yMin = 0;

            if (hMetric != null)
            {
                //Console.WriteLine("hMetric.lsb: {0}", hMetric.lsb);
                //Console.WriteLine("hMetric.advanceWidth " + hMetric.advanceWidth);
                xMin += context.Glyph.xMin - hMetric.lsb;
                xMin  = Math.Max(xMin, 0);
            }
            else
            {
                xMin += context.Glyph.xMin;
            }

            xMin *= scale;
            yMin  = context.Ascender * scale;
            xMin += context.DX;
            yMin += context.DY;

            //xMin = (float)Math.Round(xMin);

            /*
             * //Console.WriteLine("unitsPerEm " + unitsPerEm);
             * Console.WriteLine("ascender " + ascender);
             * Console.WriteLine("descender " + descender);
             * Console.WriteLine("scale " + scale);
             * Console.WriteLine("baseLine " + baseLine);
             * Console.WriteLine("glyph.xMin " + glyph.xMin);
             * Console.WriteLine("glyph.xMax " + glyph.xMax);
             * Console.WriteLine("glyph.yMin " + glyph.yMin);
             * Console.WriteLine("glyph.yMax " + glyph.yMax);
             * Console.WriteLine("head.xMin " + font.Tables.head.xMin);
             * Console.WriteLine("xMin " + xMin);
             * Console.WriteLine("yMin " + yMin);
             * Console.WriteLine();
             * //*/


            ushort[]           endPtsOfContours = simpleGlyph.endPtsOfContours;
            SimpleGlyphFlags[] flags            = simpleGlyph.flags;
            short[]            xCoordinates     = simpleGlyph.xCoordinates;
            short[]            yCoordinates     = simpleGlyph.yCoordinates;

            GraphicsPath path   = new GraphicsPath(FillMode.Alternate);
            int          length = endPtsOfContours.Length;
            int          start  = 0;

            PointF[] on  = new PointF[2];
            PointF[] off = new PointF[8];
            for (int n = 0; n < length; n++)
            {
                float fx = 0, fy = 0;
                int   onCount  = 0;
                int   offCount = 0;
                int   end      = endPtsOfContours[n];

                // first point is not on-curve
                if ((flags[start] & SimpleGlyphFlags.ON_CURVE_POINT) == 0)
                {
                    float x0 = xMin + xCoordinates[end] * scale;
                    float y0 = yMin - (yCoordinates[end] * scale);
                    on[0].X = x0;
                    on[0].Y = y0;
                    onCount++;
                    fx = x0;
                    fy = y0;
                }

                for (int i = start; i <= end; i++)
                {
                    float x0 = xMin + xCoordinates[i] * scale;
                    float y0 = yMin - (yCoordinates[i] * scale);
                    if ((flags[i] & SimpleGlyphFlags.ON_CURVE_POINT) > 0)
                    {
                        //if (onCount == 0) {
                        //	fx = x0;
                        //	fy = y0;
                        //}
                        on[onCount].X = x0;
                        on[onCount].Y = y0;
                        onCount++;
                        if (onCount == 2)
                        {
                            CreateCurvePoints(path, on, off, offCount);
                            onCount  = 1;
                            offCount = 0;
                            on[0].X  = on[1].X;
                            on[0].Y  = on[1].Y;
                        }
                        else
                        {
                            fx = x0;
                            fy = y0;
                        }
                    }
                    else
                    {
                        off[offCount].X = x0;
                        off[offCount].Y = y0;
                        offCount++;
                    }
                }
                if (onCount == 1)
                {
                    on[1].X = fx;
                    on[1].Y = fy;
                    CreateCurvePoints(path, on, off, offCount);
                }
                path.CloseFigure();
                start = end + 1;
            }
            context.Graphics.FillPath(Brushes.Black, path);
            path.Dispose();
        }