// Enumerate the drawings in the DrawingGroup. public void EnumDrawingGroup(DrawingGroup drawingGroup) { DrawingCollection dc = drawingGroup.Children; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in dc) { // If the drawing is a DrawingGroup, call the function recursively. if (drawing.GetType() == typeof(DrawingGroup)) { EnumDrawingGroup((DrawingGroup)drawing); } else if (drawing.GetType() == typeof(GeometryDrawing)) { // Perform action based on drawing type. } else if (drawing.GetType() == typeof(ImageDrawing)) { // Perform action based on drawing type. } else if (drawing.GetType() == typeof(GlyphRunDrawing)) { // Perform action based on drawing type. } else if (drawing.GetType() == typeof(VideoDrawing)) { // Perform action based on drawing type. } } }
private void ResetGuidelineSet(DrawingGroup group) { if (_textElement == null || _textContext == null) { return; } if (_isTextPath) { return; } DrawingCollection drawings = group.Children; int itemCount = drawings.Count; for (int i = 0; i < itemCount; i++) { DrawingGroup childGroup = drawings[i] as DrawingGroup; if (childGroup != null) { childGroup.GuidelineSet = null; ResetGuidelineSet(childGroup); } } }
//private void Draw(DrawingGroup group) //{ // DrawingVisual drawingVisual = new DrawingVisual(); // DrawingContext drawingContext = drawingVisual.RenderOpen(); // if (_offsetTransform != null) // { // drawingContext.PushTransform(_offsetTransform); // } // drawingContext.DrawDrawing(group); // if (_offsetTransform != null) // { // drawingContext.Pop(); // } // drawingContext.DrawDrawing(group); // drawingVisual.Opacity = group.Opacity; // Transform transform = group.Transform; // if (transform != null) // { // drawingVisual.Transform = transform; // } // Geometry clipGeometry = group.ClipGeometry; // if (clipGeometry != null) // { // drawingVisual.Clip = clipGeometry; // } // drawingContext.Close(); // this.AddVisual(drawingVisual); // if (_drawForInteractivity) // { // this.EnumerateDrawings(group); // } //} private void EnumerateDrawings(DrawingGroup group) { if (group == null || group == _linksDrawing) { return; } DrawingCollection drawings = group.Children; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; DrawingGroup childGroup = drawing as DrawingGroup; if (childGroup != null) { SvgObjectType objectType = SvgObject.GetType(childGroup); if (objectType == SvgObjectType.Link) { InsertLinkDrawing(childGroup); } else if (objectType == SvgObjectType.Text) { InsertTextDrawing(childGroup); } else { EnumerateDrawings(childGroup); } } else { InsertDrawing(drawing); } } }
/// Enumerate the drawings in the DrawingGroup. static public void EnumDrawingGroup(DrawingGroup drawingGroup) { DrawingCollection dc = drawingGroup.Children; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in dc) { // If the drawing is a DrawingGroup, call the function recursively. if (drawing is DrawingGroup group) { EnumDrawingGroup(group); } else if (drawing is GeometryDrawing) { // Perform action based on drawing type. } else if (drawing is ImageDrawing) { // Perform action based on drawing type. } else if (drawing is GlyphRunDrawing) { // Perform action based on drawing type. } else if (drawing is VideoDrawing) { // Perform action based on drawing type. } } }
public static DrawingCollection GetCollection() { DrawingCollection tempList = null; using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("usp_GetDrawing", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection); myConnection.Open(); using (SqlDataReader myReader = myCommand.ExecuteReader()) { if (myReader.HasRows) { tempList = new DrawingCollection(); while (myReader.Read()) { tempList.Add(FillDataRecord(myReader)); } } myReader.Close(); } } } return(tempList); }
private void LoadLayerDiagrams(DrawingGroup layerGroup) { this.UnloadDiagrams(); DrawingCollection drawings = layerGroup.Children; DrawingGroup drawGroup = null; GeometryDrawing drawGeometry = null; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; if (TryCast(drawing, out drawGroup)) { string groupName = SvgLink.GetKey(drawGroup); if (string.IsNullOrWhiteSpace(groupName)) { groupName = SvgObject.GetId(drawGroup); } //string groupName = SvgObject.GetName(childGroup); if (string.IsNullOrWhiteSpace(groupName)) { LoadLayerGroup(drawGroup); } else { SvgObjectType elementType = SvgObject.GetType(drawGroup); if (elementType == SvgObjectType.Text) { this.AddTextDrawing(drawGroup, groupName); } else { if (drawGroup.Children != null && drawGroup.Children.Count == 1) { this.AddDrawing(drawGroup, groupName); } else { //throw new InvalidOperationException( // String.Format("Error: The link group is in error - {0}", groupName)); } } } } else if (TryCast(drawing, out drawGeometry)) { this.AddGeometryDrawing(drawGeometry); } } if (_drawingCanvas != null) { _displayTransform = _drawingCanvas.DisplayTransform; } }
private void BindDrawingList() { DrawingCollection drawingList = new DrawingCollection(); drawingList = DrawingDAL.GetCollection(); rptDrawingList.DataSource = drawingList; rptDrawingList.DataBind(); }
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 void LoadLayerGroup(DrawingGroup group) { DrawingCollection drawings = group.Children; DrawingGroup drawGroup = null; GeometryDrawing drawGeometry = null; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; if (TryCast(drawing, out drawGroup)) { string groupName = SvgLink.GetKey(drawGroup); if (string.IsNullOrWhiteSpace(groupName)) { groupName = SvgObject.GetId(drawGroup); } //string groupName = childGroup.GetValue(FrameworkElement.NameProperty) as string; if (string.IsNullOrWhiteSpace(groupName)) { LoadLayerGroup(drawGroup); } else { SvgObjectType elementType = SvgObject.GetType(drawGroup); if (elementType == SvgObjectType.Text) { this.AddTextDrawing(drawGroup, groupName); } else { if (drawGroup.Children != null && drawGroup.Children.Count == 1) { this.AddDrawing(drawGroup, groupName); } else { //throw new InvalidOperationException( // String.Format("Error: The link group is in error - {0}", groupName)); } } } } else if (TryCast(drawing, out drawGeometry)) { this.AddGeometryDrawing(drawGeometry); } } }
private void AddTextDrawing(DrawingGroup group, string name) { bool isHyperlink = false; if (name == "x11201_1_") { isHyperlink = true; } SolidColorBrush textBrush = null; if (name.StartsWith("XMLID_", StringComparison.OrdinalIgnoreCase)) { textBrush = new SolidColorBrush(_colorText); } else { isHyperlink = true; textBrush = new SolidColorBrush(_colorLink); } string brushName = name + "_Brush"; SvgObject.SetName(textBrush, brushName); DrawingCollection drawings = group.Children; int itemCount = drawings != null ? drawings.Count : 0; for (int i = 0; i < itemCount; i++) { DrawingGroup drawing = drawings[i] as DrawingGroup; if (drawing != null) { for (int j = 0; j < drawing.Children.Count; j++) { GlyphRunDrawing glyphDrawing = drawing.Children[j] as GlyphRunDrawing; if (glyphDrawing != null) { glyphDrawing.ForegroundBrush = textBrush; } } } } if (isHyperlink) { _visualBrushes[name] = textBrush; _linkObjects.Add(group); } }
private void BuildGlypeTree(List <GlyphRun> textObjects, System.Windows.Media.Drawing drawing) { if (drawing is GlyphRunDrawing) { textObjects.Add((drawing as GlyphRunDrawing).GlyphRun); } else if (drawing is DrawingGroup) { DrawingCollection children = (drawing as DrawingGroup).Children; for (int i = 0; i < children.Count; i++) { BuildGlypeTree(textObjects, children[i]); } } }
public void RenderDiagrams(DrawingGroup renderedGroup) { DrawingCollection drawings = renderedGroup.Children; int linkIndex = -1; int drawIndex = -1; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; //string drawingName = SvgObject.GetName(drawing); string drawingName = SvgLink.GetKey(drawing); if (!string.IsNullOrWhiteSpace(drawingName) && string.Equals(drawingName, SvgObject.DrawLayer)) { drawIndex = i; } else if (!string.IsNullOrWhiteSpace(drawingName) && string.Equals(drawingName, SvgObject.LinksLayer)) { linkIndex = i; } } DrawingGroup mainGroups = null; if (drawIndex >= 0) { mainGroups = drawings[drawIndex] as DrawingGroup; } DrawingGroup linkGroups = null; if (linkIndex >= 0) { linkGroups = drawings[linkIndex] as DrawingGroup; } this.LoadDiagrams(renderedGroup, linkGroups, mainGroups); if (linkGroups != null) { _animationCanvas.LoadDiagrams(linkGroups, renderedGroup); } _bounds = _wholeDrawing.Bounds; this.InvalidateMeasure(); this.InvalidateVisual(); }
private static void ResetGuidelineSet(DrawingGroup group) { DrawingCollection drawings = group.Children; int itemCount = drawings.Count; for (int i = 0; i < itemCount; i++) { DrawingGroup childGroup = drawings[i] as DrawingGroup; if (childGroup != null) { childGroup.GuidelineSet = null; ResetGuidelineSet(childGroup); } } }
public void RenderDiagrams(DrawingGroup renderedGroup) { DrawingCollection drawings = renderedGroup.Children; int linkIndex = -1; int drawIndex = -1; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; //string drawingName = drawing.GetValue(FrameworkElement.NameProperty) as string; string drawingName = SvgLink.GetKey(drawing); if (!String.IsNullOrEmpty(drawingName) && String.Equals(drawingName, SvgObject.DrawLayer)) { drawIndex = i; } else if (!String.IsNullOrEmpty(drawingName) && String.Equals(drawingName, SvgObject.LinksLayer)) { linkIndex = i; } } DrawingGroup mainGroups = null; if (drawIndex >= 0) { mainGroups = drawings[drawIndex] as DrawingGroup; } DrawingGroup linkGroups = null; if (linkIndex >= 0) { linkGroups = drawings[linkIndex] as DrawingGroup; } this.LoadDiagrams(renderedGroup, linkGroups, mainGroups); if (linkGroups != null) { _animationCanvas.LoadDiagrams(linkGroups, renderedGroup); } this.InvalidateMeasure(); this.InvalidateVisual(); }
private static void ExtractGeometry(DrawingGroup group, GeometryCollection geomColl) { if (geomColl == null) { return; } DrawingCollection drawings = group.Children; int textItem = drawings.Count; for (int i = 0; i < textItem; i++) { Drawing drawing = drawings[i]; GeometryDrawing aDrawing = drawing as GeometryDrawing; if (aDrawing != null) { Geometry aGeometry = aDrawing.Geometry; if (aGeometry != null) { GeometryGroup geomGroup = aGeometry as GeometryGroup; if (geomGroup != null) { GeometryCollection children = geomGroup.Children; for (int j = 0; j < children.Count; j++) { geomColl.Add(children[j]); } } else { geomColl.Add(aGeometry); } } } else { DrawingGroup innerGroup = drawing as DrawingGroup; if (innerGroup != null) { ExtractGeometry(innerGroup, geomColl); } } } }
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); }
public static void CombineGeometries(DrawingGroup drawingGroup, GeometryCombineMode combineMode, ref CombinedGeometry combinedGeometry) { if (combinedGeometry == null) { combinedGeometry = new CombinedGeometry(); } DrawingCollection drawingCollection = drawingGroup.Children; foreach (Drawing drawing in drawingCollection) { if (drawing is DrawingGroup) { CombineGeometries((DrawingGroup)drawing, combineMode, ref combinedGeometry); } else if (drawing is GeometryDrawing) { GeometryDrawing geoDrawing = drawing as GeometryDrawing; combinedGeometry = new CombinedGeometry(combineMode, combinedGeometry, geoDrawing.Geometry); } } }
// Enumerate the drawings in the DrawingGroup. static public void EnumDrawingGroup(DrawingGroup drawingGroup, Point pt) { DrawingCollection drawingCollection = drawingGroup.Children; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingCollection) { // If the drawing is a DrawingGroup, call the function recursively. if (drawing.GetType() == typeof(DrawingGroup)) { EnumDrawingGroup((DrawingGroup)drawing, pt); } else if (drawing.GetType() == typeof(GeometryDrawing)) { // Determine whether the hit test point falls within the geometry. if (((GeometryDrawing)drawing).Geometry.FillContains(pt)) { // Perform action based on hit test on geometry. } } } }
protected override Size ArrangeOverride(Size arrangeBounds) { Debug.Print("Arrange"); var columns = (int)(arrangeBounds.Width / m_tileSize); var rows = (int)(arrangeBounds.Height / m_tileSize); if (columns != m_columns || rows != m_rows) { m_columns = columns; m_rows = rows; var bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Undefined, Colors.Black, false); var drawingCollection = new DrawingCollection(); for (int y = 0; y < m_rows; ++y) { for (int x = 0; x < m_columns; ++x) { var imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize), new Size(m_tileSize, m_tileSize))); drawingCollection.Add(imageDrawing); imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize), new Size(m_tileSize, m_tileSize))); drawingCollection.Add(imageDrawing); } } var drawingGroup = new DrawingGroup(); drawingGroup.Children = drawingCollection; m_drawing = drawingGroup; } Render(); return(base.ArrangeOverride(arrangeBounds)); }
// Enumerate the drawings in the DrawingGroup. private void EnumDrawingGroup(DrawingGroup drawingGroup) { DrawingCollection dc = drawingGroup.Children; DrawingGroup groupDrawing = null; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in dc) { string objectId = SvgObject.GetId(drawing); if (!string.IsNullOrWhiteSpace(objectId)) { _idMap.Add(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.Add(uniqueId, 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) { EnumDrawingGroup(groupDrawing); } } } }
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 void RenderPath(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } var parentNode = _svgElement.ParentNode; // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(parentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; //string sVisibility = styleElm.GetPropertyValue("visibility"); //string sDisplay = styleElm.GetPropertyValue("display"); //if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) //{ // return; //} DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); string elementId = this.GetElementName(); string elementClass = this.GetElementClass(); GeometryDrawing drawing = null; if (geometry == null || geometry.IsEmpty()) { return; } var bounds = geometry.Bounds; if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal)) { _isLineSegment = true; } else if (string.Equals(_svgElement.LocalName, "rect", StringComparison.Ordinal)) { _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0); } else if (string.Equals(_svgElement.LocalName, "path", StringComparison.Ordinal)) { _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0); } context.UpdateBounds(geometry.Bounds); // SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry, _setBrushOpacity); bool isFillTransmable = fillPaint.IsFillTransformable; WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(geometry, _setBrushOpacity); // By the SVG Specifications: // Keyword 'objectBoundingBox' should not be used when the geometry of the applicable // element has no width or no height, such as the case of a horizontal or vertical line, // even when the line has actual thickness when viewed due to having a non-zero stroke // width since stroke width is ignored for bounding box calculations. When the geometry // of the applicable element has no width or height and 'objectBoundingBox' is specified, // then the given effect (e.g., a gradient) will be ignored. if (pen != null && _isLineSegment && strokePaint.FillType == WpfFillType.Gradient) { WpfGradientFill gradientFill = (WpfGradientFill)strokePaint.PaintServer; if (gradientFill.IsUserSpace == false) { bool invalidGrad = false; if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal)) { LineGeometry lineGeometry = geometry as LineGeometry; if (lineGeometry != null) { invalidGrad = SvgObject.IsEqual(lineGeometry.EndPoint.X, lineGeometry.StartPoint.X) || SvgObject.IsEqual(lineGeometry.EndPoint.Y, lineGeometry.StartPoint.Y); } } else { invalidGrad = true; } if (invalidGrad) { // Brush is not likely inherited, we need to support fallback too WpfSvgPaint fallbackPaint = strokePaint.WpfFallback; if (fallbackPaint != null) { pen.Brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity); } else { var scopePaint = strokePaint.GetScopeStroke(); if (scopePaint != null) { if (scopePaint != strokePaint) { pen.Brush = scopePaint.GetBrush(geometry, _setBrushOpacity); } else { pen.Brush = null; } } else { pen.Brush = null; } } } } } if (_paintContext != null) { _paintContext.Fill = fillPaint; _paintContext.Stroke = strokePaint; _paintContext.Tag = geometry; } if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null && isFillTransmable) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } if (pen != null && pen.Brush != null) { Transform brushTransform = pen.Brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { pen.Brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); pen.Brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } drawing = new GeometryDrawing(brush, pen, geometry); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(drawing, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(drawing, elementClass); } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { DrawingBrush drawingBrush = (DrawingBrush)maskBrush; SvgUnitType maskUnits = this.MaskUnits; SvgUnitType maskContentUnits = this.MaskContentUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } if (maskContentUnits == SvgUnitType.ObjectBoundingBox) { TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y); transformGroup.Children.Add(translateTransform); Matrix scaleMatrix = new Matrix(); Matrix translateMatrix = new Matrix(); scaleMatrix.Scale(drawingBounds.Width, drawingBounds.Height); translateMatrix.Translate(drawingBounds.X, drawingBounds.Y); Matrix matrix = Matrix.Multiply(scaleMatrix, translateMatrix); //maskBrush.Transform = transformGroup; maskBrush.Transform = new MatrixTransform(matrix); } else { drawingBrush.Viewbox = drawingBounds; drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Stretch = Stretch.Uniform; drawingBrush.Viewport = drawingBounds; drawingBrush.ViewportUnits = BrushMappingMode.Absolute; } } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } // If this is not the child of a "marker", then try rendering a marker... if (!string.Equals(parentNode.LocalName, "marker")) { RenderMarkers(renderer, styleElm, context); } // Register this drawing with the Drawing-Document... if (drawing != null) { this.Rendered(drawing); } }
private void RenderPath(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } var parentNode = _svgElement.ParentNode; // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(parentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; string sVisibility = styleElm.GetPropertyValue("visibility"); string sDisplay = styleElm.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); string elementId = this.GetElementName(); string elementClass = this.GetElementClass(); if (geometry != null && !geometry.IsEmpty()) { context.UpdateBounds(geometry.Bounds); // SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry); bool isFillTransmable = fillPaint.IsFillTransformable; WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(geometry); if (_paintContext != null) { _paintContext.Fill = fillPaint; _paintContext.Stroke = strokePaint; _paintContext.Tag = geometry; } if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null && isFillTransmable) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } if (pen != null && pen.Brush != null) { Transform brushTransform = pen.Brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { pen.Brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); pen.Brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } GeometryDrawing drawing = new GeometryDrawing(brush, pen, geometry); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(drawing, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(drawing, elementClass); } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { DrawingBrush drawingBrush = (DrawingBrush)maskBrush; SvgUnitType maskUnits = this.MaskUnits; SvgUnitType maskContentUnits = this.MaskContentUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } if (maskContentUnits == SvgUnitType.ObjectBoundingBox) { TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y); transformGroup.Children.Add(translateTransform); Matrix scaleMatrix = new Matrix(); Matrix translateMatrix = new Matrix(); scaleMatrix.Scale(drawingBounds.Width, drawingBounds.Height); translateMatrix.Translate(drawingBounds.X, drawingBounds.Y); Matrix matrix = Matrix.Multiply(scaleMatrix, translateMatrix); //maskBrush.Transform = transformGroup; maskBrush.Transform = new MatrixTransform(matrix); } else { drawingBrush.Viewbox = drawingBounds; drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Stretch = Stretch.Uniform; drawingBrush.Viewport = drawingBounds; drawingBrush.ViewportUnits = BrushMappingMode.Absolute; } } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } } // If this is not the child of a "marker", then try rendering a marker... if (!string.Equals(parentNode.LocalName, "marker")) { RenderMarkers(renderer, styleElm, context); } }
internal void WriteWrokSheetDrawing(DrawingCollection drawingCollection) { drawingCollection.DrawingUri = this.Context.Package.GetNewUri("/xl/drawings/drawing{0}.xml"); PackagePart wrokSheetDrawingPart = this.Context.Package.CreatePart(drawingCollection.DrawingUri, ExcelCommon.ContentType_sheetDrawing, drawingCollection._WorkSheet.WorkBook.Compression); PackageRelationship drawingRelationship = this.Context.Package.GetPart(drawingCollection._WorkSheet.SheetUri).CreateRelationship(PackUriHelper.GetRelativeUri(drawingCollection._WorkSheet.SheetUri, drawingCollection.DrawingUri), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/drawing"); drawingCollection.RelationshipID = drawingRelationship.Id; XDocument sheetDrawingDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); XElement root = new XElement(XName.Get("wsDr", ExcelCommon.Schema_SheetDrawings), new XAttribute(XNamespace.Xmlns + "xdr", ExcelCommon.Schema_SheetDrawings), new XAttribute(XNamespace.Xmlns + "a", ExcelCommon.Schema_Drawings)); WriteWrokSheetDrawing_Content(drawingCollection, root, wrokSheetDrawingPart); sheetDrawingDoc.Add(root); using (Stream stream = wrokSheetDrawingPart.GetStream(FileMode.Create, FileAccess.Write)) { sheetDrawingDoc.Save(stream); stream.Flush(); } }
private void WriteWrokSheetDrawing_Content(DrawingCollection drawingCollection, XElement root, PackagePart wrokSheetDrawingPart) { int index = 1; foreach (ExcelDrawing drawing in drawingCollection) { XElement rootNode = new XElement(XName.Get("twoCellAnchor", ExcelCommon.Schema_SheetDrawings)); if (drawing.EditAs != ExcelEditAs.TwoCell) { string strDra = drawing.EditAs.ToString(); if (string.IsNullOrEmpty(strDra) == false) rootNode.Add(new XAttribute(XName.Get("editAs"), strDra.Substring(0, 1).ToLower() + strDra.Substring(1, strDra.Length - 1))); } WriteWrokSheetDrawing_Content_DrawingPosition("from", drawing.From, rootNode); WriteWrokSheetDrawing_Content_DrawingPosition("to", drawing.To, rootNode); //todo: 图表 if (drawing is ExcelChart) rootNode.Add(WriteWorkSheetDrawing_Content_graphicFrame(drawing as ExcelChart, drawingCollection, wrokSheetDrawingPart, index)); else if (drawing is ExcelPicture) rootNode.Add(WriteWrokSheetDrawing_Content_pic(drawing as ExcelPicture, drawingCollection, wrokSheetDrawingPart, index)); XElement clientDataNode = new XElement(XName.Get("clientData", ExcelCommon.Schema_SheetDrawings)); if (drawing.Locked) clientDataNode.Add(new XAttribute(XName.Get("fLocksWithSheet"), 1)); if (drawing.Print) clientDataNode.Add(new XAttribute(XName.Get("fPrintsWithSheet"), 1)); rootNode.Add(clientDataNode); root.Add(rootNode); } }
public override void RenderText(SvgTextContentElement element, ref Point ctp, string text, double rotate, WpfTextPlacement placement) { if (string.IsNullOrWhiteSpace(text)) { return; } int vertOrientation = -1; int horzOrientation = -1; string orientationText = element.GetPropertyValue("glyph-orientation-vertical"); if (!string.IsNullOrWhiteSpace(orientationText)) { double orientationValue = 0; if (double.TryParse(orientationText, out orientationValue)) { vertOrientation = (int)orientationValue; } } orientationText = element.GetPropertyValue("glyph-orientation-horizontal"); if (!string.IsNullOrWhiteSpace(orientationText)) { double orientationValue = 0; if (double.TryParse(orientationText, out orientationValue)) { horzOrientation = (int)orientationValue; } } Point startPoint = ctp; IList <WpfTextRun> textRunList = WpfTextRun.BreakWords(text, vertOrientation, horzOrientation); for (int tr = 0; tr < textRunList.Count; tr++) { // For unknown reasons, FormattedText will split a text like "-70%" into two parts "-" // and "70%". We provide a shift to account for the split... double baselineShiftX = 0; double baselineShiftY = 0; WpfTextRun textRun = textRunList[tr]; DrawingGroup verticalGroup = new DrawingGroup(); DrawingContext verticalContext = verticalGroup.Open(); DrawingContext currentContext = _drawContext; _drawContext = verticalContext; this.DrawSingleLineText(element, ref ctp, textRun, rotate, placement); verticalContext.Close(); _drawContext = currentContext; if (verticalGroup.Children.Count == 1) { DrawingGroup textGroup = verticalGroup.Children[0] as DrawingGroup; if (textGroup != null) { verticalGroup = textGroup; } } string runText = textRun.Text; int charCount = runText.Length; double totalHeight = 0; DrawingCollection drawings = verticalGroup.Children; int itemCount = drawings != null ? drawings.Count : 0; for (int i = 0; i < itemCount; i++) { Drawing textDrawing = drawings[i]; DrawingGroup textGroup = textDrawing as DrawingGroup; if (vertOrientation == -1) { if (textGroup != null) { for (int j = 0; j < textGroup.Children.Count; j++) { GlyphRunDrawing glyphDrawing = textGroup.Children[j] as GlyphRunDrawing; if (glyphDrawing != null) { if (textRun.IsLatin) { GlyphRun glyphRun = glyphDrawing.GlyphRun; IList <ushort> glyphIndices = glyphRun.GlyphIndices; IDictionary <ushort, double> allGlyphWeights = glyphRun.GlyphTypeface.AdvanceWidths; double lastAdvanceWeight = allGlyphWeights[glyphIndices[glyphIndices.Count - 1]] * glyphRun.FontRenderingEmSize; totalHeight += glyphRun.ComputeAlignmentBox().Width + lastAdvanceWeight / 2d; } else { totalHeight += ChangeGlyphOrientation(glyphDrawing, baselineShiftX, baselineShiftY, false); } } } } else { GlyphRunDrawing glyphDrawing = textDrawing as GlyphRunDrawing; if (glyphDrawing != null) { if (textRun.IsLatin) { GlyphRun glyphRun = glyphDrawing.GlyphRun; IList <UInt16> glyphIndices = glyphRun.GlyphIndices; IDictionary <ushort, double> allGlyphWeights = glyphRun.GlyphTypeface.AdvanceWidths; double lastAdvanceWeight = allGlyphWeights[glyphIndices[glyphIndices.Count - 1]] * glyphRun.FontRenderingEmSize; totalHeight += glyphRun.ComputeAlignmentBox().Width + lastAdvanceWeight / 2d; } else { totalHeight += ChangeGlyphOrientation(glyphDrawing, baselineShiftX, baselineShiftY, false); } } } } else if (vertOrientation == 0) { if (textGroup != null) { for (int j = 0; j < textGroup.Children.Count; j++) { GlyphRunDrawing glyphDrawing = textGroup.Children[j] as GlyphRunDrawing; if (glyphDrawing != null) { baselineShiftX = ChangeGlyphOrientation(glyphDrawing, baselineShiftX, baselineShiftY, textRun.IsLatin); totalHeight += baselineShiftX; } } } else { GlyphRunDrawing glyphDrawing = textDrawing as GlyphRunDrawing; if (textDrawing != null) { totalHeight += ChangeGlyphOrientation(glyphDrawing, baselineShiftX, baselineShiftY, textRun.IsLatin); } } } else { throw new NotImplementedException(); } } if (!this.IsMeasuring) { _drawContext.DrawDrawing(verticalGroup); } if (tr < textRunList.Count) { ctp.X = startPoint.X; ctp.Y = startPoint.Y + totalHeight; startPoint.Y += totalHeight; } } }
internal void ReadWrokSheetDrawings(DrawingCollection target, XElement targetElement, ExcelLoadContext context) { IEnumerable<XElement> childNodes = targetElement.Elements(XName.Get("twoCellAnchor", ExcelCommon.Schema_SheetDrawings)); ExcelDrawing drTarget = null; foreach (XElement xnode in childNodes) { XElement childNode = xnode.Element(XName.Get("sp", ExcelCommon.Schema_SheetDrawings)); if (childNode != null) { //return new Shape(target); } childNode = xnode.Element(XName.Get("pic", ExcelCommon.Schema_SheetDrawings)); if (childNode != null) { ExcelPicture drPictureTarget = new ExcelPicture(target._WorkSheet); ReadWrokSheetDrawings_DrawingPic(drPictureTarget, childNode, target.DrawingUri); drTarget = drPictureTarget; } childNode = xnode.Element(XName.Get("graphicFrame", ExcelCommon.Schema_SheetDrawings)); if (childNode != null) { string rId = xnode.Element(XName.Get("graphicFrame", ExcelCommon.Schema_SheetDrawings)).Element(XName.Get("graphic", ExcelCommon.Schema_Drawings)).Element(XName.Get("graphicData", ExcelCommon.Schema_Drawings)).Element(XName.Get("chart", ExcelCommon.Schema_Chart)).LastAttribute.Value; PackageRelationship drawingsRelation = context.Package.GetPart(target.DrawingUri).GetRelationship(rId); Uri chartUri = PackUriHelper.ResolvePartUri(drawingsRelation.SourceUri, drawingsRelation.TargetUri); XElement drawingsElement = context.Package.GetXElementFromUri(chartUri); string chartType = ((XElement)(drawingsElement.Element(XName.Get("chart", ExcelCommon.Schema_Chart)).Element(XName.Get("plotArea", ExcelCommon.Schema_Chart)).Element(XName.Get("layout", ExcelCommon.Schema_Chart)).NextNode)).Name.LocalName; XElement element = childNode.Element(XName.Get("nvGraphicFramePr", ExcelCommon.Schema_SheetDrawings)).Element(XName.Get("cNvPr", ExcelCommon.Schema_SheetDrawings)); if (element != null) { string chartName = element.Attribute(XName.Get("name")).Value; ExcelChartType chartTypeEnum; Enum.TryParse(chartType.Replace("Chart", string.Empty), true, out chartTypeEnum); ExcelChart chart = target.AddChart(chartName, chartTypeEnum); chart.DrawingUri = target.DrawingUri; chart.RelationshipID = rId; ((IPersistable)chart).Load(context); drTarget = chart; } } if (drTarget != null) { ReadWrokSheetDrawings_Attribute(drTarget, xnode); ReadWrokSheetDrawings_clientData(drTarget, xnode); ReadWrokSheetDrawings_Common_Position(drTarget, xnode); } } }
protected override Size ArrangeOverride(Size arrangeBounds) { Debug.Print("Arrange"); var columns = (int)(arrangeBounds.Width / m_tileSize); var rows = (int)(arrangeBounds.Height / m_tileSize); if (columns != m_columns || rows != m_rows) { m_columns = columns; m_rows = rows; var bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Undefined, Colors.Black, false); var drawingCollection = new DrawingCollection(); for (int y = 0; y < m_rows; ++y) { for (int x = 0; x < m_columns; ++x) { var imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize), new Size(m_tileSize, m_tileSize))); drawingCollection.Add(imageDrawing); imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize), new Size(m_tileSize, m_tileSize))); drawingCollection.Add(imageDrawing); } } var drawingGroup = new DrawingGroup(); drawingGroup.Children = drawingCollection; m_drawing = drawingGroup; } Render(); return base.ArrangeOverride(arrangeBounds); }
private XElement WriteWrokSheetDrawing_Content_pic(ExcelPicture pic, DrawingCollection drawingCollection, PackagePart wrokSheetDrawingPart, int index) { XElement picNode = new XElement(XName.Get("pic", ExcelCommon.Schema_SheetDrawings)); #region "nvPicPr" XElement nvPicPrNode = new XElement(XName.Get("nvPicPr", ExcelCommon.Schema_SheetDrawings)); XElement cNvPrNode = new XElement(XName.Get("cNvPr", ExcelCommon.Schema_SheetDrawings), new XAttribute(XName.Get("id"), (index + 2).ToString())); if (string.IsNullOrEmpty(pic.Name)) cNvPrNode.Add(new XAttribute(XName.Get("name"), string.Format("图片 {0}", index))); else cNvPrNode.Add(new XAttribute(XName.Get("name"), pic.Name)); nvPicPrNode.Add(cNvPrNode); XElement cNvPicPrNode = new XElement(XName.Get("cNvPicPr", ExcelCommon.Schema_SheetDrawings)); cNvPicPrNode.Add(new XElement(XName.Get("picLocks", ExcelCommon.Schema_Drawings), new XAttribute("noChangeAspect", 1))); nvPicPrNode.Add(cNvPicPrNode); picNode.Add(nvPicPrNode); #endregion "nvPicPr" #region "blipFill" XElement blipFillNode = new XElement(XName.Get("blipFill", ExcelCommon.Schema_SheetDrawings)); XElement blipNode = new XElement(XName.Get("blip", ExcelCommon.Schema_Drawings)); blipNode.Add(new XAttribute(XName.Get("R", XNamespace.Xmlns.NamespaceName), ExcelCommon.Schema_Relationships)); ExcelImageInfo currentImage = SavePicture(pic.Name, pic.ImageFormat, pic.Image, pic.ContentType); if (this.Context.HashImageRelationships.ContainsKey(currentImage.Hash)) blipNode.Add(new XAttribute(XName.Get("embed", ExcelCommon.Schema_Relationships), this.Context.HashImageRelationships[currentImage.Hash])); else { PackageRelationship picRelation = wrokSheetDrawingPart.CreateRelationship(PackUriHelper.GetRelativeUri(drawingCollection.DrawingUri, currentImage.Uri), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/image"); blipNode.Add(new XAttribute(XName.Get("embed", ExcelCommon.Schema_Relationships), picRelation.Id)); this.Context.HashImageRelationships.Add(currentImage.Hash, picRelation.Id); } blipNode.Add(new XAttribute(XName.Get("cstate"), "print")); blipFillNode.Add(blipNode); XElement stretchNode = new XElement(XName.Get("stretch", ExcelCommon.Schema_Drawings), new XElement(XName.Get("fillRect", ExcelCommon.Schema_Drawings))); blipFillNode.Add(stretchNode); picNode.Add(blipFillNode); #endregion #region "spPr" XElement spPrNode = new XElement(XName.Get("spPr", ExcelCommon.Schema_SheetDrawings), new XElement(XName.Get("xfrm", ExcelCommon.Schema_Drawings), new XElement(XName.Get("off", ExcelCommon.Schema_Drawings), new XAttribute("x", 0), new XAttribute("y", 0)), new XElement(XName.Get("ext", ExcelCommon.Schema_Drawings), new XAttribute("cx", 0), new XAttribute("cy", 0))), new XElement(XName.Get("prstGeom", ExcelCommon.Schema_Drawings), new XAttribute("prst", "rect"), new XElement(XName.Get("avLst", ExcelCommon.Schema_Drawings)))); if (pic._Fill != null) WriteWrokSheetDrawing_pic_solidFill(pic._Fill, spPrNode); if (pic._Border != null) WriteWrokSheetDrawing_pic_ln(pic._Border, spPrNode); picNode.Add(spPrNode); #endregion return picNode; }
/// <summary> /// Called by a DrawingContext returned from Open or Append when the content /// created by it needs to be committed (because DrawingContext.Close/Dispose /// was called) /// </summary> /// <param name="rootDrawingGroupChildren"> /// Collection containing the Drawing elements created by a DrawingContext /// returned from Open or Append. /// </param> internal void Close(DrawingCollection rootDrawingGroupChildren) { WritePreamble(); Debug.Assert(_open); Debug.Assert(rootDrawingGroupChildren != null); if (!_openedForAppend) { // Clear out the previous contents by replacing the current collection with // the new collection. // // When more than one element exists in rootDrawingGroupChildren, the // DrawingContext had to create this new collection anyways. To behave // consistently between the one-element and many-element cases, // we always set Children to a new DrawingCollection instance during Close(). // // Doing this also avoids having to protect against exceptions being thrown // from user-code, which could be executed if a Changed event was fired when // we tried to add elements to a pre-existing collection. // // The collection created by the DrawingContext will no longer be // used after the DrawingContext is closed, so we can take ownership // of the reference here to avoid any more unneccesary copies. Children = rootDrawingGroupChildren; } else { // // // Append the collection to the current Children collection // // DrawingCollection children = Children; // // Ensure that we can Append to the Children collection // if (children == null) { throw new InvalidOperationException(SR.Get(SRID.DrawingGroup_CannotAppendToNullCollection)); } if (children.IsFrozen) { throw new InvalidOperationException(SR.Get(SRID.DrawingGroup_CannotAppendToFrozenCollection)); } // Append the new collection to our current Children. // // TransactionalAppend rolls-back the Append operation in the event // an exception is thrown from the Changed event. children.TransactionalAppend(rootDrawingGroupChildren); } // This DrawingGroup is no longer open _open = false; }
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 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); }
/// <summary> /// Draws a barcode rectangles. /// </summary> private void DrawBarcodeRectangles(IBarcodeInfo[] infos) { if (infos.Length == 0) { return; } DrawingGroup drawingGroup = new DrawingGroup(); DrawingContext drawingContext = drawingGroup.Open(); drawingContext.DrawImage(_bitmapSource, new Rect(0, 0, _bitmapSource.PixelWidth, _bitmapSource.PixelHeight)); Brush barcodeRectangleBrush = new SolidColorBrush(Color.FromArgb(48, Colors.Green.R, Colors.Green.G, Colors.Green.B)); Color barcodeRectanglePenColor = Colors.Green; barcodeRectanglePenColor.A = 192; Pen barcodeRectanglePen = new Pen(new SolidColorBrush(barcodeRectanglePenColor), 2); Typeface fontTypeface = new Typeface("Courier New"); PathGeometry barcodeRectangles = new PathGeometry(); DrawingCollection drawingCollection = new DrawingCollection(); LineSegment[] lineSegments; for (int i = 0; i < infos.Length; i++) { IBarcodeInfo inf = infos[i]; // barcode rectangle double x = inf.Region.LeftTop.X; double y = inf.Region.LeftTop.Y; Point leftTop = new Point(x, y); Point rightTop = new Point(inf.Region.RightTop.X, inf.Region.RightTop.Y); Point rightBottom = new Point(inf.Region.RightBottom.X, inf.Region.RightBottom.Y); Point leftBottom = new Point(inf.Region.LeftBottom.X, inf.Region.LeftBottom.Y); lineSegments = new LineSegment[] { new LineSegment(rightTop, true), new LineSegment(rightBottom, true), new LineSegment(leftBottom, true) }; PathGeometry barcodeRectangle = new PathGeometry(); barcodeRectangle.Figures.Add(new PathFigure(leftTop, lineSegments, true)); drawingContext.DrawDrawing(new GeometryDrawing(barcodeRectangleBrush, barcodeRectanglePen, barcodeRectangle)); // barcode orientation marker lineSegments = new LineSegment[] { new LineSegment(new Point(x + 1, y), true), new LineSegment(new Point(x + 1, y + 1), true), new LineSegment(new Point(x, y + 1), true) }; PathGeometry barcodeOrientations = new PathGeometry(); barcodeOrientations.Figures.Add(new PathFigure(leftTop, lineSegments, true)); Color barcodeOrientationColor = Colors.Lime; if (inf.ReadingQuality < 0.75) { if (inf.ReadingQuality >= 0.5) { barcodeOrientationColor = Colors.Yellow; } else { barcodeOrientationColor = Colors.Red; } } barcodeOrientationColor.A = 192; Brush barcodeOrientationBrush = new SolidColorBrush(barcodeOrientationColor); Pen barcodeOrientationPen = new Pen(barcodeOrientationBrush, 3); drawingContext.DrawDrawing(new GeometryDrawing(barcodeOrientationBrush, barcodeOrientationPen, barcodeOrientations)); string barcodeTypeValue; if (inf is BarcodeSubsetInfo) { barcodeTypeValue = ((BarcodeSubsetInfo)inf).BarcodeSubset.Name; } else { barcodeTypeValue = inf.BarcodeType.ToString(); } // barcode number and value string barcodeValue = RemoveSpecialCharacters(inf.Value); if (barcodeValue.Length > 32) { barcodeValue = barcodeValue.Substring(0, 32) + "..."; } drawingContext.DrawText(new FormattedText( string.Format("[{0}] {1}: {2}", i + 1, barcodeTypeValue, barcodeValue), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, fontTypeface, 11, Brushes.Blue), new Point(x, y - 15)); } drawingContext.Close(); DrawingImage drawingImageSource = new DrawingImage(drawingGroup); readerImage.Source = drawingImageSource; }
/// <summary> /// Called by the base class during Close/Dispose when the content created by /// the DrawingDrawingContext needs to be committed. /// </summary> /// <param name="rootDrawingGroupChildren"> /// Collection containing the Drawing elements created with this /// DrawingContext. /// </param> /// <remarks> /// This will only be called once (at most) per instance. /// </remarks> protected override void CloseCore(DrawingCollection rootDrawingGroupChildren) { Debug.Assert(null != _drawingGroup); _drawingGroup.Close(rootDrawingGroupChildren); }
private XElement WriteWorkSheetDrawing_Content_graphicFrame(ExcelChart excelchart, DrawingCollection drawingCollection, PackagePart wrokSheetDrawingPart, int index) { XElement graphicFrameNode = new XElement(XName.Get("graphicFrame", ExcelCommon.Schema_SheetDrawings), new XAttribute(XName.Get("macro"), "")); XElement nvGraphicFramePrNode = new XElement(XName.Get("nvGraphicFramePr", ExcelCommon.Schema_SheetDrawings)); XElement cNvPrNode = new XElement(XName.Get("cNvPr", ExcelCommon.Schema_SheetDrawings), new XAttribute(XName.Get("id"), index + 2), new XAttribute(XName.Get("name"), excelchart.Name)); nvGraphicFramePrNode.Add(cNvPrNode); nvGraphicFramePrNode.Add(new XElement(XName.Get("cNvGraphicFramePr", ExcelCommon.Schema_SheetDrawings))); graphicFrameNode.Add(nvGraphicFramePrNode); XElement xfrmElement = new XElement(XName.Get("xfrm", ExcelCommon.Schema_SheetDrawings), new XElement(XName.Get("off", ExcelCommon.Schema_Drawings), new XAttribute(XName.Get("x"), 0), new XAttribute(XName.Get("y"), 0)), new XElement(XName.Get("ext", ExcelCommon.Schema_Drawings), new XAttribute(XName.Get("cx"), 0), new XAttribute(XName.Get("cy"), 0))); graphicFrameNode.Add(xfrmElement); XElement graphicElement = new XElement(XName.Get("graphic", ExcelCommon.Schema_Drawings)); XElement graphicDataElement = new XElement(XName.Get("graphicData", ExcelCommon.Schema_Drawings), new XAttribute(XName.Get("uri"), ExcelCommon.Schema_Chart)); XElement chartElement = new XElement(XName.Get("chart", ExcelCommon.Schema_Chart), new XAttribute(XNamespace.Xmlns + "c", ExcelCommon.Schema_Chart), new XAttribute(XNamespace.Xmlns + "r", ExcelCommon.Schema_Relationships)); string chartRelationID = CreateChartPackage(excelchart, wrokSheetDrawingPart, drawingCollection.DrawingUri); chartElement.Add(new XAttribute(XName.Get("id", ExcelCommon.Schema_Relationships), chartRelationID)); graphicDataElement.Add(chartElement); graphicElement.Add(graphicDataElement); //graphicElement.Add(new XElement(XName.Get("clientData", ExcelCommon.Schema_SheetDrawings))); graphicFrameNode.Add(graphicElement); return graphicFrameNode; }
public void LoadDiagrams(DrawingGroup linkGroups, DrawingGroup wholeGroup) { if (linkGroups == null) { return; } DrawingCollection drawings = linkGroups.Children; if (drawings == null || drawings.Count == 0) { return; } else if (drawings.Count == 1) { DrawingGroup layerGroup = drawings[0] as DrawingGroup; if (layerGroup != null) { string elementId = SvgObject.GetId(layerGroup); if (!string.IsNullOrWhiteSpace(elementId) && string.Equals(elementId, "IndicateLayer", StringComparison.OrdinalIgnoreCase)) { this.LoadLayerDiagrams(layerGroup); _wholeDrawing = wholeGroup; _linksDrawing = linkGroups; return; } } } this.UnloadDiagrams(); for (int i = 0; i < drawings.Count; i++) { DrawingGroup childGroup = drawings[i] as DrawingGroup; if (childGroup != null) { string groupName = SvgLink.GetKey(childGroup); //string groupName = SvgObject.GetName(childGroup); if (string.IsNullOrWhiteSpace(groupName)) { if (childGroup.Children != null && childGroup.Children.Count == 1) { this.AddDrawing(childGroup); } else { throw new InvalidOperationException("Error: The link group is in error."); } } else { if (childGroup.Children != null && childGroup.Children.Count == 1) { this.AddDrawing(childGroup, groupName); } else { throw new InvalidOperationException( String.Format("Error: The link group is in error - {0}", groupName)); } } } } _wholeDrawing = wholeGroup; _linksDrawing = linkGroups; if (_drawingCanvas != null) { _displayTransform = _drawingCanvas.DisplayTransform; } }
/// <summary> /// Dispose() closes this DrawingContext for any further additions, and /// returns it's content to the object that created it. /// </summary> /// <remarks> /// Further Draw/Push/Pop calls to this DrawingContext will result in an /// exception. This method also matches any outstanding Push calls with /// a cooresponding Pop. Multiple calls to Dispose will not result in /// an exception. /// </remarks> protected override void DisposeCore() { // Dispose may be called multiple times without throwing // an exception. if (!_disposed) { // // Match any outstanding Push calls with a Pop // if (_previousDrawingGroupStack != null) { int stackCount = _previousDrawingGroupStack.Count; for (int i = 0; i < stackCount; i++) { Pop(); } } // // Call CloseCore with the root DrawingGroup's children // DrawingCollection rootChildren; if (_currentDrawingGroup != null) { // If we created a root DrawingGroup because multiple elements // exist at the root level, provide it's Children collection // directly. rootChildren = _currentDrawingGroup.Children; } else { // Create a new DrawingCollection if we didn't create a // root DrawingGroup because the root level only contained // a single child. // // This collection is needed by DrawingGroup.Open because // Open always replaces it's Children collection. It isn't // strictly needed for Append, but always using a collection // simplifies the TransactionalAppend implementation (i.e., // a seperate implemention isn't needed for a single element) rootChildren = new DrawingCollection(); // // We may need to opt-out of inheritance through the new Freezable. // This is controlled by this.CanBeInheritanceContext. // rootChildren.CanBeInheritanceContext = CanBeInheritanceContext; if (_rootDrawing != null) { rootChildren.Add(_rootDrawing); } } // Inform our derived classes that Close was called CloseCore(rootChildren); _disposed = true; } }
/// <summary> /// Called during Close/Dispose when the content created this DrawingContext /// needs to be committed. /// </summary> /// <param name="rootDrawingGroupChildren"> /// Collection containing the Drawing elements created with this /// DrawingContext. /// </param> /// <remarks> /// This will only be called once (at most) per instance. /// </remarks> protected virtual void CloseCore(DrawingCollection rootDrawingGroupChildren) { // Default implementation is a no-op }