public virtual void paint(System.Drawing.Graphics g) { Graphics2D gr = (Graphics2D)g; gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setFont(font); Iterator itshapes = shapes.iterator(); Iterator itarrows = lines.iterator(); while (itshapes.hasNext()) { Shape s = (Shape)itshapes.next(); drawPrimitive(s, gr); } while (itarrows.hasNext()) { ConnectorLine l = (ConnectorLine)itarrows.next(); drawPrimitive(l, gr); } }
/// <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); }