0
|
1 |
/****************************************************************************
|
|
2 |
**
|
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <qdebug.h>
|
|
43 |
#include <private/qfontengine_p.h>
|
|
44 |
|
|
45 |
#include "qbitmap.h"
|
|
46 |
#include "qpainter.h"
|
|
47 |
#include "qpainterpath.h"
|
|
48 |
#include "qvarlengtharray.h"
|
|
49 |
#include <private/qpdf_p.h>
|
|
50 |
#include <qmath.h>
|
|
51 |
#include <qendian.h>
|
|
52 |
#include <private/qharfbuzz_p.h>
|
|
53 |
|
|
54 |
QT_BEGIN_NAMESPACE
|
|
55 |
|
|
56 |
static inline bool qtransform_equals_no_translate(const QTransform &a, const QTransform &b)
|
|
57 |
{
|
|
58 |
if (a.type() <= QTransform::TxTranslate && b.type() <= QTransform::TxTranslate) {
|
|
59 |
return true;
|
|
60 |
} else {
|
|
61 |
// We always use paths for perspective text anyway, so no
|
|
62 |
// point in checking the full matrix...
|
|
63 |
Q_ASSERT(a.type() < QTransform::TxProject);
|
|
64 |
Q_ASSERT(b.type() < QTransform::TxProject);
|
|
65 |
|
|
66 |
return a.m11() == b.m11()
|
|
67 |
&& a.m12() == b.m12()
|
|
68 |
&& a.m21() == b.m21()
|
|
69 |
&& a.m22() == b.m22();
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
// Harfbuzz helper functions
|
|
74 |
|
|
75 |
static HB_Bool hb_stringToGlyphs(HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft)
|
|
76 |
{
|
|
77 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
78 |
|
|
79 |
QVarLengthGlyphLayoutArray qglyphs(*numGlyphs);
|
|
80 |
|
|
81 |
QTextEngine::ShaperFlags shaperFlags(QTextEngine::GlyphIndicesOnly);
|
|
82 |
if (rightToLeft)
|
|
83 |
shaperFlags |= QTextEngine::RightToLeft;
|
|
84 |
|
|
85 |
int nGlyphs = *numGlyphs;
|
|
86 |
bool result = fe->stringToCMap(reinterpret_cast<const QChar *>(string), length, &qglyphs, &nGlyphs, shaperFlags);
|
|
87 |
*numGlyphs = nGlyphs;
|
|
88 |
if (!result)
|
|
89 |
return false;
|
|
90 |
|
|
91 |
for (hb_uint32 i = 0; i < *numGlyphs; ++i)
|
|
92 |
glyphs[i] = qglyphs.glyphs[i];
|
|
93 |
|
|
94 |
return true;
|
|
95 |
}
|
|
96 |
|
|
97 |
static void hb_getAdvances(HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags)
|
|
98 |
{
|
|
99 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
100 |
|
|
101 |
QVarLengthGlyphLayoutArray qglyphs(numGlyphs);
|
|
102 |
|
|
103 |
for (hb_uint32 i = 0; i < numGlyphs; ++i)
|
|
104 |
qglyphs.glyphs[i] = glyphs[i];
|
|
105 |
|
|
106 |
fe->recalcAdvances(&qglyphs, flags & HB_ShaperFlag_UseDesignMetrics ? QFlags<QTextEngine::ShaperFlag>(QTextEngine::DesignMetrics) : QFlags<QTextEngine::ShaperFlag>(0));
|
|
107 |
|
|
108 |
for (hb_uint32 i = 0; i < numGlyphs; ++i)
|
|
109 |
advances[i] = qglyphs.advances_x[i].value();
|
|
110 |
}
|
|
111 |
|
|
112 |
static HB_Bool hb_canRender(HB_Font font, const HB_UChar16 *string, hb_uint32 length)
|
|
113 |
{
|
|
114 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
115 |
return fe->canRender(reinterpret_cast<const QChar *>(string), length);
|
|
116 |
}
|
|
117 |
|
|
118 |
static void hb_getGlyphMetrics(HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics)
|
|
119 |
{
|
|
120 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
121 |
glyph_metrics_t m = fe->boundingBox(glyph);
|
|
122 |
metrics->x = m.x.value();
|
|
123 |
metrics->y = m.y.value();
|
|
124 |
metrics->width = m.width.value();
|
|
125 |
metrics->height = m.height.value();
|
|
126 |
metrics->xOffset = m.xoff.value();
|
|
127 |
metrics->yOffset = m.yoff.value();
|
|
128 |
}
|
|
129 |
|
|
130 |
static HB_Fixed hb_getFontMetric(HB_Font font, HB_FontMetric metric)
|
|
131 |
{
|
|
132 |
if (metric == HB_FontAscent) {
|
|
133 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
134 |
return fe->ascent().value();
|
|
135 |
}
|
|
136 |
return 0;
|
|
137 |
}
|
|
138 |
|
|
139 |
HB_Error QFontEngine::getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
|
|
140 |
{
|
|
141 |
Q_UNUSED(glyph)
|
|
142 |
Q_UNUSED(flags)
|
|
143 |
Q_UNUSED(point)
|
|
144 |
Q_UNUSED(xpos)
|
|
145 |
Q_UNUSED(ypos)
|
|
146 |
Q_UNUSED(nPoints)
|
|
147 |
return HB_Err_Not_Covered;
|
|
148 |
}
|
|
149 |
|
|
150 |
static HB_Error hb_getPointInOutline(HB_Font font, HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
|
|
151 |
{
|
|
152 |
QFontEngine *fe = (QFontEngine *)font->userData;
|
|
153 |
return fe->getPointInOutline(glyph, flags, point, xpos, ypos, nPoints);
|
|
154 |
}
|
|
155 |
|
|
156 |
static const HB_FontClass hb_fontClass = {
|
|
157 |
hb_stringToGlyphs, hb_getAdvances, hb_canRender, hb_getPointInOutline,
|
|
158 |
hb_getGlyphMetrics, hb_getFontMetric
|
|
159 |
};
|
|
160 |
|
|
161 |
static HB_Error hb_getSFntTable(void *font, HB_Tag tableTag, HB_Byte *buffer, HB_UInt *length)
|
|
162 |
{
|
|
163 |
QFontEngine *fe = (QFontEngine *)font;
|
|
164 |
if (!fe->getSfntTableData(tableTag, buffer, length))
|
|
165 |
return HB_Err_Invalid_Argument;
|
|
166 |
return HB_Err_Ok;
|
|
167 |
}
|
|
168 |
|
|
169 |
// QFontEngine
|
|
170 |
|
|
171 |
QFontEngine::QFontEngine()
|
|
172 |
: QObject()
|
|
173 |
{
|
|
174 |
ref = 0;
|
|
175 |
cache_count = 0;
|
|
176 |
fsType = 0;
|
|
177 |
symbol = false;
|
|
178 |
memset(&hbFont, 0, sizeof(hbFont));
|
|
179 |
hbFont.klass = &hb_fontClass;
|
|
180 |
hbFont.userData = this;
|
|
181 |
|
|
182 |
hbFace = 0;
|
|
183 |
glyphFormat = -1;
|
|
184 |
}
|
|
185 |
|
|
186 |
QFontEngine::~QFontEngine()
|
|
187 |
{
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
188 |
for (QLinkedList<GlyphCacheEntry>::const_iterator it = m_glyphCaches.constBegin(),
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
189 |
end = m_glyphCaches.constEnd(); it != end; ++it) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
190 |
delete it->cache;
|
0
|
191 |
}
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
192 |
m_glyphCaches.clear();
|
0
|
193 |
qHBFreeFace(hbFace);
|
|
194 |
}
|
|
195 |
|
|
196 |
QFixed QFontEngine::lineThickness() const
|
|
197 |
{
|
|
198 |
// ad hoc algorithm
|
|
199 |
int score = fontDef.weight * fontDef.pixelSize;
|
|
200 |
int lw = score / 700;
|
|
201 |
|
|
202 |
// looks better with thicker line for small pointsizes
|
|
203 |
if (lw < 2 && score >= 1050) lw = 2;
|
|
204 |
if (lw == 0) lw = 1;
|
|
205 |
|
|
206 |
return lw;
|
|
207 |
}
|
|
208 |
|
|
209 |
QFixed QFontEngine::underlinePosition() const
|
|
210 |
{
|
|
211 |
return ((lineThickness() * 2) + 3) / 6;
|
|
212 |
}
|
|
213 |
|
|
214 |
HB_Font QFontEngine::harfbuzzFont() const
|
|
215 |
{
|
|
216 |
if (!hbFont.x_ppem) {
|
|
217 |
QFixed emSquare = emSquareSize();
|
|
218 |
hbFont.x_ppem = fontDef.pixelSize;
|
|
219 |
hbFont.y_ppem = fontDef.pixelSize * fontDef.stretch / 100;
|
|
220 |
hbFont.x_scale = (QFixed(hbFont.x_ppem * (1 << 16)) / emSquare).value();
|
|
221 |
hbFont.y_scale = (QFixed(hbFont.y_ppem * (1 << 16)) / emSquare).value();
|
|
222 |
}
|
|
223 |
return &hbFont;
|
|
224 |
}
|
|
225 |
|
|
226 |
HB_Face QFontEngine::harfbuzzFace() const
|
|
227 |
{
|
|
228 |
if (!hbFace) {
|
|
229 |
hbFace = qHBNewFace(const_cast<QFontEngine *>(this), hb_getSFntTable);
|
|
230 |
Q_CHECK_PTR(hbFace);
|
|
231 |
}
|
|
232 |
return hbFace;
|
|
233 |
}
|
|
234 |
|
|
235 |
glyph_metrics_t QFontEngine::boundingBox(glyph_t glyph, const QTransform &matrix)
|
|
236 |
{
|
|
237 |
glyph_metrics_t metrics = boundingBox(glyph);
|
|
238 |
|
|
239 |
if (matrix.type() > QTransform::TxTranslate) {
|
|
240 |
return metrics.transformed(matrix);
|
|
241 |
}
|
|
242 |
return metrics;
|
|
243 |
}
|
|
244 |
|
|
245 |
QFixed QFontEngine::xHeight() const
|
|
246 |
{
|
|
247 |
QGlyphLayoutArray<8> glyphs;
|
|
248 |
int nglyphs = 7;
|
|
249 |
QChar x((ushort)'x');
|
|
250 |
stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
|
|
251 |
|
|
252 |
glyph_metrics_t bb = const_cast<QFontEngine *>(this)->boundingBox(glyphs.glyphs[0]);
|
|
253 |
return bb.height;
|
|
254 |
}
|
|
255 |
|
|
256 |
QFixed QFontEngine::averageCharWidth() const
|
|
257 |
{
|
|
258 |
QGlyphLayoutArray<8> glyphs;
|
|
259 |
int nglyphs = 7;
|
|
260 |
QChar x((ushort)'x');
|
|
261 |
stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
|
|
262 |
|
|
263 |
glyph_metrics_t bb = const_cast<QFontEngine *>(this)->boundingBox(glyphs.glyphs[0]);
|
|
264 |
return bb.xoff;
|
|
265 |
}
|
|
266 |
|
|
267 |
|
|
268 |
void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags,
|
|
269 |
QVarLengthArray<glyph_t> &glyphs_out, QVarLengthArray<QFixedPoint> &positions)
|
|
270 |
{
|
|
271 |
QFixed xpos;
|
|
272 |
QFixed ypos;
|
|
273 |
|
|
274 |
const bool transform = matrix.m11() != 1.
|
|
275 |
|| matrix.m12() != 0.
|
|
276 |
|| matrix.m21() != 0.
|
|
277 |
|| matrix.m22() != 1.;
|
|
278 |
if (!transform) {
|
|
279 |
xpos = QFixed::fromReal(matrix.dx());
|
|
280 |
ypos = QFixed::fromReal(matrix.dy());
|
|
281 |
}
|
|
282 |
|
|
283 |
int current = 0;
|
|
284 |
if (flags & QTextItem::RightToLeft) {
|
|
285 |
int i = glyphs.numGlyphs;
|
|
286 |
int totalKashidas = 0;
|
|
287 |
while(i--) {
|
|
288 |
xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
|
|
289 |
ypos += glyphs.advances_y[i];
|
|
290 |
totalKashidas += glyphs.justifications[i].nKashidas;
|
|
291 |
}
|
|
292 |
positions.resize(glyphs.numGlyphs+totalKashidas);
|
|
293 |
glyphs_out.resize(glyphs.numGlyphs+totalKashidas);
|
|
294 |
|
|
295 |
i = 0;
|
|
296 |
while(i < glyphs.numGlyphs) {
|
|
297 |
if (glyphs.attributes[i].dontPrint) {
|
|
298 |
++i;
|
|
299 |
continue;
|
|
300 |
}
|
|
301 |
xpos -= glyphs.advances_x[i];
|
|
302 |
ypos -= glyphs.advances_y[i];
|
|
303 |
|
|
304 |
QFixed gpos_x = xpos + glyphs.offsets[i].x;
|
|
305 |
QFixed gpos_y = ypos + glyphs.offsets[i].y;
|
|
306 |
if (transform) {
|
|
307 |
QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
|
|
308 |
gpos = gpos * matrix;
|
|
309 |
gpos_x = QFixed::fromReal(gpos.x());
|
|
310 |
gpos_y = QFixed::fromReal(gpos.y());
|
|
311 |
}
|
|
312 |
positions[current].x = gpos_x;
|
|
313 |
positions[current].y = gpos_y;
|
|
314 |
glyphs_out[current] = glyphs.glyphs[i];
|
|
315 |
++current;
|
|
316 |
if (glyphs.justifications[i].nKashidas) {
|
|
317 |
QChar ch(0x640); // Kashida character
|
|
318 |
QGlyphLayoutArray<8> g;
|
|
319 |
int nglyphs = 7;
|
|
320 |
stringToCMap(&ch, 1, &g, &nglyphs, 0);
|
|
321 |
for (uint k = 0; k < glyphs.justifications[i].nKashidas; ++k) {
|
|
322 |
xpos -= g.advances_x[0];
|
|
323 |
ypos -= g.advances_y[0];
|
|
324 |
|
|
325 |
QFixed gpos_x = xpos + glyphs.offsets[i].x;
|
|
326 |
QFixed gpos_y = ypos + glyphs.offsets[i].y;
|
|
327 |
if (transform) {
|
|
328 |
QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
|
|
329 |
gpos = gpos * matrix;
|
|
330 |
gpos_x = QFixed::fromReal(gpos.x());
|
|
331 |
gpos_y = QFixed::fromReal(gpos.y());
|
|
332 |
}
|
|
333 |
positions[current].x = gpos_x;
|
|
334 |
positions[current].y = gpos_y;
|
|
335 |
glyphs_out[current] = g.glyphs[0];
|
|
336 |
++current;
|
|
337 |
}
|
|
338 |
} else {
|
|
339 |
xpos -= QFixed::fromFixed(glyphs.justifications[i].space_18d6);
|
|
340 |
}
|
|
341 |
++i;
|
|
342 |
}
|
|
343 |
} else {
|
|
344 |
positions.resize(glyphs.numGlyphs);
|
|
345 |
glyphs_out.resize(glyphs.numGlyphs);
|
|
346 |
int i = 0;
|
|
347 |
if (!transform) {
|
|
348 |
while (i < glyphs.numGlyphs) {
|
|
349 |
if (!glyphs.attributes[i].dontPrint) {
|
|
350 |
positions[current].x = xpos + glyphs.offsets[i].x;
|
|
351 |
positions[current].y = ypos + glyphs.offsets[i].y;
|
|
352 |
glyphs_out[current] = glyphs.glyphs[i];
|
|
353 |
xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
|
|
354 |
ypos += glyphs.advances_y[i];
|
|
355 |
++current;
|
|
356 |
}
|
|
357 |
++i;
|
|
358 |
}
|
|
359 |
} else {
|
|
360 |
while (i < glyphs.numGlyphs) {
|
|
361 |
if (!glyphs.attributes[i].dontPrint) {
|
|
362 |
QFixed gpos_x = xpos + glyphs.offsets[i].x;
|
|
363 |
QFixed gpos_y = ypos + glyphs.offsets[i].y;
|
|
364 |
QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
|
|
365 |
gpos = gpos * matrix;
|
|
366 |
positions[current].x = QFixed::fromReal(gpos.x());
|
|
367 |
positions[current].y = QFixed::fromReal(gpos.y());
|
|
368 |
glyphs_out[current] = glyphs.glyphs[i];
|
|
369 |
xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
|
|
370 |
ypos += glyphs.advances_y[i];
|
|
371 |
++current;
|
|
372 |
}
|
|
373 |
++i;
|
|
374 |
}
|
|
375 |
}
|
|
376 |
}
|
|
377 |
positions.resize(current);
|
|
378 |
glyphs_out.resize(current);
|
|
379 |
Q_ASSERT(positions.size() == glyphs_out.size());
|
|
380 |
}
|
|
381 |
|
|
382 |
|
|
383 |
glyph_metrics_t QFontEngine::tightBoundingBox(const QGlyphLayout &glyphs)
|
|
384 |
{
|
|
385 |
glyph_metrics_t overall;
|
|
386 |
|
|
387 |
QFixed ymax = 0;
|
|
388 |
QFixed xmax = 0;
|
|
389 |
for (int i = 0; i < glyphs.numGlyphs; i++) {
|
|
390 |
glyph_metrics_t bb = boundingBox(glyphs.glyphs[i]);
|
|
391 |
QFixed x = overall.xoff + glyphs.offsets[i].x + bb.x;
|
|
392 |
QFixed y = overall.yoff + glyphs.offsets[i].y + bb.y;
|
|
393 |
overall.x = qMin(overall.x, x);
|
|
394 |
overall.y = qMin(overall.y, y);
|
|
395 |
xmax = qMax(xmax, x + bb.width);
|
|
396 |
ymax = qMax(ymax, y + bb.height);
|
|
397 |
overall.xoff += bb.xoff;
|
|
398 |
overall.yoff += bb.yoff;
|
|
399 |
}
|
|
400 |
overall.height = qMax(overall.height, ymax - overall.y);
|
|
401 |
overall.width = xmax - overall.x;
|
|
402 |
|
|
403 |
return overall;
|
|
404 |
}
|
|
405 |
|
|
406 |
|
|
407 |
void QFontEngine::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path,
|
|
408 |
QTextItem::RenderFlags flags)
|
|
409 |
{
|
|
410 |
if (!glyphs.numGlyphs)
|
|
411 |
return;
|
|
412 |
|
|
413 |
QVarLengthArray<QFixedPoint> positions;
|
|
414 |
QVarLengthArray<glyph_t> positioned_glyphs;
|
|
415 |
QTransform matrix = QTransform::fromTranslate(x, y);
|
|
416 |
getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
|
|
417 |
addGlyphsToPath(positioned_glyphs.data(), positions.data(), positioned_glyphs.size(), path, flags);
|
|
418 |
}
|
|
419 |
|
|
420 |
#define GRID(x, y) grid[(y)*(w+1) + (x)]
|
|
421 |
#define SET(x, y) (*(image_data + (y)*bpl + ((x) >> 3)) & (0x80 >> ((x) & 7)))
|
|
422 |
|
|
423 |
enum { EdgeRight = 0x1,
|
|
424 |
EdgeDown = 0x2,
|
|
425 |
EdgeLeft = 0x4,
|
|
426 |
EdgeUp = 0x8
|
|
427 |
};
|
|
428 |
|
|
429 |
static void collectSingleContour(qreal x0, qreal y0, uint *grid, int x, int y, int w, int h, QPainterPath *path)
|
|
430 |
{
|
|
431 |
Q_UNUSED(h);
|
|
432 |
|
|
433 |
path->moveTo(x + x0, y + y0);
|
|
434 |
while (GRID(x, y)) {
|
|
435 |
if (GRID(x, y) & EdgeRight) {
|
|
436 |
while (GRID(x, y) & EdgeRight) {
|
|
437 |
GRID(x, y) &= ~EdgeRight;
|
|
438 |
++x;
|
|
439 |
}
|
|
440 |
Q_ASSERT(x <= w);
|
|
441 |
path->lineTo(x + x0, y + y0);
|
|
442 |
continue;
|
|
443 |
}
|
|
444 |
if (GRID(x, y) & EdgeDown) {
|
|
445 |
while (GRID(x, y) & EdgeDown) {
|
|
446 |
GRID(x, y) &= ~EdgeDown;
|
|
447 |
++y;
|
|
448 |
}
|
|
449 |
Q_ASSERT(y <= h);
|
|
450 |
path->lineTo(x + x0, y + y0);
|
|
451 |
continue;
|
|
452 |
}
|
|
453 |
if (GRID(x, y) & EdgeLeft) {
|
|
454 |
while (GRID(x, y) & EdgeLeft) {
|
|
455 |
GRID(x, y) &= ~EdgeLeft;
|
|
456 |
--x;
|
|
457 |
}
|
|
458 |
Q_ASSERT(x >= 0);
|
|
459 |
path->lineTo(x + x0, y + y0);
|
|
460 |
continue;
|
|
461 |
}
|
|
462 |
if (GRID(x, y) & EdgeUp) {
|
|
463 |
while (GRID(x, y) & EdgeUp) {
|
|
464 |
GRID(x, y) &= ~EdgeUp;
|
|
465 |
--y;
|
|
466 |
}
|
|
467 |
Q_ASSERT(y >= 0);
|
|
468 |
path->lineTo(x + x0, y + y0);
|
|
469 |
continue;
|
|
470 |
}
|
|
471 |
}
|
|
472 |
path->closeSubpath();
|
|
473 |
}
|
|
474 |
|
|
475 |
void qt_addBitmapToPath(qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
|
|
476 |
{
|
|
477 |
uint *grid = new uint[(w+1)*(h+1)];
|
|
478 |
// set up edges
|
|
479 |
for (int y = 0; y <= h; ++y) {
|
|
480 |
for (int x = 0; x <= w; ++x) {
|
|
481 |
bool topLeft = (x == 0)|(y == 0) ? false : SET(x - 1, y - 1);
|
|
482 |
bool topRight = (x == w)|(y == 0) ? false : SET(x, y - 1);
|
|
483 |
bool bottomLeft = (x == 0)|(y == h) ? false : SET(x - 1, y);
|
|
484 |
bool bottomRight = (x == w)|(y == h) ? false : SET(x, y);
|
|
485 |
|
|
486 |
GRID(x, y) = 0;
|
|
487 |
if ((!topRight) & bottomRight)
|
|
488 |
GRID(x, y) |= EdgeRight;
|
|
489 |
if ((!bottomRight) & bottomLeft)
|
|
490 |
GRID(x, y) |= EdgeDown;
|
|
491 |
if ((!bottomLeft) & topLeft)
|
|
492 |
GRID(x, y) |= EdgeLeft;
|
|
493 |
if ((!topLeft) & topRight)
|
|
494 |
GRID(x, y) |= EdgeUp;
|
|
495 |
}
|
|
496 |
}
|
|
497 |
|
|
498 |
// collect edges
|
|
499 |
for (int y = 0; y < h; ++y) {
|
|
500 |
for (int x = 0; x < w; ++x) {
|
|
501 |
if (!GRID(x, y))
|
|
502 |
continue;
|
|
503 |
// found start of a contour, follow it
|
|
504 |
collectSingleContour(x0, y0, grid, x, y, w, h, path);
|
|
505 |
}
|
|
506 |
}
|
|
507 |
delete [] grid;
|
|
508 |
}
|
|
509 |
|
|
510 |
#undef GRID
|
|
511 |
#undef SET
|
|
512 |
|
|
513 |
|
|
514 |
void QFontEngine::addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
|
|
515 |
QPainterPath *path, QTextItem::RenderFlags flags)
|
|
516 |
{
|
|
517 |
// TODO what to do with 'flags' ??
|
|
518 |
Q_UNUSED(flags);
|
|
519 |
QFixed advanceX = QFixed::fromReal(x);
|
|
520 |
QFixed advanceY = QFixed::fromReal(y);
|
|
521 |
for (int i=0; i < glyphs.numGlyphs; ++i) {
|
|
522 |
glyph_metrics_t metrics = boundingBox(glyphs.glyphs[i]);
|
|
523 |
if (metrics.width.value() == 0 || metrics.height.value() == 0) {
|
|
524 |
advanceX += glyphs.advances_x[i];
|
|
525 |
advanceY += glyphs.advances_y[i];
|
|
526 |
continue;
|
|
527 |
}
|
|
528 |
const QImage alphaMask = alphaMapForGlyph(glyphs.glyphs[i]);
|
|
529 |
|
|
530 |
const int w = alphaMask.width();
|
|
531 |
const int h = alphaMask.height();
|
|
532 |
const int srcBpl = alphaMask.bytesPerLine();
|
|
533 |
QImage bitmap;
|
|
534 |
if (alphaMask.depth() == 1) {
|
|
535 |
bitmap = alphaMask;
|
|
536 |
} else {
|
|
537 |
bitmap = QImage(w, h, QImage::Format_Mono);
|
|
538 |
const uchar *imageData = alphaMask.bits();
|
|
539 |
const int destBpl = bitmap.bytesPerLine();
|
|
540 |
uchar *bitmapData = bitmap.bits();
|
|
541 |
|
|
542 |
for (int yi = 0; yi < h; ++yi) {
|
|
543 |
const uchar *src = imageData + yi*srcBpl;
|
|
544 |
uchar *dst = bitmapData + yi*destBpl;
|
|
545 |
for (int xi = 0; xi < w; ++xi) {
|
|
546 |
const int byte = xi / 8;
|
|
547 |
const int bit = xi % 8;
|
|
548 |
if (bit == 0)
|
|
549 |
dst[byte] = 0;
|
|
550 |
if (src[xi])
|
|
551 |
dst[byte] |= 128 >> bit;
|
|
552 |
}
|
|
553 |
}
|
|
554 |
}
|
|
555 |
const uchar *bitmap_data = bitmap.bits();
|
|
556 |
QFixedPoint offset = glyphs.offsets[i];
|
|
557 |
advanceX += offset.x;
|
|
558 |
advanceY += offset.y;
|
|
559 |
qt_addBitmapToPath((advanceX + metrics.x).toReal(), (advanceY + metrics.y).toReal(), bitmap_data, bitmap.bytesPerLine(), w, h, path);
|
|
560 |
advanceX += glyphs.advances_x[i];
|
|
561 |
advanceY += glyphs.advances_y[i];
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
void QFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nGlyphs,
|
|
566 |
QPainterPath *path, QTextItem::RenderFlags flags)
|
|
567 |
{
|
|
568 |
qreal x = positions[0].x.toReal();
|
|
569 |
qreal y = positions[0].y.toReal();
|
|
570 |
QVarLengthGlyphLayoutArray g(nGlyphs);
|
|
571 |
|
|
572 |
for (int i = 0; i < nGlyphs; ++i) {
|
|
573 |
g.glyphs[i] = glyphs[i];
|
|
574 |
if (i < nGlyphs - 1) {
|
|
575 |
g.advances_x[i] = positions[i+1].x - positions[i].x;
|
|
576 |
g.advances_y[i] = positions[i+1].y - positions[i].y;
|
|
577 |
} else {
|
|
578 |
g.advances_x[i] = QFixed::fromReal(maxCharWidth());
|
|
579 |
g.advances_y[i] = 0;
|
|
580 |
}
|
|
581 |
}
|
|
582 |
|
|
583 |
addBitmapFontToPath(x, y, g, path, flags);
|
|
584 |
}
|
|
585 |
|
|
586 |
QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &t)
|
|
587 |
{
|
|
588 |
QImage i = alphaMapForGlyph(glyph);
|
|
589 |
if (t.type() > QTransform::TxTranslate)
|
|
590 |
i = i.transformed(t);
|
|
591 |
Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
|
|
592 |
return i;
|
|
593 |
}
|
|
594 |
|
|
595 |
QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, int /* margin */, const QTransform &t)
|
|
596 |
{
|
|
597 |
QImage alphaMask = alphaMapForGlyph(glyph, t);
|
|
598 |
QImage rgbMask(alphaMask.width(), alphaMask.height(), QImage::Format_RGB32);
|
|
599 |
|
|
600 |
for (int y=0; y<alphaMask.height(); ++y) {
|
|
601 |
uint *dst = (uint *) rgbMask.scanLine(y);
|
|
602 |
uchar *src = (uchar *) alphaMask.scanLine(y);
|
|
603 |
for (int x=0; x<alphaMask.width(); ++x)
|
|
604 |
dst[x] = qRgb(src[x], src[x], src[x]);
|
|
605 |
}
|
|
606 |
|
|
607 |
return rgbMask;
|
|
608 |
}
|
|
609 |
|
|
610 |
QImage QFontEngine::alphaMapForGlyph(glyph_t glyph)
|
|
611 |
{
|
|
612 |
glyph_metrics_t gm = boundingBox(glyph);
|
|
613 |
int glyph_x = qFloor(gm.x.toReal());
|
|
614 |
int glyph_y = qFloor(gm.y.toReal());
|
|
615 |
int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x;
|
|
616 |
int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y;
|
|
617 |
|
|
618 |
if (glyph_width <= 0 || glyph_height <= 0)
|
|
619 |
return QImage();
|
|
620 |
QFixedPoint pt;
|
|
621 |
pt.x = 0;
|
|
622 |
pt.y = -glyph_y; // the baseline
|
|
623 |
QPainterPath path;
|
|
624 |
QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied);
|
|
625 |
im.fill(Qt::transparent);
|
|
626 |
QPainter p(&im);
|
|
627 |
p.setRenderHint(QPainter::Antialiasing);
|
|
628 |
addGlyphsToPath(&glyph, &pt, 1, &path, 0);
|
|
629 |
p.setPen(Qt::NoPen);
|
|
630 |
p.setBrush(Qt::black);
|
|
631 |
p.drawPath(path);
|
|
632 |
p.end();
|
|
633 |
|
|
634 |
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
|
|
635 |
QVector<QRgb> colors(256);
|
|
636 |
for (int i=0; i<256; ++i)
|
|
637 |
colors[i] = qRgba(0, 0, 0, i);
|
|
638 |
indexed.setColorTable(colors);
|
|
639 |
|
|
640 |
for (int y=0; y<im.height(); ++y) {
|
|
641 |
uchar *dst = (uchar *) indexed.scanLine(y);
|
|
642 |
uint *src = (uint *) im.scanLine(y);
|
|
643 |
for (int x=0; x<im.width(); ++x)
|
|
644 |
dst[x] = qAlpha(src[x]);
|
|
645 |
}
|
|
646 |
|
|
647 |
return indexed;
|
|
648 |
}
|
|
649 |
|
|
650 |
void QFontEngine::removeGlyphFromCache(glyph_t)
|
|
651 |
{
|
|
652 |
}
|
|
653 |
|
|
654 |
QFontEngine::Properties QFontEngine::properties() const
|
|
655 |
{
|
|
656 |
Properties p;
|
|
657 |
#ifndef QT_NO_PRINTER
|
|
658 |
QByteArray psname = QPdf::stripSpecialCharacters(fontDef.family.toUtf8());
|
|
659 |
#else
|
|
660 |
QByteArray psname = fontDef.family.toUtf8();
|
|
661 |
#endif
|
|
662 |
psname += '-';
|
|
663 |
psname += QByteArray::number(fontDef.style);
|
|
664 |
psname += '-';
|
|
665 |
psname += QByteArray::number(fontDef.weight);
|
|
666 |
|
|
667 |
p.postscriptName = psname;
|
|
668 |
p.ascent = ascent();
|
|
669 |
p.descent = descent();
|
|
670 |
p.leading = leading();
|
|
671 |
p.emSquare = p.ascent;
|
|
672 |
p.boundingBox = QRectF(0, -p.ascent.toReal(), maxCharWidth(), (p.ascent + p.descent).toReal());
|
|
673 |
p.italicAngle = 0;
|
|
674 |
p.capHeight = p.ascent;
|
|
675 |
p.lineWidth = lineThickness();
|
|
676 |
return p;
|
|
677 |
}
|
|
678 |
|
|
679 |
void QFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
|
|
680 |
{
|
|
681 |
*metrics = boundingBox(glyph);
|
|
682 |
QFixedPoint p;
|
|
683 |
p.x = 0;
|
|
684 |
p.y = 0;
|
|
685 |
addGlyphsToPath(&glyph, &p, 1, path, QFlag(0));
|
|
686 |
}
|
|
687 |
|
|
688 |
QByteArray QFontEngine::getSfntTable(uint tag) const
|
|
689 |
{
|
|
690 |
QByteArray table;
|
|
691 |
uint len = 0;
|
|
692 |
if (!getSfntTableData(tag, 0, &len))
|
|
693 |
return table;
|
|
694 |
if (!len)
|
|
695 |
return table;
|
|
696 |
table.resize(len);
|
|
697 |
if (!getSfntTableData(tag, reinterpret_cast<uchar *>(table.data()), &len))
|
|
698 |
return QByteArray();
|
|
699 |
return table;
|
|
700 |
}
|
|
701 |
|
|
702 |
void QFontEngine::setGlyphCache(void *key, QFontEngineGlyphCache *data)
|
|
703 |
{
|
|
704 |
Q_ASSERT(data);
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
705 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
706 |
GlyphCacheEntry entry = { key, data };
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
707 |
if (m_glyphCaches.contains(entry))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
708 |
return;
|
0
|
709 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
710 |
// Limit the glyph caches to 4. This covers all 90 degree rotations and limits
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
711 |
// memory use when there is continous or random rotation
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
712 |
if (m_glyphCaches.size() == 4)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
713 |
delete m_glyphCaches.takeLast().cache;
|
0
|
714 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
715 |
m_glyphCaches.push_front(entry);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
716 |
|
0
|
717 |
}
|
|
718 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
719 |
QFontEngineGlyphCache *QFontEngine::glyphCache(void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const
|
0
|
720 |
{
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
721 |
for (QLinkedList<GlyphCacheEntry>::const_iterator it = m_glyphCaches.constBegin(), end = m_glyphCaches.constEnd(); it != end; ++it) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
722 |
QFontEngineGlyphCache *c = it->cache;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
723 |
if (key == it->context
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
724 |
&& type == c->cacheType()
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
725 |
&& qtransform_equals_no_translate(c->m_transform, transform)) {
|
0
|
726 |
return c;
|
|
727 |
}
|
|
728 |
}
|
|
729 |
return 0;
|
|
730 |
}
|
|
731 |
|
|
732 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
|
|
733 |
static inline QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
|
|
734 |
{
|
|
735 |
uint left_right = (left << 16) + right;
|
|
736 |
|
|
737 |
left = 0, right = numPairs - 1;
|
|
738 |
while (left <= right) {
|
|
739 |
int middle = left + ( ( right - left ) >> 1 );
|
|
740 |
|
|
741 |
if(pairs[middle].left_right == left_right)
|
|
742 |
return pairs[middle].adjust;
|
|
743 |
|
|
744 |
if (pairs[middle].left_right < left_right)
|
|
745 |
left = middle + 1;
|
|
746 |
else
|
|
747 |
right = middle - 1;
|
|
748 |
}
|
|
749 |
return 0;
|
|
750 |
}
|
|
751 |
|
|
752 |
void QFontEngine::doKerning(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
|
|
753 |
{
|
|
754 |
int numPairs = kerning_pairs.size();
|
|
755 |
if(!numPairs)
|
|
756 |
return;
|
|
757 |
|
|
758 |
const KernPair *pairs = kerning_pairs.constData();
|
|
759 |
|
|
760 |
if(flags & QTextEngine::DesignMetrics) {
|
|
761 |
for(int i = 0; i < glyphs->numGlyphs - 1; ++i)
|
|
762 |
glyphs->advances_x[i] += kerning(glyphs->glyphs[i], glyphs->glyphs[i+1] , pairs, numPairs);
|
|
763 |
} else {
|
|
764 |
for(int i = 0; i < glyphs->numGlyphs - 1; ++i)
|
|
765 |
glyphs->advances_x[i] += qRound(kerning(glyphs->glyphs[i], glyphs->glyphs[i+1] , pairs, numPairs));
|
|
766 |
}
|
|
767 |
}
|
|
768 |
|
|
769 |
void QFontEngine::loadKerningPairs(QFixed scalingFactor)
|
|
770 |
{
|
|
771 |
kerning_pairs.clear();
|
|
772 |
|
|
773 |
QByteArray tab = getSfntTable(MAKE_TAG('k', 'e', 'r', 'n'));
|
|
774 |
if (tab.isEmpty())
|
|
775 |
return;
|
|
776 |
|
|
777 |
const uchar *table = reinterpret_cast<const uchar *>(tab.constData());
|
|
778 |
|
|
779 |
unsigned short version = qFromBigEndian<quint16>(table);
|
|
780 |
if (version != 0) {
|
|
781 |
// qDebug("wrong version");
|
|
782 |
return;
|
|
783 |
}
|
|
784 |
|
|
785 |
unsigned short numTables = qFromBigEndian<quint16>(table + 2);
|
|
786 |
{
|
|
787 |
int offset = 4;
|
|
788 |
for(int i = 0; i < numTables; ++i) {
|
|
789 |
if (offset + 6 > tab.size()) {
|
|
790 |
// qDebug("offset out of bounds");
|
|
791 |
goto end;
|
|
792 |
}
|
|
793 |
const uchar *header = table + offset;
|
|
794 |
|
|
795 |
ushort version = qFromBigEndian<quint16>(header);
|
|
796 |
ushort length = qFromBigEndian<quint16>(header+2);
|
|
797 |
ushort coverage = qFromBigEndian<quint16>(header+4);
|
|
798 |
// qDebug("subtable: version=%d, coverage=%x",version, coverage);
|
|
799 |
if(version == 0 && coverage == 0x0001) {
|
|
800 |
if (offset + length > tab.size()) {
|
|
801 |
// qDebug("length ouf ot bounds");
|
|
802 |
goto end;
|
|
803 |
}
|
|
804 |
const uchar *data = table + offset + 6;
|
|
805 |
|
|
806 |
ushort nPairs = qFromBigEndian<quint16>(data);
|
|
807 |
if(nPairs * 6 + 8 > length - 6) {
|
|
808 |
// qDebug("corrupt table!");
|
|
809 |
// corrupt table
|
|
810 |
goto end;
|
|
811 |
}
|
|
812 |
|
|
813 |
int off = 8;
|
|
814 |
for(int i = 0; i < nPairs; ++i) {
|
|
815 |
QFontEngine::KernPair p;
|
|
816 |
p.left_right = (((uint)qFromBigEndian<quint16>(data+off)) << 16) + qFromBigEndian<quint16>(data+off+2);
|
|
817 |
p.adjust = QFixed(((int)(short)qFromBigEndian<quint16>(data+off+4))) / scalingFactor;
|
|
818 |
kerning_pairs.append(p);
|
|
819 |
off += 6;
|
|
820 |
}
|
|
821 |
}
|
|
822 |
offset += length;
|
|
823 |
}
|
|
824 |
}
|
|
825 |
end:
|
|
826 |
qSort(kerning_pairs);
|
|
827 |
// for (int i = 0; i < kerning_pairs.count(); ++i)
|
|
828 |
// qDebug() << 'i' << i << "left_right" << hex << kerning_pairs.at(i).left_right;
|
|
829 |
}
|
|
830 |
|
|
831 |
#else
|
|
832 |
void QFontEngine::doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const
|
|
833 |
{
|
|
834 |
}
|
|
835 |
#endif
|
|
836 |
|
|
837 |
int QFontEngine::glyphCount() const
|
|
838 |
{
|
|
839 |
QByteArray maxpTable = getSfntTable(MAKE_TAG('m', 'a', 'x', 'p'));
|
|
840 |
if (maxpTable.size() < 6)
|
|
841 |
return 0;
|
|
842 |
return qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(maxpTable.constData() + 4));
|
|
843 |
}
|
|
844 |
|
|
845 |
const uchar *QFontEngine::getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
|
|
846 |
{
|
|
847 |
const uchar *header = table;
|
|
848 |
if (tableSize < 4)
|
|
849 |
return 0;
|
|
850 |
|
|
851 |
const uchar *endPtr = table + tableSize;
|
|
852 |
|
|
853 |
// version check
|
|
854 |
if (qFromBigEndian<quint16>(header) != 0)
|
|
855 |
return 0;
|
|
856 |
|
|
857 |
unsigned short numTables = qFromBigEndian<quint16>(header + 2);
|
|
858 |
const uchar *maps = table + 4;
|
|
859 |
if (maps + 8 * numTables > endPtr)
|
|
860 |
return 0;
|
|
861 |
|
|
862 |
enum {
|
|
863 |
Invalid,
|
|
864 |
Symbol,
|
|
865 |
AppleRoman,
|
|
866 |
Unicode11,
|
|
867 |
Unicode,
|
|
868 |
MicrosoftUnicode,
|
|
869 |
MicrosoftUnicodeExtended
|
|
870 |
};
|
|
871 |
|
|
872 |
int symbolTable = -1;
|
|
873 |
int tableToUse = -1;
|
|
874 |
int score = Invalid;
|
|
875 |
for (int n = 0; n < numTables; ++n) {
|
|
876 |
const quint16 platformId = qFromBigEndian<quint16>(maps + 8 * n);
|
|
877 |
const quint16 platformSpecificId = qFromBigEndian<quint16>(maps + 8 * n + 2);
|
|
878 |
switch (platformId) {
|
|
879 |
case 0: // Unicode
|
|
880 |
if (score < Unicode &&
|
|
881 |
(platformSpecificId == 0 ||
|
|
882 |
platformSpecificId == 2 ||
|
|
883 |
platformSpecificId == 3)) {
|
|
884 |
tableToUse = n;
|
|
885 |
score = Unicode;
|
|
886 |
} else if (score < Unicode11 && platformSpecificId == 1) {
|
|
887 |
tableToUse = n;
|
|
888 |
score = Unicode11;
|
|
889 |
}
|
|
890 |
break;
|
|
891 |
case 1: // Apple
|
|
892 |
if (score < AppleRoman && platformSpecificId == 0) { // Apple Roman
|
|
893 |
tableToUse = n;
|
|
894 |
score = AppleRoman;
|
|
895 |
}
|
|
896 |
break;
|
|
897 |
case 3: // Microsoft
|
|
898 |
switch (platformSpecificId) {
|
|
899 |
case 0:
|
|
900 |
symbolTable = n;
|
|
901 |
if (score < Symbol) {
|
|
902 |
tableToUse = n;
|
|
903 |
score = Symbol;
|
|
904 |
}
|
|
905 |
break;
|
|
906 |
case 1:
|
|
907 |
if (score < MicrosoftUnicode) {
|
|
908 |
tableToUse = n;
|
|
909 |
score = MicrosoftUnicode;
|
|
910 |
}
|
|
911 |
break;
|
|
912 |
case 0xa:
|
|
913 |
if (score < MicrosoftUnicodeExtended) {
|
|
914 |
tableToUse = n;
|
|
915 |
score = MicrosoftUnicodeExtended;
|
|
916 |
}
|
|
917 |
break;
|
|
918 |
default:
|
|
919 |
break;
|
|
920 |
}
|
|
921 |
default:
|
|
922 |
break;
|
|
923 |
}
|
|
924 |
}
|
|
925 |
if(tableToUse < 0)
|
|
926 |
return 0;
|
|
927 |
|
|
928 |
resolveTable:
|
|
929 |
*isSymbolFont = (score == Symbol);
|
|
930 |
|
|
931 |
unsigned int unicode_table = qFromBigEndian<quint32>(maps + 8*tableToUse + 4);
|
|
932 |
|
|
933 |
if (!unicode_table || unicode_table + 8 > tableSize)
|
|
934 |
return 0;
|
|
935 |
|
|
936 |
// get the header of the unicode table
|
|
937 |
header = table + unicode_table;
|
|
938 |
|
|
939 |
unsigned short format = qFromBigEndian<quint16>(header);
|
|
940 |
unsigned int length;
|
|
941 |
if(format < 8)
|
|
942 |
length = qFromBigEndian<quint16>(header + 2);
|
|
943 |
else
|
|
944 |
length = qFromBigEndian<quint32>(header + 4);
|
|
945 |
|
|
946 |
if (table + unicode_table + length > endPtr)
|
|
947 |
return 0;
|
|
948 |
*cmapSize = length;
|
|
949 |
|
|
950 |
// To support symbol fonts that contain a unicode table for the symbol area
|
|
951 |
// we check the cmap tables and fall back to symbol font unless that would
|
|
952 |
// involve losing information from the unicode table
|
|
953 |
if (symbolTable > -1 && ((score == Unicode) || (score == Unicode11))) {
|
|
954 |
const uchar *selectedTable = table + unicode_table;
|
|
955 |
|
|
956 |
// Check that none of the latin1 range are in the unicode table
|
|
957 |
bool unicodeTableHasLatin1 = false;
|
|
958 |
for (int uc=0x00; uc<0x100; ++uc) {
|
|
959 |
if (getTrueTypeGlyphIndex(selectedTable, uc) != 0) {
|
|
960 |
unicodeTableHasLatin1 = true;
|
|
961 |
break;
|
|
962 |
}
|
|
963 |
}
|
|
964 |
|
|
965 |
// Check that at least one symbol char is in the unicode table
|
|
966 |
bool unicodeTableHasSymbols = false;
|
|
967 |
if (!unicodeTableHasLatin1) {
|
|
968 |
for (int uc=0xf000; uc<0xf100; ++uc) {
|
|
969 |
if (getTrueTypeGlyphIndex(selectedTable, uc) != 0) {
|
|
970 |
unicodeTableHasSymbols = true;
|
|
971 |
break;
|
|
972 |
}
|
|
973 |
}
|
|
974 |
}
|
|
975 |
|
|
976 |
// Fall back to symbol table
|
|
977 |
if (!unicodeTableHasLatin1 && unicodeTableHasSymbols) {
|
|
978 |
tableToUse = symbolTable;
|
|
979 |
score = Symbol;
|
|
980 |
goto resolveTable;
|
|
981 |
}
|
|
982 |
}
|
|
983 |
|
|
984 |
return table + unicode_table;
|
|
985 |
}
|
|
986 |
|
|
987 |
quint32 QFontEngine::getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
|
|
988 |
{
|
|
989 |
unsigned short format = qFromBigEndian<quint16>(cmap);
|
|
990 |
if (format == 0) {
|
|
991 |
if (unicode < 256)
|
|
992 |
return (int) *(cmap+6+unicode);
|
|
993 |
} else if (format == 4) {
|
|
994 |
/* some fonts come with invalid cmap tables, where the last segment
|
|
995 |
specified end = start = rangeoffset = 0xffff, delta = 0x0001
|
|
996 |
Since 0xffff is never a valid Unicode char anyway, we just get rid of the issue
|
|
997 |
by returning 0 for 0xffff
|
|
998 |
*/
|
|
999 |
if(unicode >= 0xffff)
|
|
1000 |
return 0;
|
|
1001 |
quint16 segCountX2 = qFromBigEndian<quint16>(cmap + 6);
|
|
1002 |
const unsigned char *ends = cmap + 14;
|
|
1003 |
int i = 0;
|
|
1004 |
for (; i < segCountX2/2 && qFromBigEndian<quint16>(ends + 2*i) < unicode; i++) {}
|
|
1005 |
|
|
1006 |
const unsigned char *idx = ends + segCountX2 + 2 + 2*i;
|
|
1007 |
quint16 startIndex = qFromBigEndian<quint16>(idx);
|
|
1008 |
|
|
1009 |
if (startIndex > unicode)
|
|
1010 |
return 0;
|
|
1011 |
|
|
1012 |
idx += segCountX2;
|
|
1013 |
qint16 idDelta = (qint16)qFromBigEndian<quint16>(idx);
|
|
1014 |
idx += segCountX2;
|
|
1015 |
quint16 idRangeoffset_t = (quint16)qFromBigEndian<quint16>(idx);
|
|
1016 |
|
|
1017 |
quint16 glyphIndex;
|
|
1018 |
if (idRangeoffset_t) {
|
|
1019 |
quint16 id = qFromBigEndian<quint16>(idRangeoffset_t + 2*(unicode - startIndex) + idx);
|
|
1020 |
if (id)
|
|
1021 |
glyphIndex = (idDelta + id) % 0x10000;
|
|
1022 |
else
|
|
1023 |
glyphIndex = 0;
|
|
1024 |
} else {
|
|
1025 |
glyphIndex = (idDelta + unicode) % 0x10000;
|
|
1026 |
}
|
|
1027 |
return glyphIndex;
|
|
1028 |
} else if (format == 6) {
|
|
1029 |
quint16 tableSize = qFromBigEndian<quint16>(cmap + 2);
|
|
1030 |
|
|
1031 |
quint16 firstCode6 = qFromBigEndian<quint16>(cmap + 6);
|
|
1032 |
if (unicode < firstCode6)
|
|
1033 |
return 0;
|
|
1034 |
|
|
1035 |
quint16 entryCount6 = qFromBigEndian<quint16>(cmap + 8);
|
|
1036 |
if (entryCount6 * 2 + 10 > tableSize)
|
|
1037 |
return 0;
|
|
1038 |
|
|
1039 |
quint16 sentinel6 = firstCode6 + entryCount6;
|
|
1040 |
if (unicode >= sentinel6)
|
|
1041 |
return 0;
|
|
1042 |
|
|
1043 |
quint16 entryIndex6 = unicode - firstCode6;
|
|
1044 |
return qFromBigEndian<quint16>(cmap + 10 + (entryIndex6 * 2));
|
|
1045 |
} else if (format == 12) {
|
|
1046 |
quint32 nGroups = qFromBigEndian<quint32>(cmap + 12);
|
|
1047 |
|
|
1048 |
cmap += 16; // move to start of groups
|
|
1049 |
|
|
1050 |
int left = 0, right = nGroups - 1;
|
|
1051 |
while (left <= right) {
|
|
1052 |
int middle = left + ( ( right - left ) >> 1 );
|
|
1053 |
|
|
1054 |
quint32 startCharCode = qFromBigEndian<quint32>(cmap + 12*middle);
|
|
1055 |
if(unicode < startCharCode)
|
|
1056 |
right = middle - 1;
|
|
1057 |
else {
|
|
1058 |
quint32 endCharCode = qFromBigEndian<quint32>(cmap + 12*middle + 4);
|
|
1059 |
if(unicode <= endCharCode)
|
|
1060 |
return qFromBigEndian<quint32>(cmap + 12*middle + 8) + unicode - startCharCode;
|
|
1061 |
left = middle + 1;
|
|
1062 |
}
|
|
1063 |
}
|
|
1064 |
} else {
|
|
1065 |
qDebug("cmap table of format %d not implemented", format);
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
return 0;
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
Q_GLOBAL_STATIC_WITH_INITIALIZER(QVector<QRgb>, qt_grayPalette, {
|
|
1072 |
x->resize(256);
|
|
1073 |
QRgb *it = x->data();
|
|
1074 |
for (int i = 0; i < x->size(); ++i, ++it)
|
|
1075 |
*it = 0xff000000 | i | (i<<8) | (i<<16);
|
|
1076 |
})
|
|
1077 |
|
|
1078 |
const QVector<QRgb> &QFontEngine::grayPalette()
|
|
1079 |
{
|
|
1080 |
return *qt_grayPalette();
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
// ------------------------------------------------------------------
|
|
1084 |
// The box font engine
|
|
1085 |
// ------------------------------------------------------------------
|
|
1086 |
|
|
1087 |
QFontEngineBox::QFontEngineBox(int size)
|
|
1088 |
: _size(size)
|
|
1089 |
{
|
|
1090 |
cache_cost = sizeof(QFontEngineBox);
|
|
1091 |
}
|
|
1092 |
|
|
1093 |
QFontEngineBox::~QFontEngineBox()
|
|
1094 |
{
|
|
1095 |
}
|
|
1096 |
|
|
1097 |
bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags) const
|
|
1098 |
{
|
|
1099 |
if (*nglyphs < len) {
|
|
1100 |
*nglyphs = len;
|
|
1101 |
return false;
|
|
1102 |
}
|
|
1103 |
|
|
1104 |
for (int i = 0; i < len; i++) {
|
|
1105 |
glyphs->glyphs[i] = 0;
|
|
1106 |
glyphs->advances_x[i] = _size;
|
|
1107 |
glyphs->advances_y[i] = 0;
|
|
1108 |
}
|
|
1109 |
|
|
1110 |
*nglyphs = len;
|
|
1111 |
glyphs->numGlyphs = len;
|
|
1112 |
return true;
|
|
1113 |
}
|
|
1114 |
|
|
1115 |
void QFontEngineBox::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
|
|
1116 |
{
|
|
1117 |
for (int i = 0; i < glyphs->numGlyphs; i++) {
|
|
1118 |
glyphs->advances_x[i] = _size;
|
|
1119 |
glyphs->advances_y[i] = 0;
|
|
1120 |
}
|
|
1121 |
}
|
|
1122 |
|
|
1123 |
void QFontEngineBox::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
|
|
1124 |
{
|
|
1125 |
if (!glyphs.numGlyphs)
|
|
1126 |
return;
|
|
1127 |
|
|
1128 |
QVarLengthArray<QFixedPoint> positions;
|
|
1129 |
QVarLengthArray<glyph_t> positioned_glyphs;
|
|
1130 |
QTransform matrix = QTransform::fromTranslate(x, y - _size);
|
|
1131 |
getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
|
|
1132 |
|
|
1133 |
QSize s(_size - 3, _size - 3);
|
|
1134 |
for (int k = 0; k < positions.size(); k++)
|
|
1135 |
path->addRect(QRectF(positions[k].toPointF(), s));
|
|
1136 |
}
|
|
1137 |
|
|
1138 |
glyph_metrics_t QFontEngineBox::boundingBox(const QGlyphLayout &glyphs)
|
|
1139 |
{
|
|
1140 |
glyph_metrics_t overall;
|
|
1141 |
overall.width = _size*glyphs.numGlyphs;
|
|
1142 |
overall.height = _size;
|
|
1143 |
overall.xoff = overall.width;
|
|
1144 |
return overall;
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
#if defined(Q_WS_QWS)
|
|
1148 |
void QFontEngineBox::draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &ti)
|
|
1149 |
{
|
|
1150 |
if (!ti.glyphs.numGlyphs)
|
|
1151 |
return;
|
|
1152 |
|
|
1153 |
// any fixes here should probably also be done in QPaintEnginePrivate::drawBoxTextItem
|
|
1154 |
QSize s(_size - 3, _size - 3);
|
|
1155 |
|
|
1156 |
QVarLengthArray<QFixedPoint> positions;
|
|
1157 |
QVarLengthArray<glyph_t> glyphs;
|
|
1158 |
QTransform matrix = QTransform::fromTranslate(x, y - _size);
|
|
1159 |
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
|
|
1160 |
if (glyphs.size() == 0)
|
|
1161 |
return;
|
|
1162 |
|
|
1163 |
|
|
1164 |
QPainter *painter = p->painter();
|
|
1165 |
painter->save();
|
|
1166 |
painter->setBrush(Qt::NoBrush);
|
|
1167 |
QPen pen = painter->pen();
|
|
1168 |
pen.setWidthF(lineThickness().toReal());
|
|
1169 |
painter->setPen(pen);
|
|
1170 |
for (int k = 0; k < positions.size(); k++)
|
|
1171 |
painter->drawRect(QRectF(positions[k].toPointF(), s));
|
|
1172 |
painter->restore();
|
|
1173 |
}
|
|
1174 |
#endif
|
|
1175 |
|
|
1176 |
glyph_metrics_t QFontEngineBox::boundingBox(glyph_t)
|
|
1177 |
{
|
|
1178 |
return glyph_metrics_t(0, -_size, _size, _size, _size, 0);
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
|
|
1182 |
|
|
1183 |
QFixed QFontEngineBox::ascent() const
|
|
1184 |
{
|
|
1185 |
return _size;
|
|
1186 |
}
|
|
1187 |
|
|
1188 |
QFixed QFontEngineBox::descent() const
|
|
1189 |
{
|
|
1190 |
return 0;
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
QFixed QFontEngineBox::leading() const
|
|
1194 |
{
|
|
1195 |
QFixed l = _size * QFixed::fromReal(qreal(0.15));
|
|
1196 |
return l.ceil();
|
|
1197 |
}
|
|
1198 |
|
|
1199 |
qreal QFontEngineBox::maxCharWidth() const
|
|
1200 |
{
|
|
1201 |
return _size;
|
|
1202 |
}
|
|
1203 |
|
|
1204 |
#ifdef Q_WS_X11
|
|
1205 |
int QFontEngineBox::cmap() const
|
|
1206 |
{
|
|
1207 |
return -1;
|
|
1208 |
}
|
|
1209 |
#endif
|
|
1210 |
|
|
1211 |
const char *QFontEngineBox::name() const
|
|
1212 |
{
|
|
1213 |
return "null";
|
|
1214 |
}
|
|
1215 |
|
|
1216 |
bool QFontEngineBox::canRender(const QChar *, int)
|
|
1217 |
{
|
|
1218 |
return true;
|
|
1219 |
}
|
|
1220 |
|
|
1221 |
QFontEngine::Type QFontEngineBox::type() const
|
|
1222 |
{
|
|
1223 |
return Box;
|
|
1224 |
}
|
|
1225 |
|
|
1226 |
QImage QFontEngineBox::alphaMapForGlyph(glyph_t)
|
|
1227 |
{
|
|
1228 |
QImage image(_size, _size, QImage::Format_Indexed8);
|
|
1229 |
QVector<QRgb> colors(256);
|
|
1230 |
for (int i=0; i<256; ++i)
|
|
1231 |
colors[i] = qRgba(0, 0, 0, i);
|
|
1232 |
image.setColorTable(colors);
|
|
1233 |
image.fill(0);
|
|
1234 |
|
|
1235 |
// can't use qpainter for index8; so use setPixel to draw our rectangle.
|
|
1236 |
for (int i=2; i <= _size-3; ++i) {
|
|
1237 |
image.setPixel(i, 2, 255);
|
|
1238 |
image.setPixel(i, _size-3, 255);
|
|
1239 |
image.setPixel(2, i, 255);
|
|
1240 |
image.setPixel(_size-3, i, 255);
|
|
1241 |
}
|
|
1242 |
return image;
|
|
1243 |
}
|
|
1244 |
|
|
1245 |
// ------------------------------------------------------------------
|
|
1246 |
// Multi engine
|
|
1247 |
// ------------------------------------------------------------------
|
|
1248 |
|
|
1249 |
static inline uchar highByte(glyph_t glyph)
|
|
1250 |
{ return glyph >> 24; }
|
|
1251 |
|
|
1252 |
// strip high byte from glyph
|
|
1253 |
static inline glyph_t stripped(glyph_t glyph)
|
|
1254 |
{ return glyph & 0x00ffffff; }
|
|
1255 |
|
|
1256 |
QFontEngineMulti::QFontEngineMulti(int engineCount)
|
|
1257 |
{
|
|
1258 |
engines.fill(0, engineCount);
|
|
1259 |
cache_cost = 0;
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
QFontEngineMulti::~QFontEngineMulti()
|
|
1263 |
{
|
|
1264 |
for (int i = 0; i < engines.size(); ++i) {
|
|
1265 |
QFontEngine *fontEngine = engines.at(i);
|
|
1266 |
if (fontEngine) {
|
|
1267 |
fontEngine->ref.deref();
|
|
1268 |
if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
|
|
1269 |
delete fontEngine;
|
|
1270 |
}
|
|
1271 |
}
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
|
|
1275 |
QGlyphLayout *glyphs, int *nglyphs,
|
|
1276 |
QTextEngine::ShaperFlags flags) const
|
|
1277 |
{
|
|
1278 |
int ng = *nglyphs;
|
|
1279 |
if (!engine(0)->stringToCMap(str, len, glyphs, &ng, flags))
|
|
1280 |
return false;
|
|
1281 |
|
|
1282 |
int glyph_pos = 0;
|
|
1283 |
for (int i = 0; i < len; ++i) {
|
|
1284 |
bool surrogate = (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 && i < len-1
|
|
1285 |
&& str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000);
|
|
1286 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1287 |
if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
|
0
|
1288 |
QGlyphLayoutInstance tmp = glyphs->instance(glyph_pos);
|
|
1289 |
for (int x = 1; x < engines.size(); ++x) {
|
|
1290 |
QFontEngine *engine = engines.at(x);
|
|
1291 |
if (!engine) {
|
|
1292 |
const_cast<QFontEngineMulti *>(this)->loadEngine(x);
|
|
1293 |
engine = engines.at(x);
|
|
1294 |
}
|
|
1295 |
Q_ASSERT(engine != 0);
|
|
1296 |
if (engine->type() == Box)
|
|
1297 |
continue;
|
|
1298 |
glyphs->advances_x[glyph_pos] = glyphs->advances_y[glyph_pos] = 0;
|
|
1299 |
glyphs->offsets[glyph_pos] = QFixedPoint();
|
|
1300 |
int num = 2;
|
|
1301 |
QGlyphLayout offs = glyphs->mid(glyph_pos, num);
|
|
1302 |
engine->stringToCMap(str + i, surrogate ? 2 : 1, &offs, &num, flags);
|
|
1303 |
Q_ASSERT(num == 1); // surrogates only give 1 glyph
|
|
1304 |
if (glyphs->glyphs[glyph_pos]) {
|
|
1305 |
// set the high byte to indicate which engine the glyph came from
|
|
1306 |
glyphs->glyphs[glyph_pos] |= (x << 24);
|
|
1307 |
break;
|
|
1308 |
}
|
|
1309 |
}
|
|
1310 |
// ensure we use metrics from the 1st font when we use the fallback image.
|
|
1311 |
if (!glyphs->glyphs[glyph_pos]) {
|
|
1312 |
glyphs->setInstance(glyph_pos, tmp);
|
|
1313 |
}
|
|
1314 |
}
|
|
1315 |
if (surrogate)
|
|
1316 |
++i;
|
|
1317 |
++glyph_pos;
|
|
1318 |
}
|
|
1319 |
|
|
1320 |
*nglyphs = ng;
|
|
1321 |
glyphs->numGlyphs = ng;
|
|
1322 |
return true;
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
glyph_metrics_t QFontEngineMulti::boundingBox(const QGlyphLayout &glyphs)
|
|
1326 |
{
|
|
1327 |
if (glyphs.numGlyphs <= 0)
|
|
1328 |
return glyph_metrics_t();
|
|
1329 |
|
|
1330 |
glyph_metrics_t overall;
|
|
1331 |
|
|
1332 |
int which = highByte(glyphs.glyphs[0]);
|
|
1333 |
int start = 0;
|
|
1334 |
int end, i;
|
|
1335 |
for (end = 0; end < glyphs.numGlyphs; ++end) {
|
|
1336 |
const int e = highByte(glyphs.glyphs[end]);
|
|
1337 |
if (e == which)
|
|
1338 |
continue;
|
|
1339 |
|
|
1340 |
// set the high byte to zero
|
|
1341 |
for (i = start; i < end; ++i)
|
|
1342 |
glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
|
|
1343 |
|
|
1344 |
// merge the bounding box for this run
|
|
1345 |
const glyph_metrics_t gm = engine(which)->boundingBox(glyphs.mid(start, end - start));
|
|
1346 |
|
|
1347 |
overall.x = qMin(overall.x, gm.x);
|
|
1348 |
overall.y = qMin(overall.y, gm.y);
|
|
1349 |
overall.width = overall.xoff + gm.width;
|
|
1350 |
overall.height = qMax(overall.height + overall.y, gm.height + gm.y) -
|
|
1351 |
qMin(overall.y, gm.y);
|
|
1352 |
overall.xoff += gm.xoff;
|
|
1353 |
overall.yoff += gm.yoff;
|
|
1354 |
|
|
1355 |
// reset the high byte for all glyphs
|
|
1356 |
const int hi = which << 24;
|
|
1357 |
for (i = start; i < end; ++i)
|
|
1358 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i];
|
|
1359 |
|
|
1360 |
// change engine
|
|
1361 |
start = end;
|
|
1362 |
which = e;
|
|
1363 |
}
|
|
1364 |
|
|
1365 |
// set the high byte to zero
|
|
1366 |
for (i = start; i < end; ++i)
|
|
1367 |
glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
|
|
1368 |
|
|
1369 |
// merge the bounding box for this run
|
|
1370 |
const glyph_metrics_t gm = engine(which)->boundingBox(glyphs.mid(start, end - start));
|
|
1371 |
|
|
1372 |
overall.x = qMin(overall.x, gm.x);
|
|
1373 |
overall.y = qMin(overall.y, gm.y);
|
|
1374 |
overall.width = overall.xoff + gm.width;
|
|
1375 |
overall.height = qMax(overall.height + overall.y, gm.height + gm.y) -
|
|
1376 |
qMin(overall.y, gm.y);
|
|
1377 |
overall.xoff += gm.xoff;
|
|
1378 |
overall.yoff += gm.yoff;
|
|
1379 |
|
|
1380 |
// reset the high byte for all glyphs
|
|
1381 |
const int hi = which << 24;
|
|
1382 |
for (i = start; i < end; ++i)
|
|
1383 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i];
|
|
1384 |
|
|
1385 |
return overall;
|
|
1386 |
}
|
|
1387 |
|
|
1388 |
void QFontEngineMulti::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
|
|
1389 |
QPainterPath *path, QTextItem::RenderFlags flags)
|
|
1390 |
{
|
|
1391 |
if (glyphs.numGlyphs <= 0)
|
|
1392 |
return;
|
|
1393 |
|
|
1394 |
int which = highByte(glyphs.glyphs[0]);
|
|
1395 |
int start = 0;
|
|
1396 |
int end, i;
|
|
1397 |
if (flags & QTextItem::RightToLeft) {
|
|
1398 |
for (int gl = 0; gl < glyphs.numGlyphs; gl++) {
|
|
1399 |
x += glyphs.advances_x[gl].toReal();
|
|
1400 |
y += glyphs.advances_y[gl].toReal();
|
|
1401 |
}
|
|
1402 |
}
|
|
1403 |
for (end = 0; end < glyphs.numGlyphs; ++end) {
|
|
1404 |
const int e = highByte(glyphs.glyphs[end]);
|
|
1405 |
if (e == which)
|
|
1406 |
continue;
|
|
1407 |
|
|
1408 |
if (flags & QTextItem::RightToLeft) {
|
|
1409 |
for (i = start; i < end; ++i) {
|
|
1410 |
x -= glyphs.advances_x[i].toReal();
|
|
1411 |
y -= glyphs.advances_y[i].toReal();
|
|
1412 |
}
|
|
1413 |
}
|
|
1414 |
|
|
1415 |
// set the high byte to zero
|
|
1416 |
for (i = start; i < end; ++i)
|
|
1417 |
glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
|
|
1418 |
engine(which)->addOutlineToPath(x, y, glyphs.mid(start, end - start), path, flags);
|
|
1419 |
// reset the high byte for all glyphs and update x and y
|
|
1420 |
const int hi = which << 24;
|
|
1421 |
for (i = start; i < end; ++i)
|
|
1422 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i];
|
|
1423 |
|
|
1424 |
if (!(flags & QTextItem::RightToLeft)) {
|
|
1425 |
for (i = start; i < end; ++i) {
|
|
1426 |
x += glyphs.advances_x[i].toReal();
|
|
1427 |
y += glyphs.advances_y[i].toReal();
|
|
1428 |
}
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
// change engine
|
|
1432 |
start = end;
|
|
1433 |
which = e;
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
if (flags & QTextItem::RightToLeft) {
|
|
1437 |
for (i = start; i < end; ++i) {
|
|
1438 |
x -= glyphs.advances_x[i].toReal();
|
|
1439 |
y -= glyphs.advances_y[i].toReal();
|
|
1440 |
}
|
|
1441 |
}
|
|
1442 |
|
|
1443 |
// set the high byte to zero
|
|
1444 |
for (i = start; i < end; ++i)
|
|
1445 |
glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
|
|
1446 |
|
|
1447 |
engine(which)->addOutlineToPath(x, y, glyphs.mid(start, end - start), path, flags);
|
|
1448 |
|
|
1449 |
// reset the high byte for all glyphs
|
|
1450 |
const int hi = which << 24;
|
|
1451 |
for (i = start; i < end; ++i)
|
|
1452 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i];
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
void QFontEngineMulti::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
|
|
1456 |
{
|
|
1457 |
if (glyphs->numGlyphs <= 0)
|
|
1458 |
return;
|
|
1459 |
|
|
1460 |
int which = highByte(glyphs->glyphs[0]);
|
|
1461 |
int start = 0;
|
|
1462 |
int end, i;
|
|
1463 |
for (end = 0; end < glyphs->numGlyphs; ++end) {
|
|
1464 |
const int e = highByte(glyphs->glyphs[end]);
|
|
1465 |
if (e == which)
|
|
1466 |
continue;
|
|
1467 |
|
|
1468 |
// set the high byte to zero
|
|
1469 |
for (i = start; i < end; ++i)
|
|
1470 |
glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
|
|
1471 |
|
|
1472 |
QGlyphLayout offs = glyphs->mid(start, end - start);
|
|
1473 |
engine(which)->recalcAdvances(&offs, flags);
|
|
1474 |
|
|
1475 |
// reset the high byte for all glyphs and update x and y
|
|
1476 |
const int hi = which << 24;
|
|
1477 |
for (i = start; i < end; ++i)
|
|
1478 |
glyphs->glyphs[i] = hi | glyphs->glyphs[i];
|
|
1479 |
|
|
1480 |
// change engine
|
|
1481 |
start = end;
|
|
1482 |
which = e;
|
|
1483 |
}
|
|
1484 |
|
|
1485 |
// set the high byte to zero
|
|
1486 |
for (i = start; i < end; ++i)
|
|
1487 |
glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
|
|
1488 |
|
|
1489 |
QGlyphLayout offs = glyphs->mid(start, end - start);
|
|
1490 |
engine(which)->recalcAdvances(&offs, flags);
|
|
1491 |
|
|
1492 |
// reset the high byte for all glyphs
|
|
1493 |
const int hi = which << 24;
|
|
1494 |
for (i = start; i < end; ++i)
|
|
1495 |
glyphs->glyphs[i] = hi | glyphs->glyphs[i];
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
void QFontEngineMulti::doKerning(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
|
|
1499 |
{
|
|
1500 |
if (glyphs->numGlyphs <= 0)
|
|
1501 |
return;
|
|
1502 |
|
|
1503 |
int which = highByte(glyphs->glyphs[0]);
|
|
1504 |
int start = 0;
|
|
1505 |
int end, i;
|
|
1506 |
for (end = 0; end < glyphs->numGlyphs; ++end) {
|
|
1507 |
const int e = highByte(glyphs->glyphs[end]);
|
|
1508 |
if (e == which)
|
|
1509 |
continue;
|
|
1510 |
|
|
1511 |
// set the high byte to zero
|
|
1512 |
for (i = start; i < end; ++i)
|
|
1513 |
glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
|
|
1514 |
|
|
1515 |
QGlyphLayout offs = glyphs->mid(start, end - start);
|
|
1516 |
engine(which)->doKerning(&offs, flags);
|
|
1517 |
|
|
1518 |
// reset the high byte for all glyphs and update x and y
|
|
1519 |
const int hi = which << 24;
|
|
1520 |
for (i = start; i < end; ++i)
|
|
1521 |
glyphs->glyphs[i] = hi | glyphs->glyphs[i];
|
|
1522 |
|
|
1523 |
// change engine
|
|
1524 |
start = end;
|
|
1525 |
which = e;
|
|
1526 |
}
|
|
1527 |
|
|
1528 |
// set the high byte to zero
|
|
1529 |
for (i = start; i < end; ++i)
|
|
1530 |
glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
|
|
1531 |
|
|
1532 |
QGlyphLayout offs = glyphs->mid(start, end - start);
|
|
1533 |
engine(which)->doKerning(&offs, flags);
|
|
1534 |
|
|
1535 |
// reset the high byte for all glyphs
|
|
1536 |
const int hi = which << 24;
|
|
1537 |
for (i = start; i < end; ++i)
|
|
1538 |
glyphs->glyphs[i] = hi | glyphs->glyphs[i];
|
|
1539 |
}
|
|
1540 |
|
|
1541 |
glyph_metrics_t QFontEngineMulti::boundingBox(glyph_t glyph)
|
|
1542 |
{
|
|
1543 |
const int which = highByte(glyph);
|
|
1544 |
Q_ASSERT(which < engines.size());
|
|
1545 |
return engine(which)->boundingBox(stripped(glyph));
|
|
1546 |
}
|
|
1547 |
|
|
1548 |
QFixed QFontEngineMulti::ascent() const
|
|
1549 |
{ return engine(0)->ascent(); }
|
|
1550 |
|
|
1551 |
QFixed QFontEngineMulti::descent() const
|
|
1552 |
{ return engine(0)->descent(); }
|
|
1553 |
|
|
1554 |
QFixed QFontEngineMulti::leading() const
|
|
1555 |
{
|
|
1556 |
return engine(0)->leading();
|
|
1557 |
}
|
|
1558 |
|
|
1559 |
QFixed QFontEngineMulti::xHeight() const
|
|
1560 |
{
|
|
1561 |
return engine(0)->xHeight();
|
|
1562 |
}
|
|
1563 |
|
|
1564 |
QFixed QFontEngineMulti::averageCharWidth() const
|
|
1565 |
{
|
|
1566 |
return engine(0)->averageCharWidth();
|
|
1567 |
}
|
|
1568 |
|
|
1569 |
QFixed QFontEngineMulti::lineThickness() const
|
|
1570 |
{
|
|
1571 |
return engine(0)->lineThickness();
|
|
1572 |
}
|
|
1573 |
|
|
1574 |
QFixed QFontEngineMulti::underlinePosition() const
|
|
1575 |
{
|
|
1576 |
return engine(0)->underlinePosition();
|
|
1577 |
}
|
|
1578 |
|
|
1579 |
qreal QFontEngineMulti::maxCharWidth() const
|
|
1580 |
{
|
|
1581 |
return engine(0)->maxCharWidth();
|
|
1582 |
}
|
|
1583 |
|
|
1584 |
qreal QFontEngineMulti::minLeftBearing() const
|
|
1585 |
{
|
|
1586 |
return engine(0)->minLeftBearing();
|
|
1587 |
}
|
|
1588 |
|
|
1589 |
qreal QFontEngineMulti::minRightBearing() const
|
|
1590 |
{
|
|
1591 |
return engine(0)->minRightBearing();
|
|
1592 |
}
|
|
1593 |
|
|
1594 |
bool QFontEngineMulti::canRender(const QChar *string, int len)
|
|
1595 |
{
|
|
1596 |
if (engine(0)->canRender(string, len))
|
|
1597 |
return true;
|
|
1598 |
|
|
1599 |
QVarLengthGlyphLayoutArray glyphs(len);
|
|
1600 |
int nglyphs = len;
|
|
1601 |
if (stringToCMap(string, len, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly) == false) {
|
|
1602 |
glyphs.resize(nglyphs);
|
|
1603 |
stringToCMap(string, len, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
|
|
1604 |
}
|
|
1605 |
|
|
1606 |
bool allExist = true;
|
|
1607 |
for (int i = 0; i < nglyphs; i++) {
|
|
1608 |
if (!glyphs.glyphs[i]) {
|
|
1609 |
allExist = false;
|
|
1610 |
break;
|
|
1611 |
}
|
|
1612 |
}
|
|
1613 |
|
|
1614 |
return allExist;
|
|
1615 |
}
|
|
1616 |
|
|
1617 |
QImage QFontEngineMulti::alphaMapForGlyph(glyph_t)
|
|
1618 |
{
|
|
1619 |
Q_ASSERT(false);
|
|
1620 |
return QImage();
|
|
1621 |
}
|
|
1622 |
|
|
1623 |
|
|
1624 |
QT_END_NAMESPACE
|