コード例 #1
0
ファイル: PdfCache.cpp プロジェクト: wbrenna/xournalpp
void PdfCache::render(cairo_t * cr, XojPopplerPage * popplerPage, double zoom) {
	XOJ_CHECK_TYPE(PdfCache);

	g_mutex_lock(this->renderMutex);

	this->setZoom(zoom);

	cairo_surface_t * img = lookup(popplerPage);
	if (img == NULL) {
		img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, popplerPage->getWidth() * this->zoom, popplerPage->getHeight() * this->zoom);
		cairo_t * cr2 = cairo_create(img);

		cairo_scale(cr2, this->zoom, this->zoom);
		popplerPage->render(cr2, false);
		cairo_destroy(cr2);
		cache(popplerPage, img);
	}

	cairo_matrix_t mOriginal;
	cairo_matrix_t mScaled;
	cairo_get_matrix(cr, &mOriginal);
	cairo_get_matrix(cr, &mScaled);
	mScaled.xx = 1;
	mScaled.yy = 1;
	mScaled.xy = 0;
	mScaled.yx = 0;
	cairo_set_matrix(cr, &mScaled);
	cairo_set_source_surface(cr, img, 0, 0);
	cairo_paint(cr);
	cairo_set_matrix(cr, &mOriginal);

	g_mutex_unlock(this->renderMutex);
}
コード例 #2
0
void address_histogram::render_bars(cairo_t *cr, const plot::bounds_t &bounds)
{
    if(top_addrs.size() < 1 || top_addrs.at(0).count == 0) {
        return;
    }

    cairo_matrix_t original_matrix;

    cairo_get_matrix(cr, &original_matrix);
    cairo_translate(cr, bounds.x, bounds.y);

    double offset_unit = bounds.width / top_addrs.size();
    double bar_width = offset_unit / bar_space_factor;
    double space_width = offset_unit - bar_width;
    uint64_t greatest = top_addrs.at(0).count;
    int index = 0;

    for(vector<iptree::addr_elem>::const_iterator it = top_addrs.begin();
            it != top_addrs.end(); it++) {
	double bar_height = (((double) it->count) / ((double) greatest)) * bounds.height;

	if(bar_height > 0) {
            // bar
            double bar_x = index * offset_unit + space_width;
            double bar_y = bounds.height - bar_height;

            cairo_set_source_rgb(cr, bar_color.r, bar_color.g, bar_color.b);
            cairo_rectangle(cr, bar_x, bar_y, bar_width, bar_height);
            cairo_fill(cr);

            // bar label
            std::string label = it->str();

            // IP6 labels are half size since they're (potentially) much longer
            if(it->is4()) {
                cairo_set_font_size(cr, bar_label_font_size);
            }
            else {
                cairo_set_font_size(cr, bar_label_font_size / 2.0);
            }

            cairo_text_extents_t label_extents;
            cairo_text_extents(cr, label.c_str(), &label_extents);

            cairo_move_to(cr, bar_x + bar_width / 2.0, bar_y);

            cairo_matrix_t unrotated_matrix;
            cairo_get_matrix(cr, &unrotated_matrix);
            cairo_rotate(cr, -M_PI / 4.0);

            cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
            cairo_show_text(cr, label.c_str());

            cairo_set_matrix(cr, &unrotated_matrix);
	}
	index++;
    }

    cairo_set_matrix(cr, &original_matrix);
}
コード例 #3
0
void match(unsigned int position)
{
//     cairo_set_line_cap(cairoOut, CAIRO_LINE_CAP_ROUND);
    
    m_sensorReference.seek(position);
    cairo_matrix_t m1;
    cairo_get_matrix(cairoOut, &m1);
    cairo_identity_matrix(cairoOut);
    cairo_set_source_surface(cairoOut, cairo_get_target(cairoMap), 0., 0.);
    cairo_paint(cairoOut);
    cairo_set_matrix(cairoOut, &m1);
//     cairo_set_line_width(cairoOut, 1./(2.*scaleFactor));
    
    std::vector<InterestPoint *> pointsLocal(m_pointsReference[position].size());
    const LaserReading* lreadReference = dynamic_cast<const LaserReading*>(m_sensorReference.current());
    for(unsigned int j = 0; j < m_pointsReference[position].size(); j++){
	InterestPoint * point = new InterestPoint(*m_pointsReference[position][j]);
	point->setPosition(lreadReference->getLaserPose().ominus(point->getPosition()));
	pointsLocal[j] = point;
    }
    
    
    for(unsigned int i = 0; i < m_pointsReference.size(); i++){
	if(i == position) {
	    continue;
	}
	OrientedPoint2D transform;
	std::vector< std::pair<InterestPoint*, InterestPoint* > > correspondences;
	double result = m_ransac->matchSets(m_pointsReference[i], pointsLocal, transform, correspondences);
	if(correspondences.size() >= corresp) {
	    cairo_matrix_t m;
	    cairo_get_matrix(cairoOut, &m);
	    cairo_translate(cairoOut, transform.x, transform.y);
	    cairo_rotate(cairoOut, transform.theta);
	    
	    cairo_set_source_rgba(cairoOut, 1., 0., 0., 1. - result/(acceptanceSigma * acceptanceSigma * 5.99 * double(pointsLocal.size())));
	    cairo_move_to(cairoOut, 0., -0.3);
	    cairo_line_to(cairoOut, 0.6, 0.);
	    cairo_line_to(cairoOut, 0., 0.3);
	    cairo_close_path(cairoOut);
	    cairo_fill(cairoOut);
	    cairo_set_matrix(cairoOut, &m);
	}
    }
    
    cairo_matrix_t m;
    cairo_get_matrix(cairoOut, &m);
    cairo_translate(cairoOut, lreadReference->getLaserPose().x, lreadReference->getLaserPose().y);
    cairo_rotate(cairoOut, lreadReference->getLaserPose().theta);
    cairo_set_source_rgba(cairoOut, 0., 0., 1., 1.);
    cairo_move_to(cairoOut, 0., -0.3);
    cairo_line_to(cairoOut, 0.6, 0.);
    cairo_line_to(cairoOut, 0., 0.3);
    cairo_close_path(cairoOut);
    cairo_stroke(cairoOut);
    cairo_set_matrix(cairoOut, &m);
//     cairo_show_page(cairoOut);
}
コード例 #4
0
ファイル: ml_cairo.c プロジェクト: DMClambo/pfff
CAMLprim value
ml_cairo_get_matrix (value v_cr)
{
#ifndef ARCH_ALIGN_DOUBLE
  CAMLparam1(v_cr);
  value v = cairo_matrix_alloc();
  cairo_get_matrix (cairo_t_val (v_cr), cairo_matrix_t_val (v));
  CAMLreturn(v);
#else
  cairo_matrix_t mat;
  cairo_get_matrix (cairo_t_val (v_cr), &mat);
  return ml_convert_cairo_matrix_out (&mat);
#endif
}
コード例 #5
0
ファイル: graphic.c プロジェクト: MerelyAPseudonym/SmartSim
/**
 * Renders the SVG, performing any necessary transformations.
 */
void graphic_render (Graphic* self, cairo_t* context) {
	cairo_matrix_t oldMatrix = {0};
	cairo_t* _tmp0_ = NULL;
	cairo_matrix_t _tmp1_ = {0};
	cairo_t* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	RsvgHandle* _tmp5_ = NULL;
	cairo_t* _tmp6_ = NULL;
	cairo_t* _tmp7_ = NULL;
	cairo_matrix_t _tmp8_ = {0};
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = context;
	cairo_get_matrix (_tmp0_, &_tmp1_);
	oldMatrix = _tmp1_;
	_tmp2_ = context;
	_tmp3_ = self->priv->xCentre;
	_tmp4_ = self->priv->yCentre;
	cairo_translate (_tmp2_, (gdouble) (-_tmp3_), (gdouble) (-_tmp4_));
	_tmp5_ = self->priv->svgHandle;
	_tmp6_ = context;
	rsvg_handle_render_cairo (_tmp5_, _tmp6_);
	_tmp7_ = context;
	_tmp8_ = oldMatrix;
	cairo_set_matrix (_tmp7_, &_tmp8_);
}
コード例 #6
0
ファイル: widget.c プロジェクト: posnk/libwtk
void wtk_widget_render(wtk_widget_t *widget, cairo_t *context, int focused)
{
	cllist_t *_w;
	cairo_matrix_t m;
	
	cairo_get_matrix(context, &m);
	cairo_translate(context, widget->rect.x, widget->rect.y);
	cairo_save(context);
	//if (focused)
	//	printf("renderfocus\n");
	if (widget->callbacks.paint)
		widget->callbacks.paint(widget, context, focused);
	else {
		cairo_rectangle(context, 0, 0, widget->rect.w, widget->rect.h);
		cairo_set_source_rgb(context, ((double)0xF6) / 255.0, ((double)0xF4) / 255.0, ((double)0xF2) / 255.0);
		cairo_fill(context);
	}
	cairo_restore(context);

	for (_w = widget->children.next; _w != &(widget->children); _w = _w->next)
		wtk_widget_render((wtk_widget_t *) _w, context, widget->focused == (wtk_widget_t *) _w);

	cairo_set_matrix(context, &m);

	widget->flags &= ~WTK_WIDGET_FLAG_DIRTY;
}
コード例 #7
0
static PyObject *
pycairo_get_matrix (PycairoContext *o)
{
    cairo_matrix_t matrix;
    cairo_get_matrix (o->ctx, &matrix);
    return PycairoMatrix_FromMatrix (&matrix);
}
TransformationMatrix GraphicsContext::getCTM() const
{
    cairo_t* cr = platformContext();
    cairo_matrix_t m;
    cairo_get_matrix(cr, &m);
    return m;
}
コード例 #9
0
ファイル: gfxContext.cpp プロジェクト: typ4rk/mozilla-history
gfxMatrix
gfxContext::CurrentMatrix() const
{
    cairo_matrix_t mat;
    cairo_get_matrix(mCairo, &mat);
    return gfxMatrix(*reinterpret_cast<gfxMatrix*>(&mat));
}
コード例 #10
0
ファイル: geometry.cpp プロジェクト: kangaroo/moon
void
GeometryGroup::Draw (cairo_t *cr)
{
	Transform *transform = GetTransform ();
	cairo_matrix_t saved;
	cairo_get_matrix (cr, &saved);

	if (transform) {
		cairo_matrix_t matrix;
		transform->GetTransform (&matrix);
		cairo_transform (cr, &matrix);
	}
	
	GeometryCollection *children = GetChildren ();
	Geometry *geometry;

	// GeometryGroup is used for Clip (as a Geometry) so Fill (normally setting the fill rule) is never called
	cairo_set_fill_rule (cr, convert_fill_rule (GetFillRule ()));
	
	int children_count = children->GetCount ();
	for (int i = 0; i < children_count; i++) {
		geometry = children->GetValueAt (i)->AsGeometry ();
		
		geometry->Draw (cr);
	}
	
	cairo_set_matrix (cr, &saved);
}
コード例 #11
0
ファイル: gvrender_pango.c プロジェクト: DanielEColi/graphviz
static void cairogen_ellipse(GVJ_t * job, pointf * A, int filled)
{
    obj_state_t *obj = job->obj;
    cairo_t *cr = (cairo_t *) job->context;
    cairo_matrix_t matrix;
    double rx, ry;

    cairogen_set_penstyle(job, cr);

    cairo_get_matrix(cr, &matrix);

    rx = A[1].x - A[0].x;
    ry = A[1].y - A[0].y;

#define RMIN 0.01
if (rx < RMIN) rx = RMIN;
if (ry < RMIN) ry = RMIN;

    cairo_translate(cr, A[0].x, -A[0].y);
    cairo_scale(cr, rx, ry);
    cairo_move_to(cr, 1., 0.);
    cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI);

    cairo_set_matrix(cr, &matrix);

    if (filled == GRADIENT || filled == (RGRADIENT)) {
	cairo_gradient_fill (cr, obj, filled, A, 2);
    }
    else if (filled) {
	cairogen_set_color(cr, &(obj->fillcolor));
	cairo_fill_preserve(cr);
    }
    cairogen_set_color(cr, &(obj->pencolor));
    cairo_stroke(cr);
}
コード例 #12
0
ファイル: font.hpp プロジェクト: JBouron/polybar
    explicit font_fc(cairo_t* cairo, FcPattern* pattern, double offset, double dpi_x, double dpi_y) : font(cairo, offset), m_pattern(pattern) {
      cairo_matrix_t fm;
      cairo_matrix_t ctm;
      cairo_matrix_init_scale(&fm, size(dpi_x), size(dpi_y));
      cairo_get_matrix(m_cairo, &ctm);

      auto fontface = cairo_ft_font_face_create_for_pattern(m_pattern);
      auto opts = cairo_font_options_create();
      m_scaled = cairo_scaled_font_create(fontface, &fm, &ctm, opts);
      cairo_font_options_destroy(opts);
      cairo_font_face_destroy(fontface);

      auto status = cairo_scaled_font_status(m_scaled);
      if (status != CAIRO_STATUS_SUCCESS) {
        throw application_error(sstream() << "cairo_scaled_font_create(): " << cairo_status_to_string(status));
      }

      auto lock = make_unique<utils::ft_face_lock>(m_scaled);
      auto face = static_cast<FT_Face>(*lock);

      if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == FT_Err_Ok) {
        return;
      } else if (FT_Select_Charmap(face, FT_ENCODING_BIG5) == FT_Err_Ok) {
        return;
      } else if (FT_Select_Charmap(face, FT_ENCODING_SJIS) == FT_Err_Ok) {
        return;
      }

      lock.reset();
    }
コード例 #13
0
HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
    // FIXME:  We aren't really doing anything with the 'mayCreateBitmap' flag.  This needs
    // to be addressed.
    if (dstRect.isEmpty())
       return 0;

    // This is probably wrong, and definitely out of date.  Pulled from old SVN
    cairo_surface_t* surface = cairo_get_target(platformContext());
    HDC hdc = cairo_win32_surface_get_dc(surface);   
    SaveDC(hdc);

    // FIXME: We need to make sure a clip is really set on the HDC.
    // Call SetWorldTransform to honor the current Cairo transform.
    SetGraphicsMode(hdc, GM_ADVANCED); // We need this call for themes to honor world transforms.
    cairo_matrix_t mat;
    cairo_get_matrix(platformContext(), &mat);
    XFORM xform;
    xform.eM11 = mat.xx;
    xform.eM12 = mat.xy;
    xform.eM21 = mat.yx;
    xform.eM22 = mat.yy;
    xform.eDx = mat.x0;
    xform.eDy = mat.y0;
    ::SetWorldTransform(hdc, &xform);

    return hdc;
}
コード例 #14
0
IntPoint GraphicsContext::origin()
{
    cairo_matrix_t matrix;
    cairo_t* cr = m_data->cr;
    cairo_get_matrix(cr, &matrix);
    return IntPoint(static_cast<int>(matrix.x0), static_cast<int>(matrix.y0));
}
コード例 #15
0
ファイル: CairoDevice.cpp プロジェクト: anttirt/guidolib
void CairoDevice::SetOrigin( float x, float y )	
{ 
	cairo_matrix_t matrix;
	cairo_get_matrix (fNativeDevice, &matrix);
	matrix.x0 = x;
	matrix.y0 = y;
	cairo_set_matrix (fNativeDevice, &matrix);
}
コード例 #16
0
ファイル: gfxContext.cpp プロジェクト: typ4rk/mozilla-history
void
gfxContext::NudgeCurrentMatrixToIntegers()
{
    cairo_matrix_t mat;
    cairo_get_matrix(mCairo, &mat);
    gfxMatrix(*reinterpret_cast<gfxMatrix*>(&mat)).NudgeToIntegers();
    cairo_set_matrix(mCairo, &mat);
}
コード例 #17
0
static VALUE
cr_get_matrix (VALUE self)
{
  cairo_matrix_t matrix;
  cairo_get_matrix (_SELF, &matrix);
  cr_check_status (_SELF);
  return CRMATRIX2RVAL (&matrix);
}
コード例 #18
0
ファイル: obj_context.c プロジェクト: awesomeWM/oocairo
static int
cr_get_matrix (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_matrix_t mat;
    cairo_get_matrix(*obj, &mat);
    create_lua_matrix(L, &mat);
    return 1;
}
コード例 #19
0
//--------------------------------------------
// transformations
//our openGL wrappers
void ofCairoRenderer::pushMatrix(){
	if(!surface || !cr) return;
	cairo_get_matrix(cr,&tmpMatrix);
	matrixStack.push(tmpMatrix);

	if(!b3D) return;
	modelViewStack.push(modelView);
}
コード例 #20
0
ファイル: CairoBindings.cpp プロジェクト: Gemioli/lime
	value lime_cairo_get_matrix (value handle) {
		
		cairo_matrix_t cm;
		cairo_get_matrix ((cairo_t*)val_data (handle), &cm);
		Matrix3 mat3 = Matrix3 (cm.xx, cm.yx, cm.xy, cm.yy, cm.x0, cm.y0);
		return mat3.Value ();
		
	}
コード例 #21
0
ファイル: CairoBindings.cpp プロジェクト: rushmobius/lime
	value lime_cairo_get_matrix (double handle) {
		
		cairo_matrix_t cm;
		cairo_get_matrix ((cairo_t*)(intptr_t)handle, &cm);
		Matrix3 mat3 = Matrix3 (cm.xx, cm.yx, cm.xy, cm.yy, cm.x0, cm.y0);
		return mat3.Value ();
		
	}
コード例 #22
0
ファイル: openslide-grid.c プロジェクト: MIRCen/openslide
static bool read_tiles(cairo_t *cr,
                       struct _openslide_level *level,
                       struct _openslide_grid *grid,
                       struct region *region,
                       read_tiles_callback_fn callback,
                       void *arg,
                       GError **err) {
  //g_debug("offset: %g %g, advance: %g %g", region->offset_x, region->offset_y, grid->tile_advance_x, grid->tile_advance_y);
  if (fabs(region->offset_x) >= grid->tile_advance_x) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
                "internal error: fabs(offset_x) >= tile_advance_x");
    return false;
  }
  if (fabs(region->offset_y) >= grid->tile_advance_y) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
                "internal error: fabs(offset_y) >= tile_advance_y");
    return false;
  }

  //  cairo_set_source_rgb(cr, 0, 1, 0);
  //  cairo_paint(cr);
  //g_debug("offset: %d %d", region->offset_x, region->offset_y);

  //g_debug("start: %"PRId64" %"PRId64, region->start_tile_x, region->start_tile_y);
  //g_debug("end: %"PRId64" %"PRId64, region->end_tile_x, region->end_tile_y);

  cairo_matrix_t matrix;
  cairo_get_matrix(cr, &matrix);

  int64_t tile_y = region->end_tile_y - 1;

  while (tile_y >= region->start_tile_y) {
    double translate_y = ((tile_y - region->start_tile_y) *
                          grid->tile_advance_y) - region->offset_y;
    int64_t tile_x = region->end_tile_x - 1;

    while (tile_x >= region->start_tile_x) {
      double translate_x = ((tile_x - region->start_tile_x) *
                            grid->tile_advance_x) - region->offset_x;
      //      g_debug("read_tiles %"PRId64" %"PRId64, tile_x, tile_y);
      cairo_translate(cr, translate_x, translate_y);
      bool success = callback(grid, region, cr,
                              level, tile_x, tile_y,
                              arg, err);
      cairo_set_matrix(cr, &matrix);
      if (!success) {
        return false;
      }

      tile_x--;
    }

    tile_y--;
  }

  return true;
}
コード例 #23
0
static void
goo_canvas_polyline_compute_bounds (GooCanvasPolyline     *polyline,
				    cairo_t               *cr,
				    GooCanvasBounds       *bounds)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) polyline;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  GooCanvasPolylineData *polyline_data = polyline->polyline_data;
  GooCanvasBounds tmp_bounds;
  cairo_matrix_t transform;

  if (polyline_data->num_points == 0)
    {
      bounds->x1 = bounds->x2 = bounds->y1 = bounds->y2 = 0.0;
      return;
    }

  /* Use the identity matrix to get the bounds completely in user space. */
  cairo_get_matrix (cr, &transform);
  cairo_identity_matrix (cr);

  goo_canvas_polyline_create_path (polyline, cr);
  goo_canvas_item_simple_get_path_bounds (simple, cr, bounds);

  /* Add on the arrows, if required. */
  if ((polyline_data->start_arrow || polyline_data->end_arrow)
      && polyline_data->num_points >= 2)
    {
      /* We use the stroke pattern to match the style of the line. */
      goo_canvas_style_set_stroke_options (simple_data->style, cr);

      if (polyline_data->start_arrow)
	{
	  goo_canvas_polyline_create_start_arrow_path (polyline, cr);
	  cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1,
			      &tmp_bounds.x2, &tmp_bounds.y2);
	  bounds->x1 = MIN (bounds->x1, tmp_bounds.x1);
	  bounds->y1 = MIN (bounds->y1, tmp_bounds.y1);
	  bounds->x2 = MAX (bounds->x2, tmp_bounds.x2);
	  bounds->y2 = MAX (bounds->y2, tmp_bounds.y2);
	}

      if (polyline_data->end_arrow)
	{
	  goo_canvas_polyline_create_end_arrow_path (polyline, cr);
	  cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1,
			      &tmp_bounds.x2, &tmp_bounds.y2);
	  bounds->x1 = MIN (bounds->x1, tmp_bounds.x1);
	  bounds->y1 = MIN (bounds->y1, tmp_bounds.y1);
	  bounds->x2 = MAX (bounds->x2, tmp_bounds.x2);
	  bounds->y2 = MAX (bounds->y2, tmp_bounds.y2);
	}
    }

  cairo_set_matrix (cr, &transform);
}
コード例 #24
0
//----------------------------------------------------------
void ofCairoRenderer::scale(float xAmnt, float yAmnt, float zAmnt ){
	if(!surface || !cr) return;
	cairo_matrix_t matrix;
	cairo_get_matrix(cr,&matrix);
	cairo_matrix_scale(&matrix,xAmnt,yAmnt);
	cairo_set_matrix(cr,&matrix);

	if(!b3D) return;
	modelView.glScale(xAmnt,yAmnt,zAmnt);
}
コード例 #25
0
AffineTransform GraphicsContext::getCTM(IncludeDeviceScale) const
{
    if (paintingDisabled())
        return AffineTransform();

    cairo_t* cr = platformContext()->cr();
    cairo_matrix_t m;
    cairo_get_matrix(cr, &m);
    return AffineTransform(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0);
}
コード例 #26
0
IntPoint GraphicsContext::translatePoint(const IntPoint& point) const
{
    cairo_matrix_t tm;
    cairo_get_matrix(m_data->cr, &tm);
    double x = point.x();
    double y = point.y();

    cairo_matrix_transform_point(&tm, &x, &y);
    return IntPoint(x, y);
}
コード例 #27
0
//----------------------------------------------------------
void ofCairoRenderer::translate(float x, float y, float z ){
	if(!surface || !cr) return;
	cairo_matrix_t matrix;
	cairo_get_matrix(cr,&matrix);
	cairo_matrix_translate(&matrix,x,y);
	cairo_set_matrix(cr,&matrix);

	if(!b3D) return;
	modelView.glTranslate(ofVec3f(x,y,z));

}
コード例 #28
0
ファイル: gtkrendericon.c プロジェクト: GYGit/gtk
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);
}
コード例 #29
0
ファイル: gtkpixelcache.c プロジェクト: Vort/gtk
static gboolean
context_is_unscaled (cairo_t *cr)
{
  cairo_matrix_t matrix;
  gdouble x, y;

  x = y = 1;
  cairo_get_matrix (cr, &matrix);
  cairo_matrix_transform_distance (&matrix, &x, &y);

  return x == 1 && y == 1;
}
コード例 #30
0
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;
}