public static Matrix build(System.Drawing.Drawing2D.Matrix at) { Matrix matrix = new Matrix(); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.scaleX = (int)System.Math.Round((double)((float)at.Elements.GetValue(0) * flash.swf.SwfConstants_Fields.FIXED_POINT_MULTIPLE)); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.scaleY = (int)System.Math.Round((double)((float)at.Elements.GetValue(3) * flash.swf.SwfConstants_Fields.FIXED_POINT_MULTIPLE)); if (matrix.scaleX != 0 || matrix.scaleY != 0) { matrix.hasScale = true; } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.rotateSkew0 = (int)System.Math.Round((double)((float)at.Elements.GetValue(1) * flash.swf.SwfConstants_Fields.FIXED_POINT_MULTIPLE)); //Yes, these are supposed //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.rotateSkew1 = (int)System.Math.Round((double)((float)at.Elements.GetValue(2) * flash.swf.SwfConstants_Fields.FIXED_POINT_MULTIPLE)); //to be flipped if (matrix.rotateSkew0 != 0 || matrix.rotateSkew1 != 0) { matrix.hasRotate = true; //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.getType' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtgeomAffineTransformgetType'" //UPGRADE_ISSUE: Field 'java.awt.geom.AffineTransform.TYPE_MASK_ROTATION' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtgeomAffineTransformTYPE_MASK_ROTATION_f'" if ((at.getType() & AffineTransform.TYPE_MASK_ROTATION) != 0) { matrix.hasScale = true; //A rotation operation in Flash requires both rotate and scale components, even if zero scale. } } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.translateX = (int)System.Math.Round((double)((System.Single)at.OffsetX * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL)); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" matrix.translateY = (int)System.Math.Round((double)((System.Single)at.OffsetY * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL)); return(matrix); }
/// <summary> TODO: These methods need to be called based on which of two gradient transform methods we're applying. /// In SVG, these are known as: /// - userSpaceOnUse - apply gradient transform and use gradient points directly /// - objectBoundingBox - use the width/height from the target object then apply gradient transform /// </summary> //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" private static System.Drawing.Drawing2D.Matrix objectBoundingBoxTransform(ref System.Drawing.PointF gp1, ref System.Drawing.PointF gp2, double width, double height, double scaleWidth, double scaleHeight) { System.Drawing.Drawing2D.Matrix at = new System.Drawing.Drawing2D.Matrix(); //Translate gradient to the center of the bounded geometry at.Translate((System.Single)(width / 2), (System.Single)(height / 2)); //Scale to Gradient Square (in twips) at.Scale((System.Single)(scaleWidth * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL / flash.swf.SwfConstants_Fields.GRADIENT_SQUARE), (System.Single)(scaleHeight * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL / flash.swf.SwfConstants_Fields.GRADIENT_SQUARE)); //Rotate gradient to match geometry if (!gp1.IsEmpty && !gp2.IsEmpty && ((double)gp2.X - (double)gp1.X) != 0) { double mx = (double)gp2.X - (double)gp1.X; double my = (double)gp2.Y - (double)gp1.Y; double gradient = my / mx; double angle = System.Math.Atan(gradient); /* * Handle the "arctan" problem - get a standard angle so that it is positive within 360 degrees * wrt the positive x-axis in a counter-clockwise direction */ if (mx < 0) { angle += System.Math.PI; } else if (my < 0) { angle += (System.Math.PI * 2.0); } if (angle != 0) { at.Rotate((float)(angle * (180 / System.Math.PI))); } } return(at); }
/// <summary> Utility method to create an appropriate <code>FillStyle</code> from a <code>Paint</code>.</summary> /// <param name="paint">an AWT <code>Paint</code> instance /// </param> /// <param name="bounds">- required for gradient ratio calculation /// </param> /// <returns> a new <code>FillStyle</code> representing the given paint /// </returns> //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" public static FillStyle build(System.Drawing.Brush paint, ref System.Drawing.RectangleF bounds, System.Drawing.Drawing2D.Matrix transform) { FillStyle fs = null; if (paint != null) { double width = (double) bounds.Width; double height = (double) bounds.Height; if (paint is System.Drawing.Color) { //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs = new FillStyle(SwfUtils.colorToInt(ref new System.Drawing.Color[]{(System.Drawing.Color) paint}[0])); } else if (paint is System.Drawing.Drawing2D.LinearGradientBrush) { System.Drawing.Drawing2D.LinearGradientBrush gp = (System.Drawing.Drawing2D.LinearGradientBrush) paint; //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.transform' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtgeomAffineTransformtransform_javaawtgeomPoint2D_javaawtgeomPoint2D'" System.Drawing.PointF tempAux = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux2 = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux3 = transform.transform(new System.Drawing.PointF(gp.Rectangle.X, gp.Rectangle.Y), tempAux); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.PointF tempAux4 = transform.transform(new System.Drawing.PointF(gp.Rectangle.Height, gp.Rectangle.Width), tempAux2); System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref tempAux3, ref tempAux4, width, height, width, height); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); fs.type = FillStyle.FILL_LINEAR_GRADIENT; fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[2]; System.Drawing.Color tempAux5 = (gp.LinearColors)[0]; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[0] = new GradRecord(0, SwfUtils.colorToInt(ref tempAux5)); //from left System.Drawing.Color tempAux6 = (gp.LinearColors)[1]; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[1] = new GradRecord(255, SwfUtils.colorToInt(ref tempAux6)); //to right } else if (paint is LinearGradientPaint) { LinearGradientPaint lgp = (LinearGradientPaint) paint; System.Drawing.PointF start = lgp.getStartPoint(); System.Drawing.PointF end = lgp.getEndPoint(); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref start, ref end, width, height, width, height); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); System.Drawing.Color[] colors = lgp.getColors(); float[] ratios = lgp.getFractions(); if (colors.Length == 0 || colors.Length != ratios.Length) //Invalid fill so we skip { return null; } else if (colors.Length == 1) //Solid fill { //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" return new FillStyle(SwfUtils.colorToInt(ref colors[0])); } else { fs.type = FillStyle.FILL_LINEAR_GRADIENT; //Maximum of 8 gradient control points records int len = ratios.Length; if (len > 8) len = 8; fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[len]; for (int i = 0; i < len; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[i] = new GradRecord((int) System.Math.Round((double) (255 * ratios[i])), SwfUtils.colorToInt(ref colors[i])); } } } else if (paint is RadialGradientPaint) { RadialGradientPaint rgp = (RadialGradientPaint) paint; //Note: Flash doesn't support the focal point of a radial gradient //Point2D cp = rgp.getCenterPoint(); //Point2D fp = rgp.getFocusPoint(); double diameter = rgp.getRadius() * 2.0; double outerX = diameter * rgp.getTransform().getScaleX(); double outerY = diameter * rgp.getTransform().getScaleY(); System.Drawing.PointF tempAux7 = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux8 = System.Drawing.PointF.Empty; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref tempAux7, ref tempAux8, width, height, outerX, outerY); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); fs.type = FillStyle.FILL_RADIAL_GRADIENT; System.Drawing.Color[] colors = rgp.getColors(); float[] ratios = rgp.getFractions(); fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[ratios.Length <= 8?ratios.Length:8]; for (int i = 0; i < ratios.Length && i < 8; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[i] = new GradRecord((int) System.Math.Round((double) (255 * ratios[i])), SwfUtils.colorToInt(ref colors[i])); } } else if (paint is System.Drawing.TextureBrush) { System.Drawing.TextureBrush tp = (System.Drawing.TextureBrush) paint; System.Drawing.Image image = (System.Drawing.Image) tp.Image; DefineBitsLossless tag = DefineBitsLosslessBuilder.build(new LosslessImage(image)); //Apply Twips Scale of 20 x 20 System.Drawing.Drawing2D.Matrix at = new System.Drawing.Drawing2D.Matrix(); at.Scale((System.Single) flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL, (System.Single) flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL); Matrix matrix = MatrixBuilder.build(at); fs = new FillStyle(FillStyle.FILL_BITS, matrix, tag); } } return fs; }
/// <summary> TODO: These methods need to be called based on which of two gradient transform methods we're applying. /// In SVG, these are known as: /// - userSpaceOnUse - apply gradient transform and use gradient points directly /// - objectBoundingBox - use the width/height from the target object then apply gradient transform /// </summary> //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" private static System.Drawing.Drawing2D.Matrix objectBoundingBoxTransform(ref System.Drawing.PointF gp1, ref System.Drawing.PointF gp2, double width, double height, double scaleWidth, double scaleHeight) { System.Drawing.Drawing2D.Matrix at = new System.Drawing.Drawing2D.Matrix(); //Translate gradient to the center of the bounded geometry at.Translate((System.Single) (width / 2), (System.Single) (height / 2)); //Scale to Gradient Square (in twips) at.Scale((System.Single) (scaleWidth * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL / flash.swf.SwfConstants_Fields.GRADIENT_SQUARE), (System.Single) (scaleHeight * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL / flash.swf.SwfConstants_Fields.GRADIENT_SQUARE)); //Rotate gradient to match geometry if (!gp1.IsEmpty && !gp2.IsEmpty && ((double) gp2.X - (double) gp1.X) != 0) { double mx = (double) gp2.X - (double) gp1.X; double my = (double) gp2.Y - (double) gp1.Y; double gradient = my / mx; double angle = System.Math.Atan(gradient); /* Handle the "arctan" problem - get a standard angle so that it is positive within 360 degrees wrt the positive x-axis in a counter-clockwise direction */ if (mx < 0) angle += System.Math.PI; else if (my < 0) angle += (System.Math.PI * 2.0); if (angle != 0) at.Rotate((float) (angle * (180 / System.Math.PI))); } return at; }
/// <summary> Utility method to create an appropriate <code>FillStyle</code> from a <code>Paint</code>.</summary> /// <param name="paint">an AWT <code>Paint</code> instance /// </param> /// <param name="bounds">- required for gradient ratio calculation /// </param> /// <returns> a new <code>FillStyle</code> representing the given paint /// </returns> //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" public static FillStyle build(System.Drawing.Brush paint, ref System.Drawing.RectangleF bounds, System.Drawing.Drawing2D.Matrix transform) { FillStyle fs = null; if (paint != null) { double width = (double)bounds.Width; double height = (double)bounds.Height; if (paint is System.Drawing.Color) { //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs = new FillStyle(SwfUtils.colorToInt(ref new System.Drawing.Color[] { (System.Drawing.Color)paint }[0])); } else if (paint is System.Drawing.Drawing2D.LinearGradientBrush) { System.Drawing.Drawing2D.LinearGradientBrush gp = (System.Drawing.Drawing2D.LinearGradientBrush)paint; //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.transform' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtgeomAffineTransformtransform_javaawtgeomPoint2D_javaawtgeomPoint2D'" System.Drawing.PointF tempAux = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux2 = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux3 = transform.transform(new System.Drawing.PointF(gp.Rectangle.X, gp.Rectangle.Y), tempAux); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.PointF tempAux4 = transform.transform(new System.Drawing.PointF(gp.Rectangle.Height, gp.Rectangle.Width), tempAux2); System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref tempAux3, ref tempAux4, width, height, width, height); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); fs.type = FillStyle.FILL_LINEAR_GRADIENT; fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[2]; System.Drawing.Color tempAux5 = (gp.LinearColors)[0]; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[0] = new GradRecord(0, SwfUtils.colorToInt(ref tempAux5)); //from left System.Drawing.Color tempAux6 = (gp.LinearColors)[1]; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[1] = new GradRecord(255, SwfUtils.colorToInt(ref tempAux6)); //to right } else if (paint is LinearGradientPaint) { LinearGradientPaint lgp = (LinearGradientPaint)paint; System.Drawing.PointF start = lgp.getStartPoint(); System.Drawing.PointF end = lgp.getEndPoint(); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref start, ref end, width, height, width, height); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); System.Drawing.Color[] colors = lgp.getColors(); float[] ratios = lgp.getFractions(); if (colors.Length == 0 || colors.Length != ratios.Length) //Invalid fill so we skip { return(null); } else if (colors.Length == 1) //Solid fill { //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" return(new FillStyle(SwfUtils.colorToInt(ref colors[0]))); } else { fs.type = FillStyle.FILL_LINEAR_GRADIENT; //Maximum of 8 gradient control points records int len = ratios.Length; if (len > 8) { len = 8; } fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[len]; for (int i = 0; i < len; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[i] = new GradRecord((int)System.Math.Round((double)(255 * ratios[i])), SwfUtils.colorToInt(ref colors[i])); } } } else if (paint is RadialGradientPaint) { RadialGradientPaint rgp = (RadialGradientPaint)paint; //Note: Flash doesn't support the focal point of a radial gradient //Point2D cp = rgp.getCenterPoint(); //Point2D fp = rgp.getFocusPoint(); double diameter = rgp.getRadius() * 2.0; double outerX = diameter * rgp.getTransform().getScaleX(); double outerY = diameter * rgp.getTransform().getScaleY(); System.Drawing.PointF tempAux7 = System.Drawing.PointF.Empty; System.Drawing.PointF tempAux8 = System.Drawing.PointF.Empty; //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref tempAux7, ref tempAux8, width, height, outerX, outerY); fs = new FillStyle(); fs.matrix = MatrixBuilder.build(gt); fs.type = FillStyle.FILL_RADIAL_GRADIENT; System.Drawing.Color[] colors = rgp.getColors(); float[] ratios = rgp.getFractions(); fs.gradient = new Gradient(); fs.gradient.records = new GradRecord[ratios.Length <= 8?ratios.Length:8]; for (int i = 0; i < ratios.Length && i < 8; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" fs.gradient.records[i] = new GradRecord((int)System.Math.Round((double)(255 * ratios[i])), SwfUtils.colorToInt(ref colors[i])); } } else if (paint is System.Drawing.TextureBrush) { System.Drawing.TextureBrush tp = (System.Drawing.TextureBrush)paint; System.Drawing.Image image = (System.Drawing.Image)tp.Image; DefineBitsLossless tag = DefineBitsLosslessBuilder.build(new LosslessImage(image)); //Apply Twips Scale of 20 x 20 System.Drawing.Drawing2D.Matrix at = new System.Drawing.Drawing2D.Matrix(); at.Scale((System.Single)flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL, (System.Single)flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL); Matrix matrix = MatrixBuilder.build(at); fs = new FillStyle(FillStyle.FILL_BITS, matrix, tag); } } return(fs); }