annotate src/graph_engine_cairo.c @ 615:0f0abc48e10a openvg

mbe_new_path() for OpenVG
author Thinker K.F. Li <thinker@branda.to>
date Thu, 08 Jul 2010 11:29:58 +0800
parents ac2e6468a22a
children 7b4e80ab671a
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>
480
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
2 #include <cairo-ft.h>
465
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "mb_graph_engine_cairo.h"
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "mb_shapes.h"
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #ifndef ASSERT
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #define ASSERT(x)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #endif
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 /*! \brief Find out a font pattern.
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 *
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 * 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
13 * 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
14 *
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 * \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
16 * \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
17 */
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 static
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 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
20 FcPattern *ptn, *p, *fn_ptn;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 FcValue val;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 FcConfig *cfg;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 FcBool r;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 FcResult result;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 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
26 FC_SLANT_ROMAN,
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 FC_SLANT_ROMAN,
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 FC_SLANT_ITALIC,
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 FC_SLANT_OBLIQUE};
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 cfg = FcConfigGetCurrent();
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 ptn = FcPatternCreate();
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 p = FcPatternCreate();
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 if(ptn == NULL || p == NULL)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 goto err;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 val.type = FcTypeString;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 val.u.s = family;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 FcPatternAdd(ptn, "family", val, FcTrue);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 val.type = FcTypeInteger;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 val.u.i = slant_map[slant];
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 FcPatternAdd(ptn, "slant", val, FcTrue);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 val.type = FcTypeInteger;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 val.u.i = weight;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 FcPatternAdd(ptn, "weight", val, FcTrue);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 if(!r)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 goto err;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 if(!r)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 goto err;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 FcDefaultSubstitute(p);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 fn_ptn = FcFontMatch(cfg, p, &result);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 /* 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
62 * 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
63 */
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 #if 0
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 if(result != FcResultMatch) {
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 printf("%d %d\n", result, FcResultMatch);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 goto err;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 }
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 #endif
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 if(fn_ptn == NULL)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 goto err;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 FcPatternDestroy(ptn);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 FcPatternDestroy(p);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 return fn_ptn;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 err:
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 if(ptn)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 FcPatternDestroy(ptn);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 if(p)
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 FcPatternDestroy(p);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 return NULL;
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
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 /*! \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
88 *
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 * 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
90 * 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
91 * 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
92 */
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 mbe_font_face_t *
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 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
95 mbe_font_face_t *cface;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 FcPattern *ptn;
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 ptn = query_font_pattern(family, slant, weight);
469
4dc0be6c044a Add copy and clear graphic engine functions.
Thinker K.F. Li <thinker@branda.to>
parents: 465
diff changeset
99 cface = cairo_ft_font_face_create_for_pattern(ptn);
465
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 FcPatternDestroy(ptn);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 return cface;
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
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 void
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 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
107 ASSERT(face == NULL);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 mbe_font_face_destroy(face);
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 }
d8181696b689 Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111
480
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
112 mbe_pattern_t *
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
113 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, co_aix radius0,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
114 co_aix cx1, co_aix cy1, co_aix radius1,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
115 grad_stop_t *stops, int stop_cnt) {
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
116 cairo_pattern_t *ptn;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
117 grad_stop_t *stop;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
118 int i;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
119
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
120 ptn = cairo_pattern_create_radial(cx0, cy0, radius0,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
121 cx1, cy1, radius1);
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
122 if(ptn == NULL)
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
123 return NULL;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
124
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
125 stop = stops;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
126 for(i = 0; i < stop_cnt; i++) {
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
127 cairo_pattern_add_color_stop_rgba(ptn, stop->offset,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
128 stop->r, stop->g, stop->b, stop->a);
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
129 stop++;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
130 }
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
131
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
132 return ptn;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
133 }
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
134
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
135 mbe_pattern_t *
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
136 mbe_pattern_create_linear(co_aix x0, co_aix y0, co_aix x1, co_aix y1,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
137 grad_stop_t *stops, int stop_cnt) {
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
138 cairo_pattern_t *ptn;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
139 grad_stop_t *stop;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
140 int i;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
141
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
142 ptn = cairo_pattern_create_linear(x0, y0, x1, y1);
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
143 if(ptn == NULL)
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
144 return NULL;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
145
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
146 stop = stops;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
147 for(i = 0; i < stop_cnt; i++) {
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
148 cairo_pattern_add_color_stop_rgba(ptn, stop->offset,
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
149 stop->r, stop->g, stop->b, stop->a);
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
150 stop++;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
151 }
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
152
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
153 return ptn;
e813ac222f48 Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
154 }
586
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
155
602
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
156 mbe_pattern_t *
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
157 mbe_pattern_create_image(mb_img_data_t *img) {
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
158 cairo_surface_t *surf;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
159 cairo_pattern_t *ptn;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
160 cairo_format_t fmt;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
161
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
162 switch(img->fmt) {
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
163 case MB_IFMT_ARGB32:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
164 fmt = CAIRO_FORMAT_ARGB32;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
165 break;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
166
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
167 case MB_IFMT_RGB24:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
168 fmt = CAIRO_FORMAT_RGB24;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
169 break;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
170
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
171 case MB_IFMT_A8:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
172 fmt = CAIRO_FORMAT_A8;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
173 break;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
174
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
175 case MB_IFMT_A1:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
176 fmt = CAIRO_FORMAT_A1;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
177 break;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
178
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
179 case MB_IFMT_RGB16_565:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
180 fmt = CAIRO_FORMAT_RGB16_565;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
181 break;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
182
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
183 default:
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
184 return NULL;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
185 }
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
186
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
187 surf = cairo_image_surface_create_for_data(img->content, fmt,
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
188 img->w, img->h, img->stride);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
189 ptn = cairo_pattern_create_for_surface(surf);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
190 cairo_surface_destroy(surf);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
191
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
192 return ptn;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
193 }
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 586
diff changeset
194
586
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
195 void
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
196 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) {
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
197 area_t *area;
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
198 int i;
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
199
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
200 cairo_new_path(canvas);
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
201
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
202 for(i = 0; i < n_areas; i++) {
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
203 area = areas[i];
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
204 cairo_rectangle(canvas, area->x, area->y, area->w, area->h);
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
205 }
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
206
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
207 cairo_clip(canvas);
b42d69ab8857 Replace mbe_clip() with mbe_scissoring()
Thinker K.F. Li <thinker@branda.to>
parents: 480
diff changeset
208 }