コード例 #1
0
        /// <summary>
        /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <param name="pointSize">Size of the point.</param>
        /// <param name="location">The location.</param>
        /// <param name="dpi">The dpi.</param>
        /// <param name="lineHeight">The lineHeight the current glyph was draw agains to offset topLeft while calling out to IGlyphRenderer.</param>
        /// <exception cref="System.NotSupportedException">Too many control points</exception>
        public void RenderTo(IGlyphRenderer surface, float pointSize, Vector2 location, Vector2 dpi, float lineHeight)
        {
            location = location * dpi;

            Vector2 firstPoint = Vector2.Zero;

            var scaledPoint = dpi * pointSize;

            var box = this.BoundingBox(location, scaledPoint);

            var hash = HashHelpers.Combine(this.GetHashCode(), pointSize.GetHashCode());

            hash = HashHelpers.Combine(hash, dpi.GetHashCode());

            // (lineHeight * dpi.Y)
            if (surface.BeginGlyph(box, hash))
            {
                int startOfContor = 0;
                int endOfContor   = -1;
                for (int i = 0; i < this.endPoints.Length; i++)
                {
                    surface.BeginFigure();
                    startOfContor = endOfContor + 1;
                    endOfContor   = this.endPoints[i];

                    Vector2 prev = Vector2.Zero;
                    Vector2 curr = this.GetPoint(ref scaledPoint, endOfContor) + location;
                    Vector2 next = this.GetPoint(ref scaledPoint, startOfContor) + location;

                    if (this.onCurves[endOfContor])
                    {
                        surface.MoveTo(curr);
                    }
                    else
                    {
                        if (this.onCurves[startOfContor])
                        {
                            surface.MoveTo(next);
                        }
                        else
                        {
                            // If both first and last points are off-curve, start at their middle.
                            Vector2 startPoint = (curr + next) / 2;
                            surface.MoveTo(startPoint);
                        }
                    }

                    int length = (endOfContor - startOfContor) + 1;
                    for (int p = 0; p < length; p++)
                    {
                        prev = curr;
                        curr = next;
                        int currentIndex = startOfContor + p;
                        int nextIndex    = startOfContor + ((p + 1) % length);
                        int prevIndex    = startOfContor + (((length + p) - 1) % length);
                        next = this.GetPoint(ref scaledPoint, nextIndex) + location;

                        if (this.onCurves[currentIndex])
                        {
                            // This is a straight line.
                            surface.LineTo(curr);
                        }
                        else
                        {
                            Vector2 prev2 = prev;
                            Vector2 next2 = next;

                            if (!this.onCurves[prevIndex])
                            {
                                prev2 = (curr + prev) / 2;
                                surface.LineTo(prev2);
                            }

                            if (!this.onCurves[nextIndex])
                            {
                                next2 = (curr + next) / 2;
                            }

                            surface.LineTo(prev2);
                            surface.QuadraticBezierTo(curr, next2);
                        }
                    }

                    surface.EndFigure();
                }
            }

            surface.EndGlyph();
        }
コード例 #2
0
ファイル: Glyph.cs プロジェクト: stefannikolei/Fonts
 /// <summary>
 /// Renders to.
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="dpi">The dpi.</param>
 /// <param name="lineHeight">The line height.</param>
 internal void RenderTo(IGlyphRenderer surface, Vector2 location, float dpi, float lineHeight)
 => this.RenderTo(surface, location, dpi, dpi, lineHeight);
コード例 #3
0
ファイル: Glyph.cs プロジェクト: stefannikolei/Fonts
 /// <summary>
 /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="dpiX">The dpi along the X axis.</param>
 /// <param name="dpiY">The dpi along the Y axis.</param>
 /// <param name="lineHeight">The line height.</param>
 /// <exception cref="System.NotSupportedException">Too many control points</exception>
 internal void RenderTo(IGlyphRenderer surface, Vector2 location, float dpiX, float dpiY, float lineHeight)
 => this.Instance.RenderTo(surface, this.pointSize, location, new Vector2(dpiX, dpiY), lineHeight);
コード例 #4
0
 /// <summary>
 /// Renders the text to the <paramref name="renderer"/>.
 /// </summary>
 /// <param name="renderer">The target renderer.</param>
 /// <param name="text">The text.</param>
 /// <param name="options">The style.</param>
 public static void RenderTextTo(IGlyphRenderer renderer, string text, RendererOptions options)
 {
     new TextRenderer(renderer).RenderText(text, options);
 }
コード例 #5
0
 /// <summary>
 /// Renders the text.
 /// </summary>
 /// <param name="renderer">The target renderer surface.</param>
 /// <param name="text">The text.</param>
 /// <param name="options">The options.</param>
 /// <returns>Returns the orginonal <paramref name="renderer"/></returns>
 public static IGlyphRenderer Render(this IGlyphRenderer renderer, ReadOnlySpan <char> text, RendererOptions options)
 {
     new TextRenderer(renderer).RenderText(text, options);
     return(renderer);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextRenderer"/> class.
 /// </summary>
 /// <param name="renderer">The renderer.</param>
 public TextRenderer(IGlyphRenderer renderer)
     : this(renderer, TextLayout.Default)
 {
 }
コード例 #7
0
 /// <summary>
 /// Renders the text to the <paramref name="renderer"/>.
 /// </summary>
 /// <param name="renderer">The target renderer.</param>
 /// <param name="text">The text.</param>
 /// <param name="options">The style.</param>
 public static void RenderTextTo(IGlyphRenderer renderer, ReadOnlySpan <char> text, RendererOptions options)
 {
     new TextRenderer(renderer).RenderText(text, options);
 }
コード例 #8
0
 /// <summary>
 /// Renders the text.
 /// </summary>
 /// <param name="renderer">The target renderer surface.</param>
 /// <param name="text">The text.</param>
 /// <param name="options">The options.</param>
 /// <returns>Returns the orginonal <paramref name="renderer"/></returns>
 public static IGlyphRenderer Render(this IGlyphRenderer renderer, string text, RendererOptions options)
 {
     new TextRenderer(renderer).RenderText(text, options);
     return(renderer);
 }
コード例 #9
0
 internal TextRenderer(IGlyphRenderer renderer, TextLayout layoutEngine)
 {
     this.layoutEngine = layoutEngine;
     this.renderer     = renderer;
 }
コード例 #10
0
 /// <summary>
 /// Renders to.
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="dpi">The dpi.</param>
 /// <param name="lineHeight">The line height.</param>
 internal void RenderTo(IGlyphRenderer surface, PointF location, float dpi, float lineHeight)
 {
     this.RenderTo(surface, location, dpi, dpi, lineHeight);
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextRenderer"/> class.
 /// </summary>
 /// <param name="renderer">The renderer.</param>
 public TextRenderer(IGlyphRenderer renderer)
     : this(renderer, new TextLayout())
 {
 }
コード例 #12
0
 /// <summary>
 /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="options">The options to render using.</param>
 /// <exception cref="System.NotSupportedException">Too many control points.</exception>
 internal void RenderTo(IGlyphRenderer surface, Vector2 location, TextOptions options)
 => this.GlyphMetrics.RenderTo(surface, this.pointSize, location, options);
コード例 #13
0
        /// <summary>
        /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <param name="pointSize">Size of the point.</param>
        /// <param name="location">The location.</param>
        /// <param name="dpi">The dpi.</param>
        /// <param name="lineHeight">The lineHeight the current glyph was draw agains to offset topLeft while calling out to IGlyphRenderer.</param>
        /// <exception cref="NotSupportedException">Too many control points</exception>
        public void RenderTo(IGlyphRenderer surface, float pointSize, Vector2 location, Vector2 dpi, float lineHeight)
        {
            location = location * dpi;

            Vector2 firstPoint = Vector2.Zero;

            Vector2 scaledPoint = dpi * pointSize;

            FontRectangle box = this.BoundingBox(location, scaledPoint);

            var paramaters = new GlyphRendererParameters(this, pointSize, dpi);

            if (surface.BeginGlyph(box, paramaters))
            {
                if (this.GlyphColor.HasValue && surface is IColorGlyphRenderer colorSurface)
                {
                    colorSurface.SetColor(this.GlyphColor.Value);
                }

                int endOfContor = -1;
                for (int i = 0; i < this.vector.EndPoints.Length; i++)
                {
                    surface.BeginFigure();
                    int startOfContor = endOfContor + 1;
                    endOfContor = this.vector.EndPoints[i];

                    Vector2 prev = Vector2.Zero;
                    Vector2 curr = this.GetPoint(ref scaledPoint, endOfContor) + location;
                    Vector2 next = this.GetPoint(ref scaledPoint, startOfContor) + location;

                    if (this.vector.OnCurves[endOfContor])
                    {
                        surface.MoveTo(curr);
                    }
                    else
                    {
                        if (this.vector.OnCurves[startOfContor])
                        {
                            surface.MoveTo(next);
                        }
                        else
                        {
                            // If both first and last points are off-curve, start at their middle.
                            Vector2 startPoint = (curr + next) / 2;
                            surface.MoveTo(startPoint);
                        }
                    }

                    int length = (endOfContor - startOfContor) + 1;
                    for (int p = 0; p < length; p++)
                    {
                        prev = curr;
                        curr = next;
                        int currentIndex = startOfContor + p;
                        int nextIndex    = startOfContor + ((p + 1) % length);
                        int prevIndex    = startOfContor + (((length + p) - 1) % length);
                        next = this.GetPoint(ref scaledPoint, nextIndex) + location;

                        if (this.vector.OnCurves[currentIndex])
                        {
                            // This is a straight line.
                            surface.LineTo(curr);
                        }
                        else
                        {
                            Vector2 prev2 = prev;
                            Vector2 next2 = next;

                            if (!this.vector.OnCurves[prevIndex])
                            {
                                prev2 = (curr + prev) / 2;
                                surface.LineTo(prev2);
                            }

                            if (!this.vector.OnCurves[nextIndex])
                            {
                                next2 = (curr + next) / 2;
                            }

                            surface.LineTo(prev2);
                            surface.QuadraticBezierTo(curr, next2);
                        }
                    }

                    surface.EndFigure();
                }
            }

            surface.EndGlyph();
        }
コード例 #14
0
ファイル: NxFont.cs プロジェクト: tgsstdio/BirdNest.QuickFont
		public void InitialiseGlyphRenderer(IDrawCommandList commandList, IGlyphRenderer mainFont, IGlyphRenderer dropShadow)
		{			
			if (commandList == null)
				return;

			FontRenderer = mainFont ?? new BufferedGlyphRenderer (commandList, fontData, Vector3.Zero, new Vector4(1,1,1,1));

			if (DropShadow != null)
			{
				DropShadow.FontRenderer = dropShadow ?? new BufferedGlyphRenderer (commandList, DropShadow.fontData, Vector3.Zero, new Vector4(1,1,1,1));
			}
		}
コード例 #15
0
ファイル: Glyph.cs プロジェクト: hongweichang/NFinal2
 /// <summary>
 /// Renders the glyph to the render surface in font units relative to a bottom left origin at (0,0)
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="dpi">The dpi.</param>
 /// <exception cref="System.NotSupportedException">Too many control points</exception>
 public void RenderTo(IGlyphRenderer surface, Vector2 location, Vector2 dpi)
 {
     this.instance.RenderTo(surface, this.pointSize, location, dpi);
 }
コード例 #16
0
ファイル: Glyph.cs プロジェクト: hongweichang/NFinal2
 /// <summary>
 /// Renders to.
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="location">The location.</param>
 /// <param name="dpi">The dpi.</param>
 public void RenderTo(IGlyphRenderer surface, Vector2 location, float dpi)
 {
     this.RenderTo(surface, location, new Vector2(dpi));
 }