private DrawingGroup GetDrawingLayer(DrawingGroup drawingGroup) { DrawingGroup groupDrawing = null; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingGroup.Children) { var itemKey = SvgLink.GetKey(drawing); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return((DrawingGroup)drawing); } // If the drawing is a DrawingGroup, call the function recursively. if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType != SvgObjectType.Text) { var nextGroup = GetDrawingLayer(groupDrawing); if (nextGroup != groupDrawing) { itemKey = SvgLink.GetKey(nextGroup); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return(nextGroup); } } } } } return(drawingGroup); }
// Enumerate the drawings in the DrawingGroup. private void EnumDrawingGroup(DrawingGroup drawingGroup) { // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingGroup.Children) { string objectId = SvgObject.GetId(drawing); if (!string.IsNullOrWhiteSpace(objectId)) { _idMap[objectId] = drawing; } string objectName = (string)drawing.GetValue(FrameworkElement.NameProperty); if (!string.IsNullOrWhiteSpace(objectName)) { _idMap[objectName] = drawing; } string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { _guidMap[uniqueId] = drawing; } DrawingGroup groupDrawing = null; // If the drawing is a DrawingGroup, call the function recursively. if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType != SvgObjectType.Text) { EnumDrawingGroup(groupDrawing); } } } }
public void Visit(ISvgTextElement element) { Point position = GetCurrentTextPosition(element as SvgTextPositioningElement, new Point(0, 0)); Size spanSize; foreach (var child in element.ChildNodes) { Geometry geometry; Path shape; spanSize = new Size(0, 0); SvgTSpanElement tspan; Dom.Text simpleText; if (TryCast.Cast(child, out tspan)) { geometry = ConstructTextGeometry(tspan, tspan.InnerText, position, out spanSize); shape = WrapGeometry(geometry, tspan); shape.IsHitTestVisible = false; DisplayShape(shape, tspan); } else if (TryCast.Cast(child, out simpleText)) { geometry = ConstructTextGeometry(element as SvgTextBaseElement, simpleText.InnerText, position, out spanSize); shape = WrapGeometry(geometry, element); shape.IsHitTestVisible = false; DisplayShape(shape, element); } position.Offset(spanSize.Width, 0); } }
private bool HitTestDrawing(DrawingGroup group, Geometry geomDisplay, out Drawing hitDrawing, IntersectionDetail detail) { hitDrawing = null; var geomBounds = new RectangleGeometry(group.Bounds); if (geomBounds.FillContainsWithDetail(geomDisplay) == detail) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { hitDrawing = geometryDrawing; return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { hitDrawing = groupDrawing; return(true); } } if (HitTestDrawing(groupDrawing, geomDisplay, out hitDrawing, detail)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { hitDrawing = glyRunDrawing; return(true); } } } return(true); } return(false); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing) { hitDrawing = null; if (group.Bounds.Contains(pt)) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { hitDrawing = drawing; return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); //if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text) { hitDrawing = drawing; return(true); } if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { hitDrawing = glyRunDrawing; return(true); } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } } return(false); }
private bool HitTestDrawing(DrawingGroup group, Point pt) { if (group.Bounds.Contains(pt)) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { if (HitTestDrawing(groupDrawing, pt)) { return(true); } SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { return(true); } } } } return(false); }
//private Brush _testHitBrush; //private Brush _testHitBrushPen; //private Pen _testHitPen; //private GeometryDrawing _testHit; //private DrawingGroup _testHitGroup; private Drawing HitTest(Point pt) { if (_linkObjects == null) { return(null); } Point ptDisplay = _displayTransform.Transform(pt); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; //for (int i = 0; i < _linkObjects.Count; i++) for (int i = _linkObjects.Count - 1; i >= 0; i--) { Drawing drawing = _linkObjects[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, ptDisplay)) { foundDrawing = drawing; break; } } else if (TryCast.Cast(drawing, out groupDrawing)) { if (HitTestDrawing(groupDrawing, ptDisplay)) { foundDrawing = drawing; break; } else if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && groupDrawing.Bounds.Contains(ptDisplay)) { foundDrawing = drawing; break; } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, ptDisplay)) { foundDrawing = drawing; break; } } } //if (_testHit != null) //{ // if (_testHitBrush != null) // { // _testHit.Brush = _testHitBrush; // } // else if (_testHitPen != null && _testHitBrushPen != null) // { // _testHit.Pen.Brush = _testHitBrushPen; // } // _testHit = null; // _testHitPen = null; // _testHitBrush = null; //} //if (_testHitGroup != null) //{ // _testHitGroup.BitmapEffect = null; // _testHitGroup = null; //} //_testHit = foundDrawing as GeometryDrawing; //if (_testHit != null) //{ // _testHitBrush = _testHit.Brush; // _testHitPen = _testHit.Pen; // // Create and animate a Brush to set the button's Background. // SolidColorBrush animationBrush = new SolidColorBrush(); // animationBrush.Color = Colors.Blue; // ColorAnimation colorAnimation = new ColorAnimation(); // colorAnimation.From = Colors.Blue; // colorAnimation.To = Colors.Red; // colorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(1000)); // colorAnimation.AutoReverse = true; // colorAnimation.RepeatBehavior = RepeatBehavior.Forever; // if (_testHitBrush != null) // { // _testHit.Brush = animationBrush; // } // else if (_testHitPen != null) // { // _testHitBrushPen = _testHitPen.Brush; // _testHitPen.Brush = animationBrush; // } // // Apply the animation to the brush's Color property. // //animationBrush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); //} //else //{ // _testHitGroup = foundDrawing as DrawingGroup; // if (_testHitGroup != null) // { // //// Create a blur effect. // //BlurBitmapEffect blurEffect = new BlurBitmapEffect(); // //blurEffect.Radius = 3.0; // //// Apply it to the drawing group. // //_testHitGroup.BitmapEffect = blurEffect; // // Initialize a new OuterGlowBitmapEffect that will be applied // // to the TextBox. // OuterGlowBitmapEffect glowEffect = new OuterGlowBitmapEffect(); // // Set the size of the glow to 30 pixels. // glowEffect.GlowSize = 3; // // Set the color of the glow to blue. // Color glowColor = new Color(); // glowColor.ScA = 1; // glowColor.ScB = 0; // glowColor.ScG = 0; // glowColor.ScR = 1; // glowEffect.GlowColor = glowColor; // // Set the noise of the effect to the maximum possible (range 0-1). // glowEffect.Noise = 0; // // Set the Opacity of the effect to 75%. Note that the same effect // // could be done by setting the ScA property of the Color to 0.75. // glowEffect.Opacity = 0.5; // // Apply the bitmap effect to the TextBox. // _testHitGroup.BitmapEffect = glowEffect; // } //} return(foundDrawing); }
private bool HitTestDrawing(GeometryDrawing drawing, Point pt) { Pen pen = drawing.Pen; Brush brush = drawing.Brush; if (pen != null && brush == null) { if (drawing.Geometry.StrokeContains(pen, pt)) { return(true); } else { Geometry geometry = drawing.Geometry; EllipseGeometry ellipse = null; RectangleGeometry rectangle = null; PathGeometry path = null; if (TryCast.Cast(geometry, out ellipse)) { if (ellipse.FillContains(pt)) { return(true); } } else if (TryCast.Cast(geometry, out rectangle)) { if (rectangle.FillContains(pt)) { return(true); } } else if (TryCast.Cast(geometry, out path)) { PathFigureCollection pathFigures = path.Figures; int itemCount = pathFigures.Count; if (itemCount == 1) { if (pathFigures[0].IsClosed && path.FillContains(pt)) { return(true); } } else { for (int f = 0; f < itemCount; f++) { PathFigure pathFigure = pathFigures[f]; if (pathFigure.IsClosed) { PathFigureCollection testFigures = new PathFigureCollection(); testFigures.Add(pathFigure); PathGeometry testPath = new PathGeometry(); testPath.Figures = testFigures; if (testPath.FillContains(pt)) { return(true); } } } } } } } else if (brush != null && drawing.Geometry.FillContains(pt)) { return(true); } return(false); }
public static bool TryGetBrush(SvgStyleableElement element, string property, Rect bounds, Matrix transform, out Brush brush) { SvgPaint paint = new SvgPaint(element.GetComputedStyle(string.Empty).GetPropertyValue(property)); SvgPaint svgBrush; if (paint.PaintType == SvgPaintType.None) { brush = null; return(false); } if (paint.PaintType == SvgPaintType.CurrentColor) { svgBrush = new SvgPaint(element.GetComputedStyle(string.Empty).GetPropertyValue(CssConstants.PropColor)); } else { svgBrush = paint; } SvgPaintType paintType = svgBrush.PaintType; if (paintType == SvgPaintType.Uri || paintType == SvgPaintType.UriCurrentColor || paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor || paintType == SvgPaintType.UriRgbColorIccColor) { SvgStyleableElement fillNode = null; string absoluteUri = element.ResolveUri(svgBrush.Uri); if (element.Imported && element.ImportDocument != null && element.ImportNode != null) { // We need to determine whether the provided URI refers to element in the // original document or in the current document... SvgStyleableElement styleElm = element.ImportNode as SvgStyleableElement; if (styleElm != null) { string propertyValue = styleElm.GetComputedStyle(string.Empty).GetPropertyValue(property); if (!string.IsNullOrWhiteSpace(propertyValue)) { SvgPaint importFill = new SvgPaint(styleElm.GetComputedStyle(string.Empty).GetPropertyValue(property)); if (string.Equals(svgBrush.Uri, importFill.Uri, StringComparison.OrdinalIgnoreCase)) { fillNode = element.ImportDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement; } } } } else { fillNode = element.OwnerDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement; } if (fillNode != null) { SvgLinearGradientElement linearGradient; SvgRadialGradientElement radialGradient; SvgPatternElement pattern; if (TryCast.Cast(fillNode, out linearGradient)) { brush = ConstructBrush(linearGradient, bounds, transform); return(true); } if (TryCast.Cast(fillNode, out radialGradient)) { brush = ConstructBrush(radialGradient, bounds, transform); return(true); } if (TryCast.Cast(fillNode, out pattern)) { brush = ConstructBrush(pattern, bounds, transform); return(true); } } } Color solidColor; if (svgBrush == null || svgBrush.RgbColor == null || !TryConvertColor(svgBrush.RgbColor, out solidColor)) { brush = null; return(false); } brush = new SolidColorBrush(solidColor); brush.Opacity = GetOpacity(element, property); if (brush.CanFreeze) { brush.Freeze(); } return(true); }
private Drawing PerformHitTest(Rect rect, IntersectionDetail detail) { if (_svgDrawing == null) { return(null); } var rectDisplay = _displayTransform.TransformBounds(rect); var geomDisplay = new RectangleGeometry(rectDisplay); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out groupDrawing)) { if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } if (HitTestDrawing(groupDrawing, geomDisplay, out foundDrawing, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { foundDrawing = drawing; break; } } } return(foundDrawing); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing) { hitDrawing = null; bool isHit = false; if (group.Bounds.Contains(pt)) { var transform = group.Transform; if (transform != null) { var matrix = transform.Value; if (matrix != null && matrix.IsIdentity == false) { pt = transform.Inverse.Transform(pt); } } DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); //if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { hitDrawing = glyRunDrawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } } return(isHit); }
private bool HitTestDrawing(GeometryDrawing drawing, Point pt) { Pen pen = drawing.Pen; Brush brush = drawing.Brush; if (pen != null) { if (drawing.Geometry.StrokeContains(pen, pt)) { return(true); } Geometry geometry = drawing.Geometry; LineGeometry line = null; EllipseGeometry ellipse = null; RectangleGeometry rectangle = null; PathGeometry path = null; if (TryCast.Cast(geometry, out path)) { if (path.FillContains(pt, 1, ToleranceType.Absolute)) { return(true); } //PathFigureCollection pathFigures = path.Figures; //int itemCount = pathFigures.Count; //if (itemCount == 1) //{ // if (pathFigures[0].IsClosed && path.FillContains(pt)) // { // return true; // } //} //else //{ // for (int f = 0; f < itemCount; f++) // { // PathFigure pathFigure = pathFigures[f]; // if (pathFigure.IsClosed) // { // PathFigureCollection testFigures = new PathFigureCollection(); // testFigures.Add(pathFigure); // PathGeometry testPath = new PathGeometry(); // testPath.Figures = testFigures; // if (testPath.FillContains(pt)) // { // return true; // } // } // } //} } else if (TryCast.Cast(geometry, out line)) { if (line.FillContains(pt)) { return(true); } } else if (TryCast.Cast(geometry, out ellipse)) { if (ellipse.FillContains(pt)) { return(true); } } else if (TryCast.Cast(geometry, out rectangle)) { if (rectangle.FillContains(pt)) { return(true); } } } else if (brush != null && drawing.Geometry.FillContains(pt)) { return(true); } else if (drawing.Geometry.FillContains(pt)) { return(true); } return(false); }
private Drawing PerformHitTest(Point pt) { _hitGroup = null; if (_hitList == null) { _hitList = new SortedList <int, Drawing>(); } else if (_hitList.Count != 0) { _hitList.Clear(); } if (_svgDrawing == null) { return(null); } Point ptDisplay = _displayTransform.Transform(pt); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, ptDisplay)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { string uniqueId = SvgObject.GetUniqueId(geometryDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out groupDrawing)) { int orderNumber = SvgObject.GetOrder(drawing); if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && groupDrawing.Bounds.Contains(ptDisplay)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { foundDrawing = drawing; break; } } if (HitTestDrawing(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { string uniqueId = SvgObject.GetUniqueId(foundDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { //foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, ptDisplay)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { foundDrawing = drawing; break; } } } } if (_hitList.Count != 0) { return(_hitList.LastOrDefault().Value); } if (foundDrawing == null) { return(_hitGroup); } return(foundDrawing); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing, bool isText = false) { hitDrawing = null; bool isHit = false; if (!group.Bounds.Contains(pt)) { return(isHit); } var transform = group.Transform; if (transform != null && !transform.Value.IsIdentity) { pt = transform.Inverse.Transform(pt); } var groupHitPath = _hitPath; DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(drawing)); if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); isHit = false; } else { orderNumber = SvgObject.GetOrder(group); if (orderNumber >= 0) { _hitList[orderNumber] = group; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(group)); } if (!string.IsNullOrWhiteSpace(SvgObject.GetUniqueId(group))) { _hitGroup = group; } return(true); } } } else if (TryCast.Cast(drawing, out groupDrawing)) { _hitPath = groupHitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); SvgObjectType objectType = SvgObject.GetType(groupDrawing); // if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text && this.HitTestText(groupDrawing, pt, out hitDrawing)) // if (objectType == SvgObjectType.Text) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath; isHit = false; } else { return(true); } } else { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(hitDrawing)); var currentPath = _hitPath; try { if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { // int orderNumber = SvgObject.GetOrder(drawing); int orderNumber = SvgObject.GetOrder(hitDrawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(hitDrawing)); isHit = false; } else { orderNumber = SvgObject.GetOrder(groupDrawing); if (orderNumber >= 0) { _hitList[orderNumber] = groupDrawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); } return(true); } } } finally { _hitPath = currentPath; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); hitDrawing = glyRunDrawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); isHit = false; } else { return(true); } } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } return(isHit); }
private Drawing PerformHitTest(Point pt) { if (_svgDrawing == null) { return(null); } _hitGroup = null; if (_hitList == null) { _hitList = new SortedList <int, Drawing>(); _hitPaths = new SortedList <int, WpfHitPath>(); } else if (_hitList.Count != 0) { _hitList.Clear(); _hitPaths.Clear(); } var hitRootPath = new WpfHitPath(); _hitPath = hitRootPath; Point ptDisplay = _displayTransform.Transform(pt); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; //var isFound = false; //var drawingLayer = this.GetDrawingLayer(_svgDrawing, ref isFound); //System.Diagnostics.Trace.WriteLine("GetId: " + SvgObject.GetId(drawingLayer)); //System.Diagnostics.Trace.WriteLine("GetName: " + SvgObject.GetName(drawingLayer)); //System.Diagnostics.Trace.WriteLine("GetUniqueId: " + SvgObject.GetUniqueId(drawingLayer)); //DrawingCollection drawings = drawingLayer.Children; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; System.Diagnostics.Trace.WriteLine("GetId: " + SvgObject.GetId(drawing)); System.Diagnostics.Trace.WriteLine("GetName: " + SvgObject.GetName(drawing)); System.Diagnostics.Trace.WriteLine("GetUniqueId: " + SvgObject.GetUniqueId(drawing)); if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, ptDisplay)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); } else { string uniqueId = SvgObject.GetUniqueId(geometryDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out groupDrawing)) { //var ptSaved = ptDisplay; //var transform = groupDrawing.Transform; //if (transform != null && !transform.Value.IsIdentity) //{ // ptDisplay = transform.Inverse.Transform(ptDisplay); //} _hitPath = hitRootPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); int orderNumber = SvgObject.GetOrder(groupDrawing); //if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && // groupDrawing.Bounds.Contains(ptDisplay)) if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && this.HitTestText(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath; } else { foundDrawing = drawing; break; } } else { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); var currentPath = _hitPath; try { if (HitTestDrawing(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(foundDrawing)); } else { string uniqueId = SvgObject.GetUniqueId(foundDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { //foundDrawing = drawing; break; } } } } finally { _hitPath = currentPath; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, ptDisplay)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); } else { foundDrawing = drawing; break; } } } } if (_hitList.Count != 0) { var key = _hitList.LastOrDefault().Key; if (_hitPaths.ContainsKey(key)) { System.Diagnostics.Trace.WriteLine("Key Found: " + _hitPaths[key].Path); } return(_hitList.LastOrDefault().Value); } if (foundDrawing == null) { return(_hitGroup); } return(foundDrawing); }