//**************************************************************// //******************** Common Utilities **********************// //**************************************************************// public static TextRenderer getOrCreateTextRenderer(TextRendererCache cache, java.awt.Font font, bool antialiased, bool useFractionalMetrics, bool mipmap) { if (cache == null) { String message = Logging.getMessage("nullValue.CacheIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (font == null) { String message = Logging.getMessage("nullValue.FontIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } TextRendererCache.CacheKey key = new TextRendererCache.CacheKey(font, antialiased, useFractionalMetrics, mipmap); TextRenderer value = cache.get(key); if (value == null) { value = new OGLTextRenderer(font, antialiased, useFractionalMetrics, null, mipmap); cache.put(key, value); } return(value); }
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); }
/// <summary> /// 指定された文字列を指定されたフォントで描画したときのサイズを計測します。 /// </summary> /// <param name="text"></param> /// <param name="font"></param> /// <returns></returns> public static java.awt.Dimension measureString(string text, java.awt.Font font) { using (Bitmap dumy = new Bitmap(1, 1)) using (Graphics g = Graphics.FromImage(dumy)) { SizeF tmp = g.MeasureString(text, font.font); return(new java.awt.Dimension((int)tmp.Width, (int)tmp.Height)); } }
public override void setFont(java.awt.Font f) { if (f != null && f != font) { netfont = f.getNetFont(); font = f; } }
protected NetGraphics(Graphics g, java.awt.Font font, Color fgcolor, Color bgcolor) { if (font == null) { font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12); } this.font = font; netfont = font.getNetFont(); this.color = fgcolor; this.bgcolor = bgcolor; init(g); }
public CacheKey(java.awt.Font font, bool antialiased, bool useFractionalMetrics, bool mipmap) { if (font == null) { String message = Logging.getMessage("nullValue.FontIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.font = font; this.antialiased = antialiased; this.useFractionalMetrics = useFractionalMetrics; this.mipmap = mipmap; }
private java.awt.Font getFont() { if (component != null) { return(component.getFont()); } else { if (defaultFont == null) { defaultFont = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12); } return(defaultFont); } }
internal static java.awt.Font ConvertFont(Font font) { float size = font.Size; if (font.Unit != GraphicsUnit.Pixel) { size = font.SizeInPoints * java.awt.Toolkit.getDefaultToolkit().getScreenResolution() / 72; } java.awt.Font jFont = new java.awt.Font(font.Name, (int)font.Style, (int)size); if (jFont.getSize2D() != size) { jFont = jFont.deriveFont(size); } //TODO performance we should set the .NET Font, we can do it with an aditional constructor. return jFont; }
internal static java.awt.Font ConvertFont(Font font) { float size = font.Size; if (font.Unit != GraphicsUnit.Pixel) { size = font.SizeInPoints * java.awt.Toolkit.getDefaultToolkit().getScreenResolution() / 72; } java.awt.Font jFont = new java.awt.Font(font.Name, (int)font.Style, (int)size); if (jFont.getSize2D() != size) { jFont = jFont.deriveFont(size); } //TODO performance we should set the .NET Font, we can do it with an aditional constructor. return(jFont); }
public static TextRenderer getOrCreateTextRenderer(TextRendererCache cache, java.awt.Font font) { if (cache == null) { String message = Logging.getMessage("nullValue.CacheIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (font == null) { String message = Logging.getMessage("nullValue.FontIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } return(getOrCreateTextRenderer(cache, font, DEFAULT_ANTIALIAS, DEFAULT_USE_FRACTIONAL_METRICS, DEFAULT_MIPMAP)); }
public override java.awt.Font[] getAllFonts() { #if WINFX System.Collections.Generic.ICollection <Typeface> typefaces = System.Windows.Media.Fonts.SystemTypefaces; java.awt.Font[] fonts = new java.awt.Font[typefaces.Count]; int i = 0; foreach (Typeface face in typefaces) { FontFamily family = face.FontFamily; fonts[i++] = new java.awt.Font(family.GetName(0), face.Style, 1); } #else String[] names = getAvailableFontFamilyNames(); java.awt.Font[] fonts = new java.awt.Font[names.Length]; for (int i = 0; i < fonts.Length; i++) { fonts[i] = new java.awt.Font(names[i], 0, 1); } return(fonts); #endif }
public override java.awt.Font[] getAllFonts() { #if WINFX System.Collections.Generic.ICollection<Typeface> typefaces = System.Windows.Media.Fonts.SystemTypefaces; java.awt.Font[] fonts = new java.awt.Font[typefaces.Count]; int i = 0; foreach (Typeface face in typefaces) { FontFamily family = face.FontFamily; fonts[i++] = new java.awt.Font(family.GetName(0), face.Style, 1); } #else String[] names = getAvailableFontFamilyNames(); java.awt.Font[] fonts = new java.awt.Font[names.Length]; for(int i=0; i<fonts.Length; i++) { fonts[i] = new java.awt.Font(names[i], 0, 1); } return fonts; #endif }
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; } } }
internal BitmapGraphics(Bitmap bitmap, java.awt.Font font, Color fgcolor, Color bgcolor) : base(createGraphics(bitmap), font, fgcolor, bgcolor) { this.bitmap = bitmap; }
public override java.awt.FontMetrics getFontMetrics(java.awt.Font f) { return(new NetFontMetrics(f)); }
private java.awt.Font getFont() { if (component != null) { return component.getFont(); } else { if (defaultFont == null) { defaultFont = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12); } return defaultFont; } }
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; }
public static void applyFontRecurse(Control c, java.awt.Font font) { applyFontRecurse(c, font.font); }
public OGLTextRenderer(java.awt.Font font, bool antialiased, bool useFractionalMetrics) { this(font, antialiased, useFractionalMetrics, null, DEFAULT_MIPMAP); }
/// <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); }
protected NetGraphics(Graphics g, Object destination, java.awt.Font font, Color fgcolor, Color bgcolor) //: base( new sun.java2d.SurfaceData(destination) ) { if (font == null) { font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12); } this.font = font; netfont = font.getNetFont(); this.color = fgcolor; this.bgcolor = bgcolor; composite = CompositeHelper.Create(javaComposite, g); init(g); }
public override void setFont(java.awt.Font f) { if (f != null && f != font) { netfont = f.getNetFont(); font = f; baseline = getBaseline( netfont, g.TextRenderingHint ); } }
public OGLTextRenderer(java.awt.Font font, bool antialiased, bool useFractionalMetrics, RenderDelegate renderDelegate, bool mipmap) { super(font, antialiased, useFractionalMetrics, renderDelegate, mipmap); this.initialize(); }
public NetFontMetrics(java.awt.Font font) : base(font) { }
public OGLTextRenderer(java.awt.Font font, bool mipmap) { this(font, DEFAULT_ANTIALIAS, DEFAULT_USE_FRACTIONAL_METRICS, null, mipmap); }
public OGLTextRenderer(java.awt.Font font, bool antialiased, bool useFractionalMetrics, RenderDelegate renderDelegate) { this(font, antialiased, useFractionalMetrics, renderDelegate, DEFAULT_MIPMAP); }
protected NetGraphics(Graphics g, java.awt.Font font, Color fgcolor, Color bgcolor) { if (font == null) { font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12); } this.font = font; netfont = font.getNetFont(); this.color = fgcolor; this.bgcolor = bgcolor; composite = CompositeHelper.Create(javaComposite, g); init(g); }
public OGLTextRenderer(java.awt.Font font) { this(font, DEFAULT_ANTIALIAS, DEFAULT_USE_FRACTIONAL_METRICS, null, DEFAULT_MIPMAP); }