/// <summary> /// Parses a element. /// </summary> Canvas ParseObject() { Debug.Assert(this.reader.Name == ""); bool isEmptyElement = this.reader.IsEmptyElement; Canvas canvas = new Canvas(); while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Name": //canvas.Name = this.reader.Value; break; default: UnexpectedAttribute(this.reader.Name); break; } } if (!isEmptyElement) { MoveToNextElement(); while (this.reader.IsStartElement()) { switch (this.reader.Name) { case "Canvas.Resources": //MoveToNextElement(); //canvas.Resources = ParseResourceDictionary(); break; default: Debugger.Break(); break; } } } MoveToNextElement(); return canvas; }
/// <summary> /// Writes a Canvas to the content stream. /// </summary> private void WriteCanvas(Canvas canvas) { WriteSaveState("begin Canvas", canvas.Name); // Transform also affects clipping and opacity mask bool transformed = canvas.RenderTransform != null; if (transformed) { MultiplyTransform(canvas.RenderTransform); WriteRenderTransform(canvas.RenderTransform); } bool clipped = canvas.Clip != null; if (clipped) WriteClip(canvas.Clip); if (canvas.Opacity < 1) MultiplyOpacity(canvas.Opacity); if (canvas.OpacityMask != null) WriteOpacityMask(canvas.OpacityMask); WriteElements(canvas.Content); // Must leave text mode at end of canvas BeginGraphic(); WriteRestoreState("end Canvas", canvas.Name); }
/// <summary> /// Parses a Canvas element. /// </summary> Canvas ParseCanvas() { Debug.Assert(this.reader.Name == "Canvas"); Canvas canvas = new Canvas(); try { bool isEmptyElement = this.reader.IsEmptyElement; while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Name": canvas.Name = this.reader.Value; break; case "RenderTransform": canvas.RenderTransform = ParseMatrixTransform(this.reader.Value); break; case "Clip": canvas.Clip = ParsePathGeometry(this.reader.Value); break; case "Opacity": canvas.Opacity = ParseDouble(this.reader.Value); break; case "OpacityMask": canvas.OpacityMask = ParseBrush(this.reader.Value); break; case "RenderOptions.EdgeMode": canvas.RenderOptions_EdgeMode = this.reader.Value; break; case "FixedPage.NavigateUri": canvas.FixedPage_NavigateUri = this.reader.Value; break; case "AutomationProperties.HelpText": canvas.AutomationProperties_HelpText = this.reader.Value; break; case "AutomationProperties.Name": canvas.AutomationProperties_Name = this.reader.Value; break; case "xml:lang": canvas.lang = this.reader.Value; break; case "xmlns:x": break; default: UnexpectedAttribute(this.reader.Name); break; } } if (!isEmptyElement) { MoveToNextElement(); while (this.reader.IsStartElement()) { switch (this.reader.Name) { case "Canvas.Resources": MoveToNextElement(); ResourceDictionary rd = new ResourceDictionary(); canvas.Resources = rd; rd.Parent = canvas; rd.ResourceParent = ResourceDictionaryStack.Current; ResourceDictionaryStack.Push(rd); ParseResourceDictionary(rd); MoveToNextElement(); break; case "Canvas.RenderTransform": MoveToNextElement(); canvas.RenderTransform = ParseMatrixTransform(); MoveToNextElement(); break; case "Canvas.Clip": MoveToNextElement(); canvas.Clip = ParsePathGeometry(); break; case "Canvas.OpacityMask": MoveToNextElement(); canvas.OpacityMask = ParseBrush(); canvas.OpacityMask.Parent = canvas; break; case "Path": { PdfSharp.Xps.XpsModel.Path path = ParsePath(); #if DEBUG if (!String.IsNullOrEmpty(path.Name)) Debug.WriteLine("Path: " + path.Name); #endif canvas.Content.Add(path); path.Parent = canvas; } break; case "Glyphs": { PdfSharp.Xps.XpsModel.Glyphs glyphs = ParseGlyphs(); canvas.Content.Add(glyphs); glyphs.Parent = canvas; } break; case "Canvas": { PdfSharp.Xps.XpsModel.Canvas canvas2 = ParseCanvas(); canvas.Content.Add(canvas2); canvas2.Parent = canvas; } break; case "mc:AlternateContent": case "mc:Choice": MoveToNextElement(); //canvas.Content.Add(ParseCanvas()); break; default: Debugger.Break(); break; } } } MoveToNextElement(); } finally { // If the current ResourceDictionary is from this Canvas, pop it. if (canvas != null && canvas.Resources != null) { if (Object.ReferenceEquals(canvas.Resources, ResourceDictionaryStack.Current)) ResourceDictionaryStack.Pop(); } } return canvas; }
/// <summary> /// Parses a Canvas element. /// </summary> Canvas ParseCanvas() { Debug.Assert(this.reader.Name == "Canvas"); Canvas canvas = new Canvas(); try { bool isEmptyElement = this.reader.IsEmptyElement; while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Name": canvas.Name = this.reader.Value; break; case "RenderTransform": canvas.RenderTransform = ParseMatrixTransform(this.reader.Value); break; case "Clip": canvas.Clip = ParsePathGeometry(this.reader.Value); break; case "Opacity": canvas.Opacity = ParseDouble(this.reader.Value); break; case "OpacityMask": canvas.OpacityMask = ParseBrush(this.reader.Value); break; case "RenderOptions.EdgeMode": canvas.RenderOptions_EdgeMode = this.reader.Value; break; case "FixedPage.NavigateUri": canvas.FixedPage_NavigateUri = this.reader.Value; break; case "AutomationProperties.HelpText": canvas.AutomationProperties_HelpText = this.reader.Value; break; case "AutomationProperties.Name": canvas.AutomationProperties_Name = this.reader.Value; break; case "xml:lang": canvas.lang = this.reader.Value; break; case "xmlns:x": break; default: UnexpectedAttribute(this.reader.Name); break; } } if (!isEmptyElement) { MoveToNextElement(); while (this.reader.IsStartElement()) { switch (this.reader.Name) { case "Canvas.Resources": MoveToNextElement(); ResourceDictionary rd = new ResourceDictionary(); canvas.Resources = rd; rd.Parent = canvas; rd.ResourceParent = ResourceDictionaryStack.Current; ResourceDictionaryStack.Push(rd); ParseResourceDictionary(rd); MoveToNextElement(); break; case "Canvas.RenderTransform": MoveToNextElement(); canvas.RenderTransform = ParseMatrixTransform(); MoveToNextElement(); break; case "Canvas.Clip": MoveToNextElement(); canvas.Clip = ParsePathGeometry(); break; case "Canvas.OpacityMask": MoveToNextElement(); canvas.OpacityMask = ParseBrush(); canvas.OpacityMask.Parent = canvas; break; case "Path": { PdfSharp.Xps.XpsModel.Path path = ParsePath(); #if DEBUG if (!String.IsNullOrEmpty(path.Name)) { Debug.WriteLine("Path: " + path.Name); } #endif canvas.Content.Add(path); path.Parent = canvas; } break; case "Glyphs": { PdfSharp.Xps.XpsModel.Glyphs glyphs = ParseGlyphs(); canvas.Content.Add(glyphs); glyphs.Parent = canvas; } break; case "Canvas": { PdfSharp.Xps.XpsModel.Canvas canvas2 = ParseCanvas(); canvas.Content.Add(canvas2); canvas2.Parent = canvas; } break; case "mc:AlternateContent": case "mc:Choice": MoveToNextElement(); //canvas.Content.Add(ParseCanvas()); break; default: Debugger.Break(); break; } } } MoveToNextElement(); } finally { // If the current ResourceDictionary is from this Canvas, pop it. if (canvas != null && canvas.Resources != null) { if (Object.ReferenceEquals(canvas.Resources, ResourceDictionaryStack.Current)) { ResourceDictionaryStack.Pop(); } } } return(canvas); }