diff options
-rw-r--r-- | webkit/pending/SimpleFontData.cpp | 12 | ||||
-rw-r--r-- | webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp | 23 |
2 files changed, 34 insertions, 1 deletions
diff --git a/webkit/pending/SimpleFontData.cpp b/webkit/pending/SimpleFontData.cpp index 9f4037b..bbdd46d 100644 --- a/webkit/pending/SimpleFontData.cpp +++ b/webkit/pending/SimpleFontData.cpp @@ -30,6 +30,7 @@ #include "config.h" #include "SimpleFontData.h" +#include "Font.h" #include "FontMetrics.h" #if ENABLE(SVG_FONTS) @@ -149,6 +150,17 @@ float SimpleFontData::widthForGlyph(UChar32 c, Glyph glyph) const } #endif + // Some characters should be zero width and we want to ignore whatever + // crazy stuff the font may have (or not defined). If the font doesn't + // define it, we don't want to measure the width of the "invalid character" + // box, for example. + // + // TODO(brettw): we should have Font::treatAsZeroWidthSpace return true for + // zero width spaces (U+200B) just like Font::treatAsSpace will return true + // for spaces. Then the additional OR is not necessary. + if (Font::treatAsZeroWidthSpace(c) || c == 0x200b) + return 0.0f; + if (width != cGlyphWidthUnknown) return width; diff --git a/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp b/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp index 65d1350..315bef7c 100644 --- a/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp +++ b/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp @@ -32,6 +32,7 @@ #include <windows.h> #include <vector> +#include "Font.h" #include "GlyphPageTreeNode.h" #include "SimpleFontData.h" #include "UniscribeStateTextRun.h" @@ -145,8 +146,28 @@ static bool FillBMPGlyphs(UChar* buffer, !(tm.tmPitchAndFamily & TMPF_TRUETYPE)) invalid_glyph = 0x1F; + WORD space_glyph = 0; // Glyph for a space. Lazily filled, see below. + for (unsigned i = 0; i < GlyphPage::size; i++) { - if (localGlyphBuffer[i] == invalid_glyph) { + // When this character should be a space, we ignore whatever the font + // says and use a space. Otherwise, if fonts don't map one of these + // space or zero width glyphs, we will get a box. + // + // TODO(brettw): we should have Font::treatAsZeroWidthSpace return true + // for zero width spaces (U+200B) just like Font::treatAsSpace will + // return true for spaces. Then the additional OR is not necessary. + if (Font::treatAsSpace(buffer[i]) || + Font::treatAsZeroWidthSpace(buffer[i]) || + buffer[i] == 0x200B) { + // Hard code the glyph indices for characters that should be treated + // like spaces. + if (!space_glyph) { + // Get the glyph index for space. + wchar_t space = ' '; + GetGlyphIndices(dc, &space, 1, &space_glyph, 0); + } + page->setGlyphDataForIndex(i, space_glyph, fontData); + } else if (localGlyphBuffer[i] == invalid_glyph) { // WebKit expects both the glyph index and FontData // pointer to be NULL if the glyph is not present page->setGlyphDataForIndex(i, 0, 0); |