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