summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontengine_s60.cpp
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@nokia.com>2010-06-04 19:51:59 +0200
committerAlessandro Portale <alessandro.portale@nokia.com>2010-06-07 16:00:51 +0200
commit5d130f9682fbd3dc8c469468e805854fd70a11ea (patch)
tree93fa8ed4711472c03616a96e659fbf253c572d51 /src/gui/text/qfontengine_s60.cpp
parent53a3b44aea9d2e331b0359b23512b778b520091a (diff)
Retrieve proper glyph outlines from Symbian^4
Up until Symbian^4, the Symbian font Api does not provide access to the vector data of glyphs. In order to make QPainterPath::addText() and transformed text rendering work, Qt falls back to a workaound: Tracing the bitmap of a rasterized glyph. That is neither performant nor is the result of good quality. Symbian^4 will add Api that returns glyph outlines encoded as SVG paths. The code in this commit essentially parses the SVG path and returns a QPainterPath. The parsing part took some ideas from QSvg, and is implemented in a very reduced way. Task-number: QT-809 Reviewed-by: Aleksandar Sasha Babic
Diffstat (limited to 'src/gui/text/qfontengine_s60.cpp')
-rw-r--r--src/gui/text/qfontengine_s60.cpp98
1 files changed, 96 insertions, 2 deletions
diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp
index 52a2c3c4ce..925b3bf5fd 100644
--- a/src/gui/text/qfontengine_s60.cpp
+++ b/src/gui/text/qfontengine_s60.cpp
@@ -50,9 +50,9 @@
#include <e32std.h>
#include <eikenv.h>
#include <gdi.h>
-#ifdef Q_SYMBIAN_HAS_FONTTABLE_API
+#if defined(Q_SYMBIAN_HAS_FONTTABLE_API) || defined(Q_SYMBIAN_HAS_GLYPHOUTLINE_API)
#include <graphics/gdi/gdiplatapi.h>
-#endif // Q_SYMBIAN_HAS_FONTTABLE_API
+#endif // Q_SYMBIAN_HAS_FONTTABLE_API || Q_SYMBIAN_HAS_GLYPHOUTLINE_API
QT_BEGIN_NAMESPACE
@@ -279,6 +279,35 @@ void QFontEngineS60::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
}
}
+#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+static bool parseGlyphPathData(const char *dataStr, const char *dataEnd, QPainterPath &path,
+ qreal fontPixelSize, const QPointF &offset, bool hinted);
+#endif //Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+
+void QFontEngineS60::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions,
+ int nglyphs, QPainterPath *path,
+ QTextItem::RenderFlags flags)
+{
+#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+ Q_UNUSED(flags)
+ RGlyphOutlineIterator iterator;
+ const TInt error = iterator.Open(*m_activeFont, glyphs, nglyphs);
+ if (KErrNone != error)
+ return;
+ const qreal fontSizeInPixels = qreal(m_activeFont->HeightInPixels());
+ int count = 0;
+ do {
+ const TUint8* outlineUint8 = iterator.Outline();
+ const char* const outlineChar = reinterpret_cast<const char*>(outlineUint8);
+ const char* const outlineEnd = outlineChar + iterator.OutlineLength();
+ parseGlyphPathData(outlineChar, outlineEnd, *path, fontSizeInPixels,
+ positions[count++].toPointF(), false);
+ } while(KErrNone == iterator.Next() && count <= nglyphs);
+#else // Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+ QFontEngine::addGlyphsToPath(glyphs, positions, nglyphs, path, flags);
+#endif //Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+}
+
QImage QFontEngineS60::alphaMapForGlyph(glyph_t glyph)
{
TOpenFontCharMetrics metrics;
@@ -410,4 +439,69 @@ void QFontEngineS60::getCharacterData(glyph_t glyph, TOpenFontCharMetrics& metri
}
}
+#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+static inline void skipSpacesAndComma(const char* &str, const char* const strEnd)
+{
+ while (str <= strEnd && (*str == ' ' || *str == ','))
+ ++str;
+}
+
+static bool parseGlyphPathData(const char *svgPath, const char *svgPathEnd, QPainterPath &path,
+ qreal fontPixelSize, const QPointF &offset, bool hinted)
+{
+ Q_UNUSED(hinted)
+ QPointF p1, p2, firstSubPathPoint;
+ qreal *elementValues[] =
+ {&p1.rx(), &p1.ry(), &p2.rx(), &p2.ry()};
+ const int unitsPerEm = 2048; // See: http://en.wikipedia.org/wiki/Em_%28typography%29
+ const qreal resizeFactor = fontPixelSize / unitsPerEm;
+
+ while (svgPath < svgPathEnd) {
+ skipSpacesAndComma(svgPath, svgPathEnd);
+ const char pathElem = *svgPath++;
+ skipSpacesAndComma(svgPath, svgPathEnd);
+
+ if (pathElem != 'Z') {
+ char *endStr = 0;
+ int elementValuesCount = 0;
+ for (int i = 0; i < 4; ++i) { // 4 = size of elementValues[]
+ qreal coordinateValue = strtod(svgPath, &endStr);
+ if (svgPath == endStr)
+ break;
+ if (i % 2) // Flip vertically
+ coordinateValue = -coordinateValue;
+ *elementValues[i] = coordinateValue * resizeFactor;
+ elementValuesCount++;
+ svgPath = endStr;
+ skipSpacesAndComma(svgPath, svgPathEnd);
+ }
+ p1 += offset;
+ if (elementValuesCount == 2)
+ p2 = firstSubPathPoint;
+ else
+ p2 += offset;
+ }
+
+ switch (pathElem) {
+ case 'M':
+ firstSubPathPoint = p1;
+ path.moveTo(p1);
+ break;
+ case 'Z':
+ path.closeSubpath();
+ break;
+ case 'L':
+ path.lineTo(p1);
+ break;
+ case 'Q':
+ path.quadTo(p1, p2);
+ break;
+ default:
+ return false;
+ }
+ }
+ return true;
+}
+#endif // Q_SYMBIAN_HAS_GLYPHOUTLINE_API
+
QT_END_NAMESPACE