1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkprivate-x11.h"
32 #include "gdkregion-generic.h"
38 GDK_GC_DIRTY_CLIP = 1 << 0,
39 GDK_GC_DIRTY_TS = 1 << 1
42 static void gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
45 unsigned long *xvalues_mask);
47 static void gdk_x11_gc_get_values (GdkGC *gc,
49 static void gdk_x11_gc_set_values (GdkGC *gc,
51 GdkGCValuesMask values_mask);
52 static void gdk_x11_gc_set_dashes (GdkGC *gc,
57 static void gdk_gc_x11_class_init (GdkGCX11Class *klass);
58 static void gdk_gc_x11_finalize (GObject *object);
60 static gpointer parent_class = NULL;
63 _gdk_gc_x11_get_type (void)
65 static GType object_type = 0;
69 static const GTypeInfo object_info =
71 sizeof (GdkGCX11Class),
73 (GBaseFinalizeFunc) NULL,
74 (GClassInitFunc) gdk_gc_x11_class_init,
75 NULL, /* class_finalize */
76 NULL, /* class_data */
79 (GInstanceInitFunc) NULL,
82 object_type = g_type_register_static (GDK_TYPE_GC,
91 gdk_gc_x11_class_init (GdkGCX11Class *klass)
93 GObjectClass *object_class = G_OBJECT_CLASS (klass);
94 GdkGCClass *gc_class = GDK_GC_CLASS (klass);
96 parent_class = g_type_class_peek_parent (klass);
98 object_class->finalize = gdk_gc_x11_finalize;
100 gc_class->get_values = gdk_x11_gc_get_values;
101 gc_class->set_values = gdk_x11_gc_set_values;
102 gc_class->set_dashes = gdk_x11_gc_set_dashes;
106 gdk_gc_x11_finalize (GObject *object)
108 GdkGCX11 *x11_gc = GDK_GC_X11 (object);
110 if (x11_gc->clip_region)
111 gdk_region_destroy (x11_gc->clip_region);
113 if (x11_gc->fg_picture != None)
114 XRenderFreePicture (GDK_GC_XDISPLAY (x11_gc), x11_gc->fg_picture);
116 XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc));
118 G_OBJECT_CLASS (parent_class)->finalize (object);
123 _gdk_x11_gc_new (GdkDrawable *drawable,
125 GdkGCValuesMask values_mask)
131 unsigned long xvalues_mask;
133 /* NOTICE that the drawable here has to be the impl drawable,
134 * not the publically-visible drawables.
136 g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_X11 (drawable), NULL);
138 gc = g_object_new (_gdk_gc_x11_get_type (), NULL);
139 private = GDK_GC_X11 (gc);
141 private->dirty_mask = 0;
142 private->have_clip_mask = FALSE;
143 private->clip_region = NULL;
145 private->screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen;
147 private->depth = gdk_drawable_get_depth (drawable);
149 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
151 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
152 private->dirty_mask |= GDK_GC_DIRTY_CLIP;
155 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
157 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
158 private->dirty_mask |= GDK_GC_DIRTY_TS;
161 if (values_mask & GDK_GC_FOREGROUND)
162 private->fg_pixel = values->foreground.pixel;
164 if ((values_mask & GDK_GC_CLIP_MASK) && values->clip_mask)
165 private->have_clip_mask = TRUE;
167 xvalues.function = GXcopy;
168 xvalues.fill_style = FillSolid;
169 xvalues.arc_mode = ArcPieSlice;
170 xvalues.subwindow_mode = ClipByChildren;
171 xvalues.graphics_exposures = False;
172 xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures;
174 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
176 private->xgc = XCreateGC (GDK_GC_XDISPLAY (gc),
177 GDK_DRAWABLE_IMPL_X11 (drawable)->xid,
178 xvalues_mask, &xvalues);
184 _gdk_x11_gc_flush (GdkGC *gc)
186 GdkGCX11 *private = GDK_GC_X11 (gc);
188 if (private->dirty_mask & GDK_GC_DIRTY_CLIP)
190 if (!private->clip_region)
191 XSetClipOrigin (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
192 gc->clip_x_origin, gc->clip_y_origin);
195 XRectangle *rectangles;
198 _gdk_region_get_xrectangles (private->clip_region,
204 XSetClipRectangles (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), 0, 0,
212 if (private->dirty_mask & GDK_GC_DIRTY_TS)
214 XSetTSOrigin (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
215 gc->ts_x_origin, gc->ts_y_origin);
218 private->dirty_mask = 0;
219 return GDK_GC_XGC (gc);
223 gdk_x11_gc_get_values (GdkGC *gc,
228 if (XGetGCValues (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
229 GCForeground | GCBackground | GCFont |
230 GCFunction | GCTile | GCStipple | /* GCClipMask | */
231 GCSubwindowMode | GCGraphicsExposures |
232 GCTileStipXOrigin | GCTileStipYOrigin |
233 GCClipXOrigin | GCClipYOrigin |
234 GCLineWidth | GCLineStyle | GCCapStyle |
235 GCFillStyle | GCJoinStyle, &xvalues))
237 values->foreground.pixel = xvalues.foreground;
238 values->background.pixel = xvalues.background;
239 values->font = gdk_font_lookup_for_display (GDK_GC_DISPLAY (gc),
242 switch (xvalues.function)
245 values->function = GDK_COPY;
248 values->function = GDK_INVERT;
251 values->function = GDK_XOR;
254 values->function = GDK_CLEAR;
257 values->function = GDK_AND;
260 values->function = GDK_AND_REVERSE;
263 values->function = GDK_AND_INVERT;
266 values->function = GDK_NOOP;
269 values->function = GDK_OR;
272 values->function = GDK_EQUIV;
275 values->function = GDK_OR_REVERSE;
278 values->function =GDK_COPY_INVERT;
281 values->function = GDK_OR_INVERT;
284 values->function = GDK_NAND;
287 values->function = GDK_SET;
290 values->function = GDK_NOR;
294 switch (xvalues.fill_style)
297 values->fill = GDK_SOLID;
300 values->fill = GDK_TILED;
303 values->fill = GDK_STIPPLED;
305 case FillOpaqueStippled:
306 values->fill = GDK_OPAQUE_STIPPLED;
310 values->tile = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
312 values->stipple = gdk_pixmap_lookup_for_display (GDK_GC_DISPLAY (gc),
314 values->clip_mask = NULL;
315 values->subwindow_mode = xvalues.subwindow_mode;
316 values->ts_x_origin = xvalues.ts_x_origin;
317 values->ts_y_origin = xvalues.ts_y_origin;
318 values->clip_x_origin = xvalues.clip_x_origin;
319 values->clip_y_origin = xvalues.clip_y_origin;
320 values->graphics_exposures = xvalues.graphics_exposures;
321 values->line_width = xvalues.line_width;
323 switch (xvalues.line_style)
326 values->line_style = GDK_LINE_SOLID;
329 values->line_style = GDK_LINE_ON_OFF_DASH;
332 values->line_style = GDK_LINE_DOUBLE_DASH;
336 switch (xvalues.cap_style)
339 values->cap_style = GDK_CAP_NOT_LAST;
342 values->cap_style = GDK_CAP_BUTT;
345 values->cap_style = GDK_CAP_ROUND;
348 values->cap_style = GDK_CAP_PROJECTING;
352 switch (xvalues.join_style)
355 values->join_style = GDK_JOIN_MITER;
358 values->join_style = GDK_JOIN_ROUND;
361 values->join_style = GDK_JOIN_BEVEL;
367 memset (values, 0, sizeof (GdkGCValues));
373 gdk_x11_gc_set_values (GdkGC *gc,
375 GdkGCValuesMask values_mask)
379 unsigned long xvalues_mask = 0;
381 x11_gc = GDK_GC_X11 (gc);
383 if (values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
385 values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
386 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
389 if (values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN))
391 values_mask &= ~(GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
392 x11_gc->dirty_mask |= GDK_GC_DIRTY_TS;
395 if (values_mask & GDK_GC_CLIP_MASK)
397 if (x11_gc->clip_region)
399 gdk_region_destroy (x11_gc->clip_region);
400 x11_gc->clip_region = NULL;
403 x11_gc->have_clip_mask = values->clip_mask != NULL;
406 if (values_mask & GDK_GC_FOREGROUND)
407 x11_gc->fg_pixel = values->foreground.pixel;
409 gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask);
411 XChangeGC (GDK_GC_XDISPLAY (gc),
418 gdk_x11_gc_set_dashes (GdkGC *gc,
423 g_return_if_fail (GDK_IS_GC (gc));
424 g_return_if_fail (dash_list != NULL);
426 XSetDashes (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc),
427 dash_offset, dash_list, n);
431 gdk_x11_gc_values_to_xvalues (GdkGCValues *values,
432 GdkGCValuesMask mask,
434 unsigned long *xvalues_mask)
436 /* Optimization for the common case (gdk_gc_new()) */
437 if (values == NULL || mask == 0)
440 if (mask & GDK_GC_FOREGROUND)
442 xvalues->foreground = values->foreground.pixel;
443 *xvalues_mask |= GCForeground;
445 if (mask & GDK_GC_BACKGROUND)
447 xvalues->background = values->background.pixel;
448 *xvalues_mask |= GCBackground;
450 if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT))
452 xvalues->font = ((XFontStruct *) (GDK_FONT_XFONT (values->font)))->fid;
453 *xvalues_mask |= GCFont;
455 if (mask & GDK_GC_FUNCTION)
457 switch (values->function)
460 xvalues->function = GXcopy;
463 xvalues->function = GXinvert;
466 xvalues->function = GXxor;
469 xvalues->function = GXclear;
472 xvalues->function = GXand;
474 case GDK_AND_REVERSE:
475 xvalues->function = GXandReverse;
478 xvalues->function = GXandInverted;
481 xvalues->function = GXnoop;
484 xvalues->function = GXor;
487 xvalues->function = GXequiv;
490 xvalues->function = GXorReverse;
492 case GDK_COPY_INVERT:
493 xvalues->function = GXcopyInverted;
496 xvalues->function = GXorInverted;
499 xvalues->function = GXnand;
502 xvalues->function = GXset;
505 xvalues->function = GXnor;
508 *xvalues_mask |= GCFunction;
510 if (mask & GDK_GC_FILL)
512 switch (values->fill)
515 xvalues->fill_style = FillSolid;
518 xvalues->fill_style = FillTiled;
521 xvalues->fill_style = FillStippled;
523 case GDK_OPAQUE_STIPPLED:
524 xvalues->fill_style = FillOpaqueStippled;
527 *xvalues_mask |= GCFillStyle;
529 if (mask & GDK_GC_TILE)
532 xvalues->tile = GDK_DRAWABLE_XID (values->tile);
534 xvalues->tile = None;
536 *xvalues_mask |= GCTile;
538 if (mask & GDK_GC_STIPPLE)
541 xvalues->stipple = GDK_DRAWABLE_XID (values->stipple);
543 xvalues->stipple = None;
545 *xvalues_mask |= GCStipple;
547 if (mask & GDK_GC_CLIP_MASK)
549 if (values->clip_mask)
550 xvalues->clip_mask = GDK_DRAWABLE_XID (values->clip_mask);
552 xvalues->clip_mask = None;
554 *xvalues_mask |= GCClipMask;
557 if (mask & GDK_GC_SUBWINDOW)
559 xvalues->subwindow_mode = values->subwindow_mode;
560 *xvalues_mask |= GCSubwindowMode;
562 if (mask & GDK_GC_TS_X_ORIGIN)
564 xvalues->ts_x_origin = values->ts_x_origin;
565 *xvalues_mask |= GCTileStipXOrigin;
567 if (mask & GDK_GC_TS_Y_ORIGIN)
569 xvalues->ts_y_origin = values->ts_y_origin;
570 *xvalues_mask |= GCTileStipYOrigin;
572 if (mask & GDK_GC_CLIP_X_ORIGIN)
574 xvalues->clip_x_origin = values->clip_x_origin;
575 *xvalues_mask |= GCClipXOrigin;
577 if (mask & GDK_GC_CLIP_Y_ORIGIN)
579 xvalues->clip_y_origin = values->clip_y_origin;
580 *xvalues_mask |= GCClipYOrigin;
583 if (mask & GDK_GC_EXPOSURES)
585 xvalues->graphics_exposures = values->graphics_exposures;
586 *xvalues_mask |= GCGraphicsExposures;
589 if (mask & GDK_GC_LINE_WIDTH)
591 xvalues->line_width = values->line_width;
592 *xvalues_mask |= GCLineWidth;
594 if (mask & GDK_GC_LINE_STYLE)
596 switch (values->line_style)
599 xvalues->line_style = LineSolid;
601 case GDK_LINE_ON_OFF_DASH:
602 xvalues->line_style = LineOnOffDash;
604 case GDK_LINE_DOUBLE_DASH:
605 xvalues->line_style = LineDoubleDash;
608 *xvalues_mask |= GCLineStyle;
610 if (mask & GDK_GC_CAP_STYLE)
612 switch (values->cap_style)
614 case GDK_CAP_NOT_LAST:
615 xvalues->cap_style = CapNotLast;
618 xvalues->cap_style = CapButt;
621 xvalues->cap_style = CapRound;
623 case GDK_CAP_PROJECTING:
624 xvalues->cap_style = CapProjecting;
627 *xvalues_mask |= GCCapStyle;
629 if (mask & GDK_GC_JOIN_STYLE)
631 switch (values->join_style)
634 xvalues->join_style = JoinMiter;
637 xvalues->join_style = JoinRound;
640 xvalues->join_style = JoinBevel;
643 *xvalues_mask |= GCJoinStyle;
649 * gdk_gc_set_clip_rectangle:
651 * @rectangle: the rectangle to clip to.
653 * Sets the clip mask for a graphics context from a
654 * rectangle. The clip mask is interpreted relative to the clip
655 * origin. (See gdk_gc_set_clip_origin()).
658 gdk_gc_set_clip_rectangle (GdkGC *gc,
659 GdkRectangle *rectangle)
662 gboolean had_region = FALSE;
664 g_return_if_fail (GDK_IS_GC (gc));
666 x11_gc = GDK_GC_X11 (gc);
668 if (x11_gc->clip_region)
671 gdk_region_destroy (x11_gc->clip_region);
675 x11_gc->clip_region = gdk_region_rectangle (rectangle);
677 x11_gc->clip_region = NULL;
679 /* Unset immediately, to make sure Xlib doesn't keep the
680 * XID of an old clip mask cached
682 if ((had_region && !rectangle) || x11_gc->have_clip_mask)
684 XSetClipMask (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), None);
685 x11_gc->have_clip_mask = FALSE;
688 gc->clip_x_origin = 0;
689 gc->clip_y_origin = 0;
691 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
695 * gdk_gc_set_clip_region:
697 * @region: the #GdkRegion.
699 * Sets the clip mask for a graphics context from a region structure.
700 * The clip mask is interpreted relative to the clip origin. (See
701 * gdk_gc_set_clip_origin()).
704 gdk_gc_set_clip_region (GdkGC *gc,
708 gboolean had_region = FALSE;
710 g_return_if_fail (GDK_IS_GC (gc));
712 x11_gc = GDK_GC_X11 (gc);
714 if (x11_gc->clip_region)
717 gdk_region_destroy (x11_gc->clip_region);
721 x11_gc->clip_region = gdk_region_copy (region);
723 x11_gc->clip_region = NULL;
725 /* Unset immediately, to make sure Xlib doesn't keep the
726 * XID of an old clip mask cached
728 if ((had_region && !region) || x11_gc->have_clip_mask)
730 XSetClipMask (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), None);
731 x11_gc->have_clip_mask = FALSE;
734 gc->clip_x_origin = 0;
735 gc->clip_y_origin = 0;
737 x11_gc->dirty_mask |= GDK_GC_DIRTY_CLIP;
743 * @dst_gc: the destination graphics context.
744 * @src_gc: the source graphics context.
746 * Copy the set of values from one graphics context
747 * onto another graphics context.
750 gdk_gc_copy (GdkGC *dst_gc, GdkGC *src_gc)
752 GdkGCX11 *x11_src_gc;
753 GdkGCX11 *x11_dst_gc;
755 g_return_if_fail (GDK_IS_GC_X11 (dst_gc));
756 g_return_if_fail (GDK_IS_GC_X11 (src_gc));
758 x11_dst_gc = GDK_GC_X11 (dst_gc);
759 x11_src_gc = GDK_GC_X11 (src_gc);
761 XCopyGC (GDK_GC_XDISPLAY (src_gc), GDK_GC_XGC (src_gc), ~((~1) << GCLastBit),
762 GDK_GC_XGC (dst_gc));
764 dst_gc->clip_x_origin = src_gc->clip_x_origin;
765 dst_gc->clip_y_origin = src_gc->clip_y_origin;
766 dst_gc->ts_x_origin = src_gc->ts_x_origin;
767 dst_gc->ts_y_origin = src_gc->ts_y_origin;
769 if (src_gc->colormap)
770 g_object_ref (src_gc->colormap);
772 if (dst_gc->colormap)
773 g_object_unref (dst_gc->colormap);
775 dst_gc->colormap = src_gc->colormap;
777 if (x11_dst_gc->clip_region)
778 gdk_region_destroy (x11_dst_gc->clip_region);
780 if (x11_src_gc->clip_region)
781 x11_dst_gc->clip_region = gdk_region_copy (x11_src_gc->clip_region);
783 x11_dst_gc->clip_region = NULL;
785 x11_dst_gc->dirty_mask = x11_src_gc->dirty_mask;
786 x11_dst_gc->fg_pixel = x11_src_gc->fg_pixel;
793 * Gets the #GdkScreen for which @gc was created
795 * Returns: the #GdkScreen for @gc.
800 gdk_gc_get_screen (GdkGC *gc)
802 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
804 return GDK_GC_X11 (gc)->screen;
808 * gdk_x11_gc_get_xdisplay:
811 * Returns the display of a #GdkGC.
813 * Return value: an Xlib <type>Display*</type>.
816 gdk_x11_gc_get_xdisplay (GdkGC *gc)
818 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
820 return GDK_SCREEN_XDISPLAY (gdk_gc_get_screen (gc));
824 * gdk_x11_gc_get_xgc:
827 * Returns the X GC of a #GdkGC.
829 * Return value: an Xlib <type>GC</type>.
832 gdk_x11_gc_get_xgc (GdkGC *gc)
836 g_return_val_if_fail (GDK_IS_GC_X11 (gc), NULL);
838 gc_x11 = GDK_GC_X11 (gc);
840 if (gc_x11->dirty_mask)
841 _gdk_x11_gc_flush (gc);
846 /* Various bits of the below are roughly cribbed from XFree86
847 * lib/Xft/xftdraw.c, Copyright 2000, Keith Packard
850 static XRenderPictFormat *
851 foreground_format (GdkGC *gc)
853 XRenderPictFormat pf;
855 pf.type = PictTypeDirect;
857 pf.direct.redMask = 0xff;
858 pf.direct.greenMask = 0xff;
859 pf.direct.blueMask = 0xff;
860 pf.direct.alphaMask = 0xff;
862 return XRenderFindFormat (GDK_GC_XDISPLAY (gc),
866 PictFormatGreenMask |
868 PictFormatAlphaMask),
874 * _gdk_x11_gc_get_fg_picture:
877 * Gets a Xrender Picture object suitable for being the source
878 * drawable for drawing with the foreground the graphics context.
879 * (Currently, only foreground color is handled, but in the
880 * future we should handle tiles/stipples as well.)
882 * Return value: a Picture, owned by the GC; this cannot be
883 * used over subsequent modification of the GC.
886 _gdk_x11_gc_get_fg_picture (GdkGC *gc)
889 gboolean new = FALSE;
892 g_return_val_if_fail (GDK_IS_GC_X11 (gc), None);
894 if (!_gdk_x11_have_render (GDK_GC_DISPLAY (gc)))
897 x11_gc = GDK_GC_X11 (gc);
899 if (x11_gc->fg_picture == None)
901 XRenderPictureAttributes pa;
902 XRenderPictFormat *pix_format = foreground_format (gc);
908 pix = XCreatePixmap (GDK_GC_XDISPLAY (gc),
909 GDK_SCREEN_XROOTWIN (x11_gc->screen),
910 1, 1, pix_format->depth);
912 x11_gc->fg_picture = XRenderCreatePicture (GDK_GC_XDISPLAY (gc),
916 XFreePixmap (GDK_GC_XDISPLAY (gc), pix);
921 _gdk_gc_x11_get_fg_xft_color (gc, &xftcolor);
924 x11_gc->fg_picture_color.red != xftcolor.color.red ||
925 x11_gc->fg_picture_color.green != xftcolor.color.green ||
926 x11_gc->fg_picture_color.blue != xftcolor.color.blue)
928 x11_gc->fg_picture_color.red = xftcolor.color.red;
929 x11_gc->fg_picture_color.green = xftcolor.color.green;
930 x11_gc->fg_picture_color.blue = xftcolor.color.blue;
932 XRenderFillRectangle (GDK_GC_XDISPLAY (gc), PictOpSrc,
933 x11_gc->fg_picture, &x11_gc->fg_picture_color,
937 return x11_gc->fg_picture;
941 * _gdk_gc_x11_get_fg_xft_color:
943 * @xftcolor: location to store the color
945 * Gets the foreground color of the GC as a XftColor.
948 _gdk_gc_x11_get_fg_xft_color (GdkGC *gc,
955 g_return_if_fail (GDK_IS_GC_X11 (gc));
957 x11_gc = GDK_GC_X11 (gc);
959 cmap = gdk_gc_get_colormap (gc);
961 xftcolor->pixel = x11_gc->fg_pixel;
965 gdk_colormap_query_color (cmap, xftcolor->pixel, &color);
966 xftcolor->color.alpha = 0xffff;
967 xftcolor->color.red = color.red;
968 xftcolor->color.green = color.green;
969 xftcolor->color.blue = color.blue;
971 else if (x11_gc->depth == 1)
973 /* Drawing with Xft on a bitmap is a bit bizzare; it
974 * takes alpha >= 0x8000 to mean 'set to 1' and
975 * alpha < 0x8000 to mean 'set to 0'.
979 xftcolor->color.red = 0xffff;
980 xftcolor->color.green = 0xffff;
981 xftcolor->color.blue = 0xffff;
982 xftcolor->color.alpha = 0xffff;
986 xftcolor->color.red = 0;
987 xftcolor->color.green = 0;
988 xftcolor->color.blue = 0;
989 xftcolor->color.alpha = 0;
994 g_warning ("Using Xft rendering requires the GC argument to have a\n"
995 "specified colormap. If the GC was created for a drawable\n"
996 "with a colormap, the colormap will be set on the GC\n"
997 "automatically. Otherwise, a colormap must be set on it with"
998 "gdk_gc_set_colormap");