private void LayerText(FastString Page, TextObject obj) { float top = 0; switch (obj.TextRenderType) { case TextRenderType.HtmlParagraph: using (HtmlTextRenderer htmlTextRenderer = obj.GetHtmlTextRenderer(Zoom, Zoom)) { if (obj.VertAlign == VertAlign.Center) { top = (obj.Height - htmlTextRenderer.CalcHeight()) / 2; } else if (obj.VertAlign == VertAlign.Bottom) { top = obj.Height - htmlTextRenderer.CalcHeight(); } FastString sb = GetHtmlParagraph(htmlTextRenderer); LayerBack(Page, obj, GetSpanText(obj, sb, top + obj.Padding.Top, obj.Width - obj.Padding.Horizontal, obj.ParagraphOffset)); } break; default: if (obj.VertAlign != VertAlign.Top) { Graphics g = htmlMeasureGraphics; using (Font f = new Font(obj.Font.Name, obj.Font.Size, obj.Font.Style)) { RectangleF textRect = new RectangleF(obj.AbsLeft, obj.AbsTop, obj.Width, obj.Height); StringFormat format = obj.GetStringFormat(Report.GraphicCache, 0); Brush textBrush = Report.GraphicCache.GetBrush(obj.TextColor); AdvancedTextRenderer renderer = new AdvancedTextRenderer(obj.Text, g, f, textBrush, null, textRect, format, obj.HorzAlign, obj.VertAlign, obj.LineHeight, obj.Angle, obj.FontWidthRatio, obj.ForceJustify, obj.Wysiwyg, obj.HasHtmlTags, false, Zoom, Zoom, obj.InlineImageCache); if (renderer.Paragraphs.Count > 0) { if (renderer.Paragraphs[0].Lines.Count > 0) { float height = renderer.Paragraphs[0].Lines[0].CalcHeight(); if (height > obj.Height) { top = -(height - obj.Height) / 2; } else { top = renderer.Paragraphs[0].Lines[0].Top - obj.AbsTop; } } } } } LayerBack(Page, obj, GetSpanText(obj, ExportUtils.HtmlString(obj.Text, obj.TextRenderType), top + obj.Padding.Top, obj.Width - obj.Padding.Horizontal, obj.ParagraphOffset)); break; } }
private string BreakText() { ForceJustify = false; if (String.IsNullOrEmpty(Text)) { return(""); } string result = null; Report report = Report; if (report == null) { return(""); } Font font = report.GraphicCache.GetFont(Font.Name, Font.Size * 96f / DrawUtils.ScreenDpi, Font.Style); StringFormat format = GetStringFormat(report.GraphicCache, StringFormatFlags.LineLimit); RectangleF textRect = new RectangleF(0, 0, Width - Padding.Horizontal, Height - Padding.Vertical); int charactersFitted; int linesFilled; Graphics g = report.MeasureGraphics; GraphicsState state = g.Save(); try { if (report.TextQuality != TextQuality.Default) { g.TextRenderingHint = GetTextQuality(report.TextQuality); } AdvancedTextRenderer.StyleDescriptor htmlStyle = null; if (HorzAlign == HorzAlign.Justify || Wysiwyg || LineHeight != 0 || HtmlTags) { AdvancedTextRenderer renderer = new AdvancedTextRenderer(Text, g, font, Brushes.Black, textRect, format, HorzAlign, VertAlign, LineHeight, Angle, FontWidthRatio, false, Wysiwyg, HtmlTags, false); renderer.CalcHeight(out charactersFitted, out htmlStyle); if (charactersFitted == 0) { linesFilled = 0; } else { linesFilled = 2; } } else { g.MeasureString(Text, font, textRect.Size, format, out charactersFitted, out linesFilled); } if (linesFilled == 0) { return(null); } if (linesFilled == 1) { // check if there is enough space for one line float lineHeight = g.MeasureString("Wg", font).Height; if (textRect.Height < lineHeight) { return(null); } } if (charactersFitted < Text.Length) { result = Text.Substring(charactersFitted); } else { result = ""; } Text = Text.Substring(0, charactersFitted); if (HorzAlign == HorzAlign.Justify && !Text.EndsWith("\n") && result != "") { if (Text.EndsWith(" ")) { Text = Text.Substring(0, Text.Length - 1); } ForceJustify = true; } if (HtmlTags && htmlStyle != null && result != "") { result = htmlStyle.ToString() + result; } } finally { g.Restore(state); } return(result); }
/// <summary> /// Draws a text. /// </summary> /// <param name="e">Paint event data.</param> public void DrawText(FRPaintEventArgs e) { if (!String.IsNullOrEmpty(Text)) { Graphics g = e.Graphics; RectangleF textRect = new RectangleF( (AbsLeft + Padding.Left) * e.ScaleX, (AbsTop + Padding.Top) * e.ScaleY, (Width - Padding.Horizontal) * e.ScaleX, (Height - Padding.Vertical) * e.ScaleY); StringFormat format = GetStringFormat(e.Cache, 0); Font font = e.Cache.GetFont(Font.Name, IsPrinting ? Font.Size : Font.Size * e.ScaleX * 96f / DrawUtils.ScreenDpi, Font.Style); Brush textBrush = null; if (TextFill is SolidFill) { textBrush = e.Cache.GetBrush((TextFill as SolidFill).Color); } else { textBrush = TextFill.CreateBrush(textRect); } Report report = Report; if (report != null && report.TextQuality != TextQuality.Default) { g.TextRenderingHint = GetTextQuality(report.TextQuality); } if (textRect.Width > 0 && textRect.Height > 0) { if (LineHeight == 0 && HorzAlign != HorzAlign.Justify && !Wysiwyg && !HtmlTags) { // use simple rendering if (Angle == 0 && FontWidthRatio == 1) { g.DrawString(Text, font, textBrush, textRect, format); } else { StandardTextRenderer.Draw(Text, g, font, textBrush, textRect, format, Angle, FontWidthRatio); } } else { // use advanced rendering AdvancedTextRenderer renderer = new AdvancedTextRenderer(Text, g, font, textBrush, textRect, format, HorzAlign, VertAlign, LineHeight * e.ScaleY, Angle, FontWidthRatio, ForceJustify, Wysiwyg, HtmlTags, false); renderer.Draw(); } } if (!(TextFill is SolidFill)) { textBrush.Dispose(); } if (report != null && report.TextQuality != TextQuality.Default) { g.TextRenderingHint = TextRenderingHint.SystemDefault; } } DrawUnderlines(e); }
private SizeF CalcSize() { Report report = Report; if (String.IsNullOrEmpty(Text) || report == null) { return(new SizeF(0, 0)); } Font font = report.GraphicCache.GetFont(Font.Name, Font.Size * 96f / DrawUtils.ScreenDpi, Font.Style); float width = 0; if (WordWrap) { if (Angle == 90 || Angle == 270) { width = Height - Padding.Vertical; } else { width = Width - Padding.Horizontal; } } Graphics g = report.MeasureGraphics; GraphicsState state = g.Save(); try { if (report.TextQuality != TextQuality.Default) { g.TextRenderingHint = GetTextQuality(report.TextQuality); } if (HorzAlign == HorzAlign.Justify || Wysiwyg || LineHeight != 0 || HtmlTags) { if (width == 0) { width = 100000; } AdvancedTextRenderer renderer = new AdvancedTextRenderer(Text, g, font, Brushes.Black, new RectangleF(0, 0, width, 100000), GetStringFormat(report.GraphicCache, 0), HorzAlign, VertAlign, LineHeight, Angle, FontWidthRatio, false, Wysiwyg, HtmlTags, false); float height = renderer.CalcHeight(); width = renderer.CalcWidth(); width += Padding.Horizontal + 1; if (LineHeight == 0) { height += Padding.Vertical + 1; } return(new SizeF(width, height)); } else { if (FontWidthRatio != 1) { width /= FontWidthRatio; } SizeF size = g.MeasureString(Text, font, new SizeF(width, 100000)); size.Width += Padding.Horizontal + 1; size.Height += Padding.Vertical + 1; return(size); } } finally { g.Restore(state); } }