-
Notifications
You must be signed in to change notification settings - Fork 7
/
HtmlStyle.h
189 lines (170 loc) · 3.63 KB
/
HtmlStyle.h
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#pragma once
#include "JSVMInterface.h"
class HtmlElement;
enum COORDTYPE//×ø±êÀàÐÍ
{
CT_NOVALUE,//δÔÚstyleÖÐÉèÖÃ
CT_PX,//px
CT_PERCENT,//%
};
struct HTMLCOORD
{
std::string strvalue;
double value = 0;
COORDTYPE typ = CT_PX;
bool SetValue(const std::string& szValue)
{
strvalue = szValue;
char*p = 0;
value = strtod(szValue.c_str(), &p);
if (!_stricmp(p, "px"))
{
typ = CT_PX;
}
else if (!_stricmp(p, "%"))
{
typ = CT_PERCENT;
}
else
{
typ = CT_PX;
}
return true;
}
};
void Trim(char*&str);
class HtmlStyle :
public CustomClassBase
{
DEFINE_CUSTOM_CLASS(HtmlStyle, CustomClassBase)
public:
BEGIN_CUSTOM_FUNCTION
END_CUSTOM_FUNCTION
BEGIN_CUSTOM_PROPERTY
DEFINE_CUSTOM_PROPERTY("left")
DEFINE_CUSTOM_PROPERTY("top")
DEFINE_CUSTOM_PROPERTY("width")
DEFINE_CUSTOM_PROPERTY("height")
DEFINE_CUSTOM_PROPERTY("fontFamily")
DEFINE_CUSTOM_PROPERTY("fontSize")
DEFINE_CUSTOM_PROPERTY("backgroundImage")
DEFINE_CUSTOM_PROPERTY("cssText")
DEFINE_CUSTOM_PROPERTY("transform")
DEFINE_CUSTOM_PROPERTY("transformOrigin")
END_CUSTOM_PROPERTY
HTMLCOORD m_left;
HTMLCOORD m_top;
HTMLCOORD m_width;
HTMLCOORD m_height;
HtmlElement* m_pParent = nullptr;
struct _TRANSFORM
{
int xTran=0;
int yTran=0;
float fRot=0;
float xScale=1;
float yScale=1;
int xOrig = 0;
int yOrig = 0;
void initial()
{
xTran = yTran = xOrig=yOrig=0;
fRot = 0;
xScale = yScale = 1;
}
void ParseTransform(const std::string&str)
{
if (str == "initial")
{
initial();
return;
}
std::vector<std::string>paralist;
char*pbuf = strdup(str.c_str());
char*p = pbuf;
while (*p)
{
char*q = p;
while (*q)
{
if (*q != '(')q++;
else break;
}
std::string szFunName;
szFunName.resize(q - p);
memcpy((char*)szFunName.data(), p, q - p);
szFunName = trim(szFunName);
p = q + 1;
q = p;
paralist.clear();
while (*q)
{
if (*q == ',' || *q == ')')
{
char ch = *q;
*q = 0;
Trim(p);
paralist.push_back(p);
q++;
p = q;
if (ch == ')')
{
break;
}
}
q++;
}
p = q;
if (szFunName == "translate")
{
if (paralist.size() == 2)
{
xTran = strtol(paralist[0].c_str(), 0, 10);
yTran = strtol(paralist[1].c_str(), 0, 10);
}
}
else if (szFunName == "rotate")
{
if (paralist.size() == 1)
{
char*d;
fRot = strtod(paralist[0].c_str(),&d);
if (!strcmp(d, "deg"))
{
fRot = fRot * PI / 180.0;
}
}
}
else if (szFunName == "scale")
{
if (paralist.size() == 2)
{
xScale = strtod(paralist[0].c_str(), 0);
yScale = strtod(paralist[1].c_str(), 0);
}
}
}
free(pbuf);
}
void ParseTransformOrigin(const std::string&str)
{
}
};
_TRANSFORM m_Transform;
std::string m_fontFamily;
std::string m_fontSize;
std::string m_backgroundImage;
std::string m_styleText;
HtmlStyle();
virtual ~HtmlStyle();
static bool InitClass(const HandleContext&context);
virtual bool OnConstructor(IFunctionCallbackArgs&args);
virtual bool OnGetProperty(GetPropertyArgs&args);
virtual bool OnSetProperty(SetPropertyArgs&args);
FontInfo GetFontInfo(const HandleContext&context);
bool SetStyle(const HandleContext&context, const char*szText, HtmlElement*pElement);
bool SetStyle(const HandleContext&context, const char*szName, std::vector<std::string>&values, HtmlElement*pElement);
void SetParent(const HandleContext&context, HtmlElement*pElement);
HandleObject GetParentElement(const HandleContext&context);
void ResetStyle(const HandleContext& context);
};