diff options
author | Silenio Quarti | 2003-10-06 21:21:00 +0000 |
---|---|---|
committer | Silenio Quarti | 2003-10-06 21:21:00 +0000 |
commit | 6a55ff57c5e25d0fe7366672ba43a62be6a8c849 (patch) | |
tree | 725ec2ace7476d97de45da145f3cb7b70ed8bfdc | |
parent | 874aac6a9b009b5b54b41c0db30484b450bf3271 (diff) | |
download | eclipse.platform.swt-6a55ff57c5e25d0fe7366672ba43a62be6a8c849.tar.gz eclipse.platform.swt-6a55ff57c5e25d0fe7366672ba43a62be6a8c849.tar.xz eclipse.platform.swt-6a55ff57c5e25d0fe7366672ba43a62be6a8c849.zip |
caching string
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java | 106 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java | 3 |
2 files changed, 46 insertions, 63 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java index d74b6fbab4..c74351e647 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java @@ -876,39 +876,10 @@ public void drawText(String string, int x, int y, boolean isTransparent) { public void drawText (String string, int x, int y, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int mnemonic, length = string.length(); + int length = string.length(); if (length == 0) return; - byte[] buffer; int layout = data.layout; - char[] text = new char[length]; - string.getChars(0, length, text, 0); - if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) { - char[] text1 = new char[mnemonic - 1]; - System.arraycopy(text, 0, text1, 0, text1.length); - byte[] buffer1 = Converter.wcsToMbcs(null, text1, false); - char[] text2 = new char[text.length - mnemonic]; - System.arraycopy(text, mnemonic - 1, text2, 0, text2.length); - byte[] buffer2 = Converter.wcsToMbcs(null, text2, false); - buffer = new byte[buffer1.length + buffer2.length]; - System.arraycopy(buffer1, 0, buffer, 0, buffer1.length); - System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length); - int attr_list = OS.pango_attr_list_new(); - int attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW); - PangoAttribute attribute = new PangoAttribute(); - OS.memmove(attribute, attr, PangoAttribute.sizeof); - attribute.start_index = buffer1.length; - attribute.end_index = buffer1.length + 1; - OS.memmove(attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attr_list, attr); - OS.pango_layout_set_attributes(layout, attr_list); - OS.pango_attr_list_unref(attr_list); - } else { - buffer = Converter.wcsToMbcs(null, text, false); - OS.pango_layout_set_attributes(layout, 0); - } - OS.pango_layout_set_text(layout, buffer, buffer.length); - OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0); - OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab); + setString(string, flags); GdkColor background = null; if ((flags & SWT.DRAW_TRANSPARENT) == 0) background = getBackground().handle; if (!data.xorMode) { @@ -1812,6 +1783,45 @@ public void setLineWidth(int width) { OS.gdk_gc_set_line_attributes(handle, width, line_style, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); } +void setString(String string, int flags) { + if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) { + return; + } + byte[] buffer; + int mnemonic, layout = data.layout, length = string.length (); + char[] text = new char[length]; + string.getChars(0, length, text, 0); + if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) { + char[] text1 = new char[mnemonic - 1]; + System.arraycopy(text, 0, text1, 0, text1.length); + byte[] buffer1 = Converter.wcsToMbcs(null, text1, false); + char[] text2 = new char[text.length - mnemonic]; + System.arraycopy(text, mnemonic - 1, text2, 0, text2.length); + byte[] buffer2 = Converter.wcsToMbcs(null, text2, false); + buffer = new byte[buffer1.length + buffer2.length]; + System.arraycopy(buffer1, 0, buffer, 0, buffer1.length); + System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length); + int attr_list = OS.pango_attr_list_new(); + int attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW); + PangoAttribute attribute = new PangoAttribute(); + OS.memmove(attribute, attr, PangoAttribute.sizeof); + attribute.start_index = buffer1.length; + attribute.end_index = buffer1.length + 1; + OS.memmove(attr, attribute, PangoAttribute.sizeof); + OS.pango_attr_list_insert(attr_list, attr); + OS.pango_layout_set_attributes(layout, attr_list); + OS.pango_attr_list_unref(attr_list); + } else { + buffer = Converter.wcsToMbcs(null, text, false); + OS.pango_layout_set_attributes(layout, 0); + } + OS.pango_layout_set_text(layout, buffer, buffer.length); + OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0); + OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab); + data.string = string; + data.drawFlags = flags; +} + /** * If the argument is <code>true</code>, puts the receiver * in a drawing mode where the resulting color in the destination @@ -1912,39 +1922,9 @@ public Point textExtent(String string) { public Point textExtent(String string, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int mnemonic, length = string.length(); - byte[] buffer; - int layout = data.layout; - char[] text = new char[length]; - string.getChars(0, length, text, 0); - if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) { - char[] text1 = new char[mnemonic - 1]; - System.arraycopy(text, 0, text1, 0, text1.length); - byte[] buffer1 = Converter.wcsToMbcs(null, text1, false); - char[] text2 = new char[text.length - mnemonic]; - System.arraycopy(text, mnemonic - 1, text2, 0, text2.length); - byte[] buffer2 = Converter.wcsToMbcs(null, text2, false); - buffer = new byte[buffer1.length + buffer2.length]; - System.arraycopy(buffer1, 0, buffer, 0, buffer1.length); - System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length); - int attr_list = OS.pango_attr_list_new(); - int attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW); - PangoAttribute attribute = new PangoAttribute(); - OS.memmove(attribute, attr, PangoAttribute.sizeof); - attribute.start_index = buffer1.length; - attribute.end_index = buffer1.length + 1; - OS.memmove(attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attr_list, attr); - OS.pango_layout_set_attributes(layout, attr_list); - OS.pango_attr_list_unref(attr_list); - } else { - buffer = Converter.wcsToMbcs(null, text, false); - } - OS.pango_layout_set_text(layout, buffer, buffer.length); - OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0); - OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab); + setString(string, flags); int[] width = new int[1], height = new int[1]; - OS.pango_layout_get_size(layout, width, height); + OS.pango_layout_get_size(data.layout, width, height); return new Point(OS.PANGO_PIXELS(width[0]), OS.PANGO_PIXELS(height[0])); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java index d1f32bdcef..155819aca0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java @@ -37,4 +37,7 @@ public final class GCData { public int clipRgn; public int lineStyle = SWT.LINE_SOLID; public boolean xorMode; + + public String string; + public int drawFlags; } |