Mercurial > MadButterfly
annotate src/shape_stext.c @ 407:92a459a1c5aa
more comment
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 07 Jul 2009 22:45:12 +0800 |
parents | aee0f66b1154 |
children | 1a923ea699c1 |
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 |
407 | 15 /*! \page stext Simple Text |
16 * | |
17 * A sh_stext_t is broken into fragments. Each fragment comprises the text | |
18 * and the styles applied on the fragement. The styles determines font face | |
19 * used to show the text. The fragment of text with styles is called | |
20 * styled block. | |
21 */ | |
22 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
23 /*! \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
|
24 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
25 * 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
|
26 * 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
|
27 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
28 * @{ |
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 * 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
|
33 * 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
|
34 * should known it. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
35 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
36 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
|
37 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
38 /*! \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
|
39 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
40 * 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
|
41 * programmers should assume it is opague. |
407 | 42 * |
43 * An extents is the span of showing a fragement of text on the output device. | |
44 * It includes x and y advance of cursor after showinng the text. | |
45 * The cursor maybe not really existed. But, the advance is computed as | |
46 * the cursor existed. It also includes width and height of the text. | |
47 * The bearing of a styled block is the left-top corner of the bounding box. | |
48 * The bounding box of a styled block is the minimal rectangle, on the | |
49 * output device, that can contain the text. The bearing is related to | |
50 * the base line for an extents. | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
51 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
52 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
|
53 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
54 #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
|
55 #define MBE_GET_Y_ADV(ext) ((ext)->y_advance) |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
56 #define MBE_GET_X_BEARING(ext) ((ext)->x_bearing) |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
57 #define MBE_GET_Y_BEARING(ext) ((ext)->y_bearing) |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
58 #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
|
59 #define MBE_GET_HEIGHT(ext) ((ext)->height) |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
60 #define MBE_SET_X_ADV(ext, v) do { ((ext)->x_advance) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
61 #define MBE_SET_Y_ADV(ext, v) do { ((ext)->y_advance) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
62 #define MBE_SET_X_BEARING(ext, v) do { ((ext)->x_bearing) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
63 #define MBE_SET_Y_BEARING(ext, v) do { ((ext)->y_bearing) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
64 #define MBE_SET_WIDTH(ext, v) do { ((ext)->width) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
65 #define MBE_SET_HEIGHT(ext, v) do { ((ext)->height) = v; } while(0) |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
66 |
395 | 67 /*! \brief Find out a font pattern. |
68 * | |
69 * This function use fontconfig to decide a font file in pattern. It can | |
70 * replaced by other mechanism if you think it is not what you want. | |
71 */ | |
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
|
72 static |
395 | 73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 |
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 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
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 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
|
91 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
|
92 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
|
93 |
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 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
|
95 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
|
96 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
|
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 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
|
99 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
|
100 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
|
101 |
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
|
102 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
|
103 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
|
104 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
|
105 |
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
|
106 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
|
107 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
|
108 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
|
109 |
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
|
110 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
|
111 |
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
|
112 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
|
113 |
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
|
114 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
|
115 |
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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
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
|
123 } |
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
|
124 |
395 | 125 /*! \brief Find out a font face for a pattern specified. |
126 * | |
127 * The pattern, here, is a vector of family, slant, and weight. | |
128 * This function base on fontconfig and cairo FreeType font supporting. | |
129 * You can replace this function with other font mechanisms. | |
130 */ | |
131 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
132 mb_font_face_t *query_font_face(const char *family, int slant, int weight) { |
395 | 133 cairo_font_face_t *cface; |
134 FcPattern *ptn; | |
135 | |
136 ptn = query_font_pattern(family, slant, weight); | |
137 cface = cairo_ft_font_face_create_for_pattern(ptn); | |
138 FcPatternDestroy(ptn); | |
139 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
140 return (mb_font_face_t *)cface; |
395 | 141 } |
142 | |
143 static | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
144 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
|
145 ASSERT(face == NULL); |
395 | 146 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
147 cairo_font_face_destroy((cairo_font_face_t *)face); |
395 | 148 } |
149 | |
150 /*! \brief This is scaled font for specified size and extent. | |
151 * | |
152 * Font face only specified which font would be used to draw text | |
153 * message. But, it also need to scale glyphs to specified size and | |
154 * rotation. This function return a scaled font specified by a | |
155 * matrix that transform glyph from design space of the font to | |
156 * user space of cairo surface. | |
157 */ | |
158 static | |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
159 mb_scaled_font_t *make_scaled_font_face_matrix(mb_font_face_t *face, |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
160 co_aix *matrix) { |
395 | 161 cairo_font_face_t *scaled_font; |
162 cairo_matrix_t font_matrix; | |
163 static cairo_matir_t id = { | |
164 1, 0, | |
165 0, 1, | |
166 0, 0 | |
167 }; | |
168 static cairo_font_options_t *opt = NULL; | |
169 | |
170 ASSERT(matrix != NULL); | |
171 | |
172 if(opt == NULL) { | |
173 opt = cairo_font_options_create(); | |
174 if(opt == NULL) | |
175 return NULL; | |
176 } | |
177 | |
178 font_matrix.xx = *matrix++; | |
179 font_matrix.xy = *matrix++; | |
180 font_matrix.x0 = *matrix++; | |
181 font_matrix.yx = *matrix++; | |
182 font_matrix.yy = *matrix++; | |
183 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
|
184 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
|
185 &font_matrix, |
395 | 186 &id, opt); |
187 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
188 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
|
189 } |
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 static |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
192 void scaled_font_free(mb_scaled_font_t *scaled_font) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
193 cairo_scaled_font_destroy((cairo_scaled_font_t *)scaled_font); |
395 | 194 } |
195 | |
196 static | |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
197 void compute_text_extents(mb_scaled_font_t *scaled_font, const char *txt, |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
198 mb_text_extents_t *extents) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
199 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
|
200 txt, |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
201 (cairo_text_extents_t *)extents); |
395 | 202 } |
203 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
204 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
205 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
|
206 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
|
207 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
208 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
|
209 return extents; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
210 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
211 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
212 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
213 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
|
214 free(extents); |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
215 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
216 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
217 /* @} */ |
395 | 218 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
219 /*! \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
|
220 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
221 * 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
|
222 * 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
|
223 * 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
|
224 * 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
|
225 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 * \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
|
227 * \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
|
228 * \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
|
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 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
|
231 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
|
232 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
|
233 int weight) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
234 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
|
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 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 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
|
238 ASSERT(face != NULL); |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
239 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
|
240 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 /*! \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
|
243 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
244 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 mb_scaled_font_t **scaled_fonts; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
253 mb_text_extents_t extents; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 } 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
|
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 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
|
257 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
|
258 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
|
259 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
260 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
|
261 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 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
|
267 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
|
268 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
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 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
|
278 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
|
279 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
|
280 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 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
|
283 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 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
|
291 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
|
292 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
|
293 /* 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
|
294 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
|
295 p++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
296 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 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
|
298 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
|
299 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 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
|
301 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 static |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
304 mb_scaled_font_t *make_scaled_font_face(sh_stext_t *txt_o, |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 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
|
306 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
|
307 co_aix font_sz) { |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
308 co_aix matrix[6], scaled_matrix[6]; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
309 co_aix *aggr; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
310 mb_scaled_font_t *scaled; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
312 aggr = sh_get_aggr_matrix((shape_t *)txt_o); |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
313 matrix[0] = font_sz; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
314 matrix[1] = 0; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
315 matrix[2] = shift_x; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
316 matrix[3] = 0; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
317 matrix[4] = font_sz; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
318 matrix[5] += shift_y; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
319 matrix_mul(aggr, matrix, scaled_matrix); |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
320 |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
321 scaled = make_scaled_font_face_matrix(face, scaled_matrix); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
322 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
323 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
|
324 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
325 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
326 /*! \brief Extend an extents from another sub-extents. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
327 * |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
328 * A styled text is styled by several styled blocks, so extents of |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
329 * blocks should be computed separated, collected, and aggreagated |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
330 * into a full extents. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
331 */ |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
332 static |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
333 void extent_extents(mb_text_extents_t *full, mb_text_extents_t *sub) { |
407 | 334 co_aix f_rbx, f_rby; /* rb stands for right button */ |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
335 co_aix s_rbx, s_rby; |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
336 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
337 f_rbx = MBE_GET_X_BEARING(full) + MBE_GET_WIDTH(full); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
338 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
339 s_rbx = MBE_GET_X_BEARING(sub) + MBE_GET_WIDTH(sub); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
340 s_rby = MBE_GET_Y_BEARING(sub) + MBE_GET_HEIGHT(sub); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
341 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
342 /* set bearing */ |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
343 if(MBE_GET_X_BEARING(full) > MBE_GET_X_BEARING(sub)) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
344 MBE_SET_X_BEARING(full, MBE_GET_X_BEARING(sub)); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
345 if(MBE_GET_Y_BEARING(full) > MBE_GET_Y_BEARING(sub)) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
346 MBE_SET_Y_BEARING(full, MBE_GET_Y_BEARING(sub)); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
347 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
348 /* set width/height */ |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
349 if(f_rbx < s_rbx) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
350 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full)); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
351 if(f_rby < s_rby) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
352 MBE_SET_HEIGHT(full, s_rby - MBE_GET_Y_BEARING(full)); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
353 } |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
354 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
355 /*! \brief Compute extents of a stext object according style blocks. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
356 * |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
357 * It create scaled fonts for style blocks, compute their extents, |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
358 * and compute where they should be draw acoording advance of style |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
359 * blocks before a style block. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
360 */ |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
361 static |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
362 void compute_styled_extents_n_scaled_font(sh_stext_t *txt_o) { |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
363 mb_text_extents_t sub_extents; |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
364 mb_text_extents_t *extents; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
365 mb_style_blk_t *blk; |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
366 int blk_txt_len; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
367 mb_scaled_font_t *scaled_font; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
368 char *txt, saved; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 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
|
370 int i; |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
371 |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
372 memset(&full_extents, sizeof(mb_text_extents_t), 0); |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
373 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
374 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
|
375 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
|
376 txt = (char *)txt_o->txt; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
377 extents = &txt_o->extents; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
378 for(i = 0; i < txt_o->nblks; i++) { |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
379 shift_x = txt_o->x + full_extents.x_adv; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
380 shift_y = txt_o->y + full_extents.y_adv; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
381 |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
382 *scaled_font = make_scaled_font_face(txt_o, blk->face, |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
383 shift_x, shift_y, font_sz); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
384 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
|
385 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
386 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
|
387 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
|
388 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
389 saved = txt[blk_txt_len]; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
390 txt[blk_txt_len] = 0; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
391 compute_text_extents(*scaled_font, txt, extents); |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
392 txt[blk_txt_len] = saved; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
393 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
394 extent_extents(&txt_o->full_extents, extents); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
395 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
396 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
|
397 blk++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
398 txt += blk_txt_len; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
399 extents = &sub_extents; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
400 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
401 } |
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 /* |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
404 * 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
|
405 * - 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
|
406 * - 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
|
407 * - 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
|
408 * - 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
|
409 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
410 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
|
411 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
|
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 ASSERT(txt_o != NULL); |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
414 compute_styled_extents_n_scaled_font(txt_o); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
415 } |
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 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
|
418 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
|
419 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
420 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
|
421 } |
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 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
|
424 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
|
425 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
|
426 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
|
427 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
428 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
|
429 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
|
430 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 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
|
435 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
436 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
|
437 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
|
438 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
439 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
|
440 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
441 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
450 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
|
451 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
|
452 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
464 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
465 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
|
466 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
|
467 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
468 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
|
469 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
470 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
471 #endif /* SHAPE_STEXT */ |