Mercurial > MadButterfly
annotate src/graph_engine_cairo.c @ 1273:1d0474f2f6fa
Make public APIs being public for frameline_stack
- Since the functions prefixed with a underline '_' is supposed a
private, we should make all public function not prefixed with a
underline.
- Remove all prefixed underline from type name of public methods for
frameline_stack.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 12 Jan 2011 21:18:23 +0800 |
parents | 851a062368bd |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
1110
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
3 #include <X11/Xlib.h> |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #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
|
5 #include <cairo-ft.h> |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include "mb_graph_engine_cairo.h" |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include "mb_shapes.h" |
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 #ifndef ASSERT |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 #define ASSERT(x) |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 #endif |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 /*! \brief Find out a font pattern. |
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 * 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
|
16 * 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
|
17 * |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 * \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
|
19 * \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
|
20 */ |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 static |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 FcPattern *query_font_pattern(const char *family, int slant, int weight) { |
901
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
23 FcPattern *ptn, *fn_ptn; |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 FcValue val; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 FcConfig *cfg; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 FcBool r; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 FcResult result; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 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
|
29 FC_SLANT_ROMAN, |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 FC_SLANT_ROMAN, |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 FC_SLANT_ITALIC, |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 FC_SLANT_OBLIQUE}; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 cfg = FcConfigGetCurrent(); |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 ptn = FcPatternCreate(); |
901
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
36 if(ptn == NULL) |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 goto err; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 val.type = FcTypeString; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 val.u.s = family; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 FcPatternAdd(ptn, "family", val, FcTrue); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
42 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 val.type = FcTypeInteger; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 val.u.i = slant_map[slant]; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 FcPatternAdd(ptn, "slant", val, FcTrue); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
46 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 val.type = FcTypeInteger; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 val.u.i = weight; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 FcPatternAdd(ptn, "weight", val, FcTrue); |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 |
901
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
51 FcDefaultSubstitute(ptn); |
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
52 |
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
53 r = FcConfigSubstituteWithPat(cfg, ptn, ptn, FcMatchPattern); |
465
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; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
56 |
901
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
57 r = FcConfigSubstituteWithPat(cfg, ptn, ptn, FcMatchFont); |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 if(!r) |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 goto err; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 |
901
74e3ba4d3fa1
Fix issue of unworking text style.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
61 fn_ptn = FcFontMatch(cfg, ptn, &result); |
465
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 /* 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
|
64 * 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
|
65 */ |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 #if 0 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 if(result != FcResultMatch) { |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 printf("%d %d\n", result, FcResultMatch); |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 goto err; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 } |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 #endif |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 if(fn_ptn == NULL) |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 goto err; |
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 FcPatternDestroy(ptn); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
76 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 return fn_ptn; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
78 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 err: |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 if(ptn) |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 FcPatternDestroy(ptn); |
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 |
1110
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
86 extern mbe_surface_t * |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
87 mbe_win_surface_create(void *display, void *drawable, |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
88 int fmt, int width, int height) { |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
89 XWindowAttributes attrs; |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
90 mbe_surface_t *surf; |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
91 int r; |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
92 |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
93 r = XGetWindowAttributes((Display *)display, (Drawable)drawable, &attrs); |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
94 if(r == 0) |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
95 return NULL; |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
96 |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
97 surf = cairo_xlib_surface_create((Display *)display, (Drawable)drawable, |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
98 attrs.visual, width, height); |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
99 |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
100 return surf; |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
101 } |
851a062368bd
Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents:
1101
diff
changeset
|
102 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 /*! \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
|
104 * |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 * 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
|
106 * 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
|
107 * 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
|
108 */ |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 mbe_font_face_t * |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 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
|
111 mbe_font_face_t *cface; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 FcPattern *ptn; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
113 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 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
|
115 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
|
116 FcPatternDestroy(ptn); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
117 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 return cface; |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 } |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 void |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 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
|
123 ASSERT(face == NULL); |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
124 |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 mbe_font_face_destroy(face); |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
126 } |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 |
480
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
128 mbe_pattern_t * |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 cairo_pattern_t *ptn; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
133 grad_stop_t *stop; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
134 int i; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
135 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
136 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
|
137 cx1, cy1, radius1); |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
138 if(ptn == NULL) |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
139 return NULL; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
480
diff
changeset
|
140 |
480
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
141 stop = stops; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 stop++; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
146 } |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
147 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
148 return ptn; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
149 } |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
150 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
151 mbe_pattern_t * |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
152 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
|
153 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
|
154 cairo_pattern_t *ptn; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
155 grad_stop_t *stop; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
156 int i; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
157 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
158 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
|
159 if(ptn == NULL) |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
160 return NULL; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
161 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
162 stop = stops; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 stop++; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
167 } |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
168 |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
169 return ptn; |
e813ac222f48
Merge add colors into constructor of gradient pattern.
Thinker K.F. Li <thinker@branda.to>
parents:
469
diff
changeset
|
170 } |
1073
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
171 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
172 mbe_pattern_t * |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
173 mbe_pattern_create_image(mb_img_data_t *img) { |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
174 cairo_surface_t *surf; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
175 cairo_pattern_t *ptn; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
176 cairo_format_t fmt; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
177 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
178 switch(img->fmt) { |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
179 case MB_IFMT_ARGB32: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
180 fmt = CAIRO_FORMAT_ARGB32; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
181 break; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
182 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
183 case MB_IFMT_RGB24: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
184 fmt = CAIRO_FORMAT_RGB24; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
185 break; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
186 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
187 case MB_IFMT_A8: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
188 fmt = CAIRO_FORMAT_A8; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
189 break; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
190 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
191 case MB_IFMT_A1: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
192 fmt = CAIRO_FORMAT_A1; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
193 break; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
194 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
195 case MB_IFMT_RGB16_565: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
196 fmt = CAIRO_FORMAT_RGB16_565; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
197 break; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
198 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
199 default: |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
200 return NULL; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
201 } |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
202 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
203 surf = cairo_image_surface_create_for_data(img->content, fmt, |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
204 img->w, img->h, img->stride); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
205 ptn = cairo_pattern_create_for_surface(surf); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
206 cairo_surface_destroy(surf); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
207 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
208 return ptn; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
209 } |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
210 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
211 void |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
212 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
213 area_t *area; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
214 int i; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
215 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
216 cairo_new_path(canvas); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
217 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
218 for(i = 0; i < n_areas; i++) { |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
219 area = areas[i]; |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
220 cairo_rectangle(canvas, area->x, area->y, area->w, area->h); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
221 } |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
222 |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
223 cairo_clip(canvas); |
d09f603438d8
Merge the work of improvement for graphic engine of openvg branch
Thinker K.F. Li <thinker@codemud.net>
parents:
1067
diff
changeset
|
224 } |
1101
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
225 |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
226 void |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
227 mbe_copy_source(mbe_t *src, mbe_t *dst) { |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
228 cairo_operator_t saved_op; |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
229 cairo_surface_t *surf; |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
230 cairo_pattern_t *ptn; |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
231 |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
232 surf = cairo_get_target(src); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
233 ptn = cairo_pattern_create_for_surface(surf); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
234 cairo_set_source(dst, ptn); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
235 cairo_pattern_destroy(ptn); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
236 saved_op = cairo_get_operator(dst); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
237 cairo_set_operator(dst, CAIRO_OPERATOR_SOURCE); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
238 cairo_paint(dst); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
239 cairo_set_operator(dst, saved_op); |
e1a76d10953e
Fix black window output for Cairo graphic engine.
Thinker K.F. Li <thinker@codemud.net>
parents:
1073
diff
changeset
|
240 } |