Bug 1279069 - Replace &nbsp; with <space> for Graphite shaping purposes if &nbsp; is not supported by the font. r=jrmuizel
authorJonathan Kew <jkew@mozilla.com>
Thu, 09 Jun 2016 23:53:22 +0100
changeset 343520 c92d81f5d0fc57d6e0d49e34bc907e74ec8525a3
parent 343519 a422e5afb098f711f8f0ebdd139b7f78dcb94c0f
child 343521 4ed63fbe3d85b9743daee5a4a450a2b65c26a771
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1279069
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1279069 - Replace &nbsp; with <space> for Graphite shaping purposes if &nbsp; is not supported by the font. r=jrmuizel
gfx/thebes/gfxGraphiteShaper.cpp
--- a/gfx/thebes/gfxGraphiteShaper.cpp
+++ b/gfx/thebes/gfxGraphiteShaper.cpp
@@ -1,10 +1,10 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxGraphiteShaper.h"
 #include "nsString.h"
 #include "gfxContext.h"
 #include "gfxFontConstants.h"
 #include "gfxTextRun.h"
@@ -154,16 +154,31 @@ gfxGraphiteShaper::ShapeText(DrawTarget 
     MergeFontFeatures(style,
                       mFont->GetFontEntry()->mFeatureSettings,
                       aShapedText->DisableLigatures(),
                       mFont->GetFontEntry()->FamilyName(),
                       mFallbackToSmallCaps,
                       AddFeature,
                       &f);
 
+    // Graphite shaping doesn't map U+00a0 (nbsp) to space if it is missing
+    // from the font, so check for that possibility. (Most fonts double-map
+    // the space glyph to both 0x20 and 0xA0, so this won't often be needed;
+    // so we don't copy the text until we know it's required.)
+    nsAutoString transformed;
+    const char16_t NO_BREAK_SPACE = 0x00a0;
+    if (!entry->HasCharacter(NO_BREAK_SPACE)) {
+        nsDependentSubstring src(aText, aLength);
+        if (src.FindChar(NO_BREAK_SPACE) != kNotFound) {
+            transformed = src;
+            transformed.ReplaceChar(NO_BREAK_SPACE, ' ');
+            aText = transformed.BeginReading();
+        }
+    }
+
     size_t numChars = gr_count_unicode_characters(gr_utf16,
                                                   aText, aText + aLength,
                                                   nullptr);
     gr_bidirtl grBidi = gr_bidirtl(aShapedText->IsRightToLeft()
                                    ? (gr_rtl | gr_nobidi) : gr_nobidi);
     gr_segment *seg = gr_make_seg(mGrFont, mGrFace, 0, grFeatures,
                                   gr_utf16, aText, numChars, grBidi);