Example #1
0
 internal static object Box(FillRule value) 
 { 
     if (value == FillRule.Nonzero)
     { 
         return NonzeroBox;
     }
     else
     { 
         return EvenOddBox;
     } 
 } 
 public static Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule ConvertFillRule(FillRule fillRule)
 {
     switch (fillRule)
     {
         case FillRule.EvenOdd:
             return Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule.EvenOdd;
         case FillRule.Nonzero:
             return Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule.Nonzero;
         default:
             throw new NotSupportedException(String.Format("Not supported fill rule: {0}", fillRule));
     }
 }
        internal PathStreamGeometryContext(FillRule fillRule, 
                                           Transform transform)
        { 
            _pathGeometry = new PathGeometry(); 

            if (fillRule != s_defaultFillRule) 
            {
                _pathGeometry.FillRule = fillRule;
            }
 
            if ((transform != null) && !transform.IsIdentity)
            { 
                _pathGeometry.Transform = transform.Clone(); 
            }
        } 
 public IPathGeometry CreatePathGeometry(ITransform?transform, IEnumerable <IPathFigure> figures, FillRule fillRule) => throw new NotImplementedException();
Example #5
0
        private void ParseString(string pathAsString)
        {
            //TODO: in this, make a list of the actions to execute on the context, which will be kept. For performance, do not create the Figures while parsing, it should only be made when the user tries to access them.
            int        currentIndex              = 0;
            int        length                    = pathAsString.Length;
            Point      lastAbsolutePosition      = new Point();
            Point      lastStartAbsolutePosition = new Point();
            bool       lastIsCubicBezier         = false;
            bool       lastIsQuadraticBezier     = false;
            Point      lastBezierControlPoint    = new Point();
            PathFigure currentFigure             = null;
            char       c = ' ';

            Figures = new PathFigureCollection();

            while (currentIndex < length)
            {
                while (currentIndex < length && ((c = pathAsString[currentIndex]) == ' '))
                {
                    currentIndex++;
                }
                currentIndex++;
                bool relative = char.IsLower(c);

#if !BRIDGE
                switch (char.ToUpperInvariant(c)) //ToUpperInvariant so that we can handle both uppercase and lowercase in the same case in the switch.
#else
                switch (char.ToUpper(c))          //BRIDGETODO : verify this code matchs the code above
#endif
                {
                case 'F':
                    c = pathAsString[currentIndex];
                    if (c == '0')
                    {
                        FillRule = FillRule.EvenOdd;
                    }
                    else if (c == '1')
                    {
                        FillRule = FillRule.Nonzero;
                    }
                    else
                    {
                        FillRule = FillRule.EvenOdd;
                    }

                    currentIndex++;
                    c = pathAsString[currentIndex];
                    break;

                case 'M':     //move the start of a path figure to a specified position

                    if (currentFigure != null)
                    {
                        Figures.Add(currentFigure);
                    }

                    //we get the point for the move command:
                    Point point = GetPoint(pathAsString, currentIndex, out currentIndex);
                    if (relative)
                    {
                        //we translate the relative coordinates into absolute coordinates:
                        point.X = point.X + lastAbsolutePosition.X;
                        point.Y = point.Y + lastAbsolutePosition.Y;
                    }

                    //we remember this figure's starting position in case it needs to be closed:
                    lastStartAbsolutePosition.X = point.X;
                    lastStartAbsolutePosition.Y = point.Y;

                    //we create the new figure, which will start from the given point, and add it to this.Figures
                    currentFigure            = new PathFigure();
                    currentFigure.Segments   = new PathSegmentCollection();
                    currentFigure.StartPoint = point;

                    //we remember the last position for the case where the next command is in relative coordinates.
                    lastAbsolutePosition.X = point.X;
                    lastAbsolutePosition.Y = point.Y;

                    //if this is followed by points, we should make lines to these:
                    ReadLines(pathAsString, ref currentIndex, ref lastAbsolutePosition, currentFigure, relative);

                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;


                    break;

                case 'L':                      //line to a specified position
                    if (currentFigure == null) //todo: remove all these tests (I assumed a move command was necessary but it apparently isn't)
                    {
                        throw new FormatException("Path badly formatted: a move command is required before any draw command.");
                    }
                    ReadLines(pathAsString, ref currentIndex, ref lastAbsolutePosition, currentFigure, relative);
                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;
                    break;

                case 'H':     //horizontal line to a specified position
                    if (currentFigure == null)
                    {
                        throw new FormatException("Path badly formatted: a move command is required before any draw command.");
                    }
                    List <double> numbersForH = ReadNumbers(pathAsString, ref currentIndex);
                    if (numbersForH.Count == 0)
                    {
                        throw new FormatException("String Badly formatted: you cannot have the H or h draw command followed with no numbers.");
                    }
                    PolyLineSegment polyLineSegmentForH = new PolyLineSegment();
                    polyLineSegmentForH.Points = new PointCollection();
                    double Y = lastAbsolutePosition.Y;
                    foreach (double number in numbersForH)
                    {
                        double newX = number;
                        if (relative)
                        {
                            newX += lastAbsolutePosition.X;
                        }
                        polyLineSegmentForH.Points.Add(new Point(newX, Y));
                        lastAbsolutePosition.X = newX;
                    }
                    currentFigure.Segments.Add(polyLineSegmentForH);

                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;
                    break;

                case 'V':     //vertical line to a specified position
                    if (currentFigure == null)
                    {
                        throw new FormatException("Path badly formatted: a move command is required before any draw command.");
                    }
                    List <double> numbersForV = ReadNumbers(pathAsString, ref currentIndex);
                    if (numbersForV.Count == 0)
                    {
                        throw new FormatException("String Badly formatted: you cannot have the H or h draw command followed with no numbers.");
                    }
                    PolyLineSegment polyLineSegmentForV = new PolyLineSegment();
                    polyLineSegmentForV.Points = new PointCollection();
                    double X = lastAbsolutePosition.X;
                    foreach (double number in numbersForV)
                    {
                        double newY = number;
                        if (relative)
                        {
                            newY += lastAbsolutePosition.Y;
                        }
                        polyLineSegmentForV.Points.Add(new Point(X, newY));
                        lastAbsolutePosition.Y = newY;
                    }
                    currentFigure.Segments.Add(polyLineSegmentForV);
                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;
                    break;

                case 'C':     //cubic bezier curve
                    while (true)
                    {
                        while (currentIndex < length && pathAsString[currentIndex] == ' ')
                        {
                            ++currentIndex;
                        }
                        if (currentIndex < length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                        {
                            Point controlPoint1 = GetPoint(pathAsString, currentIndex, out currentIndex);
                            Point controlPoint2 = GetPoint(pathAsString, currentIndex, out currentIndex);
                            Point endPoint      = GetPoint(pathAsString, currentIndex, out currentIndex);
                            if (relative)
                            {
                                controlPoint1.X += lastAbsolutePosition.X;
                                controlPoint1.Y += lastAbsolutePosition.Y;
                                controlPoint2.X += lastAbsolutePosition.X;
                                controlPoint2.Y += lastAbsolutePosition.Y;
                                endPoint.X      += lastAbsolutePosition.X;
                                endPoint.Y      += lastAbsolutePosition.Y;
                            }
                            BezierSegment bezierSegment = new BezierSegment();     //note: we do not use polyBezierSegment yet because I don't really know how it works.
                            bezierSegment.Point1   = controlPoint1;
                            bezierSegment.Point2   = controlPoint2;
                            bezierSegment.Point3   = endPoint;
                            lastBezierControlPoint = controlPoint2;
                            lastIsCubicBezier      = true;
                            currentFigure.Segments.Add(bezierSegment);
                            lastAbsolutePosition.X = endPoint.X;
                            lastAbsolutePosition.Y = endPoint.Y;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastIsQuadraticBezier = false;
                    break;

                case 'S':     //smooth cubic bezier curve
                    while (true)
                    {
                        while (currentIndex < length && pathAsString[currentIndex] == ' ')
                        {
                            ++currentIndex;
                        }
                        if (currentIndex < length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                        {
                            Point controlPoint1 = new Point();
                            if (!lastIsCubicBezier)
                            {
                                controlPoint1 = new Point(lastAbsolutePosition.X, lastAbsolutePosition.Y);
                            }
                            else
                            {
                                Point diffPoint = new Point(lastAbsolutePosition.X - lastBezierControlPoint.X, lastAbsolutePosition.Y - lastBezierControlPoint.Y);
                                controlPoint1 = new Point(lastAbsolutePosition.X + diffPoint.X, lastAbsolutePosition.Y + diffPoint.Y);
                            }
                            Point controlPoint2 = GetPoint(pathAsString, currentIndex, out currentIndex);
                            Point endPoint      = GetPoint(pathAsString, currentIndex, out currentIndex);
                            if (relative)
                            {
                                controlPoint2.X += lastAbsolutePosition.X;
                                controlPoint2.Y += lastAbsolutePosition.Y;
                                endPoint.X      += lastAbsolutePosition.X;
                                endPoint.Y      += lastAbsolutePosition.Y;
                            }
                            BezierSegment bezierSegment = new BezierSegment();     //note: we do not use polyBezierSegment yet because I don't really know how it works.
                            bezierSegment.Point1   = controlPoint1;
                            bezierSegment.Point2   = controlPoint2;
                            bezierSegment.Point3   = endPoint;
                            lastBezierControlPoint = controlPoint2;
                            lastIsCubicBezier      = true;
                            currentFigure.Segments.Add(bezierSegment);
                            lastAbsolutePosition.X = endPoint.X;
                            lastAbsolutePosition.Y = endPoint.Y;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastIsQuadraticBezier = false;
                    break;

                case 'Q':     //quadratic bezier
                    while (true)
                    {
                        while (currentIndex < length && pathAsString[currentIndex] == ' ')
                        {
                            ++currentIndex;
                        }
                        if (currentIndex < length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                        {
                            Point controlPoint1 = GetPoint(pathAsString, currentIndex, out currentIndex);

                            Point endPoint = GetPoint(pathAsString, currentIndex, out currentIndex);
                            if (relative)
                            {
                                controlPoint1.X += lastAbsolutePosition.X;
                                controlPoint1.Y += lastAbsolutePosition.Y;
                                endPoint.X      += lastAbsolutePosition.X;
                                endPoint.Y      += lastAbsolutePosition.Y;
                            }
                            QuadraticBezierSegment bezierSegment = new QuadraticBezierSegment();
                            bezierSegment.Point1 = controlPoint1;
                            bezierSegment.Point2 = endPoint;
                            currentFigure.Segments.Add(bezierSegment);
                            lastAbsolutePosition.X = endPoint.X;
                            lastAbsolutePosition.Y = endPoint.Y;
                            //we remember the position if the next segment is a smooth quadratic bezier segment.
                            lastBezierControlPoint.X = controlPoint1.X;
                            lastBezierControlPoint.Y = controlPoint1.Y;
                            lastIsCubicBezier        = false;
                            lastIsQuadraticBezier    = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastIsCubicBezier = false;
                    break;

                case 'T':     //smooth quadratic bezier curve
                    while (true)
                    {
                        while (currentIndex < length && pathAsString[currentIndex] == ' ')
                        {
                            ++currentIndex;
                        }
                        if (currentIndex < length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                        {
                            Point controlPoint1 = new Point();
                            if (!lastIsQuadraticBezier)
                            {
                                controlPoint1 = new Point(lastAbsolutePosition.X, lastAbsolutePosition.Y);
                            }
                            else
                            {
                                Point diffPoint = new Point(lastAbsolutePosition.X - lastBezierControlPoint.X, lastAbsolutePosition.Y - lastBezierControlPoint.Y);
                                controlPoint1 = new Point(lastAbsolutePosition.X + diffPoint.X, lastAbsolutePosition.Y + diffPoint.Y);
                            }
                            Point endPoint = GetPoint(pathAsString, currentIndex, out currentIndex);
                            if (relative)
                            {
                                endPoint.X += lastAbsolutePosition.X;
                                endPoint.Y += lastAbsolutePosition.Y;
                            }
                            QuadraticBezierSegment bezierSegment = new QuadraticBezierSegment();
                            bezierSegment.Point1 = controlPoint1;
                            bezierSegment.Point2 = endPoint;
                            currentFigure.Segments.Add(bezierSegment);
                            lastAbsolutePosition.X = endPoint.X;
                            lastAbsolutePosition.Y = endPoint.Y;

                            //we remember the position if the next segment is a smooth quadratic bezier segment.
                            lastBezierControlPoint.X = controlPoint1.X;
                            lastBezierControlPoint.Y = controlPoint1.Y;
                            lastIsCubicBezier        = false;
                            lastIsQuadraticBezier    = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastIsCubicBezier = false;
                    break;

                case 'A':
                    //we ignore this one since we cannot handle it yet
                    //todo: remove the following once arcs will be supported:
                    //if (!CSharpXamlForHtml5.Environment.IsRunningInJavaScript)
                    //{
                    //    if (!_messageAboutArcsAlreadyShown)
                    //    {
                    //        //MessageBox.Show("Arcs are not supported yet. It has been replaced with a line.");
                    //        global::System.Diagnostics.Debug.WriteLine("Arcs are not supported yet. The arc has been replaced with a line.");
                    //        _messageAboutArcsAlreadyShown = true;
                    //    }
                    //}

                    while (true)
                    {
                        while (currentIndex < length && pathAsString[currentIndex] == ' ')
                        {
                            ++currentIndex;
                        }
                        if (currentIndex < length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                        {
                            ArcSegment arc = new ArcSegment();

                            double pointForArcX = GetNextNumber(pathAsString, currentIndex, out currentIndex);
                            double pointForArcY = GetNextNumber(pathAsString, currentIndex, out currentIndex);
                            arc.Size = new Size(pointForArcX, pointForArcY);

                            arc.RotationAngle  = GetNextNumber(pathAsString, currentIndex, out currentIndex);
                            arc.IsLargeArc     = GetNextNumber(pathAsString, currentIndex, out currentIndex) == 1 ? true : false;
                            arc.SweepDirection = GetNextNumber(pathAsString, currentIndex, out currentIndex) == 1 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;

                            pointForArcX = GetNextNumber(pathAsString, currentIndex, out currentIndex);
                            pointForArcY = GetNextNumber(pathAsString, currentIndex, out currentIndex);
                            Point endPoint = new Point(pointForArcX, pointForArcY);
                            if (relative)
                            {
                                endPoint.X += lastAbsolutePosition.X;
                                endPoint.Y += lastAbsolutePosition.Y;
                            }
                            arc.Point = endPoint;
                            lastAbsolutePosition.X = endPoint.X;
                            lastAbsolutePosition.Y = endPoint.Y;
                            ////todo: remove the following lines and add the arc itself to the figure, instead of the replacement line.
                            //LineSegment replacementLine = new LineSegment();
                            //replacementLine.Point = endPoint;


                            //currentFigure.Segments.Add(replacementLine);
                            currentFigure.Segments.Add(arc);
                        }
                        else
                        {
                            break;
                        }
                    }
                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;
                    break;

                case 'Z':
                    currentFigure.IsClosed = true;
                    lastAbsolutePosition.X = lastStartAbsolutePosition.X;
                    lastAbsolutePosition.Y = lastStartAbsolutePosition.Y;
                    Figures.Add(currentFigure);
                    currentFigure         = null; //so that we do not add it again when reaching a Move command for the next figure.
                    lastIsCubicBezier     = false;
                    lastIsQuadraticBezier = false;
                    break;

                default:
                    break;
                }
            }
            if (currentFigure != null)
            {
                Figures.Add(currentFigure);
            }
        }
Example #6
0
        public bool Equals([AllowNull] NewShape other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return((Line == other.Line && Line != null && other.Line != null && Line.Equals(other.Line)) &&
                   (FillColor == other.FillColor && FillColor != null && other.FillColor != null && FillColor.Equals(other.FillColor)) &&
                   (FillRule == other.FillRule && FillRule != null && other.FillRule != null && FillRule.Equals(other.FillRule)) &&
                   (Opacity == other.Opacity && Opacity != null && other.Opacity != null && Opacity.Equals(other.Opacity)) &&
                   (Layer == other.Layer && Layer != null && other.Layer != null && Layer.Equals(other.Layer)) &&
                   (DrawDirection == other.DrawDirection && DrawDirection != null && other.DrawDirection != null && DrawDirection.Equals(other.DrawDirection)));
        }
Example #7
0
 public void ClipRule(FillRule value)
 {
   _NativeInstance.ClipRule(value);
 }
Example #8
0
 public static PathGeometry Geometry(this PathGeometry path, PathFigureCollection collection, FillRule fillRule)
 {
     return(path.Figures(collection).FillRule(fillRule));
 }
Example #9
0
        public IPathGeometry CreatePathGeometry(ITransform?transformInterface, IEnumerable <IPathFigure> figures, FillRule fillRule)
        {
            var pathGeometry = new PathGeometry()
            {
                FillRule = fillRule
            };

            if (transformInterface != null)
            {
                if (!(transformInterface is Transform transform))
                {
                    throw new InvalidOperationException($"Transforms should all be of type {nameof(Transform)}");
                }

                pathGeometry.Transform = transform;
            }

            XGraphicsCollection <PathFigure> destinationFigures = pathGeometry.Figures;

            foreach (IPathFigure pathFigureInterface in figures)
            {
                if (!(pathFigureInterface is PathFigure pathFigure))
                {
                    throw new InvalidOperationException($"{nameof(CreatePathGeometry)} figures should all be of type {nameof(PathFigure)}");
                }

                destinationFigures.Add(pathFigure);
            }

            return(pathGeometry);
        }
Example #10
0
 public void FillRule(FillRule value)
 {
   IntPtr exception = IntPtr.Zero;
   #if ANYCPU
   if (NativeLibrary.Is64Bit)
   #endif
   #if WIN64 || ANYCPU
   NativeMethods.X64.DrawingWand_FillRule(Instance, (UIntPtr)value, out exception);
   #endif
   #if ANYCPU
   else
   #endif
   #if !WIN64 || ANYCPU
   NativeMethods.X86.DrawingWand_FillRule(Instance, (UIntPtr)value, out exception);
   #endif
   CheckException(exception);
 }
 internal unsafe static extern int MilUtility_PathGeometryHitTestPathGeometry(
     MilMatrix3x2D *pMatrix1,
     FillRule fillRule1,
     byte *pPathData1,
     UInt32 nSize1,
     MilMatrix3x2D *pMatrix2,
     FillRule fillRule2,
     byte *pPathData2,
     UInt32 nSize2,
     double rTolerance,
     bool fRelative,
     IntersectionDetail* pDetail);
 public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList <Geometry> children) => throw new NotImplementedException();
 internal unsafe static extern int MilUtility_GetPointAtLengthFraction(
     MilMatrix3x2D *pMatrix,
     FillRule fillRule,
     byte *pPathData,
     UInt32 nSize,
     double rFraction,
     out Point pt,
     out Point vecTangent);
 internal unsafe static extern int MilUtility_PathGeometryHitTest(
     MilMatrix3x2D *pMatrix,
     MIL_PEN_DATA* pPenData,
     double* pDashArray,
     FillRule fillRule,
     byte *pPathData,
     UInt32 nSize,
     double rTolerance,
     bool fRelative,
     Point* pHitPoint,
     out bool pDoesContain);
 public void SetFillRule(FillRule fillRule)
 {
     _target.FillRule = fillRule;
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="figures">A collection of figures</param>
        /// <param name="fillRule">The fill rule (OddEven or NonZero)</param>
        /// <param name="transform">A transformation to apply to the input</param>
        public PathGeometry(IEnumerable<PathFigure> figures, FillRule fillRule, Transform transform)
        {
            Transform = transform;
            if (ValidateEnums.IsFillRuleValid(fillRule))
            {
                FillRule = fillRule;

                if (figures != null)
                {
                    foreach (PathFigure item in figures)
                    {
                        Figures.Add(item);
                    }
                }
                else
                {
                    throw new ArgumentNullException("figures");
                }

                SetDirty();
            }
        }
 public void SetFillRule(FillRule fillRule)
 {
     _path.FillType = fillRule == FillRule.EvenOdd ? SKPathFillType.EvenOdd : SKPathFillType.Winding;
 }
 public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList <Geometry> children)
 {
     return(new GeometryGroupImpl(fillRule, children));
 }
Example #19
0
        /// <summary>
        /// Returns a path geometry
        /// </summary>
        /// <param name="fillRule">FillRule</param>
        /// <param name="startPoint">Start point</param>
        /// <param name="pathGeometryParams">List of path geometry parameters</param>
        /// <returns>PathGeometry</returns>
        private static PathGeometry GetPathGeometryFromList(FillRule fillRule, Point startPoint, List<PathGeometryParams> pathGeometryParams, Boolean isClosed)
        {
            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry.FillRule = fillRule;
            pathGeometry.Figures = new PathFigureCollection();

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = startPoint;
            pathFigure.Segments = new PathSegmentCollection();
            pathFigure.IsClosed = isClosed;

            foreach (PathGeometryParams param in pathGeometryParams)
            {
                switch (param.GetType().Name)
                {
                    case "LineSegmentParams":
                        LineSegment lineSegment = new LineSegment();
                        lineSegment.Point = param.EndPoint;
                        pathFigure.Segments.Add(lineSegment);
                        break;

                    case "ArcSegmentParams":
                        ArcSegment arcSegment = new ArcSegment();

                        arcSegment.Point = param.EndPoint;
                        arcSegment.IsLargeArc = (param as ArcSegmentParams).IsLargeArc;
                        arcSegment.RotationAngle = (param as ArcSegmentParams).RotationAngle;
                        arcSegment.SweepDirection = (param as ArcSegmentParams).SweepDirection;
                        arcSegment.Size = (param as ArcSegmentParams).Size;
                        pathFigure.Segments.Add(arcSegment);

                        break;
                }
            }

            pathGeometry.Figures.Add(pathFigure);

            return pathGeometry;
        }
Example #20
0
        internal static PathGeometry InternalCombine(
            Geometry geometry1,
            Geometry geometry2,
            GeometryCombineMode mode,
            Transform transform,
            double tolerance,
            ToleranceType type)
        {
            PathGeometry resultGeometry = null;

            unsafe
            {
                MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(transform);

                PathGeometryData data1 = geometry1.GetPathGeometryData();
                PathGeometryData data2 = geometry2.GetPathGeometryData();

                fixed(byte *pPathData1 = data1.SerializedData)
                {
                    Debug.Assert(pPathData1 != (byte *)0);

                    fixed(byte *pPathData2 = data2.SerializedData)
                    {
                        Debug.Assert(pPathData2 != (byte *)0);

                        FillRule fillRule = FillRule.Nonzero;

                        FigureList list = new FigureList();
                        int        hr   = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryCombine(
                            &matrix,
                            &data1.Matrix,
                            data1.FillRule,
                            pPathData1,
                            data1.Size,
                            &data2.Matrix,
                            data2.FillRule,
                            pPathData2,
                            data2.Size,
                            tolerance,
                            type == ToleranceType.Relative,
                            new AddFigureToListDelegate(list.AddFigureToList),
                            mode,
                            out fillRule);

                        if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                        {
                            // When we encounter NaNs in the renderer, we absorb the error and draw
                            // nothing. To be consistent, we return an empty geometry.
                            resultGeometry = new PathGeometry();
                        }
                        else
                        {
                            HRESULT.Check(hr);

                            resultGeometry = new PathGeometry(list.Figures, fillRule, null);
                        }
                    }
                }
            }

            return(resultGeometry);
        }
 internal unsafe static extern int MilUtility_PathGeometryWiden( 
     MIL_PEN_DATA *pPenData,
     double *pDashArray,
     MilMatrix3x2D* pMatrix,
     FillRule fillRule, 
     byte* pPathData,
     UInt32 nSize, 
     double rTolerance, 
     bool fRelative,
     Delegate addFigureCallback, 
     out FillRule widenedFillRule);
 internal unsafe static extern int MilUtility_GeometryGetArea(
     FillRule fillRule,
     byte *pPathData,
     UInt32 nSize,
     MilMatrix3x2D *pMatrix,
     double rTolerance,
     bool fRelative,
     double* pArea);
Example #23
0
	/// <summary>
	/// <para>Construct a new <see cref="T:Xsharp.Region"/>
	/// instance that is initially set to a polygon.</para>
	/// </summary>
	///
	/// <param name="points">
	/// <para>An array of points that defines the polygon.</para>
	/// </param>
	///
	/// <param name="fillRule">
	/// <para>The area fill rule to use for the polygon.</para>
	/// </param>
	///
	/// <exception cref="T:System.ArgumentNullException">
	/// <para>Raised if <paramref name="points"/> is <see langword="null"/>.
	/// </para>
	/// </exception>
	///
	/// <exception cref="T:System.ArgumentOutOfRangeException">
	/// <para>Raised if <paramref name="points"/> has less than 3
	/// elements.</para>
	/// </exception>
	///
	/// <exception cref="T:Xsharp.XException">
	/// <para>Raised if any of the elements in <paramref name="points"/>
	/// has co-ordinates that are out of range, or if
	/// <paramref name="fillRule"/> is invalid.</para>
	/// </exception>
	public Region(Point[] points, FillRule fillRule)
			{
				// Validate the parameters.
				if(points == null)
				{
					throw new ArgumentNullException("points");
				}
				else if(points.Length < 3)
				{
					throw new ArgumentOutOfRangeException
						("points", S._("X_PolygonNeeds3Pts"));
				}

				// Convert "points" into an "XPoint[]" array.
				XPoint[] pts = new XPoint [points.Length];
				try
				{
					checked
					{
						for(int index = 0; index < points.Length; ++index)
						{
							pts[index].x = (short)(points[index].x);
							pts[index].y = (short)(points[index].y);
						}
					}
				}
				catch(OverflowException)
				{
					throw new XException(S._("X_PointCoordRange"));
				}

				// Validate the fill rule.
				if(fillRule != FillRule.EvenOddRule &&
				   fillRule != FillRule.WindingRule)
				{
					throw new XException
						(String.Format(S._("X_FillRule"), (int)fillRule));
				}

				// Create the polygon region.
				lock(typeof(Region))
				{
					region = Xlib.XPolygonRegion(pts, pts.Length,
												 (int)fillRule);
					if(region == IntPtr.Zero)
					{
						Display.OutOfMemory();
					}
				}
			}
Example #24
0
        /// <summary>
        /// Sets path's winding rule (default is EvenOdd). You should call this method before any calls to BeginFigure. If you wonder why, ask Direct2D guys about their design decisions.
        /// </summary>
        /// <param name="fillRule"></param>

        public void SetFillRule(FillRule fillRule)
        {
            _impl.SetFillRule(fillRule);
        }
Example #25
0
		public PathGeometry (IEnumerable<PathFigure> figures, FillRule fillRule, Transform transform)
		{
			Figures = new PathFigureCollection (figures);
			FillRule = fillRule;
			Transform = transform;
		}
 internal unsafe static extern int MilUtility_PathGeometryBounds( 
     MIL_PEN_DATA *pPenData, 
     double *pDashArray,
     MilMatrix3x2D* pWorldMatrix, 
     FillRule fillRule,
     byte* pPathData,
     UInt32 nSize,
     MilMatrix3x2D* pGeometryMatrix, 
     double rTolerance,
     bool fRelative, 
     bool fSkipHollows, 
     MilRectD* pBounds);
Example #27
0
 public void SetFillRule(FillRule fillRule)
 {
     _geometryImpl.FillRule = fillRule;
 }
 internal unsafe static extern int MilGlyphRun_GetGlyphOutline(
     IntPtr pFontFace, 
     ushort glyphIndex, 
     bool sideways,
     double renderingEmSize, 
     out byte* pPathGeometryData,
     out UInt32 pSize,
     out FillRule pFillRule
     ); 
 private static bool FillRuleToBool(FillRule fill)
 {
     if (fill == FillRule.EvenOdd)
         return false;
     else
         return true;
 }
Example #30
0
 public static PathGeometry FillRule(this PathGeometry path, FillRule fillRule)
 {
     path.FillRule = fillRule;
     return(path);
 }
 internal void SetFillRule(FillRule fillRule)
 public void SetFillRule(FillRule fillRule)
 {
     _pathGeometry.FillRule = fillRule;
 }
Example #33
0
        /// <summary>
        /// Given a mini-language representation of a Geometry - write it to the supplied StreamGeometryContext
        /// </summary>
        /// <param name="context">context </param>
        /// <param name="pathString">path to parse</param>
        /// <param name="fillRule">returned fill rule, if the string contains a fill rule set explicitly at the beginning</param>
        private static void ParseStringToStreamGeometryContext(StreamGeometryContext context, string pathString, ref FillRule fillRule)
        {
            // Check to ensure that there's something to parse
            if (pathString == null)
            {
                return;
            }

            int curIndex = 0;

            // skip any leading space
            while ((curIndex < pathString.Length) && Char.IsWhiteSpace(pathString, curIndex))
            {
                curIndex++;
            }

            // Is there anything to look at?
            if (curIndex < pathString.Length)
            {
                // If so, we only care if the first non-WhiteSpace char encountered is 'F'
                if (pathString[curIndex] == 'F')
                {
                    curIndex++;

                    // Since we found 'F' the next non-WhiteSpace char must be 0 or 1 - look for it.
                    while ((curIndex < pathString.Length) && Char.IsWhiteSpace(pathString, curIndex))
                    {
                        curIndex++;
                    }

                    // If we ran out of text, this is an error, because 'F' cannot be specified without 0 or 1
                    // Also, if the next token isn't 0 or 1, this too is illegal
                    if ((curIndex == pathString.Length) ||
                        ((pathString[curIndex] != '0') &&
                         (pathString[curIndex] != '1')))
                    {
                        throw new FormatException("Token is not valid.");
                    }

                    fillRule = pathString[curIndex] == '0' ? FillRule.EvenOdd : FillRule.Nonzero;

                    // Increment curIndex to point to the next char
                    curIndex++;
                }
            }

            AbbreviatedGeometryParser parser = new AbbreviatedGeometryParser(pathString);

            parser.ParseToGeometryContext(context, curIndex);
        }
Example #34
0
 winMedia.FillRule ConvertFillRule(FillRule fillRule)
 {
     return(fillRule == FillRule.EvenOdd ? winMedia.FillRule.EvenOdd : winMedia.FillRule.Nonzero);
 }
 public DrawableFillRule(FillRule fillRule)
     : base(AssemblyHelper.CreateInstance(Types.DrawableFillRule, new Type[] { Types.FillRule }, fillRule))
 {
 }
Example #36
0
 ///<summary>
 /// Creates a new DrawableFillRule instance.
 ///</summary>
 ///<param name="fillRule">The rule to use when filling drawn objects.</param>
 public DrawableFillRule(FillRule fillRule)
 {
   FillRule = fillRule;
 }
Example #37
0
        private void ExecuteDrawableFillRule(XmlElement element, Collection <IDrawable> drawables)
        {
            FillRule fillRule_ = Variables.GetValue <FillRule>(element, "fillRule");

            drawables.Add(new DrawableFillRule(fillRule_));
        }
 public static extern Status XSetFillRule(IntPtr display, IntPtr gc, FillRule fill_rule);
 public void SetFillRule(FillRule fillRule)
 {
 }
Example #40
0
        //
        // Given a mini-language representation of a Geometry - write it to the 
        // supplied streamgeometrycontext
        // 

        private static void ParseStringToStreamGeometryContext ( 
            StreamGeometryContext context, 
            string pathString,
            IFormatProvider formatProvider, 
#if PRESENTATION_CORE            
            ref FillRule fillRule 
#else            
            ref bool fillRule 
Example #41
0
        /// <summary>
        /// Parses the specified path data and writes the result to the geometryContext of this instance.
        /// </summary>
        /// <param name="s">The path data.</param>
        public void Parse(string s, ref FillRule fillRule)         // Uno specific: FillRule parameter.
        {
            var span = s.AsSpan();

            _currentPoint = new Point();

            while (!span.IsEmpty)
            {
                if (!ReadCommand(ref span, out var command, out var relative))
                {
                    break;
                }

                bool initialCommand = true;

                do
                {
                    if (!initialCommand)
                    {
                        span = ReadSeparator(span);
                    }

                    switch (command)
                    {
                    case Command.None:
                        break;

                    case Command.FillRule:
                        // Uno specific:
                        fillRule = GetFillRule(ref span);
                        break;

                    case Command.Move:
                        AddMove(ref span, relative);
                        break;

                    case Command.Line:
                        AddLine(ref span, relative);
                        break;

                    case Command.HorizontalLine:
                        AddHorizontalLine(ref span, relative);
                        break;

                    case Command.VerticalLine:
                        AddVerticalLine(ref span, relative);
                        break;

                    case Command.CubicBezierCurve:
                        AddCubicBezierCurve(ref span, relative);
                        break;

                    case Command.QuadraticBezierCurve:
                        AddQuadraticBezierCurve(ref span, relative);
                        break;

                    case Command.SmoothCubicBezierCurve:
                        AddSmoothCubicBezierCurve(ref span, relative);
                        break;

                    case Command.SmoothQuadraticBezierCurve:
                        AddSmoothQuadraticBezierCurve(ref span, relative);
                        break;

                    case Command.Arc:
                        AddArc(ref span, relative);
                        break;

                    case Command.Close:
                        CloseFigure();
                        break;

                    default:
                        throw new NotSupportedException("Unsupported command");
                    }

                    initialCommand = false;
                } while (PeekArgument(span));
            }

            if (_isOpen)
            {
                // Uno specific: EndFigure → SetClosedState
                _geometryContext.SetClosedState(false);
            }
        }
Example #42
0
 static WMedia.FillRule ConvertFillRule(FillRule fillRule)
 {
     return(fillRule == FillRule.EvenOdd ? WMedia.FillRule.EvenOdd : WMedia.FillRule.Nonzero);
 }
Example #43
0
        public virtual PathGeometry GetWidenedPathGeometry(Pen pen, double tolerance, ToleranceType type)
        {
            ReadPreamble();

            if (pen == null)
            {
                throw new System.ArgumentNullException("pen");
            }

            if (IsObviouslyEmpty())
            {
                return(new PathGeometry());
            }

            PathGeometryData pathData = GetPathGeometryData();

            if (pathData.IsEmpty())
            {
                return(new PathGeometry());
            }

            PathGeometry resultGeometry = null;

            unsafe
            {
                MIL_PEN_DATA penData;
                double[]     dashArray = null;

                pen.GetBasicPenData(&penData, out dashArray);

                fixed(byte *pbPathData = pathData.SerializedData)
                {
                    Debug.Assert(pbPathData != (byte *)0);

                    FillRule fillRule = FillRule.Nonzero;

                    PathGeometry.FigureList list = new PathGeometry.FigureList();

                    // The handle to the pDashArray, if we have one.
                    // Since the dash array is optional, we may not need to Free it.
                    GCHandle handle = new GCHandle();

                    // Pin the pDashArray, if we have one.
                    if (dashArray != null)
                    {
                        handle = GCHandle.Alloc(dashArray, GCHandleType.Pinned);
                    }

                    try
                    {
                        int hr = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryWiden(
                            &penData,
                            (dashArray == null) ? null : (double *)handle.AddrOfPinnedObject(),
                            &pathData.Matrix,
                            pathData.FillRule,
                            pbPathData,
                            pathData.Size,
                            tolerance,
                            type == ToleranceType.Relative,
                            new PathGeometry.AddFigureToListDelegate(list.AddFigureToList),
                            out fillRule);

                        if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                        {
                            // When we encounter NaNs in the renderer, we absorb the error and draw
                            // nothing. To be consistent, we return an empty geometry.
                            resultGeometry = new PathGeometry();
                        }
                        else
                        {
                            HRESULT.Check(hr);

                            resultGeometry = new PathGeometry(list.Figures, fillRule, null);
                        }
                    }
                    finally
                    {
                        if (handle.IsAllocated)
                        {
                            handle.Free();
                        }
                    }
                }

                return(resultGeometry);
            }
        }
Example #44
0
 /// <summary>
 /// Adds a new instance of the <see cref="DrawableFillRule" /> class to the <see cref="Drawables" />.
 /// </summary>
 /// <param name="fillRule">The rule to use when filling drawn objects.</param>
 /// <returns>The <see cref="Drawables" /> instance.</returns>
 public Drawables FillRule(FillRule fillRule)
 {
     _drawables.Add(new DrawableFillRule(fillRule));
     return(this);
 }
Example #45
0
        /// <inheritdoc />
        public bool Equals([AllowNull] Shape other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Visible == other.Visible ||
                     Visible != null &&
                     Visible.Equals(other.Visible)
                     ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     Layer == other.Layer ||
                     Layer != null &&
                     Layer.Equals(other.Layer)
                 ) &&
                 (
                     XRef == other.XRef ||
                     XRef != null &&
                     XRef.Equals(other.XRef)
                 ) &&
                 (
                     XSizeMode == other.XSizeMode ||
                     XSizeMode != null &&
                     XSizeMode.Equals(other.XSizeMode)
                 ) &&
                 (
                     XAnchor == other.XAnchor ||
                     XAnchor != null &&
                     XAnchor.Equals(other.XAnchor)
                 ) &&
                 (
                     X0 == other.X0 ||
                     X0 != null &&
                     X0.Equals(other.X0)
                 ) &&
                 (
                     X1 == other.X1 ||
                     X1 != null &&
                     X1.Equals(other.X1)
                 ) &&
                 (
                     YRef == other.YRef ||
                     YRef != null &&
                     YRef.Equals(other.YRef)
                 ) &&
                 (
                     YSizeMode == other.YSizeMode ||
                     YSizeMode != null &&
                     YSizeMode.Equals(other.YSizeMode)
                 ) &&
                 (
                     YAnchor == other.YAnchor ||
                     YAnchor != null &&
                     YAnchor.Equals(other.YAnchor)
                 ) &&
                 (
                     Y0 == other.Y0 ||
                     Y0 != null &&
                     Y0.Equals(other.Y0)
                 ) &&
                 (
                     Y1 == other.Y1 ||
                     Y1 != null &&
                     Y1.Equals(other.Y1)
                 ) &&
                 (
                     Path == other.Path ||
                     Path != null &&
                     Path.Equals(other.Path)
                 ) &&
                 (
                     Opacity == other.Opacity ||
                     Opacity != null &&
                     Opacity.Equals(other.Opacity)
                 ) &&
                 (
                     Line == other.Line ||
                     Line != null &&
                     Line.Equals(other.Line)
                 ) &&
                 (
                     FillColor == other.FillColor ||
                     FillColor != null &&
                     FillColor.Equals(other.FillColor)
                 ) &&
                 (
                     FillRule == other.FillRule ||
                     FillRule != null &&
                     FillRule.Equals(other.FillRule)
                 ) &&
                 (
                     Editable == other.Editable ||
                     Editable != null &&
                     Editable.Equals(other.Editable)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     TemplateItemName == other.TemplateItemName ||
                     TemplateItemName != null &&
                     TemplateItemName.Equals(other.TemplateItemName)
                 ));
        }
 public void SetFillRule(FillRule fillRule)
 {
 }
Example #47
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Visible != null)
         {
             hashCode = hashCode * 59 + Visible.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (Layer != null)
         {
             hashCode = hashCode * 59 + Layer.GetHashCode();
         }
         if (XRef != null)
         {
             hashCode = hashCode * 59 + XRef.GetHashCode();
         }
         if (XSizeMode != null)
         {
             hashCode = hashCode * 59 + XSizeMode.GetHashCode();
         }
         if (XAnchor != null)
         {
             hashCode = hashCode * 59 + XAnchor.GetHashCode();
         }
         if (X0 != null)
         {
             hashCode = hashCode * 59 + X0.GetHashCode();
         }
         if (X1 != null)
         {
             hashCode = hashCode * 59 + X1.GetHashCode();
         }
         if (YRef != null)
         {
             hashCode = hashCode * 59 + YRef.GetHashCode();
         }
         if (YSizeMode != null)
         {
             hashCode = hashCode * 59 + YSizeMode.GetHashCode();
         }
         if (YAnchor != null)
         {
             hashCode = hashCode * 59 + YAnchor.GetHashCode();
         }
         if (Y0 != null)
         {
             hashCode = hashCode * 59 + Y0.GetHashCode();
         }
         if (Y1 != null)
         {
             hashCode = hashCode * 59 + Y1.GetHashCode();
         }
         if (Path != null)
         {
             hashCode = hashCode * 59 + Path.GetHashCode();
         }
         if (Opacity != null)
         {
             hashCode = hashCode * 59 + Opacity.GetHashCode();
         }
         if (Line != null)
         {
             hashCode = hashCode * 59 + Line.GetHashCode();
         }
         if (FillColor != null)
         {
             hashCode = hashCode * 59 + FillColor.GetHashCode();
         }
         if (FillRule != null)
         {
             hashCode = hashCode * 59 + FillRule.GetHashCode();
         }
         if (Editable != null)
         {
             hashCode = hashCode * 59 + Editable.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (TemplateItemName != null)
         {
             hashCode = hashCode * 59 + TemplateItemName.GetHashCode();
         }
         return(hashCode);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawableFillRule"/> class.
 /// </summary>
 /// <param name="fillRule">The rule to use when filling drawn objects.</param>
 public DrawableFillRule(FillRule fillRule)
 {
     FillRule = fillRule;
 }
Example #49
0
        public static Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule ConvertFillRule(FillRule fillRule)
        {
            switch (fillRule)
            {
            case FillRule.EvenOdd:
                return(Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule.EvenOdd);

            case FillRule.Nonzero:
                return(Telerik.Windows.Documents.Fixed.Model.Graphics.FillRule.Nonzero);

            default:
                throw new NotSupportedException(String.Format("Not supported fill rule: {0}", fillRule));
            }
        }
Example #50
0
 public bool containsPoint(LDPoint pt, FillRule fillRule)
 {
     throw new NotImplementedException();
 }
Example #51
0
 // Draw a polyline.
 public static void DrawPolyline(this DrawingContext drawingContext,
                                 Brush brush, Pen pen, Point[] points, FillRule fill_rule)
 {
     drawingContext.DrawPolygonOrPolyline(brush, pen, points, fill_rule, false);
 }
		public DrawableFillRule(FillRule fillRule)
			: base(AssemblyHelper.CreateInstance(Types.DrawableFillRule, new Type[] {Types.FillRule}, fillRule))
		{
		}
Example #53
0
 public void ClipRule(FillRule value) => _nativeInstance.ClipRule(value);
 internal unsafe static extern int MilUtility_PathGeometryCombine( 
     MilMatrix3x2D* pMatrix, 
     MilMatrix3x2D* pMatrix1,
     FillRule fillRule1, 
     byte* pPathData1,
     UInt32 nSize1,
     MilMatrix3x2D* pMatrix2,
     FillRule fillRule2, 
     byte* pPathData2,
     UInt32 nSize2, 
     double rTolerance, 
     bool fRelative,
     Delegate addFigureCallback, 
     GeometryCombineMode combineMode,
     out FillRule resultFillRule);
Example #55
0
 public void FillRule(FillRule value) => _nativeInstance.FillRule(value);
 internal unsafe static extern int MilUtility_PathGeometryFlatten(
     MilMatrix3x2D* pMatrix, 
     FillRule fillRule, 
     byte* pPathData,
     UInt32 nSize, 
     double rTolerance,
     bool fRelative,
     Delegate addFigureCallback,
     out FillRule resultFillRule); 
Example #57
0
 internal void SetFillRule(FillRule fillRule)
 public void SetFillRule(FillRule fillRule)
 {
     _sink.SetFillMode(fillRule == FillRule.EvenOdd ? FillMode.Alternate : FillMode.Winding);
 }
Example #59
0
 public void FillRule(FillRule value)
 {
   _NativeInstance.FillRule(value);
 }