static VALUE cr_set_tolerance (VALUE self, VALUE tolerance) { cairo_set_tolerance (_SELF, NUM2DBL (tolerance)); cr_check_status (_SELF); return self; }
static void generate_reference (double ppi_x, double ppi_y, const char *filename) { cairo_surface_t *surface, *target; cairo_t *cr; cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE*ppi_x/72, SIZE*ppi_y/72); cr = cairo_create (surface); cairo_surface_destroy (surface); /* As we wish to mimic a PDF surface, copy across the default font options * from the PDF backend. */ { cairo_surface_t *pdf; cairo_font_options_t *options; options = cairo_font_options_create (); pdf = cairo_pdf_surface_create ("tmp.pdf", 1, 1); cairo_surface_get_font_options (pdf, options); cairo_surface_destroy (pdf); cairo_set_font_options (cr, options); cairo_font_options_destroy (options); } #if SET_TOLERANCE cairo_set_tolerance (cr, 3.0); #endif cairo_save (cr); { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); } cairo_restore (cr); cairo_scale (cr, ppi_x/72., ppi_y/72.); draw (cr, SIZE, SIZE); surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE); cr = cairo_create (target); cairo_scale (cr, 72./ppi_x, 72./ppi_y); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); status = cairo_surface_write_to_png (cairo_get_target (cr), filename); cairo_destroy (cr); if (status) { fprintf (stderr, "Failed to generate reference image '%s': %s\n", filename, cairo_status_to_string (status)); exit (1); } }
static PyObject * pycairo_set_tolerance (PycairoContext *o, PyObject *args) { double tolerance; if (!PyArg_ParseTuple (args, "d:Context.set_tolerance", &tolerance)) return NULL; cairo_set_tolerance (o->ctx, tolerance); RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx); Py_RETURN_NONE; }
LcCairoPainter* LcCairoPainter::createPainter(int width, int height) { cairo_surface_t* surface; cairo_t* cr; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_tolerance(cr, 0.25); cairo_set_antialias(cr, CAIRO_ANTIALIAS_GOOD); return new LcCairoPainter(surface, cr); }
LcCairoPainter* LcCairoPainter::createImagePainter(unsigned char* data , int width, int height) { cairo_surface_t* surface; cairo_t* cr; int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); cr = cairo_create(surface); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_tolerance(cr, 0.25); cairo_set_antialias(cr, CAIRO_ANTIALIAS_GOOD); return new LcCairoPainter(surface, cr); }
static void settings_set (cairo_t *cr, const settings_t *settings) { cairo_set_operator (cr, settings->op); cairo_set_tolerance (cr, settings->tolerance); cairo_set_fill_rule (cr, settings->fill_rule); cairo_set_line_width (cr, settings->line_width); cairo_set_line_cap (cr, settings->line_cap); cairo_set_line_join (cr, settings->line_join); cairo_set_miter_limit (cr, settings->miter_limit); cairo_set_matrix (cr, &settings->matrix); cairo_set_dash (cr, settings->dash, 5, settings->dash_offset); }
static PyObject * pycairo_set_tolerance (PycairoContext *o, PyObject *args) { double tolerance; if (!PyArg_ParseTuple (args, "d:Context.set_tolerance", &tolerance)) return NULL; cairo_set_tolerance (o->ctx, tolerance); if (Pycairo_Check_Status (cairo_status (o->ctx))) return NULL; Py_RETURN_NONE; }
static void sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf) { SPCanvasBPath *cbp = SP_CANVAS_BPATH (item); Geom::Rect area = buf->rect; if ( !cbp->curve || ((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) || cbp->curve->get_segment_count() < 1) return; if (!buf->ct) return; bool dofill = ((cbp->fill_rgba & 0xff) != 0); bool dostroke = ((cbp->stroke_rgba & 0xff) != 0); cairo_set_tolerance(buf->ct, 0.5); cairo_new_path(buf->ct); feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, /* optimized_stroke = */ !dofill, 1); if (dofill) { // RGB / BGR ink_cairo_set_source_rgba32(buf->ct, cbp->fill_rgba); cairo_set_fill_rule(buf->ct, cbp->fill_rule == SP_WIND_RULE_EVENODD? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); cairo_fill_preserve(buf->ct); } if (dostroke) { ink_cairo_set_source_rgba32(buf->ct, cbp->stroke_rgba); cairo_set_line_width(buf->ct, 1); if (cbp->dashes[0] != 0 && cbp->dashes[1] != 0) { cairo_set_dash (buf->ct, cbp->dashes, 2, 0); } cairo_stroke(buf->ct); } else { cairo_new_path(buf->ct); } }
static cairo_rectangle_t * ar_card_theme_kde_get_card_extents (ArCardThemeKDE *theme, int card_id, const char *node) { ArSvg *svg; cairo_rectangle_t *card_extents; cairo_rectangle_t rect; cairo_surface_t *surface; cairo_t *cr; card_extents = &theme->card_extents[card_id]; /* Is it initalised yet? */ if (card_extents->width != 0. && card_extents->height != 0.) return card_extents; svg = ((ArCardThemePreimage *) theme)->cards_svg; surface = cairo_recording_surface_create (CAIRO_CONTENT_ALPHA, NULL); cr = cairo_create (surface); cairo_set_tolerance (cr, 1.); ar_profilestart ("getting ink extents for node %s", node); rsvg_handle_render_cairo_sub (RSVG_HANDLE (svg), cr, node); ar_profileend ("getting ink extents for node %s", node); cairo_destroy (cr); cairo_recording_surface_ink_extents (surface, &rect.x, &rect.y, &rect.width, &rect.height); cairo_surface_destroy (surface); ar_debug_print (AR_DEBUG_CARD_THEME, "card %s %.3f x%.3f at (%.3f | %.3f)\n", node, card_extents->width, card_extents->height, card_extents->x, card_extents->y); *card_extents = rect; /* Sanity check; necessary? */ if (rect.width == 0. || rect.height == 0.) return NULL; return card_extents; }
static void generate_reference (double ppi_x, double ppi_y, const char *filename) { cairo_surface_t *surface, *target; cairo_t *cr; cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE*ppi_x/72, SIZE*ppi_y/72); cr = cairo_create (surface); cairo_surface_destroy (surface); #if SET_TOLERANCE cairo_set_tolerance (cr, 3.0); #endif cairo_save (cr); { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); } cairo_restore (cr); cairo_scale (cr, ppi_x/72., ppi_y/72.); draw (cr, SIZE, SIZE); surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE); cr = cairo_create (target); cairo_scale (cr, 72./ppi_x, 72./ppi_y); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); status = cairo_surface_write_to_png (cairo_get_target (cr), filename); cairo_destroy (cr); if (status) { fprintf (stderr, "Failed to generate reference image '%s': %s\n", filename, cairo_status_to_string (status)); exit (1); } }
static void draw_twisted (RsvgDrawingCtx * ctx, cairo_t *cr, cairo_path_t *path, double *x, double *y, const char *text) { cairo_path_t *path_copy; cairo_save (cr); /* Decrease tolerance a bit, since it's going to be magnified */ cairo_set_tolerance (cr, 0.01); /* Using cairo_copy_path() here shows our deficiency in handling * Bezier curves, specially around sharper curves. * * Using cairo_copy_path_flat() on the other hand, magnifies the * flattening error with large off-path values. We decreased * tolerance for that reason. Increase tolerance to see that * artifact. */ // Load the previously drawn path in order to make a copy cairo_new_path(cr); cairo_append_path(cr, path); path_copy = cairo_copy_path_flat (cr); // Draw the text cairo_new_path (cr); draw_text (ctx, cr, x, y, text); map_path_onto (cr, path_copy); cairo_path_destroy (path_copy); // Render the text path using current text settings //cairo_fill_preserve (cr); path_copy = cairo_copy_path(cr); ctx->render->render_path(ctx, path_copy); cairo_path_destroy (path_copy); cairo_restore (cr); }
static cairo_status_t twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, unsigned long glyph, cairo_t *cr, cairo_text_extents_t *metrics) { double x1, y1, x2, y2, x3, y3; double marginl; twin_scaled_properties_t *props; twin_snap_info_t info; const int8_t *b; const int8_t *g; int8_t w; double gw; props = cairo_scaled_font_get_user_data (scaled_font, &twin_properties_key); /* Save glyph space, we need it when stroking */ cairo_save (cr); /* center the pen */ cairo_translate (cr, props->penx * .5, -props->peny * .5); /* small-caps */ if (props->face_props->smallcaps && glyph >= 'a' && glyph <= 'z') { glyph += 'A' - 'a'; /* 28 and 42 are small and capital letter heights of the glyph data */ cairo_scale (cr, 1, 28. / 42); } /* slant */ if (props->face_props->slant != CAIRO_FONT_SLANT_NORMAL) { cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0}; cairo_transform (cr, &shear); } b = _cairo_twin_outlines + _cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph]; g = twin_glyph_draw(b); w = twin_glyph_right(b); gw = F(w); marginl = props->marginl; /* monospace */ if (props->face_props->monospace) { double monow = F(24); double extra = props->penx + props->marginl + props->marginr; cairo_scale (cr, (monow + extra) / (gw + extra), 1); gw = monow; /* resnap margin for new transform */ { double x, y, x_scale, x_scale_inv; x = 1; y = 0; compute_hinting_scale (cr, x, y, &x_scale, &x_scale_inv); marginl = SNAPXI (marginl); } } cairo_translate (cr, marginl, 0); /* stretch */ cairo_scale (cr, props->stretch, 1); if (props->snap) twin_compute_snap (cr, &info, b); else info.n_snap_x = info.n_snap_y = 0; /* advance width */ metrics->x_advance = gw * props->stretch + props->penx + props->marginl + props->marginr; /* glyph shape */ for (;;) { switch (*g++) { case 'M': cairo_close_path (cr); /* fall through */ case 'm': x1 = SNAPX(*g++); y1 = SNAPY(*g++); cairo_move_to (cr, x1, y1); continue; case 'L': cairo_close_path (cr); /* fall through */ case 'l': x1 = SNAPX(*g++); y1 = SNAPY(*g++); cairo_line_to (cr, x1, y1); continue; case 'C': cairo_close_path (cr); /* fall through */ case 'c': x1 = SNAPX(*g++); y1 = SNAPY(*g++); x2 = SNAPX(*g++); y2 = SNAPY(*g++); x3 = SNAPX(*g++); y3 = SNAPY(*g++); cairo_curve_to (cr, x1, y1, x2, y2, x3, y3); continue; case 'E': cairo_close_path (cr); /* fall through */ case 'e': cairo_restore (cr); /* restore glyph space */ cairo_set_tolerance (cr, 0.01); cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_width (cr, 1); cairo_scale (cr, props->penx, props->peny); cairo_stroke (cr); break; case 'X': /* filler */ continue; } break; } return CAIRO_STATUS_SUCCESS; }
void lime_cairo_set_tolerance (double handle, double tolerance) { cairo_set_tolerance ((cairo_t*)(intptr_t)handle, tolerance); }
int main (int argc, char **argv) { XEvent event; XSizeHints xsh; XSetWindowAttributes xswa; XVisualInfo *vinfo; glitz_drawable_format_t templ; glitz_drawable_format_t *dformat; unsigned long mask = 0; unsigned int width, height, window_width, window_height; int i; program_name = argv[0]; for (i = 1; i < argc; i++) { if (!strcasecmp ("-image", argv[i])) output_type = IMAGE_TYPE; #ifdef CAIRO_HAS_XLIB_SURFACE else if (!strcasecmp ("-xrender", argv[i])) { output_type = XRENDER_TYPE; } #endif else if (!strcasecmp ("-glx", argv[i])) { output_type = GLX_TYPE; } else if (!strcasecmp ("-noaa", argv[i])) { aa = 0; } else if (!strcasecmp ("-swaa", argv[i])) { aa = 1; } else if (!strcasecmp ("-hwaa", argv[i])) { aa = 3; } else { test_type = get_test_type (argv[i]); } } if (!test_type) { usage(); exit(1); } if (output_type != GLX_TYPE && test_type >= OPENGL_TYPE) { printf ("Sorry, this test only works with OpenGL!\n"); usage(); exit(1); } window_width = width = WINDOW_WIDTH; window_height = height = WINDOW_HEIGHT; if (aa == 3) templ.samples = 4; else templ.samples = 1; templ.depth_size = 16; if (test_type == CUBE_TYPE) mask |= GLITZ_FORMAT_DEPTH_SIZE_MASK; mask |= GLITZ_FORMAT_SAMPLES_MASK; if ((dpy = XOpenDisplay (NULL)) == NULL) { fprintf(stderr, "%s: can't open display: %s\n", argv[0], XDisplayName (NULL)); exit(1); } if (output_type != GLX_TYPE) { xsh.flags = PSize; xsh.width = width; xsh.height = height; xsh.x = 0; xsh.y = 0; win = XCreateWindow (dpy, RootWindow (dpy, DefaultScreen (dpy)), xsh.x, xsh.y, xsh.width, xsh.height, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, &xswa); XSetStandardProperties (dpy, win, PACKAGE, PACKAGE, None, argv, argc, &xsh); XSetWMHints (dpy, win, &xwmh); XSelectInput (dpy, win, StructureNotifyMask); } else { xsh.flags = PSize; xsh.width = width; xsh.height = height; xsh.x = 0; xsh.y = 0; mask = 0; templ.doublebuffer = 1; mask |= GLITZ_FORMAT_DOUBLEBUFFER_MASK; dformat = glitz_glx_find_window_format (dpy, DefaultScreen (dpy), mask, &templ, 0); vinfo = glitz_glx_get_visual_info_from_format (dpy, DefaultScreen (dpy), dformat); xswa.colormap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)), vinfo->visual, AllocNone); win = XCreateWindow (dpy, RootWindow (dpy, DefaultScreen (dpy)), xsh.x, xsh.y, xsh.width, xsh.height, 0, vinfo->depth, CopyFromParent, vinfo->visual, CWColormap, &xswa); XSetStandardProperties (dpy, win, PACKAGE, PACKAGE, None, argv, argc, &xsh); XSetWMHints (dpy, win, &xwmh); XSelectInput (dpy, win, StructureNotifyMask); } switch (output_type) { case XRENDER_TYPE: resize_pixmap (width, height); break; case IMAGE_TYPE: resize_image (width, height); break; case GLX_TYPE: drawable = glitz_glx_create_drawable_for_window (dpy, 0, dformat, win, width, height); if (!drawable) { printf ("failed to create glitz drawable\n"); exit (1); } break; } if (aa == 3 && dformat->samples < 2) { fprintf (stderr, "hardware multi-sampling not available\n"); exit (1); } if (drawable) { surface = resize_glitz_drawable (drawable, dformat, width, height); } cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); setup (test_type); XMapWindow (dpy, win); for (;;) { if (XPending (dpy)) { XNextEvent (dpy, &event); if (event.type == ConfigureNotify) { width = event.xconfigure.width; height = event.xconfigure.height; switch (output_type) { #ifdef CAIRO_HAS_XLIB_SURFACE case XRENDER_TYPE: resize_pixmap (width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; #endif case IMAGE_TYPE: resize_image (width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; case GLX_TYPE: cairo_surface_destroy (surface); surface = resize_glitz_drawable (drawable, dformat, width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; } } } else { render (test_type, output_type == GLX_TYPE); switch (output_type) { #ifdef CAIRO_HAS_XLIB_SURFACE case XRENDER_TYPE: XSetWindowBackgroundPixmap (dpy, win, pixmap); XClearWindow (dpy, win); break; #endif case IMAGE_TYPE: { GC gc; XImage *xim; pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy), width, height, DefaultDepth (dpy, DefaultScreen (dpy))); xim = XCreateImage(dpy, DefaultVisual (dpy, DefaultScreen (dpy)), DefaultDepth(dpy, DefaultScreen (dpy)), ZPixmap, 0, (char *) image, width, height, 32, 0); gc = XCreateGC (dpy, pixmap, 0, NULL); XPutImage (dpy, pixmap, gc, xim, 0, 0, 0, 0, width, height); XFreeGC (dpy, gc); xim->data = NULL; XDestroyImage (xim); XSetWindowBackgroundPixmap (dpy, win, pixmap); XClearWindow (dpy, win); XFreePixmap (dpy, pixmap); } break; } XSync (dpy, 0); } } exit (1); }
void Context::setTolerance( double tolerance ) { cairo_set_tolerance( mCairo, tolerance ); }
void DatabaseTask::Run() { while (true) { mutex.Lock(); while (newJob==NULL && !finish) { condition.Wait(mutex); } if (finish) { mutex.Unlock(); return; } if (newJob!=NULL) { currentJob=newJob; newJob=NULL; } mutex.Unlock(); if (currentJob!=NULL) { if (currentSurface==NULL || currentWidth!=currentJob->width || currentHeight!=currentJob->height) { cairo_destroy(currentCairo); cairo_surface_destroy(currentSurface); currentWidth=currentJob->width; currentHeight=currentJob->height; currentSurface=cairo_image_surface_create(CAIRO_FORMAT_RGB24, currentWidth,currentHeight); currentCairo=cairo_create(currentSurface); } currentLon=currentJob->lon; currentLat=currentJob->lat; currentMagnification=currentJob->magnification; if (database->IsOpen() && styleConfig.Valid()) { osmscout::MercatorProjection projection; osmscout::MapParameter drawParameter; osmscout::AreaSearchParameter searchParameter; std::list<std::string> paths; paths.push_back("../libosmscout/data/icons/14x14/standard/"); searchParameter.SetMaximumNodes(maxNodes->Get()); searchParameter.SetMaximumWays(maxWays->Get()); searchParameter.SetMaximumAreas(maxAreas->Get()); searchParameter.SetUseLowZoomOptimization(true); searchParameter.SetUseMultithreading(currentMagnification.GetMagnification()<=osmscout::Magnification::magCity); drawParameter.SetIconPaths(paths); drawParameter.SetPatternPaths(paths); drawParameter.SetOptimizeWayNodes(optimizeWays->Get() ? osmscout::TransPolygon::quality : osmscout::TransPolygon::none); drawParameter.SetOptimizeAreaNodes(optimizeAreas->Get() ? osmscout::TransPolygon::quality : osmscout::TransPolygon::none); drawParameter.SetDrawWaysWithFixedWidth(false); drawParameter.SetRenderSeaLand(true); drawParameter.SetDebugPerformance(true); if (!dpi->IsNull()) { drawParameter.SetDPI(dpi->GetDouble()); } else { drawParameter.SetDPI(Lum::OS::display->GetDPI()); } std::cout << std::endl; osmscout::StopClock overallTimer; projection.Set(currentLon, currentLat, currentMagnification, currentWidth, currentHeight); /* double width=10*drawParameter.GetDPI()/25.4; std::cout << "10mm => " << width << std::endl; double areaMinDegree=width/currentWidth*(projection.GetLonMax()-projection.GetLonMin()); size_t level=0; double levelDegree=360.0; std::cout << "Minimum area degree: " << areaMinDegree << std::endl; while (areaMinDegree<levelDegree) { levelDegree=levelDegree/2; level++; } level=level-1; //searchParameter.SetMaximumAreaLevel(level-log2(currentMagnification)); std::cout << "Resulting max area level: " << level-log2(currentMagnification) << " <=> " << searchParameter.GetMaximumAreaLevel() << std::endl; */ osmscout::TypeSet nodeTypes; std::vector<osmscout::TypeSet> wayTypes; osmscout::TypeSet areaTypes; try { styleConfig->GetNodeTypesWithMaxMag(projection.GetMagnification(), nodeTypes); styleConfig->GetWayTypesByPrioWithMaxMag(projection.GetMagnification(), wayTypes); } catch (std::exception& e) { std::cerr << "Exception while fetching style data: " << e.what() << std::endl; } styleConfig->GetAreaTypesWithMaxMag(projection.GetMagnification(), areaTypes); osmscout::StopClock dataRetrievalTimer; mapService->GetObjects(nodeTypes, wayTypes, areaTypes, projection.GetLonMin(), projection.GetLatMin(), projection.GetLonMax(), projection.GetLatMax(), projection.GetMagnification(), searchParameter, data.nodes, data.ways, data.areas); if (drawParameter.GetRenderSeaLand()) { mapService->GetGroundTiles(projection.GetLonMin(), projection.GetLatMin(), projection.GetLonMax(), projection.GetLatMax(), projection.GetMagnification(), data.groundTiles); } dataRetrievalTimer.Stop(); osmscout::StopClock drawTimer; cairo_set_tolerance(currentCairo,0.7); try { painter->DrawMap(projection, drawParameter, data, currentCairo); drawTimer.Stop(); overallTimer.Stop(); std::cout << "All: " << overallTimer << " Data: " << dataRetrievalTimer << " Draw: " << drawTimer << std::endl; } catch (std::exception& e) { std::cerr << "Exception while rendering: " << e.what() << std::endl; } } else { std::cout << "Cannot draw map: " << database->IsOpen() << " " << (styleConfig.Valid()) << std::endl; cairo_save(currentCairo); cairo_set_source_rgb(currentCairo,0,0,0); cairo_paint(currentCairo); cairo_restore(currentCairo); } mutex.Lock(); if (finishedJob!=NULL) { delete finishedJob; } finishedJob=currentJob; currentJob=NULL; std::swap(currentSurface,finishedSurface); std::swap(currentCairo,finishedCairo); std::swap(currentWidth,finishedWidth); std::swap(currentHeight,finishedHeight); std::swap(currentLon,finishedLon); std::swap(currentLat,finishedLat); std::swap(currentMagnification,finishedMagnification); Lum::OS::display->QueueActionForAsyncNotification(jobFinishedAction); mutex.Unlock(); } } }
void CairoRenderer::RenderOperator(const Operator *pOp, const Object **pParams, int nParams) { const char *cstr; double x, y; double v[6]; int i, n; const Object *pObj; const Stream *pStream; const Dictionary *pDict; cairo_matrix_t matrix; int nWidth, nHeight; cairo_surface_t *pSurface; cstr = pOp->GetValue(); if (strchr("fFbBW", *cstr) != NULL) if (cstr[1] == '\0') cairo_set_fill_rule(m_pCairo, CAIRO_FILL_RULE_WINDING); else if (cstr[1] == '*') cairo_set_fill_rule(m_pCairo, CAIRO_FILL_RULE_EVEN_ODD); if (*cstr == 'b') //close, fill, and stroke { cairo_close_path(m_pCairo); cairo_fill(m_pCairo); Stroke(); } else if (strcmp(cstr, "B") == 0 || strcmp(cstr, "B*") == 0) //fill and stroke { cairo_fill(m_pCairo); Stroke(); } else if (strcmp(cstr, "BDC") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "BI") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "BMC") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "BT") == 0) { cairo_save(m_pCairo); cairo_move_to(m_pCairo, 0.0, 0.0); m_cairo_face = NULL; } else if (strcmp(cstr, "BX") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "c") == 0) //curve to { ConvertNumeric(pParams, nParams, v); cairo_curve_to(m_pCairo, v[0], v[1], v[2], v[3], v[4], v[5]); } else if (strcmp(cstr, "cm") == 0) //concat { ConvertNumeric(pParams, nParams, v); cairo_matrix_init(&matrix, v[0], v[1], v[2], v[3], v[4], v[5]); cairo_transform(m_pCairo, &matrix); } else if (strcmp(cstr, "CS") == 0) //color space { NOT_IMPLEMENTED; } else if (strcmp(cstr, "cs") == 0) //color space { NOT_IMPLEMENTED; } else if (strcmp(cstr, "d") == 0) //line dash SetDash(pParams[0], pParams[1]); else if (strcmp(cstr, "d0") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "d1") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "Do") == 0) { pStream = (const Stream *)GetResource(XOBJECT, ((Name *)pParams[0])->GetValue()); pDict = pStream->GetDictionary(); pObj = pDict->GetValue("Subtype"); if (strcmp(((const Name *)pObj)->GetValue(), "Image") == 0) { nWidth = ((const Numeric *)pDict->GetValue("Width"))->GetValue(); nHeight = ((const Numeric *)pDict->GetValue("Height"))->GetValue(); cairo_matrix_init(&matrix, 1.0 / nWidth, 0.0, 0.0, -1.0 / nHeight, 0.0, 1.0); cairo_save(m_pCairo); cairo_transform(m_pCairo, &matrix); cairo_rectangle(m_pCairo, 0.0, 0.0, nWidth, nHeight); cairo_clip(m_pCairo); pSurface = CreateImageSurface(pStream, nWidth, nHeight); cairo_set_source_surface(m_pCairo, pSurface, 0.0, 0.0); cairo_paint(m_pCairo); cairo_surface_destroy(pSurface); cairo_restore(m_pCairo); } } else if (strcmp(cstr, "DP") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "EI") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "EMC") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "ET") == 0) { cairo_restore(m_pCairo); if (m_cairo_face) { cairo_set_font_face(m_pCairo, NULL); cairo_font_face_destroy(m_cairo_face); } } else if (strcmp(cstr, "EX") == 0) { NOT_IMPLEMENTED; } else if (*cstr == 'f' || *cstr == 'F') //fill cairo_fill(m_pCairo); else if (strcmp(cstr, "G") == 0) { ConvertNumeric(pParams, nParams, v); m_pStrokeColor[0] = v[0]; m_pStrokeColor[1] = v[0]; m_pStrokeColor[2] = v[0]; } else if (strcmp(cstr, "g") == 0) { ConvertNumeric(pParams, nParams, v); cairo_set_source_rgba(m_pCairo, v[0], v[0], v[0], 1.0); } else if (strcmp(cstr, "gs") == 0) //set graphics state SetGraphicsState(((const Name *)pParams[0])->GetValue()); else if (strcmp(cstr, "h") == 0) //close subpath cairo_close_path(m_pCairo); else if (strcmp(cstr, "i") == 0) //flatness tolerance { ConvertNumeric(pParams, nParams, v); cairo_set_tolerance(m_pCairo, v[0]); } else if (strcmp(cstr, "ID") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "j") == 0) //line join { ConvertNumeric(pParams, nParams, v); cairo_set_line_join(m_pCairo, (cairo_line_join_t)v[0]); } else if (strcmp(cstr, "J") == 0) //line cap { ConvertNumeric(pParams, nParams, v); cairo_set_line_cap(m_pCairo, (cairo_line_cap_t)v[0]); } else if (strcmp(cstr, "K") == 0) { ConvertNumeric(pParams, nParams, v); m_pStrokeColor[0] = (1.0 - v[0]) * (1.0 - v[3]); m_pStrokeColor[1] = (1.0 - v[1]) * (1.0 - v[3]); m_pStrokeColor[2] = (1.0 - v[2]) * (1.0 - v[3]); } else if (strcmp(cstr, "k") == 0) { ConvertNumeric(pParams, nParams, v); cairo_set_source_rgba(m_pCairo, (1.0 - v[0]) * (1.0 - v[3]), (1.0 - v[1]) * (1.0 - v[3]), (1.0 - v[2]) * (1.0 - v[3]), 1.0); } else if (strcmp(cstr, "l") == 0) //line to { ConvertNumeric(pParams, nParams, v); cairo_line_to(m_pCairo, v[0], v[1]); } else if (strcmp(cstr, "m") == 0) //new sub path { ConvertNumeric(pParams, nParams, v); cairo_move_to(m_pCairo, v[0], v[1]); } else if (strcmp(cstr, "M") == 0) //miter limit { ConvertNumeric(pParams, nParams, v); cairo_set_miter_limit(m_pCairo, v[0]); } else if (strcmp(cstr, "MP") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "n") == 0) //end path cairo_new_path(m_pCairo); else if (strcmp(cstr, "q") == 0) //save graphics state cairo_save(m_pCairo); else if (strcmp(cstr, "Q") == 0) //restore graphics state cairo_restore(m_pCairo); else if (strcmp(cstr, "re") == 0) //rectangle { ConvertNumeric(pParams, nParams, v); cairo_rectangle(m_pCairo, v[0], v[1], v[2], v[3]); } else if (strcmp(cstr, "RG") == 0) { ConvertNumeric(pParams, nParams, m_pStrokeColor); } else if (strcmp(cstr, "rg") == 0) { ConvertNumeric(pParams, nParams, v); cairo_set_source_rgba(m_pCairo, v[0], v[1], v[2], 1.0); } else if (strcmp(cstr, "ri") == 0) //color rendering intent SetIntent(((const Name *)pParams[0])->GetValue()); else if (strcmp(cstr, "s") == 0) //close and stroke { cairo_close_path(m_pCairo); Stroke(); } else if (strcmp(cstr, "S") == 0) //stroke Stroke(); else if (strcmp(cstr, "SC") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "sc") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "SCN") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "scn") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "sh") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "T*") == 0) { cairo_translate(m_pCairo, 0.0, -m_dTextLead); cairo_move_to(m_pCairo, 0.0, 0.0); } else if (strcmp(cstr, "Tc") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "Td") == 0) { ConvertNumeric(pParams, nParams, v); cairo_translate(m_pCairo, v[0], v[1]); cairo_move_to(m_pCairo, 0.0, 0.0); } else if (strcmp(cstr, "TD") == 0) { ConvertNumeric(pParams, nParams, v); cairo_translate(m_pCairo, v[0], v[1]); cairo_move_to(m_pCairo, 0.0, 0.0); m_dTextLead = -v[1]; } else if (strcmp(cstr, "Tf") == 0) { ChangeFont(((const Name *)pParams[0])->GetValue()); SetFontFace(m_pFontData->GetFontFile()); ConvertNumeric(pParams + 1, nParams - 1, v); cairo_matrix_init_scale(m_pFontMatrix, v[0], -v[0]); cairo_set_font_matrix(m_pCairo, m_pFontMatrix); } else if (strcmp(cstr, "Tj") == 0) RenderString((const String *)pParams[0]); else if (strcmp(cstr, "TJ") == 0) { n = ((const Array *)pParams[0])->GetSize(); for (i = 0; i < n; i++) { pObj = ((const Array *)pParams[0])->GetValue(i); if (pObj->GetType() == Object::OBJ_STRING) RenderString((const String *)pObj); else if (pObj->GetType() == Object::OBJ_NUMERIC) cairo_translate(m_pCairo, -((const Numeric *)pObj)->GetValue() / 1000.0, 0.0); } } else if (strcmp(cstr, "TL") == 0) { ConvertNumeric(pParams, nParams, v); m_dTextLead = v[0]; } else if (strcmp(cstr, "Tm") == 0) { ConvertNumeric(pParams, nParams, v); cairo_matrix_init(&matrix, v[0], v[1], v[2], v[3], v[4], v[5]); cairo_matrix_multiply(&matrix, m_pFontMatrix, &matrix); cairo_set_font_matrix(m_pCairo, &matrix); cairo_move_to(m_pCairo, 0.0, 0.0); } else if (strcmp(cstr, "Tr") == 0) { ConvertNumeric(pParams, nParams, v); m_nTextMode = v[0]; } else if (strcmp(cstr, "Ts") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "Tw") == 0) { NOT_IMPLEMENTED; } else if (strcmp(cstr, "Tz") == 0) { ConvertNumeric(pParams, nParams, v); cairo_scale(m_pCairo, v[0] / 100.0, 1.0); } else if (strcmp(cstr, "v") == 0) //curve to { ConvertNumeric(pParams, nParams, v); cairo_get_current_point(m_pCairo, &x, &y); cairo_curve_to(m_pCairo, x, y, v[0], v[1], v[2], v[3]); } else if (strcmp(cstr, "w") == 0) //line width { ConvertNumeric(pParams, nParams, v); cairo_set_line_width(m_pCairo, v[0] + 0.5); } else if (*cstr == 'W') //clipping path cairo_clip(m_pCairo); else if (strcmp(cstr, "y") == 0) //curve to { ConvertNumeric(pParams, nParams, v); cairo_curve_to(m_pCairo, v[0], v[1], v[2], v[3], v[2], v[3]); } else if (strcmp(cstr, "'") == 0) { cairo_translate(m_pCairo, 0.0, -m_dTextLead); cairo_move_to(m_pCairo, 0.0, 0.0); RenderString((const String *)pParams[0]); } else if (strcmp(cstr, "\"") == 0) { cairo_translate(m_pCairo, 0.0, -m_dTextLead); cairo_move_to(m_pCairo, 0.0, 0.0); RenderString((const String *)pParams[2]); } else { assert(false); } }
static int cr_set_tolerance (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); cairo_set_tolerance(*obj, luaL_checknumber(L, 2)); return 0; }
void drawPie(cairo_t* c, int w, int h) { double w2 = w / 2.0f; double h2 = h / 2.0f; double r = h2 * 0.8f; double seg = (2.0f * osg::PI) / 8.0f; double top = osg::PI + (osg::PI / 2.0f); // each "tier" or level or an arc double lvl[] = { 0.0f, 0.25f, 0.50f, 0.75f, 1.0f }; const char* atts[] = { "Milk", "Horns", "Beefiness", "Moo/HR", "Grazing", "Sleeping", "Cowpower!", "s p o t s" }; double attl[] = { 0.25f, 0.0f, 0.50f, 1.0f, 0.0f, 0.25f, 0.75f, 1.0f }; cairo_set_line_width(c, ((w + h) / 2.0f) * 0.003f); cairo_select_font_face(c, "SegoeUI", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(c, ((w + h) / 2.0f) * 0.05f); cairo_translate(c, w2, h2); cairo_rotate(c, -seg / 2.0f); cairo_set_source_rgba(c, 1.0f, 1.0f, 1.0f, 1.0f); for(unsigned int i = 0; i < 8; i++) { // Pick a random level... cairo_move_to(c, 0.0f, 0.0f); cairo_line_to(c, 0.0f, -r); cairo_arc(c, 0.0f, 0.0f, attl[i] * r, top, top + seg); cairo_line_to(c, 0.0f, 0.0f); cairo_set_source_rgba(c, 0.2f, 0.8f, 0.2f, 0.5f); cairo_fill(c); cairo_set_source_rgba(c, 1.0f, 1.0f, 1.0f, 1.0f); // Do the various levels... cairo_move_to(c, 0.0f, 0.0f); cairo_line_to(c, 0.0f, -r); cairo_stroke(c); for(unsigned int l = 0; l < 5; l++) { cairo_arc(c, 0.0f, 0.0f, lvl[l] * r, top, top + seg); cairo_stroke(c); } cairo_text_extents_t extents; cairo_text_extents(c, atts[i], &extents); double arcsize = r * seg; // ------------------------------------ cairo_save(c); double tr = extents.width / r; double aa = ((arcsize - extents.width) / 2.0f) / r; cairo_arc(c, 0.0f, 0.0f, h2 * 0.85f, top + aa, top + aa + tr); cairo_set_tolerance(c, 0.01f); cairo_path_t* path = cairo_copy_path_flat(c); cairo_new_path(c); cairo_text_path(c, atts[i]); osgCairo::mapPathOnto(c, path); cairo_path_destroy(path); cairo_set_source_rgba(c, 1.0f, 1.0f, 1.0f, 1.0f); cairo_set_line_width(c, 1.0f); cairo_stroke_preserve(c); cairo_set_source_rgba(c, 0.8f, 0.5f, 0.1f, 0.7f); cairo_fill(c); cairo_restore(c); // ------------------------------------ // Pick a random level... cairo_move_to(c, 0.0f, 0.0f); cairo_line_to(c, 0.0f, -r); cairo_arc(c, 0.0f, 0.0f, r, top, top + seg); cairo_line_to(c, 0.0f, 0.0f); cairo_set_source_rgba(c, 1.0f, 1.0f, 1.0f, 1.0f); cairo_stroke(c); cairo_rotate(c, seg); } }
ClutterActor* make_flower_actor (void) { /* No science here, just a hack from toying */ gint i, j; double colors[] = { 0.71, 0.81, 0.83, 1.0, 0.78, 0.57, 0.64, 0.30, 0.35, 0.73, 0.40, 0.39, 0.91, 0.56, 0.64, 0.70, 0.47, 0.45, 0.92, 0.75, 0.60, 0.82, 0.86, 0.85, 0.51, 0.56, 0.67, 1.0, 0.79, 0.58, }; gint size; gint petal_size; gint n_groups; /* Num groups of petals 1-3 */ gint n_petals; /* num of petals 4 - 8 */ gint pm1, pm2; gint idx, last_idx = -1; ClutterActor *ctex; cairo_t *cr; petal_size = PETAL_MIN + rand() % PETAL_VAR; size = petal_size * 8; n_groups = rand() % 3 + 1; ctex = clutter_cairo_texture_new (size, size); cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (ctex)); cairo_set_tolerance (cr, 0.1); /* Clear */ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_translate(cr, size/2, size/2); for (i=0; i<n_groups; i++) { n_petals = rand() % 5 + 4; cairo_save (cr); cairo_rotate (cr, rand() % 6); do { idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; } while (idx == last_idx); cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5); last_idx = idx; /* some bezier randomness */ pm1 = rand() % 20; pm2 = rand() % 4; for (j=1; j<n_petals+1; j++) { cairo_save (cr); cairo_rotate (cr, ((2*M_PI)/n_petals)*j); /* Petals are made up beziers */ cairo_new_path (cr); cairo_move_to (cr, 0, 0); cairo_rel_curve_to (cr, petal_size, petal_size, (pm2+2)*petal_size, petal_size, (2*petal_size) + pm1, 0); cairo_rel_curve_to (cr, 0 + (pm2*petal_size), -petal_size, -petal_size, -petal_size, -((2*petal_size) + pm1), 0); cairo_close_path (cr); cairo_fill (cr); cairo_restore (cr); } petal_size -= rand() % (size/8); cairo_restore (cr); } /* Finally draw flower center */ do { idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; } while (idx == last_idx); if (petal_size < 0) petal_size = rand() % 10; cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5); cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2); cairo_fill(cr); cairo_destroy(cr); return ctex; }
static cairo_test_status_t preamble (cairo_test_context_t *ctx) { cairo_t *cr; cairo_test_status_t ret = CAIRO_TEST_UNTESTED; struct { double x, y; } ppi[] = { { 600, 600 }, { 600, 72 }, { 300, 300 }, { 300, 72 }, { 150, 150 }, { 150, 72 }, { 75, 75 }, { 75, 72 }, { 72, 600 }, { 72, 300 }, { 72, 150 }, { 72, 75 }, { 72, 72 }, { 72, 37.5 }, { 37.5, 72 }, { 37.5, 37.5 }, }; unsigned int i; int n, num_ppi; num_ppi = sizeof (ppi) / sizeof (ppi[0]); #if GENERATE_REFERENCE for (n = 0; n < num_ppi; n++) { char *ref_name; xasprintf (&ref_name, "fallback-resolution.ppi%gx%g.ref.png", ppi[n].x, ppi[n].y); generate_reference (ppi[n].x, ppi[n].y, ref_name); free (ref_name); } #endif for (i = 0; i < ctx->num_targets; i++) { const cairo_boilerplate_target_t *target = ctx->targets_to_test[i]; cairo_surface_t *surface = NULL; char *base_name; void *closure; const char *format; cairo_status_t status; if (! target->is_vector) continue; if (! cairo_test_is_target_enabled (ctx, target->name)) continue; format = cairo_boilerplate_content_name (target->content); xasprintf (&base_name, "fallback-resolution.%s.%s", target->name, format); surface = (target->create_surface) (base_name, target->content, SIZE, SIZE, SIZE, SIZE, CAIRO_BOILERPLATE_MODE_TEST, 0, &closure); if (surface == NULL) { free (base_name); continue; } if (ret == CAIRO_TEST_UNTESTED) ret = CAIRO_TEST_SUCCESS; cairo_surface_destroy (surface); if (target->cleanup) target->cleanup (closure); free (base_name); /* we need to recreate the surface for each resolution as we include * SVG in testing which does not support the paginated interface. */ for (n = 0; n < num_ppi; n++) { char *test_name; cairo_bool_t pass; xasprintf (&test_name, "fallback-resolution.ppi%gx%g", ppi[n].x, ppi[n].y); xasprintf (&base_name, "%s.%s.%s", test_name, target->name, format); surface = (target->create_surface) (base_name, target->content, SIZE + 25, SIZE + 25, SIZE + 25, SIZE + 25, CAIRO_BOILERPLATE_MODE_TEST, 0, &closure); if (surface == NULL || cairo_surface_status (surface)) { cairo_test_log (ctx, "Failed to generate surface: %s.%s\n", target->name, format); free (base_name); free (test_name); ret = CAIRO_TEST_FAILURE; continue; } cairo_test_log (ctx, "Testing fallback-resolution %gx%g with %s target\n", ppi[n].x, ppi[n].y, target->name); printf ("%s:\t", base_name); fflush (stdout); if (target->force_fallbacks != NULL) target->force_fallbacks (surface, ~0U); cr = cairo_create (surface); #if SET_TOLERANCE cairo_set_tolerance (cr, 3.0); #endif cairo_surface_set_device_offset (surface, 25, 25); cairo_surface_set_fallback_resolution (surface, ppi[n].x, ppi[n].y); cairo_save (cr); { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); } cairo_restore (cr); /* First draw the top half in a conventional way. */ cairo_save (cr); { cairo_rectangle (cr, 0, 0, SIZE, SIZE / 2.0); cairo_clip (cr); draw (cr, SIZE, SIZE); } cairo_restore (cr); /* Then draw the bottom half in a separate group, * (exposing a bug in 1.6.4 with the group not being * rendered with the correct fallback resolution). */ cairo_save (cr); { cairo_rectangle (cr, 0, SIZE / 2.0, SIZE, SIZE / 2.0); cairo_clip (cr); cairo_push_group (cr); { draw (cr, SIZE, SIZE); } cairo_pop_group_to_source (cr); cairo_paint (cr); } cairo_restore (cr); status = cairo_status (cr); cairo_destroy (cr); pass = FALSE; if (status) { cairo_test_log (ctx, "Error: Failed to create target surface: %s\n", cairo_status_to_string (status)); ret = CAIRO_TEST_FAILURE; } else { /* extract the image and compare it to our reference */ if (! check_result (ctx, target, test_name, base_name, surface)) ret = CAIRO_TEST_FAILURE; else pass = TRUE; } cairo_surface_destroy (surface); if (target->cleanup) target->cleanup (closure); free (base_name); free (test_name); if (pass) { printf ("PASS\n"); } else { printf ("FAIL\n"); } fflush (stdout); } } return ret; }
static gboolean draw_flower (ClutterCanvas *canvas, cairo_t *cr, gint width, gint height, gpointer user_data) { /* No science here, just a hack from toying */ gint i, j; double colors[] = { 0.71, 0.81, 0.83, 1.0, 0.78, 0.57, 0.64, 0.30, 0.35, 0.73, 0.40, 0.39, 0.91, 0.56, 0.64, 0.70, 0.47, 0.45, 0.92, 0.75, 0.60, 0.82, 0.86, 0.85, 0.51, 0.56, 0.67, 1.0, 0.79, 0.58, }; gint size; gint petal_size; gint n_groups; /* Num groups of petals 1-3 */ gint n_petals; /* num of petals 4 - 8 */ gint pm1, pm2; gint idx, last_idx = -1; petal_size = GPOINTER_TO_INT (user_data); size = petal_size * 8; n_groups = rand() % 3 + 1; cairo_set_tolerance (cr, 0.1); /* Clear */ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_translate(cr, size/2, size/2); for (i=0; i<n_groups; i++) { n_petals = rand() % 5 + 4; cairo_save (cr); cairo_rotate (cr, rand() % 6); do { idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; } while (idx == last_idx); cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5); last_idx = idx; /* some bezier randomness */ pm1 = rand() % 20; pm2 = rand() % 4; for (j=1; j<n_petals+1; j++) { cairo_save (cr); cairo_rotate (cr, ((2*M_PI)/n_petals)*j); /* Petals are made up beziers */ cairo_new_path (cr); cairo_move_to (cr, 0, 0); cairo_rel_curve_to (cr, petal_size, petal_size, (pm2+2)*petal_size, petal_size, (2*petal_size) + pm1, 0); cairo_rel_curve_to (cr, 0 + (pm2*petal_size), -petal_size, -petal_size, -petal_size, -((2*petal_size) + pm1), 0); cairo_close_path (cr); cairo_fill (cr); cairo_restore (cr); } petal_size -= rand() % (size/8); cairo_restore (cr); } /* Finally draw flower center */ do { idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; } while (idx == last_idx); if (petal_size < 0) petal_size = rand() % 10; cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5); cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2); cairo_fill(cr); return TRUE; }
void lime_cairo_set_tolerance (value handle, double tolerance) { cairo_set_tolerance ((cairo_t*)val_data (handle), tolerance); }
void grava_renderer_draw_node (cairo_t* ctx, GravaNode* node) { #line 185 "renderer.vala" g_return_if_fail (ctx != NULL); #line 185 "renderer.vala" g_return_if_fail (node != NULL); #line 187 "renderer.vala" cairo_save (ctx); #line 189 "renderer.vala" cairo_set_tolerance (ctx, 0.1); #line 190 "renderer.vala" cairo_set_line_join (ctx, CAIRO_LINE_JOIN_ROUND); #line 191 "renderer.vala" cairo_set_line_width (ctx, (double) 1); #line 192 "renderer.vala" cairo_translate (ctx, node->x, node->y); #line 462 "renderer.c" /*ctx.set_source_rgb (1, 1, 1);*/ #line 195 "renderer.vala" cairo_set_source_rgb (ctx, 0.8, 0.8, 0.8); #line 466 "renderer.c" /*#if 0 if (node.calls.length() >0) set_color(ctx, "red"); else set_color(ctx, "blue"); #endif */ #line 203 "renderer.vala" grava_renderer_set_color (ctx, node->data); #line 204 "renderer.vala" grava_renderer_set_color_str (ctx, (const char*) g_hash_table_lookup (node->data, "bgcolor")); #line 206 "renderer.vala" if (node->has_body) { #line 207 "renderer.vala" switch (node->shape) { #line 482 "renderer.c" case GRAVA_SHAPE_CIRCLE: { #line 209 "renderer.vala" grava_renderer_circle (ctx, node->w, node->h); #line 210 "renderer.vala" cairo_fill (ctx); #line 211 "renderer.vala" break; #line 491 "renderer.c" } default: { #line 214 "renderer.vala" grava_renderer_square (ctx, node->w, node->h); #line 215 "renderer.vala" cairo_fill (ctx); #line 216 "renderer.vala" break; #line 501 "renderer.c" } } } /* title rectangle */ #line 221 "renderer.vala" if (((const char*) g_hash_table_lookup (node->data, "color")) != NULL) { #line 222 "renderer.vala" grava_renderer_set_color_str (ctx, (const char*) g_hash_table_lookup (node->data, "color")); #line 510 "renderer.c" } else { #line 224 "renderer.vala" if (g_slist_length (node->calls) == 1) { #line 225 "renderer.vala" cairo_set_source_rgba (ctx, 0.2, 0.2, 0.4, 0.7); #line 516 "renderer.c" } else { #line 227 "renderer.vala" if (g_slist_length (node->calls) > 0) { #line 228 "renderer.vala" cairo_set_source_rgba (ctx, 0.3, 0.3, (double) 1, 0.7); #line 522 "renderer.c" } else { #line 230 "renderer.vala" cairo_set_source_rgba (ctx, 0.8, 0.8, 0.8, 0.8); #line 526 "renderer.c" } } } #line 231 "renderer.vala" grava_renderer_square (ctx, node->w, (double) 15); #line 232 "renderer.vala" cairo_fill (ctx); #line 233 "renderer.vala" grava_renderer_line (ctx, (double) 0, (double) 15, node->w, (double) 0); #line 536 "renderer.c" /* draw minimize button */ #line 236 "renderer.vala" cairo_save (ctx); #line 540 "renderer.c" /*ctx.set_source_rgba (0.7, 0.0, 0.0, 1);*/ #line 238 "renderer.vala" cairo_set_source_rgba (ctx, 0.6, 0.6, 0.6, 0.8); #line 239 "renderer.vala" cairo_translate (ctx, node->w - 13, (double) 3); #line 240 "renderer.vala" grava_renderer_square (ctx, (double) 10, (double) 10); #line 241 "renderer.vala" cairo_fill (ctx); #line 242 "renderer.vala" cairo_restore (ctx); #line 244 "renderer.vala" cairo_select_font_face (ctx, "Sans Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); #line 554 "renderer.c" /*Courier", */ #line 247 "renderer.vala" cairo_set_font_size (ctx, (double) 10); #line 558 "renderer.c" /* set label */ #line 250 "renderer.vala" cairo_set_source_rgb (ctx, 0.1, 0.1, 0.1); #line 251 "renderer.vala" cairo_move_to (ctx, (double) 5, (double) 10); #line 252 "renderer.vala" cairo_show_text (ctx, (const char*) g_hash_table_lookup (node->data, "label")); #line 566 "renderer.c" /* set body */ #line 255 "renderer.vala" if (node->has_body) { #line 570 "renderer.c" gint y; const char* _tmp0_; char* body; y = 25; #line 257 "renderer.vala" _tmp0_ = NULL; #line 577 "renderer.c" body = (_tmp0_ = (const char*) g_hash_table_lookup (node->data, "body"), (_tmp0_ == NULL) ? NULL : g_strdup (_tmp0_)); #line 258 "renderer.vala" if (body != NULL) { #line 581 "renderer.c" { char** _tmp1_; char** str_collection; int str_collection_length1; int str_it; _tmp1_ = NULL; #line 259 "renderer.vala" str_collection = _tmp1_ = g_strsplit (body, "\n", 0); #line 590 "renderer.c" str_collection_length1 = _vala_array_length (_tmp1_); for (str_it = 0; str_it < _vala_array_length (_tmp1_); str_it = str_it + 1) { const char* _tmp3_; char* str; #line 822 "glib-2.0.vapi" _tmp3_ = NULL; #line 597 "renderer.c" str = (_tmp3_ = str_collection[str_it], (_tmp3_ == NULL) ? NULL : g_strdup (_tmp3_)); { gboolean _tmp2_ = {0}; #line 260 "renderer.vala" y = y + 10; #line 261 "renderer.vala" cairo_move_to (ctx, (double) 5, (double) y); #line 262 "renderer.vala" if (strstr (str, "call ") != NULL) { #line 262 "renderer.vala" _tmp2_ = TRUE; #line 609 "renderer.c" } else { #line 263 "renderer.vala" _tmp2_ = strstr (str, "bl ") != NULL; #line 613 "renderer.c" } #line 262 "renderer.vala" if (_tmp2_) { #line 264 "renderer.vala" grava_renderer_set_color_str (ctx, "blue"); #line 619 "renderer.c" } else { #line 266 "renderer.vala" if (strstr (str, "goto") != NULL) { #line 267 "renderer.vala" grava_renderer_set_color_str (ctx, "green"); #line 625 "renderer.c" } else { #line 269 "renderer.vala" if (strstr (str, " j") != NULL) { #line 270 "renderer.vala" grava_renderer_set_color_str (ctx, "green"); #line 631 "renderer.c" } else { #line 272 "renderer.vala" if (g_str_has_suffix (str, ":")) { #line 273 "renderer.vala" grava_renderer_set_color_str (ctx, "red"); #line 637 "renderer.c" } else { #line 275 "renderer.vala" grava_renderer_set_color_str (ctx, "black"); #line 641 "renderer.c" } } } } #line 276 "renderer.vala" cairo_show_text (ctx, str); #line 648 "renderer.c" str = (g_free (str), NULL); } } #line 259 "renderer.vala" str_collection = (_vala_array_free (str_collection, str_collection_length1, (GDestroyNotify) g_free), NULL); #line 654 "renderer.c" } } /*set_color(ctx, node.data); box square */ #line 281 "renderer.vala" if (grava_graph_selected == node) { #line 661 "renderer.c" /*ctx.set_source_rgba (1, 0.8, 0.0, 0.9);*/ #line 283 "renderer.vala" cairo_set_source_rgba (ctx, (double) 0, 0.0, 0.0, 1.0); #line 284 "renderer.vala" cairo_set_line_width (ctx, (double) 2); #line 667 "renderer.c" } else { #line 286 "renderer.vala" cairo_set_source_rgba (ctx, 0.2, 0.2, 0.2, 0.4); #line 287 "renderer.vala" cairo_set_line_width (ctx, (double) 1); #line 673 "renderer.c" } #line 290 "renderer.vala" if (node->shape == GRAVA_SHAPE_CIRCLE) { #line 291 "renderer.vala" grava_renderer_circle (ctx, node->w, node->h); #line 679 "renderer.c" } else { #line 292 "renderer.vala" grava_renderer_square (ctx, node->w, node->h); #line 683 "renderer.c" } body = (g_free (body), NULL); } #line 295 "renderer.vala" cairo_stroke (ctx); #line 297 "renderer.vala" cairo_restore (ctx); #line 691 "renderer.c" }