summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java')
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java72
1 files changed, 18 insertions, 54 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java
index c5e751f68ef..d6b3de8c07f 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java
@@ -75,13 +75,21 @@ public class GdkTextLayout
initStaticState ();
}
private native void setText(String str);
+ private native void setFont(GdkFontPeer font);
private native void getExtents(double[] inkExtents,
double[] logExtents);
private native void indexToPos(int idx, double[] pos);
+
private native void initState ();
+
private native void dispose ();
+
+ private native void cairoDrawGdkTextLayout(CairoGraphics2D g, float x, float y);
+
static native void initStaticState();
+
private final int native_state = GtkGenericPeer.getUniqueInteger ();
+
protected void finalize ()
{
dispose ();
@@ -97,6 +105,15 @@ public class GdkTextLayout
initState();
attributedString = str;
fontRenderContext = frc;
+ AttributedCharacterIterator aci = str.getIterator();
+ char[] chars = new char[aci.getEndIndex() - aci.getBeginIndex()];
+ for(int i = aci.getBeginIndex(); i < aci.getEndIndex(); i++)
+ chars[i] = aci.setIndex(i);
+ setText(new String(chars));
+
+ Object fnt = aci.getAttribute(TextAttribute.FONT);
+ if (fnt != null && fnt instanceof Font)
+ setFont( (GdkFontPeer) ((Font)fnt).getPeer() );
}
protected class CharacterIteratorProxy
@@ -199,60 +216,7 @@ public class GdkTextLayout
public void draw (Graphics2D g2, float x, float y)
{
- if (g2 instanceof GdkGraphics2D)
- {
- // we share pango structures directly with GdkGraphics2D
- // when legal
- GdkGraphics2D gg2 = (GdkGraphics2D) g2;
- gg2.drawGdkTextLayout(this, x, y);
- }
- else
- {
- // falling back to a rather tedious layout algorithm when
- // not legal
- AttributedCharacterIterator ci = attributedString.getIterator ();
- CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci);
- Font defFont = g2.getFont ();
-
- /* Note: this implementation currently only interprets FONT text
- * attributes. There is a reasonable argument to be made for some
- * attributes being interpreted out here, where we have control of the
- * Graphics2D and can construct or derive new fonts, and some
- * attributes being interpreted by the GlyphVector itself. So far, for
- * all attributes except FONT we do neither.
- */
-
- for (char c = ci.first ();
- c != CharacterIterator.DONE;
- c = ci.next ())
- {
- proxy.begin = ci.getIndex ();
- proxy.limit = ci.getRunLimit(TextAttribute.FONT);
- if (proxy.limit <= proxy.begin)
- continue;
-
- proxy.index = proxy.begin;
-
- Object fnt = ci.getAttribute(TextAttribute.FONT);
- GlyphVector gv;
- if (fnt instanceof Font)
- gv = ((Font)fnt).createGlyphVector (fontRenderContext, proxy);
- else
- gv = defFont.createGlyphVector (fontRenderContext, proxy);
-
- g2.drawGlyphVector (gv, x, y);
-
- int n = gv.getNumGlyphs ();
- for (int i = 0; i < n; ++i)
- {
- GlyphMetrics gm = gv.getGlyphMetrics (i);
- if (gm.getAdvanceX() == gm.getAdvance ())
- x += gm.getAdvanceX ();
- else
- y += gm.getAdvanceY ();
- }
- }
- }
+ cairoDrawGdkTextLayout((CairoGraphics2D)g2, x, y);
}
public TextHitInfo getStrongCaret (TextHitInfo hit1,