Merge lp:~widelands-dev/widelands/fh1-documentation into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8606
Proposed branch: lp:~widelands-dev/widelands/fh1-documentation
Merge into: lp:widelands
Diff against target: 1414 lines (+698/-391)
6 files modified
data/scripting/messages.lua (+22/-0)
data/scripting/richtext.lua (+355/-226)
data/scripting/richtext_scenarios.lua (+14/-9)
doc/sphinx/extract_rst.py (+1/-0)
doc/sphinx/source/wlrichtext.rst (+60/-115)
src/graphic/text/rt_parse.cc (+246/-41)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fh1-documentation
Reviewer Review Type Date Requested Status
GunChleoc Needs Resubmitting
Review via email: mp+337545@code.launchpad.net

Commit message

Documented tag constraints for new font renderer and updated the main articles.

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

The send_to_all function change is from https://code.launchpad.net/~widelands-dev/widelands/fh1-maps-multiplayer/+merge/337506, so that branch needs to be merged first.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3168. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/340441956.
Appveyor build 2975. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fh1_documentation-2975.

Revision history for this message
kaputtnik (franku) wrote :

Took the freedom to adjust the RST parts. Mainly:

- make lists of allowed attributes a bulleted list (i think this was intended)
- fixed some args
- fixed indentation to have it consistent over the pages
- added the function definition of new_objectives() in richtext_scenarios.lua
- added some links in the text

For the allowed attributes it would be nice to have a description how to use them. Something like

Attributes have to be applied as a string in form of "attribute1=value1 attribute2=value2": E.g. font("color=ff0000 italic=1", text)

Don't know were to put such an example though.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3173. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/340643220.
Appveyor build 2980. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fh1_documentation-2980.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Hm, we now have the allowed attributes documented in 2 places. The reason that I documented them in the C++ code is to be close to the code, so that we won't forget to update the documentation when they change. We can pretty much guarantee that updating the documentation in richtext.lua will be forgotten eventually.

Revision history for this message
kaputtnik (franku) wrote :

I didn't add any documenation ;)

Double documentation is not good. What about having the richtext documentation in the cpp file and parse it like we have for src/scripting/lua_bases.cpp? -> https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/doc/sphinx/extract_rst.py#L18

The real problem is that we have two different document generators with different syntax: doxygen and sphinx. So making documentation for one of them means it does not work with the other one. I'ts also bad for devolpers, because they have to use two different syntaxes for the source code documentation. Sphinx is also capable to document c++ code, imho: http://www.sphinx-doc.org/en/stable/domains.html#id2 In the long term run there should only be one source code documentation generator, imho.

Revision history for this message
GunChleoc (gunchleoc) wrote :

But you did add some, in this commit: https://bazaar.launchpad.net/~widelands-dev/widelands/fh1-documentation/revision/8429

It would be better to link to the allowed attributes documentation in src/graphic/text/rt_parse.cc and not duplicate the documentation in the Lua file.

I also still need to rewrite the main Richtext document https://wl.widelands.org/docs/wl/wlrichtext/ and link everything together in a tree.

Revision history for this message
kaputtnik (franku) wrote :

> But you did add some

Ok, i correct my self: I did not add any documentation which were in two places:

> Hm, we now have the allowed attributes documented in 2 places.

The allowed attributes were already at 2 places in the documentation, before i edited the RST comments. My fault that i didn't mention this. But please don't make me feel guilty for things i haven't done :-)

Revision history for this message
GunChleoc (gunchleoc) wrote :

Sorry, I'm seeing it now, you just edited them. Duh.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have now rewritten the main article and added a table of contents to it. I have also hooked up the attributes documentation for 2 tags. Before I continue with those, what do you think?

I also think that I should reorganize the richtext.lua script so that we can divide the documentation into logical sections for easier reading.

Revision history for this message
kaputtnik (franku) wrote :

I think this is good now. For the first time it is confusing that we have functions and the '<>' tags when switching between the pages. It's unclear where one has landet after clicking the link to attributes. Maybe write it in another way?

Instead:
attributes (string) – the attributes for the img tag.

Something like:
attributes (string) – see the rt-tags documentation for the attributes #attributes is the link

Revision history for this message
GunChleoc (gunchleoc) wrote :

Should be done now. I have also reorganized the document into sections.

review: Needs Resubmitting
Revision history for this message
kaputtnik (franku) wrote :

Good work :-)

The grouping into headers is nice. A user can find the things he needs much better. There is one exception though: The rt tags documentation contain too much headers, imho. E.g for <rt> there are headers 'Attributes', 'Padding', 'Background Color' and 'Global Formatting Controls'. While the subheaders are a bit smaller it's nevertheless confusing. I think it would be better to have all attributes in one list. The attributes names are quite self explaining, imho. Same goes for the <div> tag. Just like it is for the <p> tag: One header 'Attributes' and a list of all attributes.

I miss an example how to use the attributes.

I am unsure about tags with no attributes or no subtags. I think we could omit the headers if there are no entries in it. A reader can imho understand if there is nothing documented, there are no attributes or subtags possible.

Added also two diff comments.

Revision history for this message
GunChleoc (gunchleoc) wrote :

All done.

For code examples, I just linked back to the main code example. Is this OK for now? Some of the attributes are still a bit WIP.

Revision history for this message
kaputtnik (franku) wrote :

I think this is better :-)

Maybe i have not explained enough about the code example for the attributes. The reason why i am so stubborn for a related code example is that it took me some time to fiddle out how to use them. E.g. it was unclear how to use values for an attribute.

I would suggest to change the code example in richtext.lua to something like:

-- h1(_[[Header]]) ..
-- p(_[[A Paragraph]]) ..
-- p(_[[A Paragraph with ]] .. font("color=ff0000", _[[red text ]]) .. _[[and ]] .. font("italic=1", _[[italic formatted text.]])) ..
-- and so on

No idea if this code will ever work :-D But hopefully it shows what kind of code example i miss. I could add such an example with a related image, if you don't want to do the additional work to create such an image. May i could test then also if i have understand all the things ;)

I have found some misspelling, will do a complete proof reading this weekend.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks!

Maybe it would indeed be best if you created the examples - I am too close to this, so you know better what is needed here.

Revision history for this message
kaputtnik (franku) wrote :

Changed the code example and the resulting image. I have tried also to explain in short what the '..' are used for. While a first reader may does not know what my explanation means exactly, one can search the web for the keyword.

Feel free to rephrase :-)

Revision history for this message
kaputtnik (franku) wrote :

Ah forgotten: Not directly related to this branch but a question about the translation makro '_' and the use of brackets for strings instead of double quotation marks:

Does the _ only work with '_[[some text]]' and not with _"some text"?

The doc for _ (https://wl.widelands.org/docs/wl/autogen_globals/#_) says _"some text" can also be used.

Why are then all strings in the campaign files enclosed with brackets? Is there a benefit of using [[ ]] in comparison with using ""?

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the image! I have also changed the code example in the main article to match. The red is a bit glaring, maybe we can have different color, just toned down a bit? I also fixed a spelling error in the text contained in the image, so it needs rerendering anyway.

It doesn't matter whether we use "" or [[]] in Lua. [[]] is for multiline strings that will ignore newlines, but using those would make for weird strings presented to translators. https://www.lua.org/manual/5.3/manual.html#3.1

Revision history for this message
kaputtnik (franku) wrote :

Thanks for explanation.

I have used now blue and white instead of red and completed the example. In r8443 i have changed both code examples accordingly. In r8444 i have removed the code example from wlrichtext and linked the example in richtext.lua. Feel free to revert this change, but one example is better for maintenance, imho.

Revision history for this message
kaputtnik (franku) wrote :

Did now some proof reading, see inline comments.

What i stumbled over is a mixed use of uppercase/lowercase after hyphen/colon. Eg. for the two text composition functions we have:

In join_sentence() its lowercase:
:arg sentence1: text of the first sentence

In localize lists its uppercase:
:arg items: An array of strings

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for proofreading :)

I'm not font of the blue either, can you please try something like 6699ff? The problem wasn't the hue, but the saturation.

Revision history for this message
kaputtnik (franku) wrote :

Done.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks a lot for your help! :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/scripting/messages.lua'
--- data/scripting/messages.lua 2017-12-09 06:29:26 +0000
+++ data/scripting/messages.lua 2018-02-24 15:32:03 +0000
@@ -33,6 +33,28 @@
33 player:send_message(title, body, parameters)33 player:send_message(title, body, parameters)
34end34end
3535
36
37-- RST
38-- .. function:: send_to_all(text[, heading])
39--
40-- Sends a game status message to all players.
41--
42-- :arg text: the localized body of the message. You can use rt functions here.
43-- :type text: :class:`string`
44-- :arg heading: the localized title of the message (optional)
45-- :type heading: :class:`string`
46--
47function send_to_all(text, heading)
48 for idx,plr in ipairs(game.players) do
49 if (heading ~= nil and heading ~= "") then
50 send_message(plr, _"Status", text, {popup=true, heading=heading})
51 else
52 send_message(plr, _"Status", text, {popup=true})
53 end
54 end
55end
56
57
36-- RST58-- RST
37-- .. function:: message_box(player, title, message, parameters)59-- .. function:: message_box(player, title, message, parameters)
38--60--
3961
=== modified file 'data/scripting/richtext.lua'
--- data/scripting/richtext.lua 2018-02-12 10:17:22 +0000
+++ data/scripting/richtext.lua 2018-02-24 15:32:03 +0000
@@ -1,60 +1,40 @@
1-- TODO(GunChleoc): Wrap all tags and document allowed attributes when we're done1-- TODO(GunChleoc): Wrap all tags and document allowed attributes when we're done
22
3-- RST3-- RST
4--
5-- .. _richtext.lua:
6--
4-- richtext.lua7-- richtext.lua
5-- ------------8-- ------------
6--9--
7-- Functions to simplify and unique text formatting in scenarios and help files.10-- Functions to simplify and unique text formatting in scenarios and help files.
8-- Most of these functions are simple wrapper functions that make working with11-- Most of these functions are simple wrapper functions that make working with the
9-- widelands rich text formatting system more bearable.12-- :ref:`widelands rich text formatting system <wlrichtext>` more bearable.
10-- Function names generally follow HTML names.13-- Function names generally follow HTML names.
14-- We strongly recommend that you make use of these functions rather than hacking
15-- the tags manually.
16-- If you're writing a scenario, you should also have a look at
17-- :ref:`richtext_scenarios.lua`.
18--
19-- - `Blocks and Positioning`_
20-- - `Headings and Paragraphs`_
21-- - `Text Formatting`_
22-- - `Lists`_
23-- - `Images`_
24-- - `Links`_
25-- - `Text Composition`_
26-- - `Code Example`_
1127
1228
13-- RST29-- RST
14-- .. function:: localize_list(items, listtype, former_textdomain)30-- Blocks and Positioning
15-- :noindex:31-- ^^^^^^^^^^^^^^^^^^^^^^
16--32--
17-- Turns an array of string items into a localized string list with33-- This section covers functions for structuring your text layout.
18-- appropriate concatenation.
19--
20-- e.g. localize_list({"foo", "bar", baz"}, "or", "widelands") will return
21-- _"foo, bar or baz"
22--
23-- :arg items: An array of strings
24-- :arg listtype: The type of concatenation to use.
25-- Legal values are "&", "and", "or", and ";"
26-- :arg former_textdomain: The textdomain to restore after running this function.
27-- :returns: The concatenated list string, using localized concatenation operators.
28--
29-- Same algorithm as in src/base/i18n
30function localize_list(items, listtype, former_textdomain)
31 set_textdomain("widelands")
32 local result = ""
33 for i, item in pairs(items) do
34 if (i == 1) then
35 result = item
36 elseif (i == #items) then
37 if (listtype == "&") then
38 result = _"%1$s & %2$s":bformat(result, item)
39 elseif (listtype == "or") then
40 result = _"%1$s or %2$s":bformat(result, item)
41 elseif (listtype == ",") then
42 result = _"%1$s, %2$s":bformat(result, item)
43 else
44 result = _"%1$s and %2$s":bformat(result, item)
45 end
46 else
47 result = _"%1$s, %2$s":bformat(result, item)
48 end
49 end
50 set_textdomain(former_textdomain)
51 return result
52end
5334
5435
55-- RST36-- RST
56-- .. function:: rt(text_or_attributes[, text = nil])37-- .. function:: rt(text_or_attributes[, text = nil])
57-- :noindex:
58--38--
59-- Wraps a block of text into Lua rich text.39-- Wraps a block of text into Lua rich text.
60-- Only call this once for the whole text that gets sent to the backend.40-- Only call this once for the whole text that gets sent to the backend.
@@ -62,14 +42,9 @@
62-- because the backend will take care of it.42-- because the backend will take care of it.
63-- So, only use this function if you wish to add some attributes to the tag.43-- So, only use this function if you wish to add some attributes to the tag.
64--44--
65-- Allowed attributes are:45-- :arg text_or_attributes: see the :ref:`rt tag's documentation <rt_tags_rt>`
66-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document46-- for a list of attributes and their descriptions.
67-- background: a background color or image47-- :type text_or_attributes: :class:`string`
68-- debug: add visual debug information and debug log
69-- editor_mode: allow multiple blank spaces for editing
70--
71-- :arg attributes: the attributes for the rt tag.
72-- :type attributes: :class:`string`
73-- :arg text: the text to be enclosed in rich text tags.48-- :arg text: the text to be enclosed in rich text tags.
74-- :type text: :class:`string`49-- :type text: :class:`string`
75-- :returns: the wrapped rich text.50-- :returns: the wrapped rich text.
@@ -84,31 +59,72 @@
8459
8560
86-- RST61-- RST
87-- .. function:: img(src[, attributes = nil])62-- .. function:: div(text_or_attributes[, text = nil])
88-- :noindex:63--
89--64-- Wraps a block of text into a div tag.
90-- Turns an image src path into an image tag for richtext.65--
91--66-- :arg text_or_attributes: see the :ref:`div tag's documentation <rt_tags_div>`
92-- :arg src: the file path to the image.67-- for a list of attributes and their descriptions.
93-- :type src: :class:`string`68-- :type test_or_attributes: :class:`string`
94-- :arg attributes: the attributes for the div tag.69--
95-- :type attributes: :class:`string`70-- :arg text: the text to be enclosed in div tags.
96--71-- :type text: :class:`string`
97-- Allowed attributes are:72-- :returns: the text wrapped in a div tag.
98-- color: a hex color to be applied to the image's player color mask, if it has any
99-- ref: TODO(GunChleoc): I have no idea what it does.
100--
101-- :returns: the img tag.
10273
103function img(src, attributes)74function div(text_or_attributes, text)
104 if attributes then75 if text then
105 return "<img src=" .. src .." " .. attributes .. ">"76 return ("<div %s>"):format(text_or_attributes) .. text .. "</div>"
106 else77 else
107 return "<img src=" .. src .. ">"78 return ("<div>") .. text_or_attributes .. "</div>"
108 end79 end
109end80end
11081
11182
83-- RST
84-- .. function:: space(gap)
85--
86-- Adds a horizontal space
87--
88-- :arg gap: the size of the space as pixels.
89--
90-- :returns: a space tag
91
92function space(gap)
93 return "<space gap="..gap..">"
94end
95
96
97-- RST
98-- .. function:: vspace(gap)
99--
100-- Adds a vertical space
101--
102-- :arg gap: the size of the space as pixels.
103--
104-- :returns: a vspace tag
105
106function vspace(gap)
107 return "<vspace gap="..gap..">"
108end
109
110
111-- RST
112-- :ref:`Return to index<richtext.lua>`
113--
114-- Headings and Paragraphs
115-- ^^^^^^^^^^^^^^^^^^^^^^^
116--
117-- This section covers functions for defining headings and paragraphs.
118
119
120-- RST
121-- .. function:: title(font_face, text)
122--
123-- Returns a paragraph formatted as a title heading. Use this on the top of
124-- your document only.
125--
126-- :returns: A paragraph with text formatted as title.
127
112function title(font_face, text)128function title(font_face, text)
113 return p_font("align=center", "size=38 face=".. font_face .. " color=2F9131", text)129 return p_font("align=center", "size=38 face=".. font_face .. " color=2F9131", text)
114end130end
@@ -116,12 +132,11 @@
116132
117-- RST133-- RST
118-- .. function:: h1(text_or_color[, text = nil])134-- .. function:: h1(text_or_color[, text = nil])
119-- :noindex:
120--135--
121-- Returns a paragraph formatted as a big heading with a small gap after it.136-- Returns a paragraph formatted as a big heading with a small gap after it.
122-- The mnemonic comes from HTML.
123--137--
124-- :returns: A paragraph with text formatted as heading.138-- :returns: A paragraph with text formatted as heading.
139
125function h1(text_or_color, text)140function h1(text_or_color, text)
126 if text then141 if text then
127 return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(12) .. text .. vspace(1))142 return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(12) .. text .. vspace(1))
@@ -130,20 +145,21 @@
130 end145 end
131end146end
132147
148
133-- RST149-- RST
134-- .. function:: h2(text)150-- .. function:: h2(text)
135-- :noindex:
136--151--
137-- Like :func:`h1` but smaller.152-- Like :func:`h1` but smaller.
138--153--
139-- :returns: A paragraph with text formatted as heading.154-- :returns: A paragraph with text formatted as heading.
155
140function h2(text)156function h2(text)
141 return p_font("", "size=14 bold=1 color=D1D1D1", vspace(12) .. text .. vspace(1))157 return p_font("", "size=14 bold=1 color=D1D1D1", vspace(12) .. text .. vspace(1))
142end158end
143159
160
144-- RST161-- RST
145-- .. function:: h3(text)162-- .. function:: h3(text)
146-- :noindex:
147--163--
148-- Like :func:`h2` but smaller.164-- Like :func:`h2` but smaller.
149--165--
@@ -153,9 +169,9 @@
153 return p_font("", "size=13 color=D1D1D1", vspace(6) .. text .. vspace(1))169 return p_font("", "size=13 color=D1D1D1", vspace(6) .. text .. vspace(1))
154end170end
155171
172
156-- RST173-- RST
157-- .. function:: h4(text)174-- .. function:: h4(text)
158-- :noindex:
159--175--
160-- Like :func:`h3` but smaller.176-- Like :func:`h3` but smaller.
161--177--
@@ -165,16 +181,36 @@
165 return p_font("", "size=12 italic=1 color=D1D1D1", text)181 return p_font("", "size=12 italic=1 color=D1D1D1", text)
166end182end
167183
184
185-- RST
186-- .. function:: inline_header(header, text)
187--
188-- Creates a line of h3 formatted text followed by normal paragraph text.
189--
190-- :arg header: text in h3 format.
191-- :arg text: text in p format.
192-- :returns: header text followed by normal text.
193
194function inline_header(header, text)
195 return
196 div("width=100%", vspace(8)) ..
197 div("width=100%", font("size=13 color=D1D1D1", header .. " ") ..
198 font("size=12", text))
199end
200
201
168-- RST202-- RST
169-- .. function:: p(text_or_attributes[, text = nil])203-- .. function:: p(text_or_attributes[, text = nil])
170-- :noindex:
171--204--
172-- Returns one paragraph with text followed by a small vertical gap. Options205-- Returns one paragraph with text followed by a small vertical gap. Options
173-- can be given as first argument similar to :func:`rt`.206-- can be given as first argument similar to :func:`rt`.
174--207--
175-- Allowed attributes are documented in the open_p function.208-- :arg text_or_attributes: see the :ref:`p tag's documentation <rt_tags_p>`
209-- for a list of attributes and their descriptions.
210-- :type text_or_attributes: :class:`string`
176--211--
177-- :returns: The text wrapped in <p>%s</p>212-- :returns: The text wrapped in <p>%s</p>
213
178function p(text_or_attributes, text)214function p(text_or_attributes, text)
179 if text then215 if text then
180 return open_p(text_or_attributes) .. text .. close_p()216 return open_p(text_or_attributes) .. text .. close_p()
@@ -185,38 +221,17 @@
185221
186222
187-- RST223-- RST
188-- .. function:: p_font(text_or_attributes[, text = nil])
189--
190-- Returns one paragraph with text followed by a small vertical gap. Options
191-- can be given as first argument similar to :func:`rt`.
192--
193-- Allowed p attributes are documented in the open_p function.
194--
195-- Allowed font attributes are are documented in the font function.
196--
197-- :returns: The text wrapped in <p attributes><font attributes>text</font></p>
198function p_font(p_or_font_or_attributes, text_or_font_attributes, text)
199 if text then
200 return ("<p %s>"):format(p_or_font_or_attributes) .. "<font " .. text_or_font_attributes .. ">" .. text .. close_p()
201 else
202 return "<p><font " .. p_or_font_or_attributes .. ">" .. text_or_font_attributes .. close_p()
203 end
204end
205
206
207-- RST
208-- .. function:: open_p([attributes = nil])224-- .. function:: open_p([attributes = nil])
209--225--
210-- Returns a paragraph open tag and default font size. Options226-- Returns a paragraph open tag and default font size. Options
211-- can be given as first argument similar to :func:`rt`.227-- can be given as first argument similar to :func:`rt`.
212--228--
213-- Allowed attributes are:229-- :arg attributes: see the :ref:`p tag's documentation <rt_tags_p>`
214-- indent: indents the first line of the paragraph230-- for a list of attributes and their descriptions.
215-- align: horizontal alignment (left, center, right)231-- :type attributes: :class:`string`
216-- valign: vertical alignment (top, middle, bottom)
217-- spacing: line spacing in pixels
218--232--
219-- :returns: <p> with added attributes and default font233-- :returns: <p> with added attributes and default font
234
220function open_p(attributes)235function open_p(attributes)
221 if attributes then236 if attributes then
222 return ("<p %s>"):format(attributes) .. "<font size=12>"237 return ("<p %s>"):format(attributes) .. "<font size=12>"
@@ -232,24 +247,55 @@
232-- Closes a paragraph.247-- Closes a paragraph.
233--248--
234-- :returns: The closing tags for a paragraph249-- :returns: The closing tags for a paragraph
250
235function close_p(t)251function close_p(t)
236 return vspace(6) .. "</font>" .. vspace(6) .. "</p>"252 return vspace(6) .. "</font>" .. vspace(6) .. "</p>"
237end253end
238254
255
256-- RST
257-- .. function:: p_font(p_or_font_attributes, text_or_font_attributes[, text = nil])
258--
259-- Returns one paragraph with text followed by a small vertical gap. Options
260-- can be given as first argument similar to :func:`rt`.
261--
262-- :arg p_or_font_attributes: Optional paragraph or font attributes.
263-- :type p_or_font_attributes: :class:`string`
264--
265-- :arg text_or_font_attributes: Optional font attributes or the text itself.
266-- :type text_or_font_attributes: :class:`string`
267--
268-- See the :ref:`p tag's documentation <rt_tags_p>` for a list of paragraph
269-- attributes and the :ref:`font tag's documentation <rt_tags_font>` for a
270-- list of font attributes.
271--
272-- :returns: The text wrapped in <p attributes><font attributes>text</font></p>
273
274function p_font(p_or_font_attributes, text_or_font_attributes, text)
275 if text then
276 return ("<p %s>"):format(p_or_font_attributes) .. "<font " .. text_or_font_attributes .. ">" .. text .. close_p()
277 else
278 return "<p><font " .. p_or_font_attributes .. ">" .. text_or_font_attributes .. close_p()
279 end
280end
281
282-- RST
283-- :ref:`Return to index<richtext.lua>`
284--
285-- Text Formatting
286-- ^^^^^^^^^^^^^^^
287--
288-- This section covers convenience functions for text formatting.
289
290
239-- RST291-- RST
240-- .. function:: font(attributes, text)292-- .. function:: font(attributes, text)
241--293--
242-- Wraps the text in font tags.294-- Wraps the text in font tags. See also :any:`p_font`.
243--295--
244-- Allowed attributes are:296-- :arg attributes: see the :ref:`font tag's documentation <rt_tags_font>`
245-- size: the font size in pt297-- for a list of attributes and their descriptions.
246-- face: sans, serif or condensed298-- :type attributes: :class:`string`
247-- color: a hex color
248-- bold: if you add bold=1, the text will be bold
249-- italic: if you add italic=1, the text will be italic
250-- underline: if you add underline=1, the text will be underlined
251-- shadow: if you add shadow=1, the text will have a shadow
252-- ref: TODO(GunChleoc): I don't know what this does.
253--299--
254-- :returns: The text wrapped in font tags with the given attributes300-- :returns: The text wrapped in font tags with the given attributes
255301
@@ -257,35 +303,61 @@
257 return ("<font %s>"):format(attributes) .. text .. "</font>"303 return ("<font %s>"):format(attributes) .. text .. "</font>"
258end304end
259305
260-- RST306
261-- .. function:: space(gap)307-- RST
262--308-- .. function:: b(text)
263-- Adds a horizontal space309--
264-- :arg gap: the size of the space as pixels.310-- This makes the text bold.
265--311--
266-- :returns: a space tag312-- :arg text: the text to format
267313--
268function space(gap)314-- :returns: a font tag containing the bold text
269 return "<space gap="..gap..">"315
270end316function b(text)
271317 return font("bold=1", text)
272-- RST318end
273-- .. function:: vspace(gap)319
274--320-- RST
275-- Adds a vertical space321-- .. function:: i(text)
276-- :arg gap: the size of the space as pixels.322--
277--323-- This makes the text italic.
278-- :returns: a vspace tag324--
279325-- :arg text: the text to format
280function vspace(gap)326--
281 return "<vspace gap="..gap..">"327-- :returns: a font tag containing the italic text
282end328
329function i(text)
330 return font("italic=1", text)
331end
332
333-- RST
334-- .. function:: u(text)
335--
336-- This underlines the text.
337--
338-- :arg text: the text to format
339--
340-- :returns: a font tag containing the underlined text
341
342function u(text)
343 return font("underline=1", text)
344end
345
346
347-- RST
348-- :ref:`Return to index<richtext.lua>`
349--
350-- Lists
351-- ^^^^^
352--
353-- This section covers functions for defining lists.
354
283355
284-- RST356-- RST
285-- .. function:: dl(dt, dd)357-- .. function:: dl(dt, dd)
286-- :noindex:358--
287--359-- This function imitates a HTML description list
288-- This function imitates a HTML description list360--
289-- :arg dt: "description term", will be rendered in bold.361-- :arg dt: "description term", will be rendered in bold.
290-- :arg dd: "description data", will be rendered normally.362-- :arg dd: "description data", will be rendered normally.
291--363--
@@ -295,13 +367,14 @@
295 return p(b(dt) .. " " .. dd)367 return p(b(dt) .. " " .. dd)
296end368end
297369
370
298-- RST371-- RST
299-- .. function:: li(text_or_symbol[, text = nil])372-- .. function:: li(text_or_symbol[, text = nil])
300--373--
301-- Adds the symbol in front of the text to create a list item and374-- Adds the symbol in front of the text to create a list item and
302-- wraps it in a paragraph375-- wraps it in a paragraph
303--376--
304-- :arg symbol: the item symbol for the list, e.g. "•" or "→"377-- :arg symbol: the item symbol for the list, e.g. "•" or "→". "•" is the default.
305-- :arg text: the text of the list item378-- :arg text: the text of the list item
306--379--
307-- :returns: a p tag containing the formatted text380-- :returns: a p tag containing the formatted text
@@ -314,6 +387,7 @@
314 end387 end
315end388end
316389
390
317-- RST391-- RST
318-- .. function:: li_arrow(text)392-- .. function:: li_arrow(text)
319--393--
@@ -322,19 +396,23 @@
322-- :arg text: the text of the list item396-- :arg text: the text of the list item
323--397--
324-- :returns: li("→", text)398-- :returns: li("→", text)
399
325function li_arrow(text)400function li_arrow(text)
326 -- TODO(GunChleoc): Reverse arrow for rtl languages.401 -- TODO(GunChleoc): Reverse arrow for rtl languages.
327 return li("→", text)402 return li("→", text)
328end403end
329404
405
330-- RST406-- RST
331-- .. function li_image(imagepath, text)407-- .. function:: li_image(imagepath, text)
332--408--
333-- Places a paragraph of text to the right of an image409-- Places a paragraph of text to the right of an image
334410--
335-- :arg imagepath: the full path to the image file411-- :arg imagepath: the full path to the image file
336-- :arg text_width_percent: the percentatge of space that the text will occupy412-- :type imagepath: :class:`string`
413--
337-- :arg text: the text to be placed next to the image414-- :arg text: the text to be placed next to the image
415-- :type text: :class:`string`
338--416--
339-- :returns: the text wrapped in a paragraph and placed next to the image, the outer tag is a div.417-- :returns: the text wrapped in a paragraph and placed next to the image, the outer tag is a div.
340418
@@ -347,11 +425,52 @@
347 )425 )
348end426end
349427
428
429-- RST
430-- :ref:`Return to index<richtext.lua>`
431--
432-- Images
433-- ^^^^^^
434--
435-- This section covers functions for including images.
436
437
438-- RST
439-- .. function:: img(src[, attributes = nil])
440--
441-- Turns an image src path into an image tag for richtext. See also :any:`li_image`.
442--
443-- :arg src: the file path to the image.
444-- :type src: :class:`string`
445-- :arg attributes: see the :ref:`img tag's documentation <rt_tags_img>`
446-- for a list of attributes and their descriptions.
447-- :type attributes: :class:`string`
448--
449-- :returns: the img tag.
450
451function img(src, attributes)
452 if attributes then
453 return "<img src=" .. src .." " .. attributes .. ">"
454 else
455 return "<img src=" .. src .. ">"
456 end
457end
458
459
460-- RST
461-- :ref:`Return to index<richtext.lua>`
462--
463-- Links
464-- ^^^^^
465--
466-- This section covers functions for including links. We can't do real links yet,
467-- so we only highlight the text for now.
468
350-- RST469-- RST
351-- .. function:: a(link)470-- .. function:: a(link)
352-- :noindex:471--
353--472-- This function imitates a HTML link. We can't do real links yet, so the text just gets underlines.
354-- This function imitates a HTML link. We can't do real links yet, so the text just gets underlines.473--
355-- :arg link: the text to format474-- :arg link: the text to format
356--475--
357-- :returns: a font tag containing the underlined text476-- :returns: a font tag containing the underlined text
@@ -361,87 +480,14 @@
361end480end
362481
363-- RST482-- RST
364-- .. function:: b(link)483-- :ref:`Return to index<richtext.lua>`
365-- :noindex:484--
366--485-- Text Composition
367-- This makes the text bold.486-- ^^^^^^^^^^^^^^^^
368-- :arg link: the text to format487--
369--488-- This section covers functions for text composition that help with proper markup
370-- :returns: a font tag containing the bold text489-- to make the text translatable.
371490
372function b(text)
373 return font("bold=1", text)
374end
375
376-- RST
377-- .. function:: i(link)
378-- :noindex:
379--
380-- This makes the text italic.
381-- :arg link: the text to format
382--
383-- :returns: a font tag containing the italic text
384
385function i(text)
386 return font("italic=1", text)
387end
388
389-- RST
390-- .. function:: u(link)
391--
392-- This underlines the text.
393-- :arg link: the text to format
394--
395-- :returns: a font tag containing the underlined text
396
397function u(text)
398 return font("underline=1", text)
399end
400
401-- RST
402-- .. function:: div(text_or_attributes[, text = nil])
403--
404-- Wraps a block of text into a div tag.
405--
406-- :arg attributes: the attributes for the div tag.
407-- :type attributes: :class:`string`
408--
409-- Allowed attributes are:
410-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document
411-- margin: TODO(GunChleoc): Document
412-- float: TODO(GunChleoc): this does not work yet
413-- margin: inner margin for the div
414-- valign: vertical alignment
415-- background: a background color or image
416-- width: the width of the div in pixels or percent
417--
418-- :arg text: the text to be enclosed in div tags.
419-- :type text: :class:`string`
420-- :returns: the text wrapped in a div tag.
421
422function div(text_or_attributes, text)
423 if text then
424 return ("<div %s>"):format(text_or_attributes) .. text .. "</div>"
425 else
426 return ("<div>") .. text_or_attributes .. "</div>"
427 end
428end
429
430-- RST
431-- .. function:: inline_header(t1, t2)
432--
433-- Creates a line of h3 formatted text followed by normal paragraph text.
434--
435-- :arg t1: text in h3 format.
436-- :arg t2: text in p format.
437-- :returns: header text followed by normal text.
438
439function inline_header(header, text)
440 return
441 div("width=100%", vspace(8)) ..
442 div("width=100%", font("size=13 color=D1D1D1", header .. " ") ..
443 font("size=12", text))
444end
445491
446-- RST492-- RST
447-- .. function:: join_sentences(sentence1, sentence2)493-- .. function:: join_sentences(sentence1, sentence2)
@@ -452,9 +498,92 @@
452-- :arg sentence1: text of the first sentence498-- :arg sentence1: text of the first sentence
453-- :arg sentence2: text of the second sentence499-- :arg sentence2: text of the second sentence
454-- :returns: two concatenated sentences with a localized sentence joiner.500-- :returns: two concatenated sentences with a localized sentence joiner.
455--501
456function join_sentences(sentence1, sentence2)502function join_sentences(sentence1, sentence2)
457 -- TRANSLATORS: Put 2 sentences one after the other.503 -- TRANSLATORS: Put 2 sentences one after the other.
458 -- TRANSLATORS: Languages using Chinese script probably want to lose the blank space here.504 -- TRANSLATORS: Languages using Chinese script probably want to lose the blank space here.
459 return pgettext("sentence_separator", "%s %s"):bformat(sentence1, sentence2)505 return pgettext("sentence_separator", "%s %s"):bformat(sentence1, sentence2)
460end506end
507
508
509-- RST
510-- .. function:: localize_list(items, listtype, former_textdomain)
511--
512-- Turns an array of string items into a localized string list with
513-- appropriate concatenation.
514--
515-- e.g. localize_list({"foo", "bar", "baz"}, "or", "widelands") will return
516-- _"foo, bar or baz"
517--
518-- :arg items: An array of strings
519-- :arg listtype: The type of concatenation to use.
520-- Legal values are "&", "and", "or", and ";"
521-- :arg former_textdomain: The textdomain to restore after running this function.
522-- :returns: The concatenated list string, using localized concatenation operators.
523--
524-- Same algorithm as in src/base/i18n
525
526function localize_list(items, listtype, former_textdomain)
527 set_textdomain("widelands")
528 local result = ""
529 for i, item in pairs(items) do
530 if (i == 1) then
531 result = item
532 elseif (i == #items) then
533 if (listtype == "&") then
534 result = _"%1$s & %2$s":bformat(result, item)
535 elseif (listtype == "or") then
536 result = _"%1$s or %2$s":bformat(result, item)
537 elseif (listtype == ",") then
538 result = _"%1$s, %2$s":bformat(result, item)
539 else
540 result = _"%1$s and %2$s":bformat(result, item)
541 end
542 else
543 result = _"%1$s, %2$s":bformat(result, item)
544 end
545 end
546 set_textdomain(former_textdomain)
547 return result
548end
549
550
551-- RST
552-- :ref:`Return to index<richtext.lua>`
553--
554-- .. _lua_formatting_example:
555--
556-- Code Example
557-- ^^^^^^^^^^^^
558-- Here's an example on how these functions and their attributes can be used. The double dot
559-- (``..``) is the LUA string concatenation operator. Note that this example
560-- also includes translation markup (the ``_[[Some text]]`` or ``_"Some text"`` function):
561--
562-- .. code-block:: lua
563--
564-- include "scripting/richtext.lua"
565--
566-- title = "Text Formatting",
567-- body = h1(_[[Normal header]]) ..
568-- h1("6699ff", _[[Colored header]]) ..
569-- p(_[[Normal paragraph, just with a bit more text to show how it looks like.]]) ..
570-- p("align=center", _[[A centered paragraph, just with a bit more text to show how it looks like.]]) ..
571-- li_image("images/wui/menus/menu_toggle_menu.png", _[[An image with right aligned text. This is just text to show automatic line breaks and behavior in regard with images]]) ..
572-- li(_[[A list item]]) ..
573-- li(font("color=6699ff bold=1", _[[Blue and bold]])) ..
574-- li_arrow(_[[A list item with an arrow]]) ..
575-- p(_[[A more complicated paragraph with ]] ..
576-- font("color=ffffff", _[[white text ]]) ..
577-- _[[and ]] ..
578-- font("italic=1 bold=1", _[[bold italic formatted text.]])
579-- ),
580--
581--
582-- This results in the following for a campaign message box:
583--
584-- .. image:: images/wlrichtext.png
585-- :scale: 100
586-- :alt: sample rendering
587-- :align: center
588--
589-- :ref:`Return to index<richtext.lua>`
461590
=== modified file 'data/scripting/richtext_scenarios.lua'
--- data/scripting/richtext_scenarios.lua 2018-01-04 13:45:46 +0000
+++ data/scripting/richtext_scenarios.lua 2018-02-24 15:32:03 +0000
@@ -1,12 +1,14 @@
1include "scripting/richtext.lua"1include "scripting/richtext.lua"
22
3-- RST3-- RST
4-- .. _richtext_scenarios.lua:
5--
4-- richtext_scenarios.lua6-- richtext_scenarios.lua
5-- ----------------------7-- ----------------------
6--8--
7-- Function to simplify and unique text formatting in scenarios. Most of these9-- Functions to simplify text formatting in scenarios and make it consistent.
8-- functions are simple wrapper functions that make working with widelands rich10-- Most of these functions are simple wrapper functions for our :ref:`richtext system <wlrichtext>`.
9-- text formatting system more bearable.11-- This file will include :ref:`richtext.lua` for you for additional formatting functions.
1012
11-- RST13-- RST
12-- .. function:: speech(img, clr, title, text)14-- .. function:: speech(img, clr, title, text)
@@ -36,6 +38,7 @@
36 return title .. li_image(img, p(text))38 return title .. li_image(img, p(text))
37end39end
3840
41
39-- RST42-- RST
40-- .. function:: paragraphdivider()43-- .. function:: paragraphdivider()
41--44--
@@ -49,7 +52,6 @@
49end52end
5053
5154
52
53-- RST55-- RST
54-- .. function:: objective_text(heading, body)56-- .. function:: objective_text(heading, body)
55--57--
@@ -64,13 +66,16 @@
6466
6567
66-- RST68-- RST
67-- Append an objective text with a header to a dialog box in a nice fashion.69-- .. function:: new_objectives(...)
68-- For displaying objectives with an extra title when an advisor is talking70--
71-- Append an objective text with a header to a dialog box in a nice fashion.
72-- For displaying objectives with an extra title when an advisor is talking
69--73--
70-- Provides nice formatting for objective texts.74-- Provides nice formatting for objective texts.
71-- the following arguments will be parsed:75-- The following arguments will be parsed:
72-- number: the number of objectives described in the body76--
73-- body: the objective text, e.g. created with function objective_text(heading, body)77-- - number: the number of objectives described in the body
78-- - body: the objective text, e.g. created with function objective_text(heading, body)
74--79--
75-- :returns: a rich text object that contains the formatted80-- :returns: a rich text object that contains the formatted
76-- objective text & title.81-- objective text & title.
7782
=== modified file 'doc/sphinx/extract_rst.py'
--- doc/sphinx/extract_rst.py 2017-11-05 09:30:44 +0000
+++ doc/sphinx/extract_rst.py 2018-02-24 15:32:03 +0000
@@ -14,6 +14,7 @@
14# Meaning: (src_file, file_name_to_generate_rst)14# Meaning: (src_file, file_name_to_generate_rst)
15cpp_pairs = (15cpp_pairs = (
16 ('src/ai/ai_hints.cc', 'autogen_ai_hints.rst'),16 ('src/ai/ai_hints.cc', 'autogen_ai_hints.rst'),
17 ('src/graphic/text/rt_parse.cc', 'autogen_rt_tags.rst'),
17 ('src/scripting/lua_root.cc', 'autogen_wl.rst'),18 ('src/scripting/lua_root.cc', 'autogen_wl.rst'),
18 ('src/scripting/lua_bases.cc', 'autogen_wl_bases.rst'),19 ('src/scripting/lua_bases.cc', 'autogen_wl_bases.rst'),
19 ('src/scripting/lua_editor.cc', 'autogen_wl_editor.rst'),20 ('src/scripting/lua_editor.cc', 'autogen_wl_editor.rst'),
2021
=== renamed file 'doc/sphinx/source/images/fancymsg.png' => 'doc/sphinx/source/images/wlrichtext.png'
21Binary files doc/sphinx/source/images/fancymsg.png 2012-06-20 09:07:10 +0000 and doc/sphinx/source/images/wlrichtext.png 2018-02-24 15:32:03 +0000 differ22Binary files doc/sphinx/source/images/fancymsg.png 2012-06-20 09:07:10 +0000 and doc/sphinx/source/images/wlrichtext.png 2018-02-24 15:32:03 +0000 differ
=== modified file 'doc/sphinx/source/wlrichtext.rst'
--- doc/sphinx/source/wlrichtext.rst 2016-01-28 05:24:34 +0000
+++ doc/sphinx/source/wlrichtext.rst 2018-02-24 15:32:03 +0000
@@ -1,126 +1,71 @@
1.. _wlrichtext:
2
1The Widelands Rich Text System3The Widelands Rich Text System
2==============================4==============================
35
4All texts that can be displayed to the user can be formatted to be layouted6All texts that can be displayed to the user can be marked up to be laid out
5and nicely formatted. This allows for changing of font sizes, weights, colors7and nicely formatted. This allows for changing of font sizes, weights, colors
6and for the embedding of images. This documents how to format a string to be8and for the embedding of images. This documents how to format a string to be
7recognized as rich text and which attributes are understood.9recognized as rich text and which attributes are understood.
810
9The Widelands rich text language is inspired by HTML and therefore uses a11The Widelands rich text language is inspired by HTML and therefore uses a
10syntax very similar to it. A rich text is started with ``<rt>`` and ended with12syntax very similar to it. To tell our rendering system to go into richtext mode,
11``</rt>``. A rich text can have an image associated with it, this image is13start your text with ``<rt>`` and end it with ``</rt>``.
12then displayed next to the text.14
1315.. toctree::
14Inside the rich text, each paragraph is enclosed by ``<p>`` and ``</p>``. You16 :maxdepth: 2
15give font attributes to this tag to change the appearance of the text17
16displayed inside.18 General Markup Functions <autogen_auxiliary_richtext.rst>
1719 Scenario Markup Functions <autogen_auxiliary_richtext_scenarios.rst>
18Reference20 Richtext Tags, their Attributes and Restrictions <autogen_rt_tags.rst>
19---------21
2022
21``<rt>``23Code Example
22^^^^^^^^24------------
2325
24Starts or ends a rich text. Must be the first tag to appear in the string.26Here is a simplified version of a fancy message displayed to the user:
25A full example would be::
26
27 <rt image=map:khanktrukh.png><p line-spacing=3 font-size=12>Hello<br>World</p></rt>
28
29This would instruct widelands to use the image of Khankruth that comes with
30the map, left align it. To the right of it there would be two lines of text.
31The first line being ``Hello`` and the second being ``World``. They would be
32displayed with a font-size of 12 points and a line-spacing of 3 points.
33
34Valid attributes for ``<rt>`` are:
35
36image
37 The name of a image to use, can be prefixed with ``map:`` which instructs
38 widelands to load the image from the ``pics/`` directory inside the map of
39 this scenario.
40
41image-align
42 ``right``, ``center`` or ``left``. Defines were the image is displayed.
43
44text-align
45 ``right``, ``center`` or ``left``. Defines were the text is displayed.
46
47
48``<p>``
49^^^^^^^^
50
51A text paragraph inside a rich text. This gives control over which font is
52used for rendering and how it should be formatted.
53
54Valid attributes for ``<p>`` are:
55
56font-size
57 The font size to use in points. 10 points is the default. Use 12 points for
58 mission texts.
59
60font-face
61 Font face style of the font to use. The valid fonts are ``sans``, ``serif``,
62 and ``condensed``.
63
64font-color
65 The color of this font as a RGB hex tuple. That means 000000 is completely
66 black while ff0000 is completely red. Default color is a bright yellow
67 (ffff00).
68
69font-weight
70 ``normal`` or ``bold``. Note that not everything is supported by all fonts.
71 Do not use with ``font-style=italic`` at the same time; double formatting is
72 typographically bad.
73
74font-style
75 ``normal`` or ``italic``. Note that not everything is supported by all fonts.
76 Do not use with ``font-weight=bold`` at the same time; double formatting is
77 typographically bad.
78
79font-decoration
80 ``normal`` or ``underline``. Note that not everything is supported by all fonts.
81 Do not use with ``font-weight=bold`` or ``font-style=italic`` at the same time;
82 double formatting is typographically bad.
83
84line-spacing
85 Line spacing in points. Default is 0.
86
87``<br>``
88^^^^^^^^
89
90This inserts a line break into the text. The line break character (``\n``) is
91ignored inside a rich text.
92
93Real world Lua example
94----------------------
95
96Here is a small example of a fancy message send to the user via the
97:meth:`wl.game.Player.send_message` method:
9827
99.. code-block:: lua28.. code-block:: lua
10029
101 wl.Game().players[1]:send_message(30 body =
102 "Hi",31 "<rt> -- This is richtext
103 "<rt image=images/logos/wl-ico-128.png image-align=center></rt>" ..32 <p> -- Start a paragraph
104 "<rt text-align=center>" ..33 <font size=18 bold=1 color=D1D1D1> -- Set font size and color
105 "<p font-weight=bold font-decoration=underline font-style=italic font-size=24>" ..34 Big font to create a header
106 "YOU so rock dude!" ..35 </font>
107 "</p></rt>" ..36 </p>
108 "<rt><p>No. I really mean this.<br><br>Seriously.</p></rt>",37 <p>
109 { popup = true }38 <font size=12>
110 )39 Normal paragraph, just with a bit more text to show how it looks like.
11140 </font>
112The title of the message mustn't be a rich text, the body (which is just one41 </p>
113string, it has been separated for easier reading and concatenated Lua-style42 -- The following content should be spread across a full line
114via the ``..`` operator) is one: the first rich text includes a centered image43 <div width=100%>
115and no text. The second is the text ``YOU so rock dude!`` in italic, bold and44 <div>
116underlined. Then a simple text follows in four lines -- two of them being45 <p>
117empty. The message popups the message window when it is received.46 <font size=12>
11847 <img src=images/wui/menus/menu_toggle_menu.png>
119The complete message rendered looks like this on my system:48 </font>
12049 </p>
121.. image:: images/fancymsg.png50 </div>
122 :scale: 10051 <div width=*> -- Fill up the remaining space
123 :alt: sample rendering52 <p>
124 :align: center53 <font size=12>
12554 Another normal paragraph
12655 </font>
56 </p>
57 </div>
58 </div>
59 ...
60 </rt>"
61
62This is quite a lot of hacking, so we have :ref:`Lua convenience functions <richtext.lua>`
63set up. We recommend that you always use those while scripting in Lua, which will
64also give us consistency in style throughout Widelands.
65Using the convenience functions will also result in cleaner code when
66including translation markup (the ``_[[Some text]]`` or ``_"Some text"`` function).
67
68A code example how to use the convenience functions and their attributes is given in the
69documentation for the :ref:`richtext convenience functions <lua_formatting_example>`.
70
71:ref:`Return to index<richtext.lua>`
12772
=== modified file 'src/graphic/text/rt_parse.cc'
--- src/graphic/text/rt_parse.cc 2017-12-09 06:29:26 +0000
+++ src/graphic/text/rt_parse.cc 2018-02-24 15:32:03 +0000
@@ -171,11 +171,64 @@
171 }171 }
172}172}
173173
174/* RST
175.. _rt_tags:
176
177The Richtext Tags
178=================
179
180- :ref:`rt_tags_rt`
181- :ref:`rt_tags_div`
182- :ref:`rt_tags_br`
183- :ref:`rt_tags_space`
184- :ref:`rt_tags_vspace`
185- :ref:`rt_tags_p`
186- :ref:`rt_tags_font`
187- :ref:`rt_tags_img`
188
189For an introduction to our richtext system including a code example, see :ref:`wlrichtext`.
190
191*/
192
174/*193/*
175 * Class Parser194 * Class Parser
176 */195 */
177Parser::Parser() {196Parser::Parser() {
178 { // rt tag197 {
198 /* RST
199.. _rt_tags_rt:
200
201Rich Text -- <rt>
202-----------------
203
204The main wrapper that will signal to the font renderer to go into richtext mode.
205This tag surrounds your whole text, and is allowed only once.
206You can also set some options here what will affect your whole text.
207
208Attributes
209^^^^^^^^^^
210
211* **padding**: The rectangle of this tag is shrunk so leave a gap on its outside, on all four outer edges.
212* **padding_r**: Padding on the right-hand side
213* **padding_l**: Padding on the left-hand side
214* **padding_b**: Padding on the bottom
215* **padding_t**: Padding on the top
216
217* **background**: Give this tag's rectangle a background color as a hex value.
218
219* **keep_spaces**: Do now trim away trailing and double spaces. Use this where the user is editing text.
220* **db_show_spaces**: Highlight all blank spaces for debugging purposes.
221
222Sub-tags
223^^^^^^^^
224
225* :ref:`rt_tags_div`
226* :ref:`rt_tags_font`
227* :ref:`rt_tags_p`
228* :ref:`rt_tags_vspace`
229
230:ref:`Return to tag index<rt_tags>`
231 */
179 TagConstraint tc;232 TagConstraint tc;
180 tc.allowed_attrs.insert("padding");233 tc.allowed_attrs.insert("padding");
181 tc.allowed_attrs.insert("padding_r");234 tc.allowed_attrs.insert("padding_r");
@@ -194,30 +247,92 @@
194 tc.has_closing_tag = true;247 tc.has_closing_tag = true;
195 tag_constraints_["rt"] = tc;248 tag_constraints_["rt"] = tc;
196 }249 }
197 { // br tag250 {
251 /* RST
252.. _rt_tags_div:
253
254Division -- <div>
255-----------------
256
257This tag defines a rectangle and can be used as a layout control.
258
259Attributes
260^^^^^^^^^^
261
262The same attributes as :ref:`rt_tags_rt`, plus the following:
263
264* **margin**: Shrink all contents to leave a margin towards the outer edge of this tag's rectangle
265* **float**: To be implemented. Allowed values are ``left``, ``right``
266* **valign**: Align the contents vertically. Allowed values are ``top`` (default), ``center`` or ``middle``, ``bottom``.
267* **width**: The width of this element, as a pixel amount, or as a percentage.
268 The last ``div`` in a row can be expanded automatically by using ``*``.
269
270Sub-tags
271^^^^^^^^
272
273* :ref:`rt_tags_div`
274* :ref:`rt_tags_font`
275* :ref:`rt_tags_p`
276* :ref:`rt_tags_vspace`
277
278:ref:`Return to tag index<rt_tags>`
279 */
280 TagConstraint tc;
281 tc.allowed_attrs.insert("padding");
282 tc.allowed_attrs.insert("padding_r");
283 tc.allowed_attrs.insert("padding_l");
284 tc.allowed_attrs.insert("padding_b");
285 tc.allowed_attrs.insert("padding_t");
286 tc.allowed_attrs.insert("margin");
287 tc.allowed_attrs.insert("float");
288 tc.allowed_attrs.insert("valign");
289 tc.allowed_attrs.insert("background");
290 tc.allowed_attrs.insert("width");
291
292 tc.allowed_children.insert("p");
293 tc.allowed_children.insert("vspace");
294 tc.allowed_children.insert("font");
295 tc.allowed_children.insert("div");
296
297 tc.text_allowed = false;
298 tc.has_closing_tag = true;
299 tag_constraints_["div"] = tc;
300 }
301 {
302 /* RST
303.. _rt_tags_br:
304
305Line Break -- <br>
306------------------
307
308A single line break. Use sparingly for things like poetry stanzas.
309If you are starting a new paragraph, use :ref:`rt_tags_p` instead.
310
311:ref:`Return to tag index<rt_tags>`
312 */
198 TagConstraint tc;313 TagConstraint tc;
199 tc.text_allowed = false;314 tc.text_allowed = false;
200 tc.has_closing_tag = false;315 tc.has_closing_tag = false;
201 tag_constraints_["br"] = tc;316 tag_constraints_["br"] = tc;
202 }317 }
203 { // img tag318 {
204 TagConstraint tc;319 /* RST
205 tc.allowed_attrs.insert("src");320.. _rt_tags_space:
206 tc.allowed_attrs.insert("ref");321
207 tc.allowed_attrs.insert("color");322Horizontal Space -- <space>
208 tc.allowed_attrs.insert("width");323---------------------------
209 tc.text_allowed = false;324
210 tc.has_closing_tag = false;325Inserts a horizontal gap between the previous and the following text.
211 tag_constraints_["img"] = tc;326This space can be filled with a character of your choice.
212 }327
213 { // vspace tag328Attributes
214 TagConstraint tc;329^^^^^^^^^^
215 tc.allowed_attrs.insert("gap");330
216 tc.text_allowed = false;331* **gap**: The size of the gap as a pixel amount
217 tc.has_closing_tag = false;332* **fill**: A character to fill the gap with
218 tag_constraints_["vspace"] = tc;333
219 }334:ref:`Return to tag index<rt_tags>`
220 { // space tag335 */
221 TagConstraint tc;336 TagConstraint tc;
222 tc.allowed_attrs.insert("gap");337 tc.allowed_attrs.insert("gap");
223 tc.allowed_attrs.insert("fill");338 tc.allowed_attrs.insert("fill");
@@ -225,29 +340,58 @@
225 tc.has_closing_tag = false;340 tc.has_closing_tag = false;
226 tag_constraints_["space"] = tc;341 tag_constraints_["space"] = tc;
227 }342 }
228 { // div tag343 {
344 /* RST
345.. _rt_tags_vspace:
346
347Vertical Space -- <vspace>
348--------------------------
349
350Inserts a vertical gap between the previous and the following text.
351
352Attributes
353^^^^^^^^^^
354
355* **gap**: The size of the gap as a pixel amount
356
357:ref:`Return to tag index<rt_tags>`
358 */
229 TagConstraint tc;359 TagConstraint tc;
230 tc.allowed_attrs.insert("padding");360 tc.allowed_attrs.insert("gap");
231 tc.allowed_attrs.insert("padding_r");
232 tc.allowed_attrs.insert("padding_l");
233 tc.allowed_attrs.insert("padding_b");
234 tc.allowed_attrs.insert("padding_t");
235 tc.allowed_attrs.insert("margin");
236 tc.allowed_attrs.insert("float");
237 tc.allowed_attrs.insert("valign");
238 tc.allowed_attrs.insert("background");
239 tc.allowed_attrs.insert("width");
240
241 tc.allowed_children.insert("p");
242 tc.allowed_children.insert("vspace");
243 tc.allowed_children.insert("font");
244 tc.allowed_children.insert("div");
245
246 tc.text_allowed = false;361 tc.text_allowed = false;
247 tc.has_closing_tag = true;362 tc.has_closing_tag = false;
248 tag_constraints_["div"] = tc;363 tag_constraints_["vspace"] = tc;
249 }364 }
250 { // p tag365 {
366 /* RST
367.. _rt_tags_p:
368
369Paragraph -- <p>
370----------------
371
372This tag encloses a text paragraph.
373
374Attributes
375^^^^^^^^^^
376
377* **indent**: Adds an indent to the first line of the paragraph
378* **align**: The horizontal alignment for the paragraph's text.
379 Allowed values are ``left`` (default), ``center`` or ``middle``, ``right``.
380* **valign**: See :ref:`rt_tags_div`
381* **spacing**: Vertical line spacing as a pixel value
382
383Sub-tags
384^^^^^^^^
385
386* :ref:`rt_tags_br`
387* :ref:`rt_tags_div`
388* :ref:`rt_tags_font`
389* :ref:`rt_tags_img`
390* :ref:`rt_tags_space`
391* :ref:`rt_tags_vspace`
392
393:ref:`Return to tag index<rt_tags>`
394 */
251 TagConstraint tc;395 TagConstraint tc;
252 tc.allowed_attrs.insert("indent");396 tc.allowed_attrs.insert("indent");
253 tc.allowed_attrs.insert("align");397 tc.allowed_attrs.insert("align");
@@ -264,7 +408,40 @@
264 tc.has_closing_tag = true;408 tc.has_closing_tag = true;
265 tag_constraints_["p"] = tc;409 tag_constraints_["p"] = tc;
266 }410 }
267 { // font tag411 {
412 /* RST
413.. _rt_tags_font:
414
415Font -- <font>
416--------------
417
418This tag defines the font style for the enclosed text.
419
420Attributes
421^^^^^^^^^^
422
423* **size**: The font size as a pixel value
424* **face**: The font face. Allowed values are ``sans`` (default), ``serif`` and ``condensed``.
425* **color**: The font color as a hex value
426* **bold**: Make the text bold
427* **italic**: Make the text italic
428* **underline**: Underline the text
429* **shadow**: Add a background shadow
430* **ref**: To be implemented
431
432Sub-tags
433^^^^^^^^
434
435* :ref:`rt_tags_br`
436* :ref:`rt_tags_div`
437* :ref:`rt_tags_font`
438* :ref:`rt_tags_img`
439* :ref:`rt_tags_p`
440* :ref:`rt_tags_space`
441* :ref:`rt_tags_vspace`
442
443:ref:`Return to tag index<rt_tags>`
444 */
268 TagConstraint tc;445 TagConstraint tc;
269 tc.allowed_attrs.insert("size");446 tc.allowed_attrs.insert("size");
270 tc.allowed_attrs.insert("face");447 tc.allowed_attrs.insert("face");
@@ -286,6 +463,34 @@
286 tc.has_closing_tag = true;463 tc.has_closing_tag = true;
287 tag_constraints_["font"] = tc;464 tag_constraints_["font"] = tc;
288 }465 }
466 {
467 /* RST
468.. _rt_tags_img:
469
470Image -- <img>
471--------------
472
473Displays an image with your text.
474
475Attributes
476^^^^^^^^^^
477
478* **src**: The path to the image, relative to the ``data`` directory.
479* **ref**: To be implemented
480* **color**: Player color for the image as a hex value
481* **width**: Width of the image as a pixel amount. The corresponding height will be matched automatically.
482
483:ref:`Return to tag index<rt_tags>`
484 */
485 TagConstraint tc;
486 tc.allowed_attrs.insert("src");
487 tc.allowed_attrs.insert("ref");
488 tc.allowed_attrs.insert("color");
489 tc.allowed_attrs.insert("width");
490 tc.text_allowed = false;
491 tc.has_closing_tag = false;
492 tag_constraints_["img"] = tc;
493 }
289}494}
290495
291Parser::~Parser() {496Parser::~Parser() {

Subscribers

People subscribed via source and target branches

to status/vote changes: