Text.hpp
Functionality similar to String, but tracks text formatting for easy conversion.
Text should be functionally interchangable with string, but can easily convert to HTML, Latex, RTF, or other formats that support bold, italic, super/sub-scripting, fonts, etc.
The main Text class tracks a string of text (called simply “text”) and any special styles associated with each text position (in “style_map”). The current TextEncoding class helps guide the conversion from one text encoding to another.
Internally, styles that all encodings should be able to handle (or at least be aware of) are: BASIC FORMATS : “bold” “code” “italic” “strike” “subscript” “superscript” “underline” “no_break” “color:NAME” “font:NAME” “size:POINT_SIZE”
STRUCTURAL : “heading:1” through “heading:6” different levels of headings. “blockquote” “bullet:1” through “bullet:6” (only on character after bulleted; stops an newline) “indent:1” through “indent:6” (same as bullet, but no bullet) “ordered:1” through “ordered:6” (numbers; reset less-tabbed structure is used) “link:URL” (create a link to the specified URL) “image:URL” (include in the specified image)
Note
Status: ALPHA
-
struct TextEncoding_Interface
- #include <Text.hpp>
Subclassed by TextEncoding, TextEncoding_None
-
class TextEncoding_None : public TextEncoding_Interface
- #include <Text.hpp>
Public Functions
-
inline TextEncoding_None()
-
virtual Ptr<TextEncoding_Interface> Clone() const override
-
inline TextEncoding_None()
-
class Text : public internal::WidgetFacet<Text>
- #include <Text.hpp>
A Text widget handles putting text on a web page that can be controlled and modified.
Public Functions
-
inline Text()
-
inline ~Text()
-
inline size_t GetSize() const
-
inline bool HasEncoding(const String &name) const
Test if this Text object is aware of how to use a specified encoding.
- Parameters:
name – Name of the encoding to test for.
- Returns:
A true/false indicate if the named encoding is known.
-
inline String GetEncodingName() const
Get the name of the current encoding being applied.
- Returns:
Name of the current encoding.
-
inline Text &SetEncoding(const String &name)
Change the current encoding being used to another known encoding type.
- Parameters:
name – Name of the encoding type to be used.
- Returns:
A reference to this object itself.
-
template<typename ENCODING_T, typename ...EXTRA_Ts>
inline String AddEncoding(EXTRA_Ts&&... args) Add an encoding to this Text object; new encodings automatically become active.
Add a new encoding to this Text object. Newly added encodings automatically become active (use SetEncoding() to choose a different encoding option). Will give a warning if encoding already exists, and then replace it.
- Template Parameters:
ENCODING_T – The type of the new encoding to use
...EXTRA_Ts – Automatically set by variadic arguments.
- Parameters:
...args – Any extra arguments to configure this new encoding (passed to constructor)
- Returns:
Name of the encoding that was created.
-
inline void RemoveEncoding(const String &name)
Remove an encoding with a provided name.
- Parameters:
name – Name of the encoding to remove.
-
template<typename ENCODING_T, typename ...EXTRA_Ts>
inline String ActivateEncoding(const String &name, EXTRA_Ts&&... args) Set an encoding as active, creating it if needed.
- Template Parameters:
ENCODING_T – The type of the new encoding to use
...EXTRA_Ts – Automatically set by variadic arguments.
- Parameters:
name – Name of the encoding that we want activated / added
...args – Any extra arguments to configure this new encoding (passed to constructor)
- Returns:
Name of the encoding that was created.
-
template<typename T, typename ...EXTRA_Ts>
inline Text &Append(T &&in, EXTRA_Ts&&... in_extra) Append potentially-formatted text through the current encoding.
-
template<typename ENCODING_T, typename IN_T>
inline Text &AppendAs(const String &encode_name, IN_T &&in) Specify the encoding of a value being appended.
-
inline String Encode() const
Convert text to a string using the current encoding.
- Returns:
The resulting string.
-
inline void Resize(size_t new_size)
-
inline char GetChar(size_t pos) const
-
inline TextCharRef<false> operator[](size_t pos)
-
inline TextCharRef<true> operator[](size_t pos) const
-
inline size_t size() const
-
inline void resize(size_t new_size)
-
inline TextCharRef<false> front()
-
inline TextCharRef<true> front() const
-
inline TextCharRef<false> back()
-
inline TextCharRef<true> back() const
-
inline bool empty() const
-
inline vector<String> GetStyles(size_t pos = MAX_SIZE_T) const
Return the set of active styles in this text.
- Parameters:
pos – optional position to specify only styles used at position.
-
inline bool HasBold() const
-
inline bool HasCode() const
-
inline bool HasItalic() const
-
inline bool HasStrike() const
-
inline bool HasSubscript() const
-
inline bool HasSuperscript() const
-
inline bool HasUnderline() const
-
inline bool HasBold(size_t pos) const
-
inline bool HasCode(size_t pos) const
-
inline bool HasItalic(size_t pos) const
-
inline bool HasStrike(size_t pos) const
-
inline bool HasSubscript(size_t pos) const
-
inline bool HasSuperscript(size_t pos) const
-
inline bool HasUnderline(size_t pos) const
Protected Types
-
using encoding_ptr_t = Ptr<TextEncoding_Interface>
-
inline Text()