private static IRtPureSpan CreatePureSpan(IRtSpanStyle styleProto, string initialText = "")
        {
            var span = AmFactory.Create <RtPureSpan>();

            span.Style = styleProto.CloneTyped();
            span.Text  = initialText;
            return(span);
        }
Exemple #2
0
 public void CopyFrom(IRtSpanStyle other)
 {
     FontFamily     = other.FontFamily;
     FontDecoration = other.FontDecoration;
     Size           = other.Size;
     TextColor      = other.TextColor;
     HighlightGroup = other.HighlightGroup;
 }
        private static IRtParagraph CreatePara(IRtParagraphStyle paraStyleProto, IRtSpanStyle spanStyleProto)
        {
            var para = AmFactory.Create <RtParagraph>();

            para.Style = paraStyleProto.CloneTyped();
            para.Spans.Add(CreatePureSpan(spanStyleProto));
            return(para);
        }
Exemple #4
0
        private static IRtPureSpan CreateSpan(string text, IRtSpanStyle style)
        {
            var span = AmFactory.Create <RtPureSpan>();

            span.Text  = text;
            span.Style = style;
            return(span);
        }
        private static IRtEmbeddingSpan CreateEmbeddingSpan(IRtSpanStyle styleProto, string embeddingType, string initialSource = "")
        {
            var span = AmFactory.Create <RtEmbeddingSpan>();

            span.Style         = styleProto.CloneTyped();
            span.EmbeddingType = embeddingType;
            span.SourceCode    = initialSource;
            return(span);
        }
Exemple #6
0
 private bool EqualsNotNull([NotNull] IRtSpanStyle other)
 {
     return
         (FontFamily == other.FontFamily &&
          FontDecoration == other.FontDecoration &&
          Size == other.Size &&
          TextColor == other.TextColor &&
          HighlightGroup == other.HighlightGroup);
 }
Exemple #7
0
        public Size2 MeasureString(string str, IRtSpanStyle style)
        {
            var etoFontFamily = fontFamilyCache.GetFontFamily(style.FontFamily);

            Converters.ToEto(style.FontDecoration, out var etoStyle, out var etoDecoration);
            var etoFont = new Font(etoFontFamily, style.Size, etoStyle, etoDecoration);

            return(Converters.ToClarity(graphics.MeasureString(etoFont, str)));
        }
 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);
 }
Exemple #9
0
 public bool Equals(IRtSpanStyle other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(EqualsNotNull(other));
 }
Exemple #10
0
 private bool TryParseAndRender(string text, IRtSpanStyle style, out byte[] pngBytes, out string error)
 {
     try
     {
         var formula = parser.Parse(text);
         pngBytes = formula.RenderToPng(1.6 * style.Size, 0, 0, "Arial");
         error    = null;
         return(true);
     }
     catch (Exception ex)
     {
         pngBytes = null;
         error    = ex.Message;
         return(false);
     }
 }
 private static void NormalizePara(IRtParagraph para, IRtSpanStyle prevSpanStyle)
 {
     if (para.LayoutTextLength == 0)
     {
         if (para.Spans.IsEmptyL())
         {
             para.Spans.Add(CreatePureSpan(prevSpanStyle));
         }
         else
         {
             for (var i = para.Spans.Count - 1; i >= 1; i--)
             {
                 para.Spans.RemoveAt(i);
             }
         }
     }
     else
     {
         for (var i = para.Spans.Count - 1; i >= 0; i--)
         {
             if (para.Spans[i].IsEmpty)
             {
                 para.Spans.RemoveAt(i);
             }
         }
     }
     for (var i = para.Spans.Count - 2; i >= 0; i--)
     {
         if (para.Spans[i] is IRtPureSpan span1 &&
             para.Spans[i + 1] is IRtPureSpan span2 &&
             span1.Style.Equals(span2.Style))
         {
             span1.Text += span2.Text;
             para.Spans.RemoveAt(i + 1);
         }
     }
 }
Exemple #12
0
        private void FlushBullet(BuildingContext context, Vector2 firstSpanPoint, string bulletStr, IRtSpanStyle style)
        {
            var size        = measurer.MeasureString(bulletStr, style);
            var otherCorner = firstSpanPoint - size.ToVector();

            context.ExternalLayoutSpans.Add(new RichTextBoxLayoutSpan
            {
                Text   = bulletStr,
                Bounds = new AaRectangle2(otherCorner, firstSpanPoint),
                Style  = style
            });
        }
Exemple #13
0
 protected RtPureSpan()
 {
     Text  = "";
     Style = AmFactory.Create <RtSpanStyle>();
 }
Exemple #14
0
 public Size2 GetCharSize(char ch, IRtSpanStyle style)
 {
     return(charSizes.GetOrAdd(Tuples.Pair(ch, style), x => MeasureString(x.First.ToString(), x.Second)));
 }
 public Size2 MeasureString(string str, IRtSpanStyle style)
 {
     throw new System.NotImplementedException();
 }
Exemple #16
0
 public TextImageAtom(string text, IRtSpanStyle style, bool isBullet = false)
 {
     Text     = text;
     Style    = style;
     IsBullet = isBullet;
 }
 public Size2 GetCharSize(char ch, IRtSpanStyle style)
 {
     throw new System.NotImplementedException();
 }
 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);
     }
 }