/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var canvas = dc as SKCanvas; var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } SKTypefaceStyle style = SKTypefaceStyle.Normal; if (text.Style.TextStyle.FontStyle != null) { if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold)) { style |= SKTypefaceStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic)) { style |= SKTypefaceStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline)) { // TODO: Add support for FontStyleFlags.Underline } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout)) { // TODO: Add support for FontStyleFlags.Strikeout } } using (var pen = ToSKPaintBrush(text.Style.Stroke)) using (var tf = SKTypeface.FromFamilyName(text.Style.TextStyle.FontName, style)) { pen.TextEncoding = SKTextEncoding.Utf16; pen.TextSize = _scaleToPage(text.Style.TextStyle.FontSize * _targetDpi / _sourceDpi); var fm = pen.FontMetrics; float offset = -(fm.Top + fm.Bottom); var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy, _scaleToPage); SKRect bounds = new SKRect(); pen.MeasureText(tbind, ref bounds); SKPoint origin = GetTextOrigin(text.Style, ref rect, ref bounds); canvas.DrawText(tbind, origin.X, origin.Y + offset, pen); } }
/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var _dc = dc as DrawingContext; var style = text.Style; if (style == null) { return; } var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple <Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy); Tuple <string, FormattedText, ShapeStyle> tcache = _textCache.Get(text); FormattedText ft; string ct; if (tcache != null && 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; var fontWeight = FontWeights.Regular; if (style.TextStyle.FontStyle != null) { if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic)) { fontStyle = System.Windows.FontStyles.Italic; } if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.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 != null) { if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline) || style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout)) { var decorations = new TextDecorationCollection(); if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Underline)); } if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Strikethrough)); } ft.SetTextDecorations(decorations); } } _textCache.Set(text, Tuple.Create(tbind, ft, style)); _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft)); } }
/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var _gfx = dc as AM.DrawingContext; var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } AM.IBrush brush = ToBrush(text.Style.Stroke); var fontStyle = AM.FontStyle.Normal; var fontWeight = AM.FontWeight.Normal; //var fontDecoration = PM.FontDecoration.None; if (text.Style.TextStyle.FontStyle != null) { if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic)) { fontStyle |= AM.FontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold)) { fontWeight |= AM.FontWeight.Bold; } // TODO: Implement font decoration after Avalonia adds support. /* * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline)) * { * fontDecoration |= PM.FontDecoration.Underline; * } * * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout)) * { * fontDecoration |= PM.FontDecoration.Strikethrough; * } */ } if (text.Style.TextStyle.FontSize >= 0.0) { var tf = new AM.Typeface( text.Style.TextStyle.FontName, text.Style.TextStyle.FontSize * _textScaleFactor, fontStyle, fontWeight); var ft = new AM.FormattedText() { Typeface = tf, Text = tbind, TextAlignment = AM.TextAlignment.Left, Wrapping = AM.TextWrapping.NoWrap }; 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); } }
/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var dxf = dc as DxfDocument; var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } var style = text.Style; var stroke = ToColor(style.Stroke); var strokeTansparency = ToTransparency(style.Stroke); var attachmentPoint = default(MTextAttachmentPoint); double x, y; var rect = Spatial.Rect2.FromPoints( text.TopLeft.X, text.TopLeft.Y, text.BottomRight.X, text.BottomRight.Y, dx, dy); switch (text.Style.TextStyle.TextHAlignment) { default: case TextHAlignment.Left: x = rect.X; break; case TextHAlignment.Center: x = rect.X + rect.Width / 2.0; break; case TextHAlignment.Right: x = rect.X + rect.Width; break; } switch (text.Style.TextStyle.TextVAlignment) { default: case TextVAlignment.Top: y = rect.Y; break; case TextVAlignment.Center: y = rect.Y + rect.Height / 2.0; break; case TextVAlignment.Bottom: y = rect.Y + rect.Height; break; } switch (text.Style.TextStyle.TextVAlignment) { default: case TextVAlignment.Top: switch (text.Style.TextStyle.TextHAlignment) { default: case TextHAlignment.Left: attachmentPoint = MTextAttachmentPoint.TopLeft; break; case TextHAlignment.Center: attachmentPoint = MTextAttachmentPoint.TopCenter; break; case TextHAlignment.Right: attachmentPoint = MTextAttachmentPoint.TopRight; break; } break; case TextVAlignment.Center: switch (text.Style.TextStyle.TextHAlignment) { default: case TextHAlignment.Left: attachmentPoint = MTextAttachmentPoint.MiddleLeft; break; case TextHAlignment.Center: attachmentPoint = MTextAttachmentPoint.MiddleCenter; break; case TextHAlignment.Right: attachmentPoint = MTextAttachmentPoint.MiddleRight; break; } break; case TextVAlignment.Bottom: switch (text.Style.TextStyle.TextHAlignment) { default: case TextHAlignment.Left: attachmentPoint = MTextAttachmentPoint.BottomLeft; break; case TextHAlignment.Center: attachmentPoint = MTextAttachmentPoint.BottomCenter; break; case TextHAlignment.Right: attachmentPoint = MTextAttachmentPoint.BottomRight; break; } break; } var ts = new netDxf.Tables.TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile); var dxfMText = new MText( new Vector3(ToDxfX(x), ToDxfY(y), 0), text.Style.TextStyle.FontSize * _targetDpi / _sourceDpi, rect.Width, ts); dxfMText.AttachmentPoint = attachmentPoint; var options = new MTextFormattingOptions(dxfMText.Style); var fs = text.Style.TextStyle.FontStyle; if (fs != null) { options.Bold = fs.Flags.HasFlag(FontStyleFlags.Bold); options.Italic = fs.Flags.HasFlag(FontStyleFlags.Italic); options.Underline = fs.Flags.HasFlag(FontStyleFlags.Underline); options.StrikeThrough = fs.Flags.HasFlag(FontStyleFlags.Strikeout); } options.Aligment = MTextFormattingOptions.TextAligment.Default; options.Color = null; dxfMText.Write(tbind, options); dxfMText.Layer = _currentLayer; dxfMText.Transparency.Value = strokeTansparency; dxfMText.Color = stroke; dxf.AddEntity(dxfMText); }
/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var _gfx = dc as XGraphics; var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } var options = new XPdfFontOptions(PdfFontEncoding.Unicode); var fontStyle = XFontStyle.Regular; if (text.Style.TextStyle.FontStyle != null) { if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold)) { fontStyle |= XFontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic)) { fontStyle |= XFontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline)) { fontStyle |= XFontStyle.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout)) { fontStyle |= XFontStyle.Strikeout; } } var font = new XFont( text.Style.TextStyle.FontName, _scaleToPage(text.Style.TextStyle.FontSize), fontStyle, options); var rect = Spatial.Rect2.FromPoints( text.TopLeft.X, text.TopLeft.Y, text.BottomRight.X, text.BottomRight.Y, dx, dy); var srect = new XRect( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); var format = new XStringFormat(); switch (text.Style.TextStyle.TextHAlignment) { case TextHAlignment.Left: format.Alignment = XStringAlignment.Near; break; case TextHAlignment.Center: format.Alignment = XStringAlignment.Center; break; case TextHAlignment.Right: format.Alignment = XStringAlignment.Far; break; } switch (text.Style.TextStyle.TextVAlignment) { case TextVAlignment.Top: format.LineAlignment = XLineAlignment.Near; break; case TextVAlignment.Center: format.LineAlignment = XLineAlignment.Center; break; case TextVAlignment.Bottom: format.LineAlignment = XLineAlignment.Far; break; } _gfx.DrawString( tbind, font, ToXSolidBrush(text.Style.Stroke), srect, format); }
/// <inheritdoc/> public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r) { var _gfx = dc as Graphics; var properties = (ImmutableArray <Property>)db; var record = (Record)r; var tbind = text.BindText(properties, record); if (string.IsNullOrEmpty(tbind)) { return; } Brush brush = ToSolidBrush(text.Style.Stroke); var fontStyle = System.Drawing.FontStyle.Regular; if (text.Style.TextStyle.FontStyle != null) { if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Bold)) { fontStyle |= System.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic)) { fontStyle |= System.Drawing.FontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline)) { fontStyle |= System.Drawing.FontStyle.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.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(); }