This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi, On Thu, 2004-09-02 at 21:04, Mark Wielaard wrote: > To get the JFreeChart demo program working as described on > http://classpath.wildebeest.org/dairy/index.php?p=31 > I needed the following Fixlets/Workarounds: On irc Graydon told me to just remove the asserts() and replace them with if blocks since they were wrong in the first place. And to save and restore the new Composite field in DrawState. I have committed this slightly revised patch which does both: 2004-09-03 Mark Wielaard <mark@klomp.org> * gnu/java/awt/peer/gtk/GdkGraphics.java (setColor): Use Color.BLACK if c == null, don't create new Color object each time. * gnu/java/awt/peer/gtk/GdkGraphics2D.java (comp): New private field. (setColor): Use Color.BLACK when argument null. (setComposite): Set this.comp field. (getComposite): Return this.comp, or AlphaComposite.SrcOver when null. (DrawState.comp): New private field. (DrawState.save): Save Composite. (DrawState.restore): Restore comp field. * java/awt/FontMetrics.java (gRC): New static final private field. (getLineMetrics(String, Graphics)): New method. (getLineMetrics(String, int, int, Graphics)): Likewise. (getLineMetrics(char[], int, int, Graphics)): Likewise. (getLineMetrics(CharacterIterator, int, int, Graphics)): Likewise. * javax/swing/JMenu.java (JMenu(String, boolean)): Ignore tearoff argument. PR SWING/17294. * javax/swing/plaf/basic/BasicGraphicsUtils.java (): Always use the fall-back code since none of the TextArea methods are really implemented now. PR SWING/17296. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c (GdkGlyphVector_setChars): Replace assert() with if block when pango_itemize() returns null. PR AWT/17295. (GdkGlyphVector_allInkExtents): Likewise when vec->glyphitems is null. With this the jfreechart demo (http://www.jfree.org/jfreechart/jfreechart-0.9.20.tar.gz) works out of the box (more or less) on the gui branch with: gij -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D -classpath jfreechart-0.9.20-demo.jar:jfreechart-0.9.20.jar:lib/jcommon-0.9.5.jar org.jfree.chart.demo.JFreeChartDemo Try it out, it is fun! (But a bit slow, so have patience.) Cheers, Mark
Index: gnu/java/awt/peer/gtk/GdkGraphics.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java,v retrieving revision 1.4.16.7 diff -u -r1.4.16.7 GdkGraphics.java --- gnu/java/awt/peer/gtk/GdkGraphics.java 2 Sep 2004 21:26:21 -0000 1.4.16.7 +++ gnu/java/awt/peer/gtk/GdkGraphics.java 3 Sep 2004 22:53:38 -0000 @@ -394,7 +394,7 @@ public void setColor (Color c) { if (c == null) - color = new Color (0, 0, 0); + color = Color.BLACK; else color = c; Index: gnu/java/awt/peer/gtk/GdkGraphics2D.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java,v retrieving revision 1.7.2.15 diff -u -r1.7.2.15 GdkGraphics2D.java --- gnu/java/awt/peer/gtk/GdkGraphics2D.java 30 Jul 2004 19:29:40 -0000 1.7.2.15 +++ gnu/java/awt/peer/gtk/GdkGraphics2D.java 3 Sep 2004 22:53:43 -0000 @@ -85,6 +85,8 @@ private RenderingHints hints; private BufferedImage bimage; + private Composite comp; + private Stack stateStack; native private void initState (GtkComponentPeer component); @@ -268,6 +270,7 @@ private Shape clip; private AffineTransform transform; private Font font; + private Composite comp; DrawState (GdkGraphics2D g) { this.paint = g.paint; @@ -278,6 +281,7 @@ if (g.transform != null) this.transform = (AffineTransform) g.transform.clone(); this.font = g.font; + this.comp = g.comp; } public void restore(GdkGraphics2D g) { @@ -288,6 +292,7 @@ g.clip = this.clip; g.transform = this.transform; g.font = this.font; + g.comp = this.comp; } } @@ -771,6 +776,9 @@ public void setColor (Color c) { + if (c == null) + c = Color.BLACK; + fg = c; paint = c; cairoSetRGBColor (fg.getRed() / 255.0, @@ -1259,6 +1267,8 @@ public void setComposite(Composite comp) { + this.comp = comp; + if (comp instanceof AlphaComposite) { AlphaComposite a = (AlphaComposite) comp; @@ -1345,7 +1355,10 @@ public Composite getComposite() { - throw new java.lang.UnsupportedOperationException (); + if (comp == null) + return AlphaComposite.SrcOver; + else + return comp; } public FontRenderContext getFontRenderContext () Index: java/awt/FontMetrics.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/java/awt/FontMetrics.java,v retrieving revision 1.5.2.1 diff -u -r1.5.2.1 FontMetrics.java --- java/awt/FontMetrics.java 24 Jun 2004 05:30:16 -0000 1.5.2.1 +++ java/awt/FontMetrics.java 3 Sep 2004 22:53:43 -0000 @@ -38,6 +38,10 @@ package java.awt; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.text.CharacterIterator; + // FIXME: I leave many methods basically unimplemented. This // should be reviewed. @@ -349,6 +353,114 @@ + ",descent=" + getDescent() + ",height=" + getHeight() + "]"); } + +// Generic FontRenderContext used when getLineMetrics is called with a +// plain Graphics object. +private static final FontRenderContext gRC = new FontRenderContext(null, + false, + false); + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param text The string to calculate metrics from. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + */ +public LineMetrics getLineMetrics(String text, Graphics g) +{ + return getLineMetrics(text, 0, text.length(), g); +} + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param text The string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(String text, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(text, begin, limit, rc); +} + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param chars The string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(char[] chars, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(chars, begin, limit, rc); +} + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param rc The string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(CharacterIterator ci, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(ci, begin, limit, rc); +} + } // class FontMetrics Index: javax/swing/JMenu.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenu.java,v retrieving revision 1.3.8.11 diff -u -r1.3.8.11 JMenu.java --- javax/swing/JMenu.java 13 Jul 2004 15:45:35 -0000 1.3.8.11 +++ javax/swing/JMenu.java 3 Sep 2004 22:53:46 -0000 @@ -140,7 +140,8 @@ */ public JMenu(String text, boolean tearoff) { - throw new Error("not implemented"); + // FIXME: tearoff not implemented + this(text); } private void writeObject(ObjectOutputStream stream) throws IOException Index: javax/swing/plaf/basic/BasicGraphicsUtils.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicGraphicsUtils.java,v retrieving revision 1.7.2.2 diff -u -r1.7.2.2 BasicGraphicsUtils.java --- javax/swing/plaf/basic/BasicGraphicsUtils.java 9 Jun 2004 08:40:08 -0000 1.7.2.2 +++ javax/swing/plaf/basic/BasicGraphicsUtils.java 3 Sep 2004 22:53:46 -0000 @@ -1,5 +1,5 @@ /* BasicGraphicsUtils.java - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -455,7 +455,9 @@ drawUnderline = (underlinedIndex >= 0) && (underlinedIndex < textLength); - if (!(g instanceof Graphics2D)) + // XXX - FIXME we now always use this fall-back since TextLayout is + // almost completely not implemented. + if (!(g instanceof Graphics2D) || true) { /* Fall-back. This is likely to produce garbage for any text * containing right-to-left (Hebrew or Arabic) characters, even Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c =================================================================== RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c,v retrieving revision 1.2.12.2 diff -u -r1.2.12.2 gnu_java_awt_peer_gtk_GdkGlyphVector.c --- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c 21 May 2004 23:34:16 -0000 1.2.12.2 +++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c 3 Sep 2004 22:53:46 -0000 @@ -1,5 +1,5 @@ /* gdkglyphvector.c - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -274,48 +274,53 @@ pango_context_set_font_description (vec->ctx, vec->desc); items = pango_itemize (vec->ctx, str, 0, len, attrs, NULL); - g_assert (items != NULL); - - /* - step 2: for each item: - - shape the item into a glyphstring - - store the (item, glyphstring) pair in the vec->glyphitems list - */ - - if (vec->glyphitems != NULL) + if (items != NULL) { - free_glyphitems (vec->glyphitems); - vec->glyphitems = NULL; - } - - for (item = g_list_first (items); item != NULL; item = g_list_next (item)) - { - g_assert (item->data != NULL); - - gi = NULL; - gi = g_malloc0 (sizeof(PangoGlyphItem)); - g_assert (gi != NULL); - - gi->item = (PangoItem *)item->data; - gi->glyphs = pango_glyph_string_new (); - g_assert (gi->glyphs != NULL); - - pango_shape (str + gi->item->offset, - gi->item->length, - &(gi->item->analysis), - gi->glyphs); - - vec->glyphitems = g_list_append (vec->glyphitems, gi); + + /* + step 2: for each item: + - shape the item into a glyphstring + - store the (item, glyphstring) pair in the vec->glyphitems list + */ + + if (vec->glyphitems != NULL) + { + free_glyphitems (vec->glyphitems); + vec->glyphitems = NULL; + } + + for (item = g_list_first (items); + item != NULL; + item = g_list_next (item)) + { + g_assert (item->data != NULL); + + gi = NULL; + gi = g_malloc0 (sizeof(PangoGlyphItem)); + g_assert (gi != NULL); + + gi->item = (PangoItem *)item->data; + gi->glyphs = pango_glyph_string_new (); + g_assert (gi->glyphs != NULL); + + pango_shape (str + gi->item->offset, + gi->item->length, + &(gi->item->analysis), + gi->glyphs); + + vec->glyphitems = g_list_append (vec->glyphitems, gi); + } + + /* + ownership of each item has been transferred to glyphitems, + but the list should be freed. + */ + + g_list_free (items); } - /* - ownership of each item has been transferred to glyphitems, - but the list should be freed. - */ - - g_list_free (items); pango_attr_list_unref (attrs); - + (*env)->ReleaseStringUTFChars (env, chars, str); gdk_threads_leave (); } @@ -436,33 +441,36 @@ g_assert (self != NULL); vec = (struct glyphvec *)NSA_GET_GV_PTR (env, self); g_assert (vec != NULL); - g_assert (vec->glyphitems != NULL); - - pointsize = pango_font_description_get_size (vec->desc); - pointsize /= (double) PANGO_SCALE; - - for (i = g_list_first (vec->glyphitems); i != NULL; i = g_list_next (i)) + if (vec->glyphitems != NULL) { - g_assert (i->data != NULL); - gi = (PangoGlyphItem *)i->data; - g_assert (gi->glyphs != NULL); - - face = pango_ft2_font_get_face (gi->item->analysis.font); - assume_pointsize_and_identity_transform (pointsize, face); + pointsize = pango_font_description_get_size (vec->desc); + pointsize /= (double) PANGO_SCALE; - for (j = 0; j < gi->glyphs->num_glyphs; ++j) + for (i = g_list_first (vec->glyphitems); i != NULL; i = g_list_next (i)) { - FT_Load_Glyph (face, gi->glyphs->glyphs[j].glyph, FT_LOAD_DEFAULT); - /* FIXME: this needs to change for vertical layouts */ - tmp.x = x + DOUBLE_FROM_26_6 (face->glyph->metrics.horiBearingX); - tmp.y = y + DOUBLE_FROM_26_6 (face->glyph->metrics.horiBearingY); - tmp.width = DOUBLE_FROM_26_6 (face->glyph->metrics.width); - tmp.height = DOUBLE_FROM_26_6 (face->glyph->metrics.height); - union_rects (&rect, &tmp); - x += DOUBLE_FROM_26_6 (face->glyph->advance.x); - y += DOUBLE_FROM_26_6 (face->glyph->advance.y); - } - } + g_assert (i->data != NULL); + gi = (PangoGlyphItem *)i->data; + g_assert (gi->glyphs != NULL); + + face = pango_ft2_font_get_face (gi->item->analysis.font); + assume_pointsize_and_identity_transform (pointsize, face); + + for (j = 0; j < gi->glyphs->num_glyphs; ++j) + { + FT_Load_Glyph (face, + gi->glyphs->glyphs[j].glyph, + FT_LOAD_DEFAULT); + /* FIXME: this needs to change for vertical layouts */ + tmp.x = x + DOUBLE_FROM_26_6 (face->glyph->metrics.horiBearingX); + tmp.y = y + DOUBLE_FROM_26_6 (face->glyph->metrics.horiBearingY); + tmp.width = DOUBLE_FROM_26_6 (face->glyph->metrics.width); + tmp.height = DOUBLE_FROM_26_6 (face->glyph->metrics.height); + union_rects (&rect, &tmp); + x += DOUBLE_FROM_26_6 (face->glyph->advance.x); + y += DOUBLE_FROM_26_6 (face->glyph->advance.y); + } + } + } ret = rect_to_array (env, &rect); gdk_threads_leave ();
Attachment:
signature.asc
Description: This is a digitally signed message part
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |