]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkdraw.c
[ Merges from gtk-1-2 ]
[~andy/gtk] / gdk / gdkdraw.c
index de23f6c4f50515086399bd312e5ef21fbf86ca1f..8ae417e4aa6b7fe95f92ff052aa5f515de58eb31 100644 (file)
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
  */
+
+/*
+ * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
 #include <X11/Xlib.h>
 #include <X11/Xos.h>
 #include "gdk.h"
@@ -142,6 +151,9 @@ gdk_draw_polygon (GdkDrawable *drawable,
 {
   GdkWindowPrivate *drawable_private;
   GdkGCPrivate *gc_private;
+  GdkPoint *local_points = points;
+  gint local_npoints = npoints;
+  gint local_alloc = 0;
 
   g_return_if_fail (drawable != NULL);
   g_return_if_fail (gc != NULL);
@@ -158,14 +170,24 @@ gdk_draw_polygon (GdkDrawable *drawable,
     }
   else
     {
-      XDrawLines (drawable_private->xdisplay, drawable_private->xwindow,
-                 gc_private->xgc, (XPoint*) points, npoints, CoordModeOrigin);
-
       if ((points[0].x != points[npoints-1].x) ||
-         (points[0].y != points[npoints-1].y))
-       XDrawLine (drawable_private->xdisplay, drawable_private->xwindow,
-                  gc_private->xgc, points[npoints-1].x, points[npoints-1].y,
-                  points[0].x, points[0].y);
+        (points[0].y != points[npoints-1].y)) 
+        {
+          local_alloc = 1;
+          ++local_npoints;
+          local_points = (GdkPoint*) g_malloc (local_npoints * sizeof(GdkPoint));
+          memcpy (local_points, points, npoints * sizeof(GdkPoint));
+          local_points[npoints].x = points[0].x;
+          local_points[npoints].y = points[0].y;
+      }
+
+      XDrawLines (drawable_private->xdisplay, drawable_private->xwindow,
+                 gc_private->xgc,
+                 (XPoint*) local_points, local_npoints,
+                 CoordModeOrigin);
+  
+       if (local_alloc)
+       g_free (local_points);
     }
 }
 
@@ -279,6 +301,66 @@ gdk_draw_text (GdkDrawable *drawable,
     g_error("undefined font type\n");
 }
 
+void
+gdk_draw_text_wc (GdkDrawable   *drawable,
+                 GdkFont        *font,
+                 GdkGC          *gc,
+                 gint            x,
+                 gint            y,
+                 const GdkWChar *text,
+                 gint            text_length)
+{
+  GdkWindowPrivate *drawable_private;
+  GdkFontPrivate *font_private;
+  GdkGCPrivate *gc_private;
+
+  g_return_if_fail (drawable != NULL);
+  g_return_if_fail (font != NULL);
+  g_return_if_fail (gc != NULL);
+  g_return_if_fail (text != NULL);
+
+  drawable_private = (GdkWindowPrivate*) drawable;
+  if (drawable_private->destroyed)
+    return;
+  gc_private = (GdkGCPrivate*) gc;
+  font_private = (GdkFontPrivate*) font;
+
+  if (font->type == GDK_FONT_FONT)
+    {
+      XFontStruct *xfont = (XFontStruct *) font_private->xfont;
+      gchar *text_8bit;
+      gint i;
+      XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
+      text_8bit = g_new (gchar, text_length);
+      for (i=0; i<text_length; i++) text_8bit[i] = text[i];
+      XDrawString (drawable_private->xdisplay, drawable_private->xwindow,
+                   gc_private->xgc, x, y, text_8bit, text_length);
+      g_free (text_8bit);
+    }
+  else if (font->type == GDK_FONT_FONTSET)
+    {
+      if (sizeof(GdkWChar) == sizeof(wchar_t))
+       {
+         XwcDrawString (drawable_private->xdisplay, drawable_private->xwindow,
+                        (XFontSet) font_private->xfont,
+                        gc_private->xgc, x, y, (wchar_t *)text, text_length);
+       }
+      else
+       {
+         wchar_t *text_wchar;
+         gint i;
+         text_wchar = g_new (wchar_t, text_length);
+         for (i=0; i<text_length; i++) text_wchar[i] = text[i];
+         XwcDrawString (drawable_private->xdisplay, drawable_private->xwindow,
+                        (XFontSet) font_private->xfont,
+                        gc_private->xgc, x, y, text_wchar, text_length);
+         g_free (text_wchar);
+       }
+    }
+  else
+    g_error("undefined font type\n");
+}
+
 void
 gdk_draw_pixmap (GdkDrawable *drawable,
                 GdkGC       *gc,
@@ -401,3 +483,32 @@ gdk_draw_segments (GdkDrawable *drawable,
                 (XSegment *) segs,
                 nsegs);
 }
+
+void
+gdk_draw_lines (GdkDrawable *drawable,
+              GdkGC       *gc,
+              GdkPoint    *points,
+              gint         npoints)
+{
+  GdkWindowPrivate *drawable_private;
+  GdkGCPrivate *gc_private;
+
+  if (npoints <= 0)
+    return;
+
+  g_return_if_fail (drawable != NULL);
+  g_return_if_fail (points != NULL);
+  g_return_if_fail (gc != NULL);
+
+  drawable_private = (GdkWindowPrivate*) drawable;
+  if (drawable_private->destroyed)
+    return;
+  gc_private = (GdkGCPrivate*) gc;
+
+  XDrawLines (drawable_private->xdisplay,
+             drawable_private->xwindow,
+             gc_private->xgc,
+             (XPoint *) points,
+             npoints,
+             CoordModeOrigin);
+}