public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items) { MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length]; FontX localfont1 = font; FontX localfont2 = font.WithSize(font.Size * 2 / 3); StringFormat 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((double)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; }
public override void DrawItem(Graphics g, BrushX brush, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg) { string firstpart, middelpart, exponent; double mant; SplitInFirstPartAndExponent((double)item, out firstpart, out mant, out middelpart, out 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); } }