QFontSubset: mark local types movable and hold in QVector, not QList

Virtually all of these types are too large to fit into a QList.

Change-Id: If55496ef3fb26d6531e9ef1bb1558887d9077a3b
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-06-19 02:10:18 +02:00
parent 452ece9c02
commit 90da7ba49c
2 changed files with 24 additions and 19 deletions

View File

@ -350,6 +350,7 @@ struct qttf_head_table {
quint16 macStyle; quint16 macStyle;
qint16 indexToLocFormat; qint16 indexToLocFormat;
}; };
Q_DECLARE_TYPEINFO(qttf_head_table, Q_PRIMITIVE_TYPE);
struct qttf_hhea_table { struct qttf_hhea_table {
@ -362,6 +363,7 @@ struct qttf_hhea_table {
qint16 xMaxExtent; qint16 xMaxExtent;
quint16 numberOfHMetrics; quint16 numberOfHMetrics;
}; };
Q_DECLARE_TYPEINFO(qttf_hhea_table, Q_PRIMITIVE_TYPE);
struct qttf_maxp_table { struct qttf_maxp_table {
@ -373,6 +375,7 @@ struct qttf_maxp_table {
quint16 maxComponentElements; quint16 maxComponentElements;
quint16 maxComponentDepth; quint16 maxComponentDepth;
}; };
Q_DECLARE_TYPEINFO(qttf_maxp_table, Q_PRIMITIVE_TYPE);
struct qttf_name_table { struct qttf_name_table {
QString copyright; QString copyright;
@ -380,6 +383,7 @@ struct qttf_name_table {
QString subfamily; QString subfamily;
QString postscript_name; QString postscript_name;
}; };
Q_DECLARE_TYPEINFO(qttf_name_table, Q_MOVABLE_TYPE);
static QTtfTable generateHead(const qttf_head_table &head); static QTtfTable generateHead(const qttf_head_table &head);
@ -411,9 +415,9 @@ Q_DECLARE_TYPEINFO(QTtfGlyph, Q_MOVABLE_TYPE);
static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem); static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem);
// generates glyf, loca and hmtx // generates glyf, loca and hmtx
static QList<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QList<QTtfGlyph> &_glyphs); static QVector<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QVector<QTtfGlyph> &_glyphs);
static QByteArray bindFont(const QList<QTtfTable>& _tables); static QByteArray bindFont(const QVector<QTtfTable>& _tables);
static quint32 checksum(const QByteArray &table) static quint32 checksum(const QByteArray &table)
@ -607,12 +611,13 @@ struct QTtfNameRecord {
quint16 nameId; quint16 nameId;
QString value; QString value;
}; };
Q_DECLARE_TYPEINFO(QTtfNameRecord, Q_MOVABLE_TYPE);
static QTtfTable generateName(const QList<QTtfNameRecord> &name); static QTtfTable generateName(const QVector<QTtfNameRecord> &name);
static QTtfTable generateName(const qttf_name_table &name) static QTtfTable generateName(const qttf_name_table &name)
{ {
QList<QTtfNameRecord> list; QVector<QTtfNameRecord> list;
QTtfNameRecord rec; QTtfNameRecord rec;
rec.nameId = 0; rec.nameId = 0;
rec.value = name.copyright; rec.value = name.copyright;
@ -636,7 +641,7 @@ static QTtfTable generateName(const qttf_name_table &name)
} }
// ####### should probably generate Macintosh/Roman name entries as well // ####### should probably generate Macintosh/Roman name entries as well
static QTtfTable generateName(const QList<QTtfNameRecord> &name) static QTtfTable generateName(const QVector<QTtfNameRecord> &name)
{ {
const int char_size = 2; const int char_size = 2;
@ -707,7 +712,7 @@ struct TTF_POINT {
}; };
Q_DECLARE_TYPEINFO(TTF_POINT, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(TTF_POINT, Q_PRIMITIVE_TYPE);
static void convertPath(const QPainterPath &path, QList<TTF_POINT> *points, QList<int> *endPoints, qreal ppem) static void convertPath(const QPainterPath &path, QVector<TTF_POINT> *points, QVector<int> *endPoints, qreal ppem)
{ {
int numElements = path.elementCount(); int numElements = path.elementCount();
for (int i = 0; i < numElements - 1; ++i) { for (int i = 0; i < numElements - 1; ++i) {
@ -829,7 +834,7 @@ static void convertPath(const QPainterPath &path, QList<TTF_POINT> *points, QLis
endPoints->append(points->size() - 1); endPoints->append(points->size() - 1);
} }
static void getBounds(const QList<TTF_POINT> &points, qint16 *xmin, qint16 *xmax, qint16 *ymin, qint16 *ymax) static void getBounds(const QVector<TTF_POINT> &points, qint16 *xmin, qint16 *xmax, qint16 *ymin, qint16 *ymax)
{ {
*xmin = points.at(0).x; *xmin = points.at(0).x;
*xmax = *xmin; *xmax = *xmin;
@ -844,7 +849,7 @@ static void getBounds(const QList<TTF_POINT> &points, qint16 *xmin, qint16 *xmax
} }
} }
static int convertToRelative(QList<TTF_POINT> *points) static int convertToRelative(QVector<TTF_POINT> *points)
{ {
// convert points to relative and setup flags // convert points to relative and setup flags
// qDebug() << "relative points:"; // qDebug() << "relative points:";
@ -897,7 +902,7 @@ static int convertToRelative(QList<TTF_POINT> *points)
return point_array_size; return point_array_size;
} }
static void getGlyphData(QTtfGlyph *glyph, const QList<TTF_POINT> &points, const QList<int> &endPoints, int point_array_size) static void getGlyphData(QTtfGlyph *glyph, const QVector<TTF_POINT> &points, const QVector<int> &endPoints, int point_array_size)
{ {
const int max_size = 5*sizeof(qint16) // header const int max_size = 5*sizeof(qint16) // header
+ endPoints.size()*sizeof(quint16) // end points of contours + endPoints.size()*sizeof(quint16) // end points of contours
@ -947,8 +952,8 @@ static void getGlyphData(QTtfGlyph *glyph, const QList<TTF_POINT> &points, const
static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem) static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)
{ {
QList<TTF_POINT> points; QVector<TTF_POINT> points;
QList<int> endPoints; QVector<int> endPoints;
QTtfGlyph glyph; QTtfGlyph glyph;
glyph.index = index; glyph.index = index;
glyph.advanceWidth = qRound(advance * 2048. / ppem); glyph.advanceWidth = qRound(advance * 2048. / ppem);
@ -983,10 +988,10 @@ static bool operator <(const QTtfGlyph &g1, const QTtfGlyph &g2)
return g1.index < g2.index; return g1.index < g2.index;
} }
static QList<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QList<QTtfGlyph> &_glyphs) static QVector<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QVector<QTtfGlyph> &_glyphs)
{ {
const int max_size_small = 65536*2; const int max_size_small = 65536*2;
QList<QTtfGlyph> glyphs = _glyphs; QVector<QTtfGlyph> glyphs = _glyphs;
std::sort(glyphs.begin(), glyphs.end()); std::sort(glyphs.begin(), glyphs.end());
Q_ASSERT(tables.maxp.numGlyphs == glyphs.at(glyphs.size()-1).index + 1); Q_ASSERT(tables.maxp.numGlyphs == glyphs.at(glyphs.size()-1).index + 1);
@ -1049,7 +1054,7 @@ static QList<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QLis
Q_ASSERT(loca.data.size() == ls.offset()); Q_ASSERT(loca.data.size() == ls.offset());
Q_ASSERT(hmtx.data.size() == hs.offset()); Q_ASSERT(hmtx.data.size() == hs.offset());
QList<QTtfTable> list; QVector<QTtfTable> list;
list.append(glyf); list.append(glyf);
list.append(loca); list.append(loca);
list.append(hmtx); list.append(hmtx);
@ -1061,9 +1066,9 @@ static bool operator <(const QTtfTable &t1, const QTtfTable &t2)
return t1.tag < t2.tag; return t1.tag < t2.tag;
} }
static QByteArray bindFont(const QList<QTtfTable>& _tables) static QByteArray bindFont(const QVector<QTtfTable>& _tables)
{ {
QList<QTtfTable> tables = _tables; QVector<QTtfTable> tables = _tables;
std::sort(tables.begin(), tables.end()); std::sort(tables.begin(), tables.end());
@ -1154,7 +1159,7 @@ QByteArray QFontSubset::toTruetype() const
qreal ppem = fontEngine->fontDef.pixelSize; qreal ppem = fontEngine->fontDef.pixelSize;
#define TO_TTF(x) qRound(x * 2048. / ppem) #define TO_TTF(x) qRound(x * 2048. / ppem)
QList<QTtfGlyph> glyphs; QVector<QTtfGlyph> glyphs;
QFontEngine::Properties properties = fontEngine->properties(); QFontEngine::Properties properties = fontEngine->properties();
// initialize some stuff needed in createWidthArray // initialize some stuff needed in createWidthArray
@ -1225,7 +1230,7 @@ QByteArray QFontSubset::toTruetype() const
} }
QList<QTtfTable> tables = generateGlyphTables(font, glyphs); QVector<QTtfTable> tables = generateGlyphTables(font, glyphs);
tables.append(generateHead(font.head)); tables.append(generateHead(font.head));
tables.append(generateHhea(font.hhea)); tables.append(generateHhea(font.hhea));
tables.append(generateMaxp(font.maxp)); tables.append(generateMaxp(font.maxp));

View File

@ -79,7 +79,7 @@ public:
const int object_id; const int object_id;
bool noEmbed; bool noEmbed;
QFontEngine *fontEngine; QFontEngine *fontEngine;
QList<int> glyph_indices; QVector<int> glyph_indices;
mutable int downloaded_glyphs; mutable int downloaded_glyphs;
mutable bool standard_font; mutable bool standard_font;
int nGlyphs() const { return glyph_indices.size(); } int nGlyphs() const { return glyph_indices.size(); }