summaryrefslogtreecommitdiffstats
path: root/src/distancefieldgenerator
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-06-27 16:33:48 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-06-27 16:33:48 +0200
commit9603be3007cd24b1e7944be46d32e6a9ab6f8b1e (patch)
tree1414088244874ef5dadc5bedc863160037efb141 /src/distancefieldgenerator
parent18f9ac9e9489e48ea756bd89f6f40dd4499c42a3 (diff)
parente42dd0a13ebf37f7402a4cf09a6fb62b8c740c76 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts: .qmake.conf Change-Id: I3a828f7cf61510f0bb179b760c8a335629d3c852
Diffstat (limited to 'src/distancefieldgenerator')
-rw-r--r--src/distancefieldgenerator/distancefieldmodelworker.cpp4
-rw-r--r--src/distancefieldgenerator/mainwindow.cpp25
2 files changed, 17 insertions, 12 deletions
diff --git a/src/distancefieldgenerator/distancefieldmodelworker.cpp b/src/distancefieldgenerator/distancefieldmodelworker.cpp
index 373cb05ab..b76f3b707 100644
--- a/src/distancefieldgenerator/distancefieldmodelworker.cpp
+++ b/src/distancefieldgenerator/distancefieldmodelworker.cpp
@@ -129,7 +129,7 @@ static void readCmapSubtable(DistanceFieldModelWorker *worker, const QByteArray
return;
}
- const void *end = cmap.constData() + tableOffset + subtable->length;
+ const void *end = cmap.constData() + tableOffset + length;
worker->readCmapSubtable(subtable, end);
}
@@ -148,7 +148,7 @@ void DistanceFieldModelWorker::readCmapSubtable(const CmapSubtable4 *subtable, c
const qint16 *idDeltas = reinterpret_cast<const qint16 *>(startCodes + segCount);
const quint16 *idRangeOffsets = reinterpret_cast<const quint16 *>(idDeltas + segCount);
const quint16 *glyphIdArray = idRangeOffsets + segCount;
- if (glyphIdArray >= end) {
+ if (glyphIdArray > end) {
emit error(tr("End of cmap table reached when parsing subtable format '4'"));
return;
}
diff --git a/src/distancefieldgenerator/mainwindow.cpp b/src/distancefieldgenerator/mainwindow.cpp
index 763aeaa6b..3717330b4 100644
--- a/src/distancefieldgenerator/mainwindow.cpp
+++ b/src/distancefieldgenerator/mainwindow.cpp
@@ -417,10 +417,20 @@ QByteArray MainWindow::createSfntTable()
header.minorVersion = 12;
header.pixelSize = qToBigEndian(quint16(qRound(m_model->pixelSize())));
+ const quint8 padding = 2;
+ qreal scaleFactor = qreal(1) / QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution());
+ const int radius = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution())
+ / QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution());
+
quint32 textureSize = ui->sbMaximumTextureSize->value();
+
+ // Since we are using a single area allocator that spans all textures, we need
+ // to split the textures one row before the actual maximum size, otherwise
+ // glyphs that fall on the edge between two textures will expand the texture
+ // they are assigned to, and this will end up being larger than the max.
+ textureSize -= quint32(qCeil(m_model->pixelSize() * scaleFactor) + radius * 2 + padding * 2);
header.textureSize = qToBigEndian(textureSize);
- const quint8 padding = 2;
header.padding = padding;
header.flags = m_model->doubleGlyphResolution() ? 1 : 0;
header.numGlyphs = qToBigEndian(quint32(list.size()));
@@ -428,7 +438,6 @@ QByteArray MainWindow::createSfntTable()
sizeof(QtdfHeader));
// Maximum height allocator to find optimal number of textures
- QRect allocatedArea;
QVector<QRect> allocatedAreaPerTexture;
struct GlyphData {
@@ -443,13 +452,9 @@ QByteArray MainWindow::createSfntTable()
int textureCount = 0;
{
- qreal scaleFactor = qreal(1) / QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution());
QTransform scaleDown;
scaleDown.scale(scaleFactor, scaleFactor);
- const int radius = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution())
- / QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution());
-
{
bool foundOptimalSize = false;
while (!foundOptimalSize) {
@@ -466,6 +471,7 @@ QByteArray MainWindow::createSfntTable()
glyphData.boundingRect = scaleDown.mapRect(path.boundingRect());
int glyphWidth = qCeil(glyphData.boundingRect.width()) + radius * 2;
int glyphHeight = qCeil(glyphData.boundingRect.height()) + radius * 2;
+
glyphData.glyphSize = QSize(glyphWidth + padding * 2, glyphHeight + padding * 2);
if (glyphData.glyphSize.width() > qint32(textureSize)
@@ -482,15 +488,14 @@ QByteArray MainWindow::createSfntTable()
break;
glyphData.textureIndex = rect.y() / textureSize;
- if (glyphData.textureIndex >= allocatedAreaPerTexture.size())
- allocatedAreaPerTexture.resize(glyphData.textureIndex + 1);
+ while (glyphData.textureIndex >= allocatedAreaPerTexture.size())
+ allocatedAreaPerTexture.append(QRect(0, 0, 1, 1));
+
allocatedAreaPerTexture[glyphData.textureIndex] |= QRect(rect.x(),
rect.y() % textureSize,
rect.width(),
rect.height());
- allocatedArea |= rect;
-
glyphData.texCoord.xMargin = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution()) / qreal(QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution()));
glyphData.texCoord.yMargin = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution()) / qreal(QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution()));
glyphData.texCoord.x = rect.x() + padding;