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 dtgtk_cairo_paint_triangle(cairo_t *cr, gint x,int y,gint w,gint h, gint flags) { /* initialize rotation and flip matrices */ cairo_matrix_t hflip_matrix; cairo_matrix_init(&hflip_matrix,-1,0,0,1,1,0); double C=cos(-(M_PI/2.0)),S=sin(-(M_PI/2.0)); // -90 degrees C=flags&CPF_DIRECTION_DOWN?cos(-(M_PI*1.5)):C; S=flags&CPF_DIRECTION_DOWN?sin(-(M_PI*1.5)):S; cairo_matrix_t rotation_matrix; cairo_matrix_init(&rotation_matrix,C,S,-S,C,0.5-C*0.5+S*0.5,0.5-S*0.5-C*0.5); /* scale and transform*/ gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); cairo_set_line_width(cr,0.1); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); if( flags&CPF_DIRECTION_UP || flags &CPF_DIRECTION_DOWN) cairo_transform(cr,&rotation_matrix); else if(flags&CPF_DIRECTION_LEFT) // Flip x transformation cairo_transform(cr,&hflip_matrix); cairo_move_to(cr, 0.2, 0.2); cairo_line_to(cr, 0.7, 0.5); cairo_line_to(cr, 0.2, 0.8); cairo_line_to(cr, 0.2, 0.2); cairo_stroke(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_empty(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { cairo_translate(cr, x, y); cairo_scale(cr, w, h); cairo_stroke(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_masks_eye(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s, s); cairo_set_line_width(cr, 0.15); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); if((flags & CPF_ACTIVE)) cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); else cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); double dashed[] = { 0.2, 0.2 }; int len = sizeof(dashed) / sizeof(dashed[0]); cairo_set_dash(cr, dashed, len, 0); cairo_arc(cr, 0.75, 0.75, 0.75, 2.8, 4.7124); cairo_set_line_width(cr, 0.1); cairo_stroke(cr); cairo_move_to(cr, 0.4, 0.1); cairo_line_to(cr, 0.3, 0.8); cairo_line_to(cr, 0.55, 0.716667); cairo_line_to(cr, 0.65, 1.016667); cairo_line_to(cr, 0.75, 0.983333); cairo_line_to(cr, 0.65, 0.683333); cairo_line_to(cr, 0.9, 0.6); cairo_line_to(cr, 0.4, 0.1); cairo_fill(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_store(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); cairo_set_line_width(cr,0.15); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_move_to(cr,0.275,0.1); cairo_line_to(cr,0.1,0.1); cairo_line_to(cr,0.1,0.9); cairo_line_to(cr,0.9,0.9); cairo_line_to(cr,0.9,0.175); cairo_line_to(cr,0.825,0.1); cairo_line_to(cr,0.825,0.5); cairo_line_to(cr,0.275,0.5); cairo_line_to(cr,0.275,0.1); cairo_stroke(cr); cairo_set_line_width(cr,0); cairo_rectangle(cr,0.5,0.025,0.17,0.275); cairo_fill(cr); cairo_stroke(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_flip(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { double C=cos(-1.570796327),S=sin(-1.570796327); cairo_matrix_t rotation_matrix; cairo_matrix_init(&rotation_matrix,C,S,-S,C,0.5-C*0.5+S*0.5,0.5-S*0.5-C*0.5); gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); cairo_set_line_width(cr,0.15); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); if( (flags&CPF_DIRECTION_UP) ) // Rotate -90 degrees cairo_transform(cr,&rotation_matrix); cairo_move_to(cr,0.05,0.50); cairo_line_to(cr,0.05,0); cairo_line_to(cr,0.95,0.50); cairo_line_to(cr,0.2,0.50); cairo_stroke(cr); cairo_set_line_width(cr,0.04); cairo_move_to(cr,0.05,0.62); cairo_line_to(cr,0.05,1.0); cairo_line_to(cr,0.95,0.62); cairo_stroke(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_switch(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); if( !(flags&CPF_ACTIVE) ) cairo_set_source_rgba(cr, 1,1,1,0.2); cairo_set_line_width(cr,0.125); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_arc (cr, 0.5, 0.5, 0.45, (-50*3.145/180),(230*3.145/180)); cairo_move_to(cr,0.5,0.05); cairo_line_to(cr,0.5,0.45); cairo_stroke(cr); if( (flags&CPF_ACTIVE) ) // If active add some green diffuse light { cairo_set_source_rgba(cr, 1,1,1,0.2); cairo_set_line_width(cr,0.25); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_arc (cr, 0.5, 0.5, 0.45, (-50*3.145/180),(230*3.145/180)); cairo_move_to(cr,0.5,0.1); cairo_line_to(cr,0.5,0.5); cairo_stroke(cr); } cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_plusminus(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); cairo_set_source_rgba(cr, 0.6,0.6,0.6,1.0); cairo_set_line_width(cr,0.125); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_arc (cr, 0.5, 0.5, 0.45, 0, 2*M_PI); cairo_stroke(cr); if( (flags&CPF_ACTIVE) ) { cairo_move_to(cr,0.5,0.2); cairo_line_to(cr,0.5,0.8); cairo_move_to(cr,0.2,0.5); cairo_line_to(cr,0.8,0.5); cairo_stroke(cr); } else { cairo_arc (cr, 0.5, 0.5, 0.45, 0, 2*M_PI); cairo_fill(cr); cairo_set_source_rgba(cr, 0.1,0.1,0.1,1.0); cairo_move_to(cr,0.2,0.5); cairo_line_to(cr,0.8,0.5); cairo_stroke(cr); } cairo_identity_matrix(cr); }
static VALUE cr_identity_matrix (VALUE self) { cairo_identity_matrix (_SELF); cr_check_status (_SELF); return self; }
void dtgtk_cairo_paint_eye_toggle(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s, s); cairo_set_line_width(cr, 0.15); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_arc(cr, 0.5, 0.5, 0.1, 0, 6.2832); cairo_stroke(cr); cairo_translate(cr, 0, 0.20); cairo_save(cr); cairo_scale(cr, 1.0, 0.60); cairo_arc(cr, 0.5, 0.5, 0.45, 0, 6.2832); cairo_restore(cr); cairo_stroke(cr); cairo_translate(cr, 0, -0.20); if((flags & CPF_ACTIVE)) { cairo_set_source_rgba(cr, 0.6, 0.1, 0.1, 1.0); cairo_move_to(cr, 0.1, 0.9); cairo_line_to(cr, 0.9, 0.1); cairo_stroke(cr); } cairo_identity_matrix(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 cairo_perf_ticks_t do_composite_checker (cairo_t *cr, int width, int height) { /* Compute zoom so that the src_pattern covers the whole output image. */ double xscale = width / (double) SRC_SIZE; double yscale = height / (double) SRC_SIZE; cairo_perf_timer_start (); cairo_identity_matrix (cr); /* Fill the surface with our background. */ cairo_set_source (cr, checkerboard); cairo_paint (cr); /* Draw the scaled image on top. */ cairo_scale (cr, xscale, yscale); cairo_set_source (cr, src_pattern); cairo_paint (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
void VectorGraphics::pop_matrix() { if(matrix_stack_.empty()) { cairo_identity_matrix(cr()); } else { cairo_set_matrix(cr(), &matrix_stack_.front()); matrix_stack_.pop_front(); } }
static PyObject * pycairo_identity_matrix (PycairoContext *o) { cairo_identity_matrix (o->ctx); if (Pycairo_Check_Status (cairo_status (o->ctx))) return NULL; Py_RETURN_NONE; }
static int cairo_identity_matrix_l( lua_State* L ) { lua_cairo_t* lc = lua_cairo_check( L, 1 ); cairo_identity_matrix( lc->cairo ); return( 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); }
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); }
void CairoPainter::NewCanvas(double width, double height) { double titleheight = m_title.empty() ? 0.0 : 16.0; if (m_index == 1) { // create new surface to paint on if(m_cropping) { double ratio = width / height; if(ratio > 1.0) m_height = m_height / ratio; else m_width = m_width * ratio; } m_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, static_cast<int> (m_width), static_cast<int> (m_height)); m_cairo = cairo_create(m_surface); if(m_transparent) cairo_set_source_rgba (m_cairo, 0.0, 0.0, 0.0, 0.0); else { OBColor bg = OBColor(m_fillcolor); cairo_set_source_rgb (m_cairo, bg.red, bg.green, bg.blue); } cairo_paint (m_cairo); cairo_set_line_width(m_cairo, m_pen_width); } else { // reset transformation matrix cairo_identity_matrix(m_cairo); } // Work out some things! double cellwidth = m_width/m_ncols; double cellheight = m_height/m_nrows; int row = (m_index - 1)/m_ncols + 1; int col = m_index - ((row-1)*m_ncols); // Work out the scaling factor double scale_x = cellwidth / (double) width; double scale_y = (cellheight-titleheight) / (double) height; // Leave some extra space for the title if present double scale = std::min(scale_x, scale_y); // Add the title if (!m_title.empty()) { this->SetPenColor(OBColor(m_bondcolor)); this->SetFontSize(static_cast<int>(16.0)); OBFontMetrics fm = this->GetFontMetrics(m_title); this->DrawText(cellwidth/2.0 - fm.width/2.0 + cellwidth*(col-1), cellheight - fm.height * 0.25 + cellheight*(row-1), m_title); } // Translate the over-scaled dimension into the centre if (scale < scale_y) cairo_translate(m_cairo, 0 + cellwidth*(col-1), cellheight/2.0 - scale*height/2.0 + cellheight*(row-1)); else cairo_translate(m_cairo, cellwidth/2.0 - scale*width/2.0 + cellwidth*(col-1), 0 + cellheight*(row-1)); cairo_scale(m_cairo, scale, scale); // Set a scaling transformation }
static void document_render(document_data_t *d) { GtkWidget *w = d->widget; /* render recorded data directly to widget */ cairo_t *c = gdk_cairo_create(gtk_widget_get_window(w)); cairo_set_source_rgb(c, 1.0/256*220, 1.0/256*218, 1.0/256*213); cairo_paint(c); /* render pages with scroll and zoom */ for (guint i = 0; i < d->pages->len; ++i) { page_info_t *p = g_ptr_array_index(d->pages, i); if (document_page_is_visible(d, p)) { /* render page */ cairo_scale(c, d->zoom, d->zoom); cairo_translate(c, p->rectangle->x - d->hadjust->value, p->rectangle->y - d->vadjust->value); page_render(c, p); cairo_identity_matrix(c); /* render search matches */ GList *m = p->search_matches; while (m) { PopplerRectangle *pr = (PopplerRectangle*) m->data; cairo_rectangle_t *pc = page_coordinates_from_pdf_coordinates(pr, p); cairo_rectangle_t *dc = document_coordinates_from_page_coordinates(pc, p); cairo_scale(c, d->zoom, d->zoom); cairo_translate(c, dc->x - d->hadjust->value, dc->y - d->vadjust->value); cairo_rectangle(c, 0, 0, dc->width, dc->height); if (d->current_match == m) cairo_set_source_rgba(c, 0.5, 1, 0, 0.5); else cairo_set_source_rgba(c, 1, 1, 0, 0.5); cairo_fill(c); cairo_identity_matrix(c); g_free(dc); g_free(pc); m = g_list_next(m); } } } cairo_destroy(c); }
void dtgtk_cairo_paint_color(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { cairo_translate(cr, x, y); cairo_scale(cr,w,h); cairo_set_line_width(cr,0.1); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_rectangle(cr,0.1,0.1,0.8,0.8); cairo_fill(cr); cairo_set_source_rgba(cr,0,0,0,0.6); cairo_stroke(cr); cairo_identity_matrix(cr); }
static GpStatus draw_clamp_texture (cairo_t *ct, GpBitmap *bitmap, GpTexture *brush) { cairo_surface_t *original; cairo_surface_t *texture; cairo_pattern_t *pat; GpRect *rect = &brush->rectangle; GpStatus status; cairo_t *ct2; /* Original image surface */ gdip_bitmap_ensure_surface (bitmap); original = bitmap->surface; /* Use the original as a pattern */ pat = cairo_pattern_create_for_surface (original); status = gdip_get_pattern_status (pat); if (status != Ok) { return status; } cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT); /* texture surface to be created */ texture = cairo_surface_create_similar (original, from_cairoformat_to_content (bitmap->cairo_format), rect->Width, rect->Height); if (!texture) { cairo_pattern_destroy (pat); return OutOfMemory; } /* Draw the texture */ ct2 = cairo_create (texture); cairo_identity_matrix (ct2); cairo_set_source (ct2, pat); cairo_rectangle (ct2, 0, 0, rect->Width, rect->Height); cairo_fill (ct2); cairo_destroy(ct2); brush->pattern = cairo_pattern_create_for_surface (texture); status = gdip_get_pattern_status (brush->pattern); if (status != Ok) { cairo_pattern_destroy (pat); cairo_surface_destroy (texture); return status; } cairo_pattern_destroy (pat); cairo_surface_destroy (texture); return gdip_get_status (cairo_status (ct)); }
void dtgtk_cairo_paint_reset(cairo_t *cr,gint x,gint y,gint w,gint h,gint flags) { gint s=w<h?w:h; cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0)); cairo_scale(cr,s,s); cairo_set_line_width(cr,0.15); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_arc (cr, 0.5, 0.5, 0.46, 0, 6.2832); cairo_move_to(cr,0.5,0.32); cairo_line_to(cr,0.5,0.68); cairo_stroke(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_masks_inverse(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s, s); cairo_set_line_width(cr, 0.15); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_arc(cr, 0.5, 0.5, 0.46, 0, 2.0 * M_PI); cairo_stroke(cr); cairo_arc(cr, 0.5, 0.5, 0.46, 3.0 * M_PI / 2.0, M_PI / 2.0); cairo_fill(cr); cairo_identity_matrix(cr); }
void dtgtk_cairo_paint_masks_exclusion(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s * 1.4, s); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_source_rgb(cr, 0.6, 0.6, 0.6); cairo_arc(cr, 0.0, 0.5, 0.45, 0, 6.2832); cairo_arc_negative(cr, 0.714, 0.5, 0.45, 0, 6.2832); cairo_fill(cr); cairo_identity_matrix(cr); }
static void draw_L_shape (cairo_t *cr) { cairo_move_to (cr, 0, 0); cairo_rel_line_to (cr, 0, 10); cairo_rel_line_to (cr, 5, 0); cairo_save (cr); cairo_identity_matrix (cr); cairo_set_line_width (cr, 2.0); cairo_stroke (cr); cairo_restore (cr); }
void VectorGraphics::apply_world_transform() { // Transform from world coordinates to screen coordinates. cairo_identity_matrix(cr()); // Cairo's usual coordinate system places (0,0) at the top left, but our world coordinates // have (0,0) at the bottom left. This necessitates a bit of fiddling. cairo_scale(cr(), static_cast<double>(viewport().w())/(viewport().shape().w()/meter), -static_cast<double>(viewport().h())/(viewport().shape().h()/meter)); cairo_translate(cr(), -viewport().shape().min_corner().x()/meters, -viewport().shape().max_corner().y()/meters); }
static void draw (cairo_t *cr, PangoLayout *layout, unsigned int i) { cairo_set_source_rgba (cr, 1, 1, 1, 1); cairo_paint (cr); cairo_set_source_rgba (cr, 1, 1, 1, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_identity_matrix (cr); cairo_scale (cr, (100 + i) / 100., (100 + i) / 100.); pango_cairo_update_layout (cr, layout); pango_cairo_show_layout (cr, layout); }
int buildCache(const char *path) { cairo_surface_t *img = cairo_image_surface_create_from_png (path); if (CAIRO_STATUS_SUCCESS != cairo_surface_status (img)) { fprintf(stderr, "Failed to load cusor image [%s]\n", path); return 1; } /*calculate dimensions needed for rotate image*/ wormy.width = cairo_image_surface_get_width(img); wormy.height = cairo_image_surface_get_height(img); wormy.radius = sqrt(wormy.width*wormy.width/4.0 + wormy.height*wormy.height/4.0); /*create a destination canvas*/ cairo_surface_t *work = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, 2*wormy.radius, 2*wormy.radius); cairo_t *cr = cairo_create(work); int a; for (a = 0; a < 360; a++) { /*clear background*/ cairo_identity_matrix (cr); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); /*move to the center, rotate, translate back an to the final place*/ cairo_translate(cr, wormy.radius, wormy.radius); cairo_rotate(cr, a * M_PI / 180.0); cairo_translate(cr, -wormy.width/2.0, -wormy.height/2.0); /*paint rotate image*/ cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_surface(cr, img, 0, 0); cairo_paint(cr); if (wormy.cache[a]) free(wormy.cache[a]); /*cache the image*/ int stride = cairo_image_surface_get_stride(work); void *data = cairo_image_surface_get_data(work); wormy.cache[a] = (XcursorPixel *)malloc((int)( wormy.radius * wormy.radius * stride)); memcpy(wormy.cache[a], data, wormy.radius * wormy.radius * stride); } cairo_destroy(cr); cairo_surface_destroy(img); cairo_surface_destroy(work); return 0; }
void dtgtk_cairo_paint_masks_circle(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s, s); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); if(flags & CPF_ACTIVE) cairo_set_line_width(cr, 0.25); else cairo_set_line_width(cr, 0.125); cairo_arc(cr, 0.5, 0.5, 0.46, 0, 6.2832); cairo_stroke(cr); cairo_identity_matrix(cr); }
/*================================================================================== pspltrgn - subroutine to set which small plot region to use This routine is called by pschem in psvdraw_new in order to plot multiple ternary chemographies on a single page. Each page can hold MAXPLOTSPERPAGE. If another is requested, then a new document will be created with a name similar to that of the first, and the process will begin again. This overrides any settings made in psssc2, and assumes that x and y (real-unit) bounds are 0.0-1.0. Note that if this routine is called, then plot_aspect_ratio will be ignored. Note that plotnum is a zero-based index ==================================================================================*/ void pspltrgn_ (int *plotnum) { char *outFileName = malloc((strlen(dmh_fileNameRoot)+50) * sizeof(char)); int plotPosition = *plotnum % MAXPLOTSPERPAGE; int pageNum = *plotnum / MAXPLOTSPERPAGE; int boxEdge, rowNum, colNum; DEBUGPRINT(("In pspltrgn. Plotnum = %i, plotPosition = %i, pageNum = %i\n", *plotnum, plotPosition, pageNum)); if (plotPosition == 0 && pageNum > 0) { /* we need to start a new page, so let's close the current one, and start a new one with a related name */ DEBUGPRINT(("In pspltrgn. Closing current page and starting a new one with\n page number=%i and file type=%i\n", pageNum, dmh_outputFileType)); closeSurface(); // close existing surface switch(dmh_outputFileType) { case PDFTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "pdf"); dmh_surf = cairo_pdf_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); break; case PSTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "ps"); dmh_surf = cairo_ps_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); cairo_ps_surface_set_eps (dmh_surf, 1); break; case SVGTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "svg"); dmh_surf = cairo_svg_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); break; } dmh_cr = cairo_create (dmh_surf); cairo_identity_matrix(dmh_cr); cairo_set_line_join(dmh_cr, CAIRO_LINE_JOIN_ROUND); dmh_min_tracked_x = DBL_MAX; } /* Set the location on the page for the small plot */ dmh_aspectRatio = 1.0; /* Ignores plot_aspect_ratio. */ boxEdge = (dmh_pageWidth - LEFTMARGIN - RIGHTMARGIN - MULTIPLOTGUTTER) / 2; rowNum = plotPosition / 2; colNum = plotPosition % 2; dmh_xoffset = LEFTMARGIN + ((boxEdge + MULTIPLOTGUTTER) * colNum); dmh_yoffset = (dmh_pageHeight * 0.5) + (boxEdge * 1.5) + MULTIPLOTGUTTER - (boxEdge * (rowNum+1)) - (MULTIPLOTGUTTER * rowNum); dmh_xscale = boxEdge; dmh_yscale = boxEdge; DEBUGPRINT(("End pspltrgn. boxEdge=%i; r,c=(%i,%i); scale=(%f, %f); offset=(%f, %f); DevPtRange=(%f,%f)-(%f,%f).\n", boxEdge, rowNum, colNum, dmh_xscale, dmh_yscale, dmh_xoffset, dmh_yoffset,deviceX(0), deviceY(0), deviceX(1), deviceY(1))); }