0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 "qabstractfontengine_qws.h"
|
|
43 |
#include "qabstractfontengine_p.h"
|
|
44 |
|
|
45 |
#include <private/qtextengine_p.h>
|
|
46 |
#include <private/qpaintengine_raster_p.h>
|
|
47 |
|
|
48 |
#include <qmath.h>
|
|
49 |
|
|
50 |
QT_BEGIN_NAMESPACE
|
|
51 |
|
|
52 |
class QFontEngineInfoPrivate
|
|
53 |
{
|
|
54 |
public:
|
|
55 |
inline QFontEngineInfoPrivate()
|
|
56 |
: pixelSize(0), weight(QFont::Normal), style(QFont::StyleNormal)
|
|
57 |
{}
|
|
58 |
|
|
59 |
QString family;
|
|
60 |
qreal pixelSize;
|
|
61 |
int weight;
|
|
62 |
QFont::Style style;
|
|
63 |
QList<QFontDatabase::WritingSystem> writingSystems;
|
|
64 |
};
|
|
65 |
|
|
66 |
/*!
|
|
67 |
\class QFontEngineInfo
|
|
68 |
\preliminary
|
|
69 |
\brief The QFontEngineInfo class describes a specific font provided by a font engine plugin.
|
|
70 |
\since 4.3
|
|
71 |
\ingroup qws
|
|
72 |
|
|
73 |
\tableofcontents
|
|
74 |
|
|
75 |
QFontEngineInfo is used to describe a request of a font to a font engine plugin as well as to
|
|
76 |
describe the actual fonts a plugin provides.
|
|
77 |
|
|
78 |
\sa QAbstractFontEngine, QFontEnginePlugin
|
|
79 |
*/
|
|
80 |
|
|
81 |
/*!
|
|
82 |
Constructs a new empty QFontEngineInfo.
|
|
83 |
*/
|
|
84 |
QFontEngineInfo::QFontEngineInfo()
|
|
85 |
{
|
|
86 |
d = new QFontEngineInfoPrivate;
|
|
87 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
Constructs a new QFontEngineInfo with the specified \a family.
|
|
91 |
The resulting object represents a freely scalable font with normal
|
|
92 |
weight and style.
|
|
93 |
*/
|
|
94 |
QFontEngineInfo::QFontEngineInfo(const QString &family)
|
|
95 |
{
|
|
96 |
d = new QFontEngineInfoPrivate;
|
|
97 |
d->family = family;
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Creates a new font engine info object with the same attributes as \a other.
|
|
102 |
*/
|
|
103 |
QFontEngineInfo::QFontEngineInfo(const QFontEngineInfo &other)
|
|
104 |
: d(new QFontEngineInfoPrivate(*other.d))
|
|
105 |
{
|
|
106 |
}
|
|
107 |
|
|
108 |
/*!
|
|
109 |
Assigns \a other to this font engine info object, and returns a reference
|
|
110 |
to this.
|
|
111 |
*/
|
|
112 |
QFontEngineInfo &QFontEngineInfo::operator=(const QFontEngineInfo &other)
|
|
113 |
{
|
|
114 |
*d = *other.d;
|
|
115 |
return *this;
|
|
116 |
}
|
|
117 |
|
|
118 |
/*!
|
|
119 |
Destroys this QFontEngineInfo object.
|
|
120 |
*/
|
|
121 |
QFontEngineInfo::~QFontEngineInfo()
|
|
122 |
{
|
|
123 |
delete d;
|
|
124 |
}
|
|
125 |
|
|
126 |
/*!
|
|
127 |
\property QFontEngineInfo::family
|
|
128 |
the family name of the font
|
|
129 |
*/
|
|
130 |
|
|
131 |
void QFontEngineInfo::setFamily(const QString &family)
|
|
132 |
{
|
|
133 |
d->family = family;
|
|
134 |
}
|
|
135 |
|
|
136 |
QString QFontEngineInfo::family() const
|
|
137 |
{
|
|
138 |
return d->family;
|
|
139 |
}
|
|
140 |
|
|
141 |
/*!
|
|
142 |
\property QFontEngineInfo::pixelSize
|
|
143 |
the pixel size of the font
|
|
144 |
|
|
145 |
A pixel size of 0 represents a freely scalable font.
|
|
146 |
*/
|
|
147 |
|
|
148 |
void QFontEngineInfo::setPixelSize(qreal size)
|
|
149 |
{
|
|
150 |
d->pixelSize = size;
|
|
151 |
}
|
|
152 |
|
|
153 |
qreal QFontEngineInfo::pixelSize() const
|
|
154 |
{
|
|
155 |
return d->pixelSize;
|
|
156 |
}
|
|
157 |
|
|
158 |
/*!
|
|
159 |
\property QFontEngineInfo::weight
|
|
160 |
the weight of the font
|
|
161 |
|
|
162 |
The value should be from the \l{QFont::Weight} enumeration.
|
|
163 |
*/
|
|
164 |
|
|
165 |
void QFontEngineInfo::setWeight(int weight)
|
|
166 |
{
|
|
167 |
d->weight = weight;
|
|
168 |
}
|
|
169 |
|
|
170 |
int QFontEngineInfo::weight() const
|
|
171 |
{
|
|
172 |
return d->weight;
|
|
173 |
}
|
|
174 |
|
|
175 |
/*!
|
|
176 |
\property QFontEngineInfo::style
|
|
177 |
the style of the font
|
|
178 |
*/
|
|
179 |
|
|
180 |
void QFontEngineInfo::setStyle(QFont::Style style)
|
|
181 |
{
|
|
182 |
d->style = style;
|
|
183 |
}
|
|
184 |
|
|
185 |
QFont::Style QFontEngineInfo::style() const
|
|
186 |
{
|
|
187 |
return d->style;
|
|
188 |
}
|
|
189 |
|
|
190 |
/*!
|
|
191 |
\property QFontEngineInfo::writingSystems
|
|
192 |
the writing systems supported by the font
|
|
193 |
|
|
194 |
An empty list means that any writing system is supported.
|
|
195 |
*/
|
|
196 |
|
|
197 |
QList<QFontDatabase::WritingSystem> QFontEngineInfo::writingSystems() const
|
|
198 |
{
|
|
199 |
return d->writingSystems;
|
|
200 |
}
|
|
201 |
|
|
202 |
void QFontEngineInfo::setWritingSystems(const QList<QFontDatabase::WritingSystem> &writingSystems)
|
|
203 |
{
|
|
204 |
d->writingSystems = writingSystems;
|
|
205 |
}
|
|
206 |
|
|
207 |
class QFontEnginePluginPrivate : public QObjectPrivate
|
|
208 |
{
|
|
209 |
Q_DECLARE_PUBLIC(QFontEnginePlugin)
|
|
210 |
|
|
211 |
QString foundry;
|
|
212 |
};
|
|
213 |
|
|
214 |
/*!
|
|
215 |
\class QFontEnginePlugin
|
|
216 |
\preliminary
|
|
217 |
\brief The QFontEnginePlugin class is the base class for font engine factory plugins in Qt for Embedded Linux.
|
|
218 |
\since 4.3
|
|
219 |
\ingroup qws
|
|
220 |
\ingroup plugins
|
|
221 |
|
|
222 |
\tableofcontents
|
|
223 |
|
|
224 |
QFontEnginePlugin is provided by font engine plugins to create
|
|
225 |
instances of subclasses of QAbstractFontEngine.
|
|
226 |
|
|
227 |
The member functions create() and availableFontEngines() must be
|
|
228 |
implemented.
|
|
229 |
|
|
230 |
\sa QAbstractFontEngine, QFontEngineInfo
|
|
231 |
*/
|
|
232 |
|
|
233 |
/*!
|
|
234 |
Creates a font engine plugin that creates font engines with the
|
|
235 |
specified \a foundry and \a parent.
|
|
236 |
*/
|
|
237 |
QFontEnginePlugin::QFontEnginePlugin(const QString &foundry, QObject *parent)
|
|
238 |
: QObject(*new QFontEnginePluginPrivate, parent)
|
|
239 |
{
|
|
240 |
Q_D(QFontEnginePlugin);
|
|
241 |
d->foundry = foundry;
|
|
242 |
}
|
|
243 |
|
|
244 |
/*!
|
|
245 |
Destroys this font engine plugin.
|
|
246 |
*/
|
|
247 |
QFontEnginePlugin::~QFontEnginePlugin()
|
|
248 |
{
|
|
249 |
}
|
|
250 |
|
|
251 |
/*!
|
|
252 |
Returns a list of foundries the font engine plugin provides.
|
|
253 |
The default implementation returns the foundry specified with the constructor.
|
|
254 |
*/
|
|
255 |
QStringList QFontEnginePlugin::keys() const
|
|
256 |
{
|
|
257 |
Q_D(const QFontEnginePlugin);
|
|
258 |
return QStringList(d->foundry);
|
|
259 |
}
|
|
260 |
|
|
261 |
/*!
|
|
262 |
\fn QAbstractFontEngine *QFontEnginePlugin::create(const QFontEngineInfo &info)
|
|
263 |
|
|
264 |
Implemented in subclasses to create a new font engine that provides a font that
|
|
265 |
matches \a info.
|
|
266 |
*/
|
|
267 |
|
|
268 |
/*!
|
|
269 |
\fn QList<QFontEngineInfo> QFontEnginePlugin::availableFontEngines() const
|
|
270 |
|
|
271 |
Implemented in subclasses to return a list of QFontEngineInfo objects that represents all font
|
|
272 |
engines the plugin can create.
|
|
273 |
*/
|
|
274 |
|
|
275 |
class QAbstractFontEnginePrivate : public QObjectPrivate
|
|
276 |
{
|
|
277 |
Q_DECLARE_PUBLIC(QAbstractFontEngine)
|
|
278 |
public:
|
|
279 |
};
|
|
280 |
|
|
281 |
//The <classname> class is|provides|contains|specifies...
|
|
282 |
/*!
|
|
283 |
\class QAbstractFontEngine
|
|
284 |
\preliminary
|
|
285 |
\brief The QAbstractFontEngine class is the base class for font engine plugins in Qt for Embedded Linux.
|
|
286 |
\since 4.3
|
|
287 |
\ingroup qws
|
|
288 |
|
|
289 |
\tableofcontents
|
|
290 |
|
|
291 |
QAbstractFontEngine is implemented by font engine plugins through QFontEnginePlugin.
|
|
292 |
|
|
293 |
\sa QFontEnginePlugin, QFontEngineInfo
|
|
294 |
*/
|
|
295 |
|
|
296 |
/*!
|
|
297 |
\enum QAbstractFontEngine::Capability
|
|
298 |
|
|
299 |
This enum describes the capabilities of a font engine.
|
|
300 |
|
|
301 |
\value CanRenderGlyphs_Gray The font engine can render individual glyphs into 8 bpp images.
|
|
302 |
\value CanRenderGlyphs_Mono The font engine can render individual glyphs into 1 bpp images.
|
|
303 |
\value CanRenderGlyphs The font engine can render individual glyphs into images.
|
|
304 |
\value CanOutlineGlyphs The font engine can convert glyphs to painter paths.
|
|
305 |
*/
|
|
306 |
|
|
307 |
/*!
|
|
308 |
\enum QAbstractFontEngine::FontProperty
|
|
309 |
|
|
310 |
This enum describes the properties of a font provided by a font engine.
|
|
311 |
|
|
312 |
\value Ascent The ascent of the font, specified as a 26.6 fixed point value.
|
|
313 |
\value Descent The descent of the font, specified as a 26.6 fixed point value.
|
|
314 |
\value Leading The leading of the font, specified as a 26.6 fixed point value.
|
|
315 |
\value XHeight The 'x' height of the font, specified as a 26.6 fixed point value.
|
|
316 |
\value AverageCharWidth The average character width of the font, specified as a 26.6 fixed point value.
|
|
317 |
\value LineThickness The thickness of the underline and strikeout lines for the font, specified as a 26.6 fixed point value.
|
|
318 |
\value UnderlinePosition The distance from the base line to the underline position for the font, specified as a 26.6 fixed point value.
|
|
319 |
\value MaxCharWidth The width of the widest character in the font, specified as a 26.6 fixed point value.
|
|
320 |
\value MinLeftBearing The minimum left bearing of the font, specified as a 26.6 fixed point value.
|
|
321 |
\value MinRightBearing The maximum right bearing of the font, specified as a 26.6 fixed point value.
|
|
322 |
\value GlyphCount The number of glyphs in the font, specified as an integer value.
|
|
323 |
\value CacheGlyphsHint A boolean value specifying whether rendered glyphs should be cached by Qt.
|
|
324 |
\value OutlineGlyphsHint A boolean value specifying whether the font engine prefers outline drawing over image rendering for uncached glyphs.
|
|
325 |
*/
|
|
326 |
|
|
327 |
/*!
|
|
328 |
\enum QAbstractFontEngine::TextShapingFlag
|
|
329 |
|
|
330 |
This enum describes flags controlling conversion of characters to glyphs and their metrics.
|
|
331 |
|
|
332 |
\value RightToLeft The text is used in a right-to-left context.
|
|
333 |
\value ReturnDesignMetrics Return font design metrics instead of pixel metrics.
|
|
334 |
*/
|
|
335 |
|
|
336 |
/*!
|
|
337 |
\typedef QAbstractFontEngine::Fixed
|
|
338 |
|
|
339 |
This type is \c int, interpreted as a 26.6 fixed point value.
|
|
340 |
*/
|
|
341 |
|
|
342 |
/*!
|
|
343 |
\class QAbstractFontEngine::GlyphMetrics
|
|
344 |
\brief QAbstractFontEngine::GlyphMetrics defines the metrics of a single glyph.
|
|
345 |
\preliminary
|
|
346 |
\since 4.3
|
|
347 |
*/
|
|
348 |
|
|
349 |
/*!
|
|
350 |
\variable QAbstractFontEngine::GlyphMetrics::x
|
|
351 |
|
|
352 |
The horizontal offset from the origin.
|
|
353 |
*/
|
|
354 |
|
|
355 |
/*!
|
|
356 |
\fn QAbstractFontEngine::GlyphMetrics::GlyphMetrics()
|
|
357 |
|
|
358 |
Constructs an empty glyph metrics object with all values
|
|
359 |
set to zero.
|
|
360 |
*/
|
|
361 |
|
|
362 |
/*!
|
|
363 |
\variable QAbstractFontEngine::GlyphMetrics::y
|
|
364 |
|
|
365 |
The vertical offset from the origin (baseline).
|
|
366 |
*/
|
|
367 |
|
|
368 |
/*!
|
|
369 |
\variable QAbstractFontEngine::GlyphMetrics::width
|
|
370 |
|
|
371 |
The width of the glyph.
|
|
372 |
*/
|
|
373 |
|
|
374 |
/*!
|
|
375 |
\variable QAbstractFontEngine::GlyphMetrics::height
|
|
376 |
|
|
377 |
The height of the glyph.
|
|
378 |
*/
|
|
379 |
|
|
380 |
/*!
|
|
381 |
\variable QAbstractFontEngine::GlyphMetrics::advance
|
|
382 |
|
|
383 |
The advance of the glyph.
|
|
384 |
*/
|
|
385 |
|
|
386 |
/*!
|
|
387 |
\class QAbstractFontEngine::FixedPoint
|
|
388 |
\brief QAbstractFontEngine::FixedPoint defines a point in the place using 26.6 fixed point precision.
|
|
389 |
\preliminary
|
|
390 |
\since 4.3
|
|
391 |
*/
|
|
392 |
|
|
393 |
/*!
|
|
394 |
\variable QAbstractFontEngine::FixedPoint::x
|
|
395 |
|
|
396 |
The x coordinate of this point.
|
|
397 |
*/
|
|
398 |
|
|
399 |
/*!
|
|
400 |
\variable QAbstractFontEngine::FixedPoint::y
|
|
401 |
|
|
402 |
The y coordinate of this point.
|
|
403 |
*/
|
|
404 |
|
|
405 |
/*!
|
|
406 |
Constructs a new QAbstractFontEngine with the given \a parent.
|
|
407 |
*/
|
|
408 |
QAbstractFontEngine::QAbstractFontEngine(QObject *parent)
|
|
409 |
: QObject(*new QAbstractFontEnginePrivate, parent)
|
|
410 |
{
|
|
411 |
}
|
|
412 |
|
|
413 |
/*!
|
|
414 |
Destroys this QAbstractFontEngine object.
|
|
415 |
*/
|
|
416 |
QAbstractFontEngine::~QAbstractFontEngine()
|
|
417 |
{
|
|
418 |
}
|
|
419 |
|
|
420 |
/*!
|
|
421 |
\fn QAbstractFontEngine::Capabilities QAbstractFontEngine::capabilities() const
|
|
422 |
|
|
423 |
Implemented in subclasses to specify the font engine's capabilities. The return value
|
|
424 |
may be cached by the caller and is expected not to change during the lifetime of the
|
|
425 |
font engine.
|
|
426 |
*/
|
|
427 |
|
|
428 |
/*!
|
|
429 |
\fn QVariant QAbstractFontEngine::fontProperty(FontProperty property) const
|
|
430 |
|
|
431 |
Implemented in subclasses to return the value of the font attribute \a property. The return
|
|
432 |
value may be cached by the caller and is expected not to change during the lifetime of the font
|
|
433 |
engine.
|
|
434 |
*/
|
|
435 |
|
|
436 |
/*!
|
|
437 |
\fn bool QAbstractFontEngine::convertStringToGlyphIndices(const QChar *string, int length, uint *glyphs, int *numGlyphs, TextShapingFlags flags) const
|
|
438 |
|
|
439 |
Implemented in subclasses to convert the characters specified by \a string and \a length to
|
|
440 |
glyph indicies, using \a flags. The glyph indicies should be returned in the \a glyphs array
|
|
441 |
provided by the caller. The maximum size of \a glyphs is specified by the value pointed to by \a
|
|
442 |
numGlyphs. If successful, the subclass implementation sets the value pointed to by \a numGlyphs
|
|
443 |
to the actual number of glyph indices generated, and returns true. Otherwise, e.g. if there is
|
|
444 |
not enough space in the provided \a glyphs array, it should set \a numGlyphs to the number of
|
|
445 |
glyphs needed for the conversion and return false.
|
|
446 |
*/
|
|
447 |
|
|
448 |
/*!
|
|
449 |
\fn void QAbstractFontEngine::getGlyphAdvances(const uint *glyphs, int numGlyphs, Fixed *advances, TextShapingFlags flags) const
|
|
450 |
|
|
451 |
Implemented in subclasses to retrieve the advances of the array specified by \a glyphs and \a
|
|
452 |
numGlyphs, using \a flags. The result is returned in \a advances, which is allocated by the
|
|
453 |
caller and contains \a numGlyphs elements.
|
|
454 |
*/
|
|
455 |
|
|
456 |
/*!
|
|
457 |
\fn QAbstractFontEngine::GlyphMetrics QAbstractFontEngine::glyphMetrics(uint glyph) const
|
|
458 |
|
|
459 |
Implemented in subclass to return the metrics for \a glyph.
|
|
460 |
*/
|
|
461 |
|
|
462 |
/*!
|
|
463 |
Implemented in subclasses to render the specified \a glyph into a \a buffer with the given \a depth ,
|
|
464 |
\a bytesPerLine and \a height.
|
|
465 |
|
|
466 |
Returns true if rendering succeeded, false otherwise.
|
|
467 |
*/
|
|
468 |
bool QAbstractFontEngine::renderGlyph(uint glyph, int depth, int bytesPerLine, int height, uchar *buffer)
|
|
469 |
{
|
|
470 |
Q_UNUSED(glyph)
|
|
471 |
Q_UNUSED(depth)
|
|
472 |
Q_UNUSED(bytesPerLine)
|
|
473 |
Q_UNUSED(height)
|
|
474 |
Q_UNUSED(buffer)
|
|
475 |
qWarning("QAbstractFontEngine: renderGlyph is not implemented in font plugin!");
|
|
476 |
return false;
|
|
477 |
}
|
|
478 |
|
|
479 |
/*!
|
|
480 |
Implemented in subclasses to add the outline of the glyphs specified by \a glyphs and \a
|
|
481 |
numGlyphs at the specified \a positions to the painter path \a path.
|
|
482 |
*/
|
|
483 |
void QAbstractFontEngine::addGlyphOutlinesToPath(uint *glyphs, int numGlyphs, FixedPoint *positions, QPainterPath *path)
|
|
484 |
{
|
|
485 |
Q_UNUSED(glyphs)
|
|
486 |
Q_UNUSED(numGlyphs)
|
|
487 |
Q_UNUSED(positions)
|
|
488 |
Q_UNUSED(path)
|
|
489 |
qWarning("QAbstractFontEngine: addGlyphOutlinesToPath is not implemented in font plugin!");
|
|
490 |
}
|
|
491 |
|
|
492 |
/*
|
|
493 |
bool QAbstractFontEngine::supportsExtension(Extension extension) const
|
|
494 |
{
|
|
495 |
Q_UNUSED(extension)
|
|
496 |
return false;
|
|
497 |
}
|
|
498 |
|
|
499 |
QVariant QAbstractFontEngine::extension(Extension extension, const QVariant &argument)
|
|
500 |
{
|
|
501 |
Q_UNUSED(argument)
|
|
502 |
Q_UNUSED(extension)
|
|
503 |
return QVariant();
|
|
504 |
}
|
|
505 |
*/
|
|
506 |
|
|
507 |
QProxyFontEngine::QProxyFontEngine(QAbstractFontEngine *customEngine, const QFontDef &def)
|
|
508 |
: engine(customEngine)
|
|
509 |
{
|
|
510 |
fontDef = def;
|
|
511 |
engineCapabilities = engine->capabilities();
|
|
512 |
}
|
|
513 |
|
|
514 |
QProxyFontEngine::~QProxyFontEngine()
|
|
515 |
{
|
|
516 |
delete engine;
|
|
517 |
}
|
|
518 |
|
|
519 |
bool QProxyFontEngine::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
|
|
520 |
{
|
|
521 |
if (*nglyphs < len) {
|
|
522 |
*nglyphs = len;
|
|
523 |
return false;
|
|
524 |
}
|
|
525 |
|
|
526 |
QVarLengthArray<uint> glyphIndicies(*nglyphs);
|
|
527 |
if (!engine->convertStringToGlyphIndices(str, len, glyphIndicies.data(), nglyphs, QAbstractFontEngine::TextShapingFlags(int(flags))))
|
|
528 |
return false;
|
|
529 |
|
|
530 |
// ### use memcopy instead
|
|
531 |
for (int i = 0; i < *nglyphs; ++i) {
|
|
532 |
glyphs->glyphs[i] = glyphIndicies[i];
|
|
533 |
}
|
|
534 |
glyphs->numGlyphs = *nglyphs;
|
|
535 |
|
|
536 |
recalcAdvances(glyphs, flags);
|
|
537 |
return true;
|
|
538 |
}
|
|
539 |
|
|
540 |
void QProxyFontEngine::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
|
|
541 |
{
|
|
542 |
const int nglyphs = glyphs->numGlyphs;
|
|
543 |
|
|
544 |
QVarLengthArray<QAbstractFontEngine::Fixed> advances(nglyphs);
|
|
545 |
engine->getGlyphAdvances(glyphs->glyphs, nglyphs, advances.data(), QAbstractFontEngine::TextShapingFlags(int(flags)));
|
|
546 |
|
|
547 |
|
|
548 |
// ### use memcopy instead
|
|
549 |
for (int i = 0; i < nglyphs; ++i) {
|
|
550 |
glyphs->advances_x[i] = QFixed::fromFixed(advances[i]);
|
|
551 |
glyphs->advances_y[i] = 0;
|
|
552 |
}
|
|
553 |
}
|
|
554 |
|
|
555 |
|
|
556 |
static QImage alphaMapFromPath(QFontEngine *fe, glyph_t glyph)
|
|
557 |
{
|
|
558 |
glyph_metrics_t gm = fe->boundingBox(glyph);
|
|
559 |
int glyph_x = qFloor(gm.x.toReal());
|
|
560 |
int glyph_y = qFloor(gm.y.toReal());
|
|
561 |
int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x;
|
|
562 |
int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y;
|
|
563 |
|
|
564 |
if (glyph_width <= 0 || glyph_height <= 0)
|
|
565 |
return QImage();
|
|
566 |
QFixedPoint pt;
|
|
567 |
pt.x = 0;
|
|
568 |
pt.y = -glyph_y; // the baseline
|
|
569 |
QPainterPath path;
|
|
570 |
QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied);
|
|
571 |
im.fill(Qt::transparent);
|
|
572 |
QPainter p(&im);
|
|
573 |
p.setRenderHint(QPainter::Antialiasing);
|
|
574 |
fe->addGlyphsToPath(&glyph, &pt, 1, &path, 0);
|
|
575 |
p.setPen(Qt::NoPen);
|
|
576 |
p.setBrush(Qt::black);
|
|
577 |
p.drawPath(path);
|
|
578 |
p.end();
|
|
579 |
|
|
580 |
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
|
|
581 |
QVector<QRgb> colors(256);
|
|
582 |
for (int i=0; i<256; ++i)
|
|
583 |
colors[i] = qRgba(0, 0, 0, i);
|
|
584 |
indexed.setColorTable(colors);
|
|
585 |
|
|
586 |
for (int y=0; y<im.height(); ++y) {
|
|
587 |
uchar *dst = (uchar *) indexed.scanLine(y);
|
|
588 |
uint *src = (uint *) im.scanLine(y);
|
|
589 |
for (int x=0; x<im.width(); ++x)
|
|
590 |
dst[x] = qAlpha(src[x]);
|
|
591 |
}
|
|
592 |
|
|
593 |
return indexed;
|
|
594 |
}
|
|
595 |
|
|
596 |
|
|
597 |
QImage QProxyFontEngine::alphaMapForGlyph(glyph_t glyph)
|
|
598 |
{
|
|
599 |
if (!(engineCapabilities & QAbstractFontEngine::CanRenderGlyphs_Gray))
|
|
600 |
return alphaMapFromPath(this, glyph);
|
|
601 |
|
|
602 |
QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyph);
|
|
603 |
if (metrics.width <= 0 || metrics.height <= 0)
|
|
604 |
return QImage();
|
|
605 |
|
|
606 |
QImage img(metrics.width >> 6, metrics.height >> 6, QImage::Format_Indexed8);
|
|
607 |
|
|
608 |
// ### we should have QImage::Format_GrayScale8
|
|
609 |
static QVector<QRgb> colorMap;
|
|
610 |
if (colorMap.isEmpty()) {
|
|
611 |
colorMap.resize(256);
|
|
612 |
for (int i=0; i<256; ++i)
|
|
613 |
colorMap[i] = qRgba(0, 0, 0, i);
|
|
614 |
}
|
|
615 |
|
|
616 |
img.setColorTable(colorMap);
|
|
617 |
|
|
618 |
engine->renderGlyph(glyph, /*depth*/8, img.bytesPerLine(), img.height(), img.bits());
|
|
619 |
|
|
620 |
return img;
|
|
621 |
}
|
|
622 |
|
|
623 |
void QProxyFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
|
|
624 |
{
|
|
625 |
if (engineCapabilities & QAbstractFontEngine::CanOutlineGlyphs)
|
|
626 |
engine->addGlyphOutlinesToPath(glyphs, nglyphs, reinterpret_cast<QAbstractFontEngine::FixedPoint *>(positions), path);
|
|
627 |
else
|
|
628 |
QFontEngine::addGlyphsToPath(glyphs, positions, nglyphs, path, flags);
|
|
629 |
}
|
|
630 |
|
|
631 |
glyph_metrics_t QProxyFontEngine::boundingBox(const QGlyphLayout &glyphs)
|
|
632 |
{
|
|
633 |
if (glyphs.numGlyphs == 0)
|
|
634 |
return glyph_metrics_t();
|
|
635 |
|
|
636 |
QFixed w = 0;
|
|
637 |
for (int i = 0; i < glyphs.numGlyphs; ++i)
|
|
638 |
w += glyphs.effectiveAdvance(i);
|
|
639 |
|
|
640 |
return glyph_metrics_t(0, -ascent(), w, ascent() + descent(), w, 0);
|
|
641 |
}
|
|
642 |
|
|
643 |
glyph_metrics_t QProxyFontEngine::boundingBox(glyph_t glyph)
|
|
644 |
{
|
|
645 |
glyph_metrics_t m;
|
|
646 |
|
|
647 |
QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyph);
|
|
648 |
m.x = QFixed::fromFixed(metrics.x);
|
|
649 |
m.y = QFixed::fromFixed(metrics.y);
|
|
650 |
m.width = QFixed::fromFixed(metrics.width);
|
|
651 |
m.height = QFixed::fromFixed(metrics.height);
|
|
652 |
m.xoff = QFixed::fromFixed(metrics.advance);
|
|
653 |
|
|
654 |
return m;
|
|
655 |
}
|
|
656 |
|
|
657 |
QFixed QProxyFontEngine::ascent() const
|
|
658 |
{
|
|
659 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Ascent).toInt());
|
|
660 |
}
|
|
661 |
|
|
662 |
QFixed QProxyFontEngine::descent() const
|
|
663 |
{
|
|
664 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Descent).toInt());
|
|
665 |
}
|
|
666 |
|
|
667 |
QFixed QProxyFontEngine::leading() const
|
|
668 |
{
|
|
669 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Leading).toInt());
|
|
670 |
}
|
|
671 |
|
|
672 |
QFixed QProxyFontEngine::xHeight() const
|
|
673 |
{
|
|
674 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::XHeight).toInt());
|
|
675 |
}
|
|
676 |
|
|
677 |
QFixed QProxyFontEngine::averageCharWidth() const
|
|
678 |
{
|
|
679 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::AverageCharWidth).toInt());
|
|
680 |
}
|
|
681 |
|
|
682 |
QFixed QProxyFontEngine::lineThickness() const
|
|
683 |
{
|
|
684 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::LineThickness).toInt());
|
|
685 |
}
|
|
686 |
|
|
687 |
QFixed QProxyFontEngine::underlinePosition() const
|
|
688 |
{
|
|
689 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::UnderlinePosition).toInt());
|
|
690 |
}
|
|
691 |
|
|
692 |
qreal QProxyFontEngine::maxCharWidth() const
|
|
693 |
{
|
|
694 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MaxCharWidth).toInt()).toReal();
|
|
695 |
}
|
|
696 |
|
|
697 |
qreal QProxyFontEngine::minLeftBearing() const
|
|
698 |
{
|
|
699 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MinLeftBearing).toInt()).toReal();
|
|
700 |
}
|
|
701 |
|
|
702 |
qreal QProxyFontEngine::minRightBearing() const
|
|
703 |
{
|
|
704 |
return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MinRightBearing).toInt()).toReal();
|
|
705 |
}
|
|
706 |
|
|
707 |
int QProxyFontEngine::glyphCount() const
|
|
708 |
{
|
|
709 |
return engine->fontProperty(QAbstractFontEngine::GlyphCount).toInt();
|
|
710 |
}
|
|
711 |
|
|
712 |
bool QProxyFontEngine::canRender(const QChar *string, int len)
|
|
713 |
{
|
|
714 |
QVarLengthArray<uint> glyphs(len);
|
|
715 |
int numGlyphs = len;
|
|
716 |
|
|
717 |
if (!engine->convertStringToGlyphIndices(string, len, glyphs.data(), &numGlyphs, /*flags*/0))
|
|
718 |
return false;
|
|
719 |
|
|
720 |
for (int i = 0; i < numGlyphs; ++i)
|
|
721 |
if (!glyphs[i])
|
|
722 |
return false;
|
|
723 |
|
|
724 |
return true;
|
|
725 |
}
|
|
726 |
|
|
727 |
void QProxyFontEngine::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemInt &si)
|
|
728 |
{
|
|
729 |
QPaintEngineState *pState = p->state;
|
|
730 |
QRasterPaintEngine *paintEngine = static_cast<QRasterPaintEngine*>(p);
|
|
731 |
|
|
732 |
QTransform matrix = pState->transform();
|
|
733 |
matrix.translate(_x, _y);
|
|
734 |
QFixed x = QFixed::fromReal(matrix.dx());
|
|
735 |
QFixed y = QFixed::fromReal(matrix.dy());
|
|
736 |
|
|
737 |
QVarLengthArray<QFixedPoint> positions;
|
|
738 |
QVarLengthArray<glyph_t> glyphs;
|
|
739 |
getGlyphPositions(si.glyphs, matrix, si.flags, glyphs, positions);
|
|
740 |
if (glyphs.size() == 0)
|
|
741 |
return;
|
|
742 |
|
|
743 |
for(int i = 0; i < glyphs.size(); i++) {
|
|
744 |
QImage glyph = alphaMapForGlyph(glyphs[i]);
|
|
745 |
if (glyph.isNull())
|
|
746 |
continue;
|
|
747 |
|
|
748 |
if (glyph.format() != QImage::Format_Indexed8
|
|
749 |
&& glyph.format() != QImage::Format_Mono)
|
|
750 |
continue;
|
|
751 |
|
|
752 |
QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyphs[i]);
|
|
753 |
|
|
754 |
int depth = glyph.format() == QImage::Format_Mono ? 1 : 8;
|
|
755 |
paintEngine->alphaPenBlt(glyph.bits(), glyph.bytesPerLine(), depth,
|
|
756 |
qRound(positions[i].x + QFixed::fromFixed(metrics.x)),
|
|
757 |
qRound(positions[i].y + QFixed::fromFixed(metrics.y)),
|
|
758 |
glyph.width(), glyph.height());
|
|
759 |
}
|
|
760 |
}
|
|
761 |
|
|
762 |
/*
|
|
763 |
* This is only called when we use the proxy fontengine directly (without sharing the rendered
|
|
764 |
* glyphs). So we prefer outline rendering over rendering of unshared glyphs. That decision is
|
|
765 |
* done in qfontdatabase_qws.cpp by looking at the ShareGlyphsHint and the pixel size of the font.
|
|
766 |
*/
|
|
767 |
bool QProxyFontEngine::drawAsOutline() const
|
|
768 |
{
|
|
769 |
if (!(engineCapabilities & QAbstractFontEngine::CanOutlineGlyphs))
|
|
770 |
return false;
|
|
771 |
|
|
772 |
QVariant outlineHint = engine->fontProperty(QAbstractFontEngine::OutlineGlyphsHint);
|
|
773 |
return !outlineHint.isValid() || outlineHint.toBool();
|
|
774 |
}
|
|
775 |
|
|
776 |
QT_END_NAMESPACE
|