示例#1
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            var    dataColCol   = (Altaxo.Data.DataColumnCollection)Main.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 gdiTextFont = GdiFontManager.ToGdi(_textFont);

            var       fontheight    = gdiTextFont.GetHeight(dc);
            Rectangle nameRectangle = cellRectangle;

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

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

            if (bSelected)
            {
                dc.DrawString(columnnumber, gdiTextFont, _defaultSelectedTextBrush, numRectangle, _leftUpperTextFormat);
                dc.DrawString(kindandgroup, gdiTextFont, _defaultSelectedTextBrush, numRectangle, _rightUpperTextFormat);
                dc.DrawString(data.Name, gdiTextFont, _defaultSelectedTextBrush, nameRectangle, _textFormat);
            }
            else
            {
                dc.DrawString(columnnumber, gdiTextFont, TextBrush, numRectangle, _leftUpperTextFormat);
                dc.DrawString(kindandgroup, gdiTextFont, TextBrush, numRectangle, _rightUpperTextFormat);
                dc.DrawString(data.Name, gdiTextFont, TextBrush, nameRectangle, _textFormat);
            }
        }
示例#2
0
 public override void Measure(Graphics g, MeasureContext mc, double x)
 {
   var fontInfo = mc.FontCache.GetFontInfo(g, Style.FontId);
   Width = g.MeasureString(_text, GdiFontManager.ToGdi(Style.FontId), PointF.Empty, _stringFormat).Width;
   ExtendAboveBaseline = fontInfo.cyAscent;
   ExtendBelowBaseline = fontInfo.cyDescent;
 }
示例#3
0
 public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext)
 {
     _text   = itemtext;
     _font   = font;
     _strfmt = strfmt;
     _size   = g.MeasureString(_text, GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt);
 }
示例#4
0
        public override void DrawItem(Graphics g, BrushX brush, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg)
        {
            SplitInFirstPartAndExponent(item, out var firstpart, out var mant, out var middelpart, out var exponent);

            var   gdiFont = GdiFontManager.ToGdi(font);
            SizeF size1   = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, morg, strfmt);

            g.DrawString(_prefix + firstpart + middelpart, gdiFont, brush, morg, strfmt);
            var orginalY = morg.Y;

            morg.X += size1.Width;
            morg.Y += size1.Height / 3;
            FontX font2    = font.WithSize(font.Size * 2 / 3.0);
            var   gdiFont2 = GdiFontManager.ToGdi(font2);

            g.DrawString(exponent, gdiFont2, brush, morg);
            if (!string.IsNullOrEmpty(_suffix))
            {
                morg.X += g.MeasureString(exponent, gdiFont2, morg, strfmt).Width;
                morg.Y  = orginalY;
            }

            if (!string.IsNullOrEmpty(_suffix))
            {
                g.DrawString(_suffix, gdiFont, brush, morg, strfmt);
            }
        }
示例#5
0
        public override void Paint(Graphics g, IPaintContext paintContext)
        {
            System.Drawing.Drawing2D.GraphicsState gs = g.Save();
            TransformGraphics(g);

            // Modification of StringFormat is necessary to avoid
            // too big spaces between successive words
            var strfmt = (StringFormat)StringFormat.GenericTypographic.Clone();

            strfmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

            strfmt.LineAlignment = StringAlignment.Near;
            strfmt.Alignment     = StringAlignment.Near;

            // next statement is necessary to have a consistent string length both
            // on 0 degree rotated text and rotated text
            // without this statement, the text is fitted to the pixel grid, which
            // leads to "steps" during scaling
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            if (AutoSize)
            {
                var mySize = g.MeasureString(_text, GdiFontManager.ToGdi(_font));
                Width  = mySize.Width;
                Height = mySize.Height;
                g.DrawString(_text, GdiFontManager.ToGdi(_font), new SolidBrush(_color), 0, 0, strfmt);
            }
            else
            {
                var rect = new RectangleF(0, 0, (float)Width, (float)Height);
                g.DrawString(_text, GdiFontManager.ToGdi(_font), new SolidBrush(_color), rect, strfmt);
            }

            g.Restore(gs);
        }
示例#6
0
 public override void InitializeContent()
 {
     // Fill with all available font families
     foreach (var famName in GdiFontManager.EnumerateAvailableGdiFontFamilyNames().OrderBy(x => x))
     {
         Items.Add(famName);
     }
 }
示例#7
0
 public override void Draw(Graphics g, DrawContext dc, double xbase, double ybase)
 {
   if (_child != null)
   {
     _child.Draw(g, dc, xbase, ybase);
     FontInfo fontInfo = dc.FontCache.GetFontInfo(g, Style.FontId);
     g.DrawString("_", GdiFontManager.ToGdi(Style.FontId), Style.brush, (float)(xbase), (float)(ybase - _child.ExtendAboveBaseline - fontInfo.cyAscent), StringFormat);
   }
 }
示例#8
0
        public override System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
        {
            SplitInFirstPartAndExponent(mtick, out var firstpart, out var mant, out var middelpart, out var exponent);

            var   gdiFont = GdiFontManager.ToGdi(font);
            SizeF size1   = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, new PointF(0, 0), strfmt);
            SizeF size2   = g.MeasureString(exponent, gdiFont, new PointF(size1.Width, 0), strfmt);
            SizeF size3   = g.MeasureString(_suffix, gdiFont, new PointF(0, 0), strfmt);

            return(new SizeF(size1.Width + size2.Width + size3.Width, size1.Height));
        }
示例#9
0
 public override void Draw(Graphics g, DrawContext dc, double xbase, double ybase)
 {
   if (_child != null)
   {
     _child.Draw(g, dc, xbase, ybase);
     FontInfo fontInfo = dc.FontCache.GetFontInfo(g, Style.FontId);
     var gdiFont = GdiFontManager.ToGdi(Style.FontId);
     double psize = g.MeasureString(".", gdiFont, PointF.Empty, StringFormat).Width;
     g.DrawString(".", gdiFont, Style.brush, (float)(xbase + _child.Width / 2 - psize / 2), (float)(ybase - _child.ExtendAboveBaseline - fontInfo.cyAscent), StringFormat);
   }
 }
示例#10
0
            public virtual void Draw(Graphics g, BrushX brush, PointF point)
            {
                g.DrawString(_firstpart, GdiFontManager.ToGdi(_font1), brush, point, _strfmt);

                point.X += _size1.Width;
                point.Y += 0;

                g.DrawString(_exponent, GdiFontManager.ToGdi(_font2), brush, point, _strfmt);

                point.X += _size2.Width;
                g.DrawString(_lastpart, GdiFontManager.ToGdi(_font1), brush, point, _strfmt);
            }
示例#11
0
 private static void InternalGetInformation(Graphics g, FontInfo result, FontX font)
 {
   // get some properties of the font
   var gdiFont = GdiFontManager.ToGdi(font);
   result.Size = gdiFont.Size;
   result.cyLineSpace = gdiFont.GetHeight(g); // space between two lines
   int iCellSpace = gdiFont.FontFamily.GetLineSpacing(gdiFont.Style);
   int iCellAscent = gdiFont.FontFamily.GetCellAscent(gdiFont.Style);
   int iCellDescent = gdiFont.FontFamily.GetCellDescent(gdiFont.Style);
   result.cyAscent = result.cyLineSpace * iCellAscent / iCellSpace;
   result.cyDescent = result.cyLineSpace * iCellDescent / iCellSpace;
 }
示例#12
0
 public MeasuredLabelItem(Graphics g, FontX font1, FontX font2, StringFormat strfmt, string firstpart, string exponent, string lastpart, float maxexposize)
 {
     _firstpart    = firstpart;
     _exponent     = exponent;
     _lastpart     = lastpart;
     _font1        = font1;
     _font2        = font2;
     _strfmt       = strfmt;
     _size1        = g.MeasureString(_firstpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt);
     _size2        = g.MeasureString(_exponent, GdiFontManager.ToGdi(_font2), new PointF(_size1.Width, 0), strfmt);
     _size3        = g.MeasureString(_lastpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt);
     _rightPadding = maxexposize - _size2.Width;
 }
示例#13
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            if (bSelected)
            {
                dc.DrawString("[" + nRow + "]", GdiFontManager.ToGdi(_textFont), _defaultSelectedTextBrush, cellRectangle, _textFormat);
            }
            else
            {
                dc.DrawString("[" + nRow + "]", GdiFontManager.ToGdi(_textFont), TextBrush, cellRectangle, _textFormat);
            }
        }
示例#14
0
        protected override void Initialize(bool initData)
        {
            base.Initialize(initData);

            if (initData)
            {
            }
            if (null != _view)
            {
                // fill the font name combobox with all fonts
                _view.SelectedFontFamilyName = GdiFontManager.GetValidFontFamilyName(_doc);
                _view.SelectedFontSize       = _doc.Size;
            }
        }
示例#15
0
      public override void Measure(Graphics g, MeasureContext mc, double x)
      {
        Height = 0;
        Width = 0;

        double tab = mc.TabStop;

        if (!(tab > 0))
          tab = g.MeasureString("MMMM", GdiFontManager.ToGdi(Style.BaseFontId), PointF.Empty, _stringFormat).Width;

        if (!(tab > 0))
          tab = Style.BaseFontId.Size * 4;

        if (tab > 0)
        {
          double t = Math.Floor(x / tab);
          Width = (t + 1) * tab - x;
        }
      }
示例#16
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            DateTime t = ((Altaxo.Data.DateTimeColumn)data)[nRow];

            string myString = (t.Kind == DateTimeKind.Unspecified || t.Kind == DateTimeKind.Local) ?
                              t.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFF") :
                              t.ToString("o");

            if (bSelected)
            {
                dc.DrawString(myString, GdiFontManager.ToGdi(_textFont), _defaultSelectedTextBrush, cellRectangle, _textFormat);
            }
            else
            {
                dc.DrawString(myString, GdiFontManager.ToGdi(_textFont), TextBrush, cellRectangle, _textFormat);
            }
        }
示例#17
0
        private void PaintErrorInvalidLayerType(Graphics g, object obj)
        {
            string errorMsg = "FloatingScale:Error: Invalid layer type";
            var    font     = GdiFontManager.ToGdi(GdiFontManager.GetFontXGenericSansSerif(10, FontXStyle.Regular));
            var    size     = g.MeasureString(errorMsg, font);

            if (obj is HostLayer)
            {
                var destSizeX = 0.2 * ((HostLayer)obj).Size.X;
                var factor    = destSizeX / size.Width;
                font = GdiFontManager.ToGdi(GdiFontManager.GetFontXGenericSansSerif(font.Size * factor, FontXStyle.Regular));
            }

            g.DrawString(errorMsg, font, Brushes.Red, (PointF)Position);
            size = g.MeasureString(errorMsg, font);

            _cachedPath = new GraphicsPath();
            _cachedPath.AddRectangle(new RectangleF((PointF)Position, size));

            ((ItemLocationDirectAutoSize)_location).SetSizeInAutoSizeMode(size);
        }
示例#18
0
        private void ApplyFontFamily()
        {
            var ff = _view.SelectedFontFamilyName;

            // make sure that regular style is available
            if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Regular))
            {
                _doc = GdiFontManager.GetFontX(ff, _doc.Size, FontXStyle.Regular);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Bold))
            {
                _doc = GdiFontManager.GetFontX(ff, _doc.Size, FontXStyle.Bold);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Italic))
            {
                _doc = GdiFontManager.GetFontX(ff, _doc.Size, FontXStyle.Italic);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Bold | FontXStyle.Italic))
            {
                _doc = GdiFontManager.GetFontX(ff, _doc.Size, FontXStyle.Bold | FontXStyle.Italic);
            }
        }
            public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext, double lineSpacing, StringAlignment horizontalAlignment, StringAlignment verticalAlignment, StringAlignment textBlockAligment)
            {
                _text                = itemtext.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                _stringSize          = new PointD2D[_text.Length];
                _font                = font;
                _horizontalAlignment = horizontalAlignment;
                _verticalAlignment   = verticalAlignment;
                _textBlockAligment   = textBlockAligment;
                _strfmt              = strfmt;
                _lineSpacing         = lineSpacing;
                _size                = SizeF.Empty;
                var bounds   = RectangleD2D.Empty;
                var position = new PointD2D();

                for (int i = 0; i < _text.Length; ++i)
                {
                    _stringSize[i] = g.MeasureString(_text[i], GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt);
                    bounds.ExpandToInclude(new RectangleD2D(position, _stringSize[i]));
                    position = position.WithYPlus(_stringSize[i].Y * _lineSpacing);
                }
                _size = bounds.Size;
            }
            public virtual void Draw(Graphics g, BrushX brush, PointF point)
            {
                var positionX = point.X + GetHorizontalOffset();
                var positionY = point.Y + GetVerticalOffset();

                for (int i = 0; i < _text.Length; ++i)
                {
                    var posX = positionX;
                    switch (_textBlockAligment)
                    {
                    case StringAlignment.Center:
                        posX += (_size.X - _stringSize[i].X) * 0.5;
                        break;

                    case StringAlignment.Far:
                        posX += (_size.X - _stringSize[i].X);
                        break;
                    }

                    g.DrawString(_text[i], GdiFontManager.ToGdi(_font), brush, new PointF((float)posX, (float)positionY), _strfmt);
                    positionY += _stringSize[i].Y * _lineSpacing;
                }
            }
示例#21
0
      public override void Measure(Graphics g, MeasureContext mc, double x)
      {
        Width = 0;
        Height = 0;

        var mylayer = mc.LinkedObject as HostLayer;
        if (null == mylayer)
          return;
        var layer = mylayer as XYPlotLayer;
        if (_layerNumber >= 0 && null != mylayer.SiblingLayers && _layerNumber < mylayer.SiblingLayers.Count)
          layer = mylayer.SiblingLayers[_layerNumber] as XYPlotLayer;

        if (null == layer)
          return;

        if (_plotNumber < layer.PlotItems.Flattened.Length)
        {
          var fontInfo = mc.FontCache.GetFontInfo(g, Style.FontId);
          Width = g.MeasureString("MMM", GdiFontManager.ToGdi(Style.FontId), PointF.Empty, _stringFormat).Width;
          ExtendAboveBaseline = fontInfo.cyAscent;
          ExtendBelowBaseline = fontInfo.cyDescent;
        }
      }
示例#22
0
        public void EhView_FontFamilyChanged()
        {
            var ff = _view.SelectedFont.FontFamilyName;

            // make sure that regular style is available
            if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Regular))
            {
                _doc.Font = GdiFontManager.GetFontX(ff, _doc.Font.Size, FontXStyle.Regular);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Bold))
            {
                _doc.Font = GdiFontManager.GetFontX(ff, _doc.Font.Size, FontXStyle.Bold);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Italic))
            {
                _doc.Font = GdiFontManager.GetFontX(ff, _doc.Font.Size, FontXStyle.Italic);
            }
            else if (GdiFontManager.IsFontFamilyAndStyleAvailable(ff, FontXStyle.Bold | FontXStyle.Italic))
            {
                _doc.Font = GdiFontManager.GetFontX(ff, _doc.Font.Size, FontXStyle.Bold | FontXStyle.Italic);
            }

            _view.InvalidatePreviewPanel();
        }
示例#23
0
        public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
        {
            var litems = new MeasuredLabelItem[items.Length];

            FontX localfont1 = font;
            FontX localfont2 = font.WithSize(font.Size * 2 / 3);

            var localstrfmt = (StringFormat)strfmt.Clone();

            string[] firstp = new string[items.Length];
            string[] middel = new string[items.Length];
            string[] expos  = new string[items.Length];
            double[] mants  = new double[items.Length];

            float maxexposize  = 0;
            int   firstpartmin = int.MaxValue;
            int   firstpartmax = int.MinValue;

            for (int i = 0; i < items.Length; ++i)
            {
                string firstpart, exponent;
                if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
                {
                    SplitInFirstPartAndExponent(items[i], out firstpart, out mants[i], out middel[i], out exponent);
                    if (exponent.Length > 0)
                    {
                        firstpartmin = Math.Min(firstpartmin, firstpart.Length);
                        firstpartmax = Math.Max(firstpartmax, firstpart.Length);
                    }
                }
                else
                {
                    firstpart = items[i].ToString();
                    middel[i] = string.Empty;
                    exponent  = string.Empty;
                }
                firstp[i]   = firstpart;
                expos[i]    = exponent;
                maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, GdiFontManager.ToGdi(localfont2), new PointF(0, 0), strfmt).Width);
            }

            if (firstpartmax > 0 && firstpartmax > firstpartmin) // then we must use special measures to equilibrate the mantissa
            {
                firstp = NumericLabelFormattingAuto.FormatItems(mants);
            }

            for (int i = 0; i < items.Length; ++i)
            {
                string mid = string.Empty;
                if (!string.IsNullOrEmpty(expos[i]))
                {
                    if (string.IsNullOrEmpty(firstp[i]))
                    {
                        mid = "10";
                    }
                    else
                    {
                        mid = "\u00D710";
                    }
                }
                litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize);
            }

            return(litems);
        }
示例#24
0
        /// <summary>
        /// Draws the item to a specified location.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="brush">Brush used to draw the item.</param>
        /// <param name="font">Font used to draw the item.</param>
        /// <param name="strfmt">String format.</param>
        /// <param name="item">The item to draw.</param>
        /// <param name="morg">The location where the item is drawn to.</param>
        public virtual void DrawItem(System.Drawing.Graphics g, BrushX brush, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg)
        {
            string text = _prefix + FormatItem(item) + _suffix;

            g.DrawString(text, GdiFontManager.ToGdi(font), brush, morg, strfmt);
        }
示例#25
0
 /// <summary>Measures the string with the appropriate generic typographic format.</summary>
 /// <param name="g">The graphics context.</param>
 /// <param name="text">The text to measure.</param>
 /// <param name="font">The font used.</param>
 /// <returns>Width and height of the text packed into a <see cref="PointD2D"/> structure.</returns>
 public static PointD2D MeasureString(Graphics g, string text, FontX font)
 {
   var result = g.MeasureString(text, GdiFontManager.ToGdi(font), PointF.Empty, _stringFormat);
   return new PointD2D(result.Width, result.Height);
 }
示例#26
0
        /// <summary>
        /// Measures the item, i.e. returns the size of the item.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="font">The font that is used to draw the item.</param>
        /// <param name="strfmt">String format used to draw the item.</param>
        /// <param name="mtick">The item to draw.</param>
        /// <param name="morg">The location the item will be drawn.</param>
        /// <returns>The size of the item if it would be drawn.</returns>
        public virtual System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
        {
            string text = _prefix + FormatItem(mtick) + _suffix;

            return(g.MeasureString(text, GdiFontManager.ToGdi(font), morg, strfmt));
        }
示例#27
0
 public virtual void Draw(Graphics g, BrushX brush, PointF point)
 {
     g.DrawString(_text, GdiFontManager.ToGdi(_font), brush, point, _strfmt);
 }
示例#28
0
 public override void Draw(Graphics g, DrawContext dc, double xbase, double ybase)
 {
   var fontInfo = dc.FontCache.GetFontInfo(g, Style.FontId);
   g.DrawString(_text, GdiFontManager.ToGdi(Style.FontId), Style.brush, (float)xbase, (float)(ybase - fontInfo.cyAscent), _stringFormat);
 }