diff options
author | Felipe Heidrich <fheidric> | 2004-05-07 20:05:58 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2004-05-07 20:05:58 +0000 |
commit | 88d0b371a82ed8f1081c2933382ac5c0ad56880e (patch) | |
tree | c3f592fa3fca6348181039251e2aa67510e06b88 | |
parent | 62b114225776c09f8a6570dde053dd94358f28d9 (diff) | |
download | eclipse.platform.swt-88d0b371a82ed8f1081c2933382ac5c0ad56880e.tar.gz eclipse.platform.swt-88d0b371a82ed8f1081c2933382ac5c0ad56880e.tar.xz eclipse.platform.swt-88d0b371a82ed8f1081c2933382ac5c0ad56880e.zip |
60913
5 files changed, 226 insertions, 97 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 0e025bcbc8..08b02e8fef 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -9099,6 +9099,24 @@ JNIEXPORT void JNICALL OS_NATIVE(pango_1attr_1list_1unref) } #endif +#ifndef NO_pango_1attr_1shape_1new +JNIEXPORT jint JNICALL OS_NATIVE(pango_1attr_1shape_1new) + (JNIEnv *env, jclass that, jobject arg0, jobject arg1) +{ + PangoRectangle _arg0, *lparg0=NULL; + PangoRectangle _arg1, *lparg1=NULL; + jint rc; + OS_NATIVE_ENTER(env, that, pango_1attr_1shape_1new_FUNC); + if (arg0) lparg0 = getPangoRectangleFields(env, arg0, &_arg0); + if (arg1) lparg1 = getPangoRectangleFields(env, arg1, &_arg1); + rc = (jint)pango_attr_shape_new(lparg0, lparg1); + if (arg1) setPangoRectangleFields(env, arg1, lparg1); + if (arg0) setPangoRectangleFields(env, arg0, lparg0); + OS_NATIVE_EXIT(env, that, pango_1attr_1shape_1new_FUNC); + return rc; +} +#endif + #ifndef NO_pango_1attr_1strikethrough_1new JNIEXPORT jint JNICALL OS_NATIVE(pango_1attr_1strikethrough_1new) (JNIEnv *env, jclass that, jboolean arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 1014e0e482..18387a5b46 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -18,8 +18,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 816; -int OS_nativeFunctionCallCount[816]; +int OS_nativeFunctionCount = 817; +int OS_nativeFunctionCallCount[817]; char * OS_nativeFunctionNames[] = { "GDK_1DISPLAY", "GDK_1ROOT_1PARENT", @@ -768,6 +768,7 @@ char * OS_nativeFunctionNames[] = { "pango_1attr_1list_1insert", "pango_1attr_1list_1new", "pango_1attr_1list_1unref", + "pango_1attr_1shape_1new", "pango_1attr_1strikethrough_1new", "pango_1attr_1underline_1new", "pango_1attr_1weight_1new", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index a02ff8159e..54b0d42ca2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -770,72 +770,73 @@ char* OS_nativeFunctionNames[]; #define pango_1attr_1list_1insert_FUNC 744 #define pango_1attr_1list_1new_FUNC 745 #define pango_1attr_1list_1unref_FUNC 746 -#define pango_1attr_1strikethrough_1new_FUNC 747 -#define pango_1attr_1underline_1new_FUNC 748 -#define pango_1attr_1weight_1new_FUNC 749 -#define pango_1context_1get_1base_1dir_FUNC 750 -#define pango_1context_1get_1language_FUNC 751 -#define pango_1context_1get_1metrics_FUNC 752 -#define pango_1context_1list_1families_FUNC 753 -#define pango_1context_1set_1base_1dir_FUNC 754 -#define pango_1context_1set_1language_FUNC 755 -#define pango_1font_1description_1copy_FUNC 756 -#define pango_1font_1description_1free_FUNC 757 -#define pango_1font_1description_1from_1string_FUNC 758 -#define pango_1font_1description_1get_1family_FUNC 759 -#define pango_1font_1description_1get_1size_FUNC 760 -#define pango_1font_1description_1get_1style_FUNC 761 -#define pango_1font_1description_1get_1weight_FUNC 762 -#define pango_1font_1description_1new_FUNC 763 -#define pango_1font_1description_1set_1family_FUNC 764 -#define pango_1font_1description_1set_1size_FUNC 765 -#define pango_1font_1description_1set_1stretch_FUNC 766 -#define pango_1font_1description_1set_1style_FUNC 767 -#define pango_1font_1description_1set_1weight_FUNC 768 -#define pango_1font_1description_1to_1string_FUNC 769 -#define pango_1font_1face_1describe_FUNC 770 -#define pango_1font_1family_1list_1faces_FUNC 771 -#define pango_1font_1get_1metrics_FUNC 772 -#define pango_1font_1metrics_1get_1approximate_1char_1width_FUNC 773 -#define pango_1font_1metrics_1get_1ascent_FUNC 774 -#define pango_1font_1metrics_1get_1descent_FUNC 775 -#define pango_1font_1metrics_1unref_FUNC 776 -#define pango_1language_1from_1string_FUNC 777 -#define pango_1layout_1context_1changed_FUNC 778 -#define pango_1layout_1get_1alignment_FUNC 779 -#define pango_1layout_1get_1attributes_FUNC 780 -#define pango_1layout_1get_1iter_FUNC 781 -#define pango_1layout_1get_1line_FUNC 782 -#define pango_1layout_1get_1line_1count_FUNC 783 -#define pango_1layout_1get_1log_1attrs_FUNC 784 -#define pango_1layout_1get_1size_FUNC 785 -#define pango_1layout_1get_1spacing_FUNC 786 -#define pango_1layout_1get_1tabs_FUNC 787 -#define pango_1layout_1get_1text_FUNC 788 -#define pango_1layout_1get_1width_FUNC 789 -#define pango_1layout_1index_1to_1pos_FUNC 790 -#define pango_1layout_1iter_1free_FUNC 791 -#define pango_1layout_1iter_1get_1index_FUNC 792 -#define pango_1layout_1iter_1get_1line_1extents_FUNC 793 -#define pango_1layout_1iter_1get_1run_FUNC 794 -#define pango_1layout_1iter_1next_1line_FUNC 795 -#define pango_1layout_1iter_1next_1run_FUNC 796 -#define pango_1layout_1line_1get_1extents_FUNC 797 -#define pango_1layout_1line_1x_1to_1index_FUNC 798 -#define pango_1layout_1new_FUNC 799 -#define pango_1layout_1set_1alignment_FUNC 800 -#define pango_1layout_1set_1attributes_FUNC 801 -#define pango_1layout_1set_1font_1description_FUNC 802 -#define pango_1layout_1set_1single_1paragraph_1mode_FUNC 803 -#define pango_1layout_1set_1spacing_FUNC 804 -#define pango_1layout_1set_1tabs_FUNC 805 -#define pango_1layout_1set_1text_FUNC 806 -#define pango_1layout_1set_1width_FUNC 807 -#define pango_1layout_1set_1wrap_FUNC 808 -#define pango_1layout_1xy_1to_1index_FUNC 809 -#define pango_1tab_1array_1free_FUNC 810 -#define pango_1tab_1array_1get_1size_FUNC 811 -#define pango_1tab_1array_1get_1tabs_FUNC 812 -#define pango_1tab_1array_1new_FUNC 813 -#define pango_1tab_1array_1set_1tab_FUNC 814 -#define strlen_FUNC 815 +#define pango_1attr_1shape_1new_FUNC 747 +#define pango_1attr_1strikethrough_1new_FUNC 748 +#define pango_1attr_1underline_1new_FUNC 749 +#define pango_1attr_1weight_1new_FUNC 750 +#define pango_1context_1get_1base_1dir_FUNC 751 +#define pango_1context_1get_1language_FUNC 752 +#define pango_1context_1get_1metrics_FUNC 753 +#define pango_1context_1list_1families_FUNC 754 +#define pango_1context_1set_1base_1dir_FUNC 755 +#define pango_1context_1set_1language_FUNC 756 +#define pango_1font_1description_1copy_FUNC 757 +#define pango_1font_1description_1free_FUNC 758 +#define pango_1font_1description_1from_1string_FUNC 759 +#define pango_1font_1description_1get_1family_FUNC 760 +#define pango_1font_1description_1get_1size_FUNC 761 +#define pango_1font_1description_1get_1style_FUNC 762 +#define pango_1font_1description_1get_1weight_FUNC 763 +#define pango_1font_1description_1new_FUNC 764 +#define pango_1font_1description_1set_1family_FUNC 765 +#define pango_1font_1description_1set_1size_FUNC 766 +#define pango_1font_1description_1set_1stretch_FUNC 767 +#define pango_1font_1description_1set_1style_FUNC 768 +#define pango_1font_1description_1set_1weight_FUNC 769 +#define pango_1font_1description_1to_1string_FUNC 770 +#define pango_1font_1face_1describe_FUNC 771 +#define pango_1font_1family_1list_1faces_FUNC 772 +#define pango_1font_1get_1metrics_FUNC 773 +#define pango_1font_1metrics_1get_1approximate_1char_1width_FUNC 774 +#define pango_1font_1metrics_1get_1ascent_FUNC 775 +#define pango_1font_1metrics_1get_1descent_FUNC 776 +#define pango_1font_1metrics_1unref_FUNC 777 +#define pango_1language_1from_1string_FUNC 778 +#define pango_1layout_1context_1changed_FUNC 779 +#define pango_1layout_1get_1alignment_FUNC 780 +#define pango_1layout_1get_1attributes_FUNC 781 +#define pango_1layout_1get_1iter_FUNC 782 +#define pango_1layout_1get_1line_FUNC 783 +#define pango_1layout_1get_1line_1count_FUNC 784 +#define pango_1layout_1get_1log_1attrs_FUNC 785 +#define pango_1layout_1get_1size_FUNC 786 +#define pango_1layout_1get_1spacing_FUNC 787 +#define pango_1layout_1get_1tabs_FUNC 788 +#define pango_1layout_1get_1text_FUNC 789 +#define pango_1layout_1get_1width_FUNC 790 +#define pango_1layout_1index_1to_1pos_FUNC 791 +#define pango_1layout_1iter_1free_FUNC 792 +#define pango_1layout_1iter_1get_1index_FUNC 793 +#define pango_1layout_1iter_1get_1line_1extents_FUNC 794 +#define pango_1layout_1iter_1get_1run_FUNC 795 +#define pango_1layout_1iter_1next_1line_FUNC 796 +#define pango_1layout_1iter_1next_1run_FUNC 797 +#define pango_1layout_1line_1get_1extents_FUNC 798 +#define pango_1layout_1line_1x_1to_1index_FUNC 799 +#define pango_1layout_1new_FUNC 800 +#define pango_1layout_1set_1alignment_FUNC 801 +#define pango_1layout_1set_1attributes_FUNC 802 +#define pango_1layout_1set_1font_1description_FUNC 803 +#define pango_1layout_1set_1single_1paragraph_1mode_FUNC 804 +#define pango_1layout_1set_1spacing_FUNC 805 +#define pango_1layout_1set_1tabs_FUNC 806 +#define pango_1layout_1set_1text_FUNC 807 +#define pango_1layout_1set_1width_FUNC 808 +#define pango_1layout_1set_1wrap_FUNC 809 +#define pango_1layout_1xy_1to_1index_FUNC 810 +#define pango_1tab_1array_1free_FUNC 811 +#define pango_1tab_1array_1get_1size_FUNC 812 +#define pango_1tab_1array_1get_1tabs_FUNC 813 +#define pango_1tab_1array_1new_FUNC 814 +#define pango_1tab_1array_1set_1tab_FUNC 815 +#define strlen_FUNC 816 diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index 96cf379857..41f0dd0b3a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -1110,6 +1110,7 @@ public static final native void memset(int /*long*/ buffer, char c, int /*long*/ public static final synchronized native int /*long*/ pango_attr_background_new (short red, short green, short blue); public static final synchronized native int /*long*/ pango_attr_font_desc_new(int /*long*/ desc); public static final synchronized native int /*long*/ pango_attr_foreground_new (short red, short green, short blue); +public static final synchronized native int /*long*/ pango_attr_shape_new(PangoRectangle ink_rect, PangoRectangle logical_rect); public static final synchronized native void pango_attr_list_insert(int /*long*/ list, int /*long*/ attr); public static final synchronized native void pango_attr_list_change(int /*long*/ list, int /*long*/ attr); public static final synchronized native int /*long*/ pango_attr_list_new(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java index 046aef7949..bb41515dca 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java @@ -24,11 +24,12 @@ public final class TextLayout { Device device; Font font; String text; + int ascent, descent; int[] segments; StyleItem[] styles; int /*long*/ layout, context, attrList; - static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F'; + static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F', OBJECT_REPLACEMENT_CHARACTER = '\uFFFC'; public TextLayout (Device device) { if (device == null) device = Device.getDevice(); @@ -42,6 +43,7 @@ public TextLayout (Device device) { OS.pango_layout_set_tabs(layout, device.emptyTab); OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system()); text = ""; + ascent = descent = -1; styles = new StyleItem[2]; styles[0] = new StyleItem(); styles[1] = new StyleItem(); @@ -54,12 +56,42 @@ void checkLayout() { void computeRuns () { if (attrList != 0) return; - byte[] buffer = Converter.wcsToMbcs(null, getSegmentsText(), false); + String segmentsText = getSegmentsText(); + byte[] buffer = Converter.wcsToMbcs(null, segmentsText, false); OS.pango_layout_set_text (layout, buffer, buffer.length); - if (styles.length == 2 && styles[0].style == null) return; + if (styles.length == 2 && styles[0].style == null && ascent == -1 && descent == -1) return; int /*long*/ ptr = OS.pango_layout_get_text(layout); attrList = OS.pango_attr_list_new(); - PangoAttribute attribute = new PangoAttribute(); + PangoAttribute attribute = new PangoAttribute(); + if ((ascent != -1 || descent != -1) && segmentsText.length() > 0) { + int /*long*/ iter = OS.pango_layout_get_iter(layout); + if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); + PangoRectangle rect = new PangoRectangle(); + if (ascent != -1) rect.y = -(ascent * OS.PANGO_SCALE); + rect.height = (Math.max(0, ascent) + Math.max(0, descent)) * OS.PANGO_SCALE; + int lineCount = OS.pango_layout_get_line_count(layout); + char[] chars = new char[segmentsText.length() + lineCount]; + int oldPos = 0, count = 0; + do { + int /*long*/ attr = OS.pango_attr_shape_new (rect, rect); + OS.memmove (attribute, attr, PangoAttribute.sizeof); + int bytePos = OS.pango_layout_iter_get_index(iter); + attribute.start_index = bytePos + (count * 3); + attribute.end_index = bytePos+ 3 + (count * 3); + OS.memmove (attr, attribute, PangoAttribute.sizeof); + OS.pango_attr_list_insert(attrList, attr); + int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); + chars[pos + count] = OBJECT_REPLACEMENT_CHARACTER; + segmentsText.getChars(oldPos, pos, chars, oldPos + count); + oldPos = pos; + count++; + } while (OS.pango_layout_iter_next_line(iter)); + OS.pango_layout_iter_free (iter); + segmentsText.getChars(oldPos, segmentsText.length(), chars, oldPos + count); + buffer = Converter.wcsToMbcs(null, chars, false); + OS.pango_layout_set_text (layout, buffer, buffer.length); + ptr = OS.pango_layout_get_text(layout); + } for (int i = 0; i < styles.length - 1; i++) { StyleItem styleItem = styles[i]; TextStyle style = styleItem.style; @@ -181,6 +213,11 @@ public int getAlignment() { return SWT.LEFT; } +public int getAscent () { + checkLayout(); + return ascent; +} + public Rectangle getBounds() { checkLayout(); computeRuns(); @@ -214,6 +251,11 @@ public Rectangle getBounds(int start, int end) { return new Rectangle(rect.x, rect.y, rect.width, rect.height); } +public int getDescent () { + checkLayout(); + return descent; +} + public Font getFont () { checkLayout(); return font; @@ -311,6 +353,8 @@ public FontMetrics getLineMetrics (int lineIndex) { PangoItem item = new PangoItem(); PangoLayoutRun run = new PangoLayoutRun(); int runCount = 0; + ascent = Math.max(0, this.ascent * OS.PANGO_SCALE); + descent = Math.max(0, this.descent * OS.PANGO_SCALE); while (runs != 0) { OS.memmove(run, OS.g_slist_data(runs), PangoLayoutRun.sizeof); OS.memmove(item, run.item, PangoItem.sizeof); @@ -393,28 +437,12 @@ int _getOffset (int offset, int movement, boolean forward) { length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1); offset = translateOffset(offset); PangoLogAttr logAttr = new PangoLogAttr(); - offset += step; - if (segments != null && segments.length > 2) { - for (int j = 0; j < segments.length; j++) { - if (translateOffset(segments[j]) - 1 == offset) { - offset += step; - break; - } - } - } + offset = validateOffset(offset, step); while (0 < offset && offset < length) { OS.memmove(logAttr, attrs[0] + offset * PangoLogAttr.sizeof, PangoLogAttr.sizeof); if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break; if (((movement & SWT.MOVEMENT_WORD) != 0) && (logAttr.is_word_start || logAttr.is_sentence_end)) break; - offset += step; - if (segments != null && segments.length > 2) { - for (int j = 0; j < segments.length; j++) { - if (translateOffset(segments[j]) - 1 == offset) { - offset += step; - break; - } - } - } + offset = validateOffset(offset, step); } OS.g_free(attrs[0]); return Math.min(Math.max(0, untranslateOffset(offset)), text.length()); @@ -547,6 +575,22 @@ public void setAlignment (int alignment) { OS.pango_layout_set_alignment(layout, align); } +public void setAscent (int ascent) { + checkLayout(); + if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (this.ascent == ascent) return; + freeRuns(); + this.ascent = ascent; +} + +public void setDescent (int descent) { + checkLayout(); + if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (this.descent == descent) return; + freeRuns(); + this.descent = descent; +} + public void setFont (Font font) { checkLayout (); if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -723,12 +767,29 @@ static final boolean isAlef(int ch) { return false; } +/* + * Translate a client offset to an internal offset + */ int translateOffset(int offset) { + int length = text.length(); + if (length == 0) return offset; + if (ascent != -1 || descent != -1) { + int /*long*/ ptr = OS.pango_layout_get_text(layout); + int /*long*/ iter = OS.pango_layout_get_iter(layout); + if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int count = 0; + do { + int bytePos = OS.pango_layout_iter_get_index(iter); + int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); + if (pos - count > offset) break; + count++; + } while (OS.pango_layout_iter_next_line(iter)); + OS.pango_layout_iter_free (iter); + offset += count; + } if (segments == null) return offset; int nSegments = segments.length; if (nSegments <= 1) return offset; - int length = text.length(); - if (length == 0) return offset; if (nSegments == 2) { if (segments[0] == 0 && segments[1] == length) return offset; } @@ -738,12 +799,29 @@ int translateOffset(int offset) { return offset; } +/* + * Translate an internal offset to a client offset + */ int untranslateOffset(int offset) { + int length = text.length(); + if (length == 0) return offset; + if (ascent != -1 || descent != -1) { + int /*long*/ ptr = OS.pango_layout_get_text(layout); + int /*long*/ iter = OS.pango_layout_get_iter(layout); + if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int count = 0; + do { + int bytePos = OS.pango_layout_iter_get_index(iter); + int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); + if (pos > offset) break; + count++; + } while (OS.pango_layout_iter_next_line(iter)); + OS.pango_layout_iter_free (iter); + offset -= count; + } if (segments == null) return offset; int nSegments = segments.length; if (nSegments <= 1) return offset; - int length = text.length(); - if (length == 0) return offset; if (nSegments == 2) { if (segments[0] == 0 && segments[1] == length) return offset; } @@ -752,4 +830,34 @@ int untranslateOffset(int offset) { } return offset; } + +int validateOffset(int offset, int step) { + offset += step; + int pos; + int /*long*/ iter; + int /*long*/ ptr = OS.pango_layout_get_text(layout); + if (ascent != -1 || descent != -1) { + iter = OS.pango_layout_get_iter(layout); + if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); + do { + int bytePos = OS.pango_layout_iter_get_index(iter); + pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); + if (pos == offset) { + offset += step; + break; + } + } while (OS.pango_layout_iter_next_line(iter) && offset > pos); + OS.pango_layout_iter_free (iter); + } + if (segments != null && segments.length > 2) { + for (int j = 0; j < segments.length; j++) { + if (translateOffset(segments[j]) - 1 == offset) { + offset += step; + break; + } + } + } + return offset; +} + } |