cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* scr, GdkVisual* vis) { cdCtxCanvas *ctxcanvas = (cdCtxCanvas *)malloc(sizeof(cdCtxCanvas)); memset(ctxcanvas, 0, sizeof(cdCtxCanvas)); ctxcanvas->scr = scr; ctxcanvas->vis = vis; ctxcanvas->wnd = wnd; ctxcanvas->gc = gdk_gc_new(wnd); if (!ctxcanvas->gc) { free(canvas); return NULL; } ctxcanvas->fontcontext = gdk_pango_context_get(); #if PANGO_VERSION_CHECK(1,16,0) pango_context_set_language(ctxcanvas->fontcontext, pango_language_get_default()); #endif ctxcanvas->canvas = canvas; canvas->ctxcanvas = ctxcanvas; gdk_drawable_get_size(wnd, &ctxcanvas->canvas->w, &ctxcanvas->canvas->h); ctxcanvas->depth = gdk_drawable_get_depth(wnd); canvas->bpp = ctxcanvas->depth; canvas->xres = ((double)gdk_screen_get_width(scr) / (double)gdk_screen_get_width_mm(scr)); canvas->yres = ((double)gdk_screen_get_height(scr) / (double)gdk_screen_get_height_mm(scr)); canvas->w_mm = ((double)canvas->w) / canvas->xres; canvas->h_mm = ((double)canvas->h) / canvas->yres; canvas->invert_yaxis = 1; if (canvas->bpp <= 8) { ctxcanvas->colormap = gdk_gc_get_colormap(ctxcanvas->gc); if (!ctxcanvas->colormap) { ctxcanvas->colormap = gdk_colormap_get_system(); gdk_gc_set_colormap(ctxcanvas->gc, ctxcanvas->colormap); } ctxcanvas->num_colors = ctxcanvas->colormap->size; } cdRegisterAttribute(canvas, &gc_attrib); cdRegisterAttribute(canvas, &rotate_attrib); cdRegisterAttribute(canvas, &pangoversion_attrib); cdRegisterAttribute(canvas, &imgdither_attrib); cdRegisterAttribute(canvas, &interp_attrib); return ctxcanvas; }
static void cdpalette(cdCtxCanvas *ctxcanvas, int n, const long int *palette, int mode) { int i; GdkColor clr; if (mode == CD_FORCE) { /* if was POLITE then allocates own palette */ if (ctxcanvas->colormap == gdk_gc_get_colormap(ctxcanvas->gc)) ctxcanvas->colormap = gdk_colormap_new(ctxcanvas->vis, FALSE); /* allocate all the palette colors to the CD */ for (i = 0; i < n; i++) { clr = cdColorToGdk(palette[i]); gdk_colormap_alloc_color(ctxcanvas->colormap, &clr, FALSE, FALSE); } /* set directly on the drawable */ gdk_drawable_set_colormap(ctxcanvas->wnd, ctxcanvas->colormap); } else { /* if was FORCE, remove the own palette */ if (ctxcanvas->colormap != gdk_gc_get_colormap(ctxcanvas->gc)) { g_object_unref(ctxcanvas->colormap); ctxcanvas->colormap = gdk_gc_get_colormap(ctxcanvas->gc); } /* if POLITE then just try to allocate all the colors of the palette */ for (i = 0; i < n; i++) { clr = cdColorToGdk(palette[i]); gdk_colormap_alloc_color(ctxcanvas->colormap, &clr, FALSE, TRUE); } } }
void cdgdkKillCanvas(cdCtxCanvas *ctxcanvas) { if (ctxcanvas->canvas->bpp <= 8) { if (ctxcanvas->colormap != gdk_gc_get_colormap(ctxcanvas->gc)) g_object_unref(ctxcanvas->colormap); } if (ctxcanvas->last_hatch) g_object_unref(ctxcanvas->last_hatch); if (ctxcanvas->fontdesc) pango_font_description_free(ctxcanvas->fontdesc); if (ctxcanvas->fontlayout) g_object_unref(ctxcanvas->fontlayout); if (ctxcanvas->fontcontext) g_object_unref(ctxcanvas->fontcontext); if (ctxcanvas->new_rgn) gdk_region_destroy(ctxcanvas->new_rgn); if (ctxcanvas->clip_rgn) gdk_region_destroy(ctxcanvas->clip_rgn); if (ctxcanvas->last_pattern) { g_object_unref(ctxcanvas->last_pattern_gc); g_object_unref(ctxcanvas->last_pattern); } if (ctxcanvas->last_stipple) { g_object_unref(ctxcanvas->last_stipple_gc); g_object_unref(ctxcanvas->last_stipple); } if (ctxcanvas->strLastConvertUTF8) g_free(ctxcanvas->strLastConvertUTF8); g_object_unref(ctxcanvas->gc); free(ctxcanvas); }
static VALUE rg_colormap(VALUE self) { return GOBJ2RVAL(gdk_gc_get_colormap(_SELF(self))); }