Make QGlyphLayout consume one byte less per glyph

Change-Id: Iddcc2e1f284dcf13ae98b57ea2d5854e57c83530
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Konstantin Ritt 2014-02-11 02:50:30 +02:00 committed by The Qt Project
parent 25e34dadab
commit fd498ad1c0
2 changed files with 23 additions and 18 deletions

View File

@ -1206,7 +1206,6 @@ QT_BEGIN_INCLUDE_NAMESPACE
QT_END_INCLUDE_NAMESPACE
Q_STATIC_ASSERT(sizeof(HB_Glyph) == sizeof(glyph_t));
Q_STATIC_ASSERT(sizeof(HB_GlyphAttributes) == sizeof(QGlyphAttributes));
Q_STATIC_ASSERT(sizeof(HB_Fixed) == sizeof(QFixed));
Q_STATIC_ASSERT(sizeof(HB_FixedPoint) == sizeof(QFixedPoint));
@ -1272,18 +1271,23 @@ int QTextEngine::shapeTextWithHarfbuzz(const QScriptItem &si, const ushort *stri
remaining_glyphs -= shaper_item.initialGlyphCount;
QVarLengthArray<HB_GlyphAttributes, 128> hbGlyphAttributes;
do {
if (!ensureSpace(glyph_pos + shaper_item.num_glyphs + remaining_glyphs))
return 0;
if (hbGlyphAttributes.size() < int(shaper_item.num_glyphs)) {
hbGlyphAttributes.resize(shaper_item.num_glyphs);
memset(hbGlyphAttributes.data(), 0, hbGlyphAttributes.size() * sizeof(HB_GlyphAttributes));
}
const QGlyphLayout g = availableGlyphs(&si).mid(glyph_pos);
if (fontEngine->type() == QFontEngine::Multi && shaper_item.num_glyphs > shaper_item.item.length)
moveGlyphData(g.mid(shaper_item.num_glyphs), g.mid(shaper_item.initialGlyphCount), remaining_glyphs);
shaper_item.glyphs = reinterpret_cast<HB_Glyph *>(g.glyphs);
shaper_item.attributes = reinterpret_cast<HB_GlyphAttributes *>(g.attributes);
shaper_item.advances = reinterpret_cast<HB_Fixed *>(g.advances);
shaper_item.offsets = reinterpret_cast<HB_FixedPoint *>(g.offsets);
shaper_item.attributes = hbGlyphAttributes.data();
if (engineIdx != 0 && shaper_item.glyphIndicesPresent) {
for (quint32 i = 0; i < shaper_item.initialGlyphCount; ++i)
@ -1297,6 +1301,14 @@ int QTextEngine::shapeTextWithHarfbuzz(const QScriptItem &si, const ushort *stri
if (fontEngine->type() == QFontEngine::Multi)
moveGlyphData(g.mid(shaper_item.num_glyphs), g.mid(shaper_item.initialGlyphCount), remaining_glyphs);
for (quint32 i = 0; i < shaper_item.num_glyphs; ++i) {
HB_GlyphAttributes hbAttrs = hbGlyphAttributes.at(i);
QGlyphAttributes &attrs = g.attributes[i];
attrs.clusterStart = hbAttrs.clusterStart;
attrs.dontPrint = hbAttrs.dontPrint;
attrs.justification = hbAttrs.justification;
}
for (quint32 i = 0; i < shaper_item.item.length; ++i)
shaper_item.log_clusters[i] += glyph_pos;

View File

@ -89,21 +89,6 @@ class QAbstractTextDocumentLayout;
typedef quint32 glyph_t;
#ifdef __xlC__
typedef unsigned q_hb_bitfield;
#else
typedef quint8 q_hb_bitfield;
#endif
struct QGlyphAttributes {
q_hb_bitfield justification :4;
q_hb_bitfield clusterStart :1;
q_hb_bitfield unused1 :1;
q_hb_bitfield unused2 :1;
q_hb_bitfield dontPrint :1;
q_hb_bitfield unused3 :8;
};
// this uses the same coordinate system as Qt, but a different one to freetype.
// * y is usually negative, and is equal to the ascent.
// * negative yoff means the following stuff is drawn higher up.
@ -174,6 +159,14 @@ struct QGlyphJustification
};
Q_DECLARE_TYPEINFO(QGlyphJustification, Q_PRIMITIVE_TYPE);
struct QGlyphAttributes {
uchar clusterStart : 1;
uchar dontPrint : 1;
uchar justification : 4;
uchar reserved : 2;
};
Q_STATIC_ASSERT(sizeof(QGlyphAttributes) == 1);
struct QGlyphLayout
{
enum {
@ -186,7 +179,7 @@ struct QGlyphLayout
glyph_t *glyphs; // 4 bytes per element
QFixed *advances; // 4 bytes per element
QGlyphJustification *justifications; // 4 bytes per element
QGlyphAttributes *attributes; // 2 bytes per element
QGlyphAttributes *attributes; // 1 byte per element
int numGlyphs;