[waimea] Cairo 1.0 support
Paul Hoy
paul.hoy at mac.com
Sun Oct 2 22:57:17 EEST 2005
Hi Michael,
Thanks so much for the patch, but one question. Can you tell briefly
explain how to apply the patch?
Thanks,
Paul
On Oct 2, 2005, at 3:35 PM, Michael J M Thomson wrote:
>>> Yep, patch is short one file's changes, sorry about that, will be a
>>> bit more careful before I post another.
>>>
>> There's no need to be too careful ;-)
>>
> Fair enough! Try attachment.
>
> --
> Michael J M Thomson
>
> Knock knock, Neo...
> main(){int/* gcc matrix.c -o matrix */i=0,j,s[40]={0,},l[40];for(;;)
> {s[i]||
> (l[i]=s[i]=rand()%10);for(j=0;j<25;++j)printf("\x1b[%d;%dH\x1b[%d;3%
> cm%c",s
> [i]+j,i*2+1,l[i]-j==1||l[i]-j!=2&&l[i]-j<6||l[i]-j>15&&l[i]-j<21||0,
> (l[i]-j
> <3?7:(l[i]-j<16)*2)+'0',j<l[i]?rand()%93+33:32);s[i]*=++l[i]<25;i=+
> +i%40;}}
> diff -ur waimea/configure.in waimea.new/configure.in
> --- waimea/configure.in 2005-01-26 09:15:21.000000000 +1100
> +++ waimea.new/configure.in 2005-09-07 16:16:56.000000000 +1000
> @@ -207,7 +207,7 @@
>
>
> dnl Check for cairo library
> -PKG_CHECK_MODULES(CAIRO, cairo >= 0.3.0)
> +PKG_CHECK_MODULES(CAIRO, cairo >= 1.0.0)
>
> AC_SUBST(CAIRO_CFLAGS)
> AC_SUBST(CAIRO_LIBS)
> diff -ur waimea/src/Event.cc waimea.new/src/Event.cc
> --- waimea/src/Event.cc 2005-01-26 09:15:21.000000000 +1100
> +++ waimea.new/src/Event.cc 2005-09-29 04:33:38.019122016 +1000
> @@ -147,17 +147,22 @@
> else it++;
> }
>
> +#if 0
> static cairo_t *cr = NULL;
> if (cr == NULL) {
> - cr = cairo_create();
> /* XXX: cairo need a call to this function for text
> support to be initialized, will probably
> dissapear soon. */
> - cairo_set_target_drawable(cr, waimea->display,
> - DefaultRootWindow(waimea-
> >display));
> + cairo_surface_t *surface =
> + cairo_xlib_surface_create(waimea->display,
> + DefaultRootWindow(waimea->display),
> + DefaultVisual(waimea->display,
> DefaultScreen(waimea->display)),
> + DisplayWidth(waimea->display, DefaultScreen
> (waimea->display)),
> + DisplayHeight(waimea->display,
> DefaultScreen(waimea->display)));
> + cr = cairo_create(surface);
> }
>
> dw->renderWindow(cr);
> -
> +#endif
> } else {
> FD_ZERO(&rfds);
> FD_SET(xfd, &rfds);
> diff -ur waimea/src/Render.cc waimea.new/src/Render.cc
> --- waimea/src/Render.cc 2005-09-07 18:21:18.000000000 +1000
> +++ waimea.new/src/Render.cc 2005-09-07 19:32:10.000000000 +1000
> @@ -359,21 +359,22 @@
> if (crsurface) {
> groupsurface =
> cairo_surface_create_similar(crsurface,
> - CAIRO_FORMAT_ARGB32,
> +
> CAIRO_CONTENT_COLOR_ALPHA,
> width, height);
> } else if (parent_surface) {
> groupsurface =
> cairo_surface_create_similar(parent_surface,
> - CAIRO_FORMAT_ARGB32,
> +
> CAIRO_CONTENT_COLOR_ALPHA,
> width, height);
> } else {
> if (ws->waimea->client_side_rendering) {
> data = new unsigned char[width * height * sizeof
> (WaPixel)];
> memset (data, 0, width * height * sizeof(WaPixel));
> groupsurface =
> - cairo_surface_create_for_image((char *) data,
> -
> CAIRO_FORMAT_ARGB32,
> - width, height,
> width * 4);
> + cairo_image_surface_create_for_data(data,
> +
> CAIRO_FORMAT_ARGB32,
> + width,
> height,
> + width * 4);
> } else {
> GC gc;
> XGCValues gcv;
> @@ -411,9 +412,10 @@
> colormap);
> }
> }
> -
> - cairo_set_target_surface(cr, groupsurface);
> - cairo_default_matrix(cr);
> +
> + cairo_destroy(cr);
> + cr = cairo_create(groupsurface);
> + cairo_identity_matrix(cr);
> cairo_set_operator(cr, RENDER_OPERATOR_DEFAULT);
> list<RenderOp *>::iterator oit = operations.begin();
> for (; oit != operations.end(); oit++) {
> @@ -431,13 +433,18 @@
> }
>
> if (crsurface) {
> - cairo_set_target_surface(cr, crsurface);
> + cairo_destroy(cr);
> + cr = cairo_create(crsurface);
> cairo_set_operator(cr, RENDER_OPERATOR_DEFAULT);
> if (xrop_set) cairo_set_operator(cr, xrop);
> cairo_translate(cr, x, y);
> cairo_rotate(cr, rotation);
> - cairo_set_alpha(cr, opacity);
> - cairo_show_surface(cr, cache_surface->crsurface, width,
> height);
> + // XXX: I think I may've screwed this up, at least as to
> whether there
> + // should be any clipping. -mjmt
> + cairo_set_source_surface(cr, cache_surface->crsurface, 0.,
> 0.);
> + cairo_rectangle(cr, 0., 0., width, height);
> + cairo_clip(cr);
> + cairo_paint_with_alpha(cr, opacity);
> }
>
> if (return_surface)
> @@ -832,13 +839,9 @@
> pattern = cairo_pattern_create_radial (cx, cy, 0.0, cx, cy,
> ry);
>
> if (rx != ry) {
> - cairo_matrix_t *matrix;
> -
> - matrix = cairo_matrix_create ();
> - cairo_matrix_scale (matrix, ry / rx, 1.0);
> - cairo_pattern_set_matrix (pattern, matrix);
> -
> - cairo_matrix_destroy (matrix);
> + cairo_matrix_t matrix;
> + cairo_matrix_init_scale (&matrix, ry / rx, 1.0);
> + cairo_pattern_set_matrix (pattern, &matrix);
> }
> } break;
> case GroupPatternType: {
> @@ -854,13 +857,13 @@
> group->return_surface = NULL;
> group->parent_surface = NULL;
>
> - cairo_default_matrix(cr);
> + cairo_identity_matrix(cr);
> cairo_move_to(cr, 0.0, 0.0);
> pattern = cairo_pattern_create_for_surface(subsurface-
> >crsurface);
> subsurface->unref();
> cairo_restore(cr);
> } else {
> - cairo_set_rgb_color (cr, 1.0, 1.0, 1.0);
> + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
> return;
> }
> } break;
> @@ -869,23 +872,23 @@
> int stops = 0;
> list<WaColorStop *>::iterator it = color_stops.begin();
> for (; it != color_stops.end(); ++it) {
> - cairo_pattern_add_color_stop (pattern, (*it)->offset,
> - (*it)->color->red,
> - (*it)->color->green,
> - (*it)->color->blue,
> - (*it)->color->alpha);
> + cairo_pattern_add_color_stop_rgba(pattern, (*it)->offset,
> + (*it)->color->red,
> + (*it)->color->green,
> + (*it)->color->blue,
> + (*it)->color->alpha);
> stops++;
> }
>
> if (stops == 0) {
> - cairo_pattern_add_color_stop (pattern, 0.0, 0.0, 0.0, 0.0, 1.0);
> - cairo_pattern_add_color_stop (pattern, 1.0, 1.0, 1.0, 1.0, 1.0);
> + cairo_pattern_add_color_stop_rgba(pattern, 0.0, 0.0, 0.0, 0.0,
> 1.0);
> + cairo_pattern_add_color_stop_rgba(pattern, 1.0, 1.0, 1.0, 1.0,
> 1.0);
> }
>
> cairo_pattern_set_filter (pattern, filter);
> cairo_pattern_set_extend (pattern, extend);
>
> - cairo_set_pattern (cr, pattern);
> + cairo_set_source(cr, pattern);
>
> cairo_pattern_destroy (pattern);
> }
> @@ -1110,7 +1113,6 @@
> fill_color.setcairo_color(cr);
> if (fill_pattern)
> fill_pattern->setcairo_pattern(dwo, cr, NULL, w, h);
> - cairo_set_alpha(cr, fill_color.alpha);
> cairo_fill(cr);
> cairo_restore(cr);
> }
> @@ -1429,7 +1431,7 @@
> if (name) delete [] name;
> if (bg_group) bg_group->unref();
> clear();
> - if (font) cairo_font_destroy(font);
> + if (font) cairo_font_face_destroy(font);
> }
>
> void RenderOpText::clear(void) {
> @@ -1604,20 +1606,19 @@
> calc_length(bottom_spacing, bottom_spacing_u, dwo->ws->vdpi, h,
> &bottom_space);
>
> - cairo_default_matrix(cr);
> + cairo_identity_matrix(cr);
>
> if (!font) {
> - cairo_select_font(cr, family, slant, weight);
> - /* font = cairo_current_font(cr);
> + cairo_select_font_face(cr, family, slant, weight);
> + font = cairo_get_font_face(cr);
> if (!font)
> return;
>
> - cairo_font_reference (font);
> - */
> + cairo_font_face_reference(font);
> } else
> - cairo_set_font (cr, font);
> + cairo_set_font_face(cr, font);
>
> - cairo_scale_font (cr, font_size);
> + cairo_set_font_size(cr, font_size);
>
> if (is_static)
> text = utf8;
> @@ -1657,7 +1658,7 @@
> str[end_offset] = '\0';
> sinfo->text = str;
>
> - cairo_text_extents(cr, (unsigned char *) sinfo->text,
> &extents);
> + cairo_text_extents(cr, sinfo->text, &extents);
> str_y_pos = extents.height - extents.y_bearing;
> str_width = extents.width;
> str_height = extents.height;
> @@ -1670,9 +1671,9 @@
> if (textptr[end_offset] == '\t') {
> double tab, with_space;
> if (space_width < 0.0) {
> - cairo_text_extents(cr, (unsigned char *) "1
> 1", &extents);
> + cairo_text_extents(cr, "1 1", &extents);
> with_space = extents.width;
> - cairo_text_extents(cr, (unsigned char *) "11",
> &extents);
> + cairo_text_extents(cr, "11", &extents);
> space_width = with_space - extents.width;
> }
> tab = ceil((linfo->width + space_width) / tab_space);
> @@ -1743,13 +1744,14 @@
> cairo_save(cr);
>
> text_region = cairo_surface_create_similar(
> - cairo_current_target_surface(cr), CAIRO_FORMAT_ARGB32,
> - (unsigned int) ceil(width), (unsigned int) ceil(height));
> + cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA,
> + int(ceil(width)), int(ceil(height)));
>
> - cairo_set_target_surface(cr, text_region);
> + cairo_destroy(cr);
> + cr = cairo_create(text_region);
>
> if (bg_group) {
> - bg_group->parent_surface = cairo_current_target_surface(cr);
> + bg_group->parent_surface = cairo_get_target(cr);
> bg_group->return_surface = &subsurface;
> cairo_save(cr);
> bg_group->render(dwo, cr, NULL, (unsigned int) ceil(width),
> @@ -1762,11 +1764,10 @@
> cairo_pattern_t *pattern;
>
> cairo_save(cr);
> - cairo_surface_set_repeat(subsurface->crsurface, true);
> pattern = cairo_pattern_create_for_surface(subsurface-
> >crsurface);
> - cairo_set_pattern(cr, pattern);
> + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
> + cairo_set_source(cr, pattern);
> cairo_pattern_destroy(pattern);
> - cairo_rectangle(cr, 0.0, 0.0, ceil(width), ceil(height));
> cairo_fill(cr);
> cairo_restore(cr);
> subsurface->unref();
> @@ -1789,7 +1790,7 @@
> if (stroke || fill_pattern) {
> cairo_move_to(cr, (int) (left_space + (*sit)->x +
> pos_x),
> (int) (y_off + y_pos));
> - cairo_text_path(cr, (unsigned char *) (*sit)->text);
> + cairo_text_path(cr, (*sit)->text);
> cairo_move_to(cr, 0.0, 0.0);
> draw(dwo, cr, crsurface, WA_ROUND_U(width),
> WA_ROUND_U(height));
> @@ -1799,12 +1800,12 @@
> cairo_move_to(cr, (int) (left_space + (*sit)->x +
> pos_x +
> shadow_x_offset),
> (int) (y_off + y_pos +
> shadow_y_offset));
> - cairo_show_text(cr, (unsigned char *) (*sit)->text);
> + cairo_show_text(cr, (*sit)->text);
> }
> fill_color.setcairo_color(cr);
> cairo_move_to(cr, (int) (left_space + (*sit)->x +
> pos_x),
> (int) (y_off + y_pos));
> - cairo_show_text(cr, (unsigned char *) (*sit)->text);
> + cairo_show_text(cr, (*sit)->text);
> }
> }
>
> @@ -1816,9 +1817,10 @@
> if (x || y) cairo_translate(cr, x, y);
> if (xrop_set) cairo_set_operator(cr, xrop);
> if (rotation) cairo_rotate(cr, rotation);
> - cairo_show_surface(cr, text_region, (unsigned int) ceil(width),
> - (unsigned int) ceil(height));
> -
> + cairo_set_source_surface(cr, text_region, 0., 0.);
> + cairo_rectangle(cr, 0., 0., ceil(width), ceil(height));
> + cairo_clip(cr);
> + cairo_paint(cr);
> cairo_surface_destroy(text_region);
>
> bail:
> @@ -1860,7 +1862,7 @@
> calcPositionAndSize(w, h, dwo->ws->hdpi, dwo->ws->vdpi, &x, &y,
> &width, &height);
>
> - if (color.alpha == 1.0) cairo_set_operator(cr,
> CAIRO_OPERATOR_SRC);
> + if (color.alpha == 1.0) cairo_set_operator(cr,
> CAIRO_OPERATOR_SOURCE);
> if (xrop_set) cairo_set_operator(cr, xrop);
> color.setcairo_color(cr);
> cairo_rectangle(cr, x, y, width, height);
> @@ -1946,54 +1948,61 @@
>
> switch (scale) {
> case ImageNormalScaleType:
> - cairo_default_matrix(cr);
> + cairo_identity_matrix(cr);
>
> if (width != img->width || height != img->height) {
> if (xrop_set) cairo_set_operator(cr, xrop);
> - cairo_operator_t op = cairo_current_operator(cr);
> + cairo_operator_t op = cairo_get_operator(cr);
>
> - cairo_surface_t *target =
> cairo_current_target_surface(cr);
> + cairo_surface_t *target = cairo_get_target(cr);
> cairo_surface_t *scaled =
> - cairo_surface_create_similar(target,
> CAIRO_FORMAT_ARGB32,
> + cairo_surface_create_similar(target,
> CAIRO_CONTENT_COLOR_ALPHA,
> (int) width + 2,
> (int) height + 2);
> - cairo_set_target_surface(cr, scaled);
> + cairo_destroy(cr);
> + cr = cairo_create(scaled);
> cairo_scale(cr, (double) width / (img->width -
> ((img->width >
> 1)? 1: 0)),
> (double) height / (img->height -
> ((img->height > 1)?
> 1: 0)));
> - cairo_surface_set_filter(img->crsurface, filter);
> - cairo_set_operator(cr, CAIRO_OPERATOR_SRC);
> - cairo_show_surface(cr, img->crsurface,
> - img->width + 1, img->height + 1);
> - cairo_set_target_surface(cr, target);
> - cairo_default_matrix(cr);
> + cairo_pattern_t *img_pattern =
> + cairo_pattern_create_for_surface(img->crsurface);
> + cairo_pattern_set_filter(img_pattern, filter);
> + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
> + cairo_set_source(cr, img_pattern);
> + cairo_rectangle(cr, 0., 0., img->width + 1, img-
> >height + 1);
> + cairo_fill(cr);
> + cairo_pattern_destroy(img_pattern);
> +
> + cairo_destroy(cr);
> + cr = cairo_create(target);
> cairo_translate(cr, x, y);
> cairo_set_operator(cr, op);
> - cairo_show_surface(cr, scaled, (int) width + 2,
> - (int) height + 2);
> + cairo_set_source_surface(cr, scaled, 0., 0.);
> + cairo_rectangle(cr, 0., 0., width + 2., height + 2.);
> + cairo_fill(cr);
> cairo_surface_destroy(scaled);
> } else {
> if (xrop_set) cairo_set_operator(cr, xrop);
> cairo_translate(cr, x, y);
> cairo_rotate(cr, rotation);
> - cairo_show_surface(cr, img->crsurface,
> - img->width + 1, img->height + 1);
> + cairo_set_source_surface(cr, img->crsurface, 0., 0.);
> + cairo_rectangle(cr, 0., 0., img->width + 1., img-
> >height + 1.);
> + cairo_fill(cr);
> }
> break;
> case ImageTileScaleType: {
> - cairo_default_matrix(cr);
> - cairo_surface_set_repeat(img->crsurface, true);
> + cairo_identity_matrix(cr);
> cairo_translate(cr, x, y);
> cairo_rectangle(cr, 0, 0, width, height);
> cairo_move_to(cr, 0.0, 0.0);
> - cairo_default_matrix(cr);
> + cairo_identity_matrix(cr);
> pattern = cairo_pattern_create_for_surface(img-
> >crsurface);
> - cairo_set_pattern(cr, pattern);
> + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
> + cairo_set_source(cr, pattern);
> cairo_pattern_destroy(pattern);
> if (xrop_set) cairo_set_operator(cr, xrop);
> cairo_fill(cr);
> - cairo_surface_set_repeat(img->crsurface, false);
> } break;
> }
>
> @@ -2287,19 +2296,26 @@
> cairo_operator_t crop;
> } operator_map[] = {
> { "clear", CAIRO_OPERATOR_CLEAR },
> - { "src", CAIRO_OPERATOR_SRC },
> - { "dst", CAIRO_OPERATOR_DST },
> + { "source", CAIRO_OPERATOR_SOURCE },
> { "over", CAIRO_OPERATOR_OVER },
> - { "overreverse", CAIRO_OPERATOR_OVER_REVERSE },
> { "in", CAIRO_OPERATOR_IN },
> - { "inreverse", CAIRO_OPERATOR_IN_REVERSE },
> { "out", CAIRO_OPERATOR_OUT },
> - { "outreverse", CAIRO_OPERATOR_OUT_REVERSE },
> { "atop", CAIRO_OPERATOR_ATOP },
> - { "atopreverse", CAIRO_OPERATOR_ATOP_REVERSE },
> + { "dest", CAIRO_OPERATOR_DEST },
> + { "dest_over", CAIRO_OPERATOR_DEST_OVER },
> + { "dest_in", CAIRO_OPERATOR_DEST_IN },
> + { "dest_out", CAIRO_OPERATOR_DEST_OUT },
> + { "dest_atop", CAIRO_OPERATOR_DEST_ATOP },
> { "xor", CAIRO_OPERATOR_XOR },
> { "add", CAIRO_OPERATOR_ADD },
> - { "saturate", CAIRO_OPERATOR_SATURATE }
> + { "saturate", CAIRO_OPERATOR_SATURATE },
> + // XXX: Should the names below be mentioned somewhere as
> deprecated? -mjmt
> + { "src", CAIRO_OPERATOR_SOURCE },
> + { "dst", CAIRO_OPERATOR_DEST },
> + { "overreverse", CAIRO_OPERATOR_DEST_OVER },
> + { "inreverse", CAIRO_OPERATOR_DEST_IN },
> + { "outreverse", CAIRO_OPERATOR_DEST_OUT },
> + { "atopreverse", CAIRO_OPERATOR_DEST_ATOP }
> };
>
> void attributes_get_position(Parser *parser, Tst<char *> *attr,
> diff -ur waimea/src/Render.hh waimea.new/src/Render.hh
> --- waimea/src/Render.hh 2005-01-26 09:15:21.000000000 +1100
> +++ waimea.new/src/Render.hh 2005-09-07 18:23:51.000000000 +1000
> @@ -246,8 +246,7 @@
> double getOpacity(void) { return alpha; }
>
> inline void setcairo_color(cairo_t *cr) {
> - cairo_set_rgb_color(cr, red, green, blue);
> - cairo_set_alpha(cr, alpha);
> + cairo_set_source_rgba(cr, red, green, blue, alpha);
> }
>
> double red, green, blue, alpha;
> @@ -502,7 +501,7 @@
> HorizontalAlignment text_halign;
> WaColor shadow_color;
> char *family;
> - cairo_font_t *font;
> + cairo_font_face_t *font;
> RenderGroup *bg_group;
> cairo_font_weight_t weight;
> cairo_font_slant_t slant;
> diff -ur waimea/src/Screen.cc waimea.new/src/Screen.cc
> --- waimea/src/Screen.cc 2005-01-26 09:15:21.000000000 +1100
> +++ waimea.new/src/Screen.cc 2005-09-07 16:32:11.000000000 +1000
> @@ -1549,10 +1549,10 @@
>
> if (waimea->client_side_rendering) {
> data = rgba;
> - surface = cairo_surface_create_for_image((char *) rgba,
> - CAIRO_FORMAT_ARGB32,
> - width, height,
> - width * sizeof
> (WaPixel));
> + surface = cairo_image_surface_create_for_data(rgba,
> +
> CAIRO_FORMAT_ARGB32,
> + width, height,
> + width *
> sizeof(WaPixel));
> } else {
> pixmap = XCreatePixmap(display, id, width, height, 32);
> XImage *image = XCreateImage(display, visual, 32, ZPixmap, 0,
> diff -ur waimea/stamp-h.in waimea.new/stamp-h.in
> --- waimea/stamp-h.in 2005-09-07 18:05:31.000000000 +1000
> +++ waimea.new/stamp-h.in 2005-09-12 18:30:48.000000000 +1000
> @@ -0,0 +1 @@
> +timestamp
>
More information about the waimea
mailing list