当前位置: 首页>>代码示例>>C#>>正文


C# Drawing.XMatrix类代码示例

本文整理汇总了C#中PdfSharp.Drawing.XMatrix的典型用法代码示例。如果您正苦于以下问题:C# XMatrix类的具体用法?C# XMatrix怎么用?C# XMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XMatrix类属于PdfSharp.Drawing命名空间,在下文中一共展示了XMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Format

        /// <summary>
        /// Calculates the space used for the axis title.
        /// </summary>
        internal override void Format()
        {
            XGraphics gfx = _rendererParms.Graphics;

            AxisTitleRendererInfo atri = ((AxisRendererInfo)_rendererParms.RendererInfo)._axisTitleRendererInfo;
            if (atri.AxisTitleText != "")
            {
                XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                if (atri.AxisTitleOrientation != 0)
                {
                    XPoint[] points = new XPoint[2];
                    points[0].X = 0;
                    points[0].Y = 0;
                    points[1].X = size.Width;
                    points[1].Y = size.Height;

                    XMatrix matrix = new XMatrix();
                    matrix.RotatePrepend(-atri.AxisTitleOrientation);
                    matrix.TransformPoints(points);

                    size.Width = Math.Abs(points[1].X - points[0].X);
                    size.Height = Math.Abs(points[1].Y - points[0].Y);
                }

                atri.X = 0;
                atri.Y = 0;
                atri.Height = size.Height;
                atri.Width = size.Width;
            }
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:33,代码来源:AxisTitleRenderer.cs

示例2: SetupFromBrush

    /// <summary>
    /// Setups the shading pattern from the specified brush.
    /// </summary>
    public void SetupFromBrush(XLinearGradientBrush brush, XMatrix matrix)
    {
      if (brush == null)
        throw new ArgumentNullException("brush");

      PdfShading shading = new PdfShading(this.document);
      shading.SetupFromBrush(brush);
      Elements[Keys.Shading] = shading;
      Elements[Keys.Matrix] = new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");
    }
开发者ID:BackupTheBerlios,项目名称:zp7-svn,代码行数:13,代码来源:PdfShadingPattern.cs

示例3: SetupFromBrush

        /// <summary>
        /// Setups the shading pattern from the specified brush.
        /// </summary>
        internal void SetupFromBrush(XLinearGradientBrush brush, XMatrix matrix, XGraphicsPdfRenderer renderer)
        {
            if (brush == null)
                throw new ArgumentNullException("brush");

            PdfShading shading = new PdfShading(_document);
            shading.SetupFromBrush(brush, renderer);
            Elements[Keys.Shading] = shading;
            //Elements[Keys.Matrix] = new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");
            Elements.SetMatrix(Keys.Matrix, matrix);
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:14,代码来源:PdfShadingPattern.cs

示例4: FromImageBrush

    /// <summary>
    /// Creates an XForm from an image brush.
    /// </summary>
    public static XForm FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
    {
      XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
      XImage ximage = xpImage.XImage;
      double width = ximage.PixelWidth;
      double height = ximage.PixelHeight;

      // view box in point
      // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
      XRect box = new XRect(0, 0, width, height);
      XForm xform = new XForm(context.PdfDocument, box);

      PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);

      Debug.Assert(ximage != null);

      PdfFormXObject pdfForm = xform.PdfForm;
      pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContentRaw();

      string imageID = formWriter.Resources.AddImage(new PdfImage(context.PdfDocument, ximage));
      XMatrix matrix = new XMatrix();
      double scaleX = brush.Viewport.Width / brush.Viewbox.Width * 4 / 3 * ximage.PointWidth;
      double scaleY = brush.Viewport.Height / brush.Viewbox.Height * 4 / 3 * ximage.PointHeight;
      matrix.TranslatePrepend(-brush.Viewbox.X, -brush.Viewbox.Y);
      matrix.ScalePrepend(scaleX, scaleY);
      matrix.TranslatePrepend(brush.Viewport.X / scaleX, brush.Viewport.Y / scaleY);

      matrix = new XMatrix(width, 0, 0, -height, 0, height);
      formWriter.WriteLiteral("q\n");
      // TODO:WriteClip(path.Data);
      //formWriter.WriteLiteral("{0:0.###} 0 0 -{1:0.###} {2:0.###} {3:0.###} cm 100 Tz {4} Do Q\n",
      //  matrix.M11, matrix.M22, matrix.OffsetX, matrix.OffsetY + brush.Viewport.Height, imageID);
      formWriter.WriteMatrix(matrix);
      formWriter.WriteLiteral(imageID + " Do Q\n");

      formWriter.EndContent();

      return xform;
    }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:45,代码来源:XFormBuilder.cs

示例5: FromMatrix

 /// <summary>
 /// Creates a literal from an XMatrix
 /// </summary>
 public static PdfLiteral FromMatrix(XMatrix matrix)
 {
     return new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");
 }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:7,代码来源:PdfLiteral.cs

示例6: GetMatrix

      /// Converts the specified value to XMatrix.
      /// If the value not exists, the function returns an identity matrix.
      /// If the value is not convertible, the function throws an InvalidCastException.
      public XMatrix GetMatrix(string key, bool create)
      {
        XMatrix value = new XMatrix();
        object obj = this[key];
        if (obj == null)
        {
          if (create)
            this[key] = new PdfLiteral("[1 0 0 1 0 0]");  // cannot be parsed, implement a PdfMatrix...
          return value;
        }
        if (obj is PdfReference)
          obj = ((PdfReference)obj).Value;

        PdfArray array = obj as PdfArray;
        if (array != null && array.Elements.Count == 6)
        {
          value = new XMatrix(array.Elements.GetReal(0), array.Elements.GetReal(1), array.Elements.GetReal(2),
            array.Elements.GetReal(3), array.Elements.GetReal(4), array.Elements.GetReal(5));
        }
        else if (obj is PdfLiteral)
        {
          throw new NotImplementedException("Parsing matrix from literal.");
        }
        else
          throw new InvalidCastException("Element is not an array with 6 values.");
        return value;
      }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:30,代码来源:PdfDictionary.cs

示例7: AddTransform

    /// <summary>
    /// Gets or sets the transformation matrix.
    /// </summary>
    void AddTransform(XMatrix transform, XMatrixOrder order)
    {
      //if (!this.transform.Equals(value))
      {
        XMatrix matrix = this.transform;
        matrix.Multiply(transform, order);
        this.transform = matrix;
        matrix = this.defaultViewMatrix;
        matrix.Multiply(this.transform, XMatrixOrder.Prepend);
#if GDI
        if (this.targetContext == XGraphicTargetContext.GDI)
        {
#if DEBUG
          System.Drawing.Drawing2D.Matrix m = (System.Drawing.Drawing2D.Matrix)matrix;
          this.gfx.Transform = m;
#else
          this.gfx.Transform = (System.Drawing.Drawing2D.Matrix)matrix;
#endif
        }
#endif
#if WPF
        if (this.targetContext == XGraphicTargetContext.WPF)
        {
#if !SILVERLIGHT
          MatrixTransform mt = new MatrixTransform(transform.ToWpfMatrix());
#else
          MatrixTransform mt = new MatrixTransform();
          mt.Matrix = transform.ToWpfMatrix();
#endif
          if (order == XMatrixOrder.Append)
            mt = (MatrixTransform)mt.Inverse;
          this.gsStack.Current.SetTransform(mt);
        }
#endif
        if (this.renderer != null)
          this.renderer.Transform = this.transform;
      }
    }
开发者ID:Davincier,项目名称:openpetra,代码行数:41,代码来源:XGraphics.cs

示例8: MultiplyTransform

 /// <summary>
 /// Multiplies the transformation matrix of this object and specified matrix.
 /// </summary>
 public void MultiplyTransform(XMatrix matrix)
 {
   //MultiplyTransform(matrix, XMatrixOrder.Prepend);
   XMatrix matrix2 = new XMatrix();  //XMatrix.Identity;
   matrix2.Prepend(matrix);
   AddTransform(matrix2, XMatrixOrder.Prepend);
 }
开发者ID:Davincier,项目名称:openpetra,代码行数:10,代码来源:XGraphics.cs

示例9: RotateAtTransform

 /// <summary>
 /// Applies the specified rotation operation to the transformation matrix of this object by 
 /// prepending it to the object's transformation matrix.
 /// </summary>
 public void RotateAtTransform(double angle, XPoint point, XMatrixOrder order)
 {
   //XMatrix matrix = this.transform;
   //matrix.RotateAt(angle, point, order);
   //Transform = matrix;
   XMatrix matrix = new XMatrix();  //XMatrix.Identity;
   matrix.RotateAtPrepend(angle, point);
   AddTransform(matrix, order);
 }
开发者ID:Davincier,项目名称:openpetra,代码行数:13,代码来源:XGraphics.cs

示例10: RotateTransform

 /// <summary>
 /// Applies the specified rotation operation to the transformation matrix of this object
 /// in the specified order. The angle unit of measure is degree.
 /// </summary>
 public void RotateTransform(double angle, XMatrixOrder order)
 {
   //XMatrix matrix = this.transform;
   //matrix.Rotate(angle, order);
   //Transform = matrix;
   XMatrix matrix = new XMatrix();  //XMatrix.Identity;
   matrix.RotatePrepend(angle);
   AddTransform(matrix, order);
 }
开发者ID:Davincier,项目名称:openpetra,代码行数:13,代码来源:XGraphics.cs

示例11: MultiplyTransform

 public XMatrix MultiplyTransform(XMatrix matrix)
 {
   this.transform.Prepend(matrix);
   return this.transform;
 }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:5,代码来源:PdfGraphicsState.cs

示例12: ArcToBezier

        //+------------------------------------------------------------------------------------------------- 
        //
        //  Function: ArcToBezier 
        //
        //  Synopsis: Compute the Bezier approximation of an arc
        //
        //  Notes:    This utilitycomputes the Bezier approximation for an elliptical arc as it is defined 
        //            in the SVG arc spec. The ellipse from which the arc is carved is axis-aligned in its
        //            own coordinates, and defined there by its x and y radii. The rotation angle defines 
        //            how the ellipse's axes are rotated relative to our x axis. The start and end points 
        //            define one of 4 possible arcs; the sweep and large-arc flags determine which one of
        //            these arcs will be chosen. See SVG spec for details. 
        //
        //            Returning pieces = 0 indicates a line instead of an arc
        //                      pieces = -1 indicates that the arc degenerates to a point
        // 
        //--------------------------------------------------------------------------------------------------
        public static PointCollection ArcToBezier(double xStart, double yStart, double xRadius, double yRadius, double rotationAngle,
            bool isLargeArc, bool isClockwise, double xEnd, double yEnd, out int pieces)
        {
            double cosArcAngle, sinArcAngle, xCenter, yCenter, r, bezDist;
            XVector vecToBez1, vecToBez2;
            XMatrix matToEllipse;

            double fuzz2 = FUZZ * FUZZ;
            bool isZeroCenter = false;

            pieces = -1;

            // In the following, the line segment between between the arc's start and
            // end points is referred to as "the chord".

            // Transform 1: Shift the origin to the chord's midpoint 
            double x = (xEnd - xStart) / 2;
            double y = (yEnd - yStart) / 2;

            double halfChord2 = x * x + y * y;     // (half chord length)^2

            // Degenerate case: single point
            if (halfChord2 < fuzz2)
            {
                // The chord degeneartes to a point, the arc will be ignored 
                return null;
            }

            // Degenerate case: straight line
            if (!AcceptRadius(halfChord2, fuzz2, ref xRadius) || !AcceptRadius(halfChord2, fuzz2, ref yRadius))
            {
                // We have a zero radius, add a straight line segment instead of an arc
                pieces = 0;
                return null;
            }

            if (xRadius == 0 || yRadius == 0)
            {
                // We have a zero radius, add a straight line segment instead of an arc
                pieces = 0;
                return null;
            }

            // Transform 2: Rotate to the ellipse's coordinate system
            rotationAngle = -rotationAngle * Calc.Deg2Rad;

            double cos = Math.Cos(rotationAngle);
            double sin = Math.Sin(rotationAngle);

            r = x * cos - y * sin;
            y = x * sin + y * cos;
            x = r;

            // Transform 3: Scale so that the ellipse will become a unit circle 
            x /= xRadius;
            y /= yRadius;

            // We get to the center of that circle along a verctor perpendicular to the chord 
            // from the origin, which is the chord's midpoint. By Pythagoras, the length of that
            // vector is sqrt(1 - (half chord)^2). 

            halfChord2 = x * x + y * y;   // now in the circle coordinates

            if (halfChord2 > 1)
            {
                // The chord is longer than the circle's diameter; we scale the radii uniformly so
                // that the chord will be a diameter. The center will then be the chord's midpoint, 
                // which is now the origin.
                r = Math.Sqrt(halfChord2);
                xRadius *= r;
                yRadius *= r;
                xCenter = yCenter = 0;
                isZeroCenter = true;

                // Adjust the unit-circle coordinates x and y
                x /= r;
                y /= r;
            }
            else
            {
                // The length of (-y,x) or (x,-y) is sqrt(rHalfChord2), and we want a vector 
                // of length sqrt(1 - rHalfChord2), so we'll multiply it by:
                r = Math.Sqrt((1 - halfChord2) / halfChord2);
//.........这里部分代码省略.........
开发者ID:Core2D,项目名称:PDFsharp,代码行数:101,代码来源:GeometryHelper.cs

示例13: BezierCurveFromArc

        /// <summary>
        /// Creates between 1 and 5 Béziers curves from parameters specified like in WPF.
        /// </summary>
        public static List<XPoint> BezierCurveFromArc(XPoint point1, XPoint point2, XSize size,
            double rotationAngle, bool isLargeArc, bool clockwise, PathStart pathStart)
        {
            // See also http://www.charlespetzold.com/blog/blog.xml from January 2, 2008: 
            // http://www.charlespetzold.com/blog/2008/01/Mathematics-of-ArcSegment.html
            double δx = size.Width;
            double δy = size.Height;
            Debug.Assert(δx * δy > 0);
            double factor = δy / δx;
            bool isCounterclockwise = !clockwise;

            // Adjust for different radii and rotation angle.
            XMatrix matrix = new XMatrix();
            matrix.RotateAppend(-rotationAngle);
            matrix.ScaleAppend(δy / δx, 1);
            XPoint pt1 = matrix.Transform(point1);
            XPoint pt2 = matrix.Transform(point2);

            // Get info about chord that connects both points.
            XPoint midPoint = new XPoint((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2);
            XVector vect = pt2 - pt1;
            double halfChord = vect.Length / 2;

            // Get vector from chord to center.
            XVector vectRotated;

            // (comparing two Booleans here!)
            if (isLargeArc == isCounterclockwise)
                vectRotated = new XVector(-vect.Y, vect.X);
            else
                vectRotated = new XVector(vect.Y, -vect.X);

            vectRotated.Normalize();

            // Distance from chord to center.
            double centerDistance = Math.Sqrt(δy * δy - halfChord * halfChord);
            if (double.IsNaN(centerDistance))
                centerDistance = 0;

            // Calculate center point.
            XPoint center = midPoint + centerDistance * vectRotated;

            // Get angles from center to the two points.
            double α = Math.Atan2(pt1.Y - center.Y, pt1.X - center.X);
            double β = Math.Atan2(pt2.Y - center.Y, pt2.X - center.X);

            // (another comparison of two Booleans!)
            if (isLargeArc == (Math.Abs(β - α) < Math.PI))
            {
                if (α < β)
                    α += 2 * Math.PI;
                else
                    β += 2 * Math.PI;
            }

            // Invert matrix for final point calculation.
            matrix.Invert();
            double sweepAngle = β - α;

            // Let the algorithm of GDI+ DrawArc to Bézier curves do the rest of the job
            return BezierCurveFromArc(center.X - δx * factor, center.Y - δy, 2 * δx * factor, 2 * δy,
              α / Calc.Deg2Rad, sweepAngle / Calc.Deg2Rad, pathStart, ref matrix);
        }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:66,代码来源:GeometryHelper.cs

示例14: AppendPartialArcQuadrant

        /// <summary>
        /// Appends a Bézier curve for an arc within a full quadrant.
        /// </summary>
        static void AppendPartialArcQuadrant(List<XPoint> points, double x, double y, double width, double height, double α, double β, PathStart pathStart, XMatrix matrix)
        {
            Debug.Assert(α >= 0 && α <= 360);
            Debug.Assert(β >= 0);
            if (β > 360)
                β = β - Math.Floor(β / 360) * 360;
            Debug.Assert(Math.Abs(α - β) <= 90);

            // Scanling factor.
            double δx = width / 2;
            double δy = height / 2;

            // Center of ellipse.
            double x0 = x + δx;
            double y0 = y + δy;

            // We have the following quarters:
            //     |
            //   2 | 3
            // ----+-----
            //   1 | 0
            //     |
            // If the angles lie in quarter 2 or 3, their values are subtracted by 180 and the
            // resulting curve is reflected at the center. This algorithm works as expected (simply tried out).
            // There may be a mathematically more elegant solution...
            bool reflect = false;
            if (α >= 180 && β >= 180)
            {
                α -= 180;
                β -= 180;
                reflect = true;
            }

            double cosα, cosβ, sinα, sinβ;
            if (width == height)
            {
                // Circular arc needs no correction.
                α = α * Calc.Deg2Rad;
                β = β * Calc.Deg2Rad;
            }
            else
            {
                // Elliptic arc needs the angles to be adjusted such that the scaling transformation is compensated.
                α = α * Calc.Deg2Rad;
                sinα = Math.Sin(α);
                if (Math.Abs(sinα) > 1E-10)
                    α = Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα));
                β = β * Calc.Deg2Rad;
                sinβ = Math.Sin(β);
                if (Math.Abs(sinβ) > 1E-10)
                    β = Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ));
            }

            double κ = 4 * (1 - Math.Cos((α - β) / 2)) / (3 * Math.Sin((β - α) / 2));
            sinα = Math.Sin(α);
            cosα = Math.Cos(α);
            sinβ = Math.Sin(β);
            cosβ = Math.Cos(β);

            //XPoint pt1, pt2, pt3;
            if (!reflect)
            {
                // Calculation for quarter 0 and 1.
                switch (pathStart)
                {
                    case PathStart.MoveTo1st:
                        points.Add(matrix.Transform(new XPoint(x0 + δx * cosα, y0 + δy * sinα)));
                        break;

                    case PathStart.LineTo1st:
                        points.Add(matrix.Transform(new XPoint(x0 + δx * cosα, y0 + δy * sinα)));
                        break;

                    case PathStart.Ignore1st:
                        break;
                }
                points.Add(matrix.Transform(new XPoint(x0 + δx * (cosα - κ * sinα), y0 + δy * (sinα + κ * cosα))));
                points.Add(matrix.Transform(new XPoint(x0 + δx * (cosβ + κ * sinβ), y0 + δy * (sinβ - κ * cosβ))));
                points.Add(matrix.Transform(new XPoint(x0 + δx * cosβ, y0 + δy * sinβ)));
            }
            else
            {
                // Calculation for quarter 2 and 3.
                switch (pathStart)
                {
                    case PathStart.MoveTo1st:
                        points.Add(matrix.Transform(new XPoint(x0 - δx * cosα, y0 - δy * sinα)));
                        break;

                    case PathStart.LineTo1st:
                        points.Add(matrix.Transform(new XPoint(x0 - δx * cosα, y0 - δy * sinα)));
                        break;

                    case PathStart.Ignore1st:
                        break;
                }
                points.Add(matrix.Transform(new XPoint(x0 - δx * (cosα - κ * sinα), y0 - δy * (sinα + κ * cosα))));
//.........这里部分代码省略.........
开发者ID:Core2D,项目名称:PDFsharp,代码行数:101,代码来源:GeometryHelper.cs

示例15: ScaleTransform

 /// <summary>
 /// Applies the specified scaling operation to the transformation matrix of this object
 /// in the specified order.
 /// </summary>
 public void ScaleTransform(double scaleXY, XMatrixOrder order)
 {
   //XMatrix matrix = this.transform;
   //matrix.Scale(scaleXY, scaleXY, order);
   //Transform = matrix;
   XMatrix matrix = new XMatrix();  //XMatrix.Identity;
   matrix.ScalePrepend(scaleXY, scaleXY);
   AddTransform(matrix, order);
 }
开发者ID:Davincier,项目名称:openpetra,代码行数:13,代码来源:XGraphics.cs


注:本文中的PdfSharp.Drawing.XMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。