summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Gusarov <dottedmag@dottedmag.net>2010-03-04 15:51:30 +0000
committerMikhail Gusarov <dottedmag@dottedmag.net>2010-03-04 15:51:30 +0000
commita4157cbc2a7b5405499ca36b7cb9c6820c8880a1 (patch)
tree2863022b19095e10e6c494c4e4c25a9c33c467bd
parenta5a07377f670c17ee728c1ce5ca86017e1aa140f (diff)
Insert more comments into _format and simplify if() logic as we go
SVN revision: 46873
-rw-r--r--legacy/evas/src/lib/canvas/evas_object_textblock.c75
1 files changed, 66 insertions, 9 deletions
diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c
index 3f0adf4967..12f021c039 100644
--- a/legacy/evas/src/lib/canvas/evas_object_textblock.c
+++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c
@@ -1725,6 +1725,10 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1725 const char *tbase; 1725 const char *tbase;
1726 Evas_Object_Textblock_Item *it; 1726 Evas_Object_Textblock_Item *it;
1727 1727
1728 /*
1729 * If there is replacement character and text in node is non-empty, replace
1730 * text with replacement characters.
1731 */
1728 if ((repch) && (eina_strbuf_length_get(n->text))) 1732 if ((repch) && (eina_strbuf_length_get(n->text)))
1729 { 1733 {
1730 int i, len, chlen; 1734 int i, len, chlen;
@@ -1733,21 +1737,24 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1733 len = evas_common_font_utf8_get_len((unsigned char *) eina_strbuf_string_get(n->text)); 1737 len = evas_common_font_utf8_get_len((unsigned char *) eina_strbuf_string_get(n->text));
1734 chlen = strlen(repch); 1738 chlen = strlen(repch);
1735 str = alloca((len * chlen) + 1); 1739 str = alloca((len * chlen) + 1);
1736 tbase = str;
1737 for (i = 0, ptr = str; i < len; ptr += chlen, i++) 1740 for (i = 0, ptr = str; i < len; ptr += chlen, i++)
1738 memcpy(ptr, repch, chlen); 1741 memcpy(ptr, repch, chlen);
1739 *ptr = 0; 1742 *ptr = 0;
1740 } 1743 }
1741 else 1744 else
1742 {
1743 str = (char *)eina_strbuf_string_get(n->text); 1745 str = (char *)eina_strbuf_string_get(n->text);
1744 tbase = str; 1746
1745 } 1747 /* Keep beginning of string to calculate offsets later */
1746// printf("add: wrap: %i|%i, width: %i '%s'\n", fmt->wrap_word, fmt->wrap_char, c->w, str); 1748 tbase = str;
1749
1750 /*
1751 * Layout the string piece-by-piece
1752 */
1747 new_line = 0; 1753 new_line = 0;
1748 empty_item = 0; 1754 empty_item = 0;
1749 while (str) 1755 while (str)
1750 { 1756 {
1757 /* FIXME: next comment is probably obsolete */
1751 /* if this is the first line item and it starts with spaces - remove them */ 1758 /* if this is the first line item and it starts with spaces - remove them */
1752 wrap = 0; 1759 wrap = 0;
1753 white_stripped = 0; 1760 white_stripped = 0;
@@ -1764,21 +1771,42 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1764 str = str + twrap; 1771 str = str + twrap;
1765 } 1772 }
1766 */ 1773 */
1774 /*
1775 * Create new Textblock_Item for current part of string and format it
1776 * with current format
1777 *
1778 * FIXME: why not fmt is attached to Textblock_Node instead?
1779 */
1767 it = _layout_item_new(c, fmt, str); 1780 it = _layout_item_new(c, fmt, str);
1781
1782 /*
1783 * Fill Textblock_Item with data pointing back to Textblock_Node
1784 */
1768 it->source_node = n; 1785 it->source_node = n;
1769 it->source_pos = str - tbase; 1786 it->source_pos = str - tbase;
1787
1788 /* Get width/height of text being rasterized "as if there were no constraints" */
1770 tw = th = 0; 1789 tw = th = 0;
1771 if (fmt->font.font) 1790 if (fmt->font.font)
1772 c->ENFN->font_string_size_get(c->ENDT, fmt->font.font, it->text, &tw, &th); 1791 c->ENFN->font_string_size_get(c->ENDT, fmt->font.font, it->text, &tw, &th);
1792
1793 /*
1794 * Split text to fill the current line
1795 */
1773 if ((c->w >= 0) && 1796 if ((c->w >= 0) &&
1774 ((fmt->wrap_word) || (fmt->wrap_char)) && 1797 ((fmt->wrap_word) || (fmt->wrap_char)) &&
1775 ((c->x + tw) > 1798 ((c->x + tw) >
1776 (c->w - c->o->style_pad.l - c->o->style_pad.r - 1799 (c->w - c->o->style_pad.l - c->o->style_pad.r -
1777 c->marginl - c->marginr))) 1800 c->marginl - c->marginr)))
1778 { 1801 {
1802 /*
1803 * This branch: text needs to be wrapped, and does not fit single
1804 * line.
1805 */
1779 wrap = _layout_text_cutoff_get(c, fmt, it); 1806 wrap = _layout_text_cutoff_get(c, fmt, it);
1780 if (wrap == 0) 1807 if (wrap == 0)
1781 evas_common_font_utf8_get_next((unsigned char *)str, &wrap); 1808 evas_common_font_utf8_get_next((unsigned char *)str, &wrap);
1809
1782 if (wrap > 0) 1810 if (wrap > 0)
1783 { 1811 {
1784 if (fmt->wrap_word) 1812 if (fmt->wrap_word)
@@ -1921,6 +1949,7 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1921 new_line = 1; 1949 new_line = 1;
1922 } 1950 }
1923 } 1951 }
1952
1924 if (!empty_item) 1953 if (!empty_item)
1925 { 1954 {
1926 tw = th = 0; 1955 tw = th = 0;
@@ -1929,25 +1958,52 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1929 } 1958 }
1930 } 1959 }
1931 else 1960 else
1932 str = NULL; 1961 {
1933 if (empty_item) empty_item = 0; 1962 /*
1934 else 1963 * Either string is empty, or line wrapping was not requested or
1964 * string fits the line. Anyway, just process this line and break
1965 * out of loop.
1966 */
1967 str = NULL;
1968 }
1969
1970 /* Handle non-empty items */
1971 if (!empty_item)
1935 { 1972 {
1973 /*
1974 * Store width and height of Textblock_Item as got from
1975 * font_string_size_get
1976 */
1936 it->w = tw; 1977 it->w = tw;
1937 it->h = th; 1978 it->h = th;
1979
1980 /* Adjust for insets. Will be useful later while drawing characters */
1938 inset = 0; 1981 inset = 0;
1939 if (fmt->font.font) 1982 if (fmt->font.font)
1940 inset = c->ENFN->font_inset_get(c->ENDT, fmt->font.font, it->text); 1983 inset = c->ENFN->font_inset_get(c->ENDT, fmt->font.font, it->text);
1941 it->inset = inset; 1984 it->inset = inset;
1985
1986 /*
1987 * Store horizontal position of Textblock_Item and adjust c->x
1988 * according to data retrieved from font system.
1989 *
1990 * FIXME: why it->h might be != adv?
1991 */
1942 it->x = c->x; 1992 it->x = c->x;
1943 adv = 0; 1993 adv = 0;
1944 if (fmt->font.font) 1994 if (fmt->font.font)
1945 adv = c->ENFN->font_h_advance_get(c->ENDT, fmt->font.font, it->text); 1995 adv = c->ENFN->font_h_advance_get(c->ENDT, fmt->font.font, it->text);
1946 c->x += adv; 1996 c->x += adv;
1997
1998 /* Add the Textblock_Item to items in current line */
1947 c->ln->items = (Evas_Object_Textblock_Item *)eina_inlist_append(EINA_INLIST_GET(c->ln->items), EINA_INLIST_GET(it)); 1999 c->ln->items = (Evas_Object_Textblock_Item *)eina_inlist_append(EINA_INLIST_GET(c->ln->items), EINA_INLIST_GET(it));
1948 } 2000 }
2001 empty_item = 0;
2002
2003 /* Handle "newline requested" */
1949 if (new_line) 2004 if (new_line)
1950 { 2005 {
2006 /* Skip single (?) whitespace character from str */
1951 if (str) 2007 if (str)
1952 { 2008 {
1953 if (!white_stripped) 2009 if (!white_stripped)
@@ -1957,9 +2013,10 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
1957 if (_is_white(ch)) str += index; 2013 if (_is_white(ch)) str += index;
1958 } 2014 }
1959 } 2015 }
1960 new_line = 0; 2016 /* Format current line and advance to new one */
1961 _layout_line_advance(c, fmt); 2017 _layout_line_advance(c, fmt);
1962 } 2018 }
2019 new_line = 0;
1963 } 2020 }
1964} 2021}
1965 2022