diff options
author | Alexander Kurtakov <akurtako@redhat.com> | 2012-11-14 11:44:06 +0200 |
---|---|---|
committer | Alexander Kurtakov <akurtako@redhat.com> | 2012-11-14 11:44:06 +0200 |
commit | 7d46d43cd21b835d179c72bde7bab59e61f13803 (patch) | |
tree | bde3cb0bec6bf2bc3d791cce062b69b8f96b1249 | |
parent | f0c3863919f76488edb06642c9a462968a147799 (diff) | |
download | eclipse.platform.swt-7d46d43cd21b835d179c72bde7bab59e61f13803.tar.gz eclipse.platform.swt-7d46d43cd21b835d179c72bde7bab59e61f13803.tar.xz eclipse.platform.swt-7d46d43cd21b835d179c72bde7bab59e61f13803.zip |
Bug 393856 - Consider using pango_layout_get_pixel_size
Binding for the function added and used where possible. This allows to
not convert them after fetching via OS.PANGO_PIXELS calls.
13 files changed, 75 insertions, 42 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 c7505cdde7..d53ab8d43f 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 @@ -20201,6 +20201,23 @@ fail: } #endif +#ifndef NO__1pango_1layout_1get_1pixel_1size +JNIEXPORT void JNICALL OS_NATIVE(_1pango_1layout_1get_1pixel_1size) + (JNIEnv *env, jclass that, jintLong arg0, jintArray arg1, jintArray arg2) +{ + jint *lparg1=NULL; + jint *lparg2=NULL; + OS_NATIVE_ENTER(env, that, _1pango_1layout_1get_1pixel_1size_FUNC); + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + pango_layout_get_pixel_size((PangoLayout *)arg0, (int *)lparg1, (int *)lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1pango_1layout_1get_1pixel_1size_FUNC); +} +#endif + #ifndef NO__1pango_1layout_1get_1size JNIEXPORT void JNICALL OS_NATIVE(_1pango_1layout_1get_1size) (JNIEnv *env, jclass that, jintLong arg0, jintArray arg1, jintArray arg2) 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 b9f2860800..f0850429dd 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 @@ -1496,6 +1496,7 @@ char * OS_nativeFunctionNames[] = { "_1pango_1layout_1get_1line", "_1pango_1layout_1get_1line_1count", "_1pango_1layout_1get_1log_1attrs", + "_1pango_1layout_1get_1pixel_1size", "_1pango_1layout_1get_1size", "_1pango_1layout_1get_1spacing", "_1pango_1layout_1get_1tabs", 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 494ad5f1e0..acd559a0b8 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 @@ -1506,6 +1506,7 @@ typedef enum { _1pango_1layout_1get_1line_FUNC, _1pango_1layout_1get_1line_1count_FUNC, _1pango_1layout_1get_1log_1attrs_FUNC, + _1pango_1layout_1get_1pixel_1size_FUNC, _1pango_1layout_1get_1size_FUNC, _1pango_1layout_1get_1spacing_FUNC, _1pango_1layout_1get_1tabs_FUNC, 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 7a818b05c5..f0a3c9956f 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 @@ -15496,6 +15496,20 @@ public static final void pango_layout_get_size(long /*int*/ layout, int[] width, lock.unlock(); } } +/** + * @param layout cast=(PangoLayout *) + * @param width cast=(int *) + * @param height cast=(int *) + */ +public static final native void _pango_layout_get_pixel_size(long /*int*/ layout, int[] width, int[] height); +public static final void pango_layout_get_pixel_size(long /*int*/ layout, int[] width, int[] height) { + lock.lock(); + try { + _pango_layout_get_pixel_size(layout, width, height); + } finally { + lock.unlock(); + } +} /** @param layout cast=(PangoLayout*) */ public static final native int _pango_layout_get_spacing(long /*int*/ layout); public static final int pango_layout_get_spacing(long /*int*/ layout) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java index c9c8e4910a..fc41755889 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java @@ -122,7 +122,7 @@ void drawText(Theme theme, String text, int flags, GC gc, Rectangle bounds) { byte[] buffer = Converter.wcsToMbcs(null, text, true); long /*int*/ layout = OS.gtk_widget_create_pango_layout(widget, buffer); int[] width = new int[1], height = new int[1]; - OS.pango_layout_get_size(layout, width, height); + OS.pango_layout_get_pixel_size(layout, width, height); OS.pango_layout_set_width(layout, bounds.width * OS.PANGO_SCALE); int x = bounds.x; int y = bounds.y; @@ -136,10 +136,10 @@ void drawText(Theme theme, String text, int flags, GC gc, Rectangle bounds) { OS.pango_layout_set_alignment(layout, OS.PANGO_ALIGN_RIGHT); } if ((flags & DrawData.DRAW_VCENTER) != 0) { - y += (bounds.height - OS.PANGO_PIXELS(height[0])) / 2; + y += (bounds.height - height[0]) / 2; } if ((flags & DrawData.DRAW_BOTTOM) != 0) { - y += bounds.height - OS.PANGO_PIXELS(height[0]); + y += bounds.height - height[0]; } int state_type = getStateType(DrawData.WIDGET_WHOLE); byte[] detail = Converter.wcsToMbcs(null, "label", true); @@ -192,9 +192,9 @@ Rectangle measureText(Theme theme, String text, int flags, GC gc, Rectangle boun OS.pango_layout_set_alignment(layout, OS.PANGO_ALIGN_RIGHT); } int[] width = new int[1], height = new int[1]; - OS.pango_layout_get_size(layout, width, height); + OS.pango_layout_get_pixel_size(layout, width, height); OS.g_object_unref(layout); - return new Rectangle(0, 0, OS.PANGO_PIXELS(width[0]), OS.PANGO_PIXELS(height[0])); + return new Rectangle(0, 0, width[0], height[0]); } void gtk_render_frame (long /*int*/ style, long /*int*/ window, int state_type, int shadow_type, GdkRectangle area, long /*int*/ widget, byte[] detail, int x , int y, int width, int height) { 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 1f7c385b8d..bf42c7e6da 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 @@ -3015,9 +3015,9 @@ void initCairo() { void computeStringSize() { int[] width = new int[1], height = new int[1]; - OS.pango_layout_get_size(data.layout, width, height); - data.stringHeight = OS.PANGO_PIXELS(height[0]); - data.stringWidth = OS.PANGO_PIXELS(width[0]); + OS.pango_layout_get_pixel_size(data.layout, width, height); + data.stringHeight = height[0]; + data.stringWidth = width[0]; } /** 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 7e3d2b8993..51c1c38de5 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 @@ -2213,8 +2213,8 @@ int width () { int wrapWidth = OS.pango_layout_get_width(layout); if (wrapWidth != -1) return OS.PANGO_PIXELS(wrapWidth); int[] w = new int[1], h = new int[1]; - OS.pango_layout_get_size(layout, w, h); - return OS.PANGO_PIXELS(w[0]); + OS.pango_layout_get_pixel_size(layout, w, h); + return w[0]; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index 6ebf428819..8282c908b3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -231,11 +231,11 @@ public Point computeSize (int wHint, int hHint, boolean changed) { OS.pango_layout_set_width (labelLayout, -1); } int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (labelLayout, w, h); + OS.pango_layout_get_pixel_size (labelLayout, w, h); OS.pango_layout_set_width (labelLayout, pangoWidth); size = new Point(0, 0); - size.x += wHint == SWT.DEFAULT ? OS.PANGO_PIXELS(w [0]) + imageWidth + trimWidth : wHint; - size.y += hHint == SWT.DEFAULT ? Math.max(Math.max(imageHeight, indicatorHeight), OS.PANGO_PIXELS(h [0])) + trimHeight : hHint; + size.x += wHint == SWT.DEFAULT ? w [0] + imageWidth + trimWidth : wHint; + size.y += hHint == SWT.DEFAULT ? Math.max(Math.max(imageHeight, indicatorHeight), h [0]) + trimHeight : hHint; } else { size = computeNativeSize (handle, wHint, hHint, changed); } @@ -776,7 +776,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize int pangoWidth = OS.pango_layout_get_width (labelLayout); OS.pango_layout_set_width (labelLayout, -1); int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (labelLayout, w, h); + OS.pango_layout_get_pixel_size (labelLayout, w, h); OS.pango_layout_set_width (labelLayout, pangoWidth); int imageWidth = 0; if (gtk_widget_get_visible (imageHandle)) { @@ -787,7 +787,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize OS.g_object_get (boxHandle, OS.spacing, spacing, 0); imageWidth += spacing [0]; } - OS.gtk_widget_set_size_request (labelHandle, Math.min(OS.PANGO_PIXELS(w [0]), boxWidth - imageWidth), -1); + OS.gtk_widget_set_size_request (labelHandle, Math.min(w [0], boxWidth - imageWidth), -1); /* * Bug in GTK. Setting the size request should invalidate the label's * layout, but it does not. The fix is to resize the label directly. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index 3523aa223f..7bbd628b42 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -354,7 +354,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { int[] w = new int [1], h = new int [1]; OS.gtk_widget_realize (entryHandle); long /*int*/ layout = OS.gtk_entry_get_layout (entryHandle); - OS.pango_layout_get_size (layout, w, h); + OS.pango_layout_get_pixel_size (layout, w, h); int xborder = Display.INNER_BORDER, yborder = Display.INNER_BORDER; Point thickness = getThickness (entryHandle); xborder += thickness.x; @@ -366,8 +366,8 @@ public Point computeSize (int wHint, int hHint, boolean changed) { xborder += property [0]; yborder += property [0]; } - int width = OS.PANGO_PIXELS (w [0]) + xborder * 2; - int height = OS.PANGO_PIXELS (h [0]) + yborder * 2; + int width = w [0] + xborder * 2; + int height = h [0] + yborder * 2; GtkRequisition arrowRequesition = new GtkRequisition (); gtk_widget_get_preferred_size (buttonHandle, arrowRequesition); GtkRequisition listRequesition = new GtkRequisition (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index 1ce5e0c22e..5bc4d3b8d5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -140,7 +140,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { OS.pango_layout_set_width (labelLayout, -1); } int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (labelLayout, w, h); + OS.pango_layout_get_pixel_size (labelLayout, w, h); OS.pango_layout_set_width (labelLayout, pangoWidth); if (frameHandle != 0) { int [] labelWidth = new int [1], labelHeight = new int [1]; @@ -153,8 +153,8 @@ public Point computeSize (int wHint, int hHint, boolean changed) { } else { size = new Point (0,0); } - size.x += wHint == SWT.DEFAULT ? OS.PANGO_PIXELS(w [0]) : wHint; - size.y += hHint == SWT.DEFAULT ? OS.PANGO_PIXELS(h [0]) : hHint; + size.x += wHint == SWT.DEFAULT ? w [0] : wHint; + size.y += hHint == SWT.DEFAULT ? h [0] : hHint; } else { if (frameHandle != 0) { int [] reqWidth = new int [1], reqHeight = new int [1]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java index c1588fc89b..9e36892696 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java @@ -227,10 +227,10 @@ public Point computeSize (int wHint, int hHint, boolean changed) { byte [] buffer2 = new byte [length]; OS.memmove (buffer2, ptr, length); OS.pango_layout_set_text (layout, buffer1, buffer1.length); - OS.pango_layout_get_size (layout, w, h); + OS.pango_layout_get_pixel_size (layout, w, h); OS.pango_layout_set_text (layout, buffer2, buffer2.length); - int width = OS.PANGO_PIXELS (w [0]); - int height = OS.PANGO_PIXELS (h [0]); + int width = w [0]; + int height = h [0]; width = wHint == SWT.DEFAULT ? width : wHint; height = hHint == SWT.DEFAULT ? height : hHint; Rectangle trim = computeTrim (0, 0, width, height); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index 04d8521c61..7373e65d5b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -536,7 +536,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { if ((style & SWT.SINGLE) != 0) { OS.gtk_widget_realize (handle); long /*int*/ layout = OS.gtk_entry_get_layout (handle); - OS.pango_layout_get_size (layout, w, h); + OS.pango_layout_get_pixel_size (layout, w, h); } else { byte [] start = new byte [ITER_SIZEOF], end = new byte [ITER_SIZEOF]; OS.gtk_text_buffer_get_bounds (bufferHandle, start, end); @@ -544,17 +544,17 @@ public Point computeSize (int wHint, int hHint, boolean changed) { long /*int*/ layout = OS.gtk_widget_create_pango_layout (handle, text); OS.g_free (text); OS.pango_layout_set_width (layout, wHint * OS.PANGO_SCALE); - OS.pango_layout_get_size (layout, w, h); + OS.pango_layout_get_pixel_size (layout, w, h); OS.g_object_unref (layout); } - int width = OS.PANGO_PIXELS (w [0]); - int height = OS.PANGO_PIXELS (h [0]); + int width = w [0]; + int height = h [0]; if ((style & SWT.SINGLE) != 0 && message.length () > 0) { byte [] buffer = Converter.wcsToMbcs (null, message, true); long /*int*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer); - OS.pango_layout_get_size (layout, w, h); + OS.pango_layout_get_pixel_size (layout, w, h); OS.g_object_unref (layout); - width = Math.max (width, OS.PANGO_PIXELS (w [0])); + width = Math.max (width, w [0]); } if (width == 0) width = DEFAULT_WIDTH; if (height == 0) height = DEFAULT_HEIGHT; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java index 355da7ed54..67662fd23e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java @@ -409,13 +409,13 @@ Point getSize (int maxWidth) { int [] w = new int [1], h = new int [1]; if (layoutText != 0) { OS.pango_layout_set_width (layoutText, -1); - OS.pango_layout_get_size (layoutText, w, h); - textWidth = OS.PANGO_PIXELS (w [0]); + OS.pango_layout_get_pixel_size (layoutText, w, h); + textWidth = w [0]; } if (layoutMessage != 0) { OS.pango_layout_set_width (layoutMessage, -1); - OS.pango_layout_get_size (layoutMessage, w, h); - messageWidth = OS.PANGO_PIXELS (w [0]); + OS.pango_layout_get_pixel_size (layoutMessage, w, h); + messageWidth = w [0]; } int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING; boolean hasImage = layoutText != 0 && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) != 0; @@ -424,13 +424,13 @@ Point getSize (int maxWidth) { int textHeight = 0, messageHeight = 0; if (layoutText != 0) { OS.pango_layout_set_width (layoutText, (maxWidth - textTrim) * OS.PANGO_SCALE); - OS.pango_layout_get_size (layoutText, w, h); - textHeight = OS.PANGO_PIXELS (h [0]); + OS.pango_layout_get_pixel_size (layoutText, w, h); + textHeight = h [0]; } if (layoutMessage != 0) { OS.pango_layout_set_width (layoutMessage, (maxWidth - messageTrim) * OS.PANGO_SCALE); - OS.pango_layout_get_size (layoutMessage, w, h); - messageHeight = OS.PANGO_PIXELS (h [0]); + OS.pango_layout_get_pixel_size (layoutMessage, w, h); + messageHeight = h [0]; } int height = 2 * BORDER + 2 * PADDING + messageHeight; if (layoutText != 0) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING; @@ -533,8 +533,8 @@ void drawTooltip (long /*int*/ cr) { OS.gdk_cairo_set_source_color(cairo,foreground.handle); Cairo.cairo_move_to(cairo, x,y ); OS.pango_cairo_show_layout(cairo, layoutText); - OS.pango_layout_get_size (layoutText, w, h); - y += 2 * PADDING + Math.max (IMAGE_SIZE, OS.PANGO_PIXELS (h [0])); + OS.pango_layout_get_pixel_size (layoutText, w, h); + y += 2 * PADDING + Math.max (IMAGE_SIZE, h [0]); } if (layoutMessage != 0) { x = BORDER + PADDING + INSET; @@ -576,8 +576,8 @@ void drawTooltip (long /*int*/ cr) { OS.gdk_gc_set_foreground (gdkGC, foreground.handle); OS.gdk_draw_layout (window, gdkGC, x, y, layoutText); int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (layoutText, w, h); - y += 2 * PADDING + Math.max (IMAGE_SIZE, OS.PANGO_PIXELS (h [0])); + OS.pango_layout_get_pixel_size (layoutText, w, h); + y += 2 * PADDING + Math.max (IMAGE_SIZE, h [0]); } if (layoutMessage != 0) { x = BORDER + PADDING + INSET; |