Mercurial > MadButterfly
annotate 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 |
rev | line source |
---|---|
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
1 #ifdef SHAPE_STEXT |
394
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
2 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <stdio.h> |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #include <cairo.h> |
394
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
5 #include <cairo-ft.h> |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
6 #include <fontconfig/fontconfig.h> |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include "mb_shapes.h" |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 #ifndef ASSERT |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 #define ASSERT(x) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 #endif |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 #define OK 0 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 #define ERR -1 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
15 /*! \defgroup fontconfig_freetype Fontconfig and FreeType Layer. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
16 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
17 * This layer implements a font provider to reset of the system. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
18 * It bases on fontconfig and FreeType supporting of Cairo. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
19 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
20 * @{ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
21 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
22 /*! \brief Stakeholder of scaled font. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
23 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
24 * It is actually a cairo_scaled_font_t, now. But, it should not be |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
25 * noticed by out-siders. Only \ref fontconfig_freetype |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
26 * should known it. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
27 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
28 typedef struct _mb_scaled_font mb_scaled_font_t; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
29 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
30 /*! \brief Stakeholder of scaled font. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
31 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
32 * Although, mb_text_extents_t is defined as a cairo_scaled_font_t, but |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
33 * programmers should assume it is opague. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
34 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
35 typedef cairo_text_extents_t mb_text_extents_t; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
36 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
37 #define MBE_GET_X_ADV(ext) ((ext)->x_advance) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
38 #define MBE_GET_Y_ADV(ext) ((ext)->y_advance) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
39 #define MBE_GET_WIDTH(ext) ((ext)->width) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
40 #define MBE_GET_HEIGHT(ext) ((ext)->height) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
41 |
395 | 42 /*! \brief Find out a font pattern. |
43 * | |
44 * This function use fontconfig to decide a font file in pattern. It can | |
45 * replaced by other mechanism if you think it is not what you want. | |
46 */ | |
394
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
47 static |
395 | 48 FcPattern *query_font_pattern(const char *family, int slant, int weight) { |
394
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
49 FcPattern *ptn, *p; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
50 FcValue val; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
51 FcConfig *cfg; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
52 FcBool r; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
53 static int slant_map[] = { /* from MB_FONT_SLANT_* to FC_SLANT_* */ |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
54 FC_SLANT_ROMAN, |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
55 FC_SLANT_ROMAN, |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
56 FC_SLANT_ITALIC, |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
57 FC_SLANT_OBLIQUE}; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
58 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
59 cfg = FcConfigGetCurrent(); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
60 ptn = FcPatternCreate(); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
61 p = FcPatternCreate(); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
62 if(ptn == NULL || p == NULL) |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
63 goto err; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
64 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
65 val.type = FcTypeString; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
66 val.u.s = family; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
67 FcPatternAdd(ptn, "family", &val, FcTrue); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
68 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
69 val.type = FcTypeInteger; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
70 val.u.i = slant_map[slant]; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
71 FcPatternAdd(ptn, "slant", &val, FcTrue); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
72 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
73 val.type = FcTypeInteger; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
74 val.u.i = weight; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
75 FcPatternAdd(ptn, "weight", &val, FcTrue); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
76 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
77 r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
78 if(!r) |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
79 goto err; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
80 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
81 r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
82 if(!r) |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
83 goto err; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
84 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
85 FcDefaultSubstitute(p); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
86 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
87 FcPatternDestroy(ptn); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
88 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
89 return p; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
90 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
91 err: |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
92 if(ptn) |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
93 FcPatternDestroy(ptn); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
94 if(p) |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
95 FcPatternDestroy(p); |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
96 return NULL; |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
97 |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
98 } |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
99 |
395 | 100 /*! \brief Find out a font face for a pattern specified. |
101 * | |
102 * The pattern, here, is a vector of family, slant, and weight. | |
103 * This function base on fontconfig and cairo FreeType font supporting. | |
104 * You can replace this function with other font mechanisms. | |
105 */ | |
106 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
107 mb_font_face_t *query_font_face(const char *family, int slant, int weight) { |
395 | 108 cairo_font_face_t *cface; |
109 FcPattern *ptn; | |
110 | |
111 ptn = query_font_pattern(family, slant, weight); | |
112 cface = cairo_ft_font_face_create_for_pattern(ptn); | |
113 FcPatternDestroy(ptn); | |
114 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
115 return (mb_font_face_t *)cface; |
395 | 116 } |
117 | |
118 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
119 void free_font_face(mb_font_face_t *face) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
120 ASSERT(face == NULL); |
395 | 121 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
122 cairo_font_face_destroy((cairo_font_face_t *)face); |
395 | 123 } |
124 | |
125 /*! \brief This is scaled font for specified size and extent. | |
126 * | |
127 * Font face only specified which font would be used to draw text | |
128 * message. But, it also need to scale glyphs to specified size and | |
129 * rotation. This function return a scaled font specified by a | |
130 * matrix that transform glyph from design space of the font to | |
131 * user space of cairo surface. | |
132 */ | |
133 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
134 mb_scaled_font_t *get_cairo_scaled_font(mb_font_face_t *face, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
135 co_aix *matrix) { |
395 | 136 cairo_font_face_t *scaled_font; |
137 cairo_matrix_t font_matrix; | |
138 static cairo_matir_t id = { | |
139 1, 0, | |
140 0, 1, | |
141 0, 0 | |
142 }; | |
143 static cairo_font_options_t *opt = NULL; | |
144 | |
145 ASSERT(matrix != NULL); | |
146 | |
147 if(opt == NULL) { | |
148 opt = cairo_font_options_create(); | |
149 if(opt == NULL) | |
150 return NULL; | |
151 } | |
152 | |
153 font_matrix.xx = *matrix++; | |
154 font_matrix.xy = *matrix++; | |
155 font_matrix.x0 = *matrix++; | |
156 font_matrix.yx = *matrix++; | |
157 font_matrix.yy = *matrix++; | |
158 font_matrix.y0 = *matrix; | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
159 scaled_font = cairo_scaled_font_create((cairo_font_face_t *)face, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
160 &font_matrix, |
395 | 161 &id, opt); |
162 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
163 return (mb_scaled_font_t *)scaled_font; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
164 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
165 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
166 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
167 void free_scaled_font(mb_scaled_font_t *scaled_font) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
168 cairo_scaled_font_destroy((cairo_scaled_font_t *)scaled_font); |
395 | 169 } |
170 | |
171 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
172 void text_extents(mb_scaled_font_t *scaled_font, const char *txt, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
173 mb_text_extents_t *extents) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
174 cairo_scaled_font_text_extents((cairo_scaled_font_t *)scaled_font, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
175 txt, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
176 (cairo_text_extents_t *)extents); |
395 | 177 } |
178 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
179 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
180 mb_text_extents_t *mb_text_extents_new(void) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
181 cairo_text_extents_t *extents; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
182 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
183 extents = (cairo_text_extents_t *)malloc(sizeof(cairo_text_extents_t)); |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
184 return extents; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
185 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
186 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
187 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
188 void mb_text_extents_free(mb_text_extents_t *extents) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
189 free(extents); |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
190 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
191 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
192 /* @} */ |
395 | 193 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
194 /*! \brief Query and return a font face for a specified attribute vector. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
195 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
196 * Programmers use mb_font_face_t to specify fonts used to show a |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
197 * block of text on the output device. They can get mb_font_face_t with |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
198 * this function. The objects return by mb_font_face_query() should be |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
199 * freed with mb_font_face_free() when they are not more used. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
200 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
201 * \param family is the name of a font family (times). |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
202 * \param slant is one of \ref MB_FONT_SLANTS. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
203 * \param weight decides if a font is thin or heavy. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
204 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
205 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
206 const char *family, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
207 int slant, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
208 int weight) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
209 return query_font_face(family, slant, weight); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
210 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
211 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
212 void mb_font_face_free(mb_font_face_t *face) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
213 ASSERT(face != NULL); |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
214 free_font_face(face); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
215 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
216 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
217 /*! \brief A simple implementation of text shape. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
218 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
219 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
220 typedef struct _sh_stext { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
221 shape_t shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
222 const char *txt; /*!< \brief Text to be showed */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
223 const mb_style_blk_t *style_blks; /*!< \brief Style of text */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
224 int nblks; /*!< \brief Number of style blocks */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 int max_nblks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 co_aix x, y; |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
227 mb_scaled_font_t **scaled_fonts; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
228 } sh_stext_t; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
229 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
230 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, co_aix x, co_aix y, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
231 const char *txt) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
232 sh_stext_t *txt_o; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 ASSERT(txt != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
235 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 txt_o = (sh_stext_t *)malloc(sizeof(sh_stext_t)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 if(txt_o == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
238 return NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
240 memset(&txt_o->shape, 0, sizeof(shape_t)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 mb_obj_init(txt_o, MBO_STEXT); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
243 txt_o->txt = strdup(txt); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
244 txt_o->style_blks = NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 txt_o->nblks = 0; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
246 txt_o->max_nblks = 0; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
247 txt_o->x = x; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
248 txt_o->y = y; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
249 txt_o->exts = NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 if(txt_o->txt == NULL) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 free(txt_o); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
253 txt_o = NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
256 return (shape_t *)txt_o; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
257 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
260 int compute_utf8_chars_sz(const char *txt, int n_chars) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
261 int i; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 const char *p = txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 for(i = 0; i < n && *p; i++) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 if(*p++ & 0x80) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 continue; /* single byte */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
267 /* multi-bytes */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
268 while(*p && ((*p & 0xc0) == 0x80)) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 p++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
270 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
271 if(i < n) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
272 return ERR; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
273 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
274 return p - txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
275 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
276 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
277 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
278 void compute_text_extents(char *txt, int txt_len, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
279 cairo_scaled_font_t *scaled_font, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
280 cairo_text_extents_t *extents) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 char saved; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
283 saved = txt[txt_len]; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 txt[txt_len] = 0; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 cairo_scaled_font_text_extents(scaled_font, txt, extents); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 txt[txt_len] = saved; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
288 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 cairo_scaled_font_t *make_scaled_font_face(sh_stext_t *txt_o, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 cairo_font_face_t *face, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
292 co_aix shift_x, co_aix shift_y, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 co_aix font_sz) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
294 cairo_matrix_t cmtx; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
295 static cairo_matrix_t cid; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
296 static cairo_font_options_t *fopt = NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 co_aix *matrix; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 cairo_scaled_font_t *scaled; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
299 int i; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 if(fopt == NULL) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 cairo_matrix_init_identify(&cid); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 fopt = cairo_font_options_create(); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 if(fopt == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 return NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
306 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
307 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
308 matrix = sh_get_aggr_matrix((shape_t *)txt_o); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
309 i = 0; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
310 cmtx.xx = matrix[i++]; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 cmtx.xy = matrix[i++]; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
312 cmtx.x0 = matrix[i++] + shift_x; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
313 cmtx.yx = matrix[i++]; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
314 cmtx.yy = matrix[i++]; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
315 cmtx.y0 = matrix[i] + shift_y; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
316 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
317 scaled = cairo_scaled_font_create(face, &cmtx, &cid, fopt); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
318 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
319 return scaled; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
320 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
321 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
322 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
323 void compute_extents(sh_stext_t *txt_o) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
324 co_aix adv_x, adv_y; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
325 cairo_text_extents_t extents; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
326 mb_style_blk_t *blk; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
327 cairo_scaled_font_t *scaled_font; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
328 char *txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
329 co_aix shift_x, shift_y; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
330 int blk_txt_len; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
331 int i; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
332 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
333 adv_x = adv_y = 0; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
334 blk = txt_o->style_blks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
335 scaled_font = txt_o->scaled_fonts; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
336 txt = (char *)txt_o->txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
337 shift_x = txt_o->x; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
338 shift_y = txt_o->y; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
339 for(i = 0; i < txt_o->nblks; i++) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
340 *scaled_font = make_scaled_fonts(txt_o, blk->face, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
341 shift_x, shift_y, font_sz); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
342 ASSERT(*scaled_font != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
343 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
344 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
345 ASSERT(blk_txt_len != ERR); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
346 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
347 compute_text_extents(txt, blk_txt_len, *scaled_font, &extents); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
348 adv_x += extents.x_advance; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
349 adv_y += extents.y_advance; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
350 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
351 scaled_font++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
352 blk++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
353 txt += blk_txt_len; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
354 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
355 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
356 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
357 /* |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
358 * What we have to do in sh_stext_transform() is |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
359 * - computing bounding box for the text, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
360 * - computing offset x,y for the text of style blocks, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
361 * - free old scaled fonts, and |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
362 * - making scaled fonts for style blocks. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
363 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
364 void sh_stext_transform(shape_t *shape) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
365 sh_stext_t *txt_o = (sh_stext_t *)shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
366 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
367 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
368 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
370 void sh_stext_draw(shape_t *shape, cairo_t *cr) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
371 sh_stext_t *txt_o = (sh_stext_t *)shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
372 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
373 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
374 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
375 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
376 int sh_stext_set_text(shape_t *shape, const char *txt) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
377 sh_stext_t *txt_o = (sh_stext_t *)shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
378 char *new_txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
379 int sz; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
380 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
381 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
382 ASSERT(txt != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
383 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
384 sz = strlen(txt) + 1; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
385 new_txt = realloc(txt_o->txt, sz); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
386 if(new_txt == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
387 return ERR; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
388 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
389 memcpy(new_txt, txt, sz); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
390 txt_o->txt = new_txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
391 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
392 return OK; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
393 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
394 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
395 int sh_stext_set_style(shape_t *shape, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
396 const mb_style_blk_t *blks, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
397 int nblks) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
398 sh_stext_t *txt_o = (sh_stext_t *)shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
399 mb_style_blk_t *new_blks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
400 co_aix *new_exts; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
401 int sz; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
402 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
403 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
404 ASSERT(nblks >= 0); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
405 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
406 if(nblks > txt_o->max_nblks) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
407 sz = nblks * (sizeof(mb_style_blk_t) + sizeof(int)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
408 new_blks = (mb_style_blk_t *)realloc(txt_o->style_blks, sz); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
409 if(new_blks == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
410 return ERR; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
411 new_exts = (int *)(new_blks + nblks); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
412 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
413 txt_o->style_blks = new_blks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
414 txt_o->exts = new_exts; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
415 txt_o->max_nblks = nblks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
416 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
417 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
418 memcpy(txt_o->blks, blks, nblks * sizeof(mb_style_blk_t)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
419 txt_o->nblks = nblks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
420 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
421 return OK; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
422 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
423 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
424 #endif /* SHAPE_STEXT */ |