summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2013-09-20 15:53:08 +0100
committerTom Hacohen <tom@stosb.com>2013-09-23 14:37:18 +0100
commit72167b9cc3db0a28a6be53de676662d93cd820b5 (patch)
tree90aafa3abad9828e89d70f34fcbde1c23de8c292
parent5adffd54e5f2e6490ef5c4aff4c932f625a83f68 (diff)
Evas textblock: Fixed ascent/descent calculation a bit more.
Separated maxascent/descent from ascent/descent even further. Fix calculation to be based on font instance and not the font group.
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c146
1 files changed, 110 insertions, 36 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 924ef75d7e..086cc152fc 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -2558,18 +2558,75 @@ _layout_format_ascent_descent_adjust(const Evas_Object *eo_obj,
2558 } 2558 }
2559} 2559}
2560 2560
2561static void
2562_layout_item_max_ascent_descent_calc(const Evas_Object *eo_obj,
2563 Evas_Coord *maxascent, Evas_Coord *maxdescent,
2564 Evas_Object_Textblock_Item *it, Textblock_Position position)
2565{
2566 void *fi = NULL;
2567 *maxascent = *maxdescent = 0;
2568
2569 if (it->type == EVAS_TEXTBLOCK_ITEM_TEXT)
2570 {
2571 fi = _ITEM_TEXT(it)->text_props.font_instance;
2572 }
2573
2574 if ((position == TEXTBLOCK_POSITION_START) ||
2575 (position == TEXTBLOCK_POSITION_SINGLE))
2576 {
2577 Evas_Coord asc = 0;
2578
2579 if (fi)
2580 {
2581 asc = evas_common_font_instance_max_ascent_get(fi);
2582 }
2583 else
2584 {
2585 Evas_Object_Protected_Data *obj =
2586 eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
2587 asc = ENFN->font_max_ascent_get(ENDT,
2588 it->format->font.font);
2589 }
2590
2591 if (asc > *maxascent)
2592 *maxascent = asc;
2593 }
2594
2595 if ((position == TEXTBLOCK_POSITION_END) ||
2596 (position == TEXTBLOCK_POSITION_SINGLE))
2597 {
2598 /* Calculate max descent. */
2599 Evas_Coord desc = 0;
2600
2601 if (fi)
2602 {
2603 desc = evas_common_font_instance_max_descent_get(fi);
2604 }
2605 else
2606 {
2607 Evas_Object_Protected_Data *obj =
2608 eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
2609 desc = ENFN->font_max_descent_get(ENDT,
2610 it->format->font.font);
2611 }
2612
2613 if (desc > *maxdescent)
2614 *maxdescent = desc;
2615 }
2616}
2617
2561/** 2618/**
2562 * @internal 2619 * @internal
2563 * Adjust the ascent/descent of the item and context. 2620 * Adjust the ascent/descent of the item and context.
2564 * 2621 *
2565 * @param maxascent The ascent to update - Not NUL. 2622 * @param ascent The ascent to update - Not NUL.
2566 * @param maxdescent The descent to update - Not NUL. 2623 * @param descent The descent to update - Not NUL.
2567 * @param it The format to adjust - NOT NULL. 2624 * @param it The format to adjust - NOT NULL.
2568 * @param position The position inside the textblock 2625 * @param position The position inside the textblock
2569 */ 2626 */
2570static void 2627static void
2571_layout_item_ascent_descent_adjust(const Evas_Object *eo_obj, 2628_layout_item_ascent_descent_adjust(const Evas_Object *eo_obj,
2572 Evas_Coord *maxascent, Evas_Coord *maxdescent, 2629 Evas_Coord *ascent, Evas_Coord *descent,
2573 Evas_Object_Textblock_Item *it, Textblock_Position position) 2630 Evas_Object_Textblock_Item *it, Textblock_Position position)
2574{ 2631{
2575 if (!it->format || !it->format->font.font) 2632 if (!it->format || !it->format->font.font)
@@ -2577,51 +2634,33 @@ _layout_item_ascent_descent_adjust(const Evas_Object *eo_obj,
2577 return; 2634 return;
2578 } 2635 }
2579 2636
2580 _layout_format_ascent_descent_adjust(eo_obj, maxascent, maxdescent, it->format); 2637 _layout_format_ascent_descent_adjust(eo_obj, ascent, descent, it->format);
2581 2638
2582 if (it->type == EVAS_TEXTBLOCK_ITEM_TEXT) 2639 if (it->type == EVAS_TEXTBLOCK_ITEM_TEXT)
2583 { 2640 {
2584 void *fi = _ITEM_TEXT(it)->text_props.font_instance;
2585
2586 if ((position == TEXTBLOCK_POSITION_START) ||
2587 (position == TEXTBLOCK_POSITION_SINGLE))
2588 {
2589 int asc = 0;
2590
2591 if (fi)
2592 {
2593 asc = evas_common_font_instance_max_ascent_get(fi);
2594 }
2595 else
2596 {
2597 Evas_Object_Protected_Data *obj =
2598 eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
2599 asc = ENFN->font_max_ascent_get(ENDT, it->format->font.font);
2600 }
2601
2602 if (maxascent && (asc > *maxascent))
2603 *maxascent = asc;
2604 }
2605
2606 if ((position == TEXTBLOCK_POSITION_END) ||
2607 (position == TEXTBLOCK_POSITION_SINGLE))
2608 { 2641 {
2609 int desc = 0; 2642 void *fi = _ITEM_TEXT(it)->text_props.font_instance;
2643 int asc = 0, desc = 0;
2610 2644
2611 if (fi) 2645 if (fi)
2612 { 2646 {
2613 desc = evas_common_font_instance_max_descent_get(fi); 2647 asc = evas_common_font_instance_ascent_get(fi);
2648 desc = evas_common_font_instance_descent_get(fi);
2614 } 2649 }
2615 else 2650 else
2616 { 2651 {
2617 Evas_Object_Protected_Data *obj = 2652 Evas_Object_Protected_Data *obj =
2618 eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS); 2653 eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
2654 asc =
2655 ENFN->font_ascent_get(ENDT, it->format->font.font);
2619 desc = 2656 desc =
2620 ENFN->font_max_descent_get(ENDT, it->format->font.font); 2657 ENFN->font_descent_get(ENDT, it->format->font.font);
2621 } 2658 }
2622 2659
2623 if (maxdescent && (desc > *maxdescent)) 2660 if (ascent && (asc > *ascent))
2624 *maxdescent = desc; 2661 *ascent = asc;
2662 if (descent && (desc > *descent))
2663 *descent = desc;
2625 } 2664 }
2626 } 2665 }
2627} 2666}
@@ -3265,9 +3304,6 @@ _layout_line_finalize(Ctxt *c, Evas_Object_Textblock_Format *fmt)
3265 Evas_Object_Textblock_Item *it; 3304 Evas_Object_Textblock_Item *it;
3266 Evas_Coord x = 0; 3305 Evas_Coord x = 0;
3267 3306
3268 if (c->position == TEXTBLOCK_POSITION_START)
3269 c->position = TEXTBLOCK_POSITION_ELSE;
3270
3271 /* If there are no text items yet, calc ascent/descent 3307 /* If there are no text items yet, calc ascent/descent
3272 * according to the current format. */ 3308 * according to the current format. */
3273 if (c->ascent + c->descent == 0) 3309 if (c->ascent + c->descent == 0)
@@ -3289,13 +3325,20 @@ _layout_line_finalize(Ctxt *c, Evas_Object_Textblock_Format *fmt)
3289 else 3325 else
3290 { 3326 {
3291 Evas_Coord asc = 0, desc = 0; 3327 Evas_Coord asc = 0, desc = 0;
3328 Evas_Coord maxasc = 0, maxdesc = 0;
3292 _layout_item_ascent_descent_adjust(c->obj, &asc, &desc, 3329 _layout_item_ascent_descent_adjust(c->obj, &asc, &desc,
3293 it, c->position); 3330 it, c->position);
3331 _layout_item_max_ascent_descent_calc(c->obj, &maxasc, &maxdesc,
3332 it, c->position);
3294 3333
3295 if (asc > c->ascent) 3334 if (asc > c->ascent)
3296 c->ascent = asc; 3335 c->ascent = asc;
3297 if (desc > c->descent) 3336 if (desc > c->descent)
3298 c->descent = desc; 3337 c->descent = desc;
3338 if (maxasc > c->maxascent)
3339 c->maxascent = maxasc;
3340 if (maxdesc > c->maxdescent)
3341 c->maxdescent = maxdesc;
3299 } 3342 }
3300 3343
3301loop_advance: 3344loop_advance:
@@ -3307,6 +3350,34 @@ loop_advance:
3307 3350
3308 c->ln->y = (c->y - c->par->y) + c->o->style_pad.t; 3351 c->ln->y = (c->y - c->par->y) + c->o->style_pad.t;
3309 c->ln->h = c->ascent + c->descent; 3352 c->ln->h = c->ascent + c->descent;
3353
3354 /* Handle max ascent and descent if at the edges */
3355 {
3356 /* If it's the start, offset the line according to the max ascent. */
3357 if (((c->position == TEXTBLOCK_POSITION_START) ||
3358 (c->position == TEXTBLOCK_POSITION_SINGLE))
3359 && (c->maxascent > c->ascent))
3360 {
3361 Evas_Coord ascdiff;
3362
3363 ascdiff = c->maxascent - c->ascent;
3364 c->ln->y += ascdiff;
3365 c->y += ascdiff;
3366 }
3367
3368 /* If it's the end, add the adjustment to the line height. */
3369 if (((c->position == TEXTBLOCK_POSITION_END) ||
3370 (c->position == TEXTBLOCK_POSITION_SINGLE))
3371 && (c->maxdescent > c->descent))
3372 {
3373 Evas_Coord descdiff;
3374
3375 descdiff = c->maxdescent - c->descent;
3376 c->ln->h += descdiff;
3377 c->y += descdiff;
3378 }
3379 }
3380
3310 c->ln->baseline = c->ascent; 3381 c->ln->baseline = c->ascent;
3311 if (c->have_underline2) 3382 if (c->have_underline2)
3312 { 3383 {
@@ -3341,6 +3412,9 @@ loop_advance:
3341 if (new_wmax > c->wmax) 3412 if (new_wmax > c->wmax)
3342 c->wmax = new_wmax; 3413 c->wmax = new_wmax;
3343 } 3414 }
3415
3416 if (c->position == TEXTBLOCK_POSITION_START)
3417 c->position = TEXTBLOCK_POSITION_ELSE;
3344} 3418}
3345 3419
3346/** 3420/**