This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
TWRenderDCTcw.cpp
237 lines (206 loc) · 6.85 KB
/
TWRenderDCTcw.cpp
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// TWRenderDCTcw.cpp
// XTBook
//
// Created by Nexhawks on 3/13/11.
// Copyright 2011 Nexhawks. All rights reserved.
//
/*
* This file is part of XTBook.
*
* XTBook is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XTBook 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XTBook. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TWRenderDCTcw.h"
#include <tcw/twDC.h>
#include "TWRenderManagerTcw.h"
#include "TWiki/TWRenderObject.h"
#include <typeinfo>
#include <tcw/twStrConv.h>
#include "TWiki/TWHTMLElement.h"
TWRenderDCTcw::TWRenderDCTcw(twDC *dc, TWRenderManager *manager):
m_dc(dc),
m_fontManager(manager){
}
TWRenderDCTcw::~TWRenderDCTcw(){
}
static twColor twColorFromStyleColor(const TWHTMLStyleColor& styleColor){
return twRGB(styleColor.red, styleColor.green, styleColor.blue);
}
static twRect twRectFromTWRect(const TWRect& rt){
return twRect(rt.x, rt.y, rt.w, rt.h);
}
void TWRenderDCTcw::fillBackground(const TWRect &rt){
const TWHTMLStyleColor& color=m_style.backgroundColor();
if(color.alpha==0)
return;
m_dc->fillRect(twColorFromStyleColor(color),
twRectFromTWRect(rt));
}
void TWRenderDCTcw::drawBorder(const TWRect &rt){
twColor color;
int width;
// TODO: support for non-1px-border
color=twColorFromStyleColor(m_style.borderLeft().color);
width=m_style.borderLeft().width.toPixels(0, m_style);
switch(m_style.borderLeft().style){
case TWHTMLStyleBorderStyleNone:
break;
case TWHTMLStyleBorderStyleSolid:
case TWHTMLStyleBorderStyleDouble:
case TWHTMLStyleBorderStyleGroove:
case TWHTMLStyleBorderStyleInset:
case TWHTMLStyleBorderStyleOutset:
case TWHTMLStyleBorderStyleRidge:
m_dc->fillRect(color, twRect(rt.x, rt.y,
width, rt.h));
break;
case TWHTMLStyleBorderStyleDotted:
for(int y=rt.y;y<rt.y+rt.h;y+=2)
m_dc->fillRect(color, twRect(rt.x, y, width, 1));
break;
case TWHTMLStyleBorderStyleDashed:
for(int y=rt.y;y<rt.y+rt.h;y+=4)
m_dc->fillRect(color, twRect(rt.x, y,
width, MIN(2, rt.y+rt.h-y)));
break;
}
color=twColorFromStyleColor(m_style.borderRight().color);
width=m_style.borderRight().width.toPixels(0, m_style);
switch(m_style.borderRight().style){
case TWHTMLStyleBorderStyleNone:
break;
case TWHTMLStyleBorderStyleSolid:
case TWHTMLStyleBorderStyleDouble:
case TWHTMLStyleBorderStyleGroove:
case TWHTMLStyleBorderStyleInset:
case TWHTMLStyleBorderStyleOutset:
case TWHTMLStyleBorderStyleRidge:
m_dc->fillRect(color, twRect(rt.x+rt.w-width, rt.y,
width, rt.h));
break;
case TWHTMLStyleBorderStyleDotted:
for(int y=rt.y;y<rt.y+rt.h;y+=2)
m_dc->fillRect(color, twRect(rt.x+rt.w-width, y,
width, 1));
break;
case TWHTMLStyleBorderStyleDashed:
for(int y=rt.y;y<rt.y+rt.h;y+=4)
m_dc->fillRect(color, twRect(rt.x+rt.w-width, y,
width, MIN(2, rt.y+rt.h-y)));
break;
}
color=twColorFromStyleColor(m_style.borderTop().color);
width=m_style.borderTop().width.toPixels(0, m_style);
switch(m_style.borderTop().style){
case TWHTMLStyleBorderStyleNone:
break;
case TWHTMLStyleBorderStyleSolid:
case TWHTMLStyleBorderStyleDouble:
case TWHTMLStyleBorderStyleGroove:
case TWHTMLStyleBorderStyleInset:
case TWHTMLStyleBorderStyleOutset:
case TWHTMLStyleBorderStyleRidge:
m_dc->fillRect(color, twRect(rt.x, rt.y,
rt.w, width));
break;
case TWHTMLStyleBorderStyleDotted:
for(int x=rt.x;x<rt.x+rt.w;x+=2)
m_dc->fillRect(color, twRect(x, rt.y,
1, width));
break;
case TWHTMLStyleBorderStyleDashed:
for(int x=rt.x;x<rt.x+rt.w;x+=4)
m_dc->fillRect(color, twRect(x, rt.y,
MIN(2, rt.x+rt.w-x), width));
break;
}
color=twColorFromStyleColor(m_style.borderBottom().color);
width=m_style.borderBottom().width.toPixels(0, m_style);
switch(m_style.borderBottom().style){
case TWHTMLStyleBorderStyleNone:
break;
case TWHTMLStyleBorderStyleSolid:
case TWHTMLStyleBorderStyleDouble:
case TWHTMLStyleBorderStyleGroove:
case TWHTMLStyleBorderStyleInset:
case TWHTMLStyleBorderStyleOutset:
case TWHTMLStyleBorderStyleRidge:
m_dc->fillRect(color, twRect(rt.x, rt.y+rt.h-width,
rt.w, width));
break;
case TWHTMLStyleBorderStyleDotted:
for(int x=rt.x;x<rt.x+rt.w;x+=2)
m_dc->fillRect(color, twRect(x, rt.y+rt.h-width,
1, width));
break;
case TWHTMLStyleBorderStyleDashed:
for(int x=rt.x;x<rt.x+rt.w;x+=4)
m_dc->fillRect(color, twRect(x, rt.y+rt.h-width,
MIN(2, rt.x+rt.w-x), width));
break;
}
//m_dc->drawRect(rand(), twRect(rt.x, rt.y, rt.w-1, rt.h-1));
}
void TWRenderDCTcw::debugRenderObject(const TWRect& rt, TWRenderObject *obj){
#if 0
if(obj->isRenderFlowObject())
return;
twRect r;
r=twRectFromTWRect(rt.sanitize());
m_dc->drawRect(0, twRect(r.x, r.y, r.w-1, r.h-1).inflate(3));
m_dc->drawRect(0xff, twRect(r.x, r.y, r.w-1, r.h-1).inflate(2));
std::wstring str;
TWHTMLElement *element=obj->node();
if(!element)
str=L"*";
else
str=element->name();
//std::wstring str=obj->name();
/*
str+=L'(';
str+=twM2W(typeid(*obj).name());
str+=L')';*/
twPoint pt(r.x+3, r.y+3);
twSize sz=tw_defFont->measure(str);
//pt.x-=sz.w+6;
tw_defFont->render(m_dc, 0, twPoint(pt.x-1, pt.y), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x+1, pt.y), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x, pt.y-1), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x, pt.y+1), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x-1, pt.y-1), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x+1, pt.y+1), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x-1, pt.y-1), str);
tw_defFont->render(m_dc, 0, twPoint(pt.x+1, pt.y+1), str);
tw_defFont->render(m_dc, 0x00ffff,
twPoint(pt.x, pt.y), str);
#endif
}
void TWRenderDCTcw::drawPlaceHolder(const TWRect &rt){
m_dc->fillRect(0xffffff, twRectFromTWRect(rt));
m_dc->drawLine(0, twPoint(rt.x, rt.y), twPoint(rt.x+rt.w, rt.y+rt.h));
m_dc->drawLine(0, twPoint(rt.x+rt.w, rt.y), twPoint(rt.x, rt.y+rt.h));
}
bool TWRenderDCTcw::isRectVisible(const TWRect & rt){
twRect rt2=twRectFromTWRect(rt);
twRect clipRect=m_dc->getClipRect();
return rt2 && clipRect;
}
void TWRenderDCTcw::fillSelection(const TWRect& rt){
twRect rt2=twRectFromTWRect(rt.sanitize());
rt2-=m_selectionShift;
// round rect.
m_dc->dimRect(twRect(rt2.x-1, rt2.y, rt2.w+2, rt2.h));
m_dc->dimRect(twRect(rt2.x, rt2.y-1, rt2.w, 1));
m_dc->dimRect(twRect(rt2.x, rt2.y+rt2.h, rt2.w, 1));
}