public static float ConvertToPx(CssLength length, ref ReEvaluateArgs args) { //Return zero if no length specified, zero specified switch (length.UnitOrNames) { case CssUnitOrNames.EmptyValue: return 0; case CssUnitOrNames.Percent: return (length.Number / 100f) * args.containerW; case CssUnitOrNames.Ems: return length.Number * args.emHeight; case CssUnitOrNames.Ex: return length.Number * (args.emHeight / 2); case CssUnitOrNames.Pixels: //atodo: check support for hi dpi return length.Number; case CssUnitOrNames.Milimeters: return length.Number * 3.779527559f; //3 pixels per millimeter case CssUnitOrNames.Centimeters: return length.Number * 37.795275591f; //37 pixels per centimeter case CssUnitOrNames.Inches: return length.Number * 96f; //96 pixels per inch case CssUnitOrNames.Points: return length.Number * (96f / 72f); // 1 point = 1/72 of inch case CssUnitOrNames.Picas: return length.Number * 16f; // 1 pica = 12 points default: return 0; } }
//---------------------------- public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualRadiusX = ConvertToPx(myspec.RadiusX, ref args); this.ActualRadiusY = ConvertToPx(myspec.RadiusY, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); //path may note need if (this.IsPathValid) { return; } ClearCachePath(); this.myCachedPath = args.graphicsPlatform.CreateGraphicsPath(); myCachedPath.StartFigure(); myCachedPath.AddEllipse(this.ActualX - this.ActualRadiusX, this.ActualY - this.ActualRadiusY, 2 * this.ActualRadiusX, 2 * this.ActualRadiusY); myCachedPath.CloseFigure(); ValidatePath(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); this.pointList = spec.Points.ToArray(); if (this.IsPathValid) { return; } ClearCachePath(); this.myCachedPath = new GraphicsPath(); PointF[] plist = this.pointList; int lim = plist.Length - 1; for (int i = 0; i < lim; ++i) { //p1,p2 myCachedPath.AddLine( plist[i], plist[i + 1]); } ValidatePath(); }
public override void CustomRecomputedValue(CssBox containingBlock) { var svgElement = this.SvgSpec; //recompute value if need var cnode = svgElement.GetFirstNode(); ReEvaluateArgs reEvalArgs = new ReEvaluateArgs( containingBlock.VisualWidth, 100, containingBlock.GetEmHeight()); while (cnode != null) { cnode.Value.ReEvaluateComputeValue(ref reEvalArgs); cnode = cnode.Next; } this.SetVisualSize(500, 500); }
//---------------------------- public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.rectSpec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualWidth = ConvertToPx(myspec.Width, ref args); this.ActualHeight = ConvertToPx(myspec.Height, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); this.ActualCornerX = ConvertToPx(myspec.CornerRadiusX, ref args); this.ActualCornerY = ConvertToPx(myspec.CornerRadiusY, ref args); //update graphic path if (this.IsPathValid) { return; } ClearCachePath(); if (this.ActualCornerX == 0 && this.ActualCornerY == 0) { this.myCachedPath = CreateRectGraphicPath( args.graphicsPlatform, this.ActualX, this.ActualY, this.ActualWidth, this.ActualHeight); } else { this.myCachedPath = CreateRoundRectGraphicPath( args.graphicsPlatform, this.ActualX, this.ActualY, this.ActualWidth, this.ActualHeight, this.ActualCornerX, this.ActualCornerY); } ValidatePath(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.imageSpec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualWidth = ConvertToPx(myspec.Width, ref args); this.ActualHeight = ConvertToPx(myspec.Height, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); this._path = CreateRectGraphicPath( this.ActualX, this.ActualY, this.ActualWidth, this.ActualHeight); if (this._imgRun.ImageBinder == null) { this._imgRun.ImageBinder = new SvgImageBinder(myspec.ImageSrc); } ValidatePath(); }
public static float ConvertToPx(CssLength length, ref ReEvaluateArgs args) { //Return zero if no length specified, zero specified switch (length.UnitOrNames) { case CssUnitOrNames.EmptyValue: return(0); case CssUnitOrNames.Percent: return((length.Number / 100f) * args.containerW); case CssUnitOrNames.Ems: return(length.Number * args.emHeight); case CssUnitOrNames.Ex: return(length.Number * (args.emHeight / 2)); case CssUnitOrNames.Pixels: //atodo: check support for hi dpi return(length.Number); case CssUnitOrNames.Milimeters: return(length.Number * 3.779527559f); //3 pixels per millimeter case CssUnitOrNames.Centimeters: return(length.Number * 37.795275591f); //37 pixels per centimeter case CssUnitOrNames.Inches: return(length.Number * 96f); //96 pixels per inch case CssUnitOrNames.Points: return(length.Number * (96f / 72f)); // 1 point = 1/72 of inch case CssUnitOrNames.Picas: return(length.Number * 16f); // 1 pica = 12 points default: return(0); } }
//---------------------------- public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualRadius = ConvertToPx(myspec.Radius, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); //create new path if (this.IsPathValid) { return; } ClearCachePath(); myCachedPath = new GraphicsPath(); myCachedPath.StartFigure(); myCachedPath.AddEllipse(this.ActualX - this.ActualRadius, this.ActualY - this.ActualRadius, 2 * this.ActualRadius, 2 * ActualRadius); myCachedPath.CloseFigure(); ValidatePath(); }
//---------------------------- public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.rectSpec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualWidth = ConvertToPx(myspec.Width, ref args); this.ActualHeight = ConvertToPx(myspec.Height, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); this.ActualCornerX = ConvertToPx(myspec.CornerRadiusX, ref args); this.ActualCornerY = ConvertToPx(myspec.CornerRadiusY, ref args); //update graphic path if (this.IsPathValid) { return; } ClearCachePath(); if (this.ActualCornerX == 0 && this.ActualCornerY == 0) { this.myCachedPath = CreateRectGraphicPath( this.ActualX, this.ActualY, this.ActualWidth, this.ActualHeight); } else { this.myCachedPath = CreateRoundRectGraphicPath( this.ActualX, this.ActualY, this.ActualWidth, this.ActualHeight, this.ActualCornerX, this.ActualCornerY); } ValidatePath(); }
public virtual void ReEvaluateComputeValue(ref ReEvaluateArgs args) { }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); if (this.IsPathValid) { return; } ClearCachePath(); if (segments == null) { this.myCachedPath = null; } else { List <SvgPathSeg> segs = this.segments; int segcount = segs.Count; GraphicsPath gpath = this.myCachedPath = new GraphicsPath(); float lastMoveX = 0; float lastMoveY = 0; PointF lastPoint = new PointF(); PointF p2 = new PointF(); //curve control point PointF p3 = new PointF(); //curve control point PointF intm_c3_c = new PointF(); for (int i = 0; i < segcount; ++i) { SvgPathSeg seg = segs[i]; switch (seg.Command) { case SvgPathCommand.ZClosePath: { gpath.CloseFigure(); } break; case SvgPathCommand.MoveTo: { var moveTo = (SvgPathSegMoveTo)seg; PointF moveToPoint; moveTo.GetAbsolutePoints(ref lastPoint, out moveToPoint); lastPoint = moveToPoint; gpath.StartFigure(); lastMoveX = lastPoint.X; lastMoveY = lastPoint.Y; } break; case SvgPathCommand.LineTo: { var lineTo = (SvgPathSegLineTo)seg; PointF lineToPoint; lineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.HorizontalLineTo: { var hlintTo = (SvgPathSegLineToHorizontal)seg; PointF lineToPoint; hlintTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.VerticalLineTo: { var vlineTo = (SvgPathSegLineToVertical)seg; PointF lineToPoint; vlineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; //--------------------------------------------------------------------------- //curve modes...... case SvgPathCommand.CurveTo: { //cubic curve to (2 control points) var cubicCurve = (SvgPathSegCurveToCubic)seg; PointF p; cubicCurve.GetAbsolutePoints(ref lastPoint, out p2, out p3, out p); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.QuadraticBezierCurve: { //quadratic curve (1 control point) //auto calculate for c1,c2 var quadCurve = (SvgPathSegCurveToQuadratic)seg; PointF p; quadCurve.GetAbsolutePoints(ref lastPoint, out intm_c3_c, out p); SvgCurveHelper.Curve3GetControlPoints(lastPoint, intm_c3_c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; //------------------------------------------------------------------------------------ case SvgPathCommand.SmoothCurveTo: { //smooth cubic curve to var smthC4 = (SvgPathSegCurveToCubicSmooth)seg; PointF c2, p; smthC4.GetAbsolutePoints(ref lastPoint, out c2, out p); //connect with prev segment if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: case SvgPathCommand.QuadraticBezierCurve: case SvgPathCommand.TSmoothQuadraticBezierCurveTo: //make mirror point p2 = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); p3 = c2; gpath.AddBezierCurve(lastPoint, p2, p3, p); break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //curve 3 var smtC3 = (SvgPathSegCurveToQuadraticSmooth)seg; PointF p; smtC3.GetAbsolutePoints(ref lastPoint, out p); if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: { PointF c = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //make mirror point PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; case SvgPathCommand.QuadraticBezierCurve: { PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.Arc: { var arcTo = (SvgPathSegArc)seg; PointF p; arcTo.GetAbsolutePoints(ref lastPoint, out p); if (lastPoint.IsEq(p)) { return; } if (arcTo.R1 == 0 && arcTo.R2 == 0) { gpath.AddLine(lastPoint, p); lastPoint = p; return; } PointF[] bz4Points; SvgCurveHelper.MakeBezierCurveFromArc( ref lastPoint, ref p, arcTo.R1, arcTo.R2, arcTo.Angle, arcTo.LargeArgFlag, arcTo.SweepFlag, out bz4Points); int j = bz4Points.Length; int nn = 0; while (nn < j) { gpath.AddBezierCurve( bz4Points[nn], bz4Points[nn + 1], bz4Points[nn + 2], bz4Points[nn + 3]); nn += 4; //step 4 points } //set control points p3 = bz4Points[nn - 2]; p2 = bz4Points[nn - 3]; lastPoint = p; //--------------------------------------------- } break; default: throw new NotSupportedException(); } } } ValidatePath(); }
//---------------------------- public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualX = ConvertToPx(myspec.X, ref args); this.ActualY = ConvertToPx(myspec.Y, ref args); this.ActualRadiusX = ConvertToPx(myspec.RadiusX, ref args); this.ActualRadiusY = ConvertToPx(myspec.RadiusY, ref args); this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); //path may note need if (this.IsPathValid) { return; } ClearCachePath(); this.myCachedPath = new GraphicsPath(); myCachedPath.StartFigure(); myCachedPath.AddEllipse(this.ActualX - this.ActualRadiusX, this.ActualY - this.ActualRadiusY, 2 * this.ActualRadiusX, 2 * this.ActualRadiusY); myCachedPath.CloseFigure(); ValidatePath(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); if (this.IsPathValid) { return; } ClearCachePath(); if (segments == null) { this.myCachedPath = null; } else { List<SvgPathSeg> segs = this.segments; int segcount = segs.Count; GraphicsPath gpath = this.myCachedPath = new GraphicsPath(); float lastMoveX = 0; float lastMoveY = 0; PointF lastPoint = new PointF(); PointF p2 = new PointF();//curve control point PointF p3 = new PointF();//curve control point PointF intm_c3_c = new PointF(); for (int i = 0; i < segcount; ++i) { SvgPathSeg seg = segs[i]; switch (seg.Command) { case SvgPathCommand.ZClosePath: { gpath.CloseFigure(); } break; case SvgPathCommand.MoveTo: { var moveTo = (SvgPathSegMoveTo)seg; PointF moveToPoint; moveTo.GetAbsolutePoints(ref lastPoint, out moveToPoint); lastPoint = moveToPoint; gpath.StartFigure(); lastMoveX = lastPoint.X; lastMoveY = lastPoint.Y; } break; case SvgPathCommand.LineTo: { var lineTo = (SvgPathSegLineTo)seg; PointF lineToPoint; lineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.HorizontalLineTo: { var hlintTo = (SvgPathSegLineToHorizontal)seg; PointF lineToPoint; hlintTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.VerticalLineTo: { var vlineTo = (SvgPathSegLineToVertical)seg; PointF lineToPoint; vlineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; //--------------------------------------------------------------------------- //curve modes...... case SvgPathCommand.CurveTo: { //cubic curve to (2 control points) var cubicCurve = (SvgPathSegCurveToCubic)seg; PointF p; cubicCurve.GetAbsolutePoints(ref lastPoint, out p2, out p3, out p); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.QuadraticBezierCurve: { //quadratic curve (1 control point) //auto calculate for c1,c2 var quadCurve = (SvgPathSegCurveToQuadratic)seg; PointF p; quadCurve.GetAbsolutePoints(ref lastPoint, out intm_c3_c, out p); SvgCurveHelper.Curve3GetControlPoints(lastPoint, intm_c3_c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; //------------------------------------------------------------------------------------ case SvgPathCommand.SmoothCurveTo: { //smooth cubic curve to var smthC4 = (SvgPathSegCurveToCubicSmooth)seg; PointF c2, p; smthC4.GetAbsolutePoints(ref lastPoint, out c2, out p); //connect with prev segment if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: case SvgPathCommand.QuadraticBezierCurve: case SvgPathCommand.TSmoothQuadraticBezierCurveTo: //make mirror point p2 = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); p3 = c2; gpath.AddBezierCurve(lastPoint, p2, p3, p); break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //curve 3 var smtC3 = (SvgPathSegCurveToQuadraticSmooth)seg; PointF p; smtC3.GetAbsolutePoints(ref lastPoint, out p); if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: { PointF c = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //make mirror point PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; case SvgPathCommand.QuadraticBezierCurve: { PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.Arc: { var arcTo = (SvgPathSegArc)seg; PointF p; arcTo.GetAbsolutePoints(ref lastPoint, out p); if (lastPoint.IsEq(p)) { return; } if (arcTo.R1 == 0 && arcTo.R2 == 0) { gpath.AddLine(lastPoint, p); lastPoint = p; return; } PointF[] bz4Points; SvgCurveHelper.MakeBezierCurveFromArc( ref lastPoint, ref p, arcTo.R1, arcTo.R2, arcTo.Angle, arcTo.LargeArgFlag, arcTo.SweepFlag, out bz4Points); int j = bz4Points.Length; int nn = 0; while (nn < j) { gpath.AddBezierCurve( bz4Points[nn], bz4Points[nn + 1], bz4Points[nn + 2], bz4Points[nn + 3]); nn += 4;//step 4 points } //set control points p3 = bz4Points[nn - 2]; p2 = bz4Points[nn - 3]; lastPoint = p; //--------------------------------------------- } break; default: throw new NotSupportedException(); } } } ValidatePath(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { this.fillColor = spec.ActualColor; this.strokeColor = spec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(spec.StrokeWidth, ref args); var node = this.GetFirstNode(); while (node != null) { node.Value.ReEvaluateComputeValue(ref args); node = node.Next; } ValidatePath(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { SvgLineSpec myspec = this.spec; this.fillColor = myspec.ActualColor; this.strokeColor = myspec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); this.ActualX1 = ConvertToPx(myspec.X1, ref args); this.ActualY1 = ConvertToPx(myspec.Y1, ref args); this.ActualX2 = ConvertToPx(myspec.X2, ref args); this.ActualX2 = ConvertToPx(myspec.Y2, ref args); ValidatePath(); }