コード例 #1
0
ファイル: svgFile.cs プロジェクト: inkimagine/svglayerplayer
        public void Draw(float dScale, Graphics g, float dOffsetX, float dOffsetY)
        {
            svgTransformList transform = new svgTransformList();

            //if we want to draw the layers in the center of the canvas then we need to apply a translate transform using the offset values. The offset
            //values are calculated using the size of the SVG document
            if (dOffsetX != 0 || dOffsetY != 0)
            {
                transform.Add("translate(" + dOffsetX + "," + dOffsetY + ")");
            }
            //if we are zooming in or out, apply a scaling transform
            if (dScale != 1)
            {
                String strTransform = "scale(" + dScale + "," + dScale + ")";
                transform.Add(strTransform);
            }
            //build the current transform matrix
            Matrix matrix = transform.GetMatrix();

            if (matrix != null)
            {
                //if it's a valid matrix then apply it to the graphics context
                g.Transform = matrix;
            }
            //if we only have one layer then draw the layer
            if (m_nLayerCount < 2)
            {
                for (int a = 0; a < m_entities.Count; a++)
                {
                    m_entities[a].Draw(g, transform);
                }
            }
            else
            {
                //otherwise skip to the correct layer and then draw it
                int nSkip = (m_nCurrentLayer == -1) ? 0 : m_nCurrentLayer;
                for (int a = 0; a < m_entities.Count; a++)
                {
                    if (m_entities[a].GetAttribute("inkscape:groupmode").Equals("layer"))
                    {
                        if (nSkip == 0)
                        {
                            m_entities[a].Draw(g, transform);
                            if (m_nCurrentLayer != -1)
                            {
                                break;
                            }
                        }
                        else
                        {
                            nSkip--;
                        }
                    }
                }
            }
        }
コード例 #2
0
 public virtual void Draw(Graphics g, svgTransformList transform)
 {
     try
     {
         InitializeStyle();
         if (m_strTransform.Length > 0)
         {
             transform.Add(m_strTransform);
             Matrix matrix = transform.GetMatrix();
             if (matrix != null)
             {
                 g.Transform = matrix;
             }
         }
         DrawInternal(g);
         for (int a = 0; a < m_entities.Count; a++)
         {
             m_entities[a].Draw(g, transform);
         }
         if (m_strTransform.Length > 0)
         {
             transform.Remove();
         }
         Matrix matrix2 = transform.GetMatrix();
         if (matrix2 != null)
         {
             g.Transform = matrix2;
         }
         else
         {
             g.Transform = null;
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
     }
 }