/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var _dc = dc as AM.DrawingContext; var rect = CreateRect(image.TopLeft, image.BottomRight, dx, dy); if (image.IsStroked || image.IsFilled) { AM.IBrush brush = ToBrush(image.Style.Fill); AM.Pen pen = ToPen(image.Style, _scaleToPage); DrawRectangleInternal( _dc, brush, pen, image.IsStroked, image.IsFilled, ref rect); } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { try { var bi = _biCache[image.Key]; _dc.DrawImage( bi, 1.0, new A.Rect(0, 0, bi.PixelWidth, bi.PixelHeight), new A.Rect(rect.X, rect.Y, rect.Width, rect.Height)); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } try { var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { using (var ms = new System.IO.MemoryStream(bytes)) { var bi = new AMI.Bitmap(ms); if (_enableImageCache) { _biCache[image.Key] = bi; } _dc.DrawImage( bi, 1.0, new A.Rect(0, 0, bi.PixelWidth, bi.PixelHeight), new A.Rect(rect.X, rect.Y, rect.Width, rect.Height)); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Bitmap sourceImage = null; DA.GetData(0, ref sourceImage); int size = 0; DA.GetData(1, ref size); Boolean direction = true; DA.GetData(2, ref direction); DA.SetData(0, ImageShape.resizeImage(sourceImage, size, direction)); }
public ImageObject(GameScene gameScene) { this._gameScene = gameScene; this.SetComponent(_transform = new Transform()); this.SetComponent(_imageShape = new ImageShape(gameScene.Resolution, "RenderBuffer")); this._renderBuffer = new Bitmap(gameScene.Resolution); this._renderTarget = new RenderTarget(gameScene.Resolution.Width, gameScene.Resolution.Height); this._bytes = new byte[_renderTarget.SizeBytes]; GameResource.SetBitmap("RenderBuffer", _renderBuffer); }
private async void ChangeImage(byte[] byteArray) { if (byteArray != null && byteArray.Length > 0) { var imageSource = await GetImageSource(byteArray, (int)Width * 2, (int)Height * 2); ImageShape.Fill = new ImageBrush { ImageSource = imageSource }; } else { ImageShape.ClearValue(Shape.FillProperty); } }
/// <inheritdoc/> ImageShape IShapeFactory.Image(string path, double x1, double y1, double x2, double y2, bool isStroked, bool isFilled, string text) { var style = _editor.Project.CurrentStyleLibrary.Selected; var image = ImageShape.Create( x1, y1, x2, y2, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, path, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, image); return(image); }
/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var dxf = dc as DxfDocument; var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { var rect = Spatial.Rect2.FromPoints( image.TopLeft.X, image.TopLeft.Y, image.BottomRight.X, image.BottomRight.Y, dx, dy); var dxfImageDefinitionCached = _biCache.Get(image.Key); if (dxfImageDefinitionCached != null) { var dxfImage = new Image( dxfImageDefinitionCached, new Vector3(ToDxfX(rect.X), ToDxfY(rect.Y + rect.Height), 0), rect.Width, rect.Height); dxf.AddEntity(dxfImage); } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } var path = System.IO.Path.Combine(_outputPath, System.IO.Path.GetFileName(image.Key)); System.IO.File.WriteAllBytes(path, bytes); var dxfImageDefinition = new ImageDefinition(path); _biCache.Set(image.Key, dxfImageDefinition); var dxfImage = new Image( dxfImageDefinition, new Vector3(ToDxfX(rect.X), ToDxfY(rect.Y + rect.Height), 0), rect.Width, rect.Height); dxf.AddEntity(dxfImage); } } }
/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var canvas = dc as SKCanvas; var rect = CreateRect(image.TopLeft, image.BottomRight, dx, dy, _scaleToPage); if (image.IsStroked || image.IsFilled) { using (SKPaint brush = ToSKPaintBrush(image.Style.Fill)) using (SKPaint pen = ToSKPaintPen(image.Style, _scaleToPage, _sourceDpi, _targetDpi)) { DrawRectangleInternal(canvas, brush, pen, image.IsStroked, image.IsFilled, ref rect); } } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { canvas.DrawBitmap(_biCache[image.Key], rect); } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { var bi = SKBitmap.Decode(bytes); if (_enableImageCache) { _biCache[image.Key] = bi; } canvas.DrawBitmap(bi, rect); if (!_enableImageCache) { bi.Dispose(); } } } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Bitmap sourceImage = null; DA.GetData(0, ref sourceImage); int L = 0; DA.GetData(1, ref L); int R = 0; DA.GetData(2, ref R); int T = 0; DA.GetData(3, ref T); int B = 0; DA.GetData(4, ref B); DA.SetData(0, ImageShape.PaddingImage(sourceImage, L, R, T, B)); }
/// <summary> /// Barcode form field stencil /// </summary> public BarcodeFormFieldStencil(OmrBarcodeField field) { Tag = m_field = field; Size = new SizeF(200, 96); // Container shape m_containerShape = new RectangleShape { FillBrush = new SolidBrush(Color.FromArgb(127, Color.Gainsboro)), Position = new PointF(0, 0), ShadowBrush = new SolidBrush(Color.FromArgb(127, 0, 0, 0)), Size = new SizeF(Size.Width, Size.Height) }; m_textShape = new TextShape { Alignment = StringAlignment.Center, FillBrush = Brushes.Black, Text = field.Id, Font = new Font(new FontFamily(GenericFontFamilies.Serif), 16) }; m_textShape.Position = new PointF((Size.Width - m_textShape.Size.Width) / 2, (Size.Height - 32) / 2 + 16); m_iconShape = new ImageShape { Position = new PointF((Size.Width - 32) / 2, 5), Size = new SizeF(32, 32), AutoScale = false, Image = Image.FromStream( GetType() .Assembly.GetManifestResourceStream("OmrMarkEngine.Core.Template.Resources.view-barcode.png")) }; Add(m_containerShape, "container"); Add(m_iconShape, "image"); Add(m_textShape); m_field.PropertyChanged += m_field_PropertyChanged; SizeChanged += BarcodeFormFieldStencil_SizeChanged; PositionChanged += BarcodeFormFieldStencil_PositionChanged; }
/// <inheritdoc/> ImageShape IShapeFactory.Image(string path, PointShape topLeft, PointShape bottomRight, bool isStroked, bool isFilled, string text) { byte[] bytes; using (var stream = _editor.FileIO?.Open(path)) { bytes = _editor.FileIO?.ReadBinary(stream); } var key = _editor.Project.AddImageFromFile(path, bytes); var style = _editor.Project.CurrentStyleLibrary.Selected; var image = ImageShape.Create( topLeft, bottomRight, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, key, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, image); return(image); }
/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var _gfx = dc as Graphics; Brush brush = ToSolidBrush(image.Style.Stroke); var rect = CreateRect( image.TopLeft, image.BottomRight, dx, dy); var srect = new RectangleF( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); if (image.IsFilled) { _gfx.FillRectangle( ToSolidBrush(image.Style.Fill), srect); } if (image.IsStroked) { _gfx.DrawRectangle( ToPen(image.Style, _scaleToPage), srect.X, srect.Y, srect.Width, srect.Height); } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { _gfx.DrawImage(_biCache[image.Key], srect); } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { var ms = new System.IO.MemoryStream(bytes); var bi = Image.FromStream(ms); ms.Dispose(); if (_enableImageCache) { _biCache[image.Key] = bi; } _gfx.DrawImage(bi, srect); if (!_enableImageCache) { bi.Dispose(); } } } brush.Dispose(); }
void UpdateImage(ImageShape image) { image.UpdateShape(imgPath); }
/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { if (image.Key == null) { return; } var _dc = dc as DrawingContext; var style = image.Style; if (style == null) { 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(image.TopLeft, image.BottomRight, dx, dy); DrawRectangleInternal(_dc, half, fill, stroke, image.IsStroked, image.IsFilled, ref rect); var imageCached = _biCache.Get(image.Key); if (imageCached != null) { try { _dc.DrawImage(imageCached, rect); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else { if (_state.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } try { var bytes = _state.ImageCache.GetImage(image.Key); if (bytes != null) { var ms = new System.IO.MemoryStream(bytes); var bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); _biCache.Set(image.Key, bi); _dc.DrawImage(bi, rect); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } }
public ImageShapeProperty(ImageShape shapeNode) : base(shapeNode) { shape = shapeNode; }
internal static void AddImage(IToolContext context, ImageShape rectangle, double dx, double dy, SKPath geometry) { var rect = ToSKRect(rectangle.StartPoint, rectangle.Point, dx, dy); geometry.AddRect(rect, SKPathDirection.Clockwise); }
private DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox) { List <ControlLine> debugPoints = new List <ControlLine>(); DrawingGroup grp = new DrawingGroup(); if (viewBox.HasValue) { grp.ClipGeometry = new RectangleGeometry(viewBox.Value); } foreach (Shape shape in elements) { if (shape is UseShape) { UseShape useshape = shape as UseShape; Group group = this.SVG.GetShape(useshape.hRef) as Group; if (group != null) { Shape oldparent = group.Parent; group.Parent = useshape; // this to get proper style propagated DrawingGroup subgroup = this.LoadGroup(group.Elements, null); if (group.Clip != null) { subgroup.ClipGeometry = group.Clip.ClipGeometry; } subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y); grp.Children.Add(subgroup); group.Parent = oldparent; } continue; } if (shape is Clip) { DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null); if (shape.Transform != null) { subgroup.Transform = shape.Transform; } grp.Children.Add(subgroup); continue; } if (shape is Group) { DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null); if (shape.Clip != null) { subgroup.ClipGeometry = shape.Clip.ClipGeometry; } if (shape.Transform != null) { subgroup.Transform = shape.Transform; } AddDrawingToGroup(grp, shape, subgroup); continue; } if (shape is RectangleShape) { RectangleShape r = shape as RectangleShape; RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height)); rect.RadiusX = r.RX; rect.RadiusY = r.RY; if (rect.RadiusX == 0 && rect.RadiusY > 0) { rect.RadiusX = rect.RadiusY; } var di = this.NewDrawingItem(shape, rect); AddDrawingToGroup(grp, shape, di); } if (shape is LineShape) { LineShape r = shape as LineShape; LineGeometry line = new LineGeometry(r.P1, r.P2); var di = this.NewDrawingItem(shape, line); AddDrawingToGroup(grp, shape, di); } if (shape is PolylineShape) { PolylineShape r = shape as PolylineShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = false; p.StartPoint = r.Points[0]; for (int index = 1; index < r.Points.Length; index++) { p.Segments.Add(new LineSegment(r.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); } if (shape is PolygonShape) { PolygonShape r = shape as PolygonShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = true; p.StartPoint = r.Points[0]; for (int index = 1; index < r.Points.Length; index++) { p.Segments.Add(new LineSegment(r.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); } if (shape is CircleShape) { CircleShape r = shape as CircleShape; EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); } if (shape is EllipseShape) { EllipseShape r = shape as EllipseShape; EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); } if (shape is ImageShape) { ImageShape image = shape as ImageShape; ImageDrawing i = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height)); AddDrawingToGroup(grp, shape, i); } if (shape is TextShape) { GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape); if (gp != null) { foreach (Geometry gm in gp.Children) { TextShape.TSpan.Element tspan = TextRender.GetElement(gm); if (tspan != null) { var di = this.NewDrawingItem(tspan, gm); AddDrawingToGroup(grp, shape, di); } else { var di = this.NewDrawingItem(shape, gm); AddDrawingToGroup(grp, shape, di); } } } } if (shape is PathShape) { PathShape r = shape as PathShape; PathFigure p = null; Point lastPoint = new Point(0, 0); PathShape.CurveTo lastc = null; PathShape.QuadraticCurveTo lastq = null; Point lastcirPoint = new Point(0, 0); PathGeometry path = new PathGeometry(); foreach (PathShape.PathElement element in r.Elements) { bool isRelative = element.IsRelative; if (element is PathShape.MoveTo) { p = new PathFigure(); p.IsClosed = r.ClosePath; if (isRelative) { p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point; } else { p.StartPoint = ((PathShape.MoveTo)element).Point; } lastPoint = p.StartPoint; path.Figures.Add(p); continue; } if (element is PathShape.LineTo) { PathShape.LineTo lineto = element as PathShape.LineTo; foreach (Point point in lineto.Points) { if (isRelative) { Point newpoint = lastPoint + (Vector)point; lastPoint = newpoint; p.Segments.Add(new LineSegment(newpoint, true)); } else { if (lineto.PositionType == PathShape.LineTo.eType.Point) { lastPoint = point; } if (lineto.PositionType == PathShape.LineTo.eType.Horizontal) { lastPoint = new Point(point.X, lastPoint.Y); } if (lineto.PositionType == PathShape.LineTo.eType.Vertical) { lastPoint = new Point(lastPoint.X, point.Y); } p.Segments.Add(new LineSegment(lastPoint, true)); } } continue; } if (element is PathShape.CurveTo) { PathShape.CurveTo c = element as PathShape.CurveTo; Point startPoint = lastPoint; BezierSegment s = new BezierSegment(); if (isRelative) { s.Point1 = lastPoint + (Vector)c.CtrlPoint1; if (c.Command == 's') { // first control point is a mirrored point of last end control point //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); double dx = lastc.CtrlPoint2.X - lastc.Point.X; double dy = lastc.CtrlPoint2.Y - lastc.Point.Y; s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); //s.Point1 = lastctrlpoint; } s.Point2 = lastPoint + (Vector)c.CtrlPoint2; s.Point3 = lastPoint + (Vector)c.Point; } else { if (c.Command == 's') { // first control point is a mirrored point of last end control point //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); double dx = lastc.CtrlPoint2.X - lastc.Point.X; double dy = lastc.CtrlPoint2.Y - lastc.Point.Y; s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); } else { s.Point1 = c.CtrlPoint1; } s.Point2 = c.CtrlPoint2; s.Point3 = c.Point; } lastPoint = s.Point3; p.Segments.Add(s); lastc = c; lastcirPoint = s.Point3; //debugPoints.Add(new ControlLine(startPoint, s.Point1)); //debugPoints.Add(new ControlLine(s.Point3, s.Point2)); continue; } if (element is PathShape.QuadraticCurveTo) { PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo; Point startPoint = lastPoint; QuadraticBezierSegment s = new QuadraticBezierSegment(); if (isRelative) { s.Point1 = lastPoint + (Vector)c.CtrlPoint1; if (c.Command == 'q') { // first control point is a mirrored point of last end control point //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); double dx = lastq.CtrlPoint1.X - lastq.Point.X; double dy = lastq.CtrlPoint1.Y - lastq.Point.Y; s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); //s.Point1 = lastctrlpoint; } s.Point2 = lastPoint + (Vector)c.Point; } else { if (c.Command == 'q') { // first control point is a mirrored point of last end control point //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); double dx = lastq.CtrlPoint1.X - lastq.Point.X; double dy = lastq.CtrlPoint1.Y - lastq.Point.Y; s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); } else { s.Point1 = c.CtrlPoint1; } s.Point2 = c.Point; } lastPoint = s.Point2; p.Segments.Add(s); lastq = c; lastcirPoint = s.Point2; //debugPoints.Add(new ControlLine(startPoint, s.Point1)); //debugPoints.Add(new ControlLine(s.Point3, s.Point2)); continue; } if (element is PathShape.EllipticalArcTo) { PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo; ArcSegment s = new ArcSegment(); if (isRelative) { s.Point = lastPoint + new Vector(c.X, c.Y); } else { s.Point = new Point(c.X, c.Y); } s.Size = new Size(c.RX, c.RY); s.RotationAngle = c.AxisRotation; s.SweepDirection = SweepDirection.Counterclockwise; if (c.Clockwise) { s.SweepDirection = SweepDirection.Clockwise; } s.IsLargeArc = c.LargeArc; lastPoint = s.Point; p.Segments.Add(s); continue; } } /* * if (r.Transform != null) * path.Transform = r.Transform; */ var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); //} } } if (debugPoints != null) { foreach (ControlLine line in debugPoints) { grp.Children.Add(line.Draw()); } } return(grp); }
public void Inherits_From_TextShape() { var target = new ImageShape(); Assert.True(target is TextShape); }
public void Draw(object dc, IShapeRenderer renderer, ImageShape imageShape, double dx, double dy, double scale) { DrawRectangle(dc, renderer, imageShape.StartPoint, imageShape.Point, dx, dy, scale); }
internal DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox, bool isSwitch) { List <ControlLine> debugPoints = new List <ControlLine>(); DrawingGroup grp = new DrawingGroup(); if (viewBox.HasValue) { grp.ClipGeometry = new RectangleGeometry(viewBox.Value); } foreach (Shape shape in elements) { if (isSwitch) { if (grp.Children.Count > 0) { break; } if (!string.IsNullOrEmpty(shape.RequiredFeatures)) { if (!SVGFeatures.Features.Contains(shape.RequiredFeatures)) { continue; } if (!string.IsNullOrEmpty(shape.RequiredExtensions)) { continue; } } } if (shape is AnimationBase) { if (UseAnimations) { if (shape is AnimateTransform animateTransform) { if (animateTransform.Type == AnimateTransformType.Rotate) { var animation = new DoubleAnimation { From = double.Parse(animateTransform.From), To = double.Parse(animateTransform.To), Duration = animateTransform.Duration }; animation.RepeatBehavior = RepeatBehavior.Forever; var r = new RotateTransform(); grp.Transform = r; r.BeginAnimation(RotateTransform.AngleProperty, animation); } } else if (shape is Animate animate) { var target = this.SVG.GetShape(animate.hRef); var g = target.geometryElement; //todo : rework this all, generalize it! if (animate.AttributeName == "r") { var animation = new DoubleAnimationUsingKeyFrames() { Duration = animate.Duration }; foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x)))) { animation.KeyFrames.Add(d); } animation.RepeatBehavior = RepeatBehavior.Forever; g.BeginAnimation(EllipseGeometry.RadiusXProperty, animation); g.BeginAnimation(EllipseGeometry.RadiusYProperty, animation); } else if (animate.AttributeName == "cx") { var animation = new PointAnimationUsingKeyFrames() { Duration = animate.Duration }; foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y)))) { animation.KeyFrames.Add(d); } animation.RepeatBehavior = RepeatBehavior.Forever; g.BeginAnimation(EllipseGeometry.CenterProperty, animation); } else if (animate.AttributeName == "cy") { var animation = new PointAnimationUsingKeyFrames() { Duration = animate.Duration }; foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(((EllipseGeometry)g).Center.X, double.Parse(_))))) { animation.KeyFrames.Add(d); } animation.RepeatBehavior = RepeatBehavior.Forever; g.BeginAnimation(EllipseGeometry.CenterProperty, animation); } } } continue; } if (shape is UseShape) { UseShape useshape = shape as UseShape; Shape currentUsedShape = this.SVG.GetShape(useshape.hRef); if (currentUsedShape != null) { currentUsedShape.RealParent = useshape; Shape oldparent = currentUsedShape.Parent; DrawingGroup subgroup; if (currentUsedShape is Group) { subgroup = this.LoadGroup(((Group)currentUsedShape).Elements, null, false); } else { subgroup = this.LoadGroup(new[] { currentUsedShape }, null, false); } if (currentUsedShape.Clip != null) { subgroup.ClipGeometry = currentUsedShape.Clip.ClipGeometry; } subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y); if (useshape.Transform != null) { subgroup.Transform = new TransformGroup() { Children = new TransformCollection() { subgroup.Transform, useshape.Transform } } } ; grp.Children.Add(subgroup); currentUsedShape.Parent = oldparent; } continue; } if (shape is Clip) { DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null, false); if (shape.Transform != null) { subgroup.Transform = shape.Transform; } grp.Children.Add(subgroup); continue; } if (shape is Group groupShape) { DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null, groupShape.IsSwitch); AddDrawingToGroup(grp, shape, subgroup); continue; } if (shape is RectangleShape) { RectangleShape r = shape as RectangleShape; RectangleGeometry rect = new RectangleGeometry(new Rect(r.X < 0 ? 0 : r.X, r.Y < 0 ? 0 : r.Y, r.X < 0 ? r.Width + r.X : r.Width, r.Y < 0 ? r.Height + r.Y : r.Height)); rect.RadiusX = r.RX; rect.RadiusY = r.RY; if (rect.RadiusX == 0 && rect.RadiusY > 0) { rect.RadiusX = rect.RadiusY; } var di = this.NewDrawingItem(shape, rect); AddDrawingToGroup(grp, shape, di); continue; } if (shape is LineShape) { LineShape r = shape as LineShape; LineGeometry line = new LineGeometry(r.P1, r.P2); var di = this.NewDrawingItem(shape, line); AddDrawingToGroup(grp, shape, di); continue; } if (shape is PolylineShape) { PolylineShape r = shape as PolylineShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = false; p.StartPoint = r.Points[0]; for (int index = 1; index < r.Points.Length; index++) { p.Segments.Add(new LineSegment(r.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); continue; } if (shape is PolygonShape) { PolygonShape r = shape as PolygonShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = true; p.StartPoint = r.Points[0]; for (int index = 1; index < r.Points.Length; index++) { p.Segments.Add(new LineSegment(r.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); continue; } if (shape is CircleShape) { CircleShape r = shape as CircleShape; EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); continue; } if (shape is EllipseShape) { EllipseShape r = shape as EllipseShape; EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); continue; } if (shape is ImageShape) { ImageShape image = shape as ImageShape; ImageDrawing i = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height)); AddDrawingToGroup(grp, shape, i); continue; } if (shape is TextShape) { GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape); if (gp != null) { foreach (Geometry gm in gp.Children) { TextShape.TSpan.Element tspan = TextRender.GetElement(gm); if (tspan != null) { var di = this.NewDrawingItem(tspan, gm); AddDrawingToGroup(grp, shape, di); } else { var di = this.NewDrawingItem(shape, gm); AddDrawingToGroup(grp, shape, di); } } } continue; } if (shape is PathShape) { PathShape r = shape as PathShape; PathFigure p = null; Point lastPoint = new Point(0, 0); PathShape.CurveTo lastc = null; PathShape.QuadraticCurveTo lastq = null; Point lastcirPoint = new Point(0, 0); PathGeometry path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(r.Data)); //PathGeometry path = new PathGeometry(); /* * foreach (PathShape.PathElement element in r.Elements) * { * bool isRelative = element.IsRelative; * if (element is PathShape.MoveTo) * { * p = new PathFigure(); * p.IsClosed = r.ClosePath; * if (isRelative) p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point; * else p.StartPoint = ((PathShape.MoveTo)element).Point; * lastPoint = p.StartPoint; * path.Figures.Add(p); * continue; * } * if (element is PathShape.LineTo) * { * PathShape.LineTo lineto = element as PathShape.LineTo; * foreach (Point point in lineto.Points) * { * if (isRelative) * { * Point newpoint = lastPoint + (Vector)point; * lastPoint = newpoint; * p.Segments.Add(new LineSegment(newpoint, true)); * } * else * { * if (lineto.PositionType == PathShape.LineTo.eType.Point) lastPoint = point; * if (lineto.PositionType == PathShape.LineTo.eType.Horizontal) lastPoint = new Point(point.X, lastPoint.Y); * if (lineto.PositionType == PathShape.LineTo.eType.Vertical) lastPoint = new Point(lastPoint.X, point.Y); * p.Segments.Add(new LineSegment(lastPoint, true)); * } * } * continue; * } * if (element is PathShape.CurveTo) * { * PathShape.CurveTo c = element as PathShape.CurveTo; * Point startPoint = lastPoint; * BezierSegment s = new BezierSegment(); * if (isRelative) * { * s.Point1 = lastPoint + (Vector)c.CtrlPoint1; * * if (c.Command == 's') * { * // first control point is a mirrored point of last end control point * //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); * //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); * * double dx = lastc.CtrlPoint2.X - lastc.Point.X; * double dy = lastc.CtrlPoint2.Y - lastc.Point.Y; * s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); * //s.Point1 = lastctrlpoint; * } * * s.Point2 = lastPoint + (Vector)c.CtrlPoint2; * s.Point3 = lastPoint + (Vector)c.Point; * } * else * { * if (c.Command == 's') * { * // first control point is a mirrored point of last end control point * //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); * //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); * * double dx = lastc.CtrlPoint2.X - lastc.Point.X; * double dy = lastc.CtrlPoint2.Y - lastc.Point.Y; * s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); * } * else s.Point1 = c.CtrlPoint1; * s.Point2 = c.CtrlPoint2; * s.Point3 = c.Point; * } * lastPoint = s.Point3; * p.Segments.Add(s); * * lastc = c; * lastcirPoint = s.Point3; * * //debugPoints.Add(new ControlLine(startPoint, s.Point1)); * //debugPoints.Add(new ControlLine(s.Point3, s.Point2)); * continue; * } * if (element is PathShape.QuadraticCurveTo) * { * PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo; * Point startPoint = lastPoint; * QuadraticBezierSegment s = new QuadraticBezierSegment(); * if (isRelative) * { * s.Point1 = lastPoint + (Vector)c.CtrlPoint1; * * if (c.Command == 'q' && lastq != null) // fix for horse svg! needed ?? or is it wrong in SVG? * { * // first control point is a mirrored point of last end control point * //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); * //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); * * double dx = lastq.CtrlPoint1.X - lastq.Point.X; * double dy = lastq.CtrlPoint1.Y - lastq.Point.Y; * s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); * //s.Point1 = lastctrlpoint; * } * * s.Point2 = lastPoint + (Vector)c.Point; * } * else * { * if (c.Command == 'q') * { * // first control point is a mirrored point of last end control point * //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy); * //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2); * * double dx = lastq.CtrlPoint1.X - lastq.Point.X; * double dy = lastq.CtrlPoint1.Y - lastq.Point.Y; * s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy); * } * else s.Point1 = c.CtrlPoint1; * s.Point2 = c.Point; * } * lastPoint = s.Point2; * p.Segments.Add(s); * * lastq = c; * lastcirPoint = s.Point2; * * //debugPoints.Add(new ControlLine(startPoint, s.Point1)); * //debugPoints.Add(new ControlLine(s.Point3, s.Point2)); * continue; * } * if (element is PathShape.EllipticalArcTo) * { * PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo; * ArcSegment s = new ArcSegment(); * if (isRelative) s.Point = lastPoint + new Vector(c.X, c.Y); * else s.Point = new Point(c.X, c.Y); * * s.Size = new Size(c.RX, c.RY); * s.RotationAngle = c.AxisRotation; * s.SweepDirection = SweepDirection.Counterclockwise; * if (c.Clockwise) s.SweepDirection = SweepDirection.Clockwise; * s.IsLargeArc = c.LargeArc; * lastPoint = s.Point; * p.Segments.Add(s); * continue; * } * } */ /* * if (r.Transform != null) * path.Transform = r.Transform; */ var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); //} } } if (debugPoints != null) { foreach (ControlLine line in debugPoints) { grp.Children.Add(line.Draw()); } } return(grp); }
private void writeImageShape(ImageShape image, Matrix transform) { // draw an image as a box with a red border - we are interested in position only outStream.Write("<path stroke=\"red\" stroke-wdith=\"3\" fill=\"none\" d=\""); outStream.Write("M {0} ", writePoint(0, 0, transform)); outStream.Write("L {0} ", writePoint(0, 0 + image.Height, transform)); outStream.Write("L {0} ", writePoint(0 + image.Width, 0 + image.Height, transform)); outStream.Write("L {0} ", writePoint(0 + image.Width, 0, transform)); outStream.Write("Z "); outStream.Write("\"/>\n"); }
/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var _gfx = dc as XGraphics; var rect = Spatial.Rect2.FromPoints( image.TopLeft.X, image.TopLeft.Y, image.BottomRight.X, image.BottomRight.Y, dx, dy); var srect = new XRect( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); if (image.IsStroked || image.IsFilled) { DrawRectangleInternal( _gfx, ToXSolidBrush(image.Style.Fill), ToXPen(image.Style, _scaleToPage, _sourceDpi, _targetDpi), image.IsStroked, image.IsFilled, ref srect); } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { _gfx.DrawImage(_biCache[image.Key], srect); } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { var ms = new System.IO.MemoryStream(bytes); #if WPF var bs = new BitmapImage(); bs.BeginInit(); bs.StreamSource = ms; bs.EndInit(); bs.Freeze(); var bi = XImage.FromBitmapSource(bs); #else var bi = XImage.FromStream(ms); #endif if (_enableImageCache) { _biCache[image.Key] = bi; } _gfx.DrawImage(bi, srect); if (!_enableImageCache) { bi.Dispose(); } } } }
private string GetClass(ImageShape shape) { return(shape != ImageShape.none ? "img-" + Shape.ToString() : ""); }
protected override void ReadMessage(PacketBuffer buffer) { CustomNickname = buffer.ReadShortString(); ProfileImageShape = (ImageShape)buffer.ReadByte(); }
/// <summary> /// Evaluates the lines we have in the buffer /// </summary> /// <param name="lines">Lines</param> /// <remarks> /// We keep a buffer of lines. If a list of lines cannot be /// evaluated we wait for another second or so to allow for more lines. /// When that times out and no shape can be determined, then /// we clear the buffer. /// </remarks> private void EvaluateLines(List <Line> lines) { _clearTTL = _clearTTLResetValue; _buffer.AddRange(lines); var result = _patternEvaluator.Evaluate(_buffer); if (!result.IsValid) { return; } Debug.WriteLine("evaluation succeeded: " + result.Key); switch (result.Key) { case "button": var rectShape = new RectangleShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; _shapeNode.AddChild(new ShapeNode(rectShape)); _recognizerCanvasNode.Clear(); break; case "image": var imageShape = new ImageShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; _shapeNode.AddChild(new ShapeNode(imageShape)); _recognizerCanvasNode.Clear(); break; case "text": var textShape = new TextShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; _shapeNode.AddChild(new ShapeNode(textShape)); _recognizerCanvasNode.Clear(); break; case "entry": var entryShape = new EntryShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; _shapeNode.AddChild(new ShapeNode(entryShape)); _recognizerCanvasNode.Clear(); break; case "lineoftext": var lineoftext = new LineOfTextShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; _shapeNode.AddChild(new ShapeNode(lineoftext)); _recognizerCanvasNode.Clear(); break; case "delete": var deleteShape = new DeleteShape() { P1 = result.UpperLeft.ToCCPoint(), P2 = result.LowerRight.ToCCPoint() }; var victims = IsShapeOverOtherShapes(deleteShape); foreach (var victim in victims) { _shapeNode.RemoveChild(victim); } _recognizerCanvasNode.Clear(); break; } _canvasNode.Clear(); _buffer.Clear(); }
/// <summary> /// Initializes static designer context. /// </summary> /// <param name="serviceProvider">The service provider.</param> public static void InitializeContext(IServiceProvider serviceProvider) { // Editor Editor = serviceProvider.GetService <ProjectEditor>(); // Recent Projects Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test1", "Test1.project")); Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test2", "Test2.project")); // New Project Editor.OnNewProject(); // Transform Transform = MatrixObject.Identity; // Data var db = Database.Create("Db"); var fields = new string[] { "Column0", "Column1" }; var columns = ImmutableArray.CreateRange(fields.Select(c => Column.Create(db, c))); db.Columns = columns; var values = Enumerable.Repeat("<empty>", db.Columns.Length).Select(c => Value.Create(c)); var record = Record.Create( db, ImmutableArray.CreateRange(values)); db.Records = db.Records.Add(record); db.CurrentRecord = record; Database = db; Data = Context.Create(record); Record = record; // Project IProjectFactory factory = new ProjectFactory(); Project = factory.GetProject(); Template = PageContainer.CreateTemplate(); Page = PageContainer.CreatePage(); var layer = Page.Layers.FirstOrDefault(); layer.Shapes = layer.Shapes.Add(LineShape.Create(0, 0, null, null)); Page.CurrentLayer = layer; Page.CurrentShape = layer.Shapes.FirstOrDefault(); Page.Template = Template; Document = DocumentContainer.Create(); Layer = LayerContainer.Create(); Options = Options.Create(); // State State = ShapeState.Create(); // Style ArgbColor = ArgbColor.Create(128, 255, 0, 0); ArrowStyle = ArrowStyle.Create(); FontStyle = FontStyle.Create(); LineFixedLength = LineFixedLength.Create(); LineStyle = LineStyle.Create(); Style = ShapeStyle.Create("Default"); TextStyle = TextStyle.Create(); // Shapes Arc = ArcShape.Create(0, 0, Style, null); CubicBezier = CubicBezierShape.Create(0, 0, Style, null); Ellipse = EllipseShape.Create(0, 0, Style, null); Group = GroupShape.Create(Constants.DefaulGroupName); Image = ImageShape.Create(0, 0, Style, null, "key"); Line = LineShape.Create(0, 0, Style, null); Path = PathShape.Create(Style, null); Point = PointShape.Create(); QuadraticBezier = QuadraticBezierShape.Create(0, 0, Style, null); Rectangle = RectangleShape.Create(0, 0, Style, null); Text = TextShape.Create(0, 0, Style, null, "Text"); // Path ArcSegment = ArcSegment.Create(PointShape.Create(), PathSize.Create(), 180, true, SweepDirection.Clockwise, true, true); CubicBezierSegment = CubicBezierSegment.Create(PointShape.Create(), PointShape.Create(), PointShape.Create(), true, true); LineSegment = LineSegment.Create(PointShape.Create(), true, true); PathFigure = PathFigure.Create(PointShape.Create(), false, true); PathGeometry = PathGeometry.Create(ImmutableArray.Create <PathFigure>(), FillRule.EvenOdd); PathSize = PathSize.Create(); PolyCubicBezierSegment = PolyCubicBezierSegment.Create(ImmutableArray.Create <PointShape>(), true, true); PolyLineSegment = PolyLineSegment.Create(ImmutableArray.Create <PointShape>(), true, true); PolyQuadraticBezierSegment = PolyQuadraticBezierSegment.Create(ImmutableArray.Create <PointShape>(), true, true); QuadraticBezierSegment = QuadraticBezierSegment.Create(PointShape.Create(), PointShape.Create(), true, true); }
private void DrawVagueShapes(Graphics g, ImageShape shapeType, int R, int r, double scale, Color centerColor, Color middleColor, Color edgeColor, bool drawCenter) /* * 本函数用于绘制有一定模糊效果的图形 * 假定g已经定位于屏幕的中心 * shapeType代表绘制的是圆形、正方形还是三角形 * R代表所绘图形的中心与屏幕中心之间的距离 * r描述了所绘图形的清晰部分的“大小” * scale代表了模糊部分与清晰部分之间的比值 * centerColor代表了所绘图形的清晰部分的颜色 * middleColor和edgeColor代表了所绘图形的模糊部分的渐变颜色 * drawCenter表示是否需要绘制清晰部分;若等于false就代表不绘制清晰部分 */ { int r1, r2, r3; //外径、中径、内径 r1 = (int)(r * scale); if (shapeType == ImageShape.Triangle) { r2 = (int)(r * 1.2); r3 = (int)(r * 0.85); } else { r2 = (int)(r * 1.15); r3 = (int)(r * 0.9); } //首先绘制模糊部分 Rectangle rect = new Rectangle(); //辅助矩形 Point[] points = new Point[3]; //辅助点组 switch (shapeType) { case ImageShape.Circle: case ImageShape.Cube: InitRectangle(ref rect, R, r1); break; case ImageShape.Triangle: InitTriangle(ref points, R, r1); break; } GraphicsPath path = new GraphicsPath(); switch (shapeType) { case ImageShape.Circle: path.AddEllipse(rect); break; case ImageShape.Cube: path.AddRectangle(rect); break; case ImageShape.Triangle: path.AddPolygon(points); break; } //引入一个渐变画笔 PathGradientBrush pathBrush = new PathGradientBrush(path); pathBrush.CenterPoint = new PointF(R, 0); pathBrush.CenterColor = middleColor; pathBrush.SurroundColors = new Color[] { edgeColor }; //使用渐变画笔进行画图,实现“模糊”的效果 switch (shapeType) { case ImageShape.Circle: g.FillEllipse(pathBrush, rect); break; case ImageShape.Cube: g.FillRectangle(pathBrush, rect); break; case ImageShape.Triangle: g.FillPolygon(pathBrush, points); break; } //如果不需要绘制清晰部分,则直接退出本函数 if (drawCenter == false) { return; } //然后绘制清晰部分 switch (shapeType) { case ImageShape.Circle: InitRectangle(ref rect, R, r2); g.FillEllipse(new SolidBrush(Color.Black), rect); InitRectangle(ref rect, R, r3); g.FillEllipse(new SolidBrush(centerColor), rect); break; case ImageShape.Cube: InitRectangle(ref rect, R, r2); g.FillRectangle(new SolidBrush(Color.Black), rect); InitRectangle(ref rect, R, r3); g.FillRectangle(new SolidBrush(centerColor), rect); break; case ImageShape.Triangle: InitTriangle(ref points, R, r2); g.FillPolygon(new SolidBrush(Color.Black), points); InitTriangle(ref points, R, r3); g.FillPolygon(new SolidBrush(centerColor), points); break; } }