[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / docs / content / programming-guide / markup-style.md
1 <!--
2 /**-->
3
4 # Mark-up Style {#markup-style}
5
6 Mark-up tags can be used within the text to set styles.
7
8 By default the text controls don't process the mark-up string. To enable the mark-up string processing the property *ENABLE_MARKUP* must be set to *true*.
9
10 ~~~{.cpp}
11 // C++
12
13 TextField field = TextField::New();
14 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
15
16 Stage::GetCurrent().Add( field );
17 ~~~
18
19 Note the mark-up processor doesn't check the correctness of the mark-up string. This may
20 cause the text to be badly rendered.
21
22 The table below describes the priorities when styles are applied while rendering text.
23 |  |  |  |  |
24 |--|--|--|--|
25 | Priority 1 | Style set by markup string. | Will override the style set through the control properties. | i.e The \<color\> tag will override the *TEXT_COLOR* property. |
26 | Priority 2 | Style set through the control properties. | Will override the default platform style. |  |
27 | Priority 3 | Default platform style. |  |  |
28
29 Font size has slightly different priorities - the size provided by the platform is a logical
30 size, and can be mapped to physical point sizes using style sheets. There is a default set of
31 sizes defined for DALi, and these can be overridden by application specific stylesheets. Thus
32 the priorities are:
33
34 |  |  |  |
35 |--|--|--|
36 | Priority 1 | Size set by markup string. | Will override the style set through the stylesheets. |
37 | Priority 2 | Physical Size set by application style sheet | |
38 | Priority 2 | Logical Size set by application style sheet | Mapping from platform logical to physical |
39 | Priority 3 | Logical Size set by DALi style sheet | Mapping from platform logical to physical |
40
41 See [Font Selection](@ref font-selection) for more details.
42
43 Current supported tags are:
44
45 ## \<color\>
46
47 Sets the color of the characters inside the tag. The *color* tag has a *value* attribute used to set the color. Possible values are: 'red', 'green', 'blue', 'yellow', 'magenta',
48  'cyan', 'white', 'black' and 'transparent'. Web color and 32 bits hexadecimal 0xAARRGGBB formats are also supported.
49
50 Examples below are equivalent, render the text in red. Second example codes the color in 0xAARRGGBB, third and fourth in web color with 3 and 6 characters.
51
52 ~~~{.cpp}
53 // C++
54 field.SetProperty( TextLabel::Property::TEXT, "<color value='red'>Red Text</color>" ); // Color coded with a text constant.
55 ~~~
56
57 ~~~{.cpp}
58 // C++
59 field.SetProperty( TextLabel::Property::TEXT, "<color value='0xFFFF0000'>Red Text</color>" ); // Color packed inside an ARGB hexadecimal value.
60 ~~~
61
62 ~~~{.cpp}
63 // C++
64 field.SetProperty( TextLabel::Property::TEXT, "<color value='#F00'>Red Text</color>" ); // Color packed with the web color format (3 characters).
65 ~~~
66
67 ~~~{.cpp}
68 // C++
69 field.SetProperty( TextLabel::Property::TEXT, "<color value='#FF0000'>Red Text</color>" ); // Color packed with the web color format (6 characters).
70 ~~~
71
72 ## \<font\>
73
74 Sets the font values of the characters inside the tag.
75
76 Supported attributes are:
77 - *family* The name of the font.
78 - *size* The size of the font in points.
79 - *weight* The weight of the font.
80 - *width* The width of the font
81 - *slant* The slant of the font.
82
83 See the [Font Selection](@ref font-selection) to have a view of the possible values for the *weight*, *width* and *slant* attributes.
84
85 ~~~{.cpp}
86 // C++
87 field.SetProperty( TextLabel::Property::TEXT, "<font family='SamsungSans' weight='bold'>Hello world</font>" );
88 ~~~
89
90 ## XHTML ENTITIES
91
92 Single characters can be embedded into text using character entity references. These references have a numeric value as well as a named value.
93 You can use either one of them.
94
95 XHTML ENTITIES Format:
96 - Named reference : "&entity_name;" (i.e. an ampersand, the entity name, and then a semi-colon).
97 - Numeric reference:
98 - a. Decimal reference : "&#decimal_code;" (i.e. an ampersand, a hash symbol (which signals that a number reference is coming), the character's number, and then a semi colon)
99 - b. Hex reference     : "&#xhex-code;" (i.e. an ampersand, a hash symbol (which signals that a number reference is coming), x which indicates the character's number is in hex, and then a semi colon)
100
101
102 ~~~{.cpp}
103 // C++
104 field.SetProperty( TextLabel::Property::TEXT, "Named Entity: &amp;  Numeric Entity: Decimal Entity: &#9827;  Hex Entity: &#x2660;" );
105 ~~~
106
107 ![ ](XHTML_entity.png)
108
109 ## SPECIAL CHARACTERS HANDLING IN MARKUP
110
111 Three special characters are supported :
112 - < : Less Than. It means beginning of tag.
113 - > : Greater Than. It means end of tag.
114 - & : Ampersand. It means beginning of XHTML Entity.
115
116 > "&" usage in markup style changed from Tizen 4.0.
117 "To display special character needs as regular, prepend it with two backslashes in the string."
118
119 Below are some examples
120
121 ~~~{.cpp}
122 // C++ ( Wrong usage to print text "Testing of < special character" )
123 field.SetProperty( TextLabel::Property::TEXT, "Testing of < special character" );
124 ~~~
125
126 ![ ](SpecialCharacter1.png)
127
128 ~~~{.cpp}
129 // C++ ( Wrong usage to print text "Testing of & special character" )
130 field.SetProperty( TextLabel::Property::TEXT, "Testing of & special character" );
131 ~~~
132
133 ![ ](SpecialCharacter1.png)
134
135 ~~~{.cpp}
136 // C++ ( Correct usage to print text "Testing of & < > special characters" )
137 field.SetProperty( TextLabel::Property::TEXT, "Testing of \\& \\< \\> special characters" );
138 ~~~
139
140 ![ ](SpecialCharacters.png)
141
142 */