/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> public override void LeftDown(double x, double y) { double sx = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x; double sy = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y; switch (_currentState) { case State.None: { _shape = XText.Create( sx, sy, _editor.Project.CurrentStyleLibrary.CurrentStyle, _editor.Project.Options.PointShape, "Text", _editor.Project.Options.DefaultIsStroked); if (_editor.Project.Options.TryToConnect) { TryToConnectTopLeft(_shape as XText, sx, sy); } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_shape); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_shape); _editor.Project.CurrentContainer.HelperLayer.Invalidate(); _currentState = State.One; _editor.CancelAvailable = true; } break; case State.One: { var text = _shape as XText; if (text != null) { text.BottomRight.X = sx; text.BottomRight.Y = sy; if (_editor.Project.Options.TryToConnect) { TryToConnectBottomRight(_shape as XText, sx, sy); } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape); Remove(); Finalize(_shape); _editor.AddWithHistory(_shape); _currentState = State.None; _editor.CancelAvailable = false; } } break; } }
/// <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.HasFlag(Test2d.FontStyle.Bold)) { fontStyle |= System.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Italic)) { fontStyle |= System.Drawing.FontStyle.Italic; } if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Underline)) { fontStyle |= System.Drawing.FontStyle.Underline; } if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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; } _gfx.DrawString( tbind, font, ToSolidBrush(text.Style.Stroke), srect, format); brush.Dispose(); font.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; var brush = ToSolidBrush(text.Style.Stroke); var fontStyle = Eto.Drawing.FontStyle.None; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Bold)) { fontStyle |= Eto.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Italic)) { fontStyle |= Eto.Drawing.FontStyle.Italic; } var fontDecoration = Eto.Drawing.FontDecoration.None; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Underline)) { fontDecoration |= Eto.Drawing.FontDecoration.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.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(); }
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.HasFlag(Test2d.FontStyle.Bold)) { fontWeight = FontWeights.Bold; } var fontStyle = Windows.UI.Text.FontStyle.Normal; if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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.HasFlag(Test2d.FontStyle.Underline)) { layout.SetUnderline(0, tbind.Length, true); } if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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="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 IDrawingContext; 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.HasFlag(Test2d.FontStyle.Italic)) { fontStyle |= Perspex.Media.FontStyle.Italic; } var fontWeight = Perspex.Media.FontWeight.Normal; if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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.HasFlag(Test2d.FontStyle.Underline)) { fontDecoration |= Perspex.Media.FontDecoration.Underline; } if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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(); }
/// <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.HasFlag(Test2d.FontStyle.Italic)) { fontStyle = System.Windows.FontStyles.Italic; } var fontWeight = FontWeights.Regular; if (style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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.HasFlag(Test2d.FontStyle.Underline) || style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Strikeout)) { var decorations = new TextDecorationCollection(); if (style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Underline)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Underline)); } if (style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.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="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetTextBounds(XText text, double dx, double dy) { return Rect2.Create(text.TopLeft, text.BottomRight, dx, dy); }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="x"></param> /// <param name="y"></param> public void TryToConnectTopLeft(XText text, double x, double y) { var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold); if (result != null && result is XPoint) { text.TopLeft = result as XPoint; } }
/// <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(Test2d.FontStyleFlags.Bold)) { fontStyle |= System.Drawing.FontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Italic)) { fontStyle |= System.Drawing.FontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Underline)) { fontStyle |= System.Drawing.FontStyle.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.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="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetTextBounds(XText text, double dx, double dy) { return(Rect2.Create(text.TopLeft, text.BottomRight, dx, dy)); }