Ejemplo n.º 1
0
void wxGISDisplay::InitTransformMatrix(void)
{
	m_dFrameCenterX = m_oDeviceFrameRect.GetWidth() / 2;
	m_dFrameCenterY = m_oDeviceFrameRect.GetHeight() / 2;
	double dWorldCenterX = (m_CurrentBounds.MaxX - m_CurrentBounds.MinX) / 2;
	double dWorldCenterY = (m_CurrentBounds.MaxY - m_CurrentBounds.MinY) / 2;

	//origin (UL corner)
	m_dOrigin_X = m_dCacheCenterX - m_dFrameCenterX;
	m_dOrigin_Y = m_dCacheCenterY - m_dFrameCenterY;
	//get scale
	double dScaleX = fabs(m_dFrameCenterX / dWorldCenterX);
	double dScaleY = fabs(m_dFrameCenterY / dWorldCenterY);
    m_dScale = wxMin(dScaleX, dScaleY);

	double dWorldDeltaX = dWorldCenterX + m_CurrentBounds.MinX;
	double dWorldDeltaY = dWorldCenterY + m_CurrentBounds.MinY;

	double dWorldDeltaXSt = m_dScale * dWorldDeltaX;// + m_dAngleRad * dWorldDeltaY;
	double dWorldDeltaYSt = m_dScale * dWorldDeltaY;//m_dAngleRad * dWorldDeltaX +

	//double dCenterX = m_dCacheCenterX - dWorldDeltaXSt;//(dWorldCenterX + m_CurrentBounds.MinX) * dScale;//
	//double dCenterY = m_dCacheCenterY + dWorldDeltaYSt;//(dWorldCenterY + m_CurrentBounds.MinY) * dScale;//
	m_dFrameXShift = m_dFrameCenterX - dWorldDeltaXSt;//(dWorldCenterX + m_CurrentBounds.MinX) * dScale;//
	m_dFrameYShift = m_dFrameCenterY + dWorldDeltaYSt;//(dWorldCenterY + m_CurrentBounds.MinY) * dScale;//

//	cairo_matrix_init (m_pMatrix, 1, 0, 0, 1, m_dCacheCenterX, m_dCacheCenterY);
	//cairo_matrix_init (m_pMatrix, dScale, 0.0, 0.0, -dScale, dCenterX, dCenterY);
	cairo_matrix_init_translate (m_pMatrix, m_dCacheCenterX, m_dCacheCenterY);
	//rotate
	//cairo_matrix_rotate(m_pMatrix, 45.0 * M_PI / 180.0);
	if(!IsDoubleEquil(m_dAngleRad, 0.0))
	//{
		//cairo_matrix_translate(m_pMatrix, dWorldDeltaXSt, dWorldDeltaYSt);
		cairo_matrix_rotate(m_pMatrix, m_dAngleRad);
		//cairo_matrix_translate(m_pMatrix, -dWorldDeltaXSt, dWorldDeltaYSt);
	//}
	//else
	cairo_matrix_translate(m_pMatrix, -dWorldDeltaXSt, dWorldDeltaYSt);

	cairo_matrix_scale(m_pMatrix, m_dScale, -m_dScale);

	//init matrix for Wld2DC & DC2Wld
	cairo_matrix_init_translate (m_pDisplayMatrix, m_dFrameCenterX, m_dFrameCenterY);
	if(!IsDoubleEquil(m_dAngleRad, 0.0))
		cairo_matrix_rotate(m_pDisplayMatrix, m_dAngleRad);
	cairo_matrix_translate(m_pDisplayMatrix, -dWorldDeltaXSt, dWorldDeltaYSt);
	cairo_matrix_scale(m_pDisplayMatrix, m_dScale, -m_dScale);

	//init matrix for TransformRect
	cairo_matrix_init_translate (m_pDisplayMatrixNoRotate, m_dFrameCenterX, m_dFrameCenterY);
	cairo_matrix_translate(m_pDisplayMatrixNoRotate, -dWorldDeltaXSt, dWorldDeltaYSt);
	cairo_matrix_scale(m_pDisplayMatrixNoRotate, m_dScale, -m_dScale);

	//set matrix to all caches
	for(size_t i = 0; i < m_saLayerCaches.size(); ++i)
		cairo_set_matrix (m_saLayerCaches[i].pCairoContext, m_pMatrix);
}
Ejemplo n.º 2
0
static cairo_int_status_t
render_glyphs_via_mask (cairo_gl_surface_t *dst,
			int dst_x, int dst_y,
			cairo_operator_t  op,
			cairo_surface_t *source,
			cairo_composite_glyphs_info_t *info)
{
    cairo_surface_t *mask;
    cairo_status_t status;
    cairo_bool_t has_component_alpha;

    TRACE ((stderr, "%s\n", __FUNCTION__));

    /* XXX: For non-CA, this should be CAIRO_CONTENT_ALPHA to save memory */
    mask = cairo_gl_surface_create (dst->base.device,
                                    CAIRO_CONTENT_COLOR_ALPHA,
                                    info->extents.width,
                                    info->extents.height);
    if (unlikely (mask->status))
        return mask->status;

    status = render_glyphs ((cairo_gl_surface_t *) mask,
			    info->extents.x, info->extents.y,
			    CAIRO_OPERATOR_ADD, NULL,
			    info, &has_component_alpha);
    if (likely (status == CAIRO_STATUS_SUCCESS)) {
	cairo_surface_pattern_t mask_pattern;
	cairo_surface_pattern_t source_pattern;

	mask->is_clear = FALSE;
	_cairo_pattern_init_for_surface (&mask_pattern, mask);
	mask_pattern.base.has_component_alpha = has_component_alpha;
	mask_pattern.base.filter = CAIRO_FILTER_NEAREST;
	mask_pattern.base.extend = CAIRO_EXTEND_NONE;

	cairo_matrix_init_translate (&mask_pattern.base.matrix,
		                     dst_x-info->extents.x, dst_y-info->extents.y);

	_cairo_pattern_init_for_surface (&source_pattern, source);
	cairo_matrix_init_translate (&source_pattern.base.matrix,
		                     dst_x-info->extents.x, dst_y-info->extents.y);

	status = _cairo_surface_mask (&dst->base, op,
		                      &source_pattern.base,
				      &mask_pattern.base,
				      NULL);

	_cairo_pattern_fini (&mask_pattern.base);
	_cairo_pattern_fini (&source_pattern.base);
    }

    cairo_surface_destroy (mask);

    return status;
}
Ejemplo n.º 3
0
cairo_status_t
_cairo_surface_offset_mask (cairo_surface_t		*target,
			    int x, int y,
			    cairo_operator_t		 op,
			    const cairo_pattern_t	*source,
			    const cairo_pattern_t	*mask,
			    cairo_clip_t		*clip)
{
    cairo_status_t status;
    cairo_clip_t clip_copy, *dev_clip = clip;
    cairo_pattern_union_t source_copy;
    cairo_pattern_union_t mask_copy;

    if (unlikely (target->status))
	return target->status;

    if (clip && clip->all_clipped)
	return CAIRO_STATUS_SUCCESS;

    if (x | y) {
	cairo_matrix_t m;

	if (clip != NULL) {
	    cairo_matrix_init_translate (&m, -x, -y);
	    status = _cairo_clip_init_copy_transformed (&clip_copy, clip, &m);
	    if (unlikely (status))
		goto FINISH;

	    dev_clip = &clip_copy;
	}

	cairo_matrix_init_translate (&m, x, y);
	_copy_transformed_pattern (&source_copy.base, source, &m);
	_copy_transformed_pattern (&mask_copy.base, mask, &m);
	source = &source_copy.base;
	mask = &mask_copy.base;
    }

    status = _cairo_surface_mask (target, op,
				  &source_copy.base, &mask_copy.base,
				  dev_clip);

  FINISH:
    if (dev_clip != clip)
	_cairo_clip_reset (dev_clip);

    return status;
}
Ejemplo n.º 4
0
static void
draw_grid (cairo_t *cr, cairo_pattern_t *pattern, int dst_x, int dst_y)
{
    cairo_matrix_t m;

    cairo_save (cr);
    cairo_translate (cr, dst_x, dst_y);
    cairo_scale (cr, 16, 16);
    cairo_rotate (cr, 1);

    cairo_matrix_init_translate (&m, 2560-4, 1280-4);
    cairo_pattern_set_matrix (pattern, &m);
    cairo_set_source (cr, pattern);
    cairo_rectangle (cr, 0, 0, 4, 4);
    cairo_fill (cr);

    cairo_set_source_rgb (cr, .7, .7, .7);
    cairo_set_line_width (cr, 1./16);
    cairo_move_to (cr, 0, 0);
    cairo_line_to (cr, 4, 0);
    cairo_move_to (cr, 0, 2);
    cairo_line_to (cr, 4, 2);
    cairo_move_to (cr, 0, 4);
    cairo_line_to (cr, 4, 4);
    cairo_move_to (cr, 0, 0);
    cairo_line_to (cr, 0, 4);
    cairo_move_to (cr, 2, 0);
    cairo_line_to (cr, 2, 4);
    cairo_move_to (cr, 4, 0);
    cairo_line_to (cr, 4, 4);
    cairo_stroke (cr);

    cairo_restore (cr);
}
Ejemplo n.º 5
0
void RotateEnvelope(OGREnvelope &Env, double dAngle, double dX, double dY)
{
	cairo_matrix_t Matrix;
	cairo_matrix_init_translate(&Matrix, dX, dY);
	cairo_matrix_rotate(&Matrix, dAngle);
	cairo_matrix_translate(&Matrix, -dX, -dY);
	//cairo_matrix_init_rotate(&Matrix, dAngle);
	double X1 = Env.MinX;
	double Y1 = Env.MaxY;
	double X2 = Env.MaxX;
	double Y2 = Env.MaxY;
	double X3 = Env.MaxX;
	double Y3 = Env.MinY;
	double X4 = Env.MinX;
	double Y4 = Env.MinY;

	cairo_matrix_transform_point(&Matrix, &X1, &Y1);
	cairo_matrix_transform_point(&Matrix, &X2, &Y2);
	cairo_matrix_transform_point(&Matrix, &X3, &Y3);
	cairo_matrix_transform_point(&Matrix, &X4, &Y4);

    Env.MinX = wxMin(wxMin(X1, X2), wxMin(X3, X4));
    Env.MinY = wxMin(wxMin(Y1, Y2), wxMin(Y3, Y4));
    Env.MaxX = wxMax(wxMax(X1, X2), wxMax(X3, X4));
    Env.MaxY = wxMax(wxMax(Y1, Y2), wxMax(Y3, Y4));
}
Ejemplo n.º 6
0
cairo_status_t
_cairo_surface_offset_paint (cairo_surface_t		*target,
			     int x, int y,
			     cairo_operator_t		 op,
			     const cairo_pattern_t	*source,
			     const cairo_clip_t		*clip)
{
    cairo_status_t status;
    cairo_clip_t *dev_clip = (cairo_clip_t *) clip;
    cairo_pattern_union_t source_copy;

    if (unlikely (target->status))
	return target->status;

    if (_cairo_clip_is_all_clipped (clip))
	return CAIRO_STATUS_SUCCESS;

    if (x | y) {
	cairo_matrix_t m;

	dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y);

	cairo_matrix_init_translate (&m, x, y);
	_copy_transformed_pattern (&source_copy.base, source, &m);
	source = &source_copy.base;
    }

    status = _cairo_surface_paint (target, op, source, dev_clip);

    if (dev_clip != clip)
	_cairo_clip_destroy (dev_clip);

    return status;
}
Ejemplo n.º 7
0
static cairo_status_t
_cairo_surface_subsurface_acquire_source_image (void                    *abstract_surface,
						cairo_image_surface_t  **image_out,
						void                   **extra_out)
{
    cairo_surface_subsurface_t *surface = abstract_surface;
    cairo_surface_pattern_t pattern;
    cairo_surface_t *image;
    cairo_status_t status;

    image = _cairo_image_surface_create_with_content (surface->base.content,
						      surface->extents.width,
						      surface->extents.height);
    if (unlikely (image->status))
	return image->status;

    _cairo_pattern_init_for_surface (&pattern, surface->target);
    cairo_matrix_init_translate (&pattern.base.matrix,
				 surface->extents.x,
				 surface->extents.y);
    pattern.base.filter = CAIRO_FILTER_NEAREST;
    status = _cairo_surface_paint (image,
				   CAIRO_OPERATOR_SOURCE,
				   &pattern.base, NULL);
    _cairo_pattern_fini (&pattern.base);
    if (unlikely (status)) {
	cairo_surface_destroy (image);
	return status;
    }

    *image_out = (cairo_image_surface_t *)image;
    *extra_out = NULL;
    return CAIRO_STATUS_SUCCESS;
}
Ejemplo n.º 8
0
Archivo: gtk9slice.c Proyecto: BYC/gtk
static void
render_border (cairo_t              *cr,
               cairo_surface_t      *surface,
               guint                 side,
               gdouble               x,
               gdouble               y,
               gdouble               width,
               gdouble               height,
               GtkSliceSideModifier  modifier)
{
  cairo_pattern_t *pattern;
  cairo_matrix_t matrix;

  cairo_save (cr);

  cairo_rectangle (cr, x, y, width, height);
  cairo_clip (cr);

  pattern = cairo_pattern_create_for_surface (surface);

  if (modifier == GTK_SLICE_REPEAT)
    {
      cairo_matrix_init_translate (&matrix, - x, - y);
      cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

      cairo_pattern_set_matrix (pattern, &matrix);
      cairo_set_source (cr, pattern);

      cairo_rectangle (cr, x, y, width, height);
      cairo_fill (cr);
    }
  else
    {
      /* Use nearest filter so borders aren't blurred */
      cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);

      if (side == SIDE_TOP || side == SIDE_BOTTOM)
        {
          gint w = cairo_image_surface_get_width (surface);

          cairo_translate (cr, x, y);
          cairo_scale (cr, width / w, 1.0);
        }
      else
        {
          gint h = cairo_image_surface_get_height (surface);

          cairo_translate (cr, x, y);
          cairo_scale (cr, 1.0, height / h);
        }

      cairo_set_source (cr, pattern);
      cairo_rectangle (cr, x, y, width, height);
      cairo_paint (cr);
    }

  cairo_restore (cr);

  cairo_pattern_destroy (pattern);
}
Ejemplo n.º 9
0
static cairo_status_t
_cairo_default_context_set_source_surface (void *abstract_cr,
        cairo_surface_t *surface,
        double	   x,
        double	   y)
{
    cairo_default_context_t *cr = abstract_cr;
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;
    cairo_status_t status;

    /* push the current pattern to the freed lists */
    _cairo_default_context_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black);

    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_default_context_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    return status;
}
Ejemplo n.º 10
0
void
_cairo_clip_translate (cairo_clip_t  *clip,
                       cairo_fixed_t  tx,
                       cairo_fixed_t  ty)
{
    if (clip->region) {
        pixman_region_translate (clip->region,
                                 _cairo_fixed_integer_part (tx),
                                 _cairo_fixed_integer_part (ty));
    }

    if (clip->surface) {
        clip->surface_rect.x += _cairo_fixed_integer_part (tx);
        clip->surface_rect.y += _cairo_fixed_integer_part (ty);
    }

    if (clip->path) {
        cairo_clip_path_t *clip_path = clip->path;
	cairo_matrix_t matrix;

	cairo_matrix_init_translate (&matrix,
				     _cairo_fixed_to_double (tx),
				     _cairo_fixed_to_double (ty));

        while (clip_path) {
            _cairo_path_fixed_device_transform (&clip_path->path, &matrix);
            clip_path = clip_path->prev;
        }
    }
}
Ejemplo n.º 11
0
bool ScreenAreaCairo::on_draw(const Cairo::RefPtr<Cairo::Context> &poContext)
{
	DrawingArea::on_draw(poContext);

	Cairo::RefPtr< Cairo::ImageSurface >   poImage;
	Cairo::RefPtr< Cairo::SurfacePattern > poPattern;
	Cairo::Matrix oMatrix;
	const int iScaledPitch = m_iWidth * sizeof(u32);

	poContext->set_identity_matrix();
	poContext->scale(m_dScaleFactor, m_dScaleFactor);

	poImage = Cairo::ImageSurface::create((u8 *)m_puiPixels, Cairo::FORMAT_RGB24,
	                                      m_iWidth, m_iHeight, iScaledPitch);

	cairo_matrix_init_translate(&oMatrix, -m_iAreaLeft, -m_iAreaTop);
	poPattern = Cairo::SurfacePattern::create(poImage);
	poPattern->set_filter(Cairo::FILTER_NEAREST);
	poPattern->set_matrix (oMatrix);
	poContext->set_source_rgb(0.0, 0.0, 0.0);
	poContext->paint();

	poContext->set_source(poPattern);
	poContext->paint();

	return true;
}
Ejemplo n.º 12
0
static cairo_surface_t *
_cairo_surface_subsurface_snapshot (void *abstract_surface)
{
    cairo_surface_subsurface_t *surface = abstract_surface;
    cairo_surface_pattern_t pattern;
    cairo_surface_t *clone;
    cairo_status_t status;

    TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, surface->target->unique_id));

    clone = _cairo_surface_create_similar_scratch (surface->target,
						   surface->target->content,
						   surface->extents.width,
						   surface->extents.height);
    if (unlikely (clone->status))
	return clone;

    _cairo_pattern_init_for_surface (&pattern, surface->target);
    cairo_matrix_init_translate (&pattern.base.matrix,
				 surface->extents.x, surface->extents.y);
    pattern.base.filter = CAIRO_FILTER_NEAREST;
    status = _cairo_surface_paint (clone,
				   CAIRO_OPERATOR_SOURCE,
				   &pattern.base, NULL);
    _cairo_pattern_fini (&pattern.base);

    if (unlikely (status)) {
	cairo_surface_destroy (clone);
	clone = _cairo_surface_create_in_error (status);
    }

    return clone;
}
Ejemplo n.º 13
0
static int m_cairo_matrix_init_translate(lua_State * L)
{
	cairo_matrix_t * matrix = luaL_checkudata(L, 1, MT_NAME_CAIRO_MATRIX);
	double tx = luaL_checknumber(L, 2);
	double ty = luaL_checknumber(L, 3);
	cairo_matrix_init_translate(matrix, tx, ty);
	return 0;
}
Ejemplo n.º 14
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct image *image = data;
	struct rectangle allocation;
	cairo_t *cr;
	cairo_surface_t *surface;
	double width, height, doc_aspect, window_aspect, scale;
	cairo_matrix_t matrix;
	cairo_matrix_t translate;

	surface = window_get_surface(image->window);
	cr = cairo_create(surface);
	widget_get_allocation(image->widget, &allocation);
	cairo_rectangle(cr, allocation.x, allocation.y,
			allocation.width, allocation.height);
	cairo_clip(cr);
	cairo_push_group(cr);
	cairo_translate(cr, allocation.x, allocation.y);

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_rgba(cr, 0, 0, 0, 1);
	cairo_paint(cr);

	if (!image->initialized) {
		image->initialized = true;
		width = cairo_image_surface_get_width(image->image);
		height = cairo_image_surface_get_height(image->image);

		doc_aspect = width / height;
		window_aspect = (double) allocation.width / allocation.height;
		if (doc_aspect < window_aspect)
			scale = allocation.height / height;
		else
			scale = allocation.width / width;

		image->width = width;
		image->height = height;
		cairo_matrix_init_scale(&image->matrix, scale, scale);

		clamp_view(image);
	}

	matrix = image->matrix;
	cairo_matrix_init_translate(&translate, allocation.x, allocation.y);
	cairo_matrix_multiply(&matrix, &matrix, &translate);
	cairo_set_matrix(cr, &matrix);

	cairo_set_source_surface(cr, image->image, 0, 0);
	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
	cairo_paint(cr);

	cairo_pop_group_to_source(cr);
	cairo_paint(cr);
	cairo_destroy(cr);

	cairo_surface_destroy(surface);
}
Ejemplo n.º 15
0
/**
 * cairo_matrix_translate:
 * @matrix: a #cairo_matrix_t
 * @tx: amount to translate in the X direction
 * @ty: amount to translate in the Y direction
 *
 * Applies a translation by @tx, @ty to the transformation in
 * @matrix. The effect of the new transformation is to first translate
 * the coordinates by @tx and @ty, then apply the original transformation
 * to the coordinates.
 **/
void
cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty)
{
    cairo_matrix_t tmp;

    cairo_matrix_init_translate (&tmp, tx, ty);

    cairo_matrix_multiply (matrix, &tmp, matrix);
}
Ejemplo n.º 16
0
cairo_status_t
_cairo_surface_offset_glyphs (cairo_surface_t		*surface,
			      int x, int y,
			      cairo_operator_t		 op,
			      const cairo_pattern_t	*source,
			      cairo_scaled_font_t	*scaled_font,
			      cairo_glyph_t		*glyphs,
			      int			 num_glyphs,
			      const cairo_clip_t	*clip)
{
    cairo_status_t status;
    cairo_clip_t *dev_clip = (cairo_clip_t *) clip;
    cairo_pattern_union_t source_copy;
    cairo_glyph_t *dev_glyphs;
    int i;

    if (unlikely (surface->status))
	return surface->status;

    if (_cairo_clip_is_all_clipped (clip))
	return CAIRO_STATUS_SUCCESS;

    dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
    if (dev_glyphs == NULL)
	return _cairo_error (CAIRO_STATUS_NO_MEMORY);

    memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs);

    if (x | y) {
	cairo_matrix_t m;

	dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y);

	cairo_matrix_init_translate (&m, x, y);
	_copy_transformed_pattern (&source_copy.base, source, &m);
	source = &source_copy.base;

	for (i = 0; i < num_glyphs; i++) {
	    dev_glyphs[i].x -= x;
	    dev_glyphs[i].y -= y;
	}
    }

    status = _cairo_surface_show_text_glyphs (surface, op, source,
					      NULL, 0,
					      dev_glyphs, num_glyphs,
					      NULL, 0, 0,
					      scaled_font,
					      dev_clip);

    if (dev_clip != clip)
	_cairo_clip_destroy (dev_clip);
    cr_free (dev_glyphs);

    return status;
}
Ejemplo n.º 17
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, saved_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_get_matrix (cr, &saved_matrix);
  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);
    }

  cairo_set_matrix (cr, &saved_matrix);
}
Ejemplo n.º 18
0
cairo_status_t
_cairo_surface_offset_fill (cairo_surface_t	*surface,
			    int x, int y,
			    cairo_operator_t	 op,
			    const cairo_pattern_t*source,
			    const cairo_path_fixed_t	*path,
			    cairo_fill_rule_t	 fill_rule,
			    double		 tolerance,
			    cairo_antialias_t	 antialias,
			    const cairo_clip_t	*clip)
{
    cairo_status_t status;
    cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path;
    cairo_clip_t *dev_clip = (cairo_clip_t *) clip;
    cairo_pattern_union_t source_copy;

    if (unlikely (surface->status))
	return surface->status;

    if (_cairo_clip_is_all_clipped (clip))
	return CAIRO_STATUS_SUCCESS;

    if (x | y) {
	cairo_matrix_t m;

	dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y);

	status = _cairo_path_fixed_init_copy (&path_copy, dev_path);
	if (unlikely (status))
	    goto FINISH;

	_cairo_path_fixed_translate (&path_copy,
				     _cairo_fixed_from_int (-x),
				     _cairo_fixed_from_int (-y));
	dev_path = &path_copy;

	cairo_matrix_init_translate (&m, x, y);
	_copy_transformed_pattern (&source_copy.base, source, &m);
	source = &source_copy.base;
    }

    status = _cairo_surface_fill (surface, op, source,
				  dev_path, fill_rule,
				  tolerance, antialias,
				  dev_clip);

FINISH:
    if (dev_path != path)
	_cairo_path_fixed_fini (dev_path);
    if (dev_clip != clip)
	_cairo_clip_destroy (dev_clip);

    return status;
}
static cairo_int_status_t
_cairo_gl_surface_show_glyphs_via_mask (cairo_gl_surface_t	*dst,
			                cairo_operator_t	 op,
					const cairo_pattern_t	*source,
					cairo_glyph_t		*glyphs,
					int			 num_glyphs,
					const cairo_rectangle_int_t *glyph_extents,
					cairo_scaled_font_t	*scaled_font,
					cairo_clip_t		*clip,
					int			*remaining_glyphs)
{
    cairo_surface_t *mask;
    cairo_status_t status;
    cairo_solid_pattern_t solid;
    int i;

    mask = cairo_gl_surface_create (dst->ctx,
	                            CAIRO_CONTENT_ALPHA,
				    glyph_extents->width,
				    glyph_extents->height);
    if (unlikely (mask->status))
	return mask->status;

    for (i = 0; i < num_glyphs; i++) {
	glyphs[i].x -= glyph_extents->x;
	glyphs[i].y -= glyph_extents->y;
    }

    _cairo_pattern_init_solid (&solid, CAIRO_COLOR_WHITE, CAIRO_CONTENT_ALPHA);
    status = _render_glyphs ((cairo_gl_surface_t *) mask, 0, 0,
	                     CAIRO_OPERATOR_ADD, &solid.base,
	                     glyphs, num_glyphs, glyph_extents,
			     scaled_font, NULL, remaining_glyphs);
    if (likely (status == CAIRO_STATUS_SUCCESS)) {
	cairo_surface_pattern_t mask_pattern;

	_cairo_pattern_init_for_surface (&mask_pattern, mask);
	cairo_matrix_init_translate (&mask_pattern.base.matrix,
		                     -glyph_extents->x, -glyph_extents->y);
	status = _cairo_surface_mask (&dst->base, op,
		                      source, &mask_pattern.base, clip);
	_cairo_pattern_fini (&mask_pattern.base);
    } else {
	for (i = 0; i < num_glyphs; i++) {
	    glyphs[i].x += glyph_extents->x;
	    glyphs[i].y += glyph_extents->y;
	}
	*remaining_glyphs = num_glyphs;
    }

    cairo_surface_destroy (mask);
    return status;
}
static cairo_scaled_font_t *
create_scaled_font (cairo_t * cr)
{
    FcPattern *pattern, *resolved;
    FcResult result;
    cairo_font_face_t *font_face;
    cairo_scaled_font_t *scaled_font;
    cairo_font_options_t *font_options;
    cairo_matrix_t font_matrix, ctm;
    double pixel_size;

    font_options = cairo_font_options_create ();

    cairo_get_font_options (cr, font_options);

    pattern = FcPatternCreate ();

    FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *)"Bitstream Vera Sans");
    FcPatternAddDouble (pattern, FC_PIXEL_SIZE, TEXT_SIZE);
    FcConfigSubstitute (NULL, pattern, FcMatchPattern);

    cairo_ft_font_options_substitute (font_options, pattern);

    FcDefaultSubstitute (pattern);
    resolved = FcFontMatch (NULL, pattern, &result);

    /* set layout to vertical */
    FcPatternDel (resolved, FC_VERTICAL_LAYOUT);
    FcPatternAddBool (resolved, FC_VERTICAL_LAYOUT, FcTrue);

    FcPatternGetDouble (resolved, FC_PIXEL_SIZE, 0, &pixel_size);

    font_face = cairo_ft_font_face_create_for_pattern (resolved);

    cairo_matrix_init_translate (&font_matrix, 10, 30);
    cairo_matrix_rotate (&font_matrix, M_PI_2/3);
    cairo_matrix_scale (&font_matrix, pixel_size, pixel_size);

    cairo_get_matrix (cr, &ctm);

    scaled_font = cairo_scaled_font_create (font_face,
					    &font_matrix,
					    &ctm,
					    font_options);

    cairo_font_options_destroy (font_options);
    cairo_font_face_destroy (font_face);
    FcPatternDestroy (pattern);
    FcPatternDestroy (resolved);

    return scaled_font;
}
Ejemplo n.º 21
0
void
e_canvas_item_move_absolute (GnomeCanvasItem *item,
                             gdouble dx,
                             gdouble dy)
{
	cairo_matrix_t translate;

	g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));

	cairo_matrix_init_translate (&translate, dx, dy);

	gnome_canvas_item_set_matrix (item, &translate);
}
Ejemplo n.º 22
0
void
gtk_css_style_render_icon (GtkCssStyle            *style,
                           cairo_t                *cr,
                           double                  x,
                           double                  y,
                           double                  width,
                           double                  height,
                           GtkCssImageBuiltinType  builtin_type)
{
  const GtkCssValue *shadows;
  cairo_matrix_t matrix, transform_matrix, saved_matrix;
  GtkCssImage *image;

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

  image = _gtk_css_image_value_get_image (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SOURCE));
  if (image == NULL)
    return;

  cairo_get_matrix (cr, &saved_matrix);

  shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);

  cairo_translate (cr, x, y);

  if (_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
    {
      /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
      cairo_matrix_init_translate (&matrix, width / 2, height / 2);
      cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
      cairo_matrix_translate (&matrix, - width / 2, - height / 2);

      if (_gtk_css_shadows_value_is_none (shadows))
        {
          cairo_transform (cr, &matrix);
          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
        }
      else
        {
          cairo_push_group (cr);
          cairo_transform (cr, &matrix);
          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
          cairo_pop_group_to_source (cr);
          _gtk_css_shadows_value_paint_icon (shadows, cr);
          cairo_paint (cr);
        }
    }

  cairo_set_matrix (cr, &saved_matrix);
}
Ejemplo n.º 23
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);
    }
}
Ejemplo n.º 24
0
/**
 * adg_table_cell_arrange:
 * @table_cell: an #AdgTableCell
 * @layout: the new extents to use
 *
 * Rearranges the underlying #AdgTableCell owned by @table_cell using
 * the new extents provided in @layout. If the x or y size component
 * of @layout is negative, the value holded by the internal extents
 * struct is not overriden.
 *
 * <note><para>
 * table_cell->extents must be up to date if @layout->size.x or
 * @layout->size.y is negative in order to have a valid size.
 * </para></note>
 *
 * Returns: the extents of @table_cell or <constant>NULL</constant> on errors.
 *
 * Since: 1.0
 **/
const CpmlExtents *
adg_table_cell_arrange(AdgTableCell *table_cell, const CpmlExtents *layout)
{
    CpmlExtents *extents;
    AdgAlignment *alignment;
    cairo_matrix_t map;

    /* Set the new extents */
    extents = &table_cell->extents;
    extents->org = layout->org;
    if (layout->size.x > 0)
        extents->size.x = layout->size.x;
    if (layout->size.y > 0)
        extents->size.y = layout->size.y;
    extents->is_defined = TRUE;

    if (table_cell->title) {
        alignment = (AdgAlignment *) adg_entity_get_parent(table_cell->title);

        cairo_matrix_init_translate(&map, extents->org.x, extents->org.y);
        adg_entity_set_global_map((AdgEntity *) alignment, &map);
    }

    if (table_cell->value) {
        CpmlPair to;

        alignment = (AdgAlignment *) adg_entity_get_parent(table_cell->value);
        to.x = extents->size.x * table_cell->value_factor.x + extents->org.x;
        to.y = extents->size.y * table_cell->value_factor.y + extents->org.y;

        cairo_matrix_init_translate(&map, to.x, to.y);
        adg_entity_set_global_map((AdgEntity *) alignment, &map);
    }

    return extents;
}
Ejemplo n.º 25
0
void Drawer::Rotation(double aAngle)
{
    mAngle = aAngle * M_PI / 180;

    double CentreX = 0.0;
    double CentreY = 0.0;
    cairo_matrix_t MatriceTranslate;
    cairo_matrix_t MatriceRotate;

    cairo_get_current_point(mCairoDC, &CentreX, &CentreY);

    cairo_matrix_init_translate(&MatriceTranslate,CentreX,CentreY);
    cairo_transform (mCairoDC, &MatriceTranslate);
    cairo_matrix_init_rotate(&MatriceRotate, mAngle);
    cairo_transform (mCairoDC, &MatriceRotate);
}
Ejemplo n.º 26
0
/**
 * _adg_size_allocate:
 * @widget: an #AdgGtkArea widget
 * @allocation: the new allocation struct
 *
 * Scales the drawing according to the new allocation if
 * #AdgGtkArea:autozoom is <constant>TRUE</constant>.
 *
 * TODO: the current implementation initially centers the canvas
 * on the allocation space. Further allocations (due to a
 * window resizing, for example) use the top/left corner of the
 * canvas as reference point. Plan different policies for either
 * those situations.
 *
 * Since: 1.0
 **/
static void
_adg_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
    AdgGtkArea *area;
    AdgGtkAreaPrivate *data;
    const CpmlExtents *sheet;
    CpmlVector size;
    gdouble factor;

    if (_ADG_OLD_WIDGET_CLASS->size_allocate)
        _ADG_OLD_WIDGET_CLASS->size_allocate(widget, allocation);

    area = (AdgGtkArea *) widget;
    data = area->data;

    sheet = _adg_get_extents(area);
    if (!sheet->is_defined || sheet->size.x <= 0 || sheet->size.y <= 0)
        return;

    size.x = allocation->width;
    size.y = allocation->height;

    if (data->autozoom)  {
        /* Adjust the zoom according to the allocation and sheet size */
        factor = MIN(size.x / sheet->size.x, size.y / sheet->size.y);
    } else if (!data->initialized) {
        /* First allocation with autozoom off: keep the current zoom */
        factor = 1;
    } else {
        /* Not the first allocation and autozoom off: keep the old map */
        return;
    }

    if (!data->initialized) {
        /* TODO: plan different attachment policies other than centering */
        cairo_matrix_init_translate(&data->render_map,
                                    (size.x - sheet->size.x) / 2 - sheet->org.x,
                                    (size.y - sheet->size.y) / 2 - sheet->org.y);
        data->initialized = TRUE;
    }

    /* TODO: plan other reference points other than left/top (x0, y0) */
    data->render_map.x0 *= factor;
    data->render_map.y0 *= factor;
    data->render_map.xx *= factor;
    data->render_map.yy *= factor;
}
Ejemplo n.º 27
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);
    }
}
Ejemplo n.º 28
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;

}
Ejemplo n.º 29
0
cairo_status_t
_cairo_surface_fallback_clone_similar (cairo_surface_t	*surface,
				       cairo_surface_t	*src,
				       cairo_content_t	 content,
				       int		 src_x,
				       int		 src_y,
				       int		 width,
				       int		 height,
				       int		*clone_offset_x,
				       int		*clone_offset_y,
				       cairo_surface_t **clone_out)
{
    cairo_surface_t *new_surface;
    cairo_surface_pattern_t pattern;
    cairo_status_t status;

    new_surface = _cairo_surface_create_similar_scratch (surface,
							 src->content & content,
							 width, height);
    if (new_surface->status)
	return new_surface->status;

    /* We have to copy these here, so that the coordinate spaces are correct */
    new_surface->device_transform = src->device_transform;
    new_surface->device_transform_inverse = src->device_transform_inverse;

    _cairo_pattern_init_for_surface (&pattern, src);
    cairo_matrix_init_translate (&pattern.base.matrix, src_x, src_y);
    pattern.base.filter = CAIRO_FILTER_NEAREST;

    status = _cairo_surface_paint (new_surface,
				   CAIRO_OPERATOR_SOURCE,
				   &pattern.base, NULL);
    _cairo_pattern_fini (&pattern.base);

    if (unlikely (status)) {
	cairo_surface_destroy (new_surface);
	return status;
    }

    *clone_offset_x = src_x;
    *clone_offset_y = src_y;
    *clone_out = new_surface;
    return CAIRO_STATUS_SUCCESS;
}
Ejemplo n.º 30
0
/**
 * adg_table_cell_set_text_title:
 * @table_cell: a valid #AdgTableCell
 * @title: a text string
 *
 * Convenient function to set a the title of a cell using an #AdgToyText
 * entity with the font dress picked from #AdgTable:table-dress with
 * a call to adg_table_style_get_title_dress().
 *
 * Since: 1.0
 **/
void
adg_table_cell_set_text_title(AdgTableCell *table_cell, const gchar *title)
{
    AdgTable *table;
    AdgEntity *entity;
    AdgTableStyle *table_style;
    const CpmlPair *padding;
    AdgDress table_dress, font_dress;
    cairo_matrix_t map;

    g_return_if_fail(table_cell != NULL);

    if (title == NULL)
        adg_table_cell_set_title(table_cell, NULL);

    if (table_cell->title) {
        gchar *old_title;
        gboolean unchanged;

        if (ADG_IS_TEXTUAL(table_cell->title))
            old_title = adg_textual_dup_text((AdgTextual *) table_cell->title);
        else
            old_title = NULL;

        unchanged = g_strcmp0(title, old_title) == 0;
        g_free(old_title);

        if (unchanged)
            return;
    }

    table = adg_table_cell_get_table(table_cell);
    table_dress = adg_table_get_table_dress(table);
    table_style = (AdgTableStyle *) adg_entity_style((AdgEntity *) table,
                                                     table_dress);
    padding = adg_table_style_get_cell_padding(table_style);
    font_dress = adg_table_style_get_title_dress(table_style);
    entity = g_object_new(ADG_TYPE_BEST_TEXT, "text", title,
                          "font-dress", font_dress, NULL);

    cairo_matrix_init_translate(&map, padding->x, padding->y);
    adg_entity_set_global_map(entity, &map);

    adg_table_cell_set_title(table_cell, entity);
}