Esempio n. 1
0
//=================================================================================
// mark_paint_group
//=================================================================================
void mark_paint_group(Qdr *qdr, cairo_t *cr, cairo_pattern_t *pattern, int _x, int _y)
{
	int idx = qdr->group.data[_x][_y];
	
	if(qdr->group.attr[idx].count==1 && qdr->group.image){
		int x = (_x + qdr->margin) * qdr->msize;
		int y = (_y + qdr->margin) * qdr->msize;

		if(!pattern){
			struct QDRBindImage b;
			//cairo_surface_t *surface = cairo_image_surface_create_from_png(qdr->group.image);
			cairo_surface_t *surface = image_surface_create(&b, qdr->group.image);
			if(!surface)
				return;
			
			int w = cairo_image_surface_get_width(surface);
			int h = cairo_image_surface_get_height(surface);
			
			pattern = cairo_pattern_create_for_surface(surface);
			
			//scaling
			if(w>qdr->msize || h>qdr->msize){
				int big = w>h ? w : h;
				double scaling = (double)qdr->msize/big;
				
				cairo_matrix_t matrix;
				cairo_matrix_init_scale(&matrix, 1/scaling, 1/scaling);
				cairo_pattern_set_matrix(pattern, &matrix);
			}
			cairo_surface_destroy(surface);
			if(b.data)
				free(b.data);
		}
		
		//umm...
		if(qdr->group.is_mark){
			cairo_set_source_rgba(cr, qdr->group.attr[idx].r, qdr->group.attr[idx].g, qdr->group.attr[idx].b, qdr->group.attr[idx].a);
			cairo_fill(cr);
		}
		
		cairo_translate(cr, x, y);
			cairo_set_source(cr, pattern);
			//cairo_pattern_set_filter (cairo_get_source(cr), CAIRO_FILTER_GAUSSIAN);
			cairo_rectangle(cr, 0, 0, qdr->msize, qdr->msize);
			//cairo_fill(cr);
		cairo_translate(cr, -x, -y);
		
		return;
	}

	cairo_set_source_rgba(cr, qdr->group.attr[idx].r, qdr->group.attr[idx].g, qdr->group.attr[idx].b, qdr->group.attr[idx].a);
	cairo_fill(cr);
}
Esempio n. 2
0
static int gvloadimage_process_surface(GVJ_t *job, usershape_t *us, gs_t *gs, void *instance)
{
    cairo_t *cr; /* temp cr for gs */
    int rc, rc2;
    char width_height[20], dpi[10], cairo_context[30];
    char *gs_args[] = {
	"dot",      /* actual value of argv[0] doesn't matter */
	"-dQUIET",
	"-dNOPAUSE",
	"-sDEVICE=cairo",
	cairo_context,
	width_height,
	dpi,
    };
#define GS_ARGC sizeof(gs_args)/sizeof(gs_args[0])

    gs->surface = cairo_surface_create_similar( 
	cairo_get_target(gs->cr),
	CAIRO_CONTENT_COLOR_ALPHA,
	us->x + us->w,
	us->y + us->h);

    cr = cairo_create(gs->surface);  /* temp context for gs */

    sprintf(width_height, "-g%dx%d", us->x + us->w, us->y + us->h);
    sprintf(dpi, "-r%d", us->dpi);
    sprintf(cairo_context, "-sCairoContext=%p", cr);

    rc = gsapi_init_with_args(instance, GS_ARGC, gs_args);

    cairo_destroy(cr); /* finished with temp context */

    if (rc)
	gs_error(job, us->name, "gsapi_init_with_args", rc);
    else
	rc = gvloadimage_process_file(job, us, instance);

    if (rc) {
	cairo_surface_destroy(gs->surface);
	gs->surface = NULL;
    }

    rc2 = gsapi_exit(instance);
    if (rc2) {
	gs_error(job, us->name, "gsapi_exit", rc2);
	return rc2;
    }

    if (!rc) 
        gs->pattern = cairo_pattern_create_for_surface (gs->surface);

    return rc;
}
Esempio n. 3
0
cairo_pattern_t* Pattern::createPlatformPattern(const AffineTransform& patternTransform) const
{
    cairo_surface_t* surface = tileImage()->nativeImageForCurrentFrame();
    if (!surface)
        return 0;

    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
    const cairo_matrix_t* pattern_matrix = reinterpret_cast<const cairo_matrix_t*>(&patternTransform);
    cairo_pattern_set_matrix(pattern, pattern_matrix);
    if (m_repeatX || m_repeatY)
        cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
    return pattern;
}
Esempio n. 4
0
static void
mask_surface_repeat (cairo_t         *cr,
                     cairo_surface_t *surface)
{
  cairo_pattern_t *pattern;

  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

  cairo_mask (cr, pattern);

  cairo_pattern_destroy (pattern);
}
Esempio n. 5
0
void
gtk_css_style_render_icon_surface (GtkCssStyle            *style,
                                   cairo_t                *cr,
                                   cairo_surface_t        *surface,
                                   double                  x,
                                   double                  y)
{
  const GtkCssValue *shadows;
  cairo_matrix_t matrix, transform_matrix;
  GdkRectangle extents;

  g_return_if_fail (GTK_IS_CSS_STYLE (style));
  g_return_if_fail (cr != NULL);
  g_return_if_fail (surface != NULL);

  shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);

  if (!get_surface_extents (surface, &extents))
    {
      /* weird infinite surface, no special magic for you */
      cairo_set_source_surface (cr, surface, x, y);
      _gtk_css_shadows_value_paint_icon (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW), cr);
      cairo_paint (cr);
      return;
    }

  cairo_translate (cr, x + extents.x, y + extents.y);

  if (_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
    {
      cairo_pattern_t *pattern;

      /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
      cairo_matrix_init_translate (&matrix, extents.width / 2, extents.height / 2);
      cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
      cairo_matrix_translate (&matrix, - extents.width / 2, - extents.height / 2);
      if (cairo_matrix_invert (&matrix) != CAIRO_STATUS_SUCCESS)
        {
          g_assert_not_reached ();
        }
      cairo_matrix_translate (&matrix, extents.x, extents.y);

      pattern = cairo_pattern_create_for_surface (surface);
      cairo_pattern_set_matrix (pattern, &matrix);
      cairo_set_source (cr, pattern);
      cairo_pattern_destroy (pattern);

      _gtk_css_shadows_value_paint_icon (shadows, cr);
      cairo_paint (cr);
    }
}
Esempio n. 6
0
static int cairo_pattern_create_for_surface_l( lua_State* L )
{
  lua_cairo_surface_t* lcs = lua_cairo_surface_check( L, 1 );

  lua_cairo_pattern_t* lcp = (lua_cairo_pattern_t*)lua_newuserdata( L, sizeof( lua_cairo_pattern_t ) );
  memset( lcp, 0, sizeof( lua_cairo_pattern_t ) );

  luaL_getmetatable( L, "lua_cairo_pattern_t" );
  lua_setmetatable( L, -2 );

  lcp->pattern = cairo_pattern_create_for_surface( lcs->surface );

  return( 1 );
}
Esempio n. 7
0
int
main (void)
{
    cairo_test_context_t ctx;
    cairo_surface_t *surface;
    cairo_pattern_t *solid_rgb, *solid_rgba, *surface_pattern, *linear, *radial;
    cairo_test_status_t result = CAIRO_TEST_SUCCESS;

    cairo_test_init (&ctx, "pattern-get-type");
    cairo_test_log (&ctx, "Creating patterns of all types\n");

    solid_rgb = cairo_pattern_create_rgb (0.0, 0.1, 0.2);
    solid_rgba = cairo_pattern_create_rgba (0.3, 0.4, 0.5, 0.6);
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					  1, 1);
    surface_pattern = cairo_pattern_create_for_surface (surface);
    linear = cairo_pattern_create_linear (0.0, 0.0, 10.0, 10.0);
    radial = cairo_pattern_create_radial (10.0, 10.0, 0.1,
					  10.0, 10.0, 1.0);

    cairo_test_log (&ctx, "Verifying return values of cairo_pattern_get_type\n");

    if (cairo_pattern_get_type (solid_rgb) != CAIRO_PATTERN_TYPE_SOLID)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (solid_rgba) != CAIRO_PATTERN_TYPE_SOLID)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (surface_pattern) != CAIRO_PATTERN_TYPE_SURFACE)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (linear) != CAIRO_PATTERN_TYPE_LINEAR)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (radial) != CAIRO_PATTERN_TYPE_RADIAL)
	result = CAIRO_TEST_FAILURE;

    cairo_test_log (&ctx, "Cleaning up\n");

    cairo_pattern_destroy (solid_rgb);
    cairo_pattern_destroy (solid_rgba);
    cairo_pattern_destroy (surface_pattern);
    cairo_surface_destroy (surface);
    cairo_pattern_destroy (linear);
    cairo_pattern_destroy (radial);

    cairo_test_fini (&ctx);

    return result;
}
Esempio n. 8
0
void
composite_checker (cairo_perf_t *perf,
                   cairo_t      *cr,
                   int           width,
                   int           height)
{
    cairo_surface_t *image;

    if (! cairo_perf_can_run (perf, "composite-checker"))
	return;

    /* Create the checker pattern. We don't actually need to draw
     * anything on it since that wouldn't affect performance.
     */
    image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        PAT_SIZE,
                                        PAT_SIZE);
    checkerboard = cairo_pattern_create_for_surface (image);
    cairo_pattern_set_filter (checkerboard, CAIRO_FILTER_NEAREST);
    cairo_pattern_set_extend (checkerboard, CAIRO_EXTEND_REPEAT);
    cairo_surface_destroy (image);

    /* Create the image source pattern. Again we use the NEAREST
     * filtering which should be fastest.
    */
    image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        SRC_SIZE,
                                        SRC_SIZE);
    src_pattern = cairo_pattern_create_for_surface (image);
    cairo_pattern_set_filter (src_pattern, CAIRO_FILTER_NEAREST);
    cairo_surface_destroy (image);

    cairo_perf_run (perf, "composite-checker", do_composite_checker);

    cairo_pattern_destroy (checkerboard);
    cairo_pattern_destroy (src_pattern);
}
Esempio n. 9
0
cairo_pattern_t *
gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
                                   const GimpRGB *bg,
                                   gint           index)
{
  cairo_surface_t *surface;
  cairo_pattern_t *pattern;
  guchar          *data;
  guchar          *d;
  guchar           fg_r, fg_g, fg_b, fg_a;
  guchar           bg_r, bg_g, bg_b, bg_a;
  gint             x, y;

  g_return_val_if_fail (fg != NULL, NULL);
  g_return_val_if_fail (bg != NULL, NULL);

  data = g_malloc (8 * 8 * 4);

  gimp_rgba_get_uchar (fg, &fg_r, &fg_g, &fg_b, &fg_a);
  gimp_rgba_get_uchar (bg, &bg_r, &bg_g, &bg_b, &bg_a);

  d = data;

  for (y = 0; y < 8; y++)
    {
      for (x = 0; x < 8; x++)
        {
          if ((x + y + index) % 8 >= 4)
            GIMP_CAIRO_ARGB32_SET_PIXEL (d, fg_r, fg_g, fg_b, fg_a);
          else
            GIMP_CAIRO_ARGB32_SET_PIXEL (d, bg_r, bg_g, bg_b, bg_a);

          d += 4;
        }
    }

  surface = cairo_image_surface_create_for_data (data,
                                                 CAIRO_FORMAT_ARGB32,
                                                 8, 8, 8 * 4);
  cairo_surface_set_user_data (surface, &surface_data_key,
                               data, (cairo_destroy_func_t) g_free);

  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

  cairo_surface_destroy (surface);

  return pattern;
}
static cairo_pattern_t *
_cairo_default_context_pop_group (void *abstract_cr)
{
    cairo_default_context_t *cr = abstract_cr;
    cairo_surface_t *group_surface;
    cairo_pattern_t *group_pattern;
    cairo_matrix_t group_matrix, device_transform_matrix;
    cairo_status_t status;

    /* Verify that we are at the right nesting level */
    if (unlikely (! _cairo_gstate_is_group (cr->gstate)))
        return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_POP_GROUP);

    /* Get a reference to the active surface before restoring */
    group_surface = _cairo_gstate_get_target (cr->gstate);
    group_surface = cairo_surface_reference (group_surface);

    status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist);
    assert (status == CAIRO_STATUS_SUCCESS);

    group_pattern = cairo_pattern_create_for_surface (group_surface);
    status = group_pattern->status;
    if (unlikely (status))
        goto done;

    _cairo_gstate_get_matrix (cr->gstate, &group_matrix);
    /* Transform by group_matrix centered around device_transform so that when
     * we call _cairo_gstate_copy_transformed_pattern the result is a pattern
     * with a matrix equivalent to the device_transform of group_surface. */
    if (_cairo_surface_has_device_transform (group_surface)) {
        cairo_pattern_set_matrix (group_pattern, &group_surface->device_transform);
        _cairo_pattern_transform (group_pattern, &group_matrix);
        _cairo_pattern_transform (group_pattern, &group_surface->device_transform_inverse);
    } else {
        cairo_pattern_set_matrix (group_pattern, &group_matrix);
    }

    /* If we have a current path, we need to adjust it to compensate for
     * the device offset just removed. */
    cairo_matrix_multiply (&device_transform_matrix,
                           &_cairo_gstate_get_target (cr->gstate)->device_transform,
                           &group_surface->device_transform_inverse);
    _cairo_path_fixed_transform (cr->path, &device_transform_matrix);

done:
    cairo_surface_destroy (group_surface);

    return group_pattern;
}
Esempio n. 11
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    uint32_t data[] = {
	0xaa000000, 0x55000000,
	0x55000000, 0xaa000000,
    };

    cairo_surface_t *mask, *mask2;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    mask2 = cairo_image_surface_create_for_data ((unsigned char *) data,
						CAIRO_FORMAT_ARGB32, 2, 2, 8);
    pattern = cairo_pattern_create_for_surface (mask2);
    cairo_surface_destroy (mask2);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
    cairo_mask (cr2, pattern);
    cairo_pattern_destroy (pattern);
    cairo_destroy (cr2);

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, mask, 0, 0);
    cairo_surface_destroy (mask);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 12
0
static gboolean 
pattern_value_parse (GtkCssParser *parser,
                     GValue       *value)
{
  if (_gtk_css_parser_try (parser, "none", TRUE))
    {
      /* nothing to do here */
    }
  else
    {
      GError *error = NULL;
      gchar *path;
      GdkPixbuf *pixbuf;
      GFile *file;
      cairo_surface_t *surface;
      cairo_pattern_t *pattern;
      cairo_matrix_t matrix;

      file = _gtk_css_parser_read_url (parser);
      if (file == NULL)
        return FALSE;

      path = g_file_get_path (file);
      g_object_unref (file);

      pixbuf = gdk_pixbuf_new_from_file (path, &error);
      g_free (path);
      if (pixbuf == NULL)
        {
          _gtk_css_parser_take_error (parser, error);
          return FALSE;
        }

      surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
      pattern = cairo_pattern_create_for_surface (surface);
      cairo_surface_destroy (surface);

      cairo_matrix_init_scale (&matrix,
                               gdk_pixbuf_get_width (pixbuf),
                               gdk_pixbuf_get_height (pixbuf));
      cairo_pattern_set_matrix (pattern, &matrix);

      g_object_unref (pixbuf);

      g_value_take_boxed (value, pattern);
    }
  
  return TRUE;
}
Esempio n. 13
0
File: bcard.c Progetto: pacew/bcard
int
main (int argc, char **argv)
{
	int c;
	int row, col;
	double x, y;
	char *outname;
		
	outname = "cards.pdf";

	while ((c = getopt (argc, argv, "n")) != EOF) {
		switch (c) {
		case 'n':
			draw_outline = 0;
			break;
		default:
			usage ();
		}
	}

	if (optind != argc)
		usage ();

	init_pdf (outname);
	setup_fonts ();

	code_surface
		= cairo_image_surface_create_from_png ("code-med-high.png");
	code_pattern = cairo_pattern_create_for_surface (code_surface);

	for (row = 0; row < 5; row++) {
		for (col = 0; col < 2; col++) {
			cairo_save (cr);

			x = LEFT_MARGIN + col * CARD_WIDTH;
			y = TOP_MARGIN + row * CARD_HEIGHT;
			cairo_translate (cr, x, y);
			draw_card ();

			cairo_restore (cr);
		}
	}

	cairo_destroy(cr);
	cairo_surface_flush(surface);
	cairo_surface_destroy(surface);
	printf ("evince %s\n", outname);
	return (0);
}
Esempio n. 14
0
static cairo_pattern_t *
composite_image_onto_desktop (PanelBackground *background)
{
	int              width, height;
	cairo_t         *cr;
	cairo_surface_t *surface;
	cairo_pattern_t *pattern;

	if (!background->desktop)
		background->desktop = get_desktop_pixbuf (background);

	if (!background->desktop)
		return NULL;

	width  = gdk_pixbuf_get_width  (background->desktop);
	height = gdk_pixbuf_get_height (background->desktop);

	surface = gdk_window_create_similar_surface (background->window,
						     CAIRO_CONTENT_COLOR_ALPHA,
						     width, height);
	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
		cairo_surface_destroy (surface);
		return NULL;
	}

	cr = cairo_create (surface);
	if(!gdk_window_check_composited_wm(background->window)){
		cairo_set_source_rgb (cr, 1, 1, 1);
		cairo_paint (cr);

		gdk_cairo_set_source_pixbuf (cr, background->desktop, 0, 0);
		cairo_rectangle (cr, 0, 0, width, height);
		cairo_fill (cr);
	}

	gdk_cairo_set_source_pixbuf (cr, background->transformed_image, 0, 0);
	pattern = cairo_get_source (cr);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

	cairo_rectangle (cr, 0, 0, width, height);
	cairo_fill (cr);

	cairo_destroy (cr);

	pattern = cairo_pattern_create_for_surface (surface);
	cairo_surface_destroy (surface);
	return pattern;
}
void QCairoPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags /*flags*/)
{
   //qDebug()<<"drawImage r="<<r<<" sr="<<sr;
    double              w, h;
    cairo_surface_t *image;
    QImage img;
    QRect sri=sr.toRect();
    if (sri.isValid() && (sri.x()!=0 || sri.y()!=0 || sri.size()!=sri.size())) {
        img=pm.copy(sri).convertToFormat(QImage::Format_ARGB32);
    } else {
        img=pm.convertToFormat(QImage::Format_ARGB32);
    }


    if (!img.isNull()) {
        cairo_format_t imgformat=CAIRO_FORMAT_ARGB32;

        updateMatrix();

        image = cairo_image_surface_create_for_data(img.bits(), imgformat, img.width(), img.height(), img.bytesPerLine());
        w = img.width();
        h = img.height();

        cairo_matrix_t cm;
        cairo_matrix_init_identity(&cm);
        cairo_matrix_translate (&cm, r.x(), r.y());
        if (sr.isValid()) cairo_matrix_scale(&cm, r.width() / sr.width(), r.height() / sr.height());
        //cairo_matrix_translate (&cm, -sr.x(), -sr.y());
        cairo_matrix_invert(&cm);

        cairo_pattern_t* brush=cairo_pattern_create_for_surface(image);
        cairo_pattern_set_matrix(brush, &cm);
        cairo_pattern_set_extend(brush, CAIRO_EXTEND_NONE);

        cairo_rectangle(cr, r.x(), r.y(), r.width(), r.height());
        cairo_set_source(cr, brush);
        cairo_fill_preserve(cr);
        cairo_set_source_rgba(cr, 0,0,0,0);
        cairo_set_line_width(cr, 0.0);
        cairo_stroke(cr);
        //cairo_fill(cr);

        //cairo_set_source_surface (cr, image, 0, 0);
        //cairo_paint(cr);
        releasePattern(brush);
        updateMatrix();
    }
}
Esempio n. 16
0
void
set_desktop_background(GdkWindow *window)
{
  Pixmap xpm = get_pixmap_prop(GDK_WINDOW_XWINDOW(window), "_XROOTPMAP_ID");

#ifdef HAVE_GTK3
  if (xpm != None)
    {
      GdkScreen *screen = gdk_window_get_screen(window);
      Window root_return;
      int x, y;
      unsigned int width, height, bw, depth_ret;
      cairo_surface_t *surface = NULL;

      gdk_error_trap_push();
      if (XGetGeometry(GDK_SCREEN_XDISPLAY(screen),
                       xpm,
                       &root_return,
                       &x, &y, &width, &height, &bw, &depth_ret))
        {
          surface = cairo_xlib_surface_create(GDK_SCREEN_XDISPLAY (screen),
                                              xpm,
                                              GDK_VISUAL_XVISUAL(gdk_screen_get_system_visual(screen)),
                                              width, height);
        }
      gdk_error_trap_pop_ignored ();

      cairo_pattern_t *pattern = cairo_pattern_create_for_surface(surface);
      gdk_window_set_background_pattern(window, pattern);

      cairo_surface_destroy(surface);
      // cairo_pattern_destroy      ???
    }
  else
    {
      GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
      gdk_window_set_background_rgba(window, &black);
    }

#else
  if (xpm != None)
    {
      GDKPIXMAP *gpm = gdk_pixmap_foreign_new(xpm);
      gdk_window_set_back_pixmap (window, gpm, FALSE);
      g_object_unref (gpm);
    }
#endif
}
Esempio n. 17
0
cairo_pattern_t *
cairo_test_create_pattern_from_png (const char *filename)
{
    cairo_surface_t *image;
    cairo_pattern_t *pattern;

    image = cairo_test_create_surface_from_png (filename);

    pattern = cairo_pattern_create_for_surface (image);

    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

    cairo_surface_destroy (image);

    return pattern;
}
Esempio n. 18
0
cairo_pattern_t *
gstyle_utils_get_checkered_pattern (void)
{
  static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
                                   0x00, 0xFF, 0x00, 0x00 };
  cairo_surface_t *surface;
  cairo_pattern_t *pattern;

  surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A8, 2, 2, 4);
  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
  cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
  cairo_surface_destroy (surface);

  return pattern;
}
Esempio n. 19
0
void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
                        const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
    cairo_surface_t* image = nativeImageForCurrentFrame();
    if (!image) // If it's too early we won't have an image yet.
        return;

    cairo_t* cr = context->platformContext();
    context->save();

    IntRect imageSize = enclosingIntRect(tileRect);
    OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size(), false);

    if (!imageSurface)
        return;

    if (tileRect.size() != size()) {
        cairo_t* clippedImageContext = imageSurface->context()->platformContext();
        cairo_set_source_surface(clippedImageContext, image, -tileRect.x(), -tileRect.y());
        cairo_paint(clippedImageContext);
        image = imageSurface->image()->nativeImageForCurrentFrame();
    }

    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);

    // Workaround to avoid the unwanted gradient effect (#14017)
    cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);

    cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform);
    cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x() + tileRect.x() * patternTransform.a(), phase.y() + tileRect.y() * patternTransform.d()};
    cairo_matrix_t combined;
    cairo_matrix_multiply(&combined, &pattern_matrix, &phase_matrix);
    cairo_matrix_invert(&combined);
    cairo_pattern_set_matrix(pattern, &combined);

    context->setCompositeOperation(op);
    cairo_set_source(cr, pattern);
    cairo_pattern_destroy(pattern);
    cairo_rectangle(cr, destRect.x(), destRect.y(), destRect.width(), destRect.height());
    cairo_fill(cr);

    context->restore();

    if (imageObserver())
        imageObserver()->didDraw(this);
}
Esempio n. 20
0
/**
 * gimp_cairo_checkerboard_create:
 * @cr:    Cairo context
 * @size:  check size
 * @light: light check color or %NULL to use the default light gray
 * @dark:  dark check color or %NULL to use the default dark gray
 *
 * Create a repeating checkerboard pattern.
 *
 * Return value: a new Cairo pattern that can be used as a source on @cr.
 *
 * Since: GIMP 2.6
 **/
cairo_pattern_t *
gimp_cairo_checkerboard_create (cairo_t       *cr,
                                gint           size,
                                const GimpRGB *light,
                                const GimpRGB *dark)
{
  cairo_t         *context;
  cairo_surface_t *surface;
  cairo_pattern_t *pattern;

  g_return_val_if_fail (cr != NULL, NULL);
  g_return_val_if_fail (size > 0, NULL);

  surface = cairo_surface_create_similar (cairo_get_target (cr),
                                          CAIRO_CONTENT_COLOR,
                                          2 * size, 2 * size);
  context = cairo_create (surface);

  if (light)
    gimp_cairo_set_source_rgb (context, light);
  else
    cairo_set_source_rgb (context,
                          GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT);

  cairo_rectangle (context, 0,    0,    size, size);
  cairo_rectangle (context, size, size, size, size);
  cairo_fill (context);

  if (dark)
    gimp_cairo_set_source_rgb (context, dark);
  else
    cairo_set_source_rgb (context,
                          GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK);

  cairo_rectangle (context, 0,    size, size, size);
  cairo_rectangle (context, size, 0,    size, size);
  cairo_fill (context);

  cairo_destroy (context);

  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

  cairo_surface_destroy (surface);

  return pattern;
}
Esempio n. 21
0
static cairo_surface_t *
_eventd_nd_cairo_limit_size(cairo_surface_t *source, gint max_width, gint max_height)
{
    gdouble s = 1.0;
    gint width, height;
    cairo_surface_t *surface;
    cairo_t *cr;
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;

    width = cairo_image_surface_get_width(source);
    height = cairo_image_surface_get_height(source);

    if ( ( width > max_width ) && ( height > max_height ) )
    {
        if ( width > height )
            s = (gdouble) max_width / (gdouble) width;
        else
            s = (gdouble) max_height / (gdouble) height;
    }
    else if ( width > max_width )
        s = (gdouble) max_width / (gdouble) width;
    else if ( height > max_height )
        s = (gdouble) max_height / (gdouble) height;
    else
        return source;

    width *= s;
    height *= s;

    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    cr = cairo_create(surface);

    cairo_matrix_init_scale(&matrix, 1. / s, 1. / s);

    pattern = cairo_pattern_create_for_surface(source);
    cairo_pattern_set_matrix(pattern, &matrix);

    cairo_set_source(cr, pattern);
    cairo_paint(cr);

    cairo_pattern_destroy(pattern);
    cairo_destroy(cr);
    cairo_surface_destroy(source);

    return surface;
}
Esempio n. 22
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;

    /* Paint a diagonal division as a test image */
    cairo_set_source_rgb (cr, 1, 1, 1);	/* White */
    cairo_paint (cr);

    cairo_move_to (cr, SIZE,    0);
    cairo_line_to (cr, SIZE, SIZE);
    cairo_line_to (cr, 0,    SIZE);

    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_fill (cr);

    /* Create a pattern with the target surface as the source,
     * offset by SIZE/2
     */
    pattern = cairo_pattern_create_for_surface (cairo_get_group_target (cr));

    cairo_matrix_init_translate (&matrix, - SIZE / 2, - SIZE / 2);
    cairo_pattern_set_matrix (pattern, &matrix);

    cairo_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    /* Copy two rectangles from the upper-left quarter of the image to
     * the lower right.  It will work if we use cairo_fill(), but the
     * cairo_clip() cairo_paint() combination fails because the clip
     * on the surface as a destination affects it as the source as
     * well.
     */
    cairo_rectangle (cr,
                     2 * SIZE / 4, 2 * SIZE / 4,
                     SIZE / 4,     SIZE / 4);
    cairo_rectangle (cr,
                     3 * SIZE / 4, 3 * SIZE / 4,
                     SIZE / 4,     SIZE / 4);
    cairo_clip (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;

}
Esempio n. 23
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    int i;
    uint32_t color = 0x8019334c;
    cairo_surface_t *surface;
    cairo_pattern_t *pattern;

    surface = cairo_image_surface_create_for_data ((unsigned char *) &color,
						   CAIRO_FORMAT_ARGB32, 1, 1, 4);
    pattern = cairo_pattern_create_for_surface (surface);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

    /* Several different means of making mostly the same color (though
     * we can't get anything but alpha==1.0 out of
     * cairo_set_source_rgb. */
    for (i=0; i < width; i++) {
	switch (i) {
	case 0:
	    cairo_set_source_rgb (cr, .6, .7, .8);
	    break;
	case 1:
	    cairo_set_source_rgba (cr, .2, .4, .6, 0.5);
	    break;
	case 2:
#if WE_HAD_SUPPORT_FOR_PREMULTIPLIED
	    cairo_set_source_rgba_premultiplied (cr, .1, .2, .3, 0.5);
#else
	    cairo_set_source_rgba (cr, .2, .4, .6, 0.5);
#endif
	    break;
	case 3:
	default:
	    cairo_set_source (cr, pattern);
	    break;
	}

	cairo_rectangle (cr, i, 0, 1, height);
	cairo_fill (cr);
    }

    cairo_pattern_destroy (pattern);
    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 24
0
cairo_pattern_t* Pattern::createPlatformPattern(const AffineTransform&) const
{
    NativeImageCairo* image = tileImage()->nativeImageForCurrentFrame();
    if (!image)
        return 0;

    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image->surface());

    // cairo merges patter space and user space itself
    cairo_matrix_t matrix = m_patternSpaceTransformation;
    cairo_matrix_invert(&matrix);
    cairo_pattern_set_matrix(pattern, &matrix);

    if (m_repeatX || m_repeatY)
        cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
    return pattern;
}
static cairo_pattern_t *
_cairo_skia_context_pop_group (void *abstract_cr)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    cairo_surface_t *group_surface;
    cairo_pattern_t *group_pattern;
    cairo_status_t status;

    group_surface = cairo_surface_reference (&cr->target->image.base);

    status = _cairo_skia_context_restore (cr);
    if (unlikely (status)) {
	group_pattern = _cairo_pattern_create_in_error (status);
	goto done;
    }

    group_pattern = cairo_pattern_create_for_surface (group_surface);
    status = group_pattern->status;
    if (unlikely (status))
        goto done;

#if 0
    _cairo_gstate_get_matrix (cr->gstate, &group_matrix);
    /* Transform by group_matrix centered around device_transform so that when
     * we call _cairo_gstate_copy_transformed_pattern the result is a pattern
     * with a matrix equivalent to the device_transform of group_surface. */
    if (_cairo_surface_has_device_transform (group_surface)) {
	cairo_pattern_set_matrix (group_pattern, &group_surface->device_transform);
	_cairo_pattern_transform (group_pattern, &group_matrix);
	_cairo_pattern_transform (group_pattern, &group_surface->device_transform_inverse);
    } else {
	cairo_pattern_set_matrix (group_pattern, &group_matrix);
    }

    /* If we have a current path, we need to adjust it to compensate for
     * the device offset just removed. */
    _cairo_path_fixed_transform (cr->path,
				 &group_surface->device_transform_inverse);
#endif

done:
    cairo_surface_destroy (group_surface);

    return group_pattern;
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_setTexturePixels 
  (JNIEnv *env, jobject obj, jintArray jarr, jint w, jint h, jint stride)
{
  struct graphics2d *gr = NULL;
  jint *jpixels = NULL;

  gdk_threads_enter();
  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }
  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
  g_assert (gr != NULL);

  if (gr->debug) printf ("setTexturePixels (%d pixels, %dx%d, stride: %d)\n",
			 (*env)->GetArrayLength (env, jarr), w, h, stride);

  if (gr->pattern)
    cairo_pattern_destroy (gr->pattern);

  if (gr->pattern_surface)
    cairo_surface_destroy (gr->pattern_surface);

  if (gr->pattern_pixels)
    free (gr->pattern_pixels);

  gr->pattern = NULL;
  gr->pattern_surface = NULL;
  gr->pattern_pixels = NULL;

  gr->pattern_pixels = (char *) malloc (h * stride * 4);
  g_assert (gr->pattern_pixels != NULL);

  jpixels = (*env)->GetIntArrayElements (env, jarr, NULL);
  g_assert (jpixels != NULL);
  memcpy (gr->pattern_pixels, jpixels, h * stride * 4);
  (*env)->ReleaseIntArrayElements (env, jarr, jpixels, 0);

  gr->pattern_surface = cairo_surface_create_for_image (gr->pattern_pixels, 
							CAIRO_FORMAT_ARGB32, 
							w, h, stride * 4);
  g_assert (gr->pattern_surface != NULL);
  cairo_surface_set_repeat (gr->pattern_surface, 1);
  gr->pattern = cairo_pattern_create_for_surface (gr->pattern_surface);
  g_assert (gr->pattern != NULL);
  cairo_set_pattern (gr->cr, gr->pattern);
  gdk_threads_leave();
}
Esempio n. 27
0
/**
 * ppg_visualizer_resize_timeout:
 * @visualizer: (in): A #PpgVisualizer.
 *
 * A GSourceFunc to handle a resize request. The surface of the visualizer
 * is resized and a draw request is queued.
 *
 * Returns: %FALSE always
 * Side effects: None.
 */
static gboolean
ppg_visualizer_resize_timeout (gpointer data)
{
	PpgVisualizer *visualizer = (PpgVisualizer *)data;
	PpgVisualizerPrivate *priv;
	cairo_pattern_t *pattern;
	GdkWindow *window;
	GooCanvas *canvas;
	gdouble width;
	gdouble height;

	g_return_val_if_fail(PPG_IS_VISUALIZER(visualizer), FALSE);

	priv = visualizer->priv;

	/*
	 * Remove existing surface.
	 */
	if (priv->surface) {
		g_object_set(visualizer, "pattern", NULL, NULL);
		cairo_surface_destroy(priv->surface);
		priv->surface = NULL;
	}

	/*
	 * Create new surface matching new size allocation.
	 */
	g_object_get(visualizer, "height", &height, "width", &width, NULL);
	canvas = goo_canvas_item_get_canvas(GOO_CANVAS_ITEM(visualizer));
	window = gtk_widget_get_window(GTK_WIDGET(canvas));
	priv->surface = gdk_window_create_similar_surface(window,
	                                                  CAIRO_CONTENT_COLOR_ALPHA,
	                                                  width, height);

	/*
	 * Create a new pattern for drawing the item.
	 */
	pattern = cairo_pattern_create_for_surface(priv->surface);
	g_object_set(visualizer, "pattern", pattern, NULL);
	cairo_pattern_destroy(pattern);
	ppg_visualizer_queue_draw(visualizer);

	priv->resize_handler = 0;
	return FALSE;
}
Esempio n. 28
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask_surface;
    cairo_pattern_t *mask;
    static uint32_t data[] = {
	0x80000000, 0x80000000,
	0x80000000, 0x80000000,
    };
    cairo_matrix_t matrix;

    mask_surface = cairo_image_surface_create_for_data ((unsigned char *) data,
							CAIRO_FORMAT_ARGB32, 2, 2, 8);
    mask = cairo_pattern_create_for_surface (mask_surface);
    cairo_surface_destroy (mask_surface);

    cairo_set_source_rgb (cr, 1.0, 0, 0);

    /* We can translate with the CTM, with the pattern matrix, or with
     * both. */

    /* 1. CTM alone. */
    cairo_save (cr);
    {
	cairo_translate (cr, 2, 2);
	cairo_mask (cr, mask);
    }
    cairo_restore (cr);

    /* 2. Pattern matrix alone. */
    cairo_matrix_init_translate (&matrix, -4, -4);
    cairo_pattern_set_matrix (mask, &matrix);

    cairo_mask (cr, mask);

    /* 3. CTM + pattern matrix */
    cairo_translate (cr, 2, 2);
    cairo_mask (cr, mask);

    cairo_pattern_destroy (mask);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 29
0
static cairo_int_status_t
_paint_fallback_image (cairo_paginated_surface_t *surface,
		       cairo_box_int_t           *box)
{
    double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution;
    double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution;
    cairo_matrix_t matrix;
    int x, y, width, height;
    cairo_status_t status;
    cairo_surface_t *image;
    cairo_pattern_t *pattern;

    x = box->p1.x;
    y = box->p1.y;
    width = box->p2.x - x;
    height = box->p2.y - y;
    image = _cairo_paginated_surface_create_image_surface (surface,
							   ceil (width  * x_scale),
							   ceil (height * y_scale));
    _cairo_surface_set_device_scale (image, x_scale, y_scale);
    /* set_device_offset just sets the x0/y0 components of the matrix;
     * so we have to do the scaling manually. */
    cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale);

    status = _cairo_meta_surface_replay (surface->meta, image);
    if (status)
	goto CLEANUP_IMAGE;

    pattern = cairo_pattern_create_for_surface (image);
    cairo_matrix_init (&matrix, x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale);
    cairo_pattern_set_matrix (pattern, &matrix);

    status = _cairo_surface_paint (surface->target,
				   CAIRO_OPERATOR_SOURCE,
				   pattern);

    cairo_pattern_destroy (pattern);
CLEANUP_IMAGE:
    cairo_surface_destroy (image);

    return status;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface;
    cairo_pattern_t *pat;

    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_paint (cr);

    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SRC_WIDTH, SRC_HEIGHT);
    setup_source_surface (surface, SRC_WIDTH, SRC_HEIGHT);

    pat = cairo_pattern_create_for_surface (surface);
    cairo_surface_destroy (surface);

    /* We want to draw at a position such that n * SRC_WIDTH * (SRC_WIDTH/16.0) > 32768.
     * x = n * 16.
     *
     * To show the bug, we want to draw on either side of the boundary;
     * in our case here, n = 16 results in 32768, and n = 17 results in > 32768.
     *
     * Drawing at 16 and 17 is sufficient to show the problem.
     */

#if 1
    /* n = 16 */
    draw_n (cr, pat, 16.0, 16);

    /* n = 17 */
    draw_n (cr, pat, 16.0, 17);
#else
    {
	int n;
	for (n = 0; n < 32; n++)
	    draw_n (cr, pat, 16.0, n);
    }
#endif

    cairo_pattern_destroy (pat);

    return CAIRO_TEST_SUCCESS;
}