comparison src/shape_stext.c @ 395:d30b575a4ad4

Add fontconfig layer
author Thinker K.F. Li <thinker@branda.to>
date Wed, 10 Jun 2009 21:45:39 +0800
parents b3d5ce48670a
children 7fe0b1ee92b6
comparison
equal deleted inserted replaced
394:b3d5ce48670a 395:d30b575a4ad4
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 14
15 static 15 /*! \brief Find out a font pattern.
16 FcPattern *query_fontconfig(const char *family, int slant, int weight) { 16 *
17 * 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.
19 */
20 static
21 FcPattern *query_font_pattern(const char *family, int slant, int weight) {
17 FcPattern *ptn, *p; 22 FcPattern *ptn, *p;
18 FcValue val; 23 FcValue val;
19 FcConfig *cfg; 24 FcConfig *cfg;
20 FcBool r; 25 FcBool r;
21 static int slant_map[] = { /* from MB_FONT_SLANT_* to FC_SLANT_* */ 26 static int slant_map[] = { /* from MB_FONT_SLANT_* to FC_SLANT_* */
63 FcPatternDestroy(p); 68 FcPatternDestroy(p);
64 return NULL; 69 return NULL;
65 70
66 } 71 }
67 72
73 /*! \brief Find out a font face for a pattern specified.
74 *
75 * The pattern, here, is a vector of family, slant, and weight.
76 * This function base on fontconfig and cairo FreeType font supporting.
77 * You can replace this function with other font mechanisms.
78 */
79 static
80 cairo_font_face_t *query_font_face(const char *family,
81 int slant,
82 int weight) {
83 cairo_font_face_t *cface;
84 FcPattern *ptn;
85
86 ptn = query_font_pattern(family, slant, weight);
87 cface = cairo_ft_font_face_create_for_pattern(ptn);
88 FcPatternDestroy(ptn);
89
90 return cface;
91 }
92
93 static
94 void free_font_face(cairo_font_face_t *cface) {
95 ASSERT(cface == NULL);
96
97 cairo_font_face_destroy(cface);
98 }
99
100 /*! \brief This is scaled font for specified size and extent.
101 *
102 * Font face only specified which font would be used to draw text
103 * message. But, it also need to scale glyphs to specified size and
104 * rotation. This function return a scaled font specified by a
105 * matrix that transform glyph from design space of the font to
106 * user space of cairo surface.
107 */
108 static
109 cairo_scaled_font_t *get_ciaro_scaled_font(cairo_font_face_t *cface,
110 co_aix *matrix) {
111 cairo_font_face_t *scaled_font;
112 cairo_matrix_t font_matrix;
113 static cairo_matir_t id = {
114 1, 0,
115 0, 1,
116 0, 0
117 };
118 static cairo_font_options_t *opt = NULL;
119
120 ASSERT(matrix != NULL);
121
122 if(opt == NULL) {
123 opt = cairo_font_options_create();
124 if(opt == NULL)
125 return NULL;
126 }
127
128 font_matrix.xx = *matrix++;
129 font_matrix.xy = *matrix++;
130 font_matrix.x0 = *matrix++;
131 font_matrix.yx = *matrix++;
132 font_matrix.yy = *matrix++;
133 font_matrix.y0 = *matrix;
134 scaled_font = cairo_scaled_font_create(cface, &font_matrix,
135 &id, opt);
136
137 return scaled_font;
138 }
139
140 static
141 void free_scaled_font(cairo_scaled_font_t *scaled_font) {
142 cairo_scaled_font_destroy(scaled_font);
143 }
144
145 /* ============================================================ */
146
68 /*! \brief Query and return a font face for a specified attribute vector. 147 /*! \brief Query and return a font face for a specified attribute vector.
69 * 148 *
70 * Programmers use mb_font_face_t to specify fonts used to show a 149 * Programmers use mb_font_face_t to specify fonts used to show a
71 * block of text on the output device. They can get mb_font_face_t with 150 * block of text on the output device. They can get mb_font_face_t with
72 * this function. The objects return by mb_font_face_query() should be 151 * this function. The objects return by mb_font_face_query() should be
78 */ 157 */
79 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman, 158 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman,
80 const char *family, 159 const char *family,
81 int slant, 160 int slant,
82 int weight) { 161 int weight) {
83 cairo_font_face_t *cface; 162 return (mb_font_face_t *)query_font_face(family, slant, weight);
84 FcPattern *ptn;
85
86 ptn = query_fontconfig(family, slant, weight);
87
88 cface = cairo_ft_font_face_create_for_pattern(ptn);
89 FcPatternDestroy(ptn);
90
91 return (mb_font_face_t *)cface;
92 } 163 }
93 164
94 void mb_font_face_free(mb_font_face_t *face) { 165 void mb_font_face_free(mb_font_face_t *face) {
95 cairo_font_face_t *cface = (cairo_font_face_t *)face; 166 cairo_font_face_t *cface = (cairo_font_face_t *)face;
96 ASSERT(face != NULL); 167 ASSERT(face != NULL);