public IRichTextBoxLayout Build(IRichText text, IntSize2 size, float padding) { text.Normalize(); var lspans = new List <RichTextBoxLayoutSpan>(); var externalLayoutSpans = new List <RichTextBoxLayoutSpan>(); var context = new BuildingContext { Text = text, LayoutSpans = lspans, ExternalLayoutSpans = externalLayoutSpans, RemainingShape = new AaRectangle2(new Vector2(padding), new Vector2(size.Width, size.Height) - new Vector2(padding)) }; for (var i = 0; i < text.Paragraphs.Count; i++) { BuildParagraph(context, i); } if (lspans.Count == 0) { var defaultStyle = text.Paragraphs[0].Spans[0].Style; lspans.Add(new RichTextBoxLayoutSpan { TextAbsPosition = 0, TextRelPosition = new RtPosition(), Bounds = new AaRectangle2(new Vector2(0, 0), new Vector2(1f, defaultStyle.Size)), Strip = new AaRectangle2(new Vector2(0, 0), new Vector2(1f, defaultStyle.Size)), Style = defaultStyle, Text = "", CharOffsets = EmptyArrays <float> .Array }); } return(new RichTextBoxLayout(text, lspans, externalLayoutSpans)); }
public RichTextHeadlessEditor(IRichText text) { this.text = text; defaultParaStyle = AmFactory.Create <RtParagraphStyle>(); defaultSpanStyle = AmFactory.Create <RtSpanStyle>(); inputSpanStyle = AmFactory.Create <RtSpanStyle>(); NormalizeText(text, defaultParaStyle, defaultSpanStyle); MoveCursor(0, false); }
private static void InternalProcess(Span span, IRichText node) { foreach (IRichText child in node.Items) { if (child is RichText text) { span.Inlines.Add(new Run(text.Text.ToString())); } else if (child is RichBold richBold) { Span boldSpan = new Span(); InternalProcess(boldSpan, richBold); Bold bold = new Bold(boldSpan); span.Inlines.Add(bold); } else if (child is RichItalic richItalic) { Span italicSpan = new Span(); InternalProcess(italicSpan, richItalic); Italic italic = new Italic(italicSpan); span.Inlines.Add(italic); } else if (child is RichUnderline richUnderline) { Span underlineSpan = new Span(); InternalProcess(underlineSpan, richUnderline); Underline underline = new Underline(underlineSpan); span.Inlines.Add(underline); } else if (child is RichColor richColor) { Span colorSpan = new Span(); InternalProcess(colorSpan, richColor); colorSpan.Foreground = new BrushConverter().ConvertFromString(richColor.Attribute) as SolidColorBrush; span.Inlines.Add(colorSpan); } else if (child is RichSymbol richSymbol) { Symbol symbol = richSymbol.Attribute; var image = new Image { Margin = new Thickness(0, 0, 0, -2), Height = span.FontSize + 2, Stretch = Stretch.Uniform, Source = new BitmapImage(new Uri(symbol.Source)), ToolTip = symbol.Name }; var symbolSpan = new InlineUIContainer(); symbolSpan.Child = image; span.Inlines.Add(symbolSpan); } } }
private static int GetParagraphNumbering(IRichText text, int paragraphIndex) { if (text.Paragraphs[paragraphIndex].Style.ListType != RtListType.Numbering) { return(0); } if (paragraphIndex == 0) { return(1); } return(GetParagraphNumbering(text, paragraphIndex - 1) + 1); }
private static void NormalizeText(IRichText text, IRtParagraphStyle defaultParaStyle, IRtSpanStyle defaultSpanStyle) { if (text.Paragraphs.IsEmptyL()) { text.Paragraphs.Add(CreatePara(defaultParaStyle, defaultSpanStyle)); } NormalizePara(text.Paragraphs[0], defaultSpanStyle); for (var i = 1; i < text.Paragraphs.Count; i++) { NormalizePara(text.Paragraphs[i], text.Paragraphs[i - 1].Spans.Last().Style); } }
public ISceneNode RichTextRectangle(IRichText text) { var node = objectFactory.Create <SceneNode>(); node.Name = "Text Entity"; node.Components.Add(PresentationComponent.Create()); var rectComponent = objectFactory.Create <RectangleComponent>(); rectComponent.DragByBorders = true; var richTextComponent = objectFactory.Create <RichTextComponent>(); richTextComponent.TextBox.Text = text; node.Components.Add(rectComponent); node.Components.Add(richTextComponent); return(node); }
public RichTextBoxLayout(IRichText text, IReadOnlyList <RichTextBoxLayoutSpan> lspans, IReadOnlyList <RichTextBoxLayoutSpan> externalLayoutSpans) { LayoutSpans = lspans; ExternalLayoutSpans = externalLayoutSpans; Text = text; }
public RichTextController(IRichText richText) { _richtext = richText; }