~aleteoryx/muditaos

ref: 6533aba24ef55cde97a89ef8040b9da21425d571 muditaos/module-gui/gui/widgets/RichTextParser.hpp -rw-r--r-- 2.0 KiB
6533aba2 — KacperLewandowski [EGD-4073] Alarms database rework (#1006) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <utf8/UTF8.hpp>

namespace gui
{
    class TextDocument;
    class TextFormat;
} // namespace gui

namespace gui::text
{
    inline const auto align     = "align";
    inline const auto center    = "center";
    inline const auto right     = "right";
    inline const auto left      = "left";
    inline const auto color     = "color";
    inline const auto font      = "font";
    inline const auto size      = "size";
    inline const auto weight    = "weight";
    inline const auto regular   = "regular";
    inline const auto bold      = "bold";
    inline const auto light     = "light";
    inline const auto node_text = "text";
    inline const auto node_br   = "br";
    inline const auto node_p    = "p";
    inline const auto short_bold = "b";

    /// Rich text parser utility
    /// supported specifiers
    /// * gui::text::node_text `<text> </text>` attributes:
    ///        * gui::text::align - alignment in Horizontal axis ( gui::text::center, gui::text::left, gui::text::right
    ///        )
    ///        * gui::text::color - Text color from 0 to 15 ( eink black color depth )
    ///        * gui::text::font  - Font to use ( now we have gt_pressura and some dejavu glyphs)
    ///        * gui::text::size  - size of font to use
    ///        * gui::text::weight - weight of font to use, one of: gui::text::bold, gui::text::regular,
    ///        gui::text::light
    /// please mind that selected font must exist on system, othervise closest relative will be selected
    /// * gui::text::node_p `<p> </p>`, gui::text::node_br `<br> </br>` and gui::text::shortened_bold `<b> </b>` now
    /// working identical - marking start and end with newline
    /// @return empty document on error
    class RichTextParser
    {
      public:
        auto parse(const UTF8 &text, TextFormat *base_style) -> std::unique_ptr<TextDocument>;
    };
} // namespace gui::text