本文整理汇总了C++中cairo_pattern_create_for_surface函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_pattern_create_for_surface函数的具体用法?C++ cairo_pattern_create_for_surface怎么用?C++ cairo_pattern_create_for_surface使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cairo_pattern_create_for_surface函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mark_paint_group
//=================================================================================
// 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);
}
示例2: gvloadimage_process_surface
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;
}
示例3: tileImage
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;
}
示例4: mask_surface_repeat
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);
}
示例5: gtk_css_style_render_icon_surface
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);
}
}
示例6: cairo_pattern_create_for_surface_l
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 );
}
示例7: main
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;
}
示例8: composite_checker
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);
}
示例9: gimp_cairo_stipple_pattern_create
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;
}
示例10: _cairo_default_context_pop_group
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;
}
示例11: draw
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;
}
示例12: main
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);
}
示例13: composite_image_onto_desktop
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;
}
示例14: updateMatrix
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();
}
}
示例15: set_desktop_background
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
}