/// <summary> /// Initialize new instance of <see cref="ToolTextSelection"/> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public ToolTextSelection(IServiceProvider serviceProvider, ILayerContainer layer, ITextShape shape, IShapeStyle style) { _serviceProvider = serviceProvider; _layer = layer; _text = shape; _style = style; }
/// <inheritdoc/> public void Bind(ITextShape text, object db, object r) { var properties = (ImmutableArray <IProperty>)db; var record = (IRecord)r; var tbind = text.BindText(properties, record); text.SetProperty(nameof(ITextShape.Text), tbind); }
/// <summary> /// Bind properties or data record to <see cref="ITextShape.Text"/> property. /// </summary> /// <param name="text">The text shape instance.</param> /// <param name="db">The properties database used for binding.</param> /// <param name="r">The external data record used for binding.</param> /// <returns>The string bound to properties or data record.</returns> public static string BindText(this ITextShape text, ImmutableArray <IProperty> db, IRecord r) { var record = text.Data?.Record ?? r; if (!string.IsNullOrEmpty(text.Text)) { if (IsBinding(text.Text, out string binding)) { // Try to bind to internal Record or external (r) data record using Text property as Column.Name name. if (record != null) { bool success = TryToBind(record, binding, out string value); if (success) { return(value); } } // Try to bind to external Properties database (e.g. Container.Data.Properties) using Text property as Property.Name name. if (db != null && db.Length > 0) { bool success = TryToBind(db, binding, out string value); if (success) { return(value); } } // Try to bind to internal Properties database (e.g. Data.Properties) using Text property as Property.Name name. if (text.Data?.Properties != null && text.Data.Properties.Length > 0) { bool success = TryToBind(text.Data.Properties, binding, out string value); if (success) { return(value); } } } // Try to bind to Properties using Text as formatting. if (text.Data?.Properties != null && text.Data.Properties.Length > 0) { try { var args = text.Data.Properties.Where(x => x != null).Select(x => x.Value).ToArray(); if (text.Text != null && args != null && args.Length > 0) { return(string.Format(text.Text, args)); } } catch (FormatException) { } } } return(text.Text); }
public static SKPath ToSKPath(this IBaseShape shape, double dx, double dy, Func <double, float> scale) { return(shape switch { ILineShape lineShape => ToSKPath(lineShape, dx, dy, scale), IRectangleShape rectangleShape => ToSKPath(rectangleShape, dx, dy, scale), IEllipseShape ellipseShape => ToSKPath(ellipseShape, dx, dy, scale), IImageShape imageShape => ToSKPath(imageShape, dx, dy, scale), IArcShape arcShape => ToSKPath(arcShape, dx, dy, scale), ICubicBezierShape cubicBezierShape => ToSKPath(cubicBezierShape, dx, dy, scale), IQuadraticBezierShape quadraticBezierShape => ToSKPath(quadraticBezierShape, dx, dy, scale), ITextShape textShape => ToSKPath(textShape, dx, dy, scale), IPathShape pathShape => ToSKPath(pathShape, dx, dy, scale), IGroupShape groupShape => ToSKPath(groupShape.Shapes, dx, dy, scale), _ => null, });
/// <summary> /// Bind properties or data record to <see cref="ITextShape.Text"/> property. /// </summary> /// <param name="shape">The text shape instance.</param> /// <param name="properties">The properties database used for binding.</param> /// <param name="externalRecord">The external data record used for binding.</param> /// <returns>The string bound to properties or data record.</returns> public static string Bind(ITextShape shape, ImmutableArray <IProperty> properties, IRecord externalRecord) { var text = shape.Text; var data = shape.Data; var record = data?.Record ?? externalRecord; if (string.IsNullOrEmpty(text)) { return(text); } var bindings = BindingParser.Parse(text); if (bindings.Count > 0) { var sb = new StringBuilder(text); var count = 0; bindings.Reverse(); foreach (var binding in bindings) { // Try to bind to internal Record or external (r) data record using Text property as Column.Name name. if (record != null) { bool success = GetBindingValue(record, binding.Path, out string value); if (success) { sb.Replace(binding.Value, value, binding.Start, binding.Length); count++; continue; } } // Try to bind to external Properties database (e.g. Container.Data.Properties) using Text property as Property.Name name. if (properties != null && properties.Length > 0) { bool success = GetBindingValue(properties, binding.Path, out string value); if (success) { sb.Replace(binding.Value, value, binding.Start, binding.Length); count++; continue; } } // Try to bind to internal Properties database (e.g. Data.Properties) using Text property as Property.Name name. if (data?.Properties != null && data.Properties.Length > 0) { bool success = GetBindingValue(data.Properties, binding.Path, out string value); if (success) { sb.Replace(binding.Value, value, binding.Start, binding.Length); count++; continue; } } } if (count > 0) { return(sb.ToString()); } } // Try to bind to Properties using Text as formatting args. if (data?.Properties != null && data.Properties.Length > 0) { try { var args = data.Properties.Where(x => x != null).Select(x => x.Value).ToArray(); if (args != null && args.Length > 0) { return(string.Format(text, args)); } } catch (FormatException) { } } return(text); }
public TextDrawNode(ITextShape text, IShapeStyle style) { Style = style; Text = text; UpdateGeometry(); }
public ITextDrawNode CreateTextDrawNode(ITextShape text, IShapeStyle style) { return(new TextDrawNode(text, style)); }