1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <private/qfontengine_p.h>
47 #include "qpainterpath.h"
48 #include "qvarlengtharray.h"
51 #include <private/qharfbuzz_p.h>
55 static inline bool qtransform_equals_no_translate(const QTransform &a, const QTransform &b)
57 if (a.type() <= QTransform::TxTranslate && b.type() <= QTransform::TxTranslate) {
60 // We always use paths for perspective text anyway, so no
61 // point in checking the full matrix...
62 Q_ASSERT(a.type() < QTransform::TxProject);
63 Q_ASSERT(b.type() < QTransform::TxProject);
65 return a.m11() == b.m11()
68 && a.m22() == b.m22();
72 // Harfbuzz helper functions
74 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 QFontEngine *fe = (QFontEngine *)font->userData;
78 QVarLengthGlyphLayoutArray qglyphs(*numGlyphs);
80 QTextEngine::ShaperFlags shaperFlags(QTextEngine::GlyphIndicesOnly);
82 shaperFlags |= QTextEngine::RightToLeft;
84 int nGlyphs = *numGlyphs;
85 bool result = fe->stringToCMap(reinterpret_cast<const QChar *>(string), length, &qglyphs, &nGlyphs, shaperFlags);
90 for (hb_uint32 i = 0; i < *numGlyphs; ++i)
91 glyphs[i] = qglyphs.glyphs[i];
96 static void hb_getAdvances(HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags)
98 QFontEngine *fe = (QFontEngine *)font->userData;
100 QVarLengthGlyphLayoutArray qglyphs(numGlyphs);
102 for (hb_uint32 i = 0; i < numGlyphs; ++i)
103 qglyphs.glyphs[i] = glyphs[i];
105 fe->recalcAdvances(&qglyphs, flags & HB_ShaperFlag_UseDesignMetrics ? QFlags<QTextEngine::ShaperFlag>(QTextEngine::DesignMetrics) : QFlags<QTextEngine::ShaperFlag>(0));
107 for (hb_uint32 i = 0; i < numGlyphs; ++i)
108 advances[i] = qglyphs.advances_x[i].value();
111 static HB_Bool hb_canRender(HB_Font font, const HB_UChar16 *string, hb_uint32 length)
113 QFontEngine *fe = (QFontEngine *)font->userData;
114 return fe->canRender(reinterpret_cast<const QChar *>(string), length);
117 static void hb_getGlyphMetrics(HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics)
119 QFontEngine *fe = (QFontEngine *)font->userData;
120 glyph_metrics_t m = fe->boundingBox(glyph);
121 metrics->x = m.x.value();
122 metrics->y = m.y.value();
123 metrics->width = m.width.value();
124 metrics->height = m.height.value();
125 metrics->xOffset = m.xoff.value();
126 metrics->yOffset = m.yoff.value();
129 static HB_Fixed hb_getFontMetric(HB_Font font, HB_FontMetric metric)
131 if (metric == HB_FontAscent) {
132 QFontEngine *fe = (QFontEngine *)font->userData;
133 return fe->ascent().value();
138 HB_Error QFontEngine::getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
146 return HB_Err_Not_Covered;
149 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 QFontEngine *fe = (QFontEngine *)font->userData;
152 return fe->getPointInOutline(glyph, flags, point, xpos, ypos, nPoints);
155 static const HB_FontClass hb_fontClass = {
156 hb_stringToGlyphs, hb_getAdvances, hb_canRender, hb_getPointInOutline,
157 hb_getGlyphMetrics, hb_getFontMetric
160 static HB_Error hb_getSFntTable(void *font, HB_Tag tableTag, HB_Byte *buffer, HB_UInt *length)
162 QFontEngine *fe = (QFontEngine *)font;
163 if (!fe->getSfntTableData(tableTag, buffer, length))
164 return HB_Err_Invalid_Argument;
170 QFontEngine::QFontEngine()
177 memset(&hbFont, 0, sizeof(hbFont));
178 hbFont.klass = &hb_fontClass;
179 hbFont.userData = this;
185 QFontEngine::~QFontEngine()
187 m_glyphCaches.clear();
191 QFixed QFontEngine::lineThickness() const
194 int score = fontDef.weight * fontDef.pixelSize;
195 int lw = score / 700;
197 // looks better with thicker line for small pointsizes
198 if (lw < 2 && score >= 1050) lw = 2;
204 QFixed QFontEngine::underlinePosition() const
206 return ((lineThickness() * 2) + 3) / 6;
209 HB_Font QFontEngine::harfbuzzFont() const
211 if (!hbFont.x_ppem) {
212 QFixed emSquare = emSquareSize();
213 hbFont.x_ppem = fontDef.pixelSize;
214 hbFont.y_ppem = fontDef.pixelSize * fontDef.stretch / 100;
215 hbFont.x_scale = (QFixed(hbFont.x_ppem * (1 << 16)) / emSquare).value();
216 hbFont.y_scale = (QFixed(hbFont.y_ppem * (1 << 16)) / emSquare).value();
221 HB_Face QFontEngine::harfbuzzFace() const
224 hbFace = qHBNewFace(const_cast<QFontEngine *>(this), hb_getSFntTable);
230 glyph_metrics_t QFontEngine::boundingBox(glyph_t glyph, const QTransform &matrix)
232 glyph_metrics_t metrics = boundingBox(glyph);
234 if (matrix.type() > QTransform::TxTranslate) {
235 return metrics.transformed(matrix);
240 QFixed QFontEngine::xHeight() const
242 QGlyphLayoutArray<8> glyphs;
244 QChar x((ushort)'x');
245 stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
247 glyph_metrics_t bb = const_cast<QFontEngine *>(this)->boundingBox(glyphs.glyphs[0]);
251 QFixed QFontEngine::averageCharWidth() const
253 QGlyphLayoutArray<8> glyphs;
255 QChar x((ushort)'x');
256 stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
258 glyph_metrics_t bb = const_cast<QFontEngine *>(this)->boundingBox(glyphs.glyphs[0]);
263 void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags,
264 QVarLengthArray<glyph_t> &glyphs_out, QVarLengthArray<QFixedPoint> &positions)
269 const bool transform = matrix.m11() != 1.
270 || matrix.m12() != 0.
271 || matrix.m21() != 0.
272 || matrix.m22() != 1.;
274 xpos = QFixed::fromReal(matrix.dx());
275 ypos = QFixed::fromReal(matrix.dy());
279 if (flags & QTextItem::RightToLeft) {
280 int i = glyphs.numGlyphs;
281 int totalKashidas = 0;
283 xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
284 ypos += glyphs.advances_y[i];
285 totalKashidas += glyphs.justifications[i].nKashidas;
287 positions.resize(glyphs.numGlyphs+totalKashidas);
288 glyphs_out.resize(glyphs.numGlyphs+totalKashidas);
291 while(i < glyphs.numGlyphs) {
292 if (glyphs.attributes[i].dontPrint) {
296 xpos -= glyphs.advances_x[i];
297 ypos -= glyphs.advances_y[i];
299 QFixed gpos_x = xpos + glyphs.offsets[i].x;
300 QFixed gpos_y = ypos + glyphs.offsets[i].y;
302 QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
303 gpos = gpos * matrix;
304 gpos_x = QFixed::fromReal(gpos.x());
305 gpos_y = QFixed::fromReal(gpos.y());
307 positions[current].x = gpos_x;
308 positions[current].y = gpos_y;
309 glyphs_out[current] = glyphs.glyphs[i];
311 if (glyphs.justifications[i].nKashidas) {
312 QChar ch(0x640); // Kashida character
313 QGlyphLayoutArray<8> g;
315 stringToCMap(&ch, 1, &g, &nglyphs, 0);
316 for (uint k = 0; k < glyphs.justifications[i].nKashidas; ++k) {
317 xpos -= g.advances_x[0];
318 ypos -= g.advances_y[0];
320 QFixed gpos_x = xpos + glyphs.offsets[i].x;
321 QFixed gpos_y = ypos + glyphs.offsets[i].y;
323 QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
324 gpos = gpos * matrix;
325 gpos_x = QFixed::fromReal(gpos.x());
326 gpos_y = QFixed::fromReal(gpos.y());
328 positions[current].x = gpos_x;
329 positions[current].y = gpos_y;
330 glyphs_out[current] = g.glyphs[0];
334 xpos -= QFixed::fromFixed(glyphs.justifications[i].space_18d6);
339 positions.resize(glyphs.numGlyphs);
340 glyphs_out.resize(glyphs.numGlyphs);
343 while (i < glyphs.numGlyphs) {
344 if (!glyphs.attributes[i].dontPrint) {
345 positions[current].x = xpos + glyphs.offsets[i].x;
346 positions[current].y = ypos + glyphs.offsets[i].y;
347 glyphs_out[current] = glyphs.glyphs[i];
348 xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
349 ypos += glyphs.advances_y[i];
355 while (i < glyphs.numGlyphs) {
356 if (!glyphs.attributes[i].dontPrint) {
357 QFixed gpos_x = xpos + glyphs.offsets[i].x;
358 QFixed gpos_y = ypos + glyphs.offsets[i].y;
359 QPointF gpos(gpos_x.toReal(), gpos_y.toReal());
360 gpos = gpos * matrix;
361 positions[current].x = QFixed::fromReal(gpos.x());
362 positions[current].y = QFixed::fromReal(gpos.y());
363 glyphs_out[current] = glyphs.glyphs[i];
364 xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
365 ypos += glyphs.advances_y[i];
372 positions.resize(current);
373 glyphs_out.resize(current);
374 Q_ASSERT(positions.size() == glyphs_out.size());
377 void QFontEngine::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing)
379 glyph_metrics_t gi = boundingBox(glyph);
380 bool isValid = gi.isValid();
381 if (leftBearing != 0)
382 *leftBearing = isValid ? gi.x.toReal() : 0.0;
383 if (rightBearing != 0)
384 *rightBearing = isValid ? (gi.xoff - gi.x - gi.width).toReal() : 0.0;
387 glyph_metrics_t QFontEngine::tightBoundingBox(const QGlyphLayout &glyphs)
389 glyph_metrics_t overall;
393 for (int i = 0; i < glyphs.numGlyphs; i++) {
394 glyph_metrics_t bb = boundingBox(glyphs.glyphs[i]);
395 QFixed x = overall.xoff + glyphs.offsets[i].x + bb.x;
396 QFixed y = overall.yoff + glyphs.offsets[i].y + bb.y;
397 overall.x = qMin(overall.x, x);
398 overall.y = qMin(overall.y, y);
399 xmax = qMax(xmax, x + bb.width);
400 ymax = qMax(ymax, y + bb.height);
401 overall.xoff += bb.xoff;
402 overall.yoff += bb.yoff;
404 overall.height = qMax(overall.height, ymax - overall.y);
405 overall.width = xmax - overall.x;
411 void QFontEngine::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path,
412 QTextItem::RenderFlags flags)
414 if (!glyphs.numGlyphs)
417 QVarLengthArray<QFixedPoint> positions;
418 QVarLengthArray<glyph_t> positioned_glyphs;
419 QTransform matrix = QTransform::fromTranslate(x, y);
420 getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
421 addGlyphsToPath(positioned_glyphs.data(), positions.data(), positioned_glyphs.size(), path, flags);
424 #define GRID(x, y) grid[(y)*(w+1) + (x)]
425 #define SET(x, y) (*(image_data + (y)*bpl + ((x) >> 3)) & (0x80 >> ((x) & 7)))
427 enum { EdgeRight = 0x1,
433 static void collectSingleContour(qreal x0, qreal y0, uint *grid, int x, int y, int w, int h, QPainterPath *path)
437 path->moveTo(x + x0, y + y0);
439 if (GRID(x, y) & EdgeRight) {
440 while (GRID(x, y) & EdgeRight) {
441 GRID(x, y) &= ~EdgeRight;
445 path->lineTo(x + x0, y + y0);
448 if (GRID(x, y) & EdgeDown) {
449 while (GRID(x, y) & EdgeDown) {
450 GRID(x, y) &= ~EdgeDown;
454 path->lineTo(x + x0, y + y0);
457 if (GRID(x, y) & EdgeLeft) {
458 while (GRID(x, y) & EdgeLeft) {
459 GRID(x, y) &= ~EdgeLeft;
463 path->lineTo(x + x0, y + y0);
466 if (GRID(x, y) & EdgeUp) {
467 while (GRID(x, y) & EdgeUp) {
468 GRID(x, y) &= ~EdgeUp;
472 path->lineTo(x + x0, y + y0);
476 path->closeSubpath();
479 Q_GUI_EXPORT void qt_addBitmapToPath(qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
481 uint *grid = new uint[(w+1)*(h+1)];
483 for (int y = 0; y <= h; ++y) {
484 for (int x = 0; x <= w; ++x) {
485 bool topLeft = (x == 0)|(y == 0) ? false : SET(x - 1, y - 1);
486 bool topRight = (x == w)|(y == 0) ? false : SET(x, y - 1);
487 bool bottomLeft = (x == 0)|(y == h) ? false : SET(x - 1, y);
488 bool bottomRight = (x == w)|(y == h) ? false : SET(x, y);
491 if ((!topRight) & bottomRight)
492 GRID(x, y) |= EdgeRight;
493 if ((!bottomRight) & bottomLeft)
494 GRID(x, y) |= EdgeDown;
495 if ((!bottomLeft) & topLeft)
496 GRID(x, y) |= EdgeLeft;
497 if ((!topLeft) & topRight)
498 GRID(x, y) |= EdgeUp;
503 for (int y = 0; y < h; ++y) {
504 for (int x = 0; x < w; ++x) {
507 // found start of a contour, follow it
508 collectSingleContour(x0, y0, grid, x, y, w, h, path);
518 void QFontEngine::addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
519 QPainterPath *path, QTextItem::RenderFlags flags)
521 // TODO what to do with 'flags' ??
523 QFixed advanceX = QFixed::fromReal(x);
524 QFixed advanceY = QFixed::fromReal(y);
525 for (int i=0; i < glyphs.numGlyphs; ++i) {
526 glyph_metrics_t metrics = boundingBox(glyphs.glyphs[i]);
527 if (metrics.width.value() == 0 || metrics.height.value() == 0) {
528 advanceX += glyphs.advances_x[i];
529 advanceY += glyphs.advances_y[i];
532 const QImage alphaMask = alphaMapForGlyph(glyphs.glyphs[i]);
534 const int w = alphaMask.width();
535 const int h = alphaMask.height();
536 const int srcBpl = alphaMask.bytesPerLine();
538 if (alphaMask.depth() == 1) {
541 bitmap = QImage(w, h, QImage::Format_Mono);
542 const uchar *imageData = alphaMask.bits();
543 const int destBpl = bitmap.bytesPerLine();
544 uchar *bitmapData = bitmap.bits();
546 for (int yi = 0; yi < h; ++yi) {
547 const uchar *src = imageData + yi*srcBpl;
548 uchar *dst = bitmapData + yi*destBpl;
549 for (int xi = 0; xi < w; ++xi) {
550 const int byte = xi / 8;
551 const int bit = xi % 8;
555 dst[byte] |= 128 >> bit;
559 const uchar *bitmap_data = bitmap.bits();
560 QFixedPoint offset = glyphs.offsets[i];
561 advanceX += offset.x;
562 advanceY += offset.y;
563 qt_addBitmapToPath((advanceX + metrics.x).toReal(), (advanceY + metrics.y).toReal(), bitmap_data, bitmap.bytesPerLine(), w, h, path);
564 advanceX += glyphs.advances_x[i];
565 advanceY += glyphs.advances_y[i];
569 void QFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nGlyphs,
570 QPainterPath *path, QTextItem::RenderFlags flags)
572 qreal x = positions[0].x.toReal();
573 qreal y = positions[0].y.toReal();
574 QVarLengthGlyphLayoutArray g(nGlyphs);
576 for (int i = 0; i < nGlyphs; ++i) {
577 g.glyphs[i] = glyphs[i];
578 if (i < nGlyphs - 1) {
579 g.advances_x[i] = positions[i+1].x - positions[i].x;
580 g.advances_y[i] = positions[i+1].y - positions[i].y;
582 g.advances_x[i] = QFixed::fromReal(maxCharWidth());
587 addBitmapFontToPath(x, y, g, path, flags);
590 QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition*/)
592 // For font engines don't support subpixel positioning
593 return alphaMapForGlyph(glyph);
596 QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &t)
598 QImage i = alphaMapForGlyph(glyph);
599 if (t.type() > QTransform::TxTranslate)
600 i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
601 Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
606 QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t)
608 if (! supportsSubPixelPositions())
609 return alphaMapForGlyph(glyph, t);
611 QImage i = alphaMapForGlyph(glyph, subPixelPosition);
612 if (t.type() > QTransform::TxTranslate)
613 i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
614 Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
619 QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition*/, int /* margin */, const QTransform &t)
621 QImage alphaMask = alphaMapForGlyph(glyph, t);
622 QImage rgbMask(alphaMask.width(), alphaMask.height(), QImage::Format_RGB32);
624 QVector<QRgb> colorTable = alphaMask.colorTable();
625 for (int y=0; y<alphaMask.height(); ++y) {
626 uint *dst = (uint *) rgbMask.scanLine(y);
627 uchar *src = (uchar *) alphaMask.scanLine(y);
628 for (int x=0; x<alphaMask.width(); ++x) {
629 int val = qAlpha(colorTable.at(src[x]));
630 dst[x] = qRgb(val, val, val);
637 QImage QFontEngine::alphaMapForGlyph(glyph_t glyph)
639 glyph_metrics_t gm = boundingBox(glyph);
640 int glyph_x = qFloor(gm.x.toReal());
641 int glyph_y = qFloor(gm.y.toReal());
642 int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x;
643 int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y;
645 if (glyph_width <= 0 || glyph_height <= 0)
649 pt.y = -glyph_y; // the baseline
651 QImage im(glyph_width + 4, glyph_height, QImage::Format_ARGB32_Premultiplied);
652 im.fill(Qt::transparent);
654 p.setRenderHint(QPainter::Antialiasing);
655 addGlyphsToPath(&glyph, &pt, 1, &path, 0);
657 p.setBrush(Qt::black);
661 QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
662 QVector<QRgb> colors(256);
663 for (int i=0; i<256; ++i)
664 colors[i] = qRgba(0, 0, 0, i);
665 indexed.setColorTable(colors);
667 for (int y=0; y<im.height(); ++y) {
668 uchar *dst = (uchar *) indexed.scanLine(y);
669 uint *src = (uint *) im.scanLine(y);
670 for (int x=0; x<im.width(); ++x)
671 dst[x] = qAlpha(src[x]);
677 void QFontEngine::removeGlyphFromCache(glyph_t)
681 QFontEngine::Properties QFontEngine::properties() const
684 QByteArray psname = QFontEngine::convertToPostscriptFontFamilyName(fontDef.family.toUtf8());
686 psname += QByteArray::number(fontDef.style);
688 psname += QByteArray::number(fontDef.weight);
690 p.postscriptName = psname;
692 p.descent = descent();
693 p.leading = leading();
694 p.emSquare = p.ascent;
695 p.boundingBox = QRectF(0, -p.ascent.toReal(), maxCharWidth(), (p.ascent + p.descent).toReal());
697 p.capHeight = p.ascent;
698 p.lineWidth = lineThickness();
702 void QFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
704 *metrics = boundingBox(glyph);
708 addGlyphsToPath(&glyph, &p, 1, path, QFlag(0));
711 QByteArray QFontEngine::getSfntTable(uint tag) const
715 if (!getSfntTableData(tag, 0, &len))
720 if (!getSfntTableData(tag, reinterpret_cast<uchar *>(table.data()), &len))
725 void QFontEngine::setGlyphCache(void *key, QFontEngineGlyphCache *data)
729 GlyphCacheEntry entry;
732 if (m_glyphCaches.contains(entry))
735 // Limit the glyph caches to 4. This covers all 90 degree rotations and limits
736 // memory use when there is continuous or random rotation
737 if (m_glyphCaches.size() == 4)
738 m_glyphCaches.removeLast();
740 m_glyphCaches.push_front(entry);
744 QFontEngineGlyphCache *QFontEngine::glyphCache(void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const
746 for (QLinkedList<GlyphCacheEntry>::const_iterator it = m_glyphCaches.constBegin(), end = m_glyphCaches.constEnd(); it != end; ++it) {
747 QFontEngineGlyphCache *c = it->cache.data();
748 if (key == it->context
749 && type == c->cacheType()
750 && qtransform_equals_no_translate(c->m_transform, transform)) {
757 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN)
758 static inline QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
760 uint left_right = (left << 16) + right;
762 left = 0, right = numPairs - 1;
763 while (left <= right) {
764 int middle = left + ( ( right - left ) >> 1 );
766 if(pairs[middle].left_right == left_right)
767 return pairs[middle].adjust;
769 if (pairs[middle].left_right < left_right)
777 void QFontEngine::doKerning(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
779 int numPairs = kerning_pairs.size();
783 const KernPair *pairs = kerning_pairs.constData();
785 if(flags & QTextEngine::DesignMetrics) {
786 for(int i = 0; i < glyphs->numGlyphs - 1; ++i)
787 glyphs->advances_x[i] += kerning(glyphs->glyphs[i], glyphs->glyphs[i+1] , pairs, numPairs);
789 for(int i = 0; i < glyphs->numGlyphs - 1; ++i)
790 glyphs->advances_x[i] += qRound(kerning(glyphs->glyphs[i], glyphs->glyphs[i+1] , pairs, numPairs));
794 void QFontEngine::loadKerningPairs(QFixed scalingFactor)
796 kerning_pairs.clear();
798 QByteArray tab = getSfntTable(MAKE_TAG('k', 'e', 'r', 'n'));
802 const uchar *table = reinterpret_cast<const uchar *>(tab.constData());
804 unsigned short version = qFromBigEndian<quint16>(table);
806 // qDebug("wrong version");
810 unsigned short numTables = qFromBigEndian<quint16>(table + 2);
813 for(int i = 0; i < numTables; ++i) {
814 if (offset + 6 > tab.size()) {
815 // qDebug("offset out of bounds");
818 const uchar *header = table + offset;
820 ushort version = qFromBigEndian<quint16>(header);
821 ushort length = qFromBigEndian<quint16>(header+2);
822 ushort coverage = qFromBigEndian<quint16>(header+4);
823 // qDebug("subtable: version=%d, coverage=%x",version, coverage);
824 if(version == 0 && coverage == 0x0001) {
825 if (offset + length > tab.size()) {
826 // qDebug("length ouf ot bounds");
829 const uchar *data = table + offset + 6;
831 ushort nPairs = qFromBigEndian<quint16>(data);
832 if(nPairs * 6 + 8 > length - 6) {
833 // qDebug("corrupt table!");
839 for(int i = 0; i < nPairs; ++i) {
840 QFontEngine::KernPair p;
841 p.left_right = (((uint)qFromBigEndian<quint16>(data+off)) << 16) + qFromBigEndian<quint16>(data+off+2);
842 p.adjust = QFixed(((int)(short)qFromBigEndian<quint16>(data+off+4))) / scalingFactor;
843 kerning_pairs.append(p);
851 qSort(kerning_pairs);
852 // for (int i = 0; i < kerning_pairs.count(); ++i)
853 // qDebug() << 'i' << i << "left_right" << hex << kerning_pairs.at(i).left_right;
857 void QFontEngine::doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const
862 int QFontEngine::glyphCount() const
864 QByteArray maxpTable = getSfntTable(MAKE_TAG('m', 'a', 'x', 'p'));
865 if (maxpTable.size() < 6)
867 return qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(maxpTable.constData() + 4));
870 const uchar *QFontEngine::getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
872 const uchar *header = table;
876 const uchar *endPtr = table + tableSize;
879 if (qFromBigEndian<quint16>(header) != 0)
882 unsigned short numTables = qFromBigEndian<quint16>(header + 2);
883 const uchar *maps = table + 4;
884 if (maps + 8 * numTables > endPtr)
894 MicrosoftUnicodeExtended
897 int symbolTable = -1;
900 for (int n = 0; n < numTables; ++n) {
901 const quint16 platformId = qFromBigEndian<quint16>(maps + 8 * n);
902 const quint16 platformSpecificId = qFromBigEndian<quint16>(maps + 8 * n + 2);
903 switch (platformId) {
905 if (score < Unicode &&
906 (platformSpecificId == 0 ||
907 platformSpecificId == 2 ||
908 platformSpecificId == 3)) {
911 } else if (score < Unicode11 && platformSpecificId == 1) {
917 if (score < AppleRoman && platformSpecificId == 0) { // Apple Roman
923 switch (platformSpecificId) {
926 if (score < Symbol) {
932 if (score < MicrosoftUnicode) {
934 score = MicrosoftUnicode;
938 if (score < MicrosoftUnicodeExtended) {
940 score = MicrosoftUnicodeExtended;
954 *isSymbolFont = (symbolTable > -1);
956 unsigned int unicode_table = qFromBigEndian<quint32>(maps + 8*tableToUse + 4);
958 if (!unicode_table || unicode_table + 8 > tableSize)
961 // get the header of the unicode table
962 header = table + unicode_table;
964 unsigned short format = qFromBigEndian<quint16>(header);
967 length = qFromBigEndian<quint16>(header + 2);
969 length = qFromBigEndian<quint32>(header + 4);
971 if (table + unicode_table + length > endPtr)
975 // To support symbol fonts that contain a unicode table for the symbol area
976 // we check the cmap tables and fall back to symbol font unless that would
977 // involve losing information from the unicode table
978 if (symbolTable > -1 && ((score == Unicode) || (score == Unicode11))) {
979 const uchar *selectedTable = table + unicode_table;
981 // Check that none of the latin1 range are in the unicode table
982 bool unicodeTableHasLatin1 = false;
983 for (int uc=0x00; uc<0x100; ++uc) {
984 if (getTrueTypeGlyphIndex(selectedTable, uc) != 0) {
985 unicodeTableHasLatin1 = true;
990 // Check that at least one symbol char is in the unicode table
991 bool unicodeTableHasSymbols = false;
992 if (!unicodeTableHasLatin1) {
993 for (int uc=0xf000; uc<0xf100; ++uc) {
994 if (getTrueTypeGlyphIndex(selectedTable, uc) != 0) {
995 unicodeTableHasSymbols = true;
1001 // Fall back to symbol table
1002 if (!unicodeTableHasLatin1 && unicodeTableHasSymbols) {
1003 tableToUse = symbolTable;
1009 return table + unicode_table;
1012 quint32 QFontEngine::getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
1014 unsigned short format = qFromBigEndian<quint16>(cmap);
1017 return (int) *(cmap+6+unicode);
1018 } else if (format == 4) {
1019 /* some fonts come with invalid cmap tables, where the last segment
1020 specified end = start = rangeoffset = 0xffff, delta = 0x0001
1021 Since 0xffff is never a valid Unicode char anyway, we just get rid of the issue
1022 by returning 0 for 0xffff
1024 if(unicode >= 0xffff)
1026 quint16 segCountX2 = qFromBigEndian<quint16>(cmap + 6);
1027 const unsigned char *ends = cmap + 14;
1029 for (; i < segCountX2/2 && qFromBigEndian<quint16>(ends + 2*i) < unicode; i++) {}
1031 const unsigned char *idx = ends + segCountX2 + 2 + 2*i;
1032 quint16 startIndex = qFromBigEndian<quint16>(idx);
1034 if (startIndex > unicode)
1038 qint16 idDelta = (qint16)qFromBigEndian<quint16>(idx);
1040 quint16 idRangeoffset_t = (quint16)qFromBigEndian<quint16>(idx);
1043 if (idRangeoffset_t) {
1044 quint16 id = qFromBigEndian<quint16>(idRangeoffset_t + 2*(unicode - startIndex) + idx);
1046 glyphIndex = (idDelta + id) % 0x10000;
1050 glyphIndex = (idDelta + unicode) % 0x10000;
1053 } else if (format == 6) {
1054 quint16 tableSize = qFromBigEndian<quint16>(cmap + 2);
1056 quint16 firstCode6 = qFromBigEndian<quint16>(cmap + 6);
1057 if (unicode < firstCode6)
1060 quint16 entryCount6 = qFromBigEndian<quint16>(cmap + 8);
1061 if (entryCount6 * 2 + 10 > tableSize)
1064 quint16 sentinel6 = firstCode6 + entryCount6;
1065 if (unicode >= sentinel6)
1068 quint16 entryIndex6 = unicode - firstCode6;
1069 return qFromBigEndian<quint16>(cmap + 10 + (entryIndex6 * 2));
1070 } else if (format == 12) {
1071 quint32 nGroups = qFromBigEndian<quint32>(cmap + 12);
1073 cmap += 16; // move to start of groups
1075 int left = 0, right = nGroups - 1;
1076 while (left <= right) {
1077 int middle = left + ( ( right - left ) >> 1 );
1079 quint32 startCharCode = qFromBigEndian<quint32>(cmap + 12*middle);
1080 if(unicode < startCharCode)
1083 quint32 endCharCode = qFromBigEndian<quint32>(cmap + 12*middle + 4);
1084 if(unicode <= endCharCode)
1085 return qFromBigEndian<quint32>(cmap + 12*middle + 8) + unicode - startCharCode;
1090 qDebug("cmap table of format %d not implemented", format);
1096 QByteArray QFontEngine::convertToPostscriptFontFamilyName(const QByteArray &family)
1098 QByteArray f = family;
1113 Q_GLOBAL_STATIC_WITH_INITIALIZER(QVector<QRgb>, qt_grayPalette, {
1115 QRgb *it = x->data();
1116 for (int i = 0; i < x->size(); ++i, ++it)
1117 *it = 0xff000000 | i | (i<<8) | (i<<16);
1120 const QVector<QRgb> &QFontEngine::grayPalette()
1122 return *qt_grayPalette();
1125 QFixed QFontEngine::lastRightBearing(const QGlyphLayout &glyphs, bool round)
1127 if (glyphs.numGlyphs >= 1) {
1128 glyph_t glyph = glyphs.glyphs[glyphs.numGlyphs - 1];
1129 glyph_metrics_t gi = boundingBox(glyph);
1131 return round ? QFixed(qRound(gi.xoff - gi.x - gi.width))
1132 : QFixed(gi.xoff - gi.x - gi.width);
1137 // ------------------------------------------------------------------
1138 // The box font engine
1139 // ------------------------------------------------------------------
1141 QFontEngineBox::QFontEngineBox(int size)
1144 cache_cost = sizeof(QFontEngineBox);
1147 QFontEngineBox::~QFontEngineBox()
1151 bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags) const
1153 if (*nglyphs < len) {
1158 for (int i = 0; i < len; i++) {
1159 glyphs->glyphs[i] = 0;
1160 glyphs->advances_x[i] = _size;
1161 glyphs->advances_y[i] = 0;
1165 glyphs->numGlyphs = len;
1169 void QFontEngineBox::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
1171 for (int i = 0; i < glyphs->numGlyphs; i++) {
1172 glyphs->advances_x[i] = _size;
1173 glyphs->advances_y[i] = 0;
1177 void QFontEngineBox::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
1179 if (!glyphs.numGlyphs)
1182 QVarLengthArray<QFixedPoint> positions;
1183 QVarLengthArray<glyph_t> positioned_glyphs;
1184 QTransform matrix = QTransform::fromTranslate(x, y - _size);
1185 getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
1187 QSize s(_size - 3, _size - 3);
1188 for (int k = 0; k < positions.size(); k++)
1189 path->addRect(QRectF(positions[k].toPointF(), s));
1192 glyph_metrics_t QFontEngineBox::boundingBox(const QGlyphLayout &glyphs)
1194 glyph_metrics_t overall;
1195 overall.width = _size*glyphs.numGlyphs;
1196 overall.height = _size;
1197 overall.xoff = overall.width;
1201 #if defined(Q_WS_QWS) || defined(Q_WS_QPA)
1202 void QFontEngineBox::draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &ti)
1204 if (!ti.glyphs.numGlyphs)
1207 // any fixes here should probably also be done in QPaintEnginePrivate::drawBoxTextItem
1208 QSize s(_size - 3, _size - 3);
1210 QVarLengthArray<QFixedPoint> positions;
1211 QVarLengthArray<glyph_t> glyphs;
1212 QTransform matrix = QTransform::fromTranslate(x, y - _size);
1213 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
1214 if (glyphs.size() == 0)
1218 QPainter *painter = p->painter();
1220 painter->setBrush(Qt::NoBrush);
1221 QPen pen = painter->pen();
1222 pen.setWidthF(lineThickness().toReal());
1223 painter->setPen(pen);
1224 for (int k = 0; k < positions.size(); k++)
1225 painter->drawRect(QRectF(positions[k].toPointF(), s));
1230 glyph_metrics_t QFontEngineBox::boundingBox(glyph_t)
1232 return glyph_metrics_t(0, -_size, _size, _size, _size, 0);
1237 QFixed QFontEngineBox::ascent() const
1242 QFixed QFontEngineBox::descent() const
1247 QFixed QFontEngineBox::leading() const
1249 QFixed l = _size * QFixed::fromReal(qreal(0.15));
1253 qreal QFontEngineBox::maxCharWidth() const
1259 int QFontEngineBox::cmap() const
1265 const char *QFontEngineBox::name() const
1270 bool QFontEngineBox::canRender(const QChar *, int)
1275 QFontEngine::Type QFontEngineBox::type() const
1280 QImage QFontEngineBox::alphaMapForGlyph(glyph_t)
1282 QImage image(_size, _size, QImage::Format_Indexed8);
1283 QVector<QRgb> colors(256);
1284 for (int i=0; i<256; ++i)
1285 colors[i] = qRgba(0, 0, 0, i);
1286 image.setColorTable(colors);
1289 // can't use qpainter for index8; so use setPixel to draw our rectangle.
1290 for (int i=2; i <= _size-3; ++i) {
1291 image.setPixel(i, 2, 255);
1292 image.setPixel(i, _size-3, 255);
1293 image.setPixel(2, i, 255);
1294 image.setPixel(_size-3, i, 255);
1299 // ------------------------------------------------------------------
1301 // ------------------------------------------------------------------
1303 static inline uchar highByte(glyph_t glyph)
1304 { return glyph >> 24; }
1306 // strip high byte from glyph
1307 static inline glyph_t stripped(glyph_t glyph)
1308 { return glyph & 0x00ffffff; }
1310 QFontEngineMulti::QFontEngineMulti(int engineCount)
1312 engines.fill(0, engineCount);
1316 QFontEngineMulti::~QFontEngineMulti()
1318 for (int i = 0; i < engines.size(); ++i) {
1319 QFontEngine *fontEngine = engines.at(i);
1321 fontEngine->ref.deref();
1322 if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
1328 bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
1329 QGlyphLayout *glyphs, int *nglyphs,
1330 QTextEngine::ShaperFlags flags) const
1333 if (!engine(0)->stringToCMap(str, len, glyphs, &ng, flags))
1337 for (int i = 0; i < len; ++i) {
1338 bool surrogate = (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 && i < len-1
1339 && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000);
1341 if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
1342 QGlyphLayoutInstance tmp = glyphs->instance(glyph_pos);
1343 for (int x = 1; x < engines.size(); ++x) {
1344 QFontEngine *engine = engines.at(x);
1346 const_cast<QFontEngineMulti *>(this)->loadEngine(x);
1347 engine = engines.at(x);
1349 Q_ASSERT(engine != 0);
1350 if (engine->type() == Box)
1352 glyphs->advances_x[glyph_pos] = glyphs->advances_y[glyph_pos] = 0;
1353 glyphs->offsets[glyph_pos] = QFixedPoint();
1355 QGlyphLayout offs = glyphs->mid(glyph_pos, num);
1356 engine->stringToCMap(str + i, surrogate ? 2 : 1, &offs, &num, flags);
1357 Q_ASSERT(num == 1); // surrogates only give 1 glyph
1358 if (glyphs->glyphs[glyph_pos]) {
1359 // set the high byte to indicate which engine the glyph came from
1360 glyphs->glyphs[glyph_pos] |= (x << 24);
1364 // ensure we use metrics from the 1st font when we use the fallback image.
1365 if (!glyphs->glyphs[glyph_pos]) {
1366 glyphs->setInstance(glyph_pos, tmp);
1375 glyphs->numGlyphs = ng;
1379 glyph_metrics_t QFontEngineMulti::boundingBox(const QGlyphLayout &glyphs)
1381 if (glyphs.numGlyphs <= 0)
1382 return glyph_metrics_t();
1384 glyph_metrics_t overall;
1386 int which = highByte(glyphs.glyphs[0]);
1389 for (end = 0; end < glyphs.numGlyphs; ++end) {
1390 const int e = highByte(glyphs.glyphs[end]);
1394 // set the high byte to zero
1395 for (i = start; i < end; ++i)
1396 glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
1398 // merge the bounding box for this run
1399 const glyph_metrics_t gm = engine(which)->boundingBox(glyphs.mid(start, end - start));
1401 overall.x = qMin(overall.x, gm.x);
1402 overall.y = qMin(overall.y, gm.y);
1403 overall.width = overall.xoff + gm.width;
1404 overall.height = qMax(overall.height + overall.y, gm.height + gm.y) -
1405 qMin(overall.y, gm.y);
1406 overall.xoff += gm.xoff;
1407 overall.yoff += gm.yoff;
1409 // reset the high byte for all glyphs
1410 const int hi = which << 24;
1411 for (i = start; i < end; ++i)
1412 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
1419 // set the high byte to zero
1420 for (i = start; i < end; ++i)
1421 glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
1423 // merge the bounding box for this run
1424 const glyph_metrics_t gm = engine(which)->boundingBox(glyphs.mid(start, end - start));
1426 overall.x = qMin(overall.x, gm.x);
1427 overall.y = qMin(overall.y, gm.y);
1428 overall.width = overall.xoff + gm.width;
1429 overall.height = qMax(overall.height + overall.y, gm.height + gm.y) -
1430 qMin(overall.y, gm.y);
1431 overall.xoff += gm.xoff;
1432 overall.yoff += gm.yoff;
1434 // reset the high byte for all glyphs
1435 const int hi = which << 24;
1436 for (i = start; i < end; ++i)
1437 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
1442 void QFontEngineMulti::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing)
1444 int which = highByte(glyph);
1445 engine(which)->getGlyphBearings(stripped(glyph), leftBearing, rightBearing);
1448 void QFontEngineMulti::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
1449 QPainterPath *path, QTextItem::RenderFlags flags)
1451 if (glyphs.numGlyphs <= 0)
1454 int which = highByte(glyphs.glyphs[0]);
1457 if (flags & QTextItem::RightToLeft) {
1458 for (int gl = 0; gl < glyphs.numGlyphs; gl++) {
1459 x += glyphs.advances_x[gl].toReal();
1460 y += glyphs.advances_y[gl].toReal();
1463 for (end = 0; end < glyphs.numGlyphs; ++end) {
1464 const int e = highByte(glyphs.glyphs[end]);
1468 if (flags & QTextItem::RightToLeft) {
1469 for (i = start; i < end; ++i) {
1470 x -= glyphs.advances_x[i].toReal();
1471 y -= glyphs.advances_y[i].toReal();
1475 // set the high byte to zero
1476 for (i = start; i < end; ++i)
1477 glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
1478 engine(which)->addOutlineToPath(x, y, glyphs.mid(start, end - start), path, flags);
1479 // reset the high byte for all glyphs and update x and y
1480 const int hi = which << 24;
1481 for (i = start; i < end; ++i)
1482 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
1484 if (!(flags & QTextItem::RightToLeft)) {
1485 for (i = start; i < end; ++i) {
1486 x += glyphs.advances_x[i].toReal();
1487 y += glyphs.advances_y[i].toReal();
1496 if (flags & QTextItem::RightToLeft) {
1497 for (i = start; i < end; ++i) {
1498 x -= glyphs.advances_x[i].toReal();
1499 y -= glyphs.advances_y[i].toReal();
1503 // set the high byte to zero
1504 for (i = start; i < end; ++i)
1505 glyphs.glyphs[i] = stripped(glyphs.glyphs[i]);
1507 engine(which)->addOutlineToPath(x, y, glyphs.mid(start, end - start), path, flags);
1509 // reset the high byte for all glyphs
1510 const int hi = which << 24;
1511 for (i = start; i < end; ++i)
1512 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
1515 void QFontEngineMulti::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
1517 if (glyphs->numGlyphs <= 0)
1520 int which = highByte(glyphs->glyphs[0]);
1523 for (end = 0; end < glyphs->numGlyphs; ++end) {
1524 const int e = highByte(glyphs->glyphs[end]);
1528 // set the high byte to zero
1529 for (i = start; i < end; ++i)
1530 glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
1532 QGlyphLayout offs = glyphs->mid(start, end - start);
1533 engine(which)->recalcAdvances(&offs, flags);
1535 // reset the high byte for all glyphs and update x and y
1536 const int hi = which << 24;
1537 for (i = start; i < end; ++i)
1538 glyphs->glyphs[i] = hi | glyphs->glyphs[i];
1545 // set the high byte to zero
1546 for (i = start; i < end; ++i)
1547 glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
1549 QGlyphLayout offs = glyphs->mid(start, end - start);
1550 engine(which)->recalcAdvances(&offs, flags);
1552 // reset the high byte for all glyphs
1553 const int hi = which << 24;
1554 for (i = start; i < end; ++i)
1555 glyphs->glyphs[i] = hi | glyphs->glyphs[i];
1558 void QFontEngineMulti::doKerning(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
1560 if (glyphs->numGlyphs <= 0)
1563 int which = highByte(glyphs->glyphs[0]);
1566 for (end = 0; end < glyphs->numGlyphs; ++end) {
1567 const int e = highByte(glyphs->glyphs[end]);
1571 // set the high byte to zero
1572 for (i = start; i < end; ++i)
1573 glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
1575 QGlyphLayout offs = glyphs->mid(start, end - start);
1576 engine(which)->doKerning(&offs, flags);
1578 // reset the high byte for all glyphs and update x and y
1579 const int hi = which << 24;
1580 for (i = start; i < end; ++i)
1581 glyphs->glyphs[i] = hi | glyphs->glyphs[i];
1588 // set the high byte to zero
1589 for (i = start; i < end; ++i)
1590 glyphs->glyphs[i] = stripped(glyphs->glyphs[i]);
1592 QGlyphLayout offs = glyphs->mid(start, end - start);
1593 engine(which)->doKerning(&offs, flags);
1595 // reset the high byte for all glyphs
1596 const int hi = which << 24;
1597 for (i = start; i < end; ++i)
1598 glyphs->glyphs[i] = hi | glyphs->glyphs[i];
1601 glyph_metrics_t QFontEngineMulti::boundingBox(glyph_t glyph)
1603 const int which = highByte(glyph);
1604 Q_ASSERT(which < engines.size());
1605 return engine(which)->boundingBox(stripped(glyph));
1608 QFixed QFontEngineMulti::ascent() const
1609 { return engine(0)->ascent(); }
1611 QFixed QFontEngineMulti::descent() const
1612 { return engine(0)->descent(); }
1614 QFixed QFontEngineMulti::leading() const
1616 return engine(0)->leading();
1619 QFixed QFontEngineMulti::xHeight() const
1621 return engine(0)->xHeight();
1624 QFixed QFontEngineMulti::averageCharWidth() const
1626 return engine(0)->averageCharWidth();
1629 QFixed QFontEngineMulti::lineThickness() const
1631 return engine(0)->lineThickness();
1634 QFixed QFontEngineMulti::underlinePosition() const
1636 return engine(0)->underlinePosition();
1639 qreal QFontEngineMulti::maxCharWidth() const
1641 return engine(0)->maxCharWidth();
1644 qreal QFontEngineMulti::minLeftBearing() const
1646 return engine(0)->minLeftBearing();
1649 qreal QFontEngineMulti::minRightBearing() const
1651 return engine(0)->minRightBearing();
1654 bool QFontEngineMulti::canRender(const QChar *string, int len)
1656 if (engine(0)->canRender(string, len))
1659 QVarLengthGlyphLayoutArray glyphs(len);
1661 if (stringToCMap(string, len, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly) == false) {
1662 glyphs.resize(nglyphs);
1663 stringToCMap(string, len, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
1666 bool allExist = true;
1667 for (int i = 0; i < nglyphs; i++) {
1668 if (!glyphs.glyphs[i]) {
1677 QImage QFontEngineMulti::alphaMapForGlyph(glyph_t)