summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Gusarov <dottedmag@dottedmag.net>2010-03-04 15:02:10 +0000
committerMikhail Gusarov <dottedmag@dottedmag.net>2010-03-04 15:02:10 +0000
commita5a07377f670c17ee728c1ce5ca86017e1aa140f (patch)
tree4c74460c3b5a0d0096d0cf57e29f6fbe55b8db4c
parent4d49bef2fd7dafa9c75e97603a2e1e04bfc4d9d0 (diff)
evas_textblock: Make maxascent/maxdescent variables local.
They are used in single function, so don't keep them in structure. As a side-effect rework _layout_line_advance for better readability. SVN revision: 46872
-rw-r--r--legacy/evas/src/lib/canvas/evas_object_textblock.c93
1 files changed, 55 insertions, 38 deletions
diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c
index a72b295d32..3f0adf4967 100644
--- a/legacy/evas/src/lib/canvas/evas_object_textblock.c
+++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c
@@ -1278,7 +1278,6 @@ struct _Ctxt
1278 int x, y; 1278 int x, y;
1279 int w, h; 1279 int w, h;
1280 int wmax, hmax; 1280 int wmax, hmax;
1281 int maxascent, maxdescent;
1282 int marginl, marginr; 1281 int marginl, marginr;
1283 int line_no; 1282 int line_no;
1284 int underline_extend; 1283 int underline_extend;
@@ -1287,7 +1286,8 @@ struct _Ctxt
1287}; 1286};
1288 1287
1289static void 1288static void
1290_layout_format_ascent_descent_adjust(Ctxt *c, Evas_Object_Textblock_Format *fmt) 1289_layout_format_ascent_descent_adjust(Ctxt *c, Evas_Object_Textblock_Format *fmt,
1290 int *maxascent, int *maxdescent)
1291{ 1291{
1292 int ascent, descent; 1292 int ascent, descent;
1293 1293
@@ -1308,8 +1308,8 @@ _layout_format_ascent_descent_adjust(Ctxt *c, Evas_Object_Textblock_Format *fmt)
1308 descent = ((ascent + descent) * fmt->linerelsize) - (ascent * fmt->linerelsize); 1308 descent = ((ascent + descent) * fmt->linerelsize) - (ascent * fmt->linerelsize);
1309 ascent = ascent * fmt->linerelsize; 1309 ascent = ascent * fmt->linerelsize;
1310 } 1310 }
1311 if (c->maxascent < ascent) c->maxascent = ascent; 1311 if (*maxascent < ascent) *maxascent = ascent;
1312 if (c->maxdescent < descent) c->maxdescent = descent; 1312 if (*maxdescent < descent) *maxdescent = descent;
1313 } 1313 }
1314} 1314}
1315 1315
@@ -1322,9 +1322,7 @@ _layout_line_new(Ctxt *c, Evas_Object_Textblock_Format *fmt)
1322 c->marginr = fmt->margin.r; 1322 c->marginr = fmt->margin.r;
1323 c->lines = (Evas_Object_Textblock_Line *)eina_inlist_append(EINA_INLIST_GET(c->lines), EINA_INLIST_GET(c->ln)); 1323 c->lines = (Evas_Object_Textblock_Line *)eina_inlist_append(EINA_INLIST_GET(c->lines), EINA_INLIST_GET(c->ln));
1324 c->x = 0; 1324 c->x = 0;
1325 c->maxascent = c->maxdescent = 0;
1326 c->ln->line_no = -1; 1325 c->ln->line_no = -1;
1327 _layout_format_ascent_descent_adjust(c, fmt);
1328} 1326}
1329 1327
1330static Evas_Object_Textblock_Format * 1328static Evas_Object_Textblock_Format *
@@ -1377,52 +1375,72 @@ _layout_format_value_handle(Ctxt *c, Evas_Object_Textblock_Format *fmt, char *it
1377} 1375}
1378 1376
1379static void 1377static void
1380_layout_line_advance(Ctxt *c, Evas_Object_Textblock_Format *fmt) 1378_layout_line_finish(Ctxt* c, Evas_Object_Textblock_Format *fmt)
1381{ 1379{
1382 Evas_Object_Textblock_Item *it; 1380 Evas_Object_Textblock_Item *it;
1383 1381
1384 c->maxascent = c->maxdescent = 0; 1382 /* Calculate maxascent, maxdescent for current line */
1383 int maxascent = 0;
1384 int maxdescent = 0;
1385
1385 if (!c->ln->items) 1386 if (!c->ln->items)
1386 _layout_format_ascent_descent_adjust(c, fmt); 1387 _layout_format_ascent_descent_adjust(c, fmt, &maxascent, &maxdescent);
1387 EINA_INLIST_FOREACH(c->ln->items, it) 1388 EINA_INLIST_FOREACH(c->ln->items, it)
1388 { 1389 _layout_format_ascent_descent_adjust(c, it->format, &maxascent, &maxdescent);
1389 int endx;
1390 1390
1391 if (it->format->font.font) 1391 /* Fill in baseline for each textblock item */
1392 it->baseline = c->ENFN->font_max_ascent_get(c->ENDT, it->format->font.font); 1392 EINA_INLIST_FOREACH(c->ln->items, it)
1393 _layout_format_ascent_descent_adjust(c, it->format); 1393 if (it->format->font.font)
1394 endx = it->x + it->w; 1394 it->baseline = c->ENFN->font_max_ascent_get(c->ENDT, it->format->font.font);
1395 if (endx > c->ln->w) c->ln->w = endx; 1395
1396 } 1396 /* Calculate width of line */
1397 EINA_INLIST_FOREACH(c->ln->items, it)
1398 if (it->x + it->w + c->ln->w) c->ln->w = it->x + it->w;
1399
1400 /* Adjust (?) line vertical position */
1397 c->ln->y = c->y + c->o->style_pad.t; 1401 c->ln->y = c->y + c->o->style_pad.t;
1398 c->ln->h = c->maxascent + c->maxdescent; 1402
1399 c->ln->baseline = c->maxascent; 1403 /* Calculate line height */
1404 c->ln->h = maxascent + maxdescent;
1405
1406 /* Calculate (???) line baseline */
1407 c->ln->baseline = maxascent;
1408
1409 /* Calculate adjustments for underline */
1400 if (c->have_underline2) 1410 if (c->have_underline2)
1401 { 1411 {
1402 if (c->maxdescent < 4) c->underline_extend = 4 - c->maxdescent; 1412 if (maxdescent < 4) c->underline_extend = 4 - maxdescent;
1403 } 1413 }
1404 else if (c->have_underline) 1414 else if (c->have_underline)
1405 { 1415 {
1406 if (c->maxdescent < 2) c->underline_extend = 2 - c->maxdescent; 1416 if (maxdescent < 2) c->underline_extend = 2 - maxdescent;
1407 } 1417 }
1418
1419 /* Store current line number */
1408 c->ln->line_no = c->line_no; 1420 c->ln->line_no = c->line_no;
1409 c->line_no++; 1421 c->line_no++;
1410 c->y += c->maxascent + c->maxdescent; 1422
1411 if (c->w >= 0) 1423 /* Calculate current position in context for next line */
1412 { 1424 c->y += c->ln->h;
1413 c->ln->x = c->marginl + c->o->style_pad.l + 1425
1414 ((c->w - c->ln->w - 1426 /* Calculate line horizontal position and c->wmax */
1415 c->o->style_pad.l - c->o->style_pad.r - 1427
1416 c->marginl - c->marginr) * c->align); 1428 /* If there is no width, align left */
1417 if ((c->ln->x + c->ln->w + c->marginr - c->o->style_pad.l) > c->wmax) 1429 double align = c->w >= 0 ? c->align : 0.0;
1418 c->wmax = c->ln->x + c->ln->w + c->marginl + c->marginr - c->o->style_pad.l; 1430
1419 } 1431 c->ln->x = c->marginl + c->o->style_pad.l +
1420 else 1432 ((c->w - c->ln->w -
1421 { 1433 c->o->style_pad.l - c->o->style_pad.r -
1422 c->ln->x = c->marginl + c->o->style_pad.l; 1434 c->marginl - c->marginr) * c->align);
1423 if ((c->ln->x + c->ln->w + c->marginr - c->o->style_pad.l) > c->wmax) 1435 if ((c->ln->x + c->ln->w + c->marginr - c->o->style_pad.l) > c->wmax)
1424 c->wmax = c->ln->x + c->ln->w + c->marginl + c->marginr - c->o->style_pad.l; 1436 c->wmax = c->ln->x + c->ln->w + c->marginl + c->marginr - c->o->style_pad.l;
1425 } 1437}
1438
1439
1440static void
1441_layout_line_advance(Ctxt *c, Evas_Object_Textblock_Format *fmt)
1442{
1443 _layout_line_finish(c, fmt);
1426 _layout_line_new(c, fmt); 1444 _layout_line_new(c, fmt);
1427} 1445}
1428 1446
@@ -1980,7 +1998,6 @@ _layout(const Evas_Object *obj, int calc_only, int w, int h, int *w_ret, int *h_
1980 c->w = w; 1998 c->w = w;
1981 c->h = h; 1999 c->h = h;
1982 c->wmax = c->hmax = 0; 2000 c->wmax = c->hmax = 0;
1983 c->maxascent = c->maxdescent = 0;
1984 c->marginl = c->marginr = 0; 2001 c->marginl = c->marginr = 0;
1985 c->have_underline = 0; 2002 c->have_underline = 0;
1986 c->have_underline2 = 0; 2003 c->have_underline2 = 0;