internal static SizeF CalcTextExtent(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, Font AFont, TRichString Text, out real MaxDescent) { MaxDescent = Canvas.FontDescent(AFont); if (Text.RTFRunCount == 0) { return(Canvas.MeasureStringEmptyHasHeight(Text.Value, AFont)); } real x = 0; real y = 0; SizeF Result; Result = Canvas.MeasureString(Text.Value.Substring(0, Text.RTFRun(0).FirstChar), AFont, new TPointF(0, 0)); x = Result.Width; y = Result.Height; for (int i = 0; i < Text.RTFRunCount - 1; i++) { TFlxFont Fx = Text.GetFont(Text.RTFRun(i).FontIndex); TSubscriptData Sub = new TSubscriptData(Fx.Style); Font MyFont = FontCache.GetFont(Fx, Zoom100 * Sub.Factor); { int Start = Text.RTFRun(i).FirstChar; if (Start >= Text.Length) { Start = Text.Length; } int Len = Text.RTFRun(i + 1).FirstChar; if (Len >= Text.Length) { Len = Text.Length; } Len -= Start; if (Len < 0) { continue; //wrong file, (i+1)FirstChar < (i).FirstChar } Result = Canvas.MeasureString(Text.Value.Substring(Start, Len), MyFont, new TPointF(0, 0)); x += Result.Width; y = Math.Max(y + Sub.Offset(Canvas, MyFont), Result.Height); MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont) + Sub.Offset(Canvas, MyFont)); } } TFlxFont Fy = Text.GetFont(Text.RTFRun(Text.RTFRunCount - 1).FontIndex); TSubscriptData Suby = new TSubscriptData(Fy.Style); Font MyFont2 = FontCache.GetFont(Fy, Zoom100 * Suby.Factor); { int Start = Text.RTFRun(Text.RTFRunCount - 1).FirstChar; if (Start >= Text.Length) { Start = Text.Length; } Result = Canvas.MeasureStringEmptyHasHeight(Text.Value.Substring(Start), MyFont2); x += Result.Width; y = Math.Max(y + Suby.Offset(Canvas, MyFont2), Result.Height); MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont2) + Suby.Offset(Canvas, MyFont2)); } return(new SizeF(x, y)); }
internal static void DrawPlainText(IFlxGraphics Canvas, ExcelFile Workbook, TShapeProperties ShProp, RectangleF Coords, TShadowInfo ShadowInfo, TClippingStyle Clipping, float Zoom100) { string Text = GetGeoText(ShProp); if (Text == null) { return; } Text = Text.Replace("\n", String.Empty); string[] Lines = Text.Split('\r'); if (Lines == null || Lines.Length <= 0) { return; } int LinesLength = Lines[Lines.Length - 1].Length == 0? Lines.Length - 1: Lines.Length; //Last line is an empty enter. if (LinesLength <= 0) { return; } using (Font TextFont = GetGeoFont(ShProp)) { using (Pen pe = GetPen(ShProp, Workbook, ShadowInfo)) { Canvas.SaveTransform(); try { float LineGap = Canvas.FontLinespacing(TextFont); SizeF[] Sizes = new SizeF[LinesLength]; Sizes[0] = Canvas.MeasureStringEmptyHasHeight(Lines[0], TextFont); Sizes[0].Height -= LineGap; //Linespacing is not included here. SizeF sz = Sizes[0]; for (int i = 1; i < LinesLength; i++) { Sizes[i] = Canvas.MeasureStringEmptyHasHeight(Lines[i], TextFont); if (Sizes[i].Width > sz.Width) { sz.Width = Sizes[i].Width; } sz.Height += Sizes[i].Height; } if (sz.Width <= 0 || sz.Height <= 0 || Coords.Width <= 0 || Coords.Height <= 0) { return; } float rx = Coords.Width / sz.Width; float ry = Coords.Height / sz.Height; Canvas.Scale(rx, ry); using (Brush br = GetBrush(new RectangleF(Coords.Left / rx, Coords.Top / ry, sz.Width, sz.Height), ShProp, Workbook, ShadowInfo, Zoom100)) //Mast be selected AFTER scaling, so gradients work. { float y = LineGap; for (int i = 0; i < LinesLength; i++) { y += Sizes[i].Height; float x = (sz.Width - Sizes[i].Width) / 2f; Canvas.DrawString(Lines[i], TextFont, pe, br, Coords.Left / rx + x, Coords.Top / ry + y); } } } finally { Canvas.ResetTransform(); } } } }