Example #1
0
 public static void RenderGlyph(
     TrueTypeFont.Glyph glyph,
     PixelData output,
     Vector2Int outputPosition,
     Vector2Int outputSize,
     double range,
     in Vector2Double scale,
Example #2
0
            public static Shape FromGlyph(TrueTypeFont.Glyph glyph, bool invertYAxis)
            {
                if (null == glyph)
                {
                    return(null);
                }

                Shape shape = new Shape
                {
                    contours = new Contour[glyph.contours.Length]
                };

                for (int i = 0; i < glyph.contours.Length; i++)
                {
                    ref var glyphContour = ref glyph.contours[i];

                    List <Edge> edges = new List <Edge>();

                    Vector2Double last  = glyph.points[glyphContour.start].xy;
                    Vector2Double start = last;

                    for (int p = 1; p < glyphContour.length;)
                    {
                        ref var glyphPoint = ref glyph.points[glyphContour.start + p++];

                        // Quadratic edge?
                        if (glyphPoint.curve == TrueTypeFont.CurveType.Conic)
                        {
                            var control = glyphPoint.xy;

                            for (; p < glyphContour.length;)
                            {
                                glyphPoint = ref glyph.points[glyphContour.start + p++];

                                if (glyphPoint.curve != TrueTypeFont.CurveType.Conic)
                                {
                                    edges.Add(new QuadraticEdge(
                                                  new Vector2Double(last.x, last.y),
                                                  new Vector2Double(control.x, control.y),
                                                  new Vector2Double(glyphPoint.xy.x, glyphPoint.xy.y)
                                                  ));
                                    last = glyphPoint.xy;
                                    break;
                                }

                                var middle = new Vector2Double((control.x + glyphPoint.xy.x) / 2, (control.y + glyphPoint.xy.y) / 2);

                                edges.Add(new QuadraticEdge(
                                              new Vector2Double(last.x, last.y),
                                              new Vector2Double(control.x, control.y),
                                              new Vector2Double(middle.x, middle.y)
                                              ));

                                last    = middle;
                                control = glyphPoint.xy;
                            }

                            if (p == glyphContour.length)
                            {
                                if (glyph.points[glyphContour.start + glyphContour.length - 1].curve == TrueTypeFont.CurveType.Conic)
                                {
                                    edges.Add(new QuadraticEdge(
                                                  new Vector2Double(last.x, last.y),
                                                  new Vector2Double(control.x, control.y),
                                                  new Vector2Double(start.x, start.y)
                                                  ));
                                }
                                else
                                {
                                    edges.Add(new LinearEdge(
                                                  new Vector2Double(last.x, last.y),
                                                  new Vector2Double(start.x, start.y)
                                                  ));
                                }
                            }


                            // Linear edge..
                        }
                        else
                        {
                            edges.Add(new LinearEdge(
                                          new Vector2Double(last.x, last.y),
                                          new Vector2Double(glyphPoint.xy.x, glyphPoint.xy.y)
                                          ));


                            last = glyphPoint.xy;

                            // If we ended on a linear then finish on a linear
                            if (p == glyphContour.length)
                            {
                                edges.Add(new LinearEdge(
                                              new Vector2Double(last.x, last.y),
                                              new Vector2Double(start.x, start.y)
                                              ));
                            }
                        }
                    }