summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
diff options
context:
space:
mode:
authorAnatoly Spektor <aspektor@redhat.com>2012-10-12 10:37:12 -0400
committerSilenio Quarti <silenio_quarti@ca.ibm.com>2012-10-17 10:34:22 -0400
commitb178ded274cefa13fff8fc6fb8115ee14a844dc8 (patch)
tree1b0bbd83824435229f7e6ecc4157d85590ceb9a4 /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
parentdf55805e4a74ab0fc8f545a1792d755c95a4e419 (diff)
downloadeclipse.platform.swt-b178ded274cefa13fff8fc6fb8115ee14a844dc8.tar.gz
eclipse.platform.swt-b178ded274cefa13fff8fc6fb8115ee14a844dc8.tar.xz
eclipse.platform.swt-b178ded274cefa13fff8fc6fb8115ee14a844dc8.zip
Replace GdkRegion with Cairo methods for GTK + 3.0 and higher
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java139
1 files changed, 99 insertions, 40 deletions
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 c61fadbe30..fef1763364 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
@@ -571,7 +571,7 @@ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Colo
long /*int*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
if (rgn != 0) {
OS.gdk_gc_set_clip_region(gc.handle, rgn);
- OS.gdk_region_destroy(rgn);
+ cairo_region_destroy (rgn);
}
OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.handle);
drawBorder(gc, x, y, selectionForeground.handle);
@@ -601,7 +601,7 @@ void drawWithCairo(GC gc, int x, int y, int start, int end, boolean fullSelectio
Cairo.cairo_clip(cairo);
Cairo.cairo_set_source_rgba(cairo, (bg.red & 0xFFFF) / (float)0xFFFF, (bg.green & 0xFFFF) / (float)0xFFFF, (bg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
Cairo.cairo_paint(cairo);
- OS.gdk_region_destroy(rgn);
+ cairo_region_destroy (rgn);
}
Cairo.cairo_set_source_rgba(cairo, (fg.red & 0xFFFF) / (float)0xFFFF, (fg.green & 0xFFFF) / (float)0xFFFF, (fg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
Cairo.cairo_move_to(cairo, x, y);
@@ -640,7 +640,7 @@ void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
if (rgn != 0) {
int[] nRects = new int[1];
long /*int*/[] rects = new long /*int*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
+ cairo_region_get_rectangles (rgn, rects, nRects);
GdkRectangle rect = new GdkRectangle();
GdkColor color = null;
if (color == null && style.borderColor != null) color = style.borderColor.handle;
@@ -697,7 +697,7 @@ void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
}
}
if (rects[0] != 0) OS.g_free(rects[0]);
- OS.gdk_region_destroy(rgn);
+ cairo_region_destroy (rgn);
}
}
}
@@ -827,44 +827,84 @@ public Rectangle getBounds(int start, int end) {
int[] ranges = new int[]{byteStart, byteEnd};
long /*int*/ clipRegion = OS.gdk_pango_layout_get_clip_region(layout, 0, 0, ranges, 1);
if (clipRegion == 0) return new Rectangle(0, 0, 0, 0);
- GdkRectangle rect = new GdkRectangle();
-
- /*
- * Bug in Pango. The region returned by gdk_pango_layout_get_clip_region()
- * includes areas from lines outside of the requested range. The fix
- * is to subtract these areas from the clip region.
- */
- PangoRectangle pangoRect = new PangoRectangle();
- long /*int*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- long /*int*/ linesRegion = OS.gdk_region_new();
- if (linesRegion == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int lineEnd = 0;
- do {
- OS.pango_layout_iter_get_line_extents(iter, null, pangoRect);
- if (OS.pango_layout_iter_next_line(iter)) {
- lineEnd = OS.pango_layout_iter_get_index(iter) - 1;
- } else {
- lineEnd = strlen;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
+ cairo_rectangle_int_t rect = new cairo_rectangle_int_t();
+ /*
+ * Bug in Pango. The region returned by gdk_pango_layout_get_clip_region()
+ * includes areas from lines outside of the requested range. The fix
+ * is to subtract these areas from the clip region.
+ */
+ PangoRectangle pangoRect = new PangoRectangle();
+ long /*int*/ iter = OS.pango_layout_get_iter(layout);
+ if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ long /*int*/ linesRegion = Cairo.cairo_region_create ();
+ if (linesRegion == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int lineEnd = 0;
+ do {
+ OS.pango_layout_iter_get_line_extents(iter, null, pangoRect);
+ if (OS.pango_layout_iter_next_line(iter)) {
+ lineEnd = OS.pango_layout_iter_get_index(iter) - 1;
+ } else {
+ lineEnd = strlen;
+ }
+ if (byteStart > lineEnd) continue;
+ rect.x = OS.PANGO_PIXELS(pangoRect.x);
+ rect.y = OS.PANGO_PIXELS(pangoRect.y);
+ rect.width = OS.PANGO_PIXELS(pangoRect.width);
+ rect.height = OS.PANGO_PIXELS(pangoRect.height);
+ Cairo.cairo_region_union_rectangle (linesRegion, rect);
+ } while (lineEnd + 1 <= byteEnd);
+ Cairo.cairo_region_intersect (clipRegion, linesRegion);
+ Cairo.cairo_region_destroy (linesRegion);
+ OS.pango_layout_iter_free(iter);
+
+ Cairo.cairo_region_get_extents (clipRegion, rect);
+ Cairo.cairo_region_destroy (clipRegion);
+ if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
+ rect.x = width() - rect.x - rect.width;
}
- if (byteStart > lineEnd) continue;
- rect.x = OS.PANGO_PIXELS(pangoRect.x);
- rect.y = OS.PANGO_PIXELS(pangoRect.y);
- rect.width = OS.PANGO_PIXELS(pangoRect.width);
- rect.height = OS.PANGO_PIXELS(pangoRect.height);
- OS.gdk_region_union_with_rect(linesRegion, rect);
- } while (lineEnd + 1 <= byteEnd);
- OS.gdk_region_intersect(clipRegion, linesRegion);
- OS.gdk_region_destroy(linesRegion);
- OS.pango_layout_iter_free(iter);
-
- OS.gdk_region_get_clipbox(clipRegion, rect);
- OS.gdk_region_destroy(clipRegion);
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- rect.x = width() - rect.x - rect.width;
+ rect.x += Math.min (indent, wrapIndent);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+ } else {
+ GdkRectangle rect = new GdkRectangle();
+ /*
+ * Bug in Pango. The region returned by gdk_pango_layout_get_clip_region()
+ * includes areas from lines outside of the requested range. The fix
+ * is to subtract these areas from the clip region.
+ */
+ PangoRectangle pangoRect = new PangoRectangle();
+ long /*int*/ iter = OS.pango_layout_get_iter(layout);
+ if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ long /*int*/ linesRegion = OS.gdk_region_new ();
+ if (linesRegion == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int lineEnd = 0;
+ do {
+ OS.pango_layout_iter_get_line_extents(iter, null, pangoRect);
+ if (OS.pango_layout_iter_next_line(iter)) {
+ lineEnd = OS.pango_layout_iter_get_index(iter) - 1;
+ } else {
+ lineEnd = strlen;
+ }
+ if (byteStart > lineEnd) continue;
+ rect.x = OS.PANGO_PIXELS(pangoRect.x);
+ rect.y = OS.PANGO_PIXELS(pangoRect.y);
+ rect.width = OS.PANGO_PIXELS(pangoRect.width);
+ rect.height = OS.PANGO_PIXELS(pangoRect.height);
+ OS.gdk_region_union_with_rect(linesRegion, rect);
+ } while (lineEnd + 1 <= byteEnd);
+ OS.gdk_region_intersect (clipRegion, linesRegion);
+ OS.gdk_region_destroy (linesRegion);
+ OS.pango_layout_iter_free(iter);
+
+ OS.gdk_region_get_clipbox(clipRegion, rect);
+ OS.gdk_region_destroy (clipRegion);
+ if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
+ rect.x = width() - rect.x - rect.width;
+ }
+ rect.x += Math.min (indent, wrapIndent);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
}
- rect.x += Math.min (indent, wrapIndent);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+
}
/**
@@ -2223,4 +2263,23 @@ int width () {
return OS.PANGO_PIXELS(w[0]);
}
+void cairo_region_get_rectangles (long /*int*/ region, long /*int*/[] rectangles, int[] n_rectangles) {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
+ int num = Cairo.cairo_region_num_rectangles (region);
+ for (int n = 0; n < num; n++) {
+ Cairo.cairo_region_get_rectangle (region, n, rectangles[n]);
+ }
+ } else {
+ OS.gdk_region_get_rectangles (region, rectangles, n_rectangles);
+ }
+}
+
+void cairo_region_destroy (long /*int*/ region) {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
+ Cairo.cairo_region_destroy ( region);
+ } else {
+ OS.gdk_region_destroy (region);
+ }
+}
+
}