예제 #1
0
        private void DoInsert(Bitmap1 target, string fontFamily, string characters, int originY)
        {
            DeviceContext.Target = target;
            using (var font = GetSystemFont(fontFamily))
            {
                DeviceContext.BeginDraw();
#if DEBUG
                DrawGridLines();
#endif
                DeviceContext.Transform = Matrix3x2.Translation(0, originY);
                for (int i = 0; i < characters.Length; i += ColumnCount)
                {
                    int    currentRowLength = Math.Min(ColumnCount, characters.Length - i);
                    string currentRow       = characters.Substring(i, currentRowLength);

                    using (var glyphRun = new GlyphRun())
                    {
                        glyphRun.FontFace = new FontFace(font);
                        glyphRun.FontSize = FontSize;
                        glyphRun.Indices  = glyphRun.FontFace.GetGlyphIndices(currentRow.Select(c => (int)c).ToArray());
                        glyphRun.Advances = Enumerable.Repeat <float>(CellWidth, currentRowLength).ToArray();

                        var baselineOrigin = new Vector2(1.0f, 41.0f);
                        DeviceContext.PushAxisAlignedClip(new RectangleF(0, 0, CellWidth * ColumnCount, CellHeight), AntialiasMode.PerPrimitive);
                        DeviceContext.DrawGlyphRun(baselineOrigin, glyphRun, WhiteBrush, MeasuringMode.Natural);
                        DeviceContext.PopAxisAlignedClip();
                    }

                    var transform = Matrix3x2.Multiply(DeviceContext.Transform, Matrix3x2.Translation(0, CellHeight));
                    DeviceContext.Transform = transform;
                }

                DeviceContext.EndDraw();
            }

            DeviceContext.Target = null;
        }
 internal override void DoWork(DeviceContext context)
 {
     //context.DrawGlyphRun(BaselineOrigin, GlyphRun, ForegroundBrush, MeasuringMode);
     context.DrawGlyphRun(BaselineOrigin, GlyphRun, GlyphRunDescription, ForegroundBrush, MeasuringMode);
 }