/// <ToBeCompleted></ToBeCompleted> public virtual bool GetCaptionTextBounds(int index, out Point topLeft, out Point topRight, out Point bottomRight, out Point bottomLeft) { if (index != 0) { throw new IndexOutOfRangeException("index"); } bool result; Rectangle captionBounds = Rectangle.Empty; CalcCaptionBounds(index, out captionBounds); Rectangle textBounds = Rectangle.Empty; if (caption != null) { textBounds = caption.CalculateTextBounds(captionBounds, CharacterStyle, ParagraphStyle, DisplayService); result = true; } else { // Calculate placeholder bounds textBounds.Size = TextMeasurer.MeasureText("Iq", CharacterStyle, captionBounds.Size, ParagraphStyle); textBounds.X = (int)Math.Round(captionBounds.X + (captionBounds.Width / 2f) - textBounds.Width / 2f); textBounds.Y = (int)Math.Round(captionBounds.Y + (captionBounds.Height / 2f) - textBounds.Height / 2f); result = false; } Geometry.TransformRectangle(Center, Angle, textBounds, out topLeft, out topRight, out bottomRight, out bottomLeft); return(result); }
/// <override></override> public override void DrawThumbnail(Image image, int margin, Color transparentColor) { AutoSize = false; Text = "ab"; Size textSize = Size.Empty; // Create a ParameterStyle without padding ParagraphStyle paragraphStyle = new ParagraphStyle(); paragraphStyle.Alignment = ContentAlignment.TopLeft; paragraphStyle.Padding = new TextPadding(0); paragraphStyle.Trimming = StringTrimming.None; paragraphStyle.WordWrap = false; ParagraphStyle = paragraphStyle; textSize = TextMeasurer.MeasureText(Text, ToolCache.GetFont(CharacterStyle), textSize, ParagraphStyle); Width = textSize.Width; Height = textSize.Height; // If the linestyle is transparent, modify margin in order to improve the text's readability int marginCorrection = (LineStyle.ColorStyle.Transparency == 100) ? 3 : 0; base.DrawThumbnail(image, margin - marginCorrection, transparentColor); }
private void FitShapeToText() { System.Diagnostics.Debug.Assert(CharacterStyle != null); System.Diagnostics.Debug.Assert(ParagraphStyle != null); if (!string.IsNullOrEmpty(Text) && CharacterStyle != null && ParagraphStyle != null) { Size textSize = TextMeasurer.MeasureText(Text, CharacterStyle, Size.Empty, ParagraphStyle); Width = textSize.Width + ParagraphStyle.Padding.Horizontal; Height = textSize.Height + ParagraphStyle.Padding.Vertical; } }
/// <override></override> protected override void CalcCaptionBounds(int index, out Rectangle captionBounds) { captionBounds = Rectangle.Empty; if (autoSize) { captionBounds.Size = TextMeasurer.MeasureText(Text, CharacterStyle, Size.Empty, ParagraphStyle); captionBounds.Width += ParagraphStyle.Padding.Horizontal; captionBounds.Height += ParagraphStyle.Padding.Vertical; captionBounds.X = (int)Math.Round(-captionBounds.Width / 2f); captionBounds.Y = (int)Math.Round(-captionBounds.Height / 2f); } else { base.CalcCaptionBounds(index, out captionBounds); } }