Example #1
0
static PyObject *
pattern_set_matrix (PycairoPattern *o, PyObject *args) {
  PycairoMatrix *m;

  if (!PyArg_ParseTuple (args, "O!:Pattern.set_matrix",
			 &PycairoMatrix_Type, &m))
    return NULL;

  cairo_pattern_set_matrix (o->pattern, &m->matrix);
  Py_RETURN_NONE;
}
Example #2
0
void mume_bitblt_image(
    cairo_t *cr, int x1, int y1, int w1, int h1,
    cairo_pattern_t *p, int x2, int y2)
{
    cairo_matrix_t om;
    cairo_pattern_get_matrix(p, &om);
    cairo_save(cr);
    cairo_new_path(cr);
    _mume_bitblt_image(cr, x1, y1, w1, h1, p, x2, y2);
    cairo_restore(cr);
    cairo_pattern_set_matrix(p, &om);
}
Example #3
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);
}
void
S9xGTKDisplayDriver::output (void *src,
                             int  src_pitch,
                             int  x,
                             int  y,
                             int  width,
                             int  height,
                             int  dst_width,
                             int  dst_height)
{
    if (last_known_width != dst_width || last_known_height != dst_height)
    {
        clear ();

        last_known_width = dst_width;
        last_known_height = dst_height;
    }

    cairo_t *cr = window->get_cairo ();

    cairo_surface_t *surface;

    surface = cairo_image_surface_create_for_data ((unsigned char *) src, CAIRO_FORMAT_RGB16_565, width, height, src_pitch);

    cairo_set_source_surface (cr, surface, 0, 0);

    if (width != dst_width || height != dst_height)
    {
        cairo_matrix_t matrix;
        cairo_pattern_t *pattern = cairo_get_source (cr);;

        cairo_matrix_init_identity (&matrix);
        cairo_matrix_scale (&matrix,
                            (double) width / (double) dst_width,
                            (double) height / (double) dst_height);
        cairo_matrix_translate (&matrix, -x, -y);
        cairo_pattern_set_matrix (pattern, &matrix);
        cairo_pattern_set_filter (pattern,
                                  Settings.BilinearFilter
                                       ? CAIRO_FILTER_BILINEAR
                                       : CAIRO_FILTER_NEAREST);
    }

    cairo_rectangle (cr, x, y, dst_width, dst_height);
    cairo_fill (cr);

    cairo_surface_finish (surface);
    cairo_surface_destroy (surface);

    window->release_cairo ();
    window->set_mouseable_area (x, y, width, height);
}
Example #5
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;
}
Example #6
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);
    }
}
Example #7
0
static inline void _mume_bitblt_image(
    cairo_t *cr, int x1, int y1, int w1, int h1,
    cairo_pattern_t *p, int x2, int y2)
{
    /* Similar to BitBlt in win32 GDI. */
    if (w1 > 0 && h1 > 0) {
        cairo_matrix_t matrix;
        cairo_matrix_init_translate(
            &matrix, x2 - x1, y2 - y1);
        cairo_pattern_set_matrix(p, &matrix);
        cairo_rectangle(cr, x1, y1, w1, h1);
        cairo_fill(cr);
    }
}
static void
draw_n (cairo_t *cr, cairo_pattern_t *pat, double dest_size, int n)
{
  cairo_matrix_t mat;

  cairo_matrix_init_scale (&mat, SRC_WIDTH / dest_size, SRC_HEIGHT / dest_size);
  cairo_matrix_translate (&mat, n * -dest_size, 0.0);
  cairo_pattern_set_matrix (pat, &mat);

  cairo_set_source (cr, pat);
  cairo_new_path (cr);
  cairo_rectangle (cr, n * dest_size, 0.0, dest_size, dest_size);
  cairo_fill (cr);
}
Example #9
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;
}
Example #10
0
cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
{
    if (m_gradient && m_platformGradientAlpha == globalAlpha)
        return m_gradient;

    platformDestroy();
    m_platformGradientAlpha = globalAlpha;

    if (m_radial)
        m_gradient = cairo_pattern_create_radial(m_p0.x(), m_p0.y(), m_r0, m_p1.x(), m_p1.y(), m_r1);
    else
        m_gradient = cairo_pattern_create_linear(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());

    Vector<ColorStop>::iterator stopIterator = m_stops.begin();
    while (stopIterator != m_stops.end()) {
#if !PLATFORM(JS) || USE(ACCELERATED_COMPOSITING)
        cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
                                          stopIterator->red, stopIterator->green, stopIterator->blue,
                                          stopIterator->alpha * globalAlpha);
#else
				// Swap the RGBA channels, canvas painting needs to be ARGB
				// but since the channels come out backwards as ABGR we just
				// swap the red and blue to get the same channel format without
				// haveing to go through all of the pixels and swap them post-blit.
				cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
																					stopIterator->blue, stopIterator->green, stopIterator->red,
																					stopIterator->alpha * globalAlpha);
#endif
        ++stopIterator;
    }

    switch (m_spreadMethod) {
    case SpreadMethodPad:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_PAD);
        break;
    case SpreadMethodReflect:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REFLECT);
        break;
    case SpreadMethodRepeat:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REPEAT);
        break;
    }

    cairo_matrix_t matrix = m_gradientSpaceTransformation;
    cairo_matrix_invert(&matrix);
    cairo_pattern_set_matrix(m_gradient, &matrix);

    return m_gradient;
}
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();
    }
}
Example #12
0
static cairo_pattern_t *
_pattern_build_for_cairo (DiaPattern *pattern, const Rectangle *ext)
{
  cairo_pattern_t *pat;
  gsize i;
  real x, y;
  DiaPatternType type;
  guint flags;
  Point p1, p2;
  real r;

  g_return_val_if_fail (pattern != NULL, NULL);

  dia_pattern_get_settings (pattern, &type, &flags);
  dia_pattern_get_points (pattern, &p1, &p2);
  dia_pattern_get_radius (pattern, &r);

  switch (type ) {
  case DIA_LINEAR_GRADIENT :
    pat = cairo_pattern_create_linear (p1.x, p1.y, p2.x, p2.y);
    break;
  case DIA_RADIAL_GRADIENT :
    pat = cairo_pattern_create_radial (p2.x, p2.y, 0.0, p1.x, p1.y, r);
    break;
  default :
    g_warning ("_pattern_build_for_cairo non such.");
    return NULL;
  }
  /* this must only be optionally done */
  if ((flags & DIA_PATTERN_USER_SPACE)==0) {
    cairo_matrix_t matrix;
    real w = ext->right - ext->left;
    real h = ext->bottom - ext->top;
    cairo_matrix_init (&matrix, w, 0.0, 0.0, h, ext->left, ext->top);
    cairo_matrix_invert (&matrix);
    cairo_pattern_set_matrix (pat, &matrix);
  }
  if (flags & DIA_PATTERN_EXTEND_PAD)
    cairo_pattern_set_extend (pat, CAIRO_EXTEND_PAD);
  else if (flags & DIA_PATTERN_EXTEND_REPEAT)
    cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
  else if (flags & DIA_PATTERN_EXTEND_REFLECT)
    cairo_pattern_set_extend (pat, CAIRO_EXTEND_REFLECT);

  dia_pattern_foreach (pattern, _add_color_stop, pat);

  return pat;
}
Example #13
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);
}
Example #14
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;
}
Example #15
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;

}
Example #16
0
static inline void _mume_stretch_image(
    cairo_t *cr, int x1, int y1, int w1, int h1,
    cairo_pattern_t *p, int x2, int y2, int w2, int h2)
{
    /* Similar to StretchBlt in win32 GDI. */
    if (w1 > 0 && h1 > 0 && w2 > 0 && h2 > 0) {
        cairo_matrix_t matrix;
        double hr = (double)w2 / (double)w1;
        double vr = (double)h2 / (double)h1;
        cairo_matrix_init_translate(
            &matrix, (double)x2 - x1 * hr, (double)y2 - y1 * vr);
        cairo_matrix_scale(&matrix, hr, vr);
        cairo_pattern_set_matrix(p, &matrix);
        cairo_rectangle(cr, x1, y1, w1, h1);
        cairo_fill(cr);
    }
}
Example #17
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;
}
Example #18
0
void Context::copySurface( const SurfaceBase &surface, const Area &srcArea, const Rectf &dstRect )
{
	if( ( dstRect.getWidth() == 0 ) || ( dstRect.getHeight() == 0 ) )
		return;

	save();
	cairo_set_source_surface( mCairo, const_cast<SurfaceBase&>( surface ).getCairoSurface(), 0, 0 );
	cairo_pattern_t *sourcePattern = cairo_get_source( mCairo );
	cairo_matrix_t m;
	cairo_matrix_init_identity( &m );
	cairo_matrix_scale( &m, srcArea.getWidth() / (float)dstRect.getWidth(), srcArea.getHeight() / (float)dstRect.getHeight() );
	cairo_matrix_translate( &m, srcArea.getX1() - dstRect.getX1(), srcArea.getY1() - dstRect.getY1() );
	cairo_pattern_set_matrix( sourcePattern, &m );
	cairo_rectangle( mCairo, dstRect.getX1(), dstRect.getY1(), dstRect.getWidth(), dstRect.getHeight() );
	cairo_fill( mCairo );
	restore();
}
static void 
update_pattern_transform (struct graphics2d *gr)
{
  double a, b, c, d, tx, ty;
  cairo_matrix_t *mat = NULL;

  g_assert (gr != NULL);
  if (gr->pattern == NULL)
    return;

  return;
  /* temporarily disabled: ambiguous behavior */
  /*   cairo_get_matrix (gr->cr, &a, &b, &c, &d, &tx, &ty); */
  mat = cairo_matrix_create ();
  g_assert (mat != NULL);
  cairo_matrix_set_affine (mat, a, b, c, d, tx, ty);
  cairo_pattern_set_matrix (gr->pattern, mat);
  cairo_matrix_destroy (mat);
}
Example #20
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;
}
Example #21
0
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_surface_t *parent_surface;
    cairo_matrix_t group_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);

    parent_surface = _cairo_gstate_get_target (cr->gstate);

    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);
    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_translate (cr->path,
				 _cairo_fixed_from_int (parent_surface->device_transform.x0 - group_surface->device_transform.x0),
				 _cairo_fixed_from_int (parent_surface->device_transform.y0 - group_surface->device_transform.y0));

done:
    cairo_surface_destroy (group_surface);

    return group_pattern;
}
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;
}
Example #23
0
static cairo_status_t
_cairo_skia_context_set_source_surface (void *abstract_cr,
					cairo_surface_t *surface,
					double	   x,
					double	   y)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;
    cairo_status_t status;

    if (surface->type == CAIRO_SURFACE_TYPE_SKIA) {
	cairo_skia_surface_t *esurf = (cairo_skia_surface_t *) surface;
	SkShader *shader;

	shader = SkShader::CreateBitmapShader (*esurf->bitmap,
					       SkShader::kClamp_TileMode, /* XXX */
					       SkShader::kClamp_TileMode);

	cr->paint->setShader (shader);
	shader->unref ();

	cr->paint->setFilterLevel (true ?
		(SkPaint::kLow_FilterLevel) : (SkPaint::kNone_FilterLevel));

	return CAIRO_STATUS_SUCCESS;
    }

    pattern = cairo_pattern_create_for_surface (surface);
    if (unlikely (pattern->status))
	return pattern->status;

    cairo_matrix_init_translate (&matrix, -x, -y);
    cairo_pattern_set_matrix (pattern, &matrix);

    status = _cairo_skia_context_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    return status;
}
Example #24
0
void Image::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, CompositeOperator op)
{
    cairo_t* context = ctxt->platformContext();

    if (!m_source.initialized())
        return;
    
    cairo_surface_t* image = frameAtIndex(m_currentFrame);
    if (!image) // If it's too early we won't have an image yet.
        return;

    IntSize selfSize = size();                       
    FloatRect srcRect(src);
    FloatRect dstRect(dst);

    cairo_save(context);

    // Set the compositing operation.
    setCompositingOperation(context, op, frameHasAlphaAtIndex(m_currentFrame));
    
    // If we're drawing a sub portion of the image or scaling then create
    // a pattern transformation on the image and draw the transformed pattern.
    // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
    float scaleX = srcRect.width() / dstRect.width();
    float scaleY = srcRect.height() / dstRect.height();
    cairo_matrix_t mat = { scaleX,  0, 0 , scaleY, srcRect.x(), srcRect.y() };
    cairo_pattern_set_matrix(pattern, &mat);

    // Draw the image.
    cairo_translate(context, dstRect.x(), dstRect.y());
    cairo_set_source(context, pattern);
    cairo_rectangle(context, 0, 0, dstRect.width(), dstRect.height());
    cairo_fill(context);

    cairo_restore(context);

    startAnimation();

}
Example #25
0
void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& srcRect, GraphicsContext* context)
{
    // If we're drawing a sub portion of the image or scaling then create
    // a pattern transformation on the image and draw the transformed pattern.
    // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
    RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(surface));

    ASSERT(m_state);
    switch (m_state->m_imageInterpolationQuality) {
    case InterpolationNone:
    case InterpolationLow:
        cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_FAST);
        break;
    case InterpolationMedium:
    case InterpolationHigh:
        cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BILINEAR);
        break;
    case InterpolationDefault:
        cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BILINEAR);
        break;
    }
    cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD);

    float scaleX = srcRect.width() / destRect.width();
    float scaleY = srcRect.height() / destRect.height();
    cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, srcRect.x(), srcRect.y() };
    cairo_pattern_set_matrix(pattern.get(), &matrix);

    ShadowBlur& shadow = context->platformContext()->shadowBlur();
    if (shadow.type() != ShadowBlur::NoShadow) {
        if (GraphicsContext* shadowContext = shadow.beginShadowLayer(context, destRect)) {
            drawPatternToCairoContext(shadowContext->platformContext()->cr(), pattern.get(), destRect, 1);
            shadow.endShadowLayer(context);
        }
    }

    cairo_save(m_cr.get());
    drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha());
    cairo_restore(m_cr.get());
}
Example #26
0
static cairo_status_t
test_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *metrics)
{
    test_scaled_font_glyph_t *glyphs = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
								      &test_font_face_glyphs_key);
    int i;
    unsigned char *data;
    cairo_surface_t *image;
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;
    uint8_t byte;

    /* FIXME: We simply crash on out-of-bound glyph indices */

    metrics->x_advance = (glyphs[glyph].width + 1) / 8.0;

    image = cairo_image_surface_create (CAIRO_FORMAT_A1, glyphs[glyph].width, 8);
    data = cairo_image_surface_get_data (image);
    for (i = 0; i < 8; i++) {
	byte = glyphs[glyph].data[i];
	*data = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (byte);
	data += cairo_image_surface_get_stride (image);
    }

    pattern = cairo_pattern_create_for_surface (image);
    cairo_matrix_init_identity (&matrix);
    cairo_matrix_scale (&matrix, 1.0/8.0, 1.0/8.0);
    cairo_matrix_translate (&matrix, 0, -8);
    cairo_matrix_invert (&matrix);
    cairo_pattern_set_matrix (pattern, &matrix);
    cairo_set_source (cr, pattern);
    cairo_mask (cr, pattern);
    cairo_pattern_destroy (pattern);
    cairo_surface_destroy (image);

    return CAIRO_STATUS_SUCCESS;
}
void QCairoPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
{
    double w, h;
    cairo_surface_t *image;
    QImage img=pixmap.toImage().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, s.x(), s.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_REPEAT);

        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();
    }
}
Example #28
0
void cairo_context::set_gradient(cairo_gradient const& pattern, const box2d<double> &bbox)
{
    cairo_pattern_t * gradient = pattern.gradient();
    double bx1=bbox.minx();
    double by1=bbox.miny();
    double bx2=bbox.maxx();
    double by2=bbox.maxy();
    if (pattern.units() != USER_SPACE_ON_USE)
    {
        if (pattern.units() == OBJECT_BOUNDING_BOX)
        {
            cairo_path_extents(cairo_.get(), &bx1, &by1, &bx2, &by2);
        }
        cairo_matrix_t cairo_matrix;
        cairo_pattern_get_matrix(gradient, &cairo_matrix);
        cairo_matrix_scale(&cairo_matrix,1.0/(bx2-bx1),1.0/(by2-by1));
        cairo_matrix_translate(&cairo_matrix, -bx1,-by1);
        cairo_pattern_set_matrix(gradient, &cairo_matrix);
    }
    cairo_set_source(cairo_.get(), const_cast<cairo_pattern_t*>(gradient));
    check_object_status_and_throw_exception(*this);
}
cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
{
    if (m_gradient && m_platformGradientAlpha == globalAlpha)
        return m_gradient;

    platformDestroy();
    m_platformGradientAlpha = globalAlpha;

    if (m_radial)
        m_gradient = cairo_pattern_create_radial(m_p0.x(), m_p0.y(), m_r0, m_p1.x(), m_p1.y(), m_r1);
    else
        m_gradient = cairo_pattern_create_linear(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());

    Vector<ColorStop>::iterator stopIterator = m_stops.begin();
    while (stopIterator != m_stops.end()) {
        cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
                                          stopIterator->red, stopIterator->green, stopIterator->blue,
                                          stopIterator->alpha * globalAlpha);
        ++stopIterator;
    }

    switch (m_spreadMethod) {
    case SpreadMethodPad:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_PAD);
        break;
    case SpreadMethodReflect:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REFLECT);
        break;
    case SpreadMethodRepeat:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REPEAT);
        break;
    }

    cairo_matrix_t matrix = m_gradientSpaceTransformation;
    cairo_matrix_invert(&matrix);
    cairo_pattern_set_matrix(m_gradient, &matrix);

    return m_gradient;
}
Example #30
0
static void
mech_surface_render_impl (MechSurface *surface,
                          cairo_t     *cr)
{
  cairo_surface_t *cairo_surface;
  cairo_pattern_t *pattern;
  MechSurfacePrivate *priv;
  cairo_matrix_t matrix;

  priv = mech_surface_get_instance_private (surface);
  cairo_surface = MECH_SURFACE_GET_CLASS (surface)->get_surface (surface);
  g_assert (cairo_surface != NULL);

  cairo_set_source_surface (cr, cairo_surface, 0, 0);
  pattern = cairo_get_source (cr);
  cairo_pattern_get_matrix (pattern, &matrix);

  cairo_matrix_scale (&matrix, priv->scale_x, priv->scale_y);
  cairo_matrix_translate (&matrix, -priv->cached_rect.x,
                          -priv->cached_rect.y);
  cairo_pattern_set_matrix (pattern, &matrix);
  cairo_paint (cr);
}