diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index fe230188c66..33d3589a3ed 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -839,19 +839,24 @@ QDistanceFieldData *QDistanceFieldData::create(const QSize &size) return data; } +QDistanceFieldData *QDistanceFieldData::create(QSize size, const QPainterPath &path, bool doubleResolution) +{ + QDistanceFieldData *data = create(size); + makeDistanceField(data, + path, + QT_DISTANCEFIELD_SCALE(doubleResolution), + QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution)); + return data; +} + + QDistanceFieldData *QDistanceFieldData::create(const QPainterPath &path, bool doubleResolution) { int dfMargin = QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution); int glyphWidth = qCeil(path.boundingRect().width() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2; int glyphHeight = qCeil(path.boundingRect().height() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2; - QDistanceFieldData *data = create(QSize(glyphWidth, glyphHeight)); - - makeDistanceField(data, - path, - QT_DISTANCEFIELD_SCALE(doubleResolution), - QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution)); - return data; + return create(QSize(glyphWidth, glyphHeight), path, doubleResolution); } @@ -875,6 +880,16 @@ QDistanceField::QDistanceField(QFontEngine *fontEngine, glyph_t glyph, bool doub setGlyph(fontEngine, glyph, doubleResolution); } +QDistanceField::QDistanceField(QSize size, const QPainterPath &path, glyph_t glyph, bool doubleResolution) +{ + QPainterPath dfPath = path; + dfPath.translate(-dfPath.boundingRect().topLeft()); + dfPath.setFillRule(Qt::WindingFill); + + d = QDistanceFieldData::create(size, dfPath, doubleResolution); + d->glyph = glyph; +} + QDistanceField::QDistanceField(const QPainterPath &path, glyph_t glyph, bool doubleResolution) { QPainterPath dfPath = path; diff --git a/src/gui/text/qdistancefield_p.h b/src/gui/text/qdistancefield_p.h index dbc7a0abb5c..ec00e5b0f8e 100644 --- a/src/gui/text/qdistancefield_p.h +++ b/src/gui/text/qdistancefield_p.h @@ -42,6 +42,7 @@ public: static QDistanceFieldData *create(const QSize &size); static QDistanceFieldData *create(const QPainterPath &path, bool doubleResolution); + static QDistanceFieldData *create(QSize size, const QPainterPath &path, bool doubleResolution); glyph_t glyph; int width; @@ -58,6 +59,7 @@ public: QDistanceField(const QRawFont &font, glyph_t glyph, bool doubleResolution = false); QDistanceField(QFontEngine *fontEngine, glyph_t glyph, bool doubleResolution = false); QDistanceField(const QPainterPath &path, glyph_t glyph, bool doubleResolution = false); + QDistanceField(QSize size, const QPainterPath &path, glyph_t glyph, bool doubleResolution = false); bool isNull() const;