예제 #1
0
        /// <summary>
        /// Parses a FixedPage element.
        /// </summary>
        FixedPage ParseFixedPage()
        {
            Debug.Assert(this.reader.Name == "FixedPage");
            FixedPage fpage = new FixedPage();

            try
            {
                bool isEmptyElement = this.reader.IsEmptyElement;
                Debug.Assert(this.fpage == null);
                this.fpage = fpage;
                while (this.reader.MoveToNextAttribute())
                {
                    switch (this.reader.Name)
                    {
                    case "Name":
                        fpage.Name = this.reader.Value;
                        break;

                    case "Width":
                        fpage.Width = ParseDouble(this.reader.Value);
                        break;

                    case "Height":
                        fpage.Height = ParseDouble(this.reader.Value);
                        break;

                    case "ContentBox":
                        fpage.ContentBox = Rect.Parse(this.reader.Value);
                        break;

                    case "BleedBox":
                        fpage.BleedBox = Rect.Parse(this.reader.Value);
                        break;

                    case "xmlns":
                        break;

                    case "xmlns:xps":
                        break;

                    case "xmlns:false":
                        break;

                    case "xmlns:mc":
                        break;

                    case "xmlns:x":
                        break;

                    case "xmlns:xml":
                        break;

                    case "xmlns:xsi":
                        break;

                    case "xmlns:v2":
                        break;

                    case "xml:lang":
                        fpage.Lang = this.reader.Value;
                        break;

                    case "xml:space":
                        break;

                    case "xsi:schemaLocation":
                        break;

                    case "mc:MustUnderstand":
                        break;

                    default:
                        UnexpectedAttribute(this.reader.Name);
                        break;
                    }
                }
                if (!isEmptyElement)
                {
                    MoveToNextElement();
                    while (this.reader.IsStartElement())
                    {
                        XpsElement element = null;
                        switch (reader.Name)
                        {
                        case "Path":
                            element = ParsePath();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "Canvas":
                            element = ParseCanvas();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "Glyphs":
                            element = ParseGlyphs();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "MatrixTransform":
                            Debugger.Break();
                            ParseMatrixTransform();
                            //fpage.
                            //element = ParseGlyphs();
                            //fpage.Content.Add(element);
                            break;

                        case "FixedPage.Resources":
                            MoveToNextElement();
                            ResourceDictionary rd = new ResourceDictionary();
                            fpage.Resources   = rd;
                            rd.Parent         = fpage;
                            rd.ResourceParent = ResourceDictionaryStack.Current;
                            ResourceDictionaryStack.Push(rd);
                            ParseResourceDictionary(rd);
                            MoveToNextElement();
                            break;

                        case "mc:AlternateContent":
                            MoveToNextElement();
                            break;

                        case "mc:Choice":
                            MoveToNextElement();
                            break;

                        case "v2:Circle":
                            MoveToNextElement();
                            break;

                        case "v2:Watermark":
                            MoveToNextElement();
                            break;

                        case "v2:Blink":
                            MoveToNextElement();
                            break;

                        default:
                            Debugger.Break();
                            break;
                        }
                    }
                }
                MoveToNextElement();
            }
            finally
            {
                // If the current ResourceDictionary is from this FixedPage, pop it.
                if (fpage != null && fpage.Resources != null)
                {
                    if (Object.ReferenceEquals(fpage.Resources, ResourceDictionaryStack.Current))
                    {
                        ResourceDictionaryStack.Pop();
                    }
                }
            }
            return(fpage);
        }
예제 #2
0
        /// <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);
        }