comparison src/shape_stext.c @ 396:7fe0b1ee92b6

Add extents supporting into Fontconfig and FreeType Layer
author Thinker K.F. Li <thinker@branda.to>
date Wed, 10 Jun 2009 22:46:13 +0800
parents d30b575a4ad4
children 55f38c2cdb8f
comparison
equal deleted inserted replaced
395:d30b575a4ad4 396:7fe0b1ee92b6
1 #if 0 1 #ifdef SHAPE_STEXT
2 2
3 #include <stdio.h> 3 #include <stdio.h>
4 #include <cairo.h> 4 #include <cairo.h>
5 #include <cairo-ft.h> 5 #include <cairo-ft.h>
6 #include <fontconfig/fontconfig.h> 6 #include <fontconfig/fontconfig.h>
9 #ifndef ASSERT 9 #ifndef ASSERT
10 #define ASSERT(x) 10 #define ASSERT(x)
11 #endif 11 #endif
12 #define OK 0 12 #define OK 0
13 #define ERR -1 13 #define ERR -1
14
15 /*! \defgroup fontconfig_freetype Fontconfig and FreeType Layer.
16 *
17 * This layer implements a font provider to reset of the system.
18 * It bases on fontconfig and FreeType supporting of Cairo.
19 *
20 * @{
21 */
22 /*! \brief Stakeholder of scaled font.
23 *
24 * It is actually a cairo_scaled_font_t, now. But, it should not be
25 * noticed by out-siders. Only \ref fontconfig_freetype
26 * should known it.
27 */
28 typedef struct _mb_scaled_font mb_scaled_font_t;
29
30 /*! \brief Stakeholder of scaled font.
31 *
32 * Although, mb_text_extents_t is defined as a cairo_scaled_font_t, but
33 * programmers should assume it is opague.
34 */
35 typedef cairo_text_extents_t mb_text_extents_t;
36
37 #define MBE_GET_X_ADV(ext) ((ext)->x_advance)
38 #define MBE_GET_Y_ADV(ext) ((ext)->y_advance)
39 #define MBE_GET_WIDTH(ext) ((ext)->width)
40 #define MBE_GET_HEIGHT(ext) ((ext)->height)
14 41
15 /*! \brief Find out a font pattern. 42 /*! \brief Find out a font pattern.
16 * 43 *
17 * This function use fontconfig to decide a font file in pattern. It can 44 * This function use fontconfig to decide a font file in pattern. It can
18 * replaced by other mechanism if you think it is not what you want. 45 * replaced by other mechanism if you think it is not what you want.
75 * The pattern, here, is a vector of family, slant, and weight. 102 * The pattern, here, is a vector of family, slant, and weight.
76 * This function base on fontconfig and cairo FreeType font supporting. 103 * This function base on fontconfig and cairo FreeType font supporting.
77 * You can replace this function with other font mechanisms. 104 * You can replace this function with other font mechanisms.
78 */ 105 */
79 static 106 static
80 cairo_font_face_t *query_font_face(const char *family, 107 mb_font_face_t *query_font_face(const char *family, int slant, int weight) {
81 int slant,
82 int weight) {
83 cairo_font_face_t *cface; 108 cairo_font_face_t *cface;
84 FcPattern *ptn; 109 FcPattern *ptn;
85 110
86 ptn = query_font_pattern(family, slant, weight); 111 ptn = query_font_pattern(family, slant, weight);
87 cface = cairo_ft_font_face_create_for_pattern(ptn); 112 cface = cairo_ft_font_face_create_for_pattern(ptn);
88 FcPatternDestroy(ptn); 113 FcPatternDestroy(ptn);
89 114
90 return cface; 115 return (mb_font_face_t *)cface;
91 } 116 }
92 117
93 static 118 static
94 void free_font_face(cairo_font_face_t *cface) { 119 void free_font_face(mb_font_face_t *face) {
95 ASSERT(cface == NULL); 120 ASSERT(face == NULL);
96 121
97 cairo_font_face_destroy(cface); 122 cairo_font_face_destroy((cairo_font_face_t *)face);
98 } 123 }
99 124
100 /*! \brief This is scaled font for specified size and extent. 125 /*! \brief This is scaled font for specified size and extent.
101 * 126 *
102 * Font face only specified which font would be used to draw text 127 * Font face only specified which font would be used to draw text
104 * rotation. This function return a scaled font specified by a 129 * rotation. This function return a scaled font specified by a
105 * matrix that transform glyph from design space of the font to 130 * matrix that transform glyph from design space of the font to
106 * user space of cairo surface. 131 * user space of cairo surface.
107 */ 132 */
108 static 133 static
109 cairo_scaled_font_t *get_ciaro_scaled_font(cairo_font_face_t *cface, 134 mb_scaled_font_t *get_cairo_scaled_font(mb_font_face_t *face,
110 co_aix *matrix) { 135 co_aix *matrix) {
111 cairo_font_face_t *scaled_font; 136 cairo_font_face_t *scaled_font;
112 cairo_matrix_t font_matrix; 137 cairo_matrix_t font_matrix;
113 static cairo_matir_t id = { 138 static cairo_matir_t id = {
114 1, 0, 139 1, 0,
115 0, 1, 140 0, 1,
129 font_matrix.xy = *matrix++; 154 font_matrix.xy = *matrix++;
130 font_matrix.x0 = *matrix++; 155 font_matrix.x0 = *matrix++;
131 font_matrix.yx = *matrix++; 156 font_matrix.yx = *matrix++;
132 font_matrix.yy = *matrix++; 157 font_matrix.yy = *matrix++;
133 font_matrix.y0 = *matrix; 158 font_matrix.y0 = *matrix;
134 scaled_font = cairo_scaled_font_create(cface, &font_matrix, 159 scaled_font = cairo_scaled_font_create((cairo_font_face_t *)face,
160 &font_matrix,
135 &id, opt); 161 &id, opt);
136 162
137 return scaled_font; 163 return (mb_scaled_font_t *)scaled_font;
138 } 164 }
139 165
140 static 166 static
141 void free_scaled_font(cairo_scaled_font_t *scaled_font) { 167 void free_scaled_font(mb_scaled_font_t *scaled_font) {
142 cairo_scaled_font_destroy(scaled_font); 168 cairo_scaled_font_destroy((cairo_scaled_font_t *)scaled_font);
143 } 169 }
144 170
145 /* ============================================================ */ 171 static
172 void text_extents(mb_scaled_font_t *scaled_font, const char *txt,
173 mb_text_extents_t *extents) {
174 cairo_scaled_font_text_extents((cairo_scaled_font_t *)scaled_font,
175 txt,
176 (cairo_text_extents_t *)extents);
177 }
178
179 static
180 mb_text_extents_t *mb_text_extents_new(void) {
181 cairo_text_extents_t *extents;
182
183 extents = (cairo_text_extents_t *)malloc(sizeof(cairo_text_extents_t));
184 return extents;
185 }
186
187 static
188 void mb_text_extents_free(mb_text_extents_t *extents) {
189 free(extents);
190 }
191
192 /* @} */
146 193
147 /*! \brief Query and return a font face for a specified attribute vector. 194 /*! \brief Query and return a font face for a specified attribute vector.
148 * 195 *
149 * Programmers use mb_font_face_t to specify fonts used to show a 196 * Programmers use mb_font_face_t to specify fonts used to show a
150 * block of text on the output device. They can get mb_font_face_t with 197 * block of text on the output device. They can get mb_font_face_t with
157 */ 204 */
158 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman, 205 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman,
159 const char *family, 206 const char *family,
160 int slant, 207 int slant,
161 int weight) { 208 int weight) {
162 return (mb_font_face_t *)query_font_face(family, slant, weight); 209 return query_font_face(family, slant, weight);
163 } 210 }
164 211
165 void mb_font_face_free(mb_font_face_t *face) { 212 void mb_font_face_free(mb_font_face_t *face) {
166 cairo_font_face_t *cface = (cairo_font_face_t *)face;
167 ASSERT(face != NULL); 213 ASSERT(face != NULL);
168 cairo_font_face_destroy(face); 214 free_font_face(face);
169 } 215 }
170 216
171 /*! \brief A simple implementation of text shape. 217 /*! \brief A simple implementation of text shape.
172 * 218 *
173 */ 219 */
176 const char *txt; /*!< \brief Text to be showed */ 222 const char *txt; /*!< \brief Text to be showed */
177 const mb_style_blk_t *style_blks; /*!< \brief Style of text */ 223 const mb_style_blk_t *style_blks; /*!< \brief Style of text */
178 int nblks; /*!< \brief Number of style blocks */ 224 int nblks; /*!< \brief Number of style blocks */
179 int max_nblks; 225 int max_nblks;
180 co_aix x, y; 226 co_aix x, y;
181 cairo_scaled_font_t **scaled_fonts; 227 mb_scaled_font_t **scaled_fonts;
182 } sh_stext_t; 228 } sh_stext_t;
183 229
184 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, co_aix x, co_aix y, 230 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, co_aix x, co_aix y,
185 const char *txt) { 231 const char *txt) {
186 sh_stext_t *txt_o; 232 sh_stext_t *txt_o;
373 txt_o->nblks = nblks; 419 txt_o->nblks = nblks;
374 420
375 return OK; 421 return OK;
376 } 422 }
377 423
378 #endif /* 0 */ 424 #endif /* SHAPE_STEXT */