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; }
int renderTruetypeSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *s) { int unicode; cairo_glyph_t glyph; cairo_text_extents_t extents; cairo_matrix_t trans; double ox,oy; cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img); cairo_renderer *r = CAIRO_RENDERER(img); faceCacheObj *face = getFontFace(cache,symbol->full_font_path); if(!face) return MS_FAILURE; cairo_save(r->cr); cairo_set_font_face(r->cr,face->face); cairo_set_font_size(r->cr,s->scale*96/72.0); msUTF8ToUniChar(symbol->character, &unicode); if (face->ftface->charmap && face->ftface->charmap->encoding == FT_ENCODING_MS_SYMBOL) unicode |= 0xf000; glyph.index = FT_Get_Char_Index(face->ftface, unicode); glyph.x=0; glyph.y=0; cairo_glyph_extents(r->cr,&glyph,1,&extents); ox=extents.x_bearing+extents.width/2.; oy=extents.y_bearing+extents.height/2.; cairo_matrix_init_rotate(&trans,-s->rotation); cairo_matrix_transform_point(&trans,&ox,&oy); /* cairo_translate(cr,-extents.width/2,-extents.height/2); */ cairo_translate(r->cr,x-ox,y-oy); cairo_rotate(r->cr, -s->rotation); cairo_glyph_path(r->cr,&glyph,1); if (s->outlinewidth) { msCairoSetSourceColor(r->cr, s->outlinecolor); cairo_set_line_width(r->cr, s->outlinewidth + 1); cairo_stroke_preserve(r->cr); } if(s->color) { msCairoSetSourceColor(r->cr, s->color); cairo_fill_preserve(r->cr); } cairo_new_path(r->cr); cairo_restore(r->cr); return MS_SUCCESS; }
int renderLineCairo(imageObj *img, shapeObj *p, strokeStyleObj *stroke) { int i,j; cairo_renderer *r = CAIRO_RENDERER(img); assert(stroke->color); cairo_new_path(r->cr); msCairoSetSourceColor(r->cr,stroke->color); for(i=0;i<p->numlines;i++) { lineObj *l = &(p->line[i]); cairo_move_to(r->cr,l->point[0].x,l->point[0].y); for(j=1;j<l->numpoints;j++) { cairo_line_to(r->cr,l->point[j].x,l->point[j].y); } } if(stroke->patternlength>0) { cairo_set_dash(r->cr,stroke->pattern,stroke->patternlength,0); } switch(stroke->linecap) { case MS_CJC_BUTT: cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_BUTT); break; case MS_CJC_SQUARE: cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_SQUARE); break; case MS_CJC_ROUND: case MS_CJC_NONE: default: cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_ROUND); } cairo_set_line_width (r->cr, stroke->width); cairo_stroke (r->cr); if(stroke->patternlength>0) { cairo_set_dash(r->cr,stroke->pattern,0,0); } return MS_SUCCESS; }
int renderGlyphs2Cairo(imageObj *img, textPathObj *tp, colorObj *c, colorObj *oc, int ow) { cairo_renderer *r = CAIRO_RENDERER(img); cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img); cairoFaceCache *cairo_face = NULL; FT_Face prevface = NULL; int g; cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0)); for(g=0;g<tp->numglyphs;g++) { glyphObj *gl = &tp->glyphs[g]; cairo_glyph_t glyph; /* load the glyph's face into cairo, if not already present */ if(gl->face->face != prevface) { cairo_face = getCairoFontFace(cache,gl->face->face); cairo_set_font_face(r->cr, cairo_face->face); cairo_set_font_options(r->cr,cairo_face->options); prevface = gl->face->face; cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0)); } cairo_save(r->cr); cairo_translate(r->cr,gl->pnt.x,gl->pnt.y); if(gl->rot != 0.0) cairo_rotate(r->cr, -gl->rot); glyph.x = glyph.y = 0; glyph.index = gl->glyph->key.codepoint; cairo_glyph_path(r->cr,&glyph,1); cairo_restore(r->cr); } if (oc) { cairo_save(r->cr); msCairoSetSourceColor(r->cr, oc); cairo_set_line_width(r->cr, ow + 1); cairo_stroke_preserve(r->cr); cairo_restore(r->cr); } if(c) { msCairoSetSourceColor(r->cr, c); cairo_fill(r->cr); } cairo_new_path(r->cr); return MS_SUCCESS; }
int renderVectorSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); double ox=symbol->sizex*0.5,oy=symbol->sizey*0.5; int is_new = 1,i; cairo_new_path(r->cr); cairo_save(r->cr); cairo_translate(r->cr,x,y); cairo_scale(r->cr,style->scale,style->scale); cairo_rotate(r->cr,-style->rotation); cairo_translate(r->cr,-ox,-oy); for (i = 0; i < symbol->numpoints; i++) { if ((symbol->points[i].x == -99) && (symbol->points[i].y == -99)) { /* (PENUP) */ is_new = 1; } else { if (is_new) { cairo_move_to(r->cr,symbol->points[i].x,symbol->points[i].y); is_new = 0; } else { cairo_line_to(r->cr,symbol->points[i].x,symbol->points[i].y); } } } cairo_restore(r->cr); if(style->color) { msCairoSetSourceColor(r->cr,style->color); cairo_fill_preserve(r->cr); } if(style->outlinewidth>0) { msCairoSetSourceColor(r->cr,style->outlinecolor); cairo_set_line_width (r->cr, style->outlinewidth); cairo_stroke_preserve(r->cr); } cairo_new_path(r->cr); return MS_SUCCESS; }
int renderPolygonCairo(imageObj *img, shapeObj *p, colorObj *c) { cairo_renderer *r = CAIRO_RENDERER(img); int i,j; cairo_new_path(r->cr); cairo_set_fill_rule(r->cr,CAIRO_FILL_RULE_EVEN_ODD); msCairoSetSourceColor(r->cr,c); for(i=0;i<p->numlines;i++) { lineObj *l = &(p->line[i]); cairo_move_to(r->cr,l->point[0].x,l->point[0].y); for(j=1;j<l->numpoints;j++) { cairo_line_to(r->cr,l->point[j].x,l->point[j].y); } cairo_close_path(r->cr); } cairo_fill(r->cr); return MS_SUCCESS; }
imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg) { imageObj *image = NULL; cairo_renderer *r=NULL; if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) { msSetError(MS_MISCERR, "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()"); return image; } if (width > 0 && height > 0) { image = (imageObj *) calloc(1, sizeof(imageObj)); r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer)); if(!strcasecmp(format->driver,"cairo/pdf")) { r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_pdf_surface_create_for_stream( _stream_write_fn, r->outputStream, width,height); } else if(!strcasecmp(format->driver,"cairo/svg")) { r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_svg_surface_create_for_stream( _stream_write_fn, r->outputStream, width,height); } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_surface_create(format->device); #else msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", "msImageCreateCairo()"); #endif } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_printing_surface_create(format->device); #else msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", "msImageCreateCairo()"); #endif } else { r->outputStream = NULL; r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); } r->cr = cairo_create(r->surface); if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) { r->use_alpha = 1; cairo_set_source_rgba (r->cr, 0,0,0,0); } else { r->use_alpha = 0; msCairoSetSourceColor(r->cr,bg); } cairo_save (r->cr); cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE); cairo_paint (r->cr); cairo_restore (r->cr); cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND); cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND); image->img.plugin = (void*)r; } else { msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.", "msImageCreateCairo()", width, height); } return image; }
int renderGlyphsCairo(imageObj *img,double x, double y, labelStyleObj *style, char *text) { cairo_renderer *r = CAIRO_RENDERER(img); cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img); faceCacheObj *face = getFontFace(cache,style->font); char *utfptr=text; int i,has_kerning,unicode; unsigned long previdx=0; int numglyphs = msGetNumGlyphs(text); cairo_glyph_t glyph; cairo_text_extents_t extents; double px=0,py=0; if(face == NULL) { return MS_FAILURE; } cairo_set_font_face(r->cr,face->face); cairo_set_font_size(r->cr,style->size*96/72.0); cairo_save(r->cr); cairo_translate(r->cr,MS_NINT(x),MS_NINT(y)); if(style->rotation != 0.0) cairo_rotate(r->cr, -style->rotation); has_kerning = FT_HAS_KERNING((face->ftface)); for(i=0;i<numglyphs;i++) { utfptr+=msUTF8ToUniChar(utfptr, &unicode); glyph.x=px; glyph.y=py; if(unicode=='\n') { py += ceil(style->size*CAIROLINESPACE); px = 0; previdx=0; continue; } glyph.index = FT_Get_Char_Index(face->ftface, unicode); if( has_kerning && previdx ) { FT_Vector delta; FT_Get_Kerning( face->ftface, previdx, glyph.index, FT_KERNING_DEFAULT, &delta ); px += delta.x / 64.; } cairo_glyph_extents(r->cr,&glyph,1,&extents); cairo_glyph_path(r->cr,&glyph,1); px += extents.x_advance; previdx=glyph.index; } if (style->outlinewidth > 0) { cairo_save(r->cr); msCairoSetSourceColor(r->cr, style->outlinecolor); cairo_set_line_width(r->cr, style->outlinewidth + 1); cairo_stroke_preserve(r->cr); cairo_restore(r->cr); } if(style->color) { msCairoSetSourceColor(r->cr, style->color); cairo_fill(r->cr); } cairo_new_path(r->cr); cairo_restore(r->cr); return MS_SUCCESS; }