summaryrefslogtreecommitdiff
path: root/src/gdk/cdgdk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdk/cdgdk.c')
-rw-r--r--src/gdk/cdgdk.c707
1 files changed, 320 insertions, 387 deletions
diff --git a/src/gdk/cdgdk.c b/src/gdk/cdgdk.c
index 87a7a6c..e0692fc 100644
--- a/src/gdk/cdgdk.c
+++ b/src/gdk/cdgdk.c
@@ -14,17 +14,12 @@
#include <gdk/gdk.h>
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
GdkColor (*cdgdkGetPixel)(cdCtxCanvas *ctxcanvas, unsigned long rgb); /* access to the color table */
void (*cdgdkGetRGB)(cdCtxCanvas *ctxcanvas, unsigned long pixel,
unsigned char* red,
unsigned char* green,
unsigned char* blue); /* access to the color table */
-static GdkGCValues* gcval;
-
static int cdgdkDirectColorTable[256]; /* used with directColor visuals */
#define NUM_HATCHES 6
@@ -47,14 +42,12 @@ static char hatches[NUM_HATCHES][8] = {
/******************************************************/
-/* Done! */
static void update_colors(cdCtxCanvas *ctxcanvas)
{
gboolean success;
gdk_colormap_alloc_colors(ctxcanvas->colormap, ctxcanvas->color_table, ctxcanvas->num_colors, FALSE, TRUE, &success);
}
-/* Done! */
static int find_color(cdCtxCanvas *ctxcanvas, GdkColor xc1)
{
int pos = 0, i;
@@ -82,7 +75,6 @@ static int find_color(cdCtxCanvas *ctxcanvas, GdkColor xc1)
return pos;
}
-/* Done! */
/* Search the nearest RGB in the color table */
static unsigned long nearest_rgb(cdCtxCanvas *ctxcanvas, GdkColor clr)
{
@@ -117,7 +109,6 @@ static unsigned long nearest_rgb(cdCtxCanvas *ctxcanvas, GdkColor clr)
return ctxcanvas->color_table[pos].pixel;
}
-/* Done! */
/* GetPixel using the conversion table. Used when the system is not True color. */
static GdkColor not_truecolor_get_pixel(cdCtxCanvas *ctxcanvas, unsigned long rgb)
{
@@ -142,7 +133,6 @@ static GdkColor not_truecolor_get_pixel(cdCtxCanvas *ctxcanvas, unsigned long rg
return clr;
}
-/* Done! */
/* GetRGB using the conversion table. Used when the system is not True color. */
static void not_truecolor_get_rgb(cdCtxCanvas *ctxcanvas, unsigned long pixel, unsigned char* red, unsigned char* green, unsigned char* blue)
{
@@ -155,7 +145,6 @@ static void not_truecolor_get_rgb(cdCtxCanvas *ctxcanvas, unsigned long pixel, u
*blue = cdCOLOR16TO8(clr.blue);
}
-/* Done! */
/* GetRGB function used in True color system. */
static void truecolor_get_rgb(cdCtxCanvas *ctxcanvas, unsigned long pixel, unsigned char* red, unsigned char* green, unsigned char* blue)
{
@@ -183,7 +172,6 @@ static void truecolor_get_rgb(cdCtxCanvas *ctxcanvas, unsigned long pixel, unsig
*blue = cdCOLOR16TO8(b);
}
-/* Done! */
/* GetPixel function used in TrueColor mode. */
static GdkColor truecolor_get_pixel(cdCtxCanvas *ctxcanvas, unsigned long rgb)
{
@@ -193,29 +181,30 @@ static GdkColor truecolor_get_pixel(cdCtxCanvas *ctxcanvas, unsigned long rgb)
clrRGB.green = cdCOLOR8TO16(cdGreen(rgb));
clrRGB.blue = cdCOLOR8TO16(cdBlue(rgb));
- if (ctxcanvas->rshift < 0)
- clrRGB.red = clrRGB.red << (-ctxcanvas->rshift);
- else
- clrRGB.red = clrRGB.red >> ctxcanvas->rshift;
-
- if (ctxcanvas->gshift < 0)
- clrRGB.green = clrRGB.green << (-ctxcanvas->gshift);
- else
- clrRGB.green = clrRGB.green >> ctxcanvas->gshift;
-
- if (ctxcanvas->bshift < 0)
- clrRGB.blue = clrRGB.blue << (-ctxcanvas->bshift);
- else
- clrRGB.blue = clrRGB.blue >> ctxcanvas->bshift;
+ (void)ctxcanvas;
- clrRGB.red = clrRGB.red & ctxcanvas->vis->red_mask;
- clrRGB.green = clrRGB.green & ctxcanvas->vis->green_mask;
- clrRGB.blue = clrRGB.blue & ctxcanvas->vis->blue_mask;
+ //if (ctxcanvas->rshift < 0)
+ // clrRGB.red = clrRGB.red << (-ctxcanvas->rshift);
+ //else
+ // clrRGB.red = clrRGB.red >> ctxcanvas->rshift;
+
+ //if (ctxcanvas->gshift < 0)
+ // clrRGB.green = clrRGB.green << (-ctxcanvas->gshift);
+ //else
+ // clrRGB.green = clrRGB.green >> ctxcanvas->gshift;
+
+ //if (ctxcanvas->bshift < 0)
+ // clrRGB.blue = clrRGB.blue << (-ctxcanvas->bshift);
+ //else
+ // clrRGB.blue = clrRGB.blue >> ctxcanvas->bshift;
+
+ //clrRGB.red = clrRGB.red & ctxcanvas->vis->red_mask;
+ //clrRGB.green = clrRGB.green & ctxcanvas->vis->green_mask;
+ //clrRGB.blue = clrRGB.blue & ctxcanvas->vis->blue_mask;
return clrRGB;
}
-/* Done! */
/* Returns position of highest set bit in 'ul' as an integer (0-31), or -1 if none */
static int highbit(unsigned long ul)
{
@@ -307,7 +296,7 @@ static void makeDirectCmap(cdCtxCanvas *ctxcanvas, GdkColormap* cmap)
/******************************************************/
-void cdxKillCanvas(cdCtxCanvas *ctxcanvas)
+void cdgdkKillCanvas(cdCtxCanvas *ctxcanvas)
{
if (ctxcanvas->canvas->bpp <= 8)
{
@@ -319,7 +308,7 @@ void cdxKillCanvas(cdCtxCanvas *ctxcanvas)
}
if (ctxcanvas->xidata) free(ctxcanvas->xidata);
- if (ctxcanvas->font) g_object_unref(ctxcanvas->font);
+ if (ctxcanvas->font) cairo_scaled_font_destroy(ctxcanvas->font);
if (ctxcanvas->last_hatch) g_object_unref(ctxcanvas->last_hatch);
if (ctxcanvas->clip_polygon) g_object_unref(ctxcanvas->clip_polygon);
@@ -349,7 +338,6 @@ void cdxKillCanvas(cdCtxCanvas *ctxcanvas)
/******************************************************/
-/* done! */
static void cdflush(cdCtxCanvas *ctxcanvas)
{
(void)ctxcanvas;
@@ -358,21 +346,18 @@ static void cdflush(cdCtxCanvas *ctxcanvas)
/******************************************************/
-/* Done! */
static GdkPixmap* build_clip_polygon(cdCtxCanvas *ctxcanvas, GdkPoint* pnt, int n)
{
GdkPixmap *pix = gdk_pixmap_new(ctxcanvas->wnd, ctxcanvas->canvas->w, ctxcanvas->canvas->h, 1);
GdkGC *gc = gdk_gc_new((GdkDrawable*)pix);
- GdkGCValues values;
-
- gdk_gc_get_values(gc, &values);
+ GdkColor clr;
- values.foreground.pixel = 0;
- gdk_gc_set_foreground(gc, &values.foreground);
+ clr.pixel = 0;
+ gdk_gc_set_foreground(gc, &clr);
gdk_draw_rectangle(pix, gc, TRUE, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
- values.foreground.pixel = 1;
- gdk_gc_set_foreground(gc, &values.foreground);
+ clr.pixel = 1;
+ gdk_gc_set_foreground(gc, &clr);
gdk_region_polygon(pnt, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
gdk_draw_polygon(pix, gc, TRUE, pnt, n);
@@ -381,7 +366,6 @@ static GdkPixmap* build_clip_polygon(cdCtxCanvas *ctxcanvas, GdkPoint* pnt, int
return pix;
}
-/* Done! */
static void gdksetclip_area(cdCtxCanvas *ctxcanvas)
{
cdRect* clip_rect = &ctxcanvas->canvas->clip_rect;
@@ -392,7 +376,7 @@ static void gdksetclip_area(cdCtxCanvas *ctxcanvas)
poly[1].x = clip_rect->xmin; poly[1].y = clip_rect->ymax;
poly[2].x = clip_rect->xmax; poly[2].y = clip_rect->ymax;
poly[3].x = clip_rect->xmax; poly[3].y = clip_rect->ymin;
- ctxcanvas->canvas->cxPoly(ctxcanvas, CD_CLIP, poly, 4); // VER ISSO!!!!
+ ctxcanvas->canvas->cxPoly(ctxcanvas, CD_CLIP, poly, 4);
}
else
{
@@ -405,7 +389,6 @@ static void gdksetclip_area(cdCtxCanvas *ctxcanvas)
}
}
-/* Done! */
int cdgdkClip(cdCtxCanvas *ctxcanvas, int clip_mode)
{
switch (clip_mode)
@@ -428,7 +411,6 @@ int cdgdkClip(cdCtxCanvas *ctxcanvas, int clip_mode)
return clip_mode;
}
-/* Done! */
static void cdcliparea(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
if (ctxcanvas->canvas->clip_mode == CD_CLIPAREA)
@@ -441,10 +423,9 @@ static void cdcliparea(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int
}
}
-/* Done! */
static void cdnewregion(cdCtxCanvas *ctxcanvas)
{
- GdkGCValues values;
+ GdkColor clr;
if (ctxcanvas->new_region)
{
@@ -458,10 +439,9 @@ static void cdnewregion(cdCtxCanvas *ctxcanvas)
{
GdkGC* gc = gdk_gc_new((GdkDrawable*)ctxcanvas->new_region);
- gdk_gc_get_values(gc, &values);
+ clr.pixel = 0;
+ gdk_gc_set_foreground(gc, &clr);
- values.foreground.pixel = 0;
- gdk_gc_set_foreground(gc, &values.foreground);
gdk_draw_rectangle(ctxcanvas->new_region, gc, TRUE, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
g_object_unref(gc);
@@ -470,12 +450,10 @@ static void cdnewregion(cdCtxCanvas *ctxcanvas)
ctxcanvas->region_aux = gdk_pixmap_new(ctxcanvas->wnd, ctxcanvas->canvas->w, ctxcanvas->canvas->h, 1);
ctxcanvas->region_aux_gc = gdk_gc_new((GdkDrawable*)ctxcanvas->region_aux);
- gdk_gc_get_values(ctxcanvas->region_aux_gc, &values);
- values.background.pixel = 0;
- gdk_gc_set_background(ctxcanvas->region_aux_gc, &values.background);
+ clr.pixel = 0;
+ gdk_gc_set_background(ctxcanvas->region_aux_gc, &clr);
}
-/* Done! */
static int cdispointinregion(cdCtxCanvas *ctxcanvas, int x, int y)
{
if (!ctxcanvas->new_region)
@@ -484,7 +462,7 @@ static int cdispointinregion(cdCtxCanvas *ctxcanvas, int x, int y)
if (x >= 0 && y >= 0 && x < ctxcanvas->canvas->w && y < ctxcanvas->canvas->h)
{
long p;
- GdkImage* img = gdk_drawable_get_image((GdkDrawable*)ctxcanvas->new_region, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h); // 1, XYPixmap;
+ GdkImage* img = gdk_drawable_get_image((GdkDrawable*)ctxcanvas->new_region, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
p = gdk_image_get_pixel(img, x, y);
g_object_unref(img);
@@ -496,7 +474,6 @@ static int cdispointinregion(cdCtxCanvas *ctxcanvas, int x, int y)
return 0;
}
-/* Done! */
static void cdgetregionbox(cdCtxCanvas *ctxcanvas, int *xmin, int *xmax, int *ymin, int *ymax)
{
if (!ctxcanvas->new_region)
@@ -510,7 +487,7 @@ static void cdgetregionbox(cdCtxCanvas *ctxcanvas, int *xmin, int *xmax, int *ym
{
int x, y;
long p;
- GdkImage* img = gdk_drawable_get_image((GdkDrawable*)ctxcanvas->new_region, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h); // 1, XYPixmap
+ GdkImage* img = gdk_drawable_get_image((GdkDrawable*)ctxcanvas->new_region, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
for (y = 0; y < ctxcanvas->canvas->h; y++)
{
@@ -550,28 +527,24 @@ static void cdgetregionbox(cdCtxCanvas *ctxcanvas, int *xmin, int *xmax, int *ym
}
}
-/* Done! */
static void sPrepareRegion(cdCtxCanvas *ctxcanvas)
{
- GdkGCValues values;
+ GdkColor clr;
if (!ctxcanvas->new_region)
return;
- gdk_gc_get_values(ctxcanvas->region_aux_gc, &values);
-
gdk_gc_set_function(ctxcanvas->region_aux_gc, GDK_COPY);
- values.foreground.pixel = 0;
- gdk_gc_set_foreground(ctxcanvas->region_aux_gc, &values.foreground);
+ clr.pixel = 0;
+ gdk_gc_set_foreground(ctxcanvas->region_aux_gc, &clr);
gdk_draw_rectangle(ctxcanvas->region_aux, ctxcanvas->region_aux_gc, TRUE, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
- values.foreground.pixel = 1;
- gdk_gc_set_foreground(ctxcanvas->region_aux_gc, &values.foreground);
+ clr.pixel = 1;
+ gdk_gc_set_foreground(ctxcanvas->region_aux_gc, &clr);
}
-/* Done! */
static void sCombineRegion(cdCtxCanvas *ctxcanvas)
{
switch(ctxcanvas->canvas->combine_mode)
@@ -595,7 +568,6 @@ static void sCombineRegion(cdCtxCanvas *ctxcanvas)
ctxcanvas->canvas->w, ctxcanvas->canvas->h);
}
-/* Done! */
static void cdoffsetregion(cdCtxCanvas *ctxcanvas, int x, int y)
{
if (!ctxcanvas->new_region)
@@ -614,26 +586,24 @@ static void cdoffsetregion(cdCtxCanvas *ctxcanvas, int x, int y)
/******************************************************/
-/* Done! */
static int cdwritemode(cdCtxCanvas *ctxcanvas, int write_mode)
{
switch (write_mode)
{
case CD_REPLACE:
- gdk_gc_set_function(ctxcanvas->region_aux_gc, GDK_COPY);
+ gdk_gc_set_function(ctxcanvas->gc, GDK_COPY);
break;
case CD_XOR:
- gdk_gc_set_function(ctxcanvas->region_aux_gc, GDK_XOR);
+ gdk_gc_set_function(ctxcanvas->gc, GDK_XOR);
break;
case CD_NOT_XOR:
- gdk_gc_set_function(ctxcanvas->region_aux_gc, GDK_EQUIV);
+ gdk_gc_set_function(ctxcanvas->gc, GDK_EQUIV);
break;
}
return write_mode;
}
-/* Done! */
static int cdinteriorstyle(cdCtxCanvas *ctxcanvas, int style)
{
GdkFill sty = GDK_SOLID;
@@ -676,7 +646,6 @@ static int cdinteriorstyle(cdCtxCanvas *ctxcanvas, int style)
return style;
}
-/* Done! */
static int cdhatch(cdCtxCanvas *ctxcanvas, int hatch_style)
{
GdkColor fg, bg;
@@ -695,7 +664,6 @@ static int cdhatch(cdCtxCanvas *ctxcanvas, int hatch_style)
return hatch_style;
}
-/* Done! */
static void cdstipple(cdCtxCanvas *ctxcanvas, int w, int h, const unsigned char *data)
{
int x, y;
@@ -721,16 +689,14 @@ static void cdstipple(cdCtxCanvas *ctxcanvas, int w, int h, const unsigned char
{
for (x = 0; x < w; x++)
{
- GdkGCValues values;
-
- gdk_gc_get_values(ctxcanvas->last_stipple_gc, &values);
+ GdkColor clr;
if(data[y*w+x])
- values.foreground.pixel = 1;
+ clr.pixel = 1;
else
- values.foreground.pixel = 0;
+ clr.pixel = 0;
- gdk_gc_set_foreground(ctxcanvas->last_stipple_gc, &values.foreground);
+ gdk_gc_set_foreground(ctxcanvas->last_stipple_gc, &clr);
gdk_draw_point(ctxcanvas->last_stipple, ctxcanvas->last_stipple_gc, x, h-y-1);
}
}
@@ -738,7 +704,6 @@ static void cdstipple(cdCtxCanvas *ctxcanvas, int w, int h, const unsigned char
cdinteriorstyle(ctxcanvas, CD_STIPPLE);
}
-/* Done! */
static int find_match(unsigned long* palette, int pal_size, unsigned long color, unsigned char *match)
{
int i;
@@ -755,12 +720,11 @@ static int find_match(unsigned long* palette, int pal_size, unsigned long color,
return 0;
}
-/* Done! */
static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colors)
{
int x, y, i;
int size = w*h;
- GdkColor *pixels = NULL;
+ GdkColor *pixels = g_new (GdkColor, size);
if (ctxcanvas->last_pattern == 0 || (ctxcanvas->last_pattern_w != w || ctxcanvas->last_pattern_h != h))
{
@@ -774,14 +738,14 @@ static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colo
if (!ctxcanvas->last_pattern)
return;
- ctxcanvas->last_stipple_gc = gdk_gc_new((GdkDrawable*)ctxcanvas->last_pattern);
+ ctxcanvas->last_pattern_gc = gdk_gc_new((GdkDrawable*)ctxcanvas->last_pattern);
ctxcanvas->last_pattern_w = w;
ctxcanvas->last_pattern_h = h;
}
if (ctxcanvas->canvas->bpp <= 8)
{
- GdkColor* match_table = NULL; /* GDK colors */
+ GdkColor* match_table; /* GDK colors */
unsigned long palette[256]; /* CD colors */
unsigned char *index = (unsigned char*)malloc(size), match;
int pal_size = 1;
@@ -804,6 +768,7 @@ static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colo
}
/* CD colors to GDK colors */
+ match_table = g_new (GdkColor, pal_size);
for (i = 0; i < pal_size; i++)
match_table[i] = cdgdkGetPixel(ctxcanvas, palette[i]);
@@ -811,6 +776,7 @@ static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colo
for (i = 0; i < size; i++)
pixels[i] = match_table[index[i]];
+ g_free(match_table);
free(index);
}
else
@@ -823,26 +789,21 @@ static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colo
{
for (x = 0; x < w; x++)
{
- GdkGCValues values;
-
- gdk_gc_get_values(ctxcanvas->last_pattern_gc, &values);
- values.foreground = pixels[y*w+x];
-
- gdk_gc_set_foreground(ctxcanvas->last_pattern_gc, &values.foreground);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->last_pattern_gc, &pixels[y*w+x]);
gdk_draw_point(ctxcanvas->last_pattern, ctxcanvas->last_pattern_gc, x, h-y-1);
}
}
cdinteriorstyle(ctxcanvas, CD_PATTERN);
+ g_free(pixels);
}
-/* Done! */
static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
{
switch (style)
{
case CD_CONTINUOUS:
- gcval->line_style = GDK_LINE_SOLID;
+ ctxcanvas->gcval.line_style = GDK_LINE_SOLID;
break;
case CD_DASHED:
case CD_DOTTED:
@@ -860,9 +821,9 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
};
if (ctxcanvas->canvas->back_opacity == CD_OPAQUE)
- gcval->line_style = GDK_LINE_DOUBLE_DASH;
+ ctxcanvas->gcval.line_style = GDK_LINE_DOUBLE_DASH;
else
- gcval->line_style = GDK_LINE_ON_OFF_DASH;
+ ctxcanvas->gcval.line_style = GDK_LINE_ON_OFF_DASH;
gdk_gc_set_dashes(ctxcanvas->gc, 0, dashes[style-CD_DASHED].list, dashes[style-CD_DASHED].size);
break;
@@ -875,9 +836,9 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
dash_style[i] = (char)ctxcanvas->canvas->line_dashes[i];
if (ctxcanvas->canvas->back_opacity == CD_OPAQUE)
- gcval->line_style = GDK_LINE_DOUBLE_DASH;
+ ctxcanvas->gcval.line_style = GDK_LINE_DOUBLE_DASH;
else
- gcval->line_style = GDK_LINE_ON_OFF_DASH;
+ ctxcanvas->gcval.line_style = GDK_LINE_ON_OFF_DASH;
gdk_gc_set_dashes(ctxcanvas->gc, 0, dash_style, ctxcanvas->canvas->line_dashes_count);
free(dash_style);
@@ -885,47 +846,43 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
}
}
- gdk_gc_set_values(ctxcanvas->gc, gcval, GDK_GC_LINE_STYLE);
+ gdk_gc_set_values(ctxcanvas->gc, &ctxcanvas->gcval, GDK_GC_LINE_STYLE);
return style;
}
-/* Done! */
static int cdlinewidth(cdCtxCanvas *ctxcanvas, int width)
{
if (width == 1)
- gcval->line_width = 0;
+ ctxcanvas->gcval.line_width = 0;
else
- gcval->line_width = width;
+ ctxcanvas->gcval.line_width = width;
- gdk_gc_set_values(ctxcanvas->gc, gcval, GDK_GC_LINE_WIDTH);
+ gdk_gc_set_values(ctxcanvas->gc, &ctxcanvas->gcval, GDK_GC_LINE_WIDTH);
return width;
}
-/* Done! */
static int cdlinecap(cdCtxCanvas *ctxcanvas, int cap)
{
int cd2x_cap[] = {GDK_CAP_BUTT, GDK_CAP_PROJECTING, GDK_CAP_ROUND};
- gcval->cap_style = cd2x_cap[cap];
- gdk_gc_set_values(ctxcanvas->gc, gcval, GDK_GC_CAP_STYLE);
+ ctxcanvas->gcval.cap_style = cd2x_cap[cap];
+ gdk_gc_set_values(ctxcanvas->gc, &ctxcanvas->gcval, GDK_GC_CAP_STYLE);
return cap;
}
-/* Done! */
static int cdlinejoin(cdCtxCanvas *ctxcanvas, int join)
{
int cd2x_join[] = {GDK_JOIN_MITER, GDK_JOIN_BEVEL, GDK_JOIN_ROUND};
- gcval->join_style = cd2x_join[join];
- gdk_gc_set_values(ctxcanvas->gc, gcval, GDK_GC_JOIN_STYLE);
+ ctxcanvas->gcval.join_style = cd2x_join[join];
+ gdk_gc_set_values(ctxcanvas->gc, &ctxcanvas->gcval, GDK_GC_JOIN_STYLE);
return join;
}
-/* Done! */
static int cdbackopacity(cdCtxCanvas *ctxcanvas, int opaque)
{
ctxcanvas->canvas->back_opacity = opaque;
@@ -934,13 +891,10 @@ static int cdbackopacity(cdCtxCanvas *ctxcanvas, int opaque)
return opaque;
}
-/* done! */
static int cdfont(cdCtxCanvas *ctxcanvas, const char *type_face, int style, int size)
{
cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
- cairo_font_face_t *font;
- char font_name[1024];
- char* foundry = "*";
+ cairo_scaled_font_t *font;
cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL; /* default is */
cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL; /* CD_PLAIN */
@@ -953,44 +907,34 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *type_face, int style, int
else if (cdStrEqualNoCase(type_face, "Sans") || cdStrEqualNoCase(type_face, "Arial"))
type_face = "helvetica";
- if (cdStrEqualNoCase(type_face, "Fixed"))
- foundry = "misc";
-
/* no underline or strikeout support */
- if (style&CD_BOLD)
+ if (style & CD_BOLD)
weight = CAIRO_FONT_WEIGHT_BOLD;
- if (style&CD_ITALIC)
+ if (style & CD_ITALIC)
slant = CAIRO_FONT_SLANT_ITALIC;
- if (style&CD_BOLD_ITALIC)
- {
- slant = CAIRO_FONT_SLANT_ITALIC;
- weight = CAIRO_FONT_WEIGHT_BOLD;
- }
-
- size = cdGetFontSizePoints(ctxcanvas->canvas, size);
- size *= 10; /* convert to deci-points */
+ cairo_select_font_face(crWnd, type_face, slant, weight);
+ cairo_set_font_size(crWnd, (double)cdGetFontSizePixels(ctxcanvas->canvas, size));
- sprintf(font_name,"-%s-%s-*-*-*-*-*-*-*-*-*-*-*", foundry, type_face);
-
- font = cairo_toy_font_face_create(font_name, slant, weight);
+ font = cairo_get_scaled_font(crWnd);
if (!font)
return 0;
if (ctxcanvas->font)
- cairo_font_face_destroy(ctxcanvas->font);
+ cairo_scaled_font_destroy(ctxcanvas->font);
+
+ font = cairo_scaled_font_reference(font);
ctxcanvas->font = font;
- cairo_set_font_face(crWnd, ctxcanvas->font);
- cairo_set_font_size(crWnd, size);
+
+ cairo_destroy(crWnd);
return 1;
}
-/* done! */
static int cdnativefont(cdCtxCanvas *ctxcanvas, const char* nativefont)
{
int size = 12, style = CD_PLAIN;
@@ -999,22 +943,28 @@ static int cdnativefont(cdCtxCanvas *ctxcanvas, const char* nativefont)
if (nativefont[0] == '-')
{
- cairo_font_face_t *font = cairo_toy_font_face_create(nativefont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_scaled_font_t *font;
+
+ cairo_select_font_face(crWnd, nativefont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_set_font_size(crWnd, (double)cdGetFontSizePixels(ctxcanvas->canvas, size));
+
+ font = cairo_get_scaled_font(crWnd);
if (!font)
return 0;
if (!cdParseXWinFont(nativefont, type_face, &style, &size))
{
- cairo_font_face_destroy(font);
+ cairo_scaled_font_destroy(font);
return 0;
}
if (ctxcanvas->font)
- cairo_font_face_destroy(font);
-
+ cairo_scaled_font_destroy(ctxcanvas->font);
+
ctxcanvas->font = font;
- cairo_set_font_face(crWnd, ctxcanvas->font);
+
+ cairo_set_scaled_font(crWnd, ctxcanvas->font);
}
else
{
@@ -1030,10 +980,11 @@ static int cdnativefont(cdCtxCanvas *ctxcanvas, const char* nativefont)
ctxcanvas->canvas->font_size = size;
strcpy(ctxcanvas->canvas->font_type_face, type_face);
+ cairo_destroy(crWnd);
+
return 1;
}
-/* done! */
static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, int *ascent, int *descent)
{
cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
@@ -1042,35 +993,38 @@ static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, in
if (!ctxcanvas->font)
return;
- cairo_set_font_face(crWnd, ctxcanvas->font);
+ cairo_set_scaled_font(crWnd, ctxcanvas->font);
cairo_font_extents(crWnd, &extents);
if (max_width) *max_width = (int)extents.max_x_advance;
if (height) *height = (int)extents.height;
if (ascent) *ascent = (int)extents.ascent;
if (descent) *descent = (int)extents.descent;
+
+ cairo_destroy(crWnd);
}
-/* done! */
static long int cdbackground(cdCtxCanvas *ctxcanvas, long int color)
{
- GdkColor clr = cdgdkGetPixel(ctxcanvas, color);
- gdk_gc_set_background(ctxcanvas->gc, &clr);
+ ctxcanvas->bg = cdgdkGetPixel(ctxcanvas, color);
+ gdk_gc_set_rgb_bg_color(ctxcanvas->gc, &ctxcanvas->bg);
return color;
}
-/* done! */
static long int cdforeground(cdCtxCanvas *ctxcanvas, long int color)
{
ctxcanvas->fg = cdgdkGetPixel(ctxcanvas, color);
- gdk_gc_set_foreground(ctxcanvas->gc, &ctxcanvas->fg);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &ctxcanvas->fg);
return color;
}
-/* done! */
static void cdpalette(cdCtxCanvas *ctxcanvas, int n, const long int *palette, int mode)
{
int i;
+ GdkColor *pixels = g_new (GdkColor, 256);
+
+ for(i = 0; i < ctxcanvas->num_colors; i++)
+ pixels[i] = ctxcanvas->color_table[i];
gdk_colormap_free_colors(ctxcanvas->colormap, ctxcanvas->color_table, ctxcanvas->num_colors);
@@ -1096,7 +1050,7 @@ static void cdpalette(cdCtxCanvas *ctxcanvas, int n, const long int *palette, in
gdk_colormap_alloc_colors(gdk_colormap_get_system(), ctxcanvas->color_table, tokeep, FALSE, TRUE, &success);
- /* reserve these colors to the CD use too */
+ /* reserve these colors to use in CD */
for (i=0; i<tokeep; i++)
gdk_colormap_alloc_color(ctxcanvas->colormap, &(ctxcanvas->color_table[i]), FALSE, TRUE);
}
@@ -1131,11 +1085,12 @@ static void cdpalette(cdCtxCanvas *ctxcanvas, int n, const long int *palette, in
for (i = 0; i < n; i++)
cdgdkGetPixel(ctxcanvas, palette[i]);
}
+
+ g_free(pixels);
}
/******************************************************/
-/* done! */
static void cdgdkCheckSolidStyle(cdCtxCanvas *ctxcanvas, int set)
{
if (ctxcanvas->canvas->interior_style == CD_SOLID)
@@ -1147,7 +1102,6 @@ static void cdgdkCheckSolidStyle(cdCtxCanvas *ctxcanvas, int set)
cdinteriorstyle(ctxcanvas, ctxcanvas->canvas->interior_style);
}
-/* done! */
static void cdclear(cdCtxCanvas* ctxcanvas)
{
GdkColor clr;
@@ -1155,17 +1109,16 @@ static void cdclear(cdCtxCanvas* ctxcanvas)
cdgdkCheckSolidStyle(ctxcanvas, 1);
clr = cdgdkGetPixel(ctxcanvas, ctxcanvas->canvas->background);
- gdk_gc_set_foreground(ctxcanvas->gc, &clr);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &clr);
gdk_draw_rectangle(ctxcanvas->wnd, ctxcanvas->gc, TRUE, 0, 0, ctxcanvas->canvas->w, ctxcanvas->canvas->h);
-
+
clr = cdgdkGetPixel(ctxcanvas, ctxcanvas->canvas->foreground);
- gdk_gc_set_foreground(ctxcanvas->gc, &clr);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &clr);
cdgdkCheckSolidStyle(ctxcanvas, 0);
}
-/* done! */
static void cdline(cdCtxCanvas *ctxcanvas, int x1, int y1, int x2, int y2)
{
if (ctxcanvas->canvas->use_matrix)
@@ -1179,7 +1132,6 @@ static void cdline(cdCtxCanvas *ctxcanvas, int x1, int y1, int x2, int y2)
cdgdkCheckSolidStyle(ctxcanvas, 0);
}
-/* Done! */
static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a1, double a2)
{
if (ctxcanvas->canvas->use_matrix)
@@ -1193,7 +1145,6 @@ static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a
cdgdkCheckSolidStyle(ctxcanvas, 0);
}
-/* Done! */
static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a1, double a2)
{
if (ctxcanvas->canvas->use_matrix)
@@ -1216,7 +1167,6 @@ static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doubl
}
}
-/* Done! */
static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a1, double a2)
{
if (ctxcanvas->canvas->new_region)
@@ -1231,7 +1181,6 @@ static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double
}
}
-/* Done! */
static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
if (ctxcanvas->canvas->use_matrix)
@@ -1245,23 +1194,6 @@ static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int yma
cdgdkCheckSolidStyle(ctxcanvas, 0);
}
-static void cdrectCairo(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
-{
- if (ctxcanvas->canvas->use_matrix)
- {
- cdrectSIM(ctxcanvas, xmin, xmax, ymin, ymax);
- return;
- }
-
- cdgdkCheckSolidStyle(ctxcanvas, 1);
- {
- cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
- cairo_rectangle(crWnd, (double)xmin, (double)ymin, (double)(xmax-xmin), (double)(ymax-ymin));
- }
- cdgdkCheckSolidStyle(ctxcanvas, 0);
-}
-
-/* Done! */
static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
if (ctxcanvas->canvas->use_matrix)
@@ -1280,34 +1212,42 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax
gdk_draw_rectangle(ctxcanvas->wnd, ctxcanvas->gc, TRUE, xmin, ymin, xmax-xmin+1, ymax-ymin+1);
}
-/* done! */
static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
- int dir = -1;
- cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
- cairo_t* crWndAux = gdk_cairo_create((GdkDrawable*)ctxcanvas->region_aux);
- cairo_matrix_t matrix;
+ cairo_t *crWnd;
cairo_text_extents_t extents;
cairo_font_extents_t font_extents;
+ const char *utf8_text;
+
+ int dir = -1;
+ int x_origin = x;
+ int y_origin = y;
- cairo_set_font_face(crWnd, ctxcanvas->font);
- cairo_font_extents(crWnd, &font_extents);
+ if (!ctxcanvas->canvas->new_region)
+ crWnd = gdk_cairo_create(ctxcanvas->wnd);
+ else
+ crWnd = gdk_cairo_create((GdkDrawable*)ctxcanvas->region_aux);
- cairo_text_extents (crWnd, s, &extents);
+ utf8_text = g_locale_to_utf8(s, len, NULL, 0, NULL);
+ cairo_set_scaled_font(crWnd, ctxcanvas->font);
+
+ cairo_font_extents(crWnd, &font_extents);
+ cairo_text_extents(crWnd, utf8_text, &extents);
+
switch (ctxcanvas->canvas->text_alignment)
{
case CD_BASE_RIGHT:
case CD_NORTH_EAST:
case CD_EAST:
case CD_SOUTH_EAST:
- x = x - (int)extents.width;
+ x = x - (int)extents.width;
break;
case CD_BASE_CENTER:
case CD_CENTER:
case CD_NORTH:
case CD_SOUTH:
- x = x - (int)extents.width/2;
+ x = x - (int)(extents.width/2);
break;
case CD_BASE_LEFT:
case CD_NORTH_WEST:
@@ -1335,51 +1275,33 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
case CD_NORTH_EAST:
case CD_NORTH:
case CD_NORTH_WEST:
- y = y + dir*((int)extents.height - (int)font_extents.descent);
+ y = y + dir*(int)(extents.height - font_extents.descent);
break;
case CD_CENTER:
case CD_EAST:
case CD_WEST:
- y = y + dir*((int)extents.height/2 - (int)font_extents.descent);
+ y = y + dir*(int)(extents.height/2 - font_extents.descent);
break;
}
if (ctxcanvas->canvas->text_orientation != 0)
{
- cdgdkCheckSolidStyle(ctxcanvas, 1);
+ cairo_matrix_t matrix;
- if (ctxcanvas->canvas->use_matrix)
- cdMatrixTransformPoint(ctxcanvas->xmatrix, x, y, &x, &y);
-
- if (ctxcanvas->canvas->new_region)
- {
- sPrepareRegion(ctxcanvas);
+ cairo_translate(crWnd, (double)x_origin, (double)y_origin);
+ cairo_get_matrix(crWnd, &matrix);
- cairo_get_matrix(crWndAux, &matrix);
+ x -= ctxcanvas->canvas->w/2;
+ y -= ctxcanvas->canvas->h/2;
- cairo_set_font_face(crWndAux, ctxcanvas->font);
- cairo_move_to(crWndAux, (double)x, (double)(y));
- cairo_rotate(crWndAux, ctxcanvas->canvas->text_orientation * (M_PI/180));
- cairo_show_text(crWndAux, s);
- cairo_set_matrix(crWndAux, &matrix);
+ cairo_matrix_rotate(&matrix, -ctxcanvas->canvas->text_orientation*CD_DEG2RAD);
+ cairo_matrix_translate(&matrix, (double)x, (double)y);
- sCombineRegion(ctxcanvas);
- }
- else
- {
- cairo_get_matrix(crWnd, &matrix);
-
- cairo_set_font_face(crWnd, ctxcanvas->font);
- cairo_move_to(crWnd, (double)x, (double)(y));
- cairo_rotate(crWnd, ctxcanvas->canvas->text_orientation * (M_PI/180));
- cairo_show_text(crWnd, s);
-
- cairo_set_matrix(crWnd, &matrix);
- }
-
- cdgdkCheckSolidStyle(ctxcanvas, 0);
-
- return;
+ cairo_set_matrix(crWnd, &matrix);
+ }
+ else
+ {
+ cairo_move_to(crWnd, (double)x, (double)y);
}
cdgdkCheckSolidStyle(ctxcanvas, 1);
@@ -1391,33 +1313,35 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
sPrepareRegion(ctxcanvas);
- cairo_set_font_face(crWndAux, ctxcanvas->font);
- cairo_move_to(crWndAux, (double)x, (double)(y+1));
- cairo_show_text(crWndAux, s);
+ cairo_set_source_rgb(crWnd, 1.0, 1.0, 1.0);
+ cairo_show_text(crWnd, utf8_text);
sCombineRegion(ctxcanvas);
}
else
{
- cairo_move_to(crWnd, (double)x, (double)(y+1));
- cairo_show_text(crWnd, s);
+ cairo_set_source_rgb(crWnd, ctxcanvas->fg.red/255, ctxcanvas->fg.green/255, ctxcanvas->fg.blue/255);
+ cairo_show_text(crWnd, utf8_text);
}
cdgdkCheckSolidStyle(ctxcanvas, 0);
- (void)len;
+ cairo_destroy(crWnd);
}
-/* Done! */
static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *s, int len, int *width, int *height)
{
cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
cairo_text_extents_t extents;
+ const char *utf8_text;
if (!ctxcanvas->font)
return;
- cairo_text_extents(crWnd, s, &extents);
+ utf8_text = g_locale_to_utf8(s, len, NULL, 0, NULL);
+
+ cairo_set_scaled_font(crWnd, ctxcanvas->font);
+ cairo_text_extents(crWnd, utf8_text, &extents);
if (width)
*width = (int)extents.width;
@@ -1425,87 +1349,88 @@ static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *s, int len, int *w
if (height)
*height = (int)extents.height;
- (void)len;
+ cairo_destroy(crWnd);
}
-/* Done! */
void cdgdkPoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
{
- int i;
- GdkPoint *pnt = NULL;
-
- if (mode != CD_BEZIER)
- {
- for (i = 0; i < n; i++)
- {
- int x = poly[i].x,
- y = poly[i].y;
+ int i;
+ GdkPoint* pnt;
- if (ctxcanvas->canvas->use_matrix)
- cdMatrixTransformPoint(ctxcanvas->xmatrix, x, y, &x, &y);
-
- pnt[i].x = (short)x;
- pnt[i].y = (short)y;
- }
- }
+ pnt = g_new (GdkPoint, n);
- switch( mode )
- {
- case CD_FILL:
- if (ctxcanvas->canvas->new_region)
- {
- sPrepareRegion(ctxcanvas);
- gdk_region_polygon(pnt, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
- gdk_draw_polygon(ctxcanvas->region_aux, ctxcanvas->region_aux_gc, TRUE, pnt, n);
- sCombineRegion(ctxcanvas);
- }
- else
- {
- gdk_region_polygon(pnt, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
- gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, pnt, n);
- }
- break;
-
- case CD_CLOSED_LINES:
- pnt[n].x = pnt[0].x;
- pnt[n].y = pnt[0].y;
- n++;
- /* continue... */
-
- case CD_OPEN_LINES:
- {
- cdgdkCheckSolidStyle(ctxcanvas, 1);
- gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, pnt, n);
- cdgdkCheckSolidStyle(ctxcanvas, 0);
- break;
- }
-
- case CD_CLIP:
- if (ctxcanvas->clip_polygon)
- g_object_unref(ctxcanvas->clip_polygon);
-
- ctxcanvas->clip_polygon = build_clip_polygon(ctxcanvas, pnt, n);
-
- if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON)
- cdgdkClip(ctxcanvas, CD_CLIPPOLYGON);
-
- break;
-
- case CD_BEZIER:
- cdSimPolyBezier(ctxcanvas->canvas, poly, n);
- break;
- }
+ if(!pnt)
+ return;
- g_object_unref(pnt);
+ if (mode != CD_BEZIER)
+ {
+ for (i = 0; i < n; i++)
+ {
+ int x = poly[i].x,
+ y = poly[i].y;
+
+ if (ctxcanvas->canvas->use_matrix)
+ cdMatrixTransformPoint(ctxcanvas->xmatrix, x, y, &x, &y);
+
+ pnt[i].x = (short)x;
+ pnt[i].y = (short)y;
+ }
+ }
+
+ switch( mode )
+ {
+ case CD_FILL:
+ if (ctxcanvas->canvas->new_region)
+ {
+ sPrepareRegion(ctxcanvas);
+ gdk_region_polygon(pnt, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
+ gdk_draw_polygon(ctxcanvas->region_aux, ctxcanvas->region_aux_gc, TRUE, pnt, n);
+ sCombineRegion(ctxcanvas);
+ }
+ else
+ {
+ gdk_region_polygon(pnt, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
+ gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, pnt, n);
+ }
+ break;
+
+ case CD_CLOSED_LINES:
+ cdgdkCheckSolidStyle(ctxcanvas, 1);
+ gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, pnt, n);
+ cdgdkCheckSolidStyle(ctxcanvas, 0);
+ break;
+
+ case CD_OPEN_LINES:
+ cdgdkCheckSolidStyle(ctxcanvas, 1);
+ gdk_draw_lines(ctxcanvas->wnd, ctxcanvas->gc, pnt, n);
+ cdgdkCheckSolidStyle(ctxcanvas, 0);
+ break;
+
+ case CD_CLIP:
+ if (ctxcanvas->clip_polygon)
+ g_object_unref(ctxcanvas->clip_polygon);
+
+ ctxcanvas->clip_polygon = build_clip_polygon(ctxcanvas, pnt, n);
+
+ if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON)
+ cdgdkClip(ctxcanvas, CD_CLIPPOLYGON);
+
+ break;
+
+ case CD_BEZIER:
+ cdSimPolyBezier(ctxcanvas->canvas, poly, n);
+ break;
+ }
+
+ g_free(pnt);
}
/******************************************************/
-/* done! */
static void cdgetimagergb(cdCtxCanvas *ctxcanvas, unsigned char *r, unsigned char *g, unsigned char *b, int x, int y, int w, int h)
{
int col, lin, pos;
- GdkImage* xi = gdk_drawable_get_image(ctxcanvas->wnd, x, y-h+1, w, h); // ULONG_MAX, ZPixmap);
+ GdkImage* xi = gdk_drawable_get_image(ctxcanvas->wnd, x, y-h+1, w, h);
if (!xi)
{
fprintf(stderr, "CanvasDraw: error getting image\n");
@@ -1524,7 +1449,6 @@ static void cdgetimagergb(cdCtxCanvas *ctxcanvas, unsigned char *r, unsigned cha
g_object_unref(xi);
}
-/* done */
static long int* get_data_buffer(cdCtxCanvas *ctxcanvas, int size)
{
if (!ctxcanvas->xidata)
@@ -1544,7 +1468,6 @@ static long int* get_data_buffer(cdCtxCanvas *ctxcanvas, int size)
return ctxcanvas->xidata;
}
-/* done! */
static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsigned char *index, const long int * colors, int by, int bx, int bw, int bh, int iw)
{
GdkColor** match_table = NULL;
@@ -1622,13 +1545,9 @@ static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsi
if(xim)
{
- /* Conferir estes valores, ver se na hora da criação já não são eles próprios... */
xim->depth = (short)ctxcanvas->depth;
xim->bpp = 32;
xim->bpl = (short)imew;
- // format = ZPixmap
- // offset = 0;
- // data = (char *)imagedata
}
}
break;
@@ -1658,13 +1577,9 @@ static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsi
if(xim)
{
- /* Conferir estes valores, ver se na hora da criação já não são eles próprios... */
xim->depth = (short)ctxcanvas->depth;
xim->bpp = 16;
xim->bpl = 0;
- // format = ZPixmap
- // offset = 0;
- // data = (char *)imagedata
}
if (ctxcanvas->depth == 12 && xim->bits_per_pixel != 16)
@@ -1723,13 +1638,9 @@ static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsi
if(xim)
{
- /* Conferir estes valores, ver se na hora da criação já não são eles próprios... */
xim->depth = (short)ctxcanvas->depth;
xim->bpp = 32;
xim->bpl = 0;
- // format = ZPixmap
- // offset = 0;
- // data = (char *)imagedata
}
do32 = (xim->bits_per_pixel == 32 ? 1 : 0);
@@ -1783,13 +1694,9 @@ static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsi
if(xim)
{
- /* Conferir estes valores, ver se na hora da criação já não são eles próprios... */
xim->depth = (short)ctxcanvas->depth;
xim->bpp = 32;
xim->bpl = (short)ew*4;
- // format = ZPixmap
- // offset = 0;
- // data = (char *)imagedata
}
xim->bits_per_pixel = 32;
@@ -1815,27 +1722,22 @@ static GdkImage *map2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh, const unsi
return(xim);
}
-/* done! */
static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
const unsigned char *red, const unsigned char *green, const unsigned char *blue,
const unsigned char *alpha, GdkImage *oxi,
int by, int bx, int bw, int bh, int iw)
{
-/*
-* if we're displaying on a TrueColor
-* or DirectColor display, we've got all the colors we're going to need,
-* and 'all we have to do' is convert 24-bit RGB pixels into whatever
-* variation of RGB the X device in question wants. No color allocation
-* is involved.
-*/
- int i,j;
+/* if we're displaying on a TrueColor or DirectColor display, we've got all the colors we're going to need,
+ * and 'all we have to do' is convert 24-bit RGB pixels into whatever variation of RGB the X device in
+ * question wants. No color allocation is involved.
+ */
GdkImage *xim;
+ int *fx, *fy;
+ int i, j, maplen, src;
+ int rshift, gshift, bshift, bperpix, bperline, byte_order, cshift;
unsigned long r, g, b, rmask, gmask, bmask, xcol;
- int rshift, gshift, bshift, bperpix, bperline, byte_order, cshift;
- int maplen, src;
unsigned char *lip, *ip, *imagedata, or, ob, og, al;
- int *fx, *fy;
-
+
/* compute various shifting constants that we'll need... */
rmask = ctxcanvas->vis->red_mask;
gmask = ctxcanvas->vis->green_mask;
@@ -1843,12 +1745,12 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
rshift = 7 - highbit(rmask);
gshift = 7 - highbit(gmask);
bshift = 7 - highbit(bmask);
-
- maplen = ctxcanvas->vis->colormap_size;
+ maplen = ctxcanvas->vis->colormap_size;
+
if (maplen > 256)
maplen = 256;
-
+
cshift = 7 - highbit((unsigned long) (maplen-1));
xim = gdk_image_new(GDK_IMAGE_FASTEST, ctxcanvas->vis, ew, eh);
@@ -1859,21 +1761,9 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
return NULL;
}
- if(xim)
- {
- /* Conferir estes valores, ver se na hora da criação já não são eles próprios... */
- xim->depth = (short)ctxcanvas->depth;
- xim->bpp = 32;
- xim->bpl = 0;
- // format = ZPixmap
- // offset = 0;
- // data = NULL
- }
-
-
- bperline = xim->bpl;
- bperpix = xim->bits_per_pixel;
- byte_order = xim->byte_order;
+ bperline = xim->bpl;
+ bperpix = xim->bits_per_pixel;
+ byte_order = xim->byte_order;
if (bperpix != 8 && bperpix != 16 && bperpix != 24 && bperpix != 32)
{
@@ -1893,11 +1783,11 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
fx = cdGetZoomTable(ew, bw, bx);
fy = cdGetZoomTable(eh, bh, by);
- lip = imagedata + (eh-1)*bperline;
+ lip = imagedata + (eh - 1) * bperline;
- for (i=0; i<eh; i++, lip -= bperline)
+ for (i = 0; i < eh; i++, lip -= bperline)
{
- for (j=0, ip=lip; j<ew; j++)
+ for (j = 0, ip = lip; j < ew; j++)
{
src = fy[i]*iw + fx[j];
@@ -1916,11 +1806,9 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
b = blue[src];
}
- /* shift r,g,b so that high bit of 8-bit color specification is
- * aligned with high bit of r,g,b-mask in visual,
- * AND each component with its mask,
- * and OR the three components together
- */
+ /* shift r, g, b so that high bit of 8-bit color specification is aligned with
+ * high bit of r, g, b-mask in visual, AND each component with its mask, and
+ * OR the three components together */
if(gdk_visual_get_best_type() == GDK_VISUAL_DIRECT_COLOR)
{
r = (unsigned long) cdgdkDirectColorTable[(r>>cshift) & 0xff] << cshift;
@@ -1929,14 +1817,20 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
}
/* shift the bits around */
- if (rshift < 0) r = r << (-rshift);
- else r = r >> rshift;
+ if (rshift < 0)
+ r = r << (-rshift);
+ else
+ r = r >> rshift;
- if (gshift < 0) g = g << (-gshift);
- else g = g >> gshift;
+ if (gshift < 0)
+ g = g << (-gshift);
+ else
+ g = g >> gshift;
- if (bshift < 0) b = b << (-bshift);
- else b = b >> bshift;
+ if (bshift < 0)
+ b = b << (-bshift);
+ else
+ b = b >> bshift;
r = r & rmask;
g = g & gmask;
@@ -1994,14 +1888,16 @@ static GdkImage *rgb2gdkImage(cdCtxCanvas *ctxcanvas, int ew, int eh,
}
}
}
-
+
+ /* Copy imagedata to GdkImage */
+ memcpy (xim->mem, imagedata, eh * bperline);
+
free(fx);
free(fy);
return xim;
}
-/* done! */
static void cdputimagerectrgba_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
int t_xmin, t_xmax, t_ymin, t_ymax, ew, eh,
@@ -2058,7 +1954,7 @@ static void cdputimagerectrgba_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, co
ey = t_ymin + eh-1; /* gdkImage origin is at top-left */
GdkImage *xi, *oxi = NULL;
GdkPixmap *clip_polygon, *clip_mask = NULL;
- GdkPoint* pnt = NULL;
+ GdkPoint* pnt = g_malloc(64);
/* Since the transformation used was the original transformation, */
/* must invert the Y axis here. */
@@ -2089,7 +1985,7 @@ static void cdputimagerectrgba_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, co
if (a)
{
- oxi = gdk_drawable_get_image(ctxcanvas->wnd, ex, ey, ew, eh); // ULONG_MAX, ZPixmap);
+ oxi = gdk_drawable_get_image(ctxcanvas->wnd, ex, ey, ew, eh);
if (!oxi)
{
@@ -2112,12 +2008,13 @@ static void cdputimagerectrgba_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, co
g_object_unref(xi);
if (oxi)
g_object_unref(oxi);
+
+ g_free(pnt);
}
free(dst_r);
}
-/* done! */
static void cdputimagerectmap_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
int t_xmin, t_xmax, t_ymin, t_ymax, ew, eh,
@@ -2189,8 +2086,8 @@ static void cdputimagerectmap_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, con
gdk_gc_set_function(ctxcanvas->gc, GDK_AND);
gdk_draw_drawable((GdkDrawable*)clip_polygon, ctxcanvas->gc,
- (GdkDrawable*)clip_mask, 0, 0, 0, 0,
- ctxcanvas->canvas->w, ctxcanvas->canvas->h);
+ (GdkDrawable*)clip_mask, 0, 0, 0, 0,
+ ctxcanvas->canvas->w, ctxcanvas->canvas->h);
gdk_gc_set_clip_mask(ctxcanvas->gc, (GdkBitmap*)clip_polygon);
@@ -2212,7 +2109,6 @@ static void cdputimagerectmap_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, con
free(dst_index);
}
-/* done! */
static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
int ew = w, eh = h, ex = x, ey = y;
@@ -2245,7 +2141,6 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi
g_object_unref(xi);
}
-/* done! */
static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
GdkImage *xi, *oxi;
@@ -2269,7 +2164,7 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns
if (!cdCalcZoom(ctxcanvas->canvas->h, y, h, &ey, &eh, ymin, rh, &by, &bh, 0))
return;
- oxi = gdk_drawable_get_image(ctxcanvas->wnd, ex, ey, ew, eh); // ULONG_MAX, ZPixmap);
+ oxi = gdk_drawable_get_image(ctxcanvas->wnd, ex, ey, ew, eh);
if (!oxi)
{
@@ -2287,7 +2182,6 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns
g_object_unref(oxi);
}
-/* done! */
static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
int ew = w, eh = h, ex = x, ey = y;
@@ -2320,13 +2214,12 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi
g_object_unref(xi);
}
-/* done! */
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
if (ctxcanvas->canvas->foreground != color)
{
GdkColor clr = cdgdkGetPixel(ctxcanvas, color);
- gdk_gc_set_foreground(ctxcanvas->gc, &clr);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &clr);
}
if (ctxcanvas->canvas->use_matrix)
@@ -2336,10 +2229,9 @@ static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
gdk_draw_point(ctxcanvas->wnd, ctxcanvas->gc, x, y);
if (ctxcanvas->canvas->foreground != color)
- gdk_gc_set_foreground(ctxcanvas->gc, &ctxcanvas->fg);
+ gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &ctxcanvas->fg);
}
-/* done! */
static cdCtxImage *cdcreateimage (cdCtxCanvas *ctxcanvas, int w, int h)
{
GdkGC* gc;
@@ -2364,7 +2256,7 @@ static cdCtxImage *cdcreateimage (cdCtxCanvas *ctxcanvas, int w, int h)
clr = cdgdkGetPixel(ctxcanvas, CD_WHITE);
- gdk_gc_set_foreground(gc, &clr);
+ gdk_gc_set_rgb_fg_color(gc, &clr);
gdk_draw_rectangle(ctximage->img, gc, TRUE, 0, 0, ctximage->w, ctxcanvas->canvas->h);
g_object_unref(gc);
@@ -2372,7 +2264,6 @@ static cdCtxImage *cdcreateimage (cdCtxCanvas *ctxcanvas, int w, int h)
return (void*)ctximage;
}
-/* done! */
static void cdgetimage (cdCtxCanvas *ctxcanvas, cdCtxImage *ctximage, int x, int y)
{
gdk_draw_drawable(ctximage->img, ctxcanvas->gc,
@@ -2380,7 +2271,6 @@ static void cdgetimage (cdCtxCanvas *ctxcanvas, cdCtxImage *ctximage, int x, int
ctximage->w, ctximage->h);
}
-/* done! */
static void cdputimagerect (cdCtxCanvas *ctxcanvas, cdCtxImage *ctximage, int x, int y, int xmin, int xmax, int ymin, int ymax)
{
gdk_draw_drawable(ctxcanvas->wnd, ctxcanvas->gc,
@@ -2388,14 +2278,12 @@ static void cdputimagerect (cdCtxCanvas *ctxcanvas, cdCtxImage *ctximage, int x,
xmax-xmin+1, ymax-ymin+1);
}
-/* done! */
static void cdkillimage (cdCtxImage *ctximage)
{
g_object_unref(ctximage->img);
free(ctximage);
}
-/* done! */
static void cdscrollarea (cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax, int dx, int dy)
{
gdk_draw_drawable(ctxcanvas->wnd, ctxcanvas->gc,
@@ -2403,7 +2291,6 @@ static void cdscrollarea (cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin,
xmax-xmin+1, ymax-ymin+1);
}
-/* done! */
static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix)
{
if (matrix)
@@ -2482,6 +2369,58 @@ static cdAttribute gc_attrib =
get_gc_attrib
};
+static void set_aa_attrib(cdCtxCanvas* ctxcanvas, char* data)
+{
+ cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
+ cairo_font_options_t *crOptions = cairo_font_options_create();
+
+ cairo_scaled_font_get_font_options (ctxcanvas->font, crOptions);
+
+ if (!data || data[0] == '0')
+ {
+ cairo_set_antialias(crWnd, CAIRO_ANTIALIAS_NONE);
+ cairo_font_options_set_antialias(crOptions, CAIRO_ANTIALIAS_NONE);
+ }
+ else
+ {
+ cairo_set_antialias(crWnd, CAIRO_ANTIALIAS_DEFAULT);
+ cairo_font_options_set_antialias(crOptions, CAIRO_ANTIALIAS_DEFAULT);
+ }
+
+ cairo_font_options_destroy(crOptions);
+ cairo_destroy(crWnd);
+}
+
+static char* get_aa_attrib(cdCtxCanvas* ctxcanvas)
+{
+ cairo_t* crWnd = gdk_cairo_create(ctxcanvas->wnd);
+
+ if(cairo_get_antialias(crWnd) == CAIRO_ANTIALIAS_DEFAULT)
+ return "1";
+ else
+ return "0";
+}
+
+static cdAttribute aa_attrib =
+{
+ "ANTIALIAS",
+ set_aa_attrib,
+ get_aa_attrib
+};
+
+static char* get_version_attrib(cdCtxCanvas* ctxcanvas)
+{
+ (void)ctxcanvas;
+ return (char*)cairo_version_string();
+}
+
+static cdAttribute version_attrib =
+{
+ "CAIROVERSION",
+ NULL,
+ get_version_attrib
+};
+
cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* scr, GdkVisual* vis)
{
static int first = 1;
@@ -2501,6 +2440,8 @@ cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* sc
return NULL;
}
+ gdk_gc_set_colormap(ctxcanvas->gc, gdk_screen_get_default_colormap(ctxcanvas->scr));
+
ctxcanvas->canvas = canvas;
canvas->ctxcanvas = ctxcanvas;
@@ -2509,7 +2450,7 @@ cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* sc
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(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;
@@ -2559,13 +2500,15 @@ cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* sc
cdRegisterAttribute(canvas, &gc_attrib);
cdRegisterAttribute(canvas, &rotate_attrib);
+ cdRegisterAttribute(canvas, &aa_attrib);
+ cdRegisterAttribute(canvas, &version_attrib);
first = 0;
return ctxcanvas;
}
-void cdxInitTable(cdCanvas* canvas)
+void cdgdkInitTable(cdCanvas* canvas)
{
canvas->cxFlush = cdflush;
canvas->cxClear = cdclear;
@@ -2574,7 +2517,6 @@ void cdxInitTable(cdCanvas* canvas)
canvas->cxLine = cdline;
canvas->cxPoly = cdgdkPoly;
canvas->cxRect = cdrect;
-// canvas->cxRect = cdrectCairo;
canvas->cxBox = cdbox;
canvas->cxArc = cdarc;
canvas->cxSector = cdsector;
@@ -2620,12 +2562,3 @@ void cdxInitTable(cdCanvas* canvas)
if (canvas->bpp > 8)
canvas->cxPutImageRectRGBA = cdputimagerectrgba;
}
-
-/*
-- ver como ficará o desenho do chord (já que não tem no GDK e Cairo)
-- no final, ir convertendo o que der para Cairo
-- conferir funcionamento do gdk_gc_new
-- text e font = ver o comportamento
-- ver como funfa gdk_drawable_get_image // XPixmap, YPixmap, ZPixmap
-- conferir funções que usam gdk_image_new
-*/ \ No newline at end of file