static void add_label (struct chart *c, int test, const char *label) { cairo_text_extents_t extents; double dx, x; cairo_save (c->cr); dx = c->width / (double) c->num_tests; if (dx / 2 - PAD < 4) return; cairo_set_font_size (c->cr, dx / 2 - PAD); cairo_text_extents (c->cr, label, &extents); cairo_set_source_rgb (c->cr, .5, .5, .5); x = (test + .5) * dx; cairo_save (c->cr); cairo_translate (c->cr, x, c->height - PAD / 2); cairo_rotate (c->cr, -M_PI/2); cairo_move_to (c->cr, 0, -extents.y_bearing/2); cairo_show_text (c->cr, label); cairo_restore (c->cr); cairo_save (c->cr); cairo_translate (c->cr, x, PAD / 2); cairo_rotate (c->cr, -M_PI/2); cairo_move_to (c->cr, -extents.width, -extents.y_bearing/2); cairo_show_text (c->cr, label); cairo_restore (c->cr); cairo_restore (c->cr); }
static void add_rectangle (cairo_t *cr, double size) { double x, y; if (size < 1) return; cairo_get_current_point (cr, &x, &y); cairo_rel_move_to (cr, -size/2., -size/2.); cairo_rel_line_to (cr, size, 0); cairo_rel_line_to (cr, 0, size); cairo_rel_line_to (cr, -size, 0); cairo_close_path (cr); cairo_save (cr); cairo_translate (cr, -size/2., size); cairo_move_to (cr, x, y); cairo_rotate (cr, M_PI/4); add_rectangle (cr, size / M_SQRT2); cairo_restore (cr); cairo_save (cr); cairo_translate (cr, size/2., size); cairo_move_to (cr, x, y); cairo_rotate (cr, -M_PI/4); add_rectangle (cr, size / M_SQRT2); cairo_restore (cr); }
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); }
void BenchCairo::runFillRectRotate(BenchOutput& output, const BenchParams& params) { cairo_t* cr = cairo_create(screenCairo); configureContext(cr, params); BenchRandom rRect(app); BenchRandom rArgb(app); float cx = (float)params.screenSize.w * 0.5f; float cy = (float)params.screenSize.h * 0.5f; float angle = 0.0f; if (params.source == BENCH_SOURCE_SOLID) { uint32_t i, quantity = params.quantity; for (i = 0; i < quantity; i++, angle += 0.01f) { Fog::RectF r(rRect.getRectF(params.screenSize, params.shapeSize, params.shapeSize)); Fog::Argb32 c0(rArgb.getArgb32()); cairo_translate(cr, cx, cy); cairo_rotate(cr, angle); cairo_translate(cr, -cx, -cy); cairo_set_source_rgba(cr, double(c0.r) * sc, double(c0.g) * sc, double(c0.b) * sc, double(c0.a) * sc); cairo_rectangle(cr, r.x, r.y, r.w, r.h); cairo_fill(cr); cairo_identity_matrix(cr); } } else { uint32_t i, quantity = params.quantity; for (i = 0; i < quantity; i++, angle += 0.01f) { Fog::RectF r(rRect.getRectF(params.screenSize, params.shapeSize, params.shapeSize)); Fog::Argb32 c0(rArgb.getArgb32()); Fog::Argb32 c1(rArgb.getArgb32()); Fog::Argb32 c2(rArgb.getArgb32()); cairo_translate(cr, cx, cy); cairo_rotate(cr, angle); cairo_translate(cr, -cx, -cy); cairo_pattern_t* pattern = createLinearGradient(r.x, r.y, r.x + r.w, r.y + r.h, c0, c1, c2); cairo_set_source(cr, pattern); cairo_rectangle(cr, r.x, r.y, r.w, r.h); cairo_fill(cr); cairo_identity_matrix(cr); cairo_pattern_destroy(pattern); } } cairo_destroy(cr); }
void handle_apply(render_context& ctx) override { if(std::abs(cx_) < DBL_EPSILON && std::abs(cy_) < DBL_EPSILON) { cairo_rotate(ctx.cairo(), angle_); } else { cairo_translate(ctx.cairo(), cx_, cy_); cairo_rotate(ctx.cairo(), angle_); cairo_translate(ctx.cairo(), -cx_, -cy_); } }
void TriangleMarkerImpl::DrawSymbol() { m_icon = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_size*2, m_size*2); m_cairo = cairo_create(m_icon); size_t count = sizeof(g_auge_marker_triangle_points) / sizeof(double) / 2; double offset_x=0, offset_y=0; double cx=m_size; double cy=m_size; double x, y; double size_2 = m_size / 2.0f; cairo_new_path(m_cairo); cairo_translate (m_cairo, cx, cy); //cairo_scale(m_cairo,10,10); cairo_rotate (m_cairo, m_rotation*PI/180.0f); x = g_auge_marker_triangle_points[0][0]; y = g_auge_marker_triangle_points[0][1]; cairo_move_to(m_cairo, x*size_2, y*size_2); for(size_t i=1; i<count; i++) { x = g_auge_marker_triangle_points[i][0]; y = g_auge_marker_triangle_points[i][1]; cairo_line_to(m_cairo, x*size_2, y*size_2); } cairo_close_path(m_cairo); cairo_rotate (m_cairo, m_rotation*PI/180.0f); if(m_pFill!=NULL) { GColor& color = m_pFill->GetColor(); cairo_set_source_rgba(m_cairo, color.GetRedF(), color.GetGreenF(), color.GetBlueF(), color.GetAlphaF()); if(m_pStroke==NULL) { cairo_fill(m_cairo); } else { cairo_fill_preserve(m_cairo); } } if(m_pStroke!=NULL) { set_stroke_style(m_cairo, m_pStroke); cairo_stroke(m_cairo); } //cairo_surface_write_to_png(m_icon, "G:\\temp\\map\\icon.png"); }
static void gtk_css_image_builtin_draw_arrow (GtkCssImage *image, cairo_t *cr, double width, double height, GtkCssImageBuiltinType image_type) { GtkCssImageBuiltin *builtin = GTK_CSS_IMAGE_BUILTIN (image); double line_width; double size; size = MIN (width, height); cairo_translate (cr, width / 2.0, height / 2.0); switch (image_type) { case GTK_CSS_IMAGE_BUILTIN_ARROW_UP: break; case GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN: cairo_rotate (cr, G_PI); break; case GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT: cairo_rotate (cr, 3 * G_PI / 2); break; case GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT: cairo_rotate (cr, G_PI / 2); break; default: g_assert_not_reached (); break; } line_width = size / 3.0 / sqrt (2); cairo_set_line_width (cr, line_width); cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_scale (cr, (size / (size + line_width)), (size / (size + line_width))); cairo_move_to (cr, -size / 2.0, size / 4.0); cairo_rel_line_to (cr, size / 2.0, -size / 2.0); cairo_rel_line_to (cr, size / 2.0, size / 2.0); gdk_cairo_set_source_rgba (cr, &builtin->fg_color); cairo_stroke (cr); }
static void draw (TboObjectBase *self, Frame *frame, cairo_t *cr) { TboObjectPixmap *pixmap = TBO_OBJECT_PIXMAP (self); int w, h; cairo_surface_t *image; GdkPixbuf *pixbuf; GError *error = NULL; char path[255]; tbo_files_expand_path (pixmap->path->str, path); pixbuf = gdk_pixbuf_new_from_file (path, &error); if (!pixbuf) { g_warning ("There's a problem here: %s", error->message); return; } w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); if (!self->width) self->width = w; if (!self->height) self->height = h; float factorw = (float)self->width / (float)w; float factorh = (float)self->height / (float)h; cairo_matrix_t mx = {1, 0, 0, 1, 0, 0}; tbo_object_base_get_flip_matrix (self, &mx); cairo_rectangle(cr, frame->x+2, frame->y+2, frame->width-4, frame->height-4); cairo_clip (cr); cairo_translate (cr, frame->x+self->x, frame->y+self->y); cairo_rotate (cr, self->angle); cairo_transform (cr, &mx); cairo_scale (cr, factorw, factorh); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); cairo_scale (cr, 1/factorw, 1/factorh); cairo_transform (cr, &mx); cairo_rotate (cr, -self->angle); cairo_translate (cr, -(frame->x+self->x), -(frame->y+self->y)); cairo_reset_clip (cr); cairo_surface_destroy (image); }
static void draw_arrow (GOArrow const *arrow, cairo_t *cr, GOStyle *style, double *endx, double *endy, double phi) { double l, w; if (arrow->typ == GO_ARROW_NONE) return; l = hypot (*endx, *endy); w = style->line.width ? style->line.width / 2.0 : 0.5; switch (arrow->typ) { case GO_ARROW_KITE: cairo_save (cr); cairo_translate (cr, (int) *endx, (int) *endy); cairo_rotate (cr, phi); cairo_move_to (cr, -arrow->a, w); cairo_line_to (cr, -arrow->b, w + arrow->c); cairo_line_to (cr, 0., 0.); cairo_line_to (cr, -arrow->b, -w - arrow->c); cairo_line_to (cr, -arrow->a, -w); cairo_close_path (cr); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); cairo_fill (cr); cairo_restore (cr); if (l > 0.) { (*endx) -= arrow->a * *endx / l; (*endy) -= arrow->a * *endy / l; } else *endx = *endy = 0.; break; case GO_ARROW_OVAL: cairo_save (cr); cairo_translate (cr, *endx, *endy); cairo_rotate (cr, phi); cairo_scale (cr, arrow->a, arrow->b); cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); cairo_fill (cr); cairo_restore (cr); break; default: g_assert_not_reached (); } }
static VALUE cr_rotate (VALUE self, VALUE radians) { cairo_rotate (_SELF, NUM2DBL (radians)); cr_check_status (_SELF); return self; }
static cairo_time_t do_wide_fills (cairo_t *cr, int width, int height, int loops) { int count; /* lots and lots of overlapping stroke-like fills */ state = 0xc0ffee; for (count = 0; count < 1000; count++) { cairo_save (cr); cairo_translate (cr, uniform_random (0, width), uniform_random (0, height)); cairo_rotate (cr, uniform_random (-M_PI,M_PI)); cairo_rectangle (cr, 0, 0, uniform_random (0, width), 5); cairo_restore (cr); } cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static void goc_component_draw (GocItem const *item, cairo_t *cr) { GocComponent *component = GOC_COMPONENT (item); GocCanvas *canvas = item->canvas; double x0, y0 = component->y; if (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL) { x0 = component->x + component->w; goc_group_adjust_coords (item->parent, &x0, &y0); x0 = canvas->width - (int) (x0 - canvas->scroll_x1); } else { x0 = component->x; goc_group_adjust_coords (item->parent, &x0, &y0); x0 = (int) (x0 - canvas->scroll_x1); } cairo_save (cr); _goc_item_transform (item, cr, TRUE); if (component->rotation == 0.) cairo_translate (cr, x0, (int) (y0 - canvas->scroll_y1)); else { cairo_translate (cr, x0 + component->w / 2, (int) (y0 - canvas->scroll_y1 + component->h / 2)); cairo_rotate (cr, -component->rotation); cairo_translate (cr, -component->w / 2, -component->h / 2); } cairo_rectangle (cr, 0., 0., component->w, component->h); cairo_clip (cr); go_component_render (component->component, cr, component->w, component->h); cairo_restore (cr); }
int renderSVGSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) { #ifdef USE_SVG_CAIRO cairo_renderer *r = CAIRO_RENDERER(img); //double ox=symbol->sizex*0.5,oy=symbol->sizey*0.5; svg_cairo_status_t status; struct svg_symbol_cache *cache; msPreloadSVGSymbol(symbol); assert(symbol->renderer_cache); cache = symbol->renderer_cache; cairo_save(r->cr); cairo_translate(r->cr,x,y); cairo_scale(r->cr,style->scale,style->scale); if (style->rotation != 0) { cairo_rotate(r->cr, -style->rotation); cairo_translate (r->cr, -(int)(symbol->sizex/2), -(int)(symbol->sizey/2)); } else cairo_translate (r->cr, -(int)(symbol->sizex/2), -(int)(symbol->sizey/2)); status = svg_cairo_render(cache->svgc, r->cr); cairo_restore(r->cr); return MS_SUCCESS; #else msSetError(MS_MISCERR, "SVG Symbols requested but is not built with libsvgcairo", "renderSVGSymbolCairo()"); return MS_FAILURE; #endif }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_pattern_t *source; int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2); /* Use a gray (neutral) background, so we can spot if the backend pads * with any other colour. */ cairo_set_source_rgb (cr, .5, .5, .5); cairo_paint (cr); cairo_translate(cr, SIZE/2, SIZE/2); cairo_rotate (cr, M_PI / 4.0); cairo_translate (cr, -surface_size/2, -surface_size/2); source = create_image_source (surface_size); cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST); cairo_set_source(cr, source); cairo_pattern_destroy (source); cairo_paint (cr); return CAIRO_TEST_SUCCESS; }
void GraphicsContext::rotate(float radians) { if (paintingDisabled()) return; cairo_rotate(m_data->cr, radians); }
static void shapes (cairo_t *cr) { cairo_set_source_rgb (cr, 1, 0, 0); cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0.7, 0); cairo_arc (cr, 10, 10, 7.5, 0, 2 * M_PI); cairo_stroke (cr); cairo_set_source_rgb (cr, 0, 0.7, 0.7); cairo_arc (cr, 10, 10, 25, 0, 2 * M_PI); cairo_stroke (cr); cairo_rectangle (cr, -5, -5, 30, 30); cairo_stroke (cr); cairo_set_source_rgb (cr, 0.7, 0.7, 0); cairo_save (cr); cairo_translate (cr, 10, 10); cairo_rotate (cr, M_PI/4); cairo_translate (cr, -10, -10); cairo_rectangle (cr, -5, -5, 30, 30); cairo_stroke (cr); cairo_restore (cr); cairo_set_source_rgb (cr, 0.7, 0.0, 0.7); cairo_move_to (cr, 15, -10); cairo_line_to (cr, 30, 10); cairo_line_to (cr, 15, 30); cairo_stroke (cr); }
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); }
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); }
static void img_nordic_triangle_x(cairo_t* cr, float val, const float _xc, const float _yc, const float _r2, const float scale) { float c, s; if (val < 0.00f) val = 0.00f; if (val > 1.05f) val = 1.05f; val = (val - 0.5f) * 1.5708f; c = cosf (val); s = sinf (val); cairo_save(cr); cairo_translate (cr, _xc + s * _r2, _yc - c * _r2); cairo_rotate (cr, val); cairo_move_to (cr, 0.0, 10.0 * scale); cairo_line_to (cr, 6.9282 * scale, -2.0 * scale); cairo_line_to (cr, -6.9282 * scale, -2.0 * scale); cairo_close_path(cr); cairo_set_line_width (cr, 1.2 * scale); CairoSetSouerceRGBA(c_nrd); cairo_fill_preserve (cr); CairoSetSouerceRGBA(c_wht); cairo_stroke (cr); cairo_restore(cr); }
void *msCreateTileEllipseCairo(double width, double height, double angle, colorObj *c, colorObj *bc, colorObj *oc, double ow) { double s = (MS_MAX(width,height)+ow)*1.5; cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, s,s); cairo_t *cr = cairo_create(surface); //cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); //cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); if (bc && MS_VALID_COLOR(*bc)) { msCairoSetSourceColor(cr, bc); cairo_paint(cr); } cairo_save(cr); cairo_translate(cr,s/2,s/2); cairo_rotate(cr, -angle); cairo_scale(cr, width/2,height/2); cairo_arc(cr, 0, 0, 1, 0, 2 * MS_PI); cairo_restore(cr); if (c != NULL && MS_VALID_COLOR(*c)) { msCairoSetSourceColor(cr, c); cairo_fill_preserve(cr); } if (oc != NULL && MS_VALID_COLOR(*oc)) { cairo_set_line_width(cr, ow); msCairoSetSourceColor(cr, oc); cairo_stroke_preserve(cr); } cairo_new_path(cr); cairo_destroy(cr); return surface; }
int renderEllipseSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_save(r->cr); cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_join(r->cr, CAIRO_LINE_JOIN_MITER); cairo_translate(r->cr,x,y); cairo_rotate(r->cr,-style->rotation); cairo_scale(r->cr,symbol->sizex*style->scale/2,symbol->sizey*style->scale/2); cairo_arc (r->cr, 0,0,1, 0, 2 * MS_PI); cairo_restore(r->cr); if(style->color) { msCairoSetSourceColor(r->cr, style->color); cairo_fill_preserve(r->cr); } if(style->outlinewidth > 0) { cairo_set_line_width (r->cr, style->outlinewidth); msCairoSetSourceColor(r->cr, style->outlinecolor); cairo_stroke_preserve(r->cr); } cairo_new_path(r->cr); return MS_SUCCESS; }
/* Draw the word cairo at NUM_TEXT different angles. * We separate the circle into quadrants to reduce * numerical errors i.e. so each quarter is pixel-aligned. */ static void draw_quadrant (cairo_t *cr, const char *text, const cairo_text_extents_t *extents, const cairo_matrix_t *transform, int x_off, int y_off) { int i; for (i = 0; i < NUM_TEXT/4; i++) { cairo_save (cr); cairo_rotate (cr, 2*M_PI*i/NUM_TEXT); cairo_transform (cr, transform); cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents->width + 1, extents->height + 1); cairo_set_source_rgb (cr, 1, 0, 0); cairo_stroke (cr); cairo_move_to (cr, x_off - extents->x_bearing, y_off - extents->y_bearing); cairo_set_source_rgb (cr, 0, 0, 0); #if CAIRO_TEST_GENERATE_REFERENCE_IMAGE cairo_text_path (cr, text); cairo_fill (cr); #else cairo_show_text (cr, text); #endif cairo_restore (cr); } }
cairo_surface_t* TheStage::Render() { this->currentFrame++; cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); cairo_t* cairo = cairo_create(surface); // Clear the surface // cairo_set_source_rgb(cairo, 1.0, 1.0, 1.0); // cairo_paint(cairo); for(std::list<ISymbol*>::iterator it = this->symbols.begin(); it != this->symbols.end(); ++it) { ISymbol* symbol = *it; Camera* primaryCamera = this->GetPrimaryCamera(); double rx; double ry; double rscale = primaryCamera->GetZoom(); symbol->Sync(this->currentFrame); primaryCamera->Translate(symbol->x, symbol->y, rx, ry); cairo_surface_t* subsurface = symbol->Render(rscale); cairo_translate(cairo, rx, ry); cairo_rotate(cairo, symbol->angle); cairo_translate(cairo, -symbol->centerX * rscale, -symbol->centerY * rscale); cairo_set_source_surface(cairo, subsurface, 0, 0); cairo_paint(cairo); cairo_surface_destroy(subsurface); cairo_identity_matrix(cairo); } cairo_destroy(cairo); return surface; }
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_t *cr; cr = gdk_cairo_create (widget->window); cairo_set_source_rgb(cr, 0.6, 0.6, 0.6); cairo_rectangle(cr, 20, 20, 80, 50); cairo_stroke_preserve(cr); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); cairo_translate(cr, 150, 100); cairo_rotate(cr, M_PI/2); cairo_set_source_rgb(cr, 0.6, 0.6, 0.6); cairo_rectangle(cr, 20, 20, 80, 50); cairo_stroke_preserve(cr); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); cairo_destroy(cr); return FALSE; }
int renderPixmapSymbolCairo(imageObj *img, double x, double y,symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_surface_t *im; rasterBufferObj *b = symbol->pixmap_buffer; assert(b); if(!symbol->renderer_cache) { symbol->renderer_cache = (void*)createSurfaceFromBuffer(b); } assert(symbol->renderer_cache); im=(cairo_surface_t*)symbol->renderer_cache; cairo_save(r->cr); if(style->rotation != 0 || style->scale != 1) { cairo_translate (r->cr, x,y); cairo_rotate (r->cr, -style->rotation); cairo_scale (r->cr, style->scale,style->scale); cairo_translate (r->cr, -0.5*b->width, -0.5*b->height); } else { cairo_translate (r->cr, MS_NINT(x-0.5*b->width),MS_NINT(y-0.5*b->height)); } cairo_set_source_surface (r->cr, im, 0, 0); cairo_paint (r->cr); cairo_restore(r->cr); return MS_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_pattern_t *pattern; cairo_set_source_rgb (cr, 1., 1., 1.); cairo_paint (cr); cairo_set_source_rgb (cr, 0., 0., 0.); cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); draw_text (cr); cairo_translate (cr, SIZE, SIZE); cairo_rotate (cr, M_PI); pattern = cairo_test_create_pattern_from_png (ctx, png_filename); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); draw_text (cr); return CAIRO_TEST_SUCCESS; }
void draw_apply_netstate_transformation (cairo_t *cairoTarget, gerbv_netstate_t *state) { /* apply scale factor */ cairo_scale (cairoTarget, state->scaleA, state->scaleB); /* apply offset */ cairo_translate (cairoTarget, state->offsetA, state->offsetB); /* apply mirror */ switch (state->mirrorState) { case GERBV_MIRROR_STATE_FLIPA: cairo_scale (cairoTarget, -1, 1); break; case GERBV_MIRROR_STATE_FLIPB: cairo_scale (cairoTarget, 1, -1); break; case GERBV_MIRROR_STATE_FLIPAB: cairo_scale (cairoTarget, -1, -1); break; default: break; } /* finally, apply axis select */ if (state->axisSelect == GERBV_AXIS_SELECT_SWAPAB) { /* we do this by rotating 270 (counterclockwise, then mirroring the Y axis */ cairo_rotate (cairoTarget, M_PI + M_PI_2); cairo_scale (cairoTarget, 1, -1); } }
static void rotate_text(cairo_t *cairo, PangoLayout *layout, int x_center, int y_center, double radians) { cairo_translate(cairo, x_center, y_center); cairo_rotate(cairo, radians); /* Inform Pango to re-layout the text with the new transformation */ pango_cairo_update_layout(cairo, layout); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_pattern_t *pattern; cairo_test_paint_checkered (cr); cairo_translate (cr, PAD, PAD); pattern = cairo_pattern_create_mesh (); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 0, 0); cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0); cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100); cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100); cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 50, 50); cairo_mesh_pattern_curve_to (pattern, 80, 20, 110, 80, 150, 50); cairo_mesh_pattern_curve_to (pattern, 110, 80, 180, 110, 150, 150); cairo_mesh_pattern_curve_to (pattern, 110, 120, 80, 180, 50, 150); cairo_mesh_pattern_curve_to (pattern, 80, 120, 20, 80, 50, 50); cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); cairo_scale (cr, .5, .5); cairo_set_source (cr, pattern); cairo_paint (cr); cairo_translate (cr, PAT_WIDTH, PAT_HEIGHT); cairo_translate (cr, PAT_WIDTH/2, PAT_HEIGHT/2); cairo_rotate (cr, M_PI/4); cairo_translate (cr, -PAT_WIDTH, -PAT_HEIGHT); cairo_set_source (cr, pattern); cairo_paint (cr); cairo_pattern_destroy (pattern); return CAIRO_TEST_SUCCESS; }
cairo_surface_t * ev_document_misc_surface_rotate_and_scale (cairo_surface_t *surface, gint dest_width, gint dest_height, gint dest_rotation) { cairo_surface_t *new_surface; cairo_t *cr; gint width, height; gint new_width = dest_width; gint new_height = dest_height; width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); if (dest_width == width && dest_height == height && dest_rotation == 0) { return cairo_surface_reference (surface); } if (dest_rotation == 90 || dest_rotation == 270) { new_width = dest_height; new_height = dest_width; } new_surface = cairo_surface_create_similar (surface, cairo_surface_get_content (surface), new_width, new_height); cr = cairo_create (new_surface); switch (dest_rotation) { case 90: cairo_translate (cr, new_width, 0); break; case 180: cairo_translate (cr, new_width, new_height); break; case 270: cairo_translate (cr, 0, new_height); break; default: cairo_translate (cr, 0, 0); } cairo_rotate (cr, dest_rotation * G_PI / 180.0); if (dest_width != width || dest_height != height) { cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR); cairo_scale (cr, (gdouble)dest_width / width, (gdouble)dest_height / height); } cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_destroy (cr); return new_surface; }