[Ikvm-commit] ikvm/awt graphics.cs, 1.50, 1.51 converter.cs, 1.18, 1.19
Brought to you by:
jfrijters
From: Small S. <sma...@us...> - 2010-11-28 10:01:15
|
Update of /cvsroot/ikvm/ikvm/awt In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19494/awt Modified Files: graphics.cs converter.cs Log Message: Fix some stroke bugs Index: converter.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/awt/converter.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** converter.cs 1 Nov 2010 12:30:14 -0000 1.18 --- converter.cs 28 Nov 2010 10:01:07 -0000 1.19 *************** *** 2,6 **** Copyright (C) 2002, 2004, 2005, 2006, 2007 Jeroen Frijters Copyright (C) 2006 Active Endpoints, Inc. ! Copyright (C) 2006, 2007, 2008, 2009 Volker Berlin (i-net software) This software is provided 'as-is', without any express or implied --- 2,6 ---- Copyright (C) 2002, 2004, 2005, 2006, 2007 Jeroen Frijters Copyright (C) 2006 Active Endpoints, Inc. ! Copyright (C) 2006 - 2010 Volker Berlin (i-net software) This software is provided 'as-is', without any express or implied *************** *** 187,234 **** return LineJoin.Bevel; default: ! throw new ArgumentException("Invalid LineJoin argument."); ! } ! } ! ! internal static LineCap ConvertLineCap(int cap) ! { ! switch (cap) ! { ! case java.awt.BasicStroke.CAP_BUTT: ! return LineCap.Flat; ! case java.awt.BasicStroke.CAP_ROUND: ! return LineCap.Round; ! case java.awt.BasicStroke.CAP_SQUARE: ! return LineCap.Square; ! default: ! throw new ArgumentException("Invalid LineCap argument."); ! } ! } ! ! internal static float[] ConvertDashArray(float[] dashArray, float lineWidth) ! { ! if (dashArray == null || dashArray.Length == 0) ! { ! return null; ! } ! if (dashArray.Length % 2 == 1) ! { ! int len = dashArray.Length; ! Array.Resize(ref dashArray, len * 2); ! Array.Copy(dashArray, 0, dashArray, len, len); ! } ! float[] dash = (float[])dashArray.Clone(); ! for (int i = 0; i < dash.Length; i++) ! { ! //dividing by line thickness because of the representation difference ! dash[i] = dash[i] / lineWidth; ! } ! // To fix the problem where solid style in Java can be represented at { 1.0, 0.0 }. ! // In .NET, however, array can only have positive value ! if (dash.Length==2 && dash[dash.Length-1]==0) ! { ! Array.Resize(ref dash, 1); } - return dash; } --- 187,193 ---- return LineJoin.Bevel; default: ! Console.WriteLine("Unknown line join type:" + join); ! return LineJoin.Miter; } } *************** *** 424,428 **** break; case 3: ! // Indicates that the point is an endpoint or control point of a cubic Bézier spline. PointF point2 = path.PathPoints[++i]; PointF point3 = path.PathPoints[++i]; --- 383,387 ---- break; case 3: ! // Indicates that the point is an endpoint or control point of a cubic B�zier spline. PointF point2 = path.PathPoints[++i]; PointF point3 = path.PathPoints[++i]; Index: graphics.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/awt/graphics.cs,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** graphics.cs 16 Nov 2010 11:09:08 -0000 1.50 --- graphics.cs 28 Nov 2010 10:01:07 -0000 1.51 *************** *** 193,203 **** graphics.InterpolationMode = g.InterpolationMode; graphics.CompositingMode = g.CompositingMode; } else { // default values that Java used graphics.InterpolationMode = InterpolationMode.NearestNeighbor; } g = graphics; - brush = new SolidBrush(color); - pen = new Pen(color); } --- 193,205 ---- graphics.InterpolationMode = g.InterpolationMode; graphics.CompositingMode = g.CompositingMode; + pen = (Pen)pen.Clone(); + brush = (Brush)brush.Clone(); } else { // default values that Java used graphics.InterpolationMode = InterpolationMode.NearestNeighbor; + pen = new Pen(color); + brush = new SolidBrush(color); } g = graphics; } *************** *** 866,914 **** } this.stroke = stroke; ! if (stroke is java.awt.BasicStroke) ! { ! java.awt.BasicStroke s = (java.awt.BasicStroke)stroke; ! ! pen = new Pen(pen.Brush, s.getLineWidth()); ! ! setLineJoin(s); ! setLineCap(s); ! setLineDash(s); ! } } ! private void setLineJoin(java.awt.BasicStroke s) { pen.MiterLimit = s.getMiterLimit(); ! try ! { ! pen.LineJoin = J2C.ConvertLineJoin(s.getLineJoin()); ! } ! catch (ArgumentException aex) ! { ! Console.WriteLine(aex.StackTrace); ! } } ! private void setLineCap(java.awt.BasicStroke s) { ! try ! { ! LineCap plc = J2C.ConvertLineCap(s.getEndCap()); ! pen.SetLineCap(plc, plc, pen.DashCap); ! } ! catch (ArgumentException aex) { ! Console.WriteLine(aex.StackTrace); ! } ! } ! private void setLineDash(java.awt.BasicStroke s) ! { ! float[] dash = J2C.ConvertDashArray(s.getDashArray(), s.getLineWidth()); ! if (dash != null) ! { pen.DashPattern = dash; } --- 868,973 ---- } this.stroke = stroke; ! if (stroke is java.awt.BasicStroke) ! { ! java.awt.BasicStroke s = (java.awt.BasicStroke)stroke; ! pen = new Pen(pen.Brush, s.getLineWidth()); ! SetLineJoin(s); ! SetLineDash(s); ! } ! else ! { ! Console.WriteLine("Unknown Stroke type: " + stroke.GetType().FullName); ! } } ! private void SetLineJoin(java.awt.BasicStroke s) { pen.MiterLimit = s.getMiterLimit(); ! pen.LineJoin = J2C.ConvertLineJoin(s.getLineJoin()); } ! private void SetLineDash(java.awt.BasicStroke s) { ! float[] dash = s.getDashArray(); ! if (dash == null) { ! pen.DashStyle = DashStyle.Solid; ! } else { ! if (dash.Length % 2 == 1) ! { ! int len = dash.Length; ! Array.Resize(ref dash, len * 2); ! Array.Copy(dash, 0, dash, len, len); ! } ! float lineWidth = s.getLineWidth(); ! if (lineWidth > 1) // for values < 0 there is no correctur needed ! { ! for (int i = 0; i < dash.Length; i++) ! { ! //dividing by line thickness because of the representation difference ! dash[i] = dash[i] / lineWidth; ! } ! } ! // To fix the problem where solid style in Java can be represented at { 1.0, 0.0 }. ! // In .NET, however, array can only have positive value ! if (dash.Length == 2 && dash[dash.Length - 1] == 0) ! { ! Array.Resize(ref dash, 1); ! } ! float dashPhase = s.getDashPhase(); ! // correct the dash cap ! switch (s.getEndCap()) ! { ! case java.awt.BasicStroke.CAP_BUTT: ! pen.DashCap = DashCap.Flat; ! break; ! case java.awt.BasicStroke.CAP_ROUND: ! pen.DashCap = DashCap.Round; ! break; ! case java.awt.BasicStroke.CAP_SQUARE: ! pen.DashCap = DashCap.Flat; ! // there is no equals DashCap in .NET, we need to emulate it ! dashPhase += lineWidth / 2; ! for (int i = 0; i < dash.Length; i++) ! { ! if (i % 2 == 0) ! { ! dash[i] += 1; ! } ! else ! { ! dash[i] = Math.Max(0.00001F, dash[i] - 1); ! } ! } ! break; ! default: ! Console.WriteLine("Unknown dash cap type:" + s.getEndCap()); ! break; ! } ! ! // calc the dash offset ! if (lineWidth > 0) ! { ! //dividing by line thickness because of the representation difference ! pen.DashOffset = dashPhase / lineWidth; ! } ! else ! { ! // thickness == 0 ! if (dashPhase > 0) ! { ! pen.Width = lineWidth = 0.001F; // hack to prevent a division with 0 ! pen.DashOffset = dashPhase / lineWidth; ! } ! else ! { ! pen.DashOffset = 0; ! } ! } ! ! // set the final dash pattern pen.DashPattern = dash; } |