comparison src/graph_engine_cairo.c @ 465:d8181696b689 Android_Skia

Move functions into graphic engine layers. Cairo and Skia have their own header files and C/C++ files. Some functions are refactoried and move into graphic engine layer to make reset of MadButterfly independently from graphic engines.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 12 Nov 2009 21:22:30 +0800
parents
children 4dc0be6c044a
comparison
equal deleted inserted replaced
464:271212f325b4 465:d8181696b689
1 #include <fontconfig/fontconfig.h>
2 #include "mb_graph_engine_cairo.h"
3 #include "mb_shapes.h"
4
5 #ifndef ASSERT
6 #define ASSERT(x)
7 #endif
8
9 /*! \brief Find out a font pattern.
10 *
11 * This function use fontconfig to decide a font file in pattern. It can
12 * replaced by other mechanism if you think it is not what you want.
13 *
14 * \param slant make font prune if it it non-zero.
15 * \param weight make font normal if it is 100.
16 */
17 static
18 FcPattern *query_font_pattern(const char *family, int slant, int weight) {
19 FcPattern *ptn, *p, *fn_ptn;
20 FcValue val;
21 FcConfig *cfg;
22 FcBool r;
23 FcResult result;
24 static int slant_map[] = { /* from MB_FONT_SLANT_* to FC_SLANT_* */
25 FC_SLANT_ROMAN,
26 FC_SLANT_ROMAN,
27 FC_SLANT_ITALIC,
28 FC_SLANT_OBLIQUE};
29
30 cfg = FcConfigGetCurrent();
31 ptn = FcPatternCreate();
32 p = FcPatternCreate();
33 if(ptn == NULL || p == NULL)
34 goto err;
35
36 val.type = FcTypeString;
37 val.u.s = family;
38 FcPatternAdd(ptn, "family", val, FcTrue);
39
40 val.type = FcTypeInteger;
41 val.u.i = slant_map[slant];
42 FcPatternAdd(ptn, "slant", val, FcTrue);
43
44 val.type = FcTypeInteger;
45 val.u.i = weight;
46 FcPatternAdd(ptn, "weight", val, FcTrue);
47
48 r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern);
49 if(!r)
50 goto err;
51
52 r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont);
53 if(!r)
54 goto err;
55
56 FcDefaultSubstitute(p);
57
58 fn_ptn = FcFontMatch(cfg, p, &result);
59
60 /* It is supposed to return FcResultMatch. But, it is no, now.
61 * I don't know why. Someone should figure out the issue.
62 */
63 #if 0
64 if(result != FcResultMatch) {
65 printf("%d %d\n", result, FcResultMatch);
66 goto err;
67 }
68 #endif
69 if(fn_ptn == NULL)
70 goto err;
71
72 FcPatternDestroy(ptn);
73 FcPatternDestroy(p);
74
75 return fn_ptn;
76
77 err:
78 if(ptn)
79 FcPatternDestroy(ptn);
80 if(p)
81 FcPatternDestroy(p);
82 return NULL;
83
84 }
85
86 /*! \brief Find out a font face for a pattern specified.
87 *
88 * The pattern, here, is a vector of family, slant, and weight.
89 * This function base on fontconfig and cairo FreeType font supporting.
90 * You can replace this function with other font mechanisms.
91 */
92 mbe_font_face_t *
93 mbe_query_font_face(const char *family, int slant, int weight) {
94 mbe_font_face_t *cface;
95 FcPattern *ptn;
96
97 ptn = query_font_pattern(family, slant, weight);
98 cface = mbe_ft_font_face_create_for_pattern(ptn);
99 FcPatternDestroy(ptn);
100
101 return cface;
102 }
103
104 void
105 mbe_free_font_face(mbe_font_face_t *face) {
106 ASSERT(face == NULL);
107
108 mbe_font_face_destroy(face);
109 }
110