Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Shingarov2002-03-05 06:31:28 +0000
committerBoris Shingarov2002-03-05 06:31:28 +0000
commit721e9d5ab94911f9952bba8367b95eacacb5ef90 (patch)
tree8123fa691cd49e89aac48889d2d3911e7b0bff84
parentfb9d8b3108ecd79fb9a1ffe9150701705dc1fb91 (diff)
downloadeclipse.platform.swt-721e9d5ab94911f9952bba8367b95eacacb5ef90.tar.gz
eclipse.platform.swt-721e9d5ab94911f9952bba8367b95eacacb5ef90.tar.xz
eclipse.platform.swt-721e9d5ab94911f9952bba8367b95eacacb5ef90.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDKPIXBUF.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java19
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/GDKPIXBUF.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/OS.java19
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java22
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java92
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java22
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java92
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java11
14 files changed, 142 insertions, 168 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDKPIXBUF.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
index 3b50131b87..d84a0bec18 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
@@ -19,7 +19,7 @@ public class GDKPIXBUF extends OS {
/* GdkColorspace enumeration */
/* R/G/B additive color space */
- public final static int GDK_COLORSPACE_RGB = 0;
+ public static final native int GDK_COLORSPACE_RGB();
/* GIF-like animation overlay modes for frames */
public final static int GDK_PIXBUF_FRAME_RETAIN = 0;
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 fc2c64d0bc..ea4d45663d 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
@@ -660,6 +660,10 @@ public static final native void gtk_widget_set_uposition(int widget, int x, int
public static final native void gtk_widget_set_usize(int widget, int width, int height);
public static final native void gtk_widget_remove_accelerator(int widget, int accel_group, int accel_key, int accel_mods);
public static final native void gtk_widget_set_parent(int widget, int parent);
+public static final native void gtk_widget_modify_font(int widget, int pango_font_descr);
+public static final native void gtk_widget_reparent(int widget, int new_parent);
+public static final native void gtk_widget_size_allocate(int widget, GtkAllocation allocation);
+
/* gtk_window_* */
public static final native int gtk_window_new(int type);
@@ -675,10 +679,6 @@ public static final native void gtk_window_set_transient_for(int window, int par
-public static final native void gtk_widget_reparent(int widget, int new_parent);
-public static final native void gtk_widget_size_allocate(int widget, GtkAllocation allocation);
-
-
/* Pango */
public static final native int PANGO_WEIGHT_NORMAL();
public static final native int PANGO_WEIGHT_BOLD();
@@ -690,6 +690,12 @@ public static final native int PANGO_STRETCH_NORMAL();
public static final native int PANGO_PIXELS(int dimension);
+public static final native int pango_context_new();
+public static final native int pango_context_get_font_description(int context);
+public static final native void pango_context_set_font_description(int context, int descr);
+public static final native int pango_context_get_metrics(int context, int desc, String language);
+
+
public static final native int pango_font_description_new();
public static final native int pango_font_description_from_string(String str);
public static final native String pango_font_description_to_string(int desc);
@@ -705,6 +711,11 @@ public static final native void pango_font_description_set_style(int desc, int w
public static final native int pango_font_description_get_weight(int desc);
public static final native void pango_font_description_set_weight(int desc, int weight);
+public static final native int pango_font_metrics_get_ascent(int metrics);
+public static final native int pango_font_metrics_get_descent(int metrics);
+public static final native int pango_font_metrics_get_approximate_char_width(int metrics);
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/GDKPIXBUF.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
index 3b50131b87..d84a0bec18 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/GDKPIXBUF.java
@@ -19,7 +19,7 @@ public class GDKPIXBUF extends OS {
/* GdkColorspace enumeration */
/* R/G/B additive color space */
- public final static int GDK_COLORSPACE_RGB = 0;
+ public static final native int GDK_COLORSPACE_RGB();
/* GIF-like animation overlay modes for frames */
public final static int GDK_PIXBUF_FRAME_RETAIN = 0;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/OS.java
index fc2c64d0bc..ea4d45663d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk1x/org/eclipse/swt/internal/gtk/OS.java
@@ -660,6 +660,10 @@ public static final native void gtk_widget_set_uposition(int widget, int x, int
public static final native void gtk_widget_set_usize(int widget, int width, int height);
public static final native void gtk_widget_remove_accelerator(int widget, int accel_group, int accel_key, int accel_mods);
public static final native void gtk_widget_set_parent(int widget, int parent);
+public static final native void gtk_widget_modify_font(int widget, int pango_font_descr);
+public static final native void gtk_widget_reparent(int widget, int new_parent);
+public static final native void gtk_widget_size_allocate(int widget, GtkAllocation allocation);
+
/* gtk_window_* */
public static final native int gtk_window_new(int type);
@@ -675,10 +679,6 @@ public static final native void gtk_window_set_transient_for(int window, int par
-public static final native void gtk_widget_reparent(int widget, int new_parent);
-public static final native void gtk_widget_size_allocate(int widget, GtkAllocation allocation);
-
-
/* Pango */
public static final native int PANGO_WEIGHT_NORMAL();
public static final native int PANGO_WEIGHT_BOLD();
@@ -690,6 +690,12 @@ public static final native int PANGO_STRETCH_NORMAL();
public static final native int PANGO_PIXELS(int dimension);
+public static final native int pango_context_new();
+public static final native int pango_context_get_font_description(int context);
+public static final native void pango_context_set_font_description(int context, int descr);
+public static final native int pango_context_get_metrics(int context, int desc, String language);
+
+
public static final native int pango_font_description_new();
public static final native int pango_font_description_from_string(String str);
public static final native String pango_font_description_to_string(int desc);
@@ -705,6 +711,11 @@ public static final native void pango_font_description_set_style(int desc, int w
public static final native int pango_font_description_get_weight(int desc);
public static final native void pango_font_description_set_weight(int desc, int weight);
+public static final native int pango_font_metrics_get_ascent(int metrics);
+public static final native int pango_font_metrics_get_descent(int metrics);
+public static final native int pango_font_metrics_get_approximate_char_width(int metrics);
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
index 797fa607ed..f6e75abd12 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
@@ -95,18 +95,6 @@ public int getLeading() {
return leading;
}
-public static FontMetrics gtk_new_from_pango_font_description(int fontHandle) {
- GdkFont f = new GdkFont();
- OS.memmove (f, fontHandle);
-
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = f.ascent;
- fontMetrics.descent = f.descent;
- fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
- fontMetrics.leading = 3;
- fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
- return fontMetrics;
-}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -120,4 +108,14 @@ public static FontMetrics gtk_new_from_pango_font_description(int fontHandle) {
public int hashCode() {
return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
}
+
+static FontMetrics gtk_new(int pango_font_metrics) {
+ FontMetrics answer = new FontMetrics();
+ answer.ascent = OS.pango_font_metrics_get_ascent(pango_font_metrics);
+ answer.descent = OS.pango_font_metrics_get_descent(pango_font_metrics);
+ answer.averageCharWidth = OS.pango_font_metrics_get_approximate_char_width(pango_font_metrics);
+ answer.leading = 1; /* temporary code */
+ return answer;
+}
+
}
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 14b5394b58..cf07f2fda7 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
@@ -31,6 +31,7 @@ public final class GC {
* (Warning: This field is platform dependent)
*/
public int handle;
+ public int pango_context;
Drawable drawable;
GCData data;
@@ -65,6 +66,7 @@ public GC(Drawable drawable) {
data = new GCData();
handle = drawable.internal_new_GC(data);
this.drawable = drawable;
+ pango_context = OS.pango_context_new();
// The colors we get from the widget are not always right.
// Get the default GTK_STATE_NORMAL colors
@@ -72,17 +74,6 @@ public GC(Drawable drawable) {
setForeground( DefaultGtkStyle.instance().foregroundColorNORMAL() );
*/
- // Feature in GDK.
- // Sometimes, gdk_gc_new() doesn't get the font from the control,
- // and also, some controls don't contain a font; so when the GC
- // was created in internal_new_gc(), the font might or might not
- // be set; if the font isn't there, just fall back to default.
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- if (values.font == 0) {
-/* OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() );*/
- }
-
if (data.image != null) {
data.image.memGC = this;
/*
@@ -199,8 +190,8 @@ public void setForeground(Color color) {
*/
public int getAdvanceWidth(char ch) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- return OS.gdk_char_width(_getGCFont(), charBuffer[0]);
+ /* temporary code */
+ return 5;
}
/**
* Returns the width of the specified character in the font
@@ -219,12 +210,8 @@ public int getAdvanceWidth(char ch) {
* </ul>
*/
public int getCharWidth(char ch) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- int[] lbearing = new int[1];
- int[] rbearing = new int[1];
- int[] unused = new int[1];
- OS.gdk_string_extents(_getGCFont(), charBuffer, lbearing, rbearing, unused, unused, unused);
- return rbearing[0] - lbearing[0];
+ /* temporary code */
+ return 5;
}
/**
* Returns the bounding rectangle of the receiver's clipping
@@ -290,8 +277,10 @@ public void getClipping(Region region) {
* </ul>
*/
public Font getFont() {
- return Font.gtk_new(_getGCFont());
+ int pango_fd = OS.pango_context_get_font_description(pango_context);
+ return new Font(Display.getCurrent(), FontData.gtk_from_os(pango_fd));
}
+
/**
* Returns a FontMetrics which contains information
* about the font currently being used by the receiver
@@ -303,16 +292,12 @@ public Font getFont() {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-// Not done
public FontMetrics getFontMetrics() {
- int fontHandle = _getGCFont();
- if (fontHandle==0) {
- error(SWT.ERROR_UNSPECIFIED);
- }
- GdkFont gdkFont = new GdkFont();
- OS.memmove(gdkFont, fontHandle);
- byte [] w = Converter.wcsToMbcs (null, "w", true);
- return FontMetrics.gtk_new(fontHandle);
+ int pango_fd = OS.pango_context_get_font_description(pango_context);
+ int pango_metrics = OS.pango_context_get_metrics(pango_context, pango_fd, null);
+ FontMetrics answer = FontMetrics.gtk_new(pango_metrics);
+ answer.height = OS.pango_font_description_get_size(pango_fd);
+ return answer;
}
/**
@@ -460,17 +445,9 @@ public void setClipping(Region region) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setFont(Font font) {
-/* int fontHandle = 0;
- if (font == null) {
- GtkStyle gtkStyle = new GtkStyle();
- int style = OS.gtk_widget_get_default_style();
- OS.memmove(gtkStyle, style, GtkStyle.sizeof);
- fontHandle = gtkStyle.font;
- } else {
- fontHandle = font.handle;
- }
- OS.gdk_gc_set_font(handle, fontHandle);*/
+public void setFont(Font font) {
+ /* Set the font in the Pango context */
+ OS.pango_context_set_font_description(pango_context, font.handle);
}
/**
@@ -570,10 +547,12 @@ public void setXORMode(boolean val) {
*/
public Point stringExtent(String string) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
int width = OS.gdk_string_width(_getGCFont(), buffer);
int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
+ return new Point(width, height);*/
+ /* Temporary code */
+ return new Point(100,20);
}
/**
* Returns the extent of the given string. Tab expansion and
@@ -596,10 +575,12 @@ public Point stringExtent(String string) {
*/
public Point textExtent(String string) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
int width = OS.gdk_string_width(_getGCFont(), buffer);
int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
+ return new Point(width, height);*/
+ /* Temporary code */
+ return new Point(100,20);
}
@@ -631,13 +612,6 @@ private GdkColor _getBackgroundGdkColor() {
color.blue = values.background_blue;
return color;
}
-private int _getGCFont() {
- GdkGCValues values = _getGCValues();
- if (values.font==0) {
- SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return values.font;
-}
@@ -897,7 +871,7 @@ public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcH
double offset_y = - srcY * scale_y;
int destSizePixbuf = GDKPIXBUF.gdk_pixbuf_new (
- GDKPIXBUF.GDK_COLORSPACE_RGB,
+ GDKPIXBUF.GDK_COLORSPACE_RGB(),
true, 8, destWidth, destHeight);
GDKPIXBUF.gdk_pixbuf_scale(
pixbuf.handle, // src,
@@ -1161,13 +1135,12 @@ public void drawString (String string, int x, int y) {
*/
public void drawString(String string, int x, int y, boolean isTransparent) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
int[] unused = new int[1];
int[] width = new int[1];
int[] ascent = new int[1];
int[] average_ascent = new int [1];
- int fontHandle = _getGCFont();
OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
if (ascent[0]<average_ascent[0]) ascent[0] = average_ascent[0];
@@ -1188,7 +1161,7 @@ public void drawString(String string, int x, int y, boolean isTransparent) {
color.blue = values.foreground_blue;
OS.gdk_gc_set_foreground(handle, color);
}
- OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);
+ OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);*/
}
/**
* Draws the given string, using the receiver's current font and
@@ -1233,7 +1206,7 @@ public void drawText(String string, int x, int y) {
*/
public void drawText(String string, int x, int y, boolean isTransparent) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
int fontHandle = _getGCFont();
int[] unused = new int[1];
@@ -1260,7 +1233,7 @@ public void drawText(String string, int x, int y, boolean isTransparent) {
color.blue = values.foreground_blue;
OS.gdk_gc_set_foreground(handle, color);
}
- OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);
+ OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);*/
}
/**
@@ -1696,7 +1669,10 @@ public void dispose() {
OS.gdk_gc_unref(handle);
else
drawable.internal_dispose_GC(handle, data);
-
+
+ /* FIXME */
+ /* It is not clear how a Pango context should be freed. */
+
data.drawable = // data.colormap = data.fontList =
data.clipRgn = data.renderTable = 0;
drawable = null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index 2972898f60..ab06765c1e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -194,6 +194,9 @@ public Image(Device device, Image srcImage, int flag) {
this.transparentPixel = srcImage.transparentPixel;
// bogus - are we sure about memGC?
+ /* temporary code before we sort out greying */
+ flag = SWT.IMAGE_COPY;
+
/* Special case:
* If all we want is just a clone of the existing pixmap, it can
* be done entirely in the X server, without copying across the net.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java
index 5439fa1607..78d94f0c01 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java
@@ -273,11 +273,13 @@ final class Pixbuffer {
* an alpha channel.
*/
private void createHandle(int width, int height) {
- handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB,
+ handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB(),
true,
8,
width, height);
- if (this.handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (this.handle == 0) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
data = GDKPIXBUF.gdk_pixbuf_get_pixels(handle);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 26a19bdcde..afc45b16ae 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -107,6 +107,8 @@ public class Display extends Device {
Caret currentCaret;
Callback caretCallback;
int caretID, caretProc;
+
+ Font systemFont;
/* Colors */
Color NORMAL_fg, NORMAL_bg, NORMAL_dark, NORMAL_mid, NORMAL_light, NORMAL_text, NORMAL_base;
@@ -916,13 +918,8 @@ final void initializeSystemColors() {
*/
public Font getSystemFont () {
checkDevice ();
-/* GtkStyle style = new GtkStyle();
- OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
- int gdkFont = style.font; // gives a GdkFont*
- return Font.gtk_new (gdkFont);*/
- byte[] name = Converter.wcsToMbcs(null, "fixed");
- int f = OS.gdk_font_load(name);
- return Font.gtk_new(f);
+ if (systemFont==null) systemFont = new Font(this, new FontData("Monospace"));
+ return systemFont;
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
index 797fa607ed..f6e75abd12 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
@@ -95,18 +95,6 @@ public int getLeading() {
return leading;
}
-public static FontMetrics gtk_new_from_pango_font_description(int fontHandle) {
- GdkFont f = new GdkFont();
- OS.memmove (f, fontHandle);
-
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = f.ascent;
- fontMetrics.descent = f.descent;
- fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
- fontMetrics.leading = 3;
- fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
- return fontMetrics;
-}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -120,4 +108,14 @@ public static FontMetrics gtk_new_from_pango_font_description(int fontHandle) {
public int hashCode() {
return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
}
+
+static FontMetrics gtk_new(int pango_font_metrics) {
+ FontMetrics answer = new FontMetrics();
+ answer.ascent = OS.pango_font_metrics_get_ascent(pango_font_metrics);
+ answer.descent = OS.pango_font_metrics_get_descent(pango_font_metrics);
+ answer.averageCharWidth = OS.pango_font_metrics_get_approximate_char_width(pango_font_metrics);
+ answer.leading = 1; /* temporary code */
+ return answer;
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java
index 14b5394b58..cf07f2fda7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java
@@ -31,6 +31,7 @@ public final class GC {
* (Warning: This field is platform dependent)
*/
public int handle;
+ public int pango_context;
Drawable drawable;
GCData data;
@@ -65,6 +66,7 @@ public GC(Drawable drawable) {
data = new GCData();
handle = drawable.internal_new_GC(data);
this.drawable = drawable;
+ pango_context = OS.pango_context_new();
// The colors we get from the widget are not always right.
// Get the default GTK_STATE_NORMAL colors
@@ -72,17 +74,6 @@ public GC(Drawable drawable) {
setForeground( DefaultGtkStyle.instance().foregroundColorNORMAL() );
*/
- // Feature in GDK.
- // Sometimes, gdk_gc_new() doesn't get the font from the control,
- // and also, some controls don't contain a font; so when the GC
- // was created in internal_new_gc(), the font might or might not
- // be set; if the font isn't there, just fall back to default.
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- if (values.font == 0) {
-/* OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() );*/
- }
-
if (data.image != null) {
data.image.memGC = this;
/*
@@ -199,8 +190,8 @@ public void setForeground(Color color) {
*/
public int getAdvanceWidth(char ch) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- return OS.gdk_char_width(_getGCFont(), charBuffer[0]);
+ /* temporary code */
+ return 5;
}
/**
* Returns the width of the specified character in the font
@@ -219,12 +210,8 @@ public int getAdvanceWidth(char ch) {
* </ul>
*/
public int getCharWidth(char ch) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- int[] lbearing = new int[1];
- int[] rbearing = new int[1];
- int[] unused = new int[1];
- OS.gdk_string_extents(_getGCFont(), charBuffer, lbearing, rbearing, unused, unused, unused);
- return rbearing[0] - lbearing[0];
+ /* temporary code */
+ return 5;
}
/**
* Returns the bounding rectangle of the receiver's clipping
@@ -290,8 +277,10 @@ public void getClipping(Region region) {
* </ul>
*/
public Font getFont() {
- return Font.gtk_new(_getGCFont());
+ int pango_fd = OS.pango_context_get_font_description(pango_context);
+ return new Font(Display.getCurrent(), FontData.gtk_from_os(pango_fd));
}
+
/**
* Returns a FontMetrics which contains information
* about the font currently being used by the receiver
@@ -303,16 +292,12 @@ public Font getFont() {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-// Not done
public FontMetrics getFontMetrics() {
- int fontHandle = _getGCFont();
- if (fontHandle==0) {
- error(SWT.ERROR_UNSPECIFIED);
- }
- GdkFont gdkFont = new GdkFont();
- OS.memmove(gdkFont, fontHandle);
- byte [] w = Converter.wcsToMbcs (null, "w", true);
- return FontMetrics.gtk_new(fontHandle);
+ int pango_fd = OS.pango_context_get_font_description(pango_context);
+ int pango_metrics = OS.pango_context_get_metrics(pango_context, pango_fd, null);
+ FontMetrics answer = FontMetrics.gtk_new(pango_metrics);
+ answer.height = OS.pango_font_description_get_size(pango_fd);
+ return answer;
}
/**
@@ -460,17 +445,9 @@ public void setClipping(Region region) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setFont(Font font) {
-/* int fontHandle = 0;
- if (font == null) {
- GtkStyle gtkStyle = new GtkStyle();
- int style = OS.gtk_widget_get_default_style();
- OS.memmove(gtkStyle, style, GtkStyle.sizeof);
- fontHandle = gtkStyle.font;
- } else {
- fontHandle = font.handle;
- }
- OS.gdk_gc_set_font(handle, fontHandle);*/
+public void setFont(Font font) {
+ /* Set the font in the Pango context */
+ OS.pango_context_set_font_description(pango_context, font.handle);
}
/**
@@ -570,10 +547,12 @@ public void setXORMode(boolean val) {
*/
public Point stringExtent(String string) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
int width = OS.gdk_string_width(_getGCFont(), buffer);
int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
+ return new Point(width, height);*/
+ /* Temporary code */
+ return new Point(100,20);
}
/**
* Returns the extent of the given string. Tab expansion and
@@ -596,10 +575,12 @@ public Point stringExtent(String string) {
*/
public Point textExtent(String string) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
int width = OS.gdk_string_width(_getGCFont(), buffer);
int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
+ return new Point(width, height);*/
+ /* Temporary code */
+ return new Point(100,20);
}
@@ -631,13 +612,6 @@ private GdkColor _getBackgroundGdkColor() {
color.blue = values.background_blue;
return color;
}
-private int _getGCFont() {
- GdkGCValues values = _getGCValues();
- if (values.font==0) {
- SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return values.font;
-}
@@ -897,7 +871,7 @@ public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcH
double offset_y = - srcY * scale_y;
int destSizePixbuf = GDKPIXBUF.gdk_pixbuf_new (
- GDKPIXBUF.GDK_COLORSPACE_RGB,
+ GDKPIXBUF.GDK_COLORSPACE_RGB(),
true, 8, destWidth, destHeight);
GDKPIXBUF.gdk_pixbuf_scale(
pixbuf.handle, // src,
@@ -1161,13 +1135,12 @@ public void drawString (String string, int x, int y) {
*/
public void drawString(String string, int x, int y, boolean isTransparent) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
int[] unused = new int[1];
int[] width = new int[1];
int[] ascent = new int[1];
int[] average_ascent = new int [1];
- int fontHandle = _getGCFont();
OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
if (ascent[0]<average_ascent[0]) ascent[0] = average_ascent[0];
@@ -1188,7 +1161,7 @@ public void drawString(String string, int x, int y, boolean isTransparent) {
color.blue = values.foreground_blue;
OS.gdk_gc_set_foreground(handle, color);
}
- OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);
+ OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);*/
}
/**
* Draws the given string, using the receiver's current font and
@@ -1233,7 +1206,7 @@ public void drawText(String string, int x, int y) {
*/
public void drawText(String string, int x, int y, boolean isTransparent) {
if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
+/* byte[] buffer = Converter.wcsToMbcs(null, string, true);
byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
int fontHandle = _getGCFont();
int[] unused = new int[1];
@@ -1260,7 +1233,7 @@ public void drawText(String string, int x, int y, boolean isTransparent) {
color.blue = values.foreground_blue;
OS.gdk_gc_set_foreground(handle, color);
}
- OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);
+ OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);*/
}
/**
@@ -1696,7 +1669,10 @@ public void dispose() {
OS.gdk_gc_unref(handle);
else
drawable.internal_dispose_GC(handle, data);
-
+
+ /* FIXME */
+ /* It is not clear how a Pango context should be freed. */
+
data.drawable = // data.colormap = data.fontList =
data.clipRgn = data.renderTable = 0;
drawable = null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java
index 2972898f60..ab06765c1e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java
@@ -194,6 +194,9 @@ public Image(Device device, Image srcImage, int flag) {
this.transparentPixel = srcImage.transparentPixel;
// bogus - are we sure about memGC?
+ /* temporary code before we sort out greying */
+ flag = SWT.IMAGE_COPY;
+
/* Special case:
* If all we want is just a clone of the existing pixmap, it can
* be done entirely in the X server, without copying across the net.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java
index 5439fa1607..78d94f0c01 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java
@@ -273,11 +273,13 @@ final class Pixbuffer {
* an alpha channel.
*/
private void createHandle(int width, int height) {
- handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB,
+ handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB(),
true,
8,
width, height);
- if (this.handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (this.handle == 0) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
data = GDKPIXBUF.gdk_pixbuf_get_pixels(handle);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java
index 26a19bdcde..afc45b16ae 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java
@@ -107,6 +107,8 @@ public class Display extends Device {
Caret currentCaret;
Callback caretCallback;
int caretID, caretProc;
+
+ Font systemFont;
/* Colors */
Color NORMAL_fg, NORMAL_bg, NORMAL_dark, NORMAL_mid, NORMAL_light, NORMAL_text, NORMAL_base;
@@ -916,13 +918,8 @@ final void initializeSystemColors() {
*/
public Font getSystemFont () {
checkDevice ();
-/* GtkStyle style = new GtkStyle();
- OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
- int gdkFont = style.font; // gives a GdkFont*
- return Font.gtk_new (gdkFont);*/
- byte[] name = Converter.wcsToMbcs(null, "fixed");
- int f = OS.gdk_font_load(name);
- return Font.gtk_new(f);
+ if (systemFont==null) systemFont = new Font(this, new FontData("Monospace"));
+ return systemFont;
}
/**

Back to the top