/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) { return; } var brush = ToSolidBrush(text.Style.Stroke); var fontStyle = Eto.Drawing.FontStyle.None; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Bold)) { fontStyle |= Eto.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Italic)) { fontStyle |= Eto.Drawing.FontStyle.Italic; } var fontDecoration = Eto.Drawing.FontDecoration.None; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline)) { fontDecoration |= Eto.Drawing.FontDecoration.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout)) { fontDecoration |= Eto.Drawing.FontDecoration.Strikethrough; } var font = new Font( text.Style.TextStyle.FontName, (float)(text.Style.TextStyle.FontSize * _textScaleFactor), fontStyle, fontDecoration); var rect = CreateRect( text.TopLeft, text.BottomRight, dx, dy); var srect = new RectangleF( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); var size = _gfx.MeasureString(font, tbind); var origin = GetTextOrigin(text.Style, ref srect, ref size); _gfx.DrawText( font, brush, origin, tbind); brush.Dispose(); font.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XText text, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _dc = dc as DrawingContext; var style = text.Style; if (style == null) return; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) return; double thickness = style.Thickness / _state.Zoom; double half = thickness / 2.0; Tuple<Brush, Pen> cache = null; Brush fill; Pen stroke; if (_enableStyleCache && _styleCache.TryGetValue(style, out cache)) { fill = cache.Item1; stroke = cache.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); if (_enableStyleCache) _styleCache.Add(style, Tuple.Create(fill, stroke)); } var rect = CreateRect( text.TopLeft, text.BottomRight, dx, dy); Tuple<string, FormattedText, ShapeStyle> tcache = null; FormattedText ft; string ct; if (_enableTextCache && _textCache.TryGetValue(text, out tcache) && string.Compare(tcache.Item1, tbind) == 0 && tcache.Item3 == style) { ct = tcache.Item1; ft = tcache.Item2; _dc.DrawText( ft, GetTextOrigin(style, ref rect, ft)); } else { var ci = CultureInfo.InvariantCulture; var fontStyle = System.Windows.FontStyles.Normal; if (style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Italic)) { fontStyle = System.Windows.FontStyles.Italic; } var fontWeight = FontWeights.Regular; if (style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Bold)) { fontWeight = FontWeights.Bold; } var tf = new Typeface( new FontFamily(style.TextStyle.FontName), fontStyle, fontWeight, FontStretches.Normal); ft = new FormattedText( tbind, ci, ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, tf, style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon, stroke.Brush, null, TextFormattingMode.Ideal); if (style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Underline) || style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Strikeout)) { var decorations = new TextDecorationCollection(); if (style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Underline)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Underline)); } if (style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Strikeout)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Strikethrough)); } ft.SetTextDecorations(decorations); } if (_enableTextCache) { var tuple = Tuple.Create(tbind, ft, style); if (_textCache.ContainsKey(text)) { _textCache[text] = tuple; } else { _textCache.Add(text, tuple); } } _dc.DrawText( ft, GetTextOrigin(style, ref rect, ft)); } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _gfx = dc as DrawingContext; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) { return; } Brush brush = ToSolidBrush(text.Style.Stroke); var fontStyle = Perspex.Media.FontStyle.Normal; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic)) { fontStyle |= Perspex.Media.FontStyle.Italic; } var fontWeight = Perspex.Media.FontWeight.Normal; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold)) { fontWeight |= Perspex.Media.FontWeight.Bold; } // TODO: Implement font decoration after Perspex adds support for them. /* * var fontDecoration = Perspex.Media.FontDecoration.None; * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline)) * { * fontDecoration |= Perspex.Media.FontDecoration.Underline; * } * * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout)) * { * fontDecoration |= Perspex.Media.FontDecoration.Strikethrough; * } */ var ft = new FormattedText( tbind, text.Style.TextStyle.FontName, text.Style.TextStyle.FontSize * _textScaleFactor, fontStyle, TextAlignment.Left, fontWeight); var rect = CreateRect( text.TopLeft, text.BottomRight, dx, dy); var size = ft.Measure(); var origin = GetTextOrigin(text.Style, ref rect, ref size); _gfx.DrawText(brush, origin, ft); // TODO: brush.Dispose(); ft.Dispose(); }
public void Draw(object ds, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _ds = ds as CanvasDrawingSession; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) { return; } var brush = ToColor(text.Style.Stroke); var fontWeight = FontWeights.Normal; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Bold)) { fontWeight = FontWeights.Bold; } var fontStyle = Windows.UI.Text.FontStyle.Normal; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Italic)) { fontStyle = Windows.UI.Text.FontStyle.Italic; } var format = new CanvasTextFormat() { FontFamily = text.Style.TextStyle.FontName, FontWeight = fontWeight, FontStyle = fontStyle, FontSize = (float)text.Style.TextStyle.FontSize, WordWrapping = CanvasWordWrapping.NoWrap }; var rect = Rect2.Create(text.TopLeft, text.BottomRight, dx, dy); var layout = new CanvasTextLayout(_ds, tbind, format, (float)rect.Width, (float)rect.Height); if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Underline)) { layout.SetUnderline(0, tbind.Length, true); } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Strikeout)) { layout.SetStrikethrough(0, tbind.Length, true); } switch (text.Style.TextStyle.TextHAlignment) { case TextHAlignment.Left: layout.HorizontalAlignment = CanvasHorizontalAlignment.Left; break; case TextHAlignment.Center: layout.HorizontalAlignment = CanvasHorizontalAlignment.Center; break; case TextHAlignment.Right: layout.HorizontalAlignment = CanvasHorizontalAlignment.Right; break; } switch (text.Style.TextStyle.TextVAlignment) { case TextVAlignment.Top: layout.VerticalAlignment = CanvasVerticalAlignment.Top; break; case TextVAlignment.Center: layout.VerticalAlignment = CanvasVerticalAlignment.Center; break; case TextVAlignment.Bottom: layout.VerticalAlignment = CanvasVerticalAlignment.Bottom; break; } _ds.DrawTextLayout( layout, new N.Vector2( (float)rect.X, (float)rect.Y), brush); layout.Dispose(); format.Dispose(); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XText text, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) return; Brush brush = ToSolidBrush(text.Style.Stroke); var fontStyle = System.Drawing.FontStyle.Regular; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Bold)) { fontStyle |= System.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Italic)) { fontStyle |= System.Drawing.FontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Underline)) { fontStyle |= System.Drawing.FontStyle.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Strikeout)) { fontStyle |= System.Drawing.FontStyle.Strikeout; } Font font = new Font( text.Style.TextStyle.FontName, (float)(text.Style.TextStyle.FontSize * _textScaleFactor), fontStyle); var rect = CreateRect( text.TopLeft, text.BottomRight, dx, dy); var srect = new RectangleF( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); var format = new StringFormat(); switch (text.Style.TextStyle.TextHAlignment) { case TextHAlignment.Left: format.Alignment = StringAlignment.Near; break; case TextHAlignment.Center: format.Alignment = StringAlignment.Center; break; case TextHAlignment.Right: format.Alignment = StringAlignment.Far; break; } switch (text.Style.TextStyle.TextVAlignment) { case TextVAlignment.Top: format.LineAlignment = StringAlignment.Near; break; case TextVAlignment.Center: format.LineAlignment = StringAlignment.Center; break; case TextVAlignment.Bottom: format.LineAlignment = StringAlignment.Far; break; } format.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip; format.Trimming = StringTrimming.None; _gfx.DrawString( tbind, font, ToSolidBrush(text.Style.Stroke), srect, format); brush.Dispose(); font.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _dc = dc as DrawingContext; var style = text.Style; if (style == null) { return; } var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) { return; } double thickness = style.Thickness / _state.Zoom; double half = thickness / 2.0; Tuple <Brush, Pen> cache = null; Brush fill; Pen stroke; if (_enableStyleCache && _styleCache.TryGetValue(style, out cache)) { fill = cache.Item1; stroke = cache.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); if (_enableStyleCache) { _styleCache.Add(style, Tuple.Create(fill, stroke)); } } var rect = CreateRect( text.TopLeft, text.BottomRight, dx, dy); Tuple <string, FormattedText, ShapeStyle> tcache = null; FormattedText ft; string ct; if (_enableTextCache && _textCache.TryGetValue(text, out tcache) && string.Compare(tcache.Item1, tbind) == 0 && tcache.Item3 == style) { ct = tcache.Item1; ft = tcache.Item2; _dc.DrawText( ft, GetTextOrigin(style, ref rect, ft)); } else { var ci = CultureInfo.InvariantCulture; var fontStyle = System.Windows.FontStyles.Normal; if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Italic)) { fontStyle = System.Windows.FontStyles.Italic; } var fontWeight = FontWeights.Regular; if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Bold)) { fontWeight = FontWeights.Bold; } var tf = new Typeface( new FontFamily(style.TextStyle.FontName), fontStyle, fontWeight, FontStretches.Normal); ft = new FormattedText( tbind, ci, ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, tf, style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon, stroke.Brush, null, TextFormattingMode.Ideal); if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline) || style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout)) { var decorations = new TextDecorationCollection(); if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Underline)); } if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Strikethrough)); } ft.SetTextDecorations(decorations); } if (_enableTextCache) { var tuple = Tuple.Create(tbind, ft, style); if (_textCache.ContainsKey(text)) { _textCache[text] = tuple; } else { _textCache.Add(text, tuple); } } _dc.DrawText( ft, GetTextOrigin(style, ref rect, ft)); } }