Mercurial > MadButterfly
diff src/graph_engine_cairo.c @ 1067:7b4e80ab671a openvg
merge from default branch
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Dec 2010 12:25:56 +0800 |
parents | ac2e6468a22a 74e3ba4d3fa1 |
children | d09f603438d8 |
line wrap: on
line diff
--- a/src/graph_engine_cairo.c Mon Jul 19 15:44:49 2010 +0800 +++ b/src/graph_engine_cairo.c Wed Dec 01 12:25:56 2010 +0800 @@ -1,3 +1,5 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 #include <fontconfig/fontconfig.h> #include <cairo-ft.h> #include "mb_graph_engine_cairo.h" @@ -17,7 +19,7 @@ */ static FcPattern *query_font_pattern(const char *family, int slant, int weight) { - FcPattern *ptn, *p, *fn_ptn; + FcPattern *ptn, *fn_ptn; FcValue val; FcConfig *cfg; FcBool r; @@ -30,33 +32,32 @@ cfg = FcConfigGetCurrent(); ptn = FcPatternCreate(); - p = FcPatternCreate(); - if(ptn == NULL || p == NULL) + if(ptn == NULL) goto err; val.type = FcTypeString; val.u.s = family; FcPatternAdd(ptn, "family", val, FcTrue); - + val.type = FcTypeInteger; val.u.i = slant_map[slant]; FcPatternAdd(ptn, "slant", val, FcTrue); - + val.type = FcTypeInteger; val.u.i = weight; FcPatternAdd(ptn, "weight", val, FcTrue); - r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern); - if(!r) - goto err; - - r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont); + FcDefaultSubstitute(ptn); + + r = FcConfigSubstituteWithPat(cfg, ptn, ptn, FcMatchPattern); if(!r) goto err; - FcDefaultSubstitute(p); + r = FcConfigSubstituteWithPat(cfg, ptn, ptn, FcMatchFont); + if(!r) + goto err; - fn_ptn = FcFontMatch(cfg, p, &result); + fn_ptn = FcFontMatch(cfg, ptn, &result); /* It is supposed to return FcResultMatch. But, it is no, now. * I don't know why. Someone should figure out the issue. @@ -71,15 +72,12 @@ goto err; FcPatternDestroy(ptn); - FcPatternDestroy(p); - + return fn_ptn; - + err: if(ptn) FcPatternDestroy(ptn); - if(p) - FcPatternDestroy(p); return NULL; } @@ -94,11 +92,11 @@ mbe_query_font_face(const char *family, int slant, int weight) { mbe_font_face_t *cface; FcPattern *ptn; - + ptn = query_font_pattern(family, slant, weight); cface = cairo_ft_font_face_create_for_pattern(ptn); FcPatternDestroy(ptn); - + return cface; } @@ -121,7 +119,7 @@ cx1, cy1, radius1); if(ptn == NULL) return NULL; - + stop = stops; for(i = 0; i < stop_cnt; i++) { cairo_pattern_add_color_stop_rgba(ptn, stop->offset, @@ -152,57 +150,3 @@ return ptn; } - -mbe_pattern_t * -mbe_pattern_create_image(mb_img_data_t *img) { - cairo_surface_t *surf; - cairo_pattern_t *ptn; - cairo_format_t fmt; - - switch(img->fmt) { - case MB_IFMT_ARGB32: - fmt = CAIRO_FORMAT_ARGB32; - break; - - case MB_IFMT_RGB24: - fmt = CAIRO_FORMAT_RGB24; - break; - - case MB_IFMT_A8: - fmt = CAIRO_FORMAT_A8; - break; - - case MB_IFMT_A1: - fmt = CAIRO_FORMAT_A1; - break; - - case MB_IFMT_RGB16_565: - fmt = CAIRO_FORMAT_RGB16_565; - break; - - default: - return NULL; - } - - surf = cairo_image_surface_create_for_data(img->content, fmt, - img->w, img->h, img->stride); - ptn = cairo_pattern_create_for_surface(surf); - cairo_surface_destroy(surf); - - return ptn; -} - -void -mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { - area_t *area; - int i; - - cairo_new_path(canvas); - - for(i = 0; i < n_areas; i++) { - area = areas[i]; - cairo_rectangle(canvas, area->x, area->y, area->w, area->h); - } - - cairo_clip(canvas); -}