summaryrefslogtreecommitdiff
path: root/cd/src/gdk
diff options
context:
space:
mode:
Diffstat (limited to 'cd/src/gdk')
-rw-r--r--cd/src/gdk/cdgdk.c196
-rw-r--r--cd/src/gdk/cdgdk.h2
-rw-r--r--cd/src/gdk/cdgdkclp.c2
-rw-r--r--cd/src/gdk/cdgdkdbuf.c3
-rw-r--r--cd/src/gdk/cdgdkimg.c2
-rw-r--r--cd/src/gdk/cdgdknative.c2
6 files changed, 91 insertions, 116 deletions
diff --git a/cd/src/gdk/cdgdk.c b/cd/src/gdk/cdgdk.c
index b0c8ea8..dfffef1 100644
--- a/cd/src/gdk/cdgdk.c
+++ b/cd/src/gdk/cdgdk.c
@@ -12,8 +12,6 @@
#include "cdgdk.h"
-#include <gdk/gdk.h>
-
#define NUM_HATCHES 6
#define HATCH_WIDTH 8
#define HATCH_HEIGHT 8
@@ -35,7 +33,7 @@ static char hatches[NUM_HATCHES][8] = {
/******************************************************/
-static int gdkStrIsAscii(const char* str)
+static int sStrIsAscii(const char* str)
{
while(*str)
{
@@ -47,12 +45,12 @@ static int gdkStrIsAscii(const char* str)
return 1;
}
-static char* gdkStrToUTF8(const char *str, const char* charset, int length)
+static char* sStrToUTF8(const char *str, const char* charset, int length)
{
return g_convert(str, length, "UTF-8", charset, NULL, NULL, NULL);
}
-char* cdgdkStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, int length) /* From CD to GTK/GDK */
+static char* sStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, int length) /* From CD to GDK */
{
const char *charset = NULL;
@@ -67,28 +65,28 @@ char* cdgdkStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, int length)
}
else
{
- ctxcanvas->gdkLastConvertUTF8 = gdkStrToUTF8(str, "ISO8859-1", length); /* if string is not UTF-8, assume ISO8859-1 */
+ ctxcanvas->strLastConvertUTF8 = sStrToUTF8(str, "ISO8859-1", length); /* if string is not UTF-8, assume ISO8859-1 */
- if (!ctxcanvas->gdkLastConvertUTF8)
+ if (!ctxcanvas->strLastConvertUTF8)
return (char*)str;
- return ctxcanvas->gdkLastConvertUTF8;
+ return ctxcanvas->strLastConvertUTF8;
}
}
else
{
- if (gdkStrIsAscii(str) || !charset)
+ if (sStrIsAscii(str) || !charset)
{
return (char*)str;
}
else if (charset)
{
- ctxcanvas->gdkLastConvertUTF8 = gdkStrToUTF8(str, charset, length);
+ ctxcanvas->strLastConvertUTF8 = sStrToUTF8(str, charset, length);
- if (!ctxcanvas->gdkLastConvertUTF8)
+ if (!ctxcanvas->strLastConvertUTF8)
return (char*)str;
- return ctxcanvas->gdkLastConvertUTF8;
+ return ctxcanvas->strLastConvertUTF8;
}
}
return (char*)str;
@@ -136,6 +134,9 @@ void cdgdkKillCanvas(cdCtxCanvas *ctxcanvas)
g_object_unref(ctxcanvas->last_stipple);
}
+ if (ctxcanvas->strLastConvertUTF8)
+ g_free(ctxcanvas->strLastConvertUTF8);
+
g_object_unref(ctxcanvas->gc);
free(ctxcanvas);
@@ -532,23 +533,21 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int s
if (style & CD_STRIKEOUT)
is_strikeout = 1;
- if (size < 0)
- {
- double res = ((double)gdk_screen_get_width(gdk_screen_get_default()) /
- (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */
-
- /* 1 point = 1/72 inch 1 inch = 25.4 mm */
- /* pixel = ((point/72)*25.4)*pixel/mm */
- size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */
- }
+ size = cdGetFontSizePoints(ctxcanvas->canvas, size);
sprintf(font, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size);
+ if (ctxcanvas->fontdesc)
+ pango_font_description_free(ctxcanvas->fontdesc);
+
ctxcanvas->fontdesc = pango_font_description_from_string(font);
if (!ctxcanvas->fontdesc)
return 0;
+ if (ctxcanvas->fontlayout)
+ g_object_unref(ctxcanvas->fontlayout);
+
ctxcanvas->fontlayout = pango_layout_new(ctxcanvas->fontcontext);
pango_layout_set_font_description(ctxcanvas->fontlayout, ctxcanvas->fontdesc);
@@ -562,28 +561,6 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int s
return 1;
}
-static int cdnativefont(cdCtxCanvas *ctxcanvas, const char* nativefont)
-{
- int size = 12, style = CD_PLAIN;
- char typeface[1024];
-
- /* parse the old Windows format first */
- if (!cdParseIupWinFont(nativefont, typeface, &style, &size))
- if (!cdParseXWinFont(nativefont, typeface, &style, &size))
- if (!cdParsePangoFont(nativefont, typeface, &style, &size))
- return 0;
-
- if (!cdfont(ctxcanvas, typeface, style, size))
- return 0;
-
- /* update cdfont parameters */
- ctxcanvas->canvas->font_style = style;
- ctxcanvas->canvas->font_size = size;
- strcpy(ctxcanvas->canvas->font_type_face, typeface);
-
- return 1;
-}
-
static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, int *ascent, int *descent)
{
PangoFontMetrics* metrics;
@@ -712,10 +689,12 @@ static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a
{
if (ctxcanvas->canvas->use_matrix)
{
- cdarcSIM(ctxcanvas, xc, yc, w, h, a1, a2);
+ cdSimArc(ctxcanvas, xc, yc, w, h, a1, a2);
return;
}
+ /* angles in 1/64ths of degrees counterclockwise, similar to CD */
+
cdgdkCheckSolidStyle(ctxcanvas, 1);
gdk_draw_arc(ctxcanvas->wnd, ctxcanvas->gc, FALSE, xc-w/2, yc-h/2, w, h, cdRound(a1*64), cdRound((a2 - a1)*64));
cdgdkCheckSolidStyle(ctxcanvas, 0);
@@ -725,13 +704,13 @@ static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doubl
{
if (ctxcanvas->canvas->use_matrix)
{
- cdsectorSIM(ctxcanvas, xc, yc, w, h, a1, a2);
+ cdSimSector(ctxcanvas, xc, yc, w, h, a1, a2);
return;
}
if (ctxcanvas->canvas->new_region)
{
- cdsectorSIM(ctxcanvas, xc, yc, w, h, a1, a2);
+ cdSimSector(ctxcanvas, xc, yc, w, h, a1, a2);
}
else
{
@@ -744,7 +723,7 @@ static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int yma
{
if (ctxcanvas->canvas->use_matrix)
{
- cdrectSIM(ctxcanvas, xmin, xmax, ymin, ymax);
+ cdSimRect(ctxcanvas, xmin, xmax, ymin, ymax);
return;
}
@@ -757,7 +736,7 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax
{
if (ctxcanvas->canvas->use_matrix)
{
- cdboxSIM(ctxcanvas, xmin, xmax, ymin, ymax);
+ cdSimBox(ctxcanvas, xmin, xmax, ymin, ymax);
return;
}
@@ -782,8 +761,7 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
int w, h, desc, dir = -1;
int ox = x, oy = y;
- ctxcanvas->gdkLastConvertUTF8 = cdgdkStrConvertToUTF8(ctxcanvas, s, len);
- pango_layout_set_text(ctxcanvas->fontlayout, ctxcanvas->gdkLastConvertUTF8, -1);
+ pango_layout_set_text(ctxcanvas->fontlayout, sStrConvertToUTF8(ctxcanvas, s, len), -1);
pango_layout_get_pixel_size(ctxcanvas->fontlayout, &w, &h);
metrics = pango_context_get_metrics(ctxcanvas->fontcontext, ctxcanvas->fontdesc, pango_context_get_language(ctxcanvas->fontcontext));
@@ -903,58 +881,61 @@ static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *s, int len, int *w
if (!ctxcanvas->fontlayout)
return;
- ctxcanvas->gdkLastConvertUTF8 = cdgdkStrConvertToUTF8(ctxcanvas, s, len);
- pango_layout_set_text(ctxcanvas->fontlayout, ctxcanvas->gdkLastConvertUTF8, -1);
+ pango_layout_set_text(ctxcanvas->fontlayout, sStrConvertToUTF8(ctxcanvas, s, len), len);
pango_layout_get_pixel_size(ctxcanvas->fontlayout, width, height);
}
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
{
- int i;
+ int i;
- if (mode != CD_BEZIER)
- {
- for (i = 0; i < n; i++)
- {
- if (ctxcanvas->canvas->use_matrix)
- cdMatrixTransformPoint(ctxcanvas->xmatrix, poly[i].x, poly[i].y, &(poly[i].x), &(poly[i].y));
- }
- }
-
- switch( mode )
- {
- case CD_FILL:
- if (ctxcanvas->canvas->new_region)
- {
- GdkRegion* rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
- sCombineRegion(ctxcanvas, rgn);
- }
- else
- gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, (GdkPoint*)poly, n);
- break;
-
- case CD_CLOSED_LINES:
- cdgdkCheckSolidStyle(ctxcanvas, 1);
- gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, (GdkPoint*)poly, n);
- cdgdkCheckSolidStyle(ctxcanvas, 0);
- break;
-
- case CD_OPEN_LINES:
- cdgdkCheckSolidStyle(ctxcanvas, 1);
- gdk_draw_lines(ctxcanvas->wnd, ctxcanvas->gc, (GdkPoint*)poly, n);
- cdgdkCheckSolidStyle(ctxcanvas, 0);
- break;
-
- case CD_CLIP:
- ctxcanvas->clip_rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
- if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON)
- cdclip(ctxcanvas, CD_CLIPPOLYGON);
- break;
-
- case CD_BEZIER:
- cdSimPolyBezier(ctxcanvas->canvas, poly, n);
- break;
- }
+ if (mode != CD_BEZIER && mode != CD_PATH)
+ {
+ for (i = 0; i < n; i++)
+ {
+ if (ctxcanvas->canvas->use_matrix)
+ cdMatrixTransformPoint(ctxcanvas->xmatrix, poly[i].x, poly[i].y, &(poly[i].x), &(poly[i].y));
+ }
+ }
+
+ switch( mode )
+ {
+ case CD_FILL:
+ if (ctxcanvas->canvas->new_region)
+ {
+ GdkRegion* rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
+ sCombineRegion(ctxcanvas, rgn);
+ }
+ else
+ gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, (GdkPoint*)poly, n);
+ break;
+
+ case CD_CLOSED_LINES:
+ cdgdkCheckSolidStyle(ctxcanvas, 1);
+ gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, (GdkPoint*)poly, n);
+ cdgdkCheckSolidStyle(ctxcanvas, 0);
+ break;
+
+ case CD_OPEN_LINES:
+ cdgdkCheckSolidStyle(ctxcanvas, 1);
+ gdk_draw_lines(ctxcanvas->wnd, ctxcanvas->gc, (GdkPoint*)poly, n);
+ cdgdkCheckSolidStyle(ctxcanvas, 0);
+ break;
+
+ case CD_CLIP:
+ ctxcanvas->clip_rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE);
+ if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON)
+ cdclip(ctxcanvas, CD_CLIPPOLYGON);
+ break;
+
+ case CD_BEZIER:
+ cdSimPolyBezier(ctxcanvas->canvas, poly, n);
+ break;
+
+ case CD_PATH:
+ cdSimPolyPath(ctxcanvas->canvas, poly, n);
+ break;
+ }
}
/******************************************************/
@@ -1076,10 +1057,7 @@ static void cdgetimagergb(cdCtxCanvas *ctxcanvas, unsigned char *r, unsigned cha
x, y-h+1,
0, 0, w, h);
if (!pixbuf)
- {
- fprintf(stderr, "CanvasDraw: error getting image\n");
return;
- }
cdgdkGetPixbufData(pixbuf, r, g, b);
}
@@ -1106,10 +1084,8 @@ static void cdputimagerectrgba_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, co
if (a) nc = 4;
dst_r = malloc(nc*size);
if (!dst_r)
- {
- fprintf(stderr, "CanvasDraw: no enough memory\n");
return;
- }
+
dst_g = dst_r + size;
dst_b = dst_g + size;
if (a) dst_a = dst_b + size;
@@ -1196,10 +1172,8 @@ static void cdputimagerectmap_matrix(cdCtxCanvas* ctxcanvas, int iw, int ih, con
size = ew*eh;
dst_index = malloc(size);
if (!dst_index)
- {
- fprintf(stderr, "CanvasDraw: no enough memory\n");
return;
- }
+
memset(dst_index, 0, size);
/* for all pixels in the destiny area */
@@ -1353,7 +1327,7 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi
rw = xmax-xmin+1;
rh = ymax-ymin+1;
- y -= (h - 1); /* GdkPixbuf origin is at top-left */
+ y -= (h - 1); /* GdkPixbuf image origin is at top-left */
if (!cdCalcZoom(ctxcanvas->canvas->w, x, w, &ex, &ew, xmin, rw, &bx, &bw, 1))
return;
@@ -1429,8 +1403,11 @@ static cdCtxImage *cdcreateimage (cdCtxCanvas *ctxcanvas, int w, int h)
static void cdgetimage (cdCtxCanvas *ctxcanvas, cdCtxImage *ctximage, int x, int y)
{
+ /* y is the bottom-left of the image in CD, must be at upper-left */
+ y -= ctximage->h-1;
+
gdk_draw_drawable(ctximage->img, ctxcanvas->gc,
- ctxcanvas->wnd, x, y - ctximage->h+1, 0, 0,
+ ctxcanvas->wnd, x, y, 0, 0,
ctximage->w, ctximage->h);
}
@@ -1491,6 +1468,7 @@ static void set_rotate_attrib(cdCtxCanvas* ctxcanvas, char* data)
{
if (data)
{
+ /* use this configuration when there is NO native tranformation support */
sscanf(data, "%g %d %d", &ctxcanvas->rotate_angle,
&ctxcanvas->rotate_center_x,
&ctxcanvas->rotate_center_y);
@@ -1620,7 +1598,6 @@ cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* sc
ctxcanvas->fontcontext = gdk_pango_context_get();
pango_context_set_language(ctxcanvas->fontcontext, pango_language_get_default());
- ctxcanvas->gdkLastConvertUTF8 = NULL;
ctxcanvas->canvas = canvas;
canvas->ctxcanvas = ctxcanvas;
@@ -1667,7 +1644,7 @@ void cdgdkInitTable(cdCanvas* canvas)
canvas->cxBox = cdbox;
canvas->cxArc = cdarc;
canvas->cxSector = cdsector;
- canvas->cxChord = cdchordSIM;
+ canvas->cxChord = cdSimChord;
canvas->cxText = cdtext;
canvas->cxNewRegion = cdnewregion;
@@ -1687,7 +1664,6 @@ void cdgdkInitTable(cdCanvas* canvas)
canvas->cxStipple = cdstipple;
canvas->cxPattern = cdpattern;
canvas->cxFont = cdfont;
- canvas->cxNativeFont = cdnativefont;
canvas->cxGetFontDim = cdgetfontdim;
canvas->cxGetTextSize = cdgettextsize;
canvas->cxPalette = cdpalette;
diff --git a/cd/src/gdk/cdgdk.h b/cd/src/gdk/cdgdk.h
index af3cdc0..18eb288 100644
--- a/cd/src/gdk/cdgdk.h
+++ b/cd/src/gdk/cdgdk.h
@@ -59,7 +59,7 @@ struct _cdCtxCanvas {
PangoFontDescription *fontdesc;
PangoLayout *fontlayout;
PangoMatrix fontmatrix;
- char* gdkLastConvertUTF8;
+ char* strLastConvertUTF8;
cdImage* image_dbuffer; /* Used by double buffer driver */
cdCanvas* canvas_dbuffer;
diff --git a/cd/src/gdk/cdgdkclp.c b/cd/src/gdk/cdgdkclp.c
index 22e7690..3eabc54 100644
--- a/cd/src/gdk/cdgdkclp.c
+++ b/cd/src/gdk/cdgdkclp.c
@@ -115,7 +115,7 @@ static void cdinittable(cdCanvas* canvas)
static cdContext cdClipboardContext =
{
- CD_CAP_ALL & ~(CD_CAP_GETIMAGERGB | CD_CAP_IMAGESRV | CD_CAP_FONTDIM | CD_CAP_TEXTSIZE),
+ CD_CAP_ALL & ~(CD_CAP_GETIMAGERGB | CD_CAP_IMAGESRV | CD_CAP_FONTDIM | CD_CAP_TEXTSIZE ), /* same as CD_MF */
0,
cdcreatecanvas,
cdinittable,
diff --git a/cd/src/gdk/cdgdkdbuf.c b/cd/src/gdk/cdgdkdbuf.c
index aa8d587..b399cbe 100644
--- a/cd/src/gdk/cdgdkdbuf.c
+++ b/cd/src/gdk/cdgdkdbuf.c
@@ -147,8 +147,7 @@ static void cdinittable(cdCanvas* canvas)
static cdContext cdDBufferContext =
{
- CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS |
- CD_CAP_FPRIMTIVES ),
+ CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_PATH | CD_CAP_BEZIER | CD_CAP_FPRIMTIVES ),
0,
cdcreatecanvas,
cdinittable,
diff --git a/cd/src/gdk/cdgdkimg.c b/cd/src/gdk/cdgdkimg.c
index 0c5e5dd..4b4475b 100644
--- a/cd/src/gdk/cdgdkimg.c
+++ b/cd/src/gdk/cdgdkimg.c
@@ -30,7 +30,7 @@ static void cdinittable(cdCanvas* canvas)
static cdContext cdImageContext =
{
- CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_FPRIMTIVES ),
+ CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_FPRIMTIVES | CD_CAP_PATH | CD_CAP_BEZIER ),
0,
cdcreatecanvas,
cdinittable,
diff --git a/cd/src/gdk/cdgdknative.c b/cd/src/gdk/cdgdknative.c
index 9f0c5ed..8865d7e 100644
--- a/cd/src/gdk/cdgdknative.c
+++ b/cd/src/gdk/cdgdknative.c
@@ -95,7 +95,7 @@ static void cdinittable(cdCanvas* canvas)
static cdContext cdNativeWindowContext =
{
- CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_FPRIMTIVES ),
+ CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_FPRIMTIVES | CD_CAP_PATH | CD_CAP_BEZIER ),
1,
cdcreatecanvas,
cdinittable,