This class has some static convertion methods from Java to C# objects
コード例 #1
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void draw(java.awt.Shape shape)
 {
     using (GraphicsPath gp = J2C.ConvertShape(shape))
     {
         g.DrawPath(pen, gp);
     }
 }
コード例 #2
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void fill(java.awt.Shape shape)
 {
     using (Region region = new Region(J2C.ConvertShape(shape)))
     {
         g.FillRegion(brush, region);
     }
 }
コード例 #3
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override void fillRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight)
        {
            GraphicsPath gp = J2C.ConvertRoundRect(x, y, w, h, arcWidth, arcHeight);

            g.FillPath(brush, gp);
            gp.Dispose();
        }
コード例 #4
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 private void setLineDash(java.awt.BasicStroke s)
 {
     float[] dash = J2C.ConvertDashArray(s.getDashArray(), s.getLineWidth());
     if (dash != null)
     {
         pen.DashPattern = dash;
     }
 }
コード例 #5
0
ファイル: fonts-0.95.cs プロジェクト: maikebing/IKVM.NetCore
 public NetLineMetrics(java.awt.Font aFont, String aString)
 {
     mFont      = aFont;
     mString    = aString;
     fontFamily = J2C.CreateFontFamily(aFont.getName());
     style      = (FontStyle)mFont.getStyle();
     factor     = aFont.getSize2D() / fontFamily.GetEmHeight(style);
 }
コード例 #6
0
 public override java.awt.Graphics2D createGraphics()
 {
     //Graphics g = Graphics.FromImage(bitmap);
     // HACK for off-screen images we don't want ClearType or anti-aliasing
     // TODO I'm sure Java 2D has a way to control text rendering quality, we should honor that
     //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
     return(new BitmapGraphics(bitmap, getFont(), J2C.ConvertColor(getForeground()), J2C.ConvertColor(getBackground())));
 }
コード例 #7
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void transform(java.awt.geom.AffineTransform tx)
 {
     using (Matrix transform = g.Transform,
            matrix = J2C.ConvertTransform(tx))
     {
         transform.Multiply(matrix);
         g.Transform = transform;
     }
 }
コード例 #8
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 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);
     }
 }
コード例 #9
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 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);
     }
 }
コード例 #10
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void setClip(java.awt.Shape shape)
 {
     if (shape == null)
     {
         Region clip = g.Clip;
         clip.MakeInfinite();
         g.Clip = clip;
     }
     else
     {
         g.Clip = new Region(J2C.ConvertShape(shape));
     }
 }
コード例 #11
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override bool drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            lock (image)
            {
                g.DrawImage(image, x, y);
            }
            return(true);
        }
コード例 #12
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void clip(java.awt.Shape shape)
 {
     if (shape == null)
     {
         // the API specification says that this will clear
         // the clip, but in fact the reference implementation throws a
         // NullPointerException - see the following entry in the bug parade:
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189
         throw new java.lang.NullPointerException();
     }
     else
     {
         g.IntersectClip(new Region(J2C.ConvertShape(shape)));
     }
 }
コード例 #13
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override bool drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            Rectangle destRect = new Rectangle(dx1, dy1, dx2 - dx1, dy2 - dy1);
            Rectangle srcRect  = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);

            lock (image)
            {
                g.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);
            }
            return(true);
        }
コード例 #14
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override bool drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            using (Brush brush = J2C.CreateBrush(bgcolor))
            {
                g.FillRectangle(brush, x, y, image.Width, image.Height);
            }
            lock (image)
            {
                g.DrawImage(image, x, y);
            }
            return(true);
        }
コード例 #15
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override void drawGlyphVector(java.awt.font.GlyphVector gv, float x, float y)
        {
            java.awt.Font javaFont = gv.getFont();
            if (javaFont == null)
            {
                javaFont = font;
            }
            int count = gv.getNumGlyphs();

            char[] text = new char[count];
            for (int i = 0; i < count; i++)
            {
                text[i] = (char)gv.getGlyphCode(i);
            }
            java.awt.font.FontRenderContext frc = gv.getFontRenderContext();
            Matrix matrix = null;

            try
            {
                if (frc != null && !frc.getTransform().equals(getTransform()))
                {
                    // save the old context and use the transformation from the renderContext
                    matrix      = g.Transform;
                    g.Transform = J2C.ConvertTransform(frc.getTransform());
                }
                g.DrawString(new string(text), javaFont.getNetFont(), brush, x, y - javaFont.getSize(), StringFormat.GenericTypographic);
            }
            finally
            {
                // Restore the old context if needed
                if (matrix != null)
                {
                    g.Transform = matrix;
                }
            }
        }
コード例 #16
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void setBackground(java.awt.Color color)
 {
     bgcolor = J2C.ConvertColor(color);
 }
コード例 #17
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 internal ComponentGraphics(Control control, java.awt.Color fgColor, java.awt.Color bgColor, java.awt.Font font)
     : base(control.CreateGraphics(), font, J2C.ConvertColor(fgColor), J2C.ConvertColor(bgColor))
 {
     this.control = control;
 }
コード例 #18
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
        public override void setPaint(java.awt.Paint paint)
        {
            if (paint is java.awt.Color)
            {
                setColor((java.awt.Color)paint);
                return;
            }

            if (paint == null || this.javaPaint == paint)
            {
                return;
            }
            this.javaPaint = paint;

            if (paint is java.awt.GradientPaint)
            {
                java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint;
                LinearGradientBrush    linear;
                if (gradient.isCyclic())
                {
                    linear = new LinearGradientBrush(
                        J2C.ConvertPoint(gradient.getPoint1()),
                        J2C.ConvertPoint(gradient.getPoint2()),
                        J2C.ConvertColor(gradient.getColor1()),
                        J2C.ConvertColor(gradient.getColor2()));
                }
                else
                {
                    //HACK because .NET does not support continue gradient like Java else Tile Gradient
                    //that we receize the rectangle very large (factor z) and set 4 color values
                    // a exact solution will calculate the size of the Graphics with the current transform
                    Color       color1 = J2C.ConvertColor(gradient.getColor1());
                    Color       color2 = J2C.ConvertColor(gradient.getColor2());
                    float       x1     = (float)gradient.getPoint1().getX();
                    float       x2     = (float)gradient.getPoint2().getX();
                    float       y1     = (float)gradient.getPoint1().getY();
                    float       y2     = (float)gradient.getPoint2().getY();
                    float       diffX  = x2 - x1;
                    float       diffY  = y2 - y1;
                    const float z      = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider.
                    linear = new LinearGradientBrush(
                        new PointF(x1 - z * diffX, y1 - z * diffY),
                        new PointF(x2 + z * diffX, y2 + z * diffY),
                        color1,
                        color1);
                    ColorBlend colorBlend = new ColorBlend(4);
                    Color[]    colors     = colorBlend.Colors;
                    colors[0] = colors[1] = color1;
                    colors[2] = colors[3] = color2;
                    float[] positions = colorBlend.Positions;
                    positions[1] = z / (2 * z + 1);
                    positions[2] = (z + 1) / (2 * z + 1);
                    positions[3] = 1.0f;
                    linear.InterpolationColors = colorBlend;
                }
                linear.WrapMode = WrapMode.TileFlipXY;
                brush           = linear;
                pen.Brush       = brush;
                return;
            }

            if (paint is java.awt.TexturePaint)
            {
                java.awt.TexturePaint texture = (java.awt.TexturePaint)paint;
                brush = new TextureBrush(
                    J2C.ConvertImage(texture.getImage()),
                    J2C.ConvertRect(texture.getAnchorRect()));
                pen.Brush = brush;
                return;
            }

            throw new NotImplementedException("setPaint(" + paint.GetType().FullName + ")");
        }
コード例 #19
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 public override void setTransform(java.awt.geom.AffineTransform tx)
 {
     g.Transform = J2C.ConvertTransform(tx);
     this.tx     = tx;
 }
コード例 #20
0
ファイル: graphics.cs プロジェクト: maikebing/IKVM.NetCore
 /// <summary>
 /// Apparently there is no rounded rec function in .Net. Draw the
 /// rounded rectangle by using lines and arcs.
 /// </summary>
 public override void drawRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight)
 {
     using (GraphicsPath gp = J2C.ConvertRoundRect(x, y, w, h, arcWidth, arcHeight))
         g.DrawPath(pen, gp);
 }