utils.h 4.93 KB
Newer Older
XueShuming's avatar
XueShuming committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/////////////////////////////////////////////////////////////////////////////// //
//                          IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
 \verbatim

XueShuming's avatar
XueShuming committed
15
16
17
    This file is part of HiDOMLayout. hiDOMLayout is a library to
    maintain a DOM tree, lay out and stylize the DOM nodes by
    using CSS (Cascaded Style Sheets).
XueShuming's avatar
XueShuming committed
18

XueShuming's avatar
XueShuming committed
19
    Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
XueShuming's avatar
XueShuming committed
20
21

    This program is free software: you can redistribute it and/or modify
XueShuming's avatar
XueShuming committed
22
    it under the terms of the GNU Lesser General License as published by
XueShuming's avatar
XueShuming committed
23
24
25
26
27
28
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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
XueShuming's avatar
XueShuming committed
29
    GNU Lesser General License for more details.
XueShuming's avatar
XueShuming committed
30

XueShuming's avatar
XueShuming committed
31
    You should have received a copy of the GNU Lesser General License
XueShuming's avatar
XueShuming committed
32
33
34
35
36
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Or,

    As this program is a library, any link to this program must follow
XueShuming's avatar
XueShuming committed
37
38
    GNU Lesser General License version 3 (LGPLv3). If you cannot accept
    LGPLv3, you need to be licensed from FMSoft.
XueShuming's avatar
XueShuming committed
39
40
41
42
43
44
45
46
47
48
49
50
51

    If you have got a commercial license of this program, please use it
    under the terms and conditions of the commercial license.

    For more information about the commercial license, please refer to
    <http://www.minigui.com/blog/minigui-licensing-policy/>.

 \endverbatim
 */

#ifndef _HL_UTILS_H_
#define _HL_UTILS_H_

XueShuming's avatar
XueShuming committed
52
#include "hidomlayout.h"
XueShuming's avatar
XueShuming committed
53
54
55
56
57
58
59
60
61
#include <libcss/libcss.h>

// top, right, bottom, left
#define HL_TOP          0
#define HL_RIGHT        1
#define HL_BOTTOM       2
#define HL_LEFT         3

#define HL_AUTO         INT_MIN
XueShuming's avatar
XueShuming committed
62
#define UNKNOWN_WIDTH   INT_MAX
XueShuming's avatar
XueShuming committed
63
64
65
66

/* Fixed point percentage (a) of an integer (b), to an integer */
#define HL_FPCT_OF_INT_TOINT(a, b) (FIXTOINT(FDIV((a * b), F_100)))

XueShuming's avatar
XueShuming committed
67
68
69
70
71
72
/** 22:10 fixed point */
#define HL_PLOT_STYLE_RADIX (10)

/** Scaling factor for plot styles */
#define HL_PLOT_STYLE_SCALE (1 << HL_PLOT_STYLE_RADIX)

XueShuming's avatar
XueShuming committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif

#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif

typedef struct HLContext_ {
    HLMedia* media;
    HLCSS* css;
    css_fixed hl_css_media_dpi;
    css_fixed hl_css_baseline_pixel_density;

    int vw;
    int vh;
    const css_computed_style *root_style;
90
91

    HLDomElementNode* root;
XueShuming's avatar
XueShuming committed
92
93
} HLContext;

XueShuming's avatar
XueShuming committed
94
95
96
97
98
99
100
101
typedef enum HLGridItemRowColumnE_ {
    HL_GRID_ITEM_RC_NONE            = 0x00,
    HL_GRID_ITEM_RC_FULL            = 0x0F,
    HL_GRID_ITEM_RC_ROW_START       = (1<<3),
    HL_GRID_ITEM_RC_ROW_END         = (1<<2),
    HL_GRID_ITEM_RC_COLUMN_START    = (1<<1),
    HL_GRID_ITEM_RC_COLUMN_END      = (1<<0),
} HLGridItemRowColumnE;
102

XueShuming's avatar
XueShuming committed
103
104
typedef struct HLGridItem_ {
    HLGridItemRowColumnE rc_set;
XueShuming's avatar
XueShuming committed
105
106
    int row_start;
    int row_end;
107

XueShuming's avatar
XueShuming committed
108
109
    int column_start;
    int column_end;
XueShuming's avatar
XueShuming committed
110
    uint8_t layout_done;
111
} HLGridItem;
XueShuming's avatar
XueShuming committed
112

XueShuming's avatar
XueShuming committed
113
typedef struct HLGridTemplate_ {
XueShuming's avatar
XueShuming committed
114
115
116
117
    int x;
    int y;
    int w;
    int h;
XueShuming's avatar
XueShuming committed
118
119
120
121
122
123
124
125
    int32_t* rows;
    int32_t* columns;

    int n_row;
    int n_column;

    uint8_t** mask;
} HLGridTemplate;
XueShuming's avatar
XueShuming committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

#ifdef __cplusplus
extern "C" {
#endif

css_fixed _hl_css_pixels_css_to_physical(const HLContext* ctx, css_fixed css_pixels);
css_fixed _hl_css_pixels_physical_to_css(const HLContext* ctx, css_fixed physical_pixels);
int _hl_set_media_dpi(HLContext* ctx, int dpi);
int _hl_set_baseline_pixel_density(HLContext* ctx, int density);


css_unit _hl_css_utils_fudge_viewport_units(const HLContext *ctx, css_unit unit);
css_fixed _hl_css_len2pt(const HLContext *ctx, css_fixed length, css_unit unit);
css_fixed _hl_css_len2px(const HLContext *ctx,
		css_fixed length,
		css_unit unit,
		const css_computed_style *style);

XueShuming's avatar
XueShuming committed
144
uint8_t _hl_computed_min_height(
145
146
        const css_computed_style *style,
        css_fixed *length, css_unit *unit);
XueShuming's avatar
XueShuming committed
147
uint8_t _hl_computed_min_width(
148
149
        const css_computed_style *style,
        css_fixed *length, css_unit *unit);
XueShuming's avatar
XueShuming committed
150

XueShuming's avatar
XueShuming committed
151
uint8_t _hl_computed_display(const css_computed_style *style, bool root);
152
int _hi_computed_z_index(HLDomElementNode *node);
153
154
HLGridItem* _hl_grid_item_create(HLDomElementNode *node);
void _hl_grid_item_destroy(HLGridItem*);
XueShuming's avatar
XueShuming committed
155

156
HLGridTemplate* _hl_grid_template_create(const HLContext *ctx, HLDomElementNode *node);
XueShuming's avatar
XueShuming committed
157
void _hl_grid_template_destroy(HLGridTemplate*);
XueShuming's avatar
XueShuming committed
158

XueShuming's avatar
XueShuming committed
159
160
161
typedef void (*each_child_callback)(HLContext* ctx, HLDomElementNode* node, void* user_data);
void _hl_for_each_child(HLContext* ctx, HLDomElementNode* node, each_child_callback callback, void* user_data);

XueShuming's avatar
XueShuming committed
162
163
int _hilayout_find_font(HLContext* ctx, HLDomElementNode* node);
int _hilayout_find_background(HLDomElementNode* node);
XueShuming's avatar
XueShuming committed
164

XueShuming's avatar
XueShuming committed
165
166
167
168
169
170
#ifdef __cplusplus
}
#endif

#endif // _HL_UTILS_H_