private static void ColumnHeaderStyle_Paint(Altaxo.Worksheet.ColumnHeaderStyle thiss, object drawingContext, RectangleD2D cellRect, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            var  dc            = (DrawingContext)drawingContext;
            Rect cellRectangle = cellRect.ToWpf();

            thiss.PaintBackground(dc, cellRect, bSelected);

            var    dataColCol    = (Altaxo.Data.DataColumnCollection)AbsoluteDocumentPath.GetRootNodeImplementing(data, typeof(Altaxo.Data.DataColumnCollection));
            string columnnumber  = dataColCol.GetColumnNumber(data).ToString();
            string kindandgroup  = string.Format("({0}{1})", dataColCol.GetColumnKind(data).ToString(), dataColCol.GetColumnGroup(data));
            var    font          = WpfFontManager.ToWpf(thiss.TextFont);
            var    fontSize      = (thiss.TextFont.Size * 96) / 72;
            var    fontheight    = font.FontFamily.LineSpacing * fontSize;
            var    nameRectangle = cellRectangle;

            nameRectangle.Height = Math.Max(fontheight, cellRectangle.Height - fontheight);
            var numRectangle = cellRectangle;

            numRectangle.Height = fontheight;
            numRectangle.Y      = Math.Max(cellRectangle.Y + cellRectangle.Height - fontheight, cellRectangle.Y);

            var txtBrush = bSelected ? thiss.DefaultSelectedTextBrush.ToWpf() : thiss.TextBrush.ToWpf();

            FormattedText t;

            t = new FormattedText(columnnumber, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font, fontSize, txtBrush)
            {
                MaxTextWidth  = numRectangle.Width,
                TextAlignment = TextAlignment.Left
            };
            dc.DrawText(t, numRectangle.Location);

            t = new FormattedText(kindandgroup, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font, fontSize, txtBrush)
            {
                MaxTextWidth  = numRectangle.Width,
                TextAlignment = TextAlignment.Right
            };
            dc.DrawText(t, numRectangle.Location);

            t = new FormattedText(data.Name, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font, fontSize, txtBrush)
            {
                MaxTextWidth  = nameRectangle.Width,
                TextAlignment = TextAlignment.Center
            };
            dc.DrawText(t, nameRectangle.Location);
        }
        private static void GeneralText_Paint(Altaxo.Worksheet.ColumnStyle thiss, object drawingContext, RectangleD2D cellRect, string textToDraw, TextAlignment alignment, bool bSelected)
        {
            var  dc            = (DrawingContext)drawingContext;
            Rect cellRectangle = cellRect.ToWpf();

            thiss.PaintBackground(dc, cellRect, bSelected);

            var font     = WpfFontManager.ToWpf(thiss.TextFont);
            var fontSize = (thiss.TextFont.Size * 96) / 72;
            var txtBrush = bSelected ? thiss.DefaultSelectedTextBrush.ToWpf() : thiss.TextBrush.ToWpf();

            FormattedText t;

            t = new FormattedText(textToDraw, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font, fontSize, txtBrush)
            {
                MaxTextWidth  = cellRect.Width,
                TextAlignment = alignment,
                Trimming      = TextTrimming.CharacterEllipsis
            };
            dc.DrawText(t, cellRectangle.Location);
        }
        private static void RowHeaderStyle_Paint(Altaxo.Worksheet.RowHeaderStyle thiss, object drawingContext, RectangleD2D cellRect, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            var  dc            = (DrawingContext)drawingContext;
            Rect cellRectangle = cellRect.ToWpf();

            thiss.PaintBackground(dc, cellRect, bSelected);

            string text = "[" + nRow + "]";

            var font     = WpfFontManager.ToWpf(thiss.TextFont);
            var fontSize = (thiss.TextFont.Size * 96) / 72;
            var txtBrush = bSelected ? thiss.DefaultSelectedTextBrush.ToWpf() : thiss.TextBrush.ToWpf();

            FormattedText t;

            t = new FormattedText(text, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font, fontSize, txtBrush)
            {
                MaxTextWidth  = cellRectangle.Width,
                TextAlignment = TextAlignment.Center
            };
            dc.DrawText(t, cellRectangle.Location); // ("[" + nRow + "]", _textFont, _textBrush, cellRectangle, _textFormat);
        }
            private static ImageSource GetImage(string fontFamilyName)
            {
                const double height   = 1;
                const double width    = 2;
                const double fontSize = 1;

                var drawingGroup = new DrawingGroup();

                var outerGeometry = new RectangleGeometry(new Rect(0, 0, width, height));

                var geometryDrawing = new GeometryDrawing()
                {
                    Geometry = outerGeometry
                };

                geometryDrawing.Pen = new Pen(Brushes.Transparent, 0);
                drawingGroup.Children.Add(geometryDrawing);

                var      fontX    = WpfFontManager.GetFontX(fontFamilyName, 12, Altaxo.Drawing.FontXStyle.Regular);
                Typeface typeface = WpfFontManager.ToWpf(fontX);

                if (!typeface.TryGetGlyphTypeface(out var glyphTypeFace))
                {
                    glyphTypeFace = null;
                }

                if (null != glyphTypeFace)
                {
                    var glyphRun = new GlyphRun();
                    ((System.ComponentModel.ISupportInitialize)glyphRun).BeginInit();
                    glyphRun.GlyphTypeface       = glyphTypeFace;
                    glyphRun.FontRenderingEmSize = fontSize;
                    var textChars = GetDisplayText(glyphTypeFace);
                    glyphRun.Characters = textChars;

                    ushort[] glyphIndices  = new ushort[textChars.Length];
                    double[] advanceWidths = new double[textChars.Length];

                    for (int i = 0; i < textChars.Length; ++i)
                    {
                        int    codePoint  = textChars[i];
                        ushort glyphIndex = glyphTypeFace.CharacterToGlyphMap[codePoint];
                        double glyphWidht = glyphTypeFace.AdvanceWidths[glyphIndex];
                        glyphIndices[i]  = glyphIndex;
                        advanceWidths[i] = glyphWidht * fontSize;
                    }

                    if (glyphIndices.Length > 0)
                    {
                        glyphRun.GlyphIndices   = glyphIndices;
                        glyphRun.AdvanceWidths  = advanceWidths;
                        glyphRun.BaselineOrigin = new Point(0, glyphTypeFace.Baseline * fontSize);
                        ((System.ComponentModel.ISupportInitialize)glyphRun).EndInit();

                        var glyphRunDrawing = new GlyphRunDrawing(Brushes.Black, glyphRun);
                        drawingGroup.Children.Add(glyphRunDrawing);
                    }
                }

                drawingGroup.ClipGeometry = outerGeometry;

                var geometryImage = new DrawingImage(drawingGroup);

                // Freeze the DrawingImage for performance benefits.
                geometryImage.Freeze();
                return(geometryImage);
            }