Exemple #1
0
        /// <summary>
        /// GetPathGeometryData - returns a struct which contains this Geometry represented
        /// as a path geometry's serialized format.
        /// </summary>
        internal override PathGeometryData GetPathGeometryData()
        {
            PathGeometryData data = new PathGeometryData();

            data.FillRule = FillRule;
            data.Matrix   = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);

            if (IsObviouslyEmpty())
            {
                return(Geometry.GetEmptyPathGeometryData());
            }

            ByteStreamGeometryContext ctx = new ByteStreamGeometryContext();

            PathFigureCollection figures = Figures;

            int figureCount = figures == null ? 0 : figures.Count;

            for (int i = 0; i < figureCount; i++)
            {
                figures.Internal_GetItem(i).SerializeData(ctx);
            }

            ctx.Close();
            data.SerializedData = ctx.GetData();

            return(data);
        }
Exemple #2
0
        /// <summary>
        /// GetPathGeometryData - returns a byte[] which contains this Geometry represented
        /// as a path geometry's serialized format.
        /// </summary>
        internal override PathGeometryData GetPathGeometryData()
        {
            if (IsObviouslyEmpty())
            {
                return(Geometry.GetEmptyPathGeometryData());
            }

            PathGeometryData data = new PathGeometryData();

            data.FillRule = FillRule.EvenOdd;
            data.Matrix   = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);

            Point[] points = GetPointList();

            ByteStreamGeometryContext ctx = new ByteStreamGeometryContext();

            ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */);

            // i == 0, 3, 6, 9
            for (int i = 0; i < 12; i += 3)
            {
                ctx.BezierTo(points[i + 1], points[i + 2], points[i + 3], true /* is stroked */, true /* is smooth join */);
            }

            ctx.Close();
            data.SerializedData = ctx.GetData();

            return(data);
        }
Exemple #3
0
        /// <summary>
        /// GetPathGeometryData - returns a struct which contains this Geometry represented
        /// as a path geometry's serialized format.
        /// </summary>
        internal override PathGeometryData GetPathGeometryData()
        {
            if (IsEmpty())
            {
                return(Geometry.GetEmptyPathGeometryData());
            }

            PathGeometryData data = new PathGeometryData();

            data.FillRule       = FillRule;
            data.Matrix         = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);
            data.SerializedData = _data;

            return(data);
        }
Exemple #4
0
        internal unsafe bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type,
                                              Point *pPoints, uint pointCount, byte *pTypes, uint typeCount)
        {
            bool contains = false;

            MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);

            MIL_PEN_DATA penData;

            double[] dashArray = null;

            if (pen != null)
            {
                pen.GetBasicPenData(&penData, out dashArray);
            }

            fixed(double *dashArrayFixed = dashArray)
            {
                int hr = MilCoreApi.MilUtility_PolygonHitTest(
                    &matrix,
                    (pen == null) ? null : &penData,
                    dashArrayFixed,
                    pPoints,
                    pTypes,
                    pointCount,
                    typeCount,
                    tolerance,
                    type == ToleranceType.Relative,
                    &hitPoint,
                    out contains);

                if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                {
                    // When we encounter NaNs in the renderer, we absorb the error and draw
                    // nothing. To be consistent, we report that the geometry is never hittable.
                    contains = false;
                }
                else
                {
                    HRESULT.Check(hr);
                }
            }

            return(contains);
        }
Exemple #5
0
        /// <summary>
        /// GetPathGeometryData - returns a byte[] which contains this Geometry represented
        /// as a path geometry's serialized format.
        /// </summary>
        internal override PathGeometryData GetPathGeometryData()
        {
            if (IsObviouslyEmpty())
            {
                return(Geometry.GetEmptyPathGeometryData());
            }

            PathGeometryData data = new PathGeometryData();

            data.FillRule = FillRule.EvenOdd;
            data.Matrix   = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);

            double radiusX = RadiusX;
            double radiusY = RadiusY;
            Rect   rect    = Rect;

            ByteStreamGeometryContext ctx = new ByteStreamGeometryContext();

            if (IsRounded(radiusX, radiusY))
            {
                Point[] points = GetPointList(rect, radiusX, radiusY);

                ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */);
                ctx.BezierTo(points[1], points[2], points[3], true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(points[4], true /* is stroked */, false /* is smooth join */);
                ctx.BezierTo(points[5], points[6], points[7], true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(points[8], true /* is stroked */, false /* is smooth join */);
                ctx.BezierTo(points[9], points[10], points[11], true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(points[12], true /* is stroked */, false /* is smooth join */);
                ctx.BezierTo(points[13], points[14], points[15], true /* is stroked */, false /* is smooth join */);
            }
            else
            {
                ctx.BeginFigure(rect.TopLeft, true /* is filled */, true /* is closed */);
                ctx.LineTo(Rect.TopRight, true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(Rect.BottomRight, true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(Rect.BottomLeft, true /* is stroked */, false /* is smooth join */);
            }

            ctx.Close();
            data.SerializedData = ctx.GetData();

            return(data);
        }
Exemple #6
0
        /// <summary>
        /// GetPathGeometryData - returns a byte[] which contains this Geometry represented
        /// as a path geometry's serialized format.
        /// </summary>
        internal override PathGeometryData GetPathGeometryData()
        {
            if (IsObviouslyEmpty())
            {
                return(Geometry.GetEmptyPathGeometryData());
            }

            PathGeometryData data = new PathGeometryData();

            data.FillRule = FillRule.EvenOdd;
            data.Matrix   = CompositionResourceManager.TransformToMilMatrix3x2D(Transform);

            ByteStreamGeometryContext ctx = new ByteStreamGeometryContext();

            ctx.BeginFigure(StartPoint, true /* is filled */, false /* is closed */);
            ctx.LineTo(EndPoint, true /* is stroked */, false /* is smooth join */);

            ctx.Close();
            data.SerializedData = ctx.GetData();

            return(data);
        }
Exemple #7
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);
        }