Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Parses a ResourceDictionary element.
    /// </summary>
    void ParseResourceDictionary(ResourceDictionary dict)
    {
      //Debug.Assert(this.reader.Name == "ResourceDictionary");
      Debug.Assert(this.reader.Name.Contains("Resource"));
      try
      {
        bool isEmptyElement = this.reader.IsEmptyElement;
        //ResourceDictionary dict = new ResourceDictionary();
        while (MoveToNextAttribute())
        {
          switch (this.reader.Name)
          {
            case "Source":
              dict.Source = this.reader.Value;
              break;

            default:
              UnexpectedAttribute(this.reader.Name);
              break;
          }
        }
        if (!isEmptyElement)
        {
          MoveToNextElement();
          while (this.reader.IsStartElement())
          {
            switch (this.reader.Name)
            {
              case "ImageBrush":
                ImageBrush ibrush = ParseImageBrush();
                dict.elements[ibrush.Key] = ibrush;
                ibrush.Parent = dict;
                break;

              case "LinearGradientBrush":
                LinearGradientBrush lbrush = ParseLinearGradientBrush();
                dict.elements[lbrush.Key] = lbrush;
                lbrush.Parent = dict;
                break;

              case "RadialGradientBrush":
                RadialGradientBrush rbrush = ParseRadialGradientBrush();
                dict.elements[rbrush.Key] = rbrush;
                rbrush.Parent = dict;
                break;

              case "VisualBrush":
                VisualBrush vbrush = ParseVisualBrush();
                dict.elements[vbrush.Key] = vbrush;
                vbrush.Parent = dict;
                break;

              case "SolidColorBrush":
                VisualBrush sbrush = ParseVisualBrush();
                dict.elements[sbrush.Key] = sbrush;
                sbrush.Parent = dict;
                break;

              case "MatrixTransform":
                MatrixTransform transform = ParseMatrixTransform();
                dict.elements[transform.Key] = transform;
                transform.Parent = dict;
                break;

              case "PathGeometry":
                PathGeometry geo = ParsePathGeometry();
                dict.elements[geo.Key] = geo;
                geo.Parent = dict;
                break;

              case "Path":
                Path path = ParsePath();
                dict.elements[path.Key] = path;
                path.Parent = dict;
                break;

              case "Glyphs":
                Glyphs glyphs = ParseGlyphs();
                dict.elements[glyphs.Key] = glyphs;
                glyphs.Parent = dict;
                break;

              case "Canvas":
                Canvas canvas = ParseCanvas();
                dict.elements[canvas.Key] = canvas;
                canvas.Parent = dict;
                break;

              default:
                Debugger.Break();
                break;
            }
          }
        }
        MoveToNextElement();
        //return dict;
      }
      finally
      {
      }
    }