private void DrawElement(TextRender2MeasureMapElement element, CanvasDrawingSession session, Rect region) { var command = element.Command; string text; var textCnt = command.Content as ITextRenderTextContent; if (textCnt != null) { text = textCnt.Text ?? ""; } else { text = ""; } using (var format = new CanvasTextFormat()) { format.FontFamily = "Segoe UI"; format.FontSize = (float)Callback.PostFontSize; format.WordWrapping = CanvasWordWrapping.NoWrap; format.TrimmingGranularity = CanvasTextTrimmingGranularity.None; format.HorizontalAlignment = CanvasHorizontalAlignment.Left; session.DrawText(text, new Vector2((float)element.Placement.X, (float)element.Placement.Y), Colors.Black, format); } }
private IRenderArgument DoRenderElement(ITextRender2MeasureMap map, ITextRender2MeasureMapLine line, TextRender2MeasureMapElement el) { return new NativeRenderArgument(map, line, el, Callback); }
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; }
public MeasureMapLine(TextRender2MeasureMapElement[] elements, int lineNumber, double height) { if (elements == null) throw new ArgumentNullException(nameof(elements)); this.elements = elements; LineNumber = lineNumber; Height = height; }