summaryrefslogtreecommitdiff
path: root/legacy/edje/src/lib/edje_text.c
diff options
context:
space:
mode:
authortsauerbeck <tsauerbeck>2004-10-30 15:51:55 +0000
committertsauerbeck <tsauerbeck@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2004-10-30 15:51:55 +0000
commit216fdda3e3ffc1ebde32d4078800963939e70abc (patch)
tree776999720b74d3543253d4f27d654661c2956333 /legacy/edje/src/lib/edje_text.c
parent5f8c7f1a8e6aacaa4d80e7050f2a2fbaf94dd6d0 (diff)
split _edje_text_recalc_apply()
SVN revision: 12092
Diffstat (limited to 'legacy/edje/src/lib/edje_text.c')
-rw-r--r--legacy/edje/src/lib/edje_text.c268
1 files changed, 146 insertions, 122 deletions
diff --git a/legacy/edje/src/lib/edje_text.c b/legacy/edje/src/lib/edje_text.c
index 4a1c4fd..692131d 100644
--- a/legacy/edje/src/lib/edje_text.c
+++ b/legacy/edje/src/lib/edje_text.c
@@ -5,6 +5,8 @@
5#include "Edje.h" 5#include "Edje.h"
6#include "edje_private.h" 6#include "edje_private.h"
7 7
8#include <stdint.h>
9
8Edje_Text_Style _edje_text_styles[EDJE_TEXT_EFFECT_LAST]; 10Edje_Text_Style _edje_text_styles[EDJE_TEXT_EFFECT_LAST];
9 11
10void 12void
@@ -285,6 +287,145 @@ _edje_text_real_part_on_del(Edje *ed, Edje_Real_Part *ep)
285} 287}
286 288
287void 289void
290_edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
291 Edje_Calc_Params *params,
292 char *text, char *font, int size,
293 Evas_Coord sw)
294{
295 Evas_Coord tw = 0, th = 0, p;
296 char *buf;
297 int c1 = -1, c2 = -1, loop = 0, extra;
298 size_t orig_len;
299
300 evas_object_text_font_set(ep->object, font, size);
301 evas_object_text_text_set(ep->object, text);
302
303 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
304
305 p = ((sw - tw) * params->text.align.x);
306
307 /* chop chop */
308 if (tw > sw)
309 {
310 if (params->text.align.x != 0.0)
311 c1 = evas_object_text_char_coords_get(ep->object,
312 -p, th / 2,
313 NULL, NULL, NULL, NULL);
314 if (params->text.align.x != 1.0)
315 c2 = evas_object_text_char_coords_get(ep->object,
316 -p + sw, th / 2,
317 NULL, NULL, NULL, NULL);
318 if ((c1 < 0) && (c2 < 0))
319 {
320 c1 = 0;
321 c2 = 0;
322 }
323 }
324
325 extra = 1 + 3 + 3; /* terminator, leading and trailing ellipsis */
326
327 orig_len = strlen(text);
328
329 /* don't overflow orig_len by adding extra
330 * FIXME: we might want to set a max string length somewhere...
331 */
332 orig_len = MIN(orig_len, SIZE_MAX - extra);
333
334 if (!(buf = malloc(orig_len + extra)))
335 return;
336
337 while (((c1 >= 0) || (c2 >= 0)) && (tw > sw))
338 {
339 loop++;
340 if (sw <= 0.0)
341 {
342 buf[0] = 0;
343 break;
344 }
345 if ((c1 >= 0) && (c2 >= 0))
346 {
347 if ((loop & 0x1))
348 {
349 if (c1 >= 0)
350 c1 = evas_string_char_next_get(text, c1, NULL);
351 }
352 else
353 {
354 if (c2 >= 0)
355 {
356 c2 = evas_string_char_prev_get(text, c2, NULL);
357 if (c2 < 0)
358 {
359 buf[0] = 0;
360 break;
361 }
362 }
363 }
364 }
365 else
366 {
367 if (c1 >= 0)
368 c1 = evas_string_char_next_get(text, c1, NULL);
369 else if (c2 >= 0)
370 {
371 c2 = evas_string_char_prev_get(text, c2, NULL);
372 if (c2 < 0)
373 {
374 buf[0] = 0;
375 break;
376 }
377 }
378 }
379 if ((c1 >= 0) && (c2 >= 0))
380 {
381 if (c1 >= c2)
382 {
383 buf[0] = 0;
384 break;
385 }
386 }
387 else
388 {
389 if (c1 >= orig_len)
390 {
391 buf[0] = 0;
392 break;
393 }
394 else if (c2 == 0)
395 {
396 buf[0] = 0;
397 break;
398 }
399 }
400 buf[0] = 0;
401 if (c1 >= 0)
402 {
403 strcpy(buf, "...");
404 if (c2 >= 0)
405 {
406 strncat(buf, text + c1, c2 - c1);
407 strcat(buf, "...");
408 }
409 else
410 strcat(buf, text + c1);
411 }
412 else
413 {
414 if (c2 >= 0)
415 {
416 strncpy(buf, text, c2);
417 buf[c2] = 0;
418 strcat(buf, "...");
419 }
420 else strcpy(buf, text);
421 }
422 evas_object_text_text_set(ep->object, buf);
423 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
424 }
425 if (loop > 0) text = buf;
426}
427
428void
288_edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, 429_edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
289 Edje_Calc_Params *params, 430 Edje_Calc_Params *params,
290 Edje_Part_Description *chosen_desc) 431 Edje_Part_Description *chosen_desc)
@@ -453,132 +594,15 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
453 } 594 }
454 } 595 }
455 if (size < 1) size = 1; 596 if (size < 1) size = 1;
597
456 if (!chosen_desc->text.fit_x) 598 if (!chosen_desc->text.fit_x)
457 { 599 {
458 Evas_Coord p; 600 if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path);
459 int c1, c2;
460 int loop;
461 int orig_len;
462
463 if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path);
464 else evas_object_text_font_source_set(ep->object, NULL); 601 else evas_object_text_font_source_set(ep->object, NULL);
465 602
466 evas_object_text_font_set(ep->object, font, size); 603 _edje_text_fit_x(ed, ep, params, text, font, size, sw);
467 evas_object_text_text_set(ep->object, text);
468 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
469 p = ((sw - tw) * params->text.align.x);
470 c1 = -1;
471 c2 = -1;
472 /* chop chop */
473 if (tw > sw)
474 {
475 if (params->text.align.x != 0.0)
476 c1 = evas_object_text_char_coords_get(ep->object,
477 -p, th / 2,
478 NULL, NULL, NULL, NULL);
479 if (params->text.align.x != 1.0)
480 c2 = evas_object_text_char_coords_get(ep->object,
481 -p + sw, th / 2,
482 NULL, NULL, NULL, NULL);
483 if ((c1 < 0) && (c2 < 0))
484 {
485 c1 = 0;
486 c2 = 0;
487 }
488 }
489 loop = 0;
490 buf = malloc(strlen(text) + 1 + 3 + 3);
491 orig_len = strlen(text);
492 while (((c1 >= 0) || (c2 >= 0)) && (tw > sw))
493 {
494 loop++;
495 if (sw <= 0.0)
496 {
497 buf[0] = 0;
498 break;
499 }
500 if ((c1 >= 0) && (c2 >= 0))
501 {
502 if ((loop & 0x1))
503 {
504 if (c1 >= 0)
505 c1 = evas_string_char_next_get(text, c1, NULL);
506 }
507 else
508 {
509 if (c2 >= 0)
510 {
511 c2 = evas_string_char_prev_get(text, c2, NULL);
512 if (c2 < 0)
513 {
514 buf[0] = 0;
515 break;
516 }
517 }
518 }
519 }
520 else
521 {
522 if (c1 >= 0)
523 c1 = evas_string_char_next_get(text, c1, NULL);
524 else if (c2 >= 0)
525 {
526 c2 = evas_string_char_prev_get(text, c2, NULL);
527 if (c2 < 0)
528 {
529 buf[0] = 0;
530 break;
531 }
532 }
533 }
534 if ((c1 >= 0) && (c2 >= 0))
535 {
536 if (c1 >= c2)
537 {
538 buf[0] = 0;
539 break;
540 }
541 }
542 else
543 {
544 if (c1 >= orig_len)
545 {
546 buf[0] = 0;
547 break;
548 }
549 else if (c2 == 0)
550 {
551 buf[0] = 0;
552 break;
553 }
554 }
555 buf[0] = 0;
556 if (c1 >= 0)
557 {
558 strcpy(buf, "...");
559 if (c2 >= 0)
560 {
561 strncat(buf, text + c1, c2 - c1);
562 strcat(buf, "...");
563 }
564 else
565 strcat(buf, text + c1);
566 }
567 else
568 {
569 if (c2 >= 0)
570 {
571 strncpy(buf, text, c2);
572 buf[c2] = 0;
573 strcat(buf, "...");
574 }
575 else strcpy(buf, text);
576 }
577 evas_object_text_text_set(ep->object, buf);
578 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
579 }
580 if (loop > 0) text = buf;
581 } 604 }
605
582 if (ep->text.cache.out_str) free(ep->text.cache.out_str); 606 if (ep->text.cache.out_str) free(ep->text.cache.out_str);
583 ep->text.cache.out_str = strdup(text); 607 ep->text.cache.out_str = strdup(text);
584 ep->text.cache.in_w = sw; 608 ep->text.cache.in_w = sw;