Make harfbuzz-old fallback available at run-time
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Mon, 19 Jan 2015 11:05:10 +0000 (12:05 +0100)
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>
Mon, 19 Jan 2015 12:50:32 +0000 (13:50 +0100)
The old harfbuzz code path is included as a fail safe for any
possible use case where the Harfbuzz-NG regresses, but because the
variable was checked statically, it was not actually possible to
build a releasable executable which employed the work-around.

Instead we use the regular global static pattern where the variable
is queried the first time it's needed.

Task-number: QTBUG-43850
Change-Id: I9ade76bf0825bbfefebdbdc4e6ee5571f1a3deec
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/gui/text/qfontengine.cpp
src/gui/text/qtextengine.cpp

index b2a7a8e91ff16bb72f1f78b4e8c33c61bfcb8ef9..b360ed5c85eb3b57b78657dea9088dddb0512e5d 100644 (file)
@@ -77,7 +77,12 @@ static inline bool qtransform_equals_no_translate(const QTransform &a, const QTr
 // Harfbuzz helper functions
 
 #ifdef QT_ENABLE_HARFBUZZ_NG
-bool useHarfbuzzNG = qgetenv("QT_HARFBUZZ") != "old";
+Q_GLOBAL_STATIC_WITH_ARGS(bool, useHarfbuzzNG,(qgetenv("QT_HARFBUZZ") != "old"))
+
+bool qt_useHarfbuzzNG()
+{
+    return *useHarfbuzzNG();
+}
 #endif
 
 Q_STATIC_ASSERT(sizeof(HB_Glyph) == sizeof(glyph_t));
@@ -282,7 +287,7 @@ void *QFontEngine::harfbuzzFont() const
 {
     Q_ASSERT(type() != QFontEngine::Multi);
 #ifdef QT_ENABLE_HARFBUZZ_NG
-    if (useHarfbuzzNG)
+    if (qt_useHarfbuzzNG())
         return hb_qt_font_get_for_engine(const_cast<QFontEngine *>(this));
 #endif
     if (!font_) {
@@ -318,7 +323,7 @@ void *QFontEngine::harfbuzzFace() const
 {
     Q_ASSERT(type() != QFontEngine::Multi);
 #ifdef QT_ENABLE_HARFBUZZ_NG
-    if (useHarfbuzzNG)
+    if (qt_useHarfbuzzNG())
         return hb_qt_face_get_for_engine(const_cast<QFontEngine *>(this));
 #endif
     if (!face_) {
@@ -360,7 +365,7 @@ bool QFontEngine::supportsScript(QChar::Script script) const
 #endif
 
 #ifdef QT_ENABLE_HARFBUZZ_NG
-    if (useHarfbuzzNG) {
+    if (qt_useHarfbuzzNG()) {
         bool ret = false;
         if (hb_face_t *face = hb_qt_face_get_for_engine(const_cast<QFontEngine *>(this))) {
             hb_tag_t script_tag_1, script_tag_2;
index d156124b984d95e2d2367f6200451a6fae143892..13bfa2386d61fa0253b479a9620df0523bd74a65 100644 (file)
@@ -938,7 +938,7 @@ void QTextEngine::shapeLine(const QScriptLine &line)
 }
 
 #ifdef QT_ENABLE_HARFBUZZ_NG
-extern bool useHarfbuzzNG; // defined in qfontengine.cpp
+extern bool qt_useHarfbuzzNG(); // defined in qfontengine.cpp
 #endif
 
 void QTextEngine::shapeText(int item) const
@@ -1051,7 +1051,7 @@ void QTextEngine::shapeText(int item) const
     }
 
 #ifdef QT_ENABLE_HARFBUZZ_NG
-    if (useHarfbuzzNG)
+    if (qt_useHarfbuzzNG())
         si.num_glyphs = shapeTextWithHarfbuzzNG(si, string, itemLength, fontEngine, itemBoundaries, kerningEnabled);
     else
 #endif
@@ -1067,7 +1067,7 @@ void QTextEngine::shapeText(int item) const
     QGlyphLayout glyphs = shapedGlyphs(&si);
 
 #ifdef QT_ENABLE_HARFBUZZ_NG
-    if (useHarfbuzzNG)
+    if (qt_useHarfbuzzNG())
         qt_getJustificationOpportunities(string, itemLength, si, glyphs, logClusters(&si));
 #endif
 
@@ -1607,7 +1607,7 @@ void QTextEngine::itemize() const
     }
 #ifdef QT_ENABLE_HARFBUZZ_NG
     analysis = scriptAnalysis.data();
-    if (useHarfbuzzNG) {
+    if (qt_useHarfbuzzNG()) {
         // ### pretend HB-old behavior for now
         for (int i = 0; i < length; ++i) {
             switch (analysis[i].script) {