summaryrefslogtreecommitdiff
path: root/legacy/edje/src/lib/edje_text.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-12-12 14:07:28 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-12-12 14:07:28 +0000
commit5e76bb821f98ccc197d9de8cd7236138d16ef6f7 (patch)
tree4171319842a65ce02b52443fd4068d1ff2fdb73e /legacy/edje/src/lib/edje_text.c
parenta16f6e2330c04b77aacc372bc7a13e064bc379eb (diff)
edje: use Evas to compute Ellipsis.
Patch with help from Tom Hacohen. SVN revision: 80764
Diffstat (limited to 'legacy/edje/src/lib/edje_text.c')
-rw-r--r--legacy/edje/src/lib/edje_text.c190
1 files changed, 8 insertions, 182 deletions
diff --git a/legacy/edje/src/lib/edje_text.c b/legacy/edje/src/lib/edje_text.c
index 0b26580..907f5d2 100644
--- a/legacy/edje/src/lib/edje_text.c
+++ b/legacy/edje/src/lib/edje_text.c
@@ -77,52 +77,12 @@ _edje_text_part_on_del(Edje *ed, Edje_Part *pt)
77 } 77 }
78} 78}
79 79
80static void
81_edje_text_fit_set(char *buf, const char *text, int c1, int c2)
82{
83 /* helper function called from _edje_text_fit_x().
84 * note that we can use strcpy()/strcat() safely, the buffer lengths
85 * are checked in the caller.
86 */
87
88 if (c1 >= 0)
89 {
90 strcpy(buf, _ELLIP_STR);
91
92 if (c2 >= 0)
93 {
94 strncat(buf, text + c1, c2 - c1);
95 strcat(buf, _ELLIP_STR);
96 }
97 else
98 strcat(buf, text + c1);
99 }
100 else
101 {
102 if (c2 >= 0)
103 {
104 strncpy(buf, text, c2);
105 buf[c2] = 0;
106 strcat(buf, _ELLIP_STR);
107 }
108 else
109 strcpy(buf, text);
110 }
111}
112
113static const char * 80static const char *
114_edje_text_fit_x(Edje *ed, Edje_Real_Part *ep, 81_edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
115 Edje_Calc_Params *params, 82 Edje_Calc_Params *params,
116 const char *text, const char *font, int size, 83 const char *text, const char *font, int size,
117 Evas_Coord sw, int *free_text) 84 Evas_Coord sw, Evas_Coord sh, int *free_text)
118{ 85{
119 Evas_Coord tw = 0, th = 0, p;
120 int l, r;
121 int i;
122 char *buf;
123 int uc1 = -1, uc2 = -1, c1 = -1, c2 = -1;
124 int loop = 0, extra;
125 size_t orig_len;
126 FLOAT_T sc; 86 FLOAT_T sc;
127 87
128 sc = ed->scale; 88 sc = ed->scale;
@@ -134,148 +94,12 @@ _edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
134 if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc)); 94 if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc));
135 95
136 eo_do(ep->object, 96 eo_do(ep->object,
137 evas_obj_text_font_set(font, size), 97 evas_obj_text_ellipsis_set(params->type.text.elipsis),
98 evas_obj_text_font_set(font, size),
138 evas_obj_text_text_set(text), 99 evas_obj_text_text_set(text),
139 evas_obj_text_style_pad_get(&l, &r, NULL, NULL)); 100 evas_obj_size_set(sw, sh));
140 part_get_geometry(ep, &tw, &th);
141
142 p = ((sw - tw) * params->type.text.elipsis);
143
144 /* chop chop */
145 if (tw > sw)
146 {
147 if (params->type.text.elipsis != 0.0)
148 /* should be the last in text! not the rightmost */
149 uc1 = evas_object_text_last_up_to_pos(ep->object,
150 -p + l, th / 2);
151 if (params->type.text.elipsis != 1.0)
152 {
153 /* should be the last in text! not the rightmost */
154 if ((-p + sw -r) < 0)
155 uc2 = evas_object_text_last_up_to_pos(ep->object, 0, th / 2);
156 else
157 uc2 = evas_object_text_last_up_to_pos(ep->object,
158 -p + sw - r, th / 2);
159 }
160 if ((uc1 < 0) && (uc2 < 0))
161 {
162 uc1 = 0;
163 uc2 = 0;
164 }
165 }
166
167 if (!(((uc1 >= 0) || (uc2 >= 0)) && (tw > sw)))
168 return text;
169
170 if ((uc1 == 0) && (uc2 == 0))
171 return text;
172
173 orig_len = strlen(text);
174
175 /* don't overflow orig_len by adding extra
176 * FIXME: we might want to set a max string length somewhere...
177 */
178 extra = 1 + 3 + 3; /* terminator, leading and trailing ellipsis */
179 orig_len = MIN(orig_len, ((size_t) 8192 - extra));
180
181 if (!(buf = malloc(orig_len + extra)))
182 return text;
183
184 /* Convert uc1, uc2 -> c1, c2 */
185 i = 0;
186 if (uc1 >= 0)
187 {
188 c1 = 0;
189 for ( ; i < uc1 ; i++)
190 {
191 c1 = evas_string_char_next_get(text, c1, NULL);
192 }
193 }
194 if (uc2 >= 0)
195 {
196 if (c1 >= 0)
197 {
198 c2 = c1;
199 }
200 else
201 {
202 c2 = 0;
203 }
204 for ( ; i < uc2 ; i++)
205 {
206 c2 = evas_string_char_next_get(text, c2, NULL);
207 }
208 }
209
210 buf[0] = '\0';
211
212 while (((c1 >= 0) || (c2 >= 0)) && (tw > sw))
213 {
214 loop++;
215 if (sw <= 0.0)
216 {
217 buf[0] = 0;
218 break;
219 }
220 if ((c1 >= 0) && (c2 >= 0))
221 {
222 if ((loop & 0x1))
223 {
224 if (c1 >= 0)
225 c1 = evas_string_char_next_get(text, c1, NULL);
226 }
227 else
228 {
229 if (c2 >= 0)
230 {
231 c2 = evas_string_char_prev_get(text, c2, NULL);
232 if (c2 < 0)
233 {
234 buf[0] = 0;
235 break;
236 }
237 }
238 }
239 }
240 else
241 {
242 if (c1 >= 0)
243 c1 = evas_string_char_next_get(text, c1, NULL);
244 else if (c2 >= 0)
245 {
246 c2 = evas_string_char_prev_get(text, c2, NULL);
247 if (c2 < 0)
248 {
249 buf[0] = 0;
250 break;
251 }
252 }
253 }
254 if ((c1 >= 0) && (c2 >= 0))
255 {
256 if (c1 >= c2)
257 {
258 buf[0] = 0;
259 break;
260 }
261 }
262 else if ((c1 > 0 && (size_t) c1 >= orig_len) || c2 == 0)
263 {
264 buf[0] = 0;
265 break;
266 }
267
268 buf[0] = 0;
269
270 _edje_text_fit_set(buf, text, c1, c2);
271
272 evas_object_text_text_set(ep->object, buf);
273 part_get_geometry(ep, &tw, &th);
274 }
275
276 *free_text = 1;
277 101
278 return buf; 102 return text;
279} 103}
280 104
281static const char * 105static const char *
@@ -569,7 +393,9 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
569 if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path); 393 if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path);
570 else evas_object_text_font_source_set(ep->object, NULL); 394 else evas_object_text_font_source_set(ep->object, NULL);
571 395
572 text = _edje_text_fit_x(ed, ep, params, text, font, size, sw, &free_text); 396 text = _edje_text_fit_x(ed, ep, params,
397 text, font, size,
398 sw, sh, &free_text);
573 } 399 }
574 400
575 eina_stringshare_replace(&ep->typedata.text->cache.out_str, text); 401 eina_stringshare_replace(&ep->typedata.text->cache.out_str, text);