qdistancefield.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qdistancefield.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtDeclarative module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qdistancefield_p.h"-
35#include <qmath.h>-
36#include <private/qdatabuffer_p.h>-
37#include <private/qimage_p.h>-
38#include <private/qpathsimplifier_p.h>-
39-
40QT_BEGIN_NAMESPACE-
41-
42namespace-
43{-
44 enum FillHDir-
45 {-
46 LeftToRight,-
47 RightToLeft-
48 };-
49-
50 enum FillVDir-
51 {-
52 TopDown,-
53 BottomUp-
54 };-
55-
56 enum FillClip-
57 {-
58 NoClip,-
59 Clip-
60 };-
61}-
62-
63template <FillClip clip, FillHDir dir>-
64inline void fillLine(qint32 *, int, int, int, qint32, qint32)-
65{-
66}-
67-
68template <>-
69inline void fillLine<Clip, LeftToRight>(qint32 *line, int width, int lx, int rx, qint32 d, qint32 dd)-
70{-
71 int fromX = qMax(0, lx >> 8);-
72 int toX = qMin(width, rx >> 8);-
73 int x = toX - fromX;-
74 if (x <= 0)
x <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
75 return;
never executed: return;
0
76 qint32 val = d + (((fromX << 8) + 0xff - lx) * dd >> 8);-
77 line += fromX;-
78 do {-
79 *line = abs(val) < abs(*line) ? val : *line;
abs(val) < abs(*line)Description
TRUEnever evaluated
FALSEnever evaluated
0
80 val += dd;-
81 ++line;-
82 } while (--x);
never executed: end of block
--xDescription
TRUEnever evaluated
FALSEnever evaluated
0
83}
never executed: end of block
0
84-
85template <>-
86inline void fillLine<Clip, RightToLeft>(qint32 *line, int width, int lx, int rx, qint32 d, qint32 dd)-
87{-
88 int fromX = qMax(0, lx >> 8);-
89 int toX = qMin(width, rx >> 8);-
90 int x = toX - fromX;-
91 if (x <= 0)
x <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
92 return;
never executed: return;
0
93 qint32 val = d + (((toX << 8) + 0xff - rx) * dd >> 8);-
94 line += toX;-
95 do {-
96 val -= dd;-
97 --line;-
98 *line = abs(val) < abs(*line) ? val : *line;
abs(val) < abs(*line)Description
TRUEnever evaluated
FALSEnever evaluated
0
99 } while (--x);
never executed: end of block
--xDescription
TRUEnever evaluated
FALSEnever evaluated
0
100}
never executed: end of block
0
101-
102template <>-
103inline void fillLine<NoClip, LeftToRight>(qint32 *line, int, int lx, int rx, qint32 d, qint32 dd)-
104{-
105 int fromX = lx >> 8;-
106 int toX = rx >> 8;-
107 int x = toX - fromX;-
108 if (x <= 0)
x <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
109 return;
never executed: return;
0
110 qint32 val = d + ((~lx & 0xff) * dd >> 8);-
111 line += fromX;-
112 do {-
113 *line = abs(val) < abs(*line) ? val : *line;
abs(val) < abs(*line)Description
TRUEnever evaluated
FALSEnever evaluated
0
114 val += dd;-
115 ++line;-
116 } while (--x);
never executed: end of block
--xDescription
TRUEnever evaluated
FALSEnever evaluated
0
117}
never executed: end of block
0
118-
119template <>-
120inline void fillLine<NoClip, RightToLeft>(qint32 *line, int, int lx, int rx, qint32 d, qint32 dd)-
121{-
122 int fromX = lx >> 8;-
123 int toX = rx >> 8;-
124 int x = toX - fromX;-
125 if (x <= 0)
x <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
126 return;
never executed: return;
0
127 qint32 val = d + ((~rx & 0xff) * dd >> 8);-
128 line += toX;-
129 do {-
130 val -= dd;-
131 --line;-
132 *line = abs(val) < abs(*line) ? val : *line;
abs(val) < abs(*line)Description
TRUEnever evaluated
FALSEnever evaluated
0
133 } while (--x);
never executed: end of block
--xDescription
TRUEnever evaluated
FALSEnever evaluated
0
134}
never executed: end of block
0
135-
136template <FillClip clip, FillVDir vDir, FillHDir hDir>-
137inline void fillLines(qint32 *bits, int width, int height, int upperY, int lowerY,-
138 int &lx, int ldx, int &rx, int rdx, qint32 &d, qint32 ddy, qint32 ddx)-
139{-
140 Q_UNUSED(height);-
141 Q_ASSERT(upperY < lowerY);-
142 int y = lowerY - upperY;-
143 if (vDir == TopDown) {
vDir == TopDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
144 qint32 *line = bits + upperY * width;-
145 do {-
146 fillLine<clip, hDir>(line, width, lx, rx, d, ddx);-
147 lx += ldx;-
148 d += ddy;-
149 rx += rdx;-
150 line += width;-
151 } while (--y);
never executed: end of block
--yDescription
TRUEnever evaluated
FALSEnever evaluated
0
152 } else {
never executed: end of block
0
153 qint32 *line = bits + lowerY * width;-
154 do {-
155 lx -= ldx;-
156 d -= ddy;-
157 rx -= rdx;-
158 line -= width;-
159 fillLine<clip, hDir>(line, width, lx, rx, d, ddx);-
160 } while (--y);
never executed: end of block
--yDescription
TRUEnever evaluated
FALSEnever evaluated
0
161 }
never executed: end of block
0
162}-
163-
164template <FillClip clip>-
165void drawTriangle(qint32 *bits, int width, int height, const QPoint *center,-
166 const QPoint *v1, const QPoint *v2, qint32 value)-
167{-
168 const int y1 = clip == Clip ? qBound(0, v1->y() >> 8, height) : v1->y() >> 8;-
169 const int y2 = clip == Clip ? qBound(0, v2->y() >> 8, height) : v2->y() >> 8;-
170 const int yC = clip == Clip ? qBound(0, center->y() >> 8, height) : center->y() >> 8;-
171-
172 const int v1Frac = clip == Clip ? (y1 << 8) + 0xff - v1->y() : ~v2->y() & 0xff;-
173 const int v2Frac = clip == Clip ? (y2 << 8) + 0xff - v2->y() : ~v1->y() & 0xff;-
174 const int centerFrac = clip == Clip ? (yC << 8) + 0xff - center->y() : ~center->y() & 0xff;-
175-
176 int dx1 = 0, x1 = 0, dx2 = 0, x2 = 0;-
177 qint32 dd1, d1, dd2, d2;-
178 if (v1->y() != center->y()) {
v1->y() != center->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
179 dx1 = ((v1->x() - center->x()) << 8) / (v1->y() - center->y());-
180 x1 = center->x() + centerFrac * (v1->x() - center->x()) / (v1->y() - center->y());-
181 }
never executed: end of block
0
182 if (v2->y() != center->y()) {
v2->y() != center->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
183 dx2 = ((v2->x() - center->x()) << 8) / (v2->y() - center->y());-
184 x2 = center->x() + centerFrac * (v2->x() - center->x()) / (v2->y() - center->y());-
185 }
never executed: end of block
0
186-
187 const qint32 div = (v2->x() - center->x()) * (v1->y() - center->y())-
188 - (v2->y() - center->y()) * (v1->x() - center->x());-
189 const qint32 dd = div ? qint32((qint64(value * (v1->y() - v2->y())) << 8) / div) : 0;-
190-
191 if (y2 < yC) {
y2 < yCDescription
TRUEnever evaluated
FALSEnever evaluated
0
192 if (y1 < yC) {
y1 < yCDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 // Center at the bottom.-
194 if (y2 < y1) {
y2 < y1Description
TRUEnever evaluated
FALSEnever evaluated
0
195 // y2 < y1 < yC-
196 // Long right edge.-
197 d1 = centerFrac * value / (v1->y() - center->y());-
198 dd1 = ((value << 8) / (v1->y() - center->y()));-
199 fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y1, yC, x1, dx1,-
200 x2, dx2, d1, dd1, dd);-
201 dx1 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
202 x1 = v1->x() + v1Frac * (v1->x() - v2->x()) / (v1->y() - v2->y());-
203 fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y2, y1, x1, dx1,-
204 x2, dx2, value, 0, dd);-
205 } else {
never executed: end of block
0
206 // y1 <= y2 < yC-
207 // Long left edge.-
208 d2 = centerFrac * value / (v2->y() - center->y());-
209 dd2 = ((value << 8) / (v2->y() - center->y()));-
210 fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y2, yC, x1, dx1,-
211 x2, dx2, d2, dd2, dd);-
212 if (y1 != y2) {
y1 != y2Description
TRUEnever evaluated
FALSEnever evaluated
0
213 dx2 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
214 x2 = v2->x() + v2Frac * (v1->x() - v2->x()) / (v1->y() - v2->y());-
215 fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y1, y2, x1, dx1,-
216 x2, dx2, value, 0, dd);-
217 }
never executed: end of block
0
218 }
never executed: end of block
0
219 } else {-
220 // y2 < yC <= y1-
221 // Center to the right.-
222 int dx = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
223 int xUp, xDn;-
224 xUp = xDn = v2->x() + (clip == Clip ? (yC << 8) + 0xff - v2->y()
clip == ClipDescription
TRUEnever evaluated
FALSEnever evaluated
0
225 : (center->y() | 0xff) - v2->y())-
226 * (v1->x() - v2->x()) / (v1->y() - v2->y());-
227 fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y2, yC, xUp, dx,-
228 x2, dx2, value, 0, dd);-
229 if (yC != y1)
yC != y1Description
TRUEnever evaluated
FALSEnever evaluated
0
230 fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y1, xDn, dx,
never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y1, xDn, dx, x1, dx1, value, 0, dd);
0
231 x1, dx1, value, 0, dd);
never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y1, xDn, dx, x1, dx1, value, 0, dd);
0
232 }
never executed: end of block
0
233 } else {-
234 if (y1 < yC) {
y1 < yCDescription
TRUEnever evaluated
FALSEnever evaluated
0
235 // y1 < yC <= y2-
236 // Center to the left.-
237 int dx = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
238 int xUp, xDn;-
239 xUp = xDn = v1->x() + (clip == Clip ? (yC << 8) + 0xff - v1->y()
clip == ClipDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 : (center->y() | 0xff) - v1->y())-
241 * (v1->x() - v2->x()) / (v1->y() - v2->y());-
242 fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y1, yC, x1, dx1,-
243 xUp, dx, value, 0, dd);-
244 if (yC != y2)
yC != y2Description
TRUEnever evaluated
FALSEnever evaluated
0
245 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y2, x2, dx2,
never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y2, x2, dx2, xDn, dx, value, 0, dd);
0
246 xDn, dx, value, 0, dd);
never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y2, x2, dx2, xDn, dx, value, 0, dd);
0
247 } else {
never executed: end of block
0
248 // Center at the top.-
249 if (y2 < y1) {
y2 < y1Description
TRUEnever evaluated
FALSEnever evaluated
0
250 // yC <= y2 < y1-
251 // Long right edge.-
252 if (yC != y2) {
yC != y2Description
TRUEnever evaluated
FALSEnever evaluated
0
253 d2 = centerFrac * value / (v2->y() - center->y());-
254 dd2 = ((value << 8) / (v2->y() - center->y()));-
255 fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y2, x2, dx2,-
256 x1, dx1, d2, dd2, dd);-
257 }
never executed: end of block
0
258 dx2 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
259 x2 = v2->x() + v2Frac * (v1->x() - v2->x()) / (v1->y() - v2->y());-
260 fillLines<clip, TopDown, LeftToRight>(bits, width, height, y2, y1, x2, dx2,-
261 x1, dx1, value, 0, dd);-
262 } else {
never executed: end of block
0
263 // Long left edge.-
264 // yC <= y1 <= y2-
265 if (yC != y1) {
yC != y1Description
TRUEnever evaluated
FALSEnever evaluated
0
266 d1 = centerFrac * value / (v1->y() - center->y());-
267 dd1 = ((value << 8) / (v1->y() - center->y()));-
268 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y1, x2, dx2,-
269 x1, dx1, d1, dd1, dd);-
270 }
never executed: end of block
0
271 if (y1 != y2) {
y1 != y2Description
TRUEnever evaluated
FALSEnever evaluated
0
272 dx1 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y());-
273 x1 = v1->x() + v1Frac * (v1->x() - v2->x()) / (v1->y() - v2->y());-
274 fillLines<clip, TopDown, RightToLeft>(bits, width, height, y1, y2, x2, dx2,-
275 x1, dx1, value, 0, dd);-
276 }
never executed: end of block
0
277 }
never executed: end of block
0
278 }-
279 }-
280}-
281-
282template <FillClip clip>-
283void drawRectangle(qint32 *bits, int width, int height,-
284 const QPoint *int1, const QPoint *center1, const QPoint *ext1,-
285 const QPoint *int2, const QPoint *center2, const QPoint *ext2,-
286 qint32 extValue)-
287{-
288 if (center1->y() > center2->y()) {
center1->y() > center2->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
289 qSwap(center1, center2);-
290 qSwap(int1, ext2);-
291 qSwap(ext1, int2);-
292 extValue = -extValue;-
293 }
never executed: end of block
0
294-
295 Q_ASSERT(ext1->x() - center1->x() == center1->x() - int1->x());-
296 Q_ASSERT(ext1->y() - center1->y() == center1->y() - int1->y());-
297 Q_ASSERT(ext2->x() - center2->x() == center2->x() - int2->x());-
298 Q_ASSERT(ext2->y() - center2->y() == center2->y() - int2->y());-
299-
300 const int yc1 = clip == Clip ? qBound(0, center1->y() >> 8, height) : center1->y() >> 8;-
301 const int yc2 = clip == Clip ? qBound(0, center2->y() >> 8, height) : center2->y() >> 8;-
302 const int yi1 = clip == Clip ? qBound(0, int1->y() >> 8, height) : int1->y() >> 8;-
303 const int yi2 = clip == Clip ? qBound(0, int2->y() >> 8, height) : int2->y() >> 8;-
304 const int ye1 = clip == Clip ? qBound(0, ext1->y() >> 8, height) : ext1->y() >> 8;-
305 const int ye2 = clip == Clip ? qBound(0, ext2->y() >> 8, height) : ext2->y() >> 8;-
306-
307 const int center1Frac = clip == Clip ? (yc1 << 8) + 0xff - center1->y() : ~center1->y() & 0xff;-
308 const int center2Frac = clip == Clip ? (yc2 << 8) + 0xff - center2->y() : ~center2->y() & 0xff;-
309 const int int1Frac = clip == Clip ? (yi1 << 8) + 0xff - int1->y() : ~int1->y() & 0xff;-
310 const int ext1Frac = clip == Clip ? (ye1 << 8) + 0xff - ext1->y() : ~ext1->y() & 0xff;-
311-
312 int dxC = 0, dxE = 0; // cap slope, edge slope-
313 qint32 ddC = 0;-
314 if (ext1->y() != int1->y()) {
ext1->y() != int1->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
315 dxC = ((ext1->x() - int1->x()) << 8) / (ext1->y() - int1->y());-
316 ddC = (extValue << 9) / (ext1->y() - int1->y());-
317 }
never executed: end of block
0
318 if (ext1->y() != ext2->y())
ext1->y() != ext2->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
319 dxE = ((ext1->x() - ext2->x()) << 8) / (ext1->y() - ext2->y());
never executed: dxE = ((ext1->x() - ext2->x()) << 8) / (ext1->y() - ext2->y());
0
320-
321 const qint32 div = (ext1->x() - int1->x()) * (ext2->y() - int1->y())-
322 - (ext1->y() - int1->y()) * (ext2->x() - int1->x());-
323 const qint32 dd = div ? qint32((qint64(extValue * (ext2->y() - ext1->y())) << 9) / div) : 0;-
324-
325 int xe1, xe2, xc1, xc2;-
326 qint32 d;-
327-
328 qint32 intValue = -extValue;-
329-
330 if (center2->x() < center1->x()) {
center2->x() < center1->x()Description
TRUEnever evaluated
FALSEnever evaluated
0
331 // Leaning to the right. '/'-
332 if (int1->y() < ext2->y()) {
int1->y() < ext2->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
333 // Mostly vertical.-
334 Q_ASSERT(ext1->y() != ext2->y());-
335 xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
336 xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
337 if (ye1 != yi1) {
ye1 != yi1Description
TRUEnever evaluated
FALSEnever evaluated
0
338 xc2 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
339 xc2 += (ye1 - yc1) * dxC;-
340 fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, yi1, xe1, dxE,-
341 xc2, dxC, extValue, 0, dd);-
342 }
never executed: end of block
0
343 if (yi1 != ye2)
yi1 != ye2Description
TRUEnever evaluated
FALSEnever evaluated
0
344 fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi1, ye2, xe1, dxE,
never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi1, ye2, xe1, dxE, xe2, dxE, extValue, 0, dd);
0
345 xe2, dxE, extValue, 0, dd);
never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi1, ye2, xe1, dxE, xe2, dxE, extValue, 0, dd);
0
346 if (ye2 != yi2) {
ye2 != yi2Description
TRUEnever evaluated
FALSEnever evaluated
0
347 xc1 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
348 xc1 += (ye2 - yc2) * dxC;-
349 fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye2, yi2, xc1, dxC,-
350 xe2, dxE, intValue, 0, dd);-
351 }
never executed: end of block
0
352 } else {
never executed: end of block
0
353 // Mostly horizontal.-
354 Q_ASSERT(ext1->y() != int1->y());-
355 xc1 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
356 xc2 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
357 xc1 += (ye2 - yc2) * dxC;-
358 xc2 += (ye1 - yc1) * dxC;-
359 if (ye1 != ye2) {
ye1 != ye2Description
TRUEnever evaluated
FALSEnever evaluated
0
360 xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
361 fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, ye2, xe1, dxE,-
362 xc2, dxC, extValue, 0, dd);-
363 }
never executed: end of block
0
364 if (ye2 != yi1) {
ye2 != yi1Description
TRUEnever evaluated
FALSEnever evaluated
0
365 d = (clip == Clip ? (ye2 << 8) + 0xff - center2->y()
clip == ClipDescription
TRUEnever evaluated
FALSEnever evaluated
0
366 : (ext2->y() | 0xff) - center2->y())-
367 * 2 * extValue / (ext1->y() - int1->y());-
368 fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye2, yi1, xc1, dxC,-
369 xc2, dxC, d, ddC, dd);-
370 }
never executed: end of block
0
371 if (yi1 != yi2) {
yi1 != yi2Description
TRUEnever evaluated
FALSEnever evaluated
0
372 xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
373 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, yi2, xc1, dxC,-
374 xe2, dxE, intValue, 0, dd);-
375 }
never executed: end of block
0
376 }
never executed: end of block
0
377 } else {-
378 // Leaning to the left. '\'-
379 if (ext1->y() < int2->y()) {
ext1->y() < int2->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
380 // Mostly vertical.-
381 Q_ASSERT(ext1->y() != ext2->y());-
382 xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
383 xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
384 if (yi1 != ye1) {
yi1 != ye1Description
TRUEnever evaluated
FALSEnever evaluated
0
385 xc1 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
386 xc1 += (yi1 - yc1) * dxC;-
387 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, ye1, xc1, dxC,-
388 xe2, dxE, intValue, 0, dd);-
389 }
never executed: end of block
0
390 if (ye1 != yi2)
ye1 != yi2Description
TRUEnever evaluated
FALSEnever evaluated
0
391 fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye1, yi2, xe1, dxE,
never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye1, yi2, xe1, dxE, xe2, dxE, intValue, 0, dd);
0
392 xe2, dxE, intValue, 0, dd);
never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye1, yi2, xe1, dxE, xe2, dxE, intValue, 0, dd);
0
393 if (yi2 != ye2) {
yi2 != ye2Description
TRUEnever evaluated
FALSEnever evaluated
0
394 xc2 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
395 xc2 += (yi2 - yc2) * dxC;-
396 fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi2, ye2, xe1, dxE,-
397 xc2, dxC, extValue, 0, dd);-
398 }
never executed: end of block
0
399 } else {
never executed: end of block
0
400 // Mostly horizontal.-
401 Q_ASSERT(ext1->y() != int1->y());-
402 xc1 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
403 xc2 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y());-
404 xc1 += (yi1 - yc1) * dxC;-
405 xc2 += (yi2 - yc2) * dxC;-
406 if (yi1 != yi2) {
yi1 != yi2Description
TRUEnever evaluated
FALSEnever evaluated
0
407 xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
408 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, yi2, xc1, dxC,-
409 xe2, dxE, intValue, 0, dd);-
410 }
never executed: end of block
0
411 if (yi2 != ye1) {
yi2 != ye1Description
TRUEnever evaluated
FALSEnever evaluated
0
412 d = (clip == Clip ? (yi2 << 8) + 0xff - center2->y()
clip == ClipDescription
TRUEnever evaluated
FALSEnever evaluated
0
413 : (int2->y() | 0xff) - center2->y())-
414 * 2 * extValue / (ext1->y() - int1->y());-
415 fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi2, ye1, xc1, dxC,-
416 xc2, dxC, d, ddC, dd);-
417 }
never executed: end of block
0
418 if (ye1 != ye2) {
ye1 != ye2Description
TRUEnever evaluated
FALSEnever evaluated
0
419 xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y());-
420 fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, ye2, xe1, dxE,-
421 xc2, dxC, extValue, 0, dd);-
422 }
never executed: end of block
0
423 }
never executed: end of block
0
424 }-
425}-
426-
427static void drawPolygons(qint32 *bits, int width, int height, const QPoint *vertices,-
428 const quint32 *indices, int indexCount, qint32 value)-
429{-
430 Q_ASSERT(indexCount != 0);-
431 typedef QVarLengthArray<quint8, 16> ScanLine;-
432 QVarLengthArray<ScanLine, 128> scans(height);-
433 int first = 0;-
434 for (int i = 1; i < indexCount; ++i) {
i < indexCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
435 quint32 idx1 = indices[i - 1];-
436 quint32 idx2 = indices[i];-
437 Q_ASSERT(idx1 != quint32(-1));-
438 if (idx2 == quint32(-1)) {
idx2 == quint32(-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
439 idx2 = indices[first];-
440 Q_ASSERT(idx2 != quint32(-1));-
441 first = ++i;-
442 }
never executed: end of block
0
443 const QPoint *v1 = &vertices[idx1];-
444 const QPoint *v2 = &vertices[idx2];-
445 if (v2->y() < v1->y())
v2->y() < v1->y()Description
TRUEnever evaluated
FALSEnever evaluated
0
446 qSwap(v1, v2);
never executed: qSwap(v1, v2);
0
447 int fromY = qMax(0, v1->y() >> 8);-
448 int toY = qMin(height, v2->y() >> 8);-
449 if (fromY >= toY)
fromY >= toYDescription
TRUEnever evaluated
FALSEnever evaluated
0
450 continue;
never executed: continue;
0
451 int dx = ((v2->x() - v1->x()) << 8) / (v2->y() - v1->y());-
452 int x = v1->x() + ((fromY << 8) + 0xff - v1->y()) * (v2->x() - v1->x()) / (v2->y() - v1->y());-
453 for (int y = fromY; y < toY; ++y) {
y < toYDescription
TRUEnever evaluated
FALSEnever evaluated
0
454 quint32 c = quint32(x >> 8);-
455 if (c < quint32(width))
c < quint32(width)Description
TRUEnever evaluated
FALSEnever evaluated
0
456 scans[y].append(quint8(c));
never executed: scans[y].append(quint8(c));
0
457 x += dx;-
458 }
never executed: end of block
0
459 }
never executed: end of block
0
460 for (int i = 0; i < height; ++i) {
i < heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
461 quint8 *scanline = scans[i].data();-
462 int size = scans[i].size();-
463 for (int j = 1; j < size; ++j) {
j < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
464 int k = j;-
465 quint8 value = scanline[k];-
466 for (; k != 0 && value < scanline[k - 1]; --k)
k != 0Description
TRUEnever evaluated
FALSEnever evaluated
value < scanline[k - 1]Description
TRUEnever evaluated
FALSEnever evaluated
0
467 scanline[k] = scanline[k - 1];
never executed: scanline[k] = scanline[k - 1];
0
468 scanline[k] = value;-
469 }
never executed: end of block
0
470 qint32 *line = bits + i * width;-
471 int j = 0;-
472 for (; j + 1 < size; j += 2) {
j + 1 < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
473 for (quint8 x = scanline[j]; x < scanline[j + 1]; ++x)
x < scanline[j + 1]Description
TRUEnever evaluated
FALSEnever evaluated
0
474 line[x] = value;
never executed: line[x] = value;
0
475 }
never executed: end of block
0
476 if (j < size) {
j < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
477 for (int x = scanline[j]; x < width; ++x)
x < widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
478 line[x] = value;
never executed: line[x] = value;
0
479 }
never executed: end of block
0
480 }
never executed: end of block
0
481}
never executed: end of block
0
482-
483static void makeDistanceField(QDistanceFieldData *data, const QPainterPath &path, int dfScale, int offs)-
484{-
485 if (!data || !data->data)
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
!data->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
486 return;
never executed: return;
0
487-
488 if (path.isEmpty()) {
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
489 memset(data->data, 0, data->nbytes);-
490 return;
never executed: return;
0
491 }-
492-
493 int imgWidth = data->width;-
494 int imgHeight = data->height;-
495-
496 QTransform transform;-
497 transform.translate(offs, offs);-
498 transform.scale(qreal(1) / dfScale, qreal(1) / dfScale);-
499-
500 QDataBuffer<quint32> pathIndices(0);-
501 QDataBuffer<QPoint> pathVertices(0);-
502 qSimplifyPath(path, pathVertices, pathIndices, transform);-
503-
504 const qint32 interiorColor = -0x7f80; // 8:8 signed format, -127.5-
505 const qint32 exteriorColor = 0x7f80; // 8:8 signed format, 127.5-
506-
507 QScopedArrayPointer<qint32> bits(new qint32[imgWidth * imgHeight]);-
508 for (int i = 0; i < imgWidth * imgHeight; ++i)
i < imgWidth * imgHeightDescription
TRUEnever evaluated
FALSEnever evaluated
0
509 bits[i] = exteriorColor;
never executed: bits[i] = exteriorColor;
0
510-
511 const qreal angleStep = qreal(15 * 3.141592653589793238 / 180);-
512 const QPoint rotation(qRound(qCos(angleStep) * 0x4000),-
513 qRound(qSin(angleStep) * 0x4000)); // 2:14 signed-
514-
515 const quint32 *indices = pathIndices.data();-
516 QVarLengthArray<QPoint> normals;-
517 QVarLengthArray<QPoint> vertices;-
518 QVarLengthArray<bool> isConvex;-
519 QVarLengthArray<bool> needsClipping;-
520-
521 drawPolygons(bits.data(), imgWidth, imgHeight, pathVertices.data(),-
522 indices, pathIndices.size(), interiorColor);-
523-
524 int index = 0;-
525-
526 while (index < pathIndices.size()) {
index < pathIndices.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
527 normals.clear();-
528 vertices.clear();-
529 needsClipping.clear();-
530-
531 // Find end of polygon.-
532 int end = index;-
533 while (indices[end] != quint32(-1))
indices[end] != quint32(-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
534 ++end;
never executed: ++end;
0
535-
536 // Calculate vertex normals.-
537 for (int next = index, prev = end - 1; next < end; prev = next++) {
next < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
538 quint32 fromVertexIndex = indices[prev];-
539 quint32 toVertexIndex = indices[next];-
540-
541 const QPoint &from = pathVertices.at(fromVertexIndex);-
542 const QPoint &to = pathVertices.at(toVertexIndex);-
543-
544 QPoint n(to.y() - from.y(), from.x() - to.x());-
545 if (n.x() == 0 && n.y() == 0)
n.x() == 0Description
TRUEnever evaluated
FALSEnever evaluated
n.y() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
546 continue;
never executed: continue;
0
547 int scale = qRound((offs << 16) / qSqrt(qreal(n.x()) * n.x() + qreal(n.y()) * n.y())); // 8:16-
548 Q_ASSERT(scale != 0);-
549-
550 n.rx() = n.x() * scale >> 8;-
551 n.ry() = n.y() * scale >> 8;-
552 normals.append(n);-
553 QPoint v(to.x() + 0x7f, to.y() + 0x7f);-
554 vertices.append(v);-
555 needsClipping.append((to.x() < offs << 8) || (to.x() >= (imgWidth - offs) << 8)-
556 || (to.y() < offs << 8) || (to.y() >= (imgHeight - offs) << 8));-
557 }
never executed: end of block
0
558-
559 isConvex.resize(normals.count());-
560 for (int next = 0, prev = normals.count() - 1; next < normals.count(); prev = next++) {
next < normals.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
561 isConvex[prev] = normals.at(prev).x() * normals.at(next).y()-
562 - normals.at(prev).y() * normals.at(next).x() < 0;-
563 }
never executed: end of block
0
564-
565 // Draw quads.-
566 for (int next = 0, prev = normals.count() - 1; next < normals.count(); prev = next++) {
next < normals.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
567 QPoint n = normals.at(next);-
568 QPoint intPrev = vertices.at(prev);-
569 QPoint extPrev = vertices.at(prev);-
570 QPoint intNext = vertices.at(next);-
571 QPoint extNext = vertices.at(next);-
572-
573 extPrev.rx() -= n.x();-
574 extPrev.ry() -= n.y();-
575 intPrev.rx() += n.x();-
576 intPrev.ry() += n.y();-
577 extNext.rx() -= n.x();-
578 extNext.ry() -= n.y();-
579 intNext.rx() += n.x();-
580 intNext.ry() += n.y();-
581-
582 if (needsClipping[prev] || needsClipping[next]) {
needsClipping[prev]Description
TRUEnever evaluated
FALSEnever evaluated
needsClipping[next]Description
TRUEnever evaluated
FALSEnever evaluated
0
583 drawRectangle<Clip>(bits.data(), imgWidth, imgHeight,-
584 &intPrev, &vertices.at(prev), &extPrev,-
585 &intNext, &vertices.at(next), &extNext,-
586 exteriorColor);-
587 } else {
never executed: end of block
0
588 drawRectangle<NoClip>(bits.data(), imgWidth, imgHeight,-
589 &intPrev, &vertices.at(prev), &extPrev,-
590 &intNext, &vertices.at(next), &extNext,-
591 exteriorColor);-
592 }
never executed: end of block
0
593-
594 if (isConvex.at(prev)) {
isConvex.at(prev)Description
TRUEnever evaluated
FALSEnever evaluated
0
595 QPoint p = extPrev;-
596 if (needsClipping[prev]) {
needsClipping[prev]Description
TRUEnever evaluated
FALSEnever evaluated
0
597 for (;;) {-
598 QPoint rn((n.x() * rotation.x() - n.y() * rotation.y()) >> 14,-
599 (n.y() * rotation.x() + n.x() * rotation.y()) >> 14);-
600 n = rn;-
601 if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0) {
n.x() * normal...prev).x() <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
602 p.rx() = vertices.at(prev).x() - normals.at(prev).x();-
603 p.ry() = vertices.at(prev).y() - normals.at(prev).y();-
604 drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
605 &extPrev, &p, exteriorColor);-
606 break;
never executed: break;
0
607 }-
608-
609 p.rx() = vertices.at(prev).x() - n.x();-
610 p.ry() = vertices.at(prev).y() - n.y();-
611 drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
612 &extPrev, &p, exteriorColor);-
613 extPrev = p;-
614 }
never executed: end of block
0
615 } else {
never executed: end of block
0
616 for (;;) {-
617 QPoint rn((n.x() * rotation.x() - n.y() * rotation.y()) >> 14,-
618 (n.y() * rotation.x() + n.x() * rotation.y()) >> 14);-
619 n = rn;-
620 if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0) {
n.x() * normal...prev).x() <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
621 p.rx() = vertices.at(prev).x() - normals.at(prev).x();-
622 p.ry() = vertices.at(prev).y() - normals.at(prev).y();-
623 drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
624 &extPrev, &p, exteriorColor);-
625 break;
never executed: break;
0
626 }-
627-
628 p.rx() = vertices.at(prev).x() - n.x();-
629 p.ry() = vertices.at(prev).y() - n.y();-
630 drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
631 &extPrev, &p, exteriorColor);-
632 extPrev = p;-
633 }
never executed: end of block
0
634 }
never executed: end of block
0
635 } else {-
636 QPoint p = intPrev;-
637 if (needsClipping[prev]) {
needsClipping[prev]Description
TRUEnever evaluated
FALSEnever evaluated
0
638 for (;;) {-
639 QPoint rn((n.x() * rotation.x() + n.y() * rotation.y()) >> 14,-
640 (n.y() * rotation.x() - n.x() * rotation.y()) >> 14);-
641 n = rn;-
642 if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0) {
n.x() * normal...prev).x() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
643 p.rx() = vertices.at(prev).x() + normals.at(prev).x();-
644 p.ry() = vertices.at(prev).y() + normals.at(prev).y();-
645 drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
646 &p, &intPrev, interiorColor);-
647 break;
never executed: break;
0
648 }-
649-
650 p.rx() = vertices.at(prev).x() + n.x();-
651 p.ry() = vertices.at(prev).y() + n.y();-
652 drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
653 &p, &intPrev, interiorColor);-
654 intPrev = p;-
655 }
never executed: end of block
0
656 } else {
never executed: end of block
0
657 for (;;) {-
658 QPoint rn((n.x() * rotation.x() + n.y() * rotation.y()) >> 14,-
659 (n.y() * rotation.x() - n.x() * rotation.y()) >> 14);-
660 n = rn;-
661 if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0) {
n.x() * normal...prev).x() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
662 p.rx() = vertices.at(prev).x() + normals.at(prev).x();-
663 p.ry() = vertices.at(prev).y() + normals.at(prev).y();-
664 drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
665 &p, &intPrev, interiorColor);-
666 break;
never executed: break;
0
667 }-
668-
669 p.rx() = vertices.at(prev).x() + n.x();-
670 p.ry() = vertices.at(prev).y() + n.y();-
671 drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev),-
672 &p, &intPrev, interiorColor);-
673 intPrev = p;-
674 }
never executed: end of block
0
675 }
never executed: end of block
0
676 }-
677 }-
678-
679 index = end + 1;-
680 }
never executed: end of block
0
681-
682 const qint32 *inLine = bits.data();-
683 uchar *outLine = data->data;-
684 for (int y = 0; y < imgHeight; ++y) {
y < imgHeightDescription
TRUEnever evaluated
FALSEnever evaluated
0
685 for (int x = 0; x < imgWidth; ++x, ++inLine, ++outLine)
x < imgWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
686 *outLine = uchar((0x7f80 - *inLine) >> 8);
never executed: *outLine = uchar((0x7f80 - *inLine) >> 8);
0
687 }
never executed: end of block
0
688}
never executed: end of block
0
689-
690static bool imageHasNarrowOutlines(const QImage &im)-
691{-
692 if (im.isNull() || im.width() < 1 || im.height() < 1)
im.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
im.width() < 1Description
TRUEnever evaluated
FALSEnever evaluated
im.height() < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
693 return false;
never executed: return false;
0
694 else if (im.width() == 1 || im.height() == 1)
im.width() == 1Description
TRUEnever evaluated
FALSEnever evaluated
im.height() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
695 return true;
never executed: return true;
0
696-
697 int minHThick = 999;-
698 int minVThick = 999;-
699-
700 int thick = 0;-
701 bool in = false;-
702 int y = (im.height() + 1) / 2;-
703 for (int x = 0; x < im.width(); ++x) {
x < im.width()Description
TRUEnever evaluated
FALSEnever evaluated
0
704 int a = qAlpha(im.pixel(x, y));-
705 if (a > 127) {
a > 127Description
TRUEnever evaluated
FALSEnever evaluated
0
706 in = true;-
707 ++thick;-
708 } else if (in) {
never executed: end of block
inDescription
TRUEnever evaluated
FALSEnever evaluated
0
709 in = false;-
710 minHThick = qMin(minHThick, thick);-
711 thick = 0;-
712 }
never executed: end of block
0
713 }
never executed: end of block
0
714-
715 thick = 0;-
716 in = false;-
717 int x = (im.width() + 1) / 2;-
718 for (int y = 0; y < im.height(); ++y) {
y < im.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
719 int a = qAlpha(im.pixel(x, y));-
720 if (a > 127) {
a > 127Description
TRUEnever evaluated
FALSEnever evaluated
0
721 in = true;-
722 ++thick;-
723 } else if (in) {
never executed: end of block
inDescription
TRUEnever evaluated
FALSEnever evaluated
0
724 in = false;-
725 minVThick = qMin(minVThick, thick);-
726 thick = 0;-
727 }
never executed: end of block
0
728 }
never executed: end of block
0
729-
730 return minHThick == 1 || minVThick == 1;
never executed: return minHThick == 1 || minVThick == 1;
minHThick == 1Description
TRUEnever evaluated
FALSEnever evaluated
minVThick == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
731}-
732-
733bool qt_fontHasNarrowOutlines(QFontEngine *fontEngine)-
734{-
735 QFontEngine *fe = fontEngine->cloneWithSize(QT_DISTANCEFIELD_DEFAULT_BASEFONTSIZE);-
736 if (!fe)
!feDescription
TRUEnever evaluated
FALSEnever evaluated
0
737 return false;
never executed: return false;
0
738-
739 QImage im;-
740-
741 const glyph_t glyph = fe->glyphIndex('O');-
742 if (glyph != 0)
glyph != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
743 im = fe->alphaMapForGlyph(glyph, QFixed(), QTransform());
never executed: im = fe->alphaMapForGlyph(glyph, QFixed(), QTransform());
0
744-
745 Q_ASSERT(fe->ref.load() == 0);-
746 delete fe;-
747-
748 return imageHasNarrowOutlines(im);
never executed: return imageHasNarrowOutlines(im);
0
749}-
750-
751bool qt_fontHasNarrowOutlines(const QRawFont &f)-
752{-
753 QRawFont font = f;-
754 font.setPixelSize(QT_DISTANCEFIELD_DEFAULT_BASEFONTSIZE);-
755 if (!font.isValid())
!font.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
756 return false;
never executed: return false;
0
757-
758 QVector<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("O"));-
759 if (glyphIndices.isEmpty() || glyphIndices[0] == 0)
glyphIndices.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
glyphIndices[0] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
760 return false;
never executed: return false;
0
761-
762 return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0),
never executed: return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0), QRawFont::PixelAntialiasing));
0
763 QRawFont::PixelAntialiasing));
never executed: return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0), QRawFont::PixelAntialiasing));
0
764}-
765-
766-
767QDistanceFieldData::QDistanceFieldData(const QDistanceFieldData &other)-
768 : QSharedData(other)-
769 , glyph(other.glyph)-
770 , width(other.width)-
771 , height(other.height)-
772 , nbytes(other.nbytes)-
773{-
774 if (nbytes && other.data)
nbytesDescription
TRUEnever evaluated
FALSEnever evaluated
other.dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
775 data = (uchar *)memcpy(malloc(nbytes), other.data, nbytes);
never executed: data = (uchar *)memcpy(malloc(nbytes), other.data, nbytes);
0
776 else-
777 data = 0;
never executed: data = 0;
0
778}-
779-
780QDistanceFieldData::~QDistanceFieldData()-
781{-
782 free(data);-
783}
never executed: end of block
0
784-
785QDistanceFieldData *QDistanceFieldData::create(const QSize &size)-
786{-
787 QDistanceFieldData *data = new QDistanceFieldData;-
788-
789 if (size.isValid()) {
size.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
790 data->width = size.width();-
791 data->height = size.height();-
792 // pixel data stored as a 1-byte alpha value-
793 data->nbytes = data->width * data->height; // tightly packed-
794 data->data = (uchar *)malloc(data->nbytes);-
795 }
never executed: end of block
0
796-
797 return data;
never executed: return data;
0
798}-
799-
800QDistanceFieldData *QDistanceFieldData::create(const QPainterPath &path, bool doubleResolution)-
801{-
802 int dfMargin = QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution);
doubleResolutionDescription
TRUEnever evaluated
FALSEnever evaluated
doubleResolutionDescription
TRUEnever evaluated
FALSEnever evaluated
0
803 int glyphWidth = qCeil(path.boundingRect().width() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2;-
804 int glyphHeight = qCeil(path.boundingRect().height() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2;-
805-
806 QDistanceFieldData *data = create(QSize(glyphWidth, glyphHeight));-
807-
808 makeDistanceField(data,-
809 path,-
810 QT_DISTANCEFIELD_SCALE(doubleResolution),-
811 QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution));-
812 return data;
never executed: return data;
0
813}-
814-
815-
816QDistanceField::QDistanceField()-
817 : d(new QDistanceFieldData)-
818{-
819}
never executed: end of block
0
820-
821QDistanceField::QDistanceField(int width, int height)-
822 : d(QDistanceFieldData::create(QSize(width, height)))-
823{-
824}
never executed: end of block
0
825-
826QDistanceField::QDistanceField(const QDistanceField &other)-
827{-
828 d = other.d;-
829}
never executed: end of block
0
830-
831QDistanceField::QDistanceField(const QRawFont &font, glyph_t glyph, bool doubleResolution)-
832{-
833 setGlyph(font, glyph, doubleResolution);-
834}
never executed: end of block
0
835-
836QDistanceField::QDistanceField(QFontEngine *fontEngine, glyph_t glyph, bool doubleResolution)-
837{-
838 setGlyph(fontEngine, glyph, doubleResolution);-
839}
never executed: end of block
0
840-
841QDistanceField::QDistanceField(const QPainterPath &path, glyph_t glyph, bool doubleResolution)-
842{-
843 QPainterPath dfPath = path;-
844 dfPath.translate(-dfPath.boundingRect().topLeft());-
845 dfPath.setFillRule(Qt::WindingFill);-
846-
847 d = QDistanceFieldData::create(dfPath, doubleResolution);-
848 d->glyph = glyph;-
849}
never executed: end of block
0
850-
851-
852QDistanceField::QDistanceField(QDistanceFieldData *data)-
853 : d(data)-
854{-
855}
never executed: end of block
0
856-
857bool QDistanceField::isNull() const-
858{-
859 return !d->data;
never executed: return !d->data;
0
860}-
861-
862glyph_t QDistanceField::glyph() const-
863{-
864 return d->glyph;
never executed: return d->glyph;
0
865}-
866-
867void QDistanceField::setGlyph(const QRawFont &font, glyph_t glyph, bool doubleResolution)-
868{-
869 QRawFont renderFont = font;-
870 renderFont.setPixelSize(QT_DISTANCEFIELD_BASEFONTSIZE(doubleResolution) * QT_DISTANCEFIELD_SCALE(doubleResolution));-
871-
872 QPainterPath path = renderFont.pathForGlyph(glyph);-
873 path.translate(-path.boundingRect().topLeft());-
874 path.setFillRule(Qt::WindingFill);-
875-
876 d = QDistanceFieldData::create(path, doubleResolution);-
877 d->glyph = glyph;-
878}
never executed: end of block
0
879-
880void QDistanceField::setGlyph(QFontEngine *fontEngine, glyph_t glyph, bool doubleResolution)-
881{-
882 QFixedPoint position;-
883 QPainterPath path;-
884 fontEngine->addGlyphsToPath(&glyph, &position, 1, &path, 0);-
885 path.translate(-path.boundingRect().topLeft());-
886 path.setFillRule(Qt::WindingFill);-
887-
888 d = QDistanceFieldData::create(path, doubleResolution);-
889 d->glyph = glyph;-
890}
never executed: end of block
0
891-
892int QDistanceField::width() const-
893{-
894 return d->width;
never executed: return d->width;
0
895}-
896-
897int QDistanceField::height() const-
898{-
899 return d->height;
never executed: return d->height;
0
900}-
901-
902QDistanceField QDistanceField::copy(const QRect &r) const-
903{-
904 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
905 return QDistanceField();
never executed: return QDistanceField();
0
906-
907 if (r.isNull())
r.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
908 return QDistanceField(new QDistanceFieldData(*d));
never executed: return QDistanceField(new QDistanceFieldData(*d));
0
909-
910 int x = r.x();-
911 int y = r.y();-
912 int w = r.width();-
913 int h = r.height();-
914-
915 int dx = 0;-
916 int dy = 0;-
917 if (w <= 0 || h <= 0)
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
918 return QDistanceField();
never executed: return QDistanceField();
0
919-
920 QDistanceField df(w, h);-
921 if (df.isNull())
df.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
922 return df;
never executed: return df;
0
923-
924 if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) {
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
x + w > d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
y + h > d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
925 memset(df.d->data, 0, df.d->nbytes);-
926 if (x < 0) {
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
927 dx = -x;-
928 x = 0;-
929 }
never executed: end of block
0
930 if (y < 0) {
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
931 dy = -y;-
932 y = 0;-
933 }
never executed: end of block
0
934 }
never executed: end of block
0
935-
936 int pixels_to_copy = qMax(w - dx, 0);-
937 if (x > d->width)
x > d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
938 pixels_to_copy = 0;
never executed: pixels_to_copy = 0;
0
939 else if (pixels_to_copy > d->width - x)
pixels_to_copy > d->width - xDescription
TRUEnever evaluated
FALSEnever evaluated
0
940 pixels_to_copy = d->width - x;
never executed: pixels_to_copy = d->width - x;
0
941 int lines_to_copy = qMax(h - dy, 0);-
942 if (y > d->height)
y > d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
943 lines_to_copy = 0;
never executed: lines_to_copy = 0;
0
944 else if (lines_to_copy > d->height - y)
lines_to_copy > d->height - yDescription
TRUEnever evaluated
FALSEnever evaluated
0
945 lines_to_copy = d->height - y;
never executed: lines_to_copy = d->height - y;
0
946-
947 const uchar *src = d->data + x + y * d->width;-
948 uchar *dest = df.d->data + dx + dy * df.d->width;-
949 for (int i = 0; i < lines_to_copy; ++i) {
i < lines_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
950 memcpy(dest, src, pixels_to_copy);-
951 src += d->width;-
952 dest += df.d->width;-
953 }
never executed: end of block
0
954-
955 df.d->glyph = d->glyph;-
956-
957 return df;
never executed: return df;
0
958}-
959-
960uchar *QDistanceField::bits()-
961{-
962 return d->data;
never executed: return d->data;
0
963}-
964-
965const uchar *QDistanceField::bits() const-
966{-
967 return d->data;
never executed: return d->data;
0
968}-
969-
970const uchar *QDistanceField::constBits() const-
971{-
972 return d->data;
never executed: return d->data;
0
973}-
974-
975uchar *QDistanceField::scanLine(int i)-
976{-
977 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
978 return 0;
never executed: return 0;
0
979-
980 Q_ASSERT(i >= 0 && i < d->height);-
981 return d->data + i * d->width;
never executed: return d->data + i * d->width;
0
982}-
983-
984const uchar *QDistanceField::scanLine(int i) const-
985{-
986 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
987 return 0;
never executed: return 0;
0
988-
989 Q_ASSERT(i >= 0 && i < d->height);-
990 return d->data + i * d->width;
never executed: return d->data + i * d->width;
0
991}-
992-
993const uchar *QDistanceField::constScanLine(int i) const-
994{-
995 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
996 return 0;
never executed: return 0;
0
997-
998 Q_ASSERT(i >= 0 && i < d->height);-
999 return d->data + i * d->width;
never executed: return d->data + i * d->width;
0
1000}-
1001-
1002QImage QDistanceField::toImage(QImage::Format format) const-
1003{-
1004 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1005 return QImage();
never executed: return QImage();
0
1006-
1007 QImage image(d->width, d->height, qt_depthForFormat(format) == 8 ?-
1008 format : QImage::Format_ARGB32_Premultiplied);-
1009 if (image.isNull())
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1010 return image;
never executed: return image;
0
1011-
1012 if (image.depth() == 8) {
image.depth() == 8Description
TRUEnever evaluated
FALSEnever evaluated
0
1013 for (int y = 0; y < d->height; ++y)
y < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1014 memcpy(image.scanLine(y), scanLine(y), d->width);
never executed: memcpy(image.scanLine(y), scanLine(y), d->width);
0
1015 } else {
never executed: end of block
0
1016 for (int y = 0; y < d->height; ++y) {
y < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1017 for (int x = 0; x < d->width; ++x) {
x < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1018 uint alpha = *(d->data + x + y * d->width);-
1019 image.setPixel(x, y, alpha << 24);-
1020 }
never executed: end of block
0
1021 }
never executed: end of block
0
1022-
1023 if (image.format() != format)
image.format() != formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1024 image = image.convertToFormat(format);
never executed: image = image.convertToFormat(format);
0
1025 }
never executed: end of block
0
1026-
1027 return image;
never executed: return image;
0
1028}-
1029-
1030QT_END_NAMESPACE-
1031-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9