File: StyleSheet.h

package info (click to toggle)
lsp-plugins 1.2.21-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 120,408 kB
  • sloc: cpp: 589,849; xml: 74,078; makefile: 13,396; php: 1,268; sh: 185
file content (163 lines) | stat: -rw-r--r-- 8,075 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-tk-lib
 * Created on: 1 нояб. 2020 г.
 *
 * lsp-tk-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-tk-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LSP_PLUG_IN_TK_STYLE_STYLESHEET_H_
#define LSP_PLUG_IN_TK_STYLE_STYLESHEET_H_

#ifndef LSP_PLUG_IN_TK_IMPL
    #error "use <lsp-plug.in/tk/tk.h>"
#endif

#include <lsp-plug.in/lltl/parray.h>
#include <lsp-plug.in/lltl/pphash.h>
#include <lsp-plug.in/runtime/LSPString.h>
#include <lsp-plug.in/runtime/Color.h>
#include <lsp-plug.in/io/Path.h>
#include <lsp-plug.in/io/IInStream.h>
#include <lsp-plug.in/io/IInSequence.h>
#include <lsp-plug.in/fmt/xml/PullParser.h>

namespace lsp
{
    namespace tk
    {
        /**
         * Style sheet class
         *
         */
        class StyleSheet
        {
            private:
                friend class Schema;

            protected:
                typedef struct property_t
                {
                    size_t                                  order;      // Property order
                    LSPString                               value;      // Property value
                } property_t;

                typedef struct style_t
                {
                    size_t                                  order_gen;  // Property order generator
                    LSPString                               name;       // Name of style
                    lltl::parray<LSPString>                 parents;    // List of parents
                    lltl::pphash<LSPString, property_t>     properties; // properties

                    style_t();
                    ~style_t();
                } style_t;

                typedef struct font_t
                {
                    LSPString                               name;       // Name of the font
                    LSPString                               path;       // Path to font
                    bool                                    alias;      // Is an alias
                } font_t;

                typedef struct path_t
                {
                    lltl::parray<style_t>                   visited;
                    style_t                                *curr;
                } path_t;

            protected:
                LSPString                           sTitle;     // Schema title
                style_t                            *pRoot;      // Root style
                lltl::pphash<LSPString, style_t>    vStyles;    // Additional named styles
                lltl::pphash<LSPString, font_t>     vFonts;     // Additional fonts
                lltl::pphash<LSPString, lsp::Color> vColors;    // Color map
                lltl::pphash<LSPString, LSPString>  vConstants; // Global constants
                LSPString                           sError;     // Error text

            public:
                explicit StyleSheet();
                StyleSheet(const StyleSheet &) = delete;
                StyleSheet(StyleSheet &&) = delete;
                ~StyleSheet();

                StyleSheet & operator = (const StyleSheet &) = delete;
                StyleSheet & operator = (StyleSheet &&) = delete;

            protected:
                status_t            parse_document(xml::PullParser *p);
                status_t            parse_schema(xml::PullParser *p);
                status_t            parse_colors(xml::PullParser *p);
                status_t            parse_fonts(xml::PullParser *p);
                status_t            parse_constants(xml::PullParser *p);

                status_t            parse_metadata(xml::PullParser *p);
                status_t            parse_style(xml::PullParser *p, bool root);
                status_t            parse_color(xml::PullParser *p, const LSPString *color_name, lsp::Color *color);
                status_t            parse_constant(xml::PullParser *p, LSPString *value);
                status_t            parse_font(xml::PullParser *p, font_t *font);
                status_t            parse_property(xml::PullParser *p, style_t *style, const LSPString *name);

                status_t            parse_style_class(LSPString *cname, const LSPString *text);
                status_t            parse_string_value(xml::PullParser *p, LSPString *value);
                status_t            parse_style_parents(style_t *style, const LSPString *text);
                status_t            parse_property_type(property_type_t *pt, const LSPString *text);
                status_t            add_parent(style_t *style, const LSPString *text);

                status_t            validate();
                status_t            validate_style(style_t *s);
                static void         drop_paths(lltl::parray<path_t> *paths);

            public:
                status_t            parse_file(const char *path, const char *charset = NULL);
                status_t            parse_file(const LSPString *path, const char *charset = NULL);
                status_t            parse_file(const io::Path *path, const char *charset = NULL);

                status_t            parse_data(io::IInStream *is, size_t flags = WRAP_NONE, const char *charset = NULL);
                status_t            parse_data(const char *str, const char *charset = NULL);
                status_t            parse_data(const LSPString *str);
                status_t            parse_data(io::IInSequence *seq, size_t flags = WRAP_NONE);

            public:
                inline const LSPString *title() const                               { return &sTitle;       }
                status_t            enum_colors(lltl::parray<LSPString> *names) const;
                status_t            enum_styles(lltl::parray<LSPString> *names) const;
                status_t            enum_fonts(lltl::parray<LSPString> *names) const;
                status_t            enum_constants(lltl::parray<LSPString> *names) const;
                status_t            enum_properties(const LSPString *style, lltl::parray<LSPString> *names) const;
                status_t            enum_properties(const char *style, lltl::parray<LSPString> *names) const;
                status_t            enum_parents(const LSPString *style, lltl::parray<LSPString> *names) const;
                status_t            enum_parents(const char *style, lltl::parray<LSPString> *names) const;

                ssize_t             get_property(const LSPString *style, const LSPString *property, LSPString *dst) const;
                ssize_t             get_property(const char *style, const char *property, LSPString *dst) const;
                ssize_t             get_color(const LSPString *color, lsp::Color *dst) const;
                ssize_t             get_color(const char *color, lsp::Color *dst) const;
                ssize_t             get_font(const LSPString *font, LSPString *path, bool *alias) const;
                ssize_t             get_font(const char *font, LSPString *path, bool *alias) const;
                ssize_t             get_constant(const LSPString *name, LSPString *dst) const;
                ssize_t             get_constant(const char *name, LSPString *dst) const;

            public:
                const LSPString    *error() const { return &sError;     }
        };

    } /* namespace tk */
} /* namespace lsp */



#endif /* LSP_PLUG_IN_TK_STYLE_STYLESHEET_H_ */