static const QTextEngine::ShaperFlags shaperflags = 0;
int nglyphs = text.size();
- QGlyphLayoutArray glyphs(nglyphs);
+ QVarLengthGlyphLayoutArray glyphs(nglyphs);
engine->stringToCMap(text.unicode(), nglyphs, &glyphs, &nglyphs, shaperflags);
engine->addOutlineToPath(point.x(), point.y(), glyphs, this);
QFixed QFontEngine::xHeight() const
{
- QGlyphLayoutArray glyphs(2);
+ QGlyphLayoutArray<2> glyphs;
int nglyphs = 1;
QChar x((ushort)'x');
stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
QFixed QFontEngine::averageCharWidth() const
{
- QGlyphLayoutArray glyphs(2);
+ QGlyphLayoutArray<2> glyphs;
int nglyphs = 1;
QChar x((ushort)'x');
stringToCMap(&x, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
void QFontEngineBox::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nGlyphs,
QPainterPath *path)
{
- QGlyphLayoutArray g(nGlyphs);
+ QVarLengthGlyphLayoutArray g(nGlyphs);
for (int i = 0; i < nGlyphs; ++i) {
g.glyphs[i] = glyphs[i];
if (rbearing == SHRT_MIN) {
lbearing = rbearing = 0;
const QChar *ch = reinterpret_cast<const QChar *>(char_table);
- QGlyphLayoutArray glyphs(char_table_entries);
+ QGlyphLayoutArray<char_table_entries> glyphs;
int ng = char_table_entries;
stringToCMap(ch, char_table_entries, &glyphs, &ng, QTextEngine::GlyphIndicesOnly);
while (--ng) {
QFontEngine *engine = d->engineForScript(script);
Q_ASSERT(engine != 0);
- QGlyphLayoutArray glyphs(2);
+ QGlyphLayoutArray<2> glyphs;
int nglyphs = 1;
engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
return qRound(glyphs.advances_x[0]);
QFontEngine *engine = d->engineForScript(script);
Q_ASSERT(engine != 0);
- QGlyphLayoutArray glyphs(2);
+ QGlyphLayoutArray<2> glyphs;
int nglyphs = 1;
engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
return glyphs.advances_x[0].toReal();
reverseMap.resize(0x10000);
for (uint i = 0; i < 0x10000; ++i)
reverseMap[i] = 0;
- QGlyphLayoutArray glyphs(2);
+ QGlyphLayoutArray<2> glyphs;
for (uint uc = 0; uc < 0x10000; ++uc) {
QChar ch(uc);
int nglyphs = 1;
static void qHB_GetGlyphAdvances(QFontEngine* fe, const HB_Glyph *glyphs, uint32_t numGlyphs, HB_Fixed *advances, int flags)
{
- QGlyphLayoutArray qglyphs(numGlyphs);
+ QVarLengthGlyphLayoutArray qglyphs(numGlyphs);
for (uint32_t i = 0; i < numGlyphs; ++i)
qglyphs.glyphs[i] = glyphs[i];
bool kerningEnabled = this->font(si).d->kerning;
HB_ShaperItem shaper_item;
- ::memset(&shaper_item, 0, sizeof(shaper_item));
+ memset(&shaper_item, 0, sizeof(shaper_item));
shaper_item.string = reinterpret_cast<const HB_UChar16 *>(layoutData->string.constData());
shaper_item.stringLength = layoutData->string.length();
shaper_item.item.pos = si.position;
const int space_preGlyphLayout = space_charAttributes + space_logClusters;
if (allocated < space_preGlyphLayout)
- ::memset(memory + allocated, 0, (space_preGlyphLayout - allocated) * QT_POINTER_SIZE);
+ memset(memory + allocated, 0, (space_preGlyphLayout - allocated) * QT_POINTER_SIZE);
glyphLayout.grow(reinterpret_cast<char *>(m), totalGlyphs);
if (numGlyphs) {
// move the existing data
- ::memmove(newLayout.attributes, oldLayout.attributes, numGlyphs * sizeof(HB_GlyphAttributes));
- ::memmove(newLayout.justifications, oldLayout.justifications, numGlyphs * sizeof(QGlyphJustification));
- ::memmove(newLayout.advances_x, oldLayout.advances_x, numGlyphs * sizeof(QFixed));
- ::memmove(newLayout.glyphs, oldLayout.glyphs, numGlyphs * sizeof(HB_Glyph));
+ memmove(newLayout.attributes, oldLayout.attributes, numGlyphs * sizeof(HB_GlyphAttributes));
+ memmove(newLayout.justifications, oldLayout.justifications, numGlyphs * sizeof(QGlyphJustification));
+ memmove(newLayout.advances_x, oldLayout.advances_x, numGlyphs * sizeof(QFixed));
+ memmove(newLayout.glyphs, oldLayout.glyphs, numGlyphs * sizeof(HB_Glyph));
}
// clear the new data
QFontEngine *fe = fnt.d->engineForScript(QUnicodeTables::Common);
- QGlyphLayoutArray ellipsisGlyph(2);
+ QGlyphLayoutArray<2> ellipsisGlyph;
{
if (fe->canRender(&ellipsisChar, 1)) {
int nGlyphs = 1;
} else {
QString dotDotDot(QLatin1String("..."));
- QGlyphLayoutArray glyphs(3);
+ QGlyphLayoutArray<3> glyphs;
int nGlyphs = 3;
if (!fe->stringToCMap(dotDotDot.constData(), 3, &glyphs, &nGlyphs, 0))
// should never happen...
struct QGlyphLayout
{
+ // init to 0 not needed, done when shaping
HB_Glyph *glyphs; // 4 bytes per element
QFixed *advances_x; // 4 bytes per element
QGlyphJustification *justifications; // 4 bytes per element
int numGlyphs;
- inline QGlyphLayout() : glyphs(nullptr), advances_x(nullptr), justifications(nullptr), attributes(nullptr), numGlyphs(0) {}
+ inline QGlyphLayout() : numGlyphs(0) {}
inline explicit QGlyphLayout(char *address, int totalGlyphs)
{
- init(address, totalGlyphs);
+ int offset = totalGlyphs * sizeof(HB_Glyph);
+ glyphs = reinterpret_cast<HB_Glyph *>(address);
+ advances_x = reinterpret_cast<QFixed *>(address + offset);
+ offset += totalGlyphs * sizeof(QFixed);
+ justifications = reinterpret_cast<QGlyphJustification *>(address + offset);
+ offset += totalGlyphs * sizeof(QGlyphJustification);
+ attributes = reinterpret_cast<HB_GlyphAttributes *>(address + offset);
+ numGlyphs = totalGlyphs;
}
inline QGlyphLayout mid(int position, int n = -1) const {
if (last == -1)
last = numGlyphs;
if (first == 0 && last == numGlyphs) {
- ::memset(glyphs, 0, QSPACEFORGLYPHS(numGlyphs));
+ memset(glyphs, 0, QSPACEFORGLYPHS(numGlyphs));
} else {
const int num = last - first;
- ::memset(glyphs + first, 0, num * sizeof(HB_Glyph));
- ::memset(advances_x + first, 0, num * sizeof(QFixed));
- ::memset(justifications + first, 0, num * sizeof(QGlyphJustification));
- ::memset(attributes + first, 0, num * sizeof(HB_GlyphAttributes));
+ memset(glyphs + first, 0, num * sizeof(HB_Glyph));
+ memset(advances_x + first, 0, num * sizeof(QFixed));
+ memset(justifications + first, 0, num * sizeof(QGlyphJustification));
+ memset(attributes + first, 0, num * sizeof(HB_GlyphAttributes));
}
}
}
void grow(char *address, int totalGlyphs);
-protected:
- inline void init(char *address, int totalGlyphs)
- {
- int offset = totalGlyphs * sizeof(HB_Glyph);
- glyphs = reinterpret_cast<HB_Glyph *>(address);
- advances_x = reinterpret_cast<QFixed *>(address + offset);
- offset += totalGlyphs * sizeof(QFixed);
- justifications = reinterpret_cast<QGlyphJustification *>(address + offset);
- offset += totalGlyphs * sizeof(QGlyphJustification);
- attributes = reinterpret_cast<HB_GlyphAttributes *>(address + offset);
- numGlyphs = totalGlyphs;
- }
};
-
-struct QGlyphLayoutArray : public QGlyphLayout
+class QVarLengthGlyphLayoutArray : private QVarLengthArray<void *>, public QGlyphLayout
{
+private:
+ typedef QVarLengthArray<void *> Array;
public:
- QGlyphLayoutArray(const int size)
- : QGlyphLayout(),
- buffer(nullptr)
+ QVarLengthGlyphLayoutArray(int totalGlyphs)
+ : Array(QSPACEFORGLYPHS(totalGlyphs) / QT_POINTER_SIZE + 1)
+ , QGlyphLayout(reinterpret_cast<char *>(Array::data()), totalGlyphs)
{
- Q_ASSERT(size);
- buffer = ::malloc(QSPACEFORGLYPHS(size));
- Q_CHECK_PTR(buffer);
- ::memset(buffer, 0, sizeof(buffer));
- init(reinterpret_cast<char *>(buffer), size);
+ memset(Array::data(), 0, Array::size() * QT_POINTER_SIZE);
}
+};
- ~QGlyphLayoutArray()
+template <int N> struct QGlyphLayoutArray : public QGlyphLayout
+{
+public:
+ QGlyphLayoutArray()
+ : QGlyphLayout(reinterpret_cast<char *>(buffer), N)
{
- ::free(buffer);
+ memset(buffer, 0, sizeof(buffer));
}
private:
- Q_DISABLE_COPY(QGlyphLayoutArray);
- void *buffer;
+ void *buffer[QSPACEFORGLYPHS(N) / QT_POINTER_SIZE + 1];
};
struct QScriptItem;