コード例 #1
0
        /// <summary>
        /// Creates the <see cref="IPathCollection"/> for all the characters, also getting their colors,
        /// glyph sizes and render offsets.
        /// </summary>
        public GlyphPath CreatePath(int size, int codepoint)
        {
            ColorGlyphRenderer glyphRenderer = new ColorGlyphRenderer();

            glyphRenderer.Reset();
            GlyphInstance glyphInstance = FontInstance.GetGlyph(codepoint);
            var           pointSize     = size * PointsPerInch / Dpi;

            glyphInstance.RenderTo(glyphRenderer, pointSize, new Vector2(0, 0), new Vector2(Dpi, Dpi), 0);
            IPathCollection p      = glyphRenderer.Paths;
            RectangleF      bounds = p.Bounds;

            var area = bounds.Width * bounds.Height;

            if (area == 0)
            {
                return(null);
            }

            if (char.IsWhiteSpace((char)codepoint))
            {
                p = null;
            }

            return(new GlyphPath
            {
                Size = size,
                Codepoint = codepoint,
                Bounds = new Microsoft.Xna.Framework.Rectangle((int)bounds.X, (int)bounds.Y,
                                                               (int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height)),
                Paths = p
            });
        }
コード例 #2
0
        /// <summary>
        /// Creates the <see cref="IPathCollection"/> for all the characters, also getting their colors,
        /// glyph sizes and render offsets.
        /// </summary>
        private IPathCollection[] CreatePaths(out Color?[][] colors, out System.Drawing.Point[] sizes, out Vector2[] offsets)
        {
            float glyphRenderY = Size / CalcDpi * FontInstance.Ascender / FontInstance.EmSize;
            ColorGlyphRenderer glyphRenderer = new ColorGlyphRenderer();

            IPathCollection[] paths = new IPathCollection[CharCount];
            sizes   = new System.Drawing.Point[paths.Length];
            offsets = new Vector2[paths.Length];
            colors  = null;

            for (int i = 0; i < paths.Length; i++)
            {
                char c = (char)(i + FirstChar);
                glyphRenderer.Reset();
                GlyphInstance glyphInstance = FontInstance.GetGlyph(c);
                glyphInstance.RenderTo(glyphRenderer, Size, new Vector2(0, glyphRenderY), new Vector2(DrawDpi, DrawDpi), 0);
                IPathCollection p      = glyphRenderer.Paths;
                RectangleF      bounds = p.Bounds;

                float area = bounds.Width * bounds.Height;
                if (float.IsFinite(area) && area != 0 && (c > char.MaxValue || !char.IsWhiteSpace(c)))
                {
                    paths[i]         = p;
                    sizes[i]         = new System.Drawing.Point((int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height));
                    renderOffsets[i] = new Vector2(bounds.X, bounds.Y);
                }

                if (glyphRenderer.HasAnyPathColors())
                {
                    if (colors == null)
                    {
                        colors = new Color?[CharCount][];
                    }

                    colors[i] = glyphRenderer.PathColors;
                }
            }

            return(paths);
        }