Пример #1
0
        /// <summary> Draws the rectangle.
        /// The draw-position is translated by (-offsetX,-offsetY)
        /// and scaled by (factorX,factorY).
        /// </summary>
        /// <param name="canvas">The canvas to draw the arrow on
        /// </param>
        /// <param name="offsetX">Translation-Vector's negative x-component
        /// </param>
        /// <param name="offsetY">Translation-Vector's negative y-component
        /// </param>
        /// <param name="factorX">Scaling-Vector*s x-component
        /// </param>
        /// <param name="factorY">Scaling-Vector*s y-component
        ///
        /// </param>
        public virtual void  draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int x = (int)System.Math.Round((this.x - offsetX) * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int y = (int)System.Math.Round((this.y - offsetY) * factorY);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int width = (int)System.Math.Round(this.width * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int height = (int)System.Math.Round(this.height * factorY);

            canvas.setColor(bgcolor);
            canvas.fillRect(x, y, width + 1, height + 1);
            canvas.setColor(bordercolor);
            canvas.drawRect(x, y, width, height);
            canvas.setColor(System.Drawing.Color.Black);
            //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
            if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
            {
                canvas.setColor(System.Drawing.Color.White);
            }
            if (height > 10)
            {
                System.Drawing.Point textpos = calculateTextPosition(text, canvas, width, height);
                canvas.drawString(text, (int)textpos.X + x, (int)textpos.Y + y);
            }
        }
Пример #2
0
        /// <summary>
        /// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
        /// </summary>
        /// <param name="font"></param>
        /// <returns></returns>
        public static int getStringDrawOffset(java.awt.Font font)
        {
            int ret = 0;

            java.awt.Dimension size = measureString(PANGRAM, font);
            if (size.height <= 0)
            {
                return(0);
            }
            java.awt.Image      b  = null;
            java.awt.Graphics2D g  = null;
            BitmapEx            b2 = null;

            try {
                int string_desty = size.height * 2; // 文字列が書き込まれるy座標
                int w            = size.width * 4;
                int h            = size.height * 4;
                b       = new java.awt.Image();
                b.image = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                g       = new java.awt.Graphics2D(System.Drawing.Graphics.FromImage(b.image));
                g.setColor(java.awt.Color.white);
                g.fillRect(0, 0, w, h);
                g.setFont(font);
                g.setColor(java.awt.Color.black);
                g.drawString(PANGRAM, size.width, string_desty);

                b2 = new BitmapEx(b.image);
                // 上端に最初に現れる色つきピクセルを探す
                int  firsty = 0;
                bool found  = false;
                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found  = true;
                            firsty = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                // 下端
                int endy = h - 1;
                found = false;
                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found = true;
                            endy  = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                int center = (firsty + endy) / 2;
                ret = center - string_desty;
            } catch (Exception ex) {
                serr.println("Util#getStringDrawOffset; ex=" + ex);
            } finally {
                if (b != null && b.image != null)
                {
                    b.image.Dispose();
                }
                if (g != null)
                {
                    g.nativeGraphics.Dispose();
                }
                if (b2 != null && b2 != null)
                {
                    b2.Dispose();
                }
            }
            return(ret);
        }
Пример #3
0
        public virtual void draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int x = (int) System.Math.Round((this.x - offsetX) * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int y = (int) System.Math.Round((this.y - offsetY) * factorY);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int width = (int) System.Math.Round(this.width * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int height = (int) System.Math.Round(this.height * factorY);
            // draw the left oval
            canvas.setColor(bgcolor);
            canvas.fillOval(x, y, height + 1, height + 1);
            canvas.setColor(bordercolor);
            canvas.drawOval(x, y, height, height);
            // draw the right oval
            canvas.setColor(bgcolor);
            canvas.fillOval(x + width - height, y, height + 1, height + 1);
            canvas.setColor(bordercolor);
            canvas.drawOval(x + width - height, y, height, height);
            // draw the center rectangle
            canvas.setColor(bgcolor);
            canvas.fillRect(x + (height / 2), y, width - height + 1, height + 1);
            canvas.setColor(bordercolor);
            canvas.drawLine(x + (height / 2), y, x + width - height / 2, y);
            canvas.drawLine(x + (height / 2), y + height + 1, x + width - height / 2, y + height + 1);

            // draw the text
            canvas.setColor(System.Drawing.Color.Black);
            //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
            if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
                canvas.setColor(System.Drawing.Color.White);
            if (height > 10)
            {
                System.Drawing.Point textpos = calculateTextPosition(text, canvas, width, height);
                canvas.drawString(text, (int) textpos.X + x, (int) textpos.Y + y);
            }
        }