コード例 #1
0
ファイル: Direct2D1Platform.cs プロジェクト: yahiheb/Avalonia
        public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width)
        {
            var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl;

            var glyphCount = glyphRun.GlyphIndices.Length;

            var run = new SharpDX.DirectWrite.GlyphRun
            {
                FontFace = glyphTypeface.FontFace,
                FontSize = (float)glyphRun.FontRenderingEmSize
            };

            var indices = new short[glyphCount];

            for (var i = 0; i < glyphCount; i++)
            {
                indices[i] = (short)glyphRun.GlyphIndices[i];
            }

            run.Indices = indices;

            run.Advances = new float[glyphCount];

            width = 0;

            for (var i = 0; i < glyphCount; i++)
            {
                run.Advances[i] = (float)glyphRun.GlyphAdvances[i];
                width          += run.Advances[i];
            }

            run.Offsets = new GlyphOffset[glyphCount];

            for (var i = 0; i < glyphCount; i++)
            {
                var offset = glyphRun.GlyphOffsets[i];

                run.Offsets[i] = new GlyphOffset
                {
                    AdvanceOffset  = (float)offset.X,
                    AscenderOffset = (float)offset.Y
                };
            }

            return(new GlyphRunImpl(run));
        }
コード例 #2
0
        public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun)
        {
            var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl;

            var glyphCount = glyphRun.GlyphIndices.Length;

            var run = new SharpDX.DirectWrite.GlyphRun
            {
                FontFace = glyphTypeface.FontFace,
                FontSize = (float)glyphRun.FontRenderingEmSize
            };

            var indices = new short[glyphCount];

            for (var i = 0; i < glyphCount; i++)
            {
                indices[i] = (short)glyphRun.GlyphIndices[i];
            }

            run.Indices = indices;

            run.Advances = new float[glyphCount];

            var scale = (float)(glyphRun.FontRenderingEmSize / glyphTypeface.DesignEmHeight);

            if (glyphRun.GlyphAdvances.IsEmpty)
            {
                for (var i = 0; i < glyphCount; i++)
                {
                    var advance = glyphTypeface.GetGlyphAdvance(glyphRun.GlyphIndices[i]) * scale;

                    run.Advances[i] = advance;
                }
            }
            else
            {
                for (var i = 0; i < glyphCount; i++)
                {
                    var advance = (float)glyphRun.GlyphAdvances[i];

                    run.Advances[i] = advance;
                }
            }

            if (glyphRun.GlyphOffsets.IsEmpty)
            {
                return(new GlyphRunImpl(run));
            }

            run.Offsets = new GlyphOffset[glyphCount];

            for (var i = 0; i < glyphCount; i++)
            {
                var(x, y) = glyphRun.GlyphOffsets[i];

                run.Offsets[i] = new GlyphOffset
                {
                    AdvanceOffset  = (float)x,
                    AscenderOffset = (float)y
                };
            }

            return(new GlyphRunImpl(run));
        }