private IEnumerable<IRenderArgument> DoRenderLine(ITextRender2MeasureMap map, ITextRender2MeasureMapLine line)
 {
     foreach (var el in line.GetMeasureMap())
     {
         yield return DoRenderElement(map, line, el);
     }
 }
 /// <summary>
 /// Отрисовать.
 /// </summary>
 /// <param name="map">Карта расположений.</param>
 /// <returns>Результат.</returns>
 public FrameworkElement Render(ITextRender2MeasureMap map)
 {
     if (map == null) throw new ArgumentNullException(nameof(map));
     var canvas = new Canvas()
     {
         Height = map.Bounds.Height,
         Width = map.Bounds.Width
     };
     DoRender(canvas, map);
     return canvas;
 }
 private IEnumerable<IRenderArgument> DoRenderLines(ITextRender2MeasureMap map)
 {
     foreach (var line in map.GetMeasureMapLines())
     {
         if (map.MaxLines.HasValue)
         {
             if (line.LineNumber >= map.MaxLines.Value)
             {
                 break;
             }
         }
         foreach (var el in DoRenderLine(map, line))
         {
             yield return el;
         }
     }
 }
 private void SetCachedMap(double width)
 {
     if (Math.Abs(VirtualCanvas.Width - width) > 0.01)
     {
         VirtualCanvas.Width = width;
     }
     if (double.IsNaN(width) || double.IsInfinity(width) || width < 50 || ControlCallback == null)
     {
         cachedMap = null;
         VirtualCanvas.Height = 1;
         return;
     }
     bool needRedraw = false;
     if (cachedMap == null)
     {
         needRedraw = true;
     }
     else if (Math.Abs(lastWidth - width) > 0.01)
     {
         needRedraw = true;
     }
     else if (Math.Abs(ControlCallback.PostFontSize - lastFontSize) > 0.01)
     {
         needRedraw = true;
     }
     else if (lastMaxLines != MaxLines)
     {
         needRedraw = true;
     }
     else if (lastId != ControlCallback.ProgramId)
     {
         needRedraw = true;
     }
     lastWidth = width;
     lastFontSize = ControlCallback.PostFontSize;
     lastMaxLines = MaxLines;
     lastId = ControlCallback.ProgramId;
     if (needRedraw)
     {
         cachedMap = DoMeasure(width);
         VirtualCanvas.Height = cachedMap.Bounds.Height;
     }
 }
 /// <summary>
 /// Отрисовать.
 /// </summary>
 /// <param name="map">Карта расположений.</param>
 /// <param name="session">Сессия.</param>
 /// <param name="region">Регион.</param>
 /// <returns>Результат.</returns>
 public void Render(ITextRender2MeasureMap map, CanvasDrawingSession session, Rect region)
 {
     foreach (var line in map.GetMeasureMapLines())
     {
         if (map.MaxLines.HasValue)
         {
             if (line.LineNumber >= map.MaxLines.Value)
             {
                 break;
             }
         }
         foreach (var element in line.GetMeasureMap())
         {
             var drawRect = new Rect(element.Placement, element.Size);
             var testRect = drawRect;
             testRect.Intersect(region);
             if (!testRect.IsEmpty)
             {
                 DrawElement(element, session, region);
             }
         }
     }
 }
 public void InvalidateRenderedStateAndClear()
 {
     cachedMap = null;
     InvalidateMeasure();
 }
 private IRenderArgument DoRenderElement(ITextRender2MeasureMap map, ITextRender2MeasureMapLine line, TextRender2MeasureMapElement el)
 {
     return new NativeRenderArgument(map, line, el, Callback);
 }
 private void DoRender(Canvas canvas, ITextRender2MeasureMap map)
 {
     var elements = DoRenderLines(map).ToArray();
     //UpdateHelper.UpdateChildren(canvas.Children, elements);
     RenderHelper.RenderToCanvas(canvas, elements);
 }
        public NativeRenderArgument(ITextRender2MeasureMap map, ITextRender2MeasureMapLine line, TextRender2MeasureMapElement el, ITextRender2RenderCallback callback)
        {
            if (map == null) throw new ArgumentNullException(nameof(map));
            if (line == null) throw new ArgumentNullException(nameof(line));
            if (callback == null) throw new ArgumentNullException(nameof(callback));

            var command = el.Command;
            string text;
            var textCnt = command.Content as ITextRenderTextContent;
            if (textCnt != null)
            {
                text = textCnt.Text ?? "";
            }
            else
            {
                text = "";
            }
            Text = text;

            ElementSize = el.Size;
            Placement = el.Placement;
            LineHeight = line.Height;
            StrikethrougKoef = map.StrikethrougKoef;

            if (command.Attributes.Attributes.ContainsKey(CommonTextRenderAttributes.Link))
            {
                var linkAttribute = command.Attributes.Attributes[CommonTextRenderAttributes.Link] as ITextRenderLinkAttribute;
                if (linkAttribute != null)
                {
                    Link = new LinkDataWrapper(linkAttribute);
                }
            }

            Callback = new RenderCallbackWrapper(callback);

            TextAttributeFlags flags = 0;

            var attr = command.Attributes.Attributes;

            if (attr.ContainsKey(CommonTextRenderAttributes.Link))
            {
                flags = flags | TextAttributeFlags.Link;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Bold))
            {
                flags = flags | TextAttributeFlags.Bold;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Fixed))
            {
                flags = flags | TextAttributeFlags.Fixed;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Italic))
            {
                flags = flags | TextAttributeFlags.Italic;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Overline))
            {
                flags = flags | TextAttributeFlags.Overline;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Quote))
            {
                flags = flags | TextAttributeFlags.Quote;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Spoiler))
            {
                flags = flags | TextAttributeFlags.Spoiler;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Strikethrough))
            {
                flags = flags | TextAttributeFlags.Strikethrough;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Subscript))
            {
                flags = flags | TextAttributeFlags.Subscript;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Superscript))
            {
                flags = flags | TextAttributeFlags.Superscript;
            }
            if (attr.ContainsKey(CommonTextRenderAttributes.Undeline))
            {
                flags = flags | TextAttributeFlags.Undeline;
            }
            Flags = flags;
        }