[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Import gtk-cairo text/font fixes from gcj gui branch p
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: Import gtk-cairo text/font fixes from gcj gui branch plus other workarounds |
Date: |
Sun, 05 Sep 2004 17:01:30 +0200 |
Hi,
This imports the work done on the gcj gui branch to get text under
Graphics2D working better and makes the JFreeChart demo work (more or
less).
Unfortunately I also need the following additional workaround:
2004-09-05 Mark Wielaard <address@hidden>
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c
(setChars): Only call pango_itemize() when vec->glyphitems != NULL.
Only call pango_shape() when gi->glyphs->num_glyphs > 0.
Somehow font selection/descriptors are foobared under pure GNU Classpath
runtimes. I have no idea what causes that though. There don't seem to be
any relevant differences between GNU Classpath CVS and gcj gui branch.
So although this patch enables the Swing Demo and the JFreeChart Demo to
work with e.g. jamvm it doesn't show any text which makes most of the
demo very boring...
Graydon, do you have any clue what could be happening here?
Also when using the packaged cairo from Debian testing/unstable I get:
** ERROR **: file
../../../../classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c:
line 279 (end_drawing_operation): assertion failed: (cairo_status (gr->cr) ==
CAIRO_STATUS_SUCCESS)
This doesn't happen with cairo from CVS though.
So please use the gcj gui branch for real Swing/Graphics2D work.
See http://people.redhat.com/fitzsim/gcj-and-jhbuild.html for
instructions.
2004-09-05 Mark Wielaard <address@hidden>
* 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.
Committed,
Mark
P.S. This is how you run the jfreechar-demo:
jamvm -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
This is after configuring with --enable-gtk-cairo (with cairo from CVS
installed).
But as said above, you will have to know where to click (or more
precisely, click just a little bit below with jamvm) since no text will
actually show. But some of the graphs do work now (without text of
course).
Index: gnu/java/awt/peer/gtk/GdkGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java,v
retrieving revision 1.28
diff -u -r1.28 GdkGraphics.java
--- gnu/java/awt/peer/gtk/GdkGraphics.java 9 Aug 2004 16:54:09 -0000
1.28
+++ gnu/java/awt/peer/gtk/GdkGraphics.java 5 Sep 2004 14:59:45 -0000
@@ -396,7 +396,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:
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java,v
retrieving revision 1.15
diff -u -r1.15 GdkGraphics2D.java
--- gnu/java/awt/peer/gtk/GdkGraphics2D.java 30 Jul 2004 16:43:18 -0000
1.15
+++ gnu/java/awt/peer/gtk/GdkGraphics2D.java 5 Sep 2004 14:59:45 -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: /cvsroot/classpath/classpath/java/awt/FontMetrics.java,v
retrieving revision 1.8
diff -u -r1.8 FontMetrics.java
--- java/awt/FontMetrics.java 17 Apr 2004 15:48:57 -0000 1.8
+++ java/awt/FontMetrics.java 5 Sep 2004 14:59:45 -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 address@hidden LineMetrics} object constructed with the
+ * specified text and the address@hidden 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 address@hidden LineMetrics} object.
+ */
+public LineMetrics getLineMetrics(String text, Graphics g)
+{
+ return getLineMetrics(text, 0, text.length(), g);
+}
+
+/**
+ * Returns a address@hidden LineMetrics} object constructed with the
+ * specified text and the address@hidden 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 address@hidden 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 address@hidden LineMetrics} object constructed with the
+ * specified text and the address@hidden 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 address@hidden 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 address@hidden LineMetrics} object constructed with the
+ * specified text and the address@hidden 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 address@hidden 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: /cvsroot/classpath/classpath/javax/swing/JMenu.java,v
retrieving revision 1.8
diff -u -r1.8 JMenu.java
--- javax/swing/JMenu.java 30 Jul 2004 20:21:19 -0000 1.8
+++ javax/swing/JMenu.java 5 Sep 2004 14:59:45 -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:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicGraphicsUtils.java,v
retrieving revision 1.9
diff -u -r1.9 BasicGraphicsUtils.java
--- javax/swing/plaf/basic/BasicGraphicsUtils.java 29 Apr 2004 07:00:34
-0000 1.9
+++ javax/swing/plaf/basic/BasicGraphicsUtils.java 5 Sep 2004 14:59:45
-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: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c,v
retrieving revision 1.6
diff -u -r1.6 gnu_java_awt_peer_gtk_GdkGlyphVector.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c 31 May 2004
21:12:11 -0000 1.6
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c 5 Sep 2004
14:59:45 -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.
@@ -273,49 +273,58 @@
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)
+ items = pango_itemize (vec->ctx, str, 0, len, attrs, 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);
+
+ if (gi->glyphs->num_glyphs > 0)
+ {
+ 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 +445,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 ();
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Import gtk-cairo text/font fixes from gcj gui branch plus other workarounds,
Mark Wielaard <=