Changeset 141122 in webkit


Ignore:
Timestamp:
Jan 29, 2013 9:25:34 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Freetype] Cannot use characters outside the BMP
https://bugs.webkit.org/show_bug.cgi?id=108102

Patch by Martin Robinson <mrobinson@igalia.com> on 2013-01-29
Reviewed by Carlos Garcia Campos.

Source/WebCore:

Test: platform/gtk/fonts/non-bmp-characters.html

Instead of never handling surrogate pairs when dealing with UChar arrays,
abstract way the logic for this into UTF16UChar32Iterator and use it
everywhere in Freetype. This allows the Freetype backend to render
non-BMP characters which are always represented as surrogate pairs in
UTF-16.

  • GNUmakefile.list.am: Added UTF16UChar32Iterator to the source list.
  • platform/graphics/freetype/FontCacheFreeType.cpp:

(WebCore::createFontConfigPatternForCharacters): Use the new iterator.
(WebCore::FontCache::getFontDataForCharacters): Ditto.

  • platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:

(WebCore::GlyphPage::fill): Ditto. Remove the early return when dealing
with non-BMP data.

  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::containsCharacters): Use the new iterator.

  • platform/graphics/freetype/UTF16UChar32Iterator.h: Added. An iterator that

extracts UChar32 from UTF-16 UChar arrays.

  • GNUmakefile.list.am:
  • platform/graphics/freetype/FontCacheFreeType.cpp:

(WebCore::createFontConfigPatternForCharacters):
(WebCore::FontCache::getFontDataForCharacters):

  • platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:

(WebCore::GlyphPage::fill):

  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::containsCharacters):

  • platform/graphics/freetype/UTF16UChar32Iterator.h: Added.

(WebCore):
(UTF16UChar32Iterator):
(WebCore::UTF16UChar32Iterator::UTF16UChar32Iterator):
(WebCore::UTF16UChar32Iterator::end):
(WebCore::UTF16UChar32Iterator::next):

  • GNUmakefile.list.am:
  • platform/graphics/freetype/FontCacheFreeType.cpp:

(WebCore::createFontConfigPatternForCharacters):

  • platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:

(WebCore::GlyphPage::fill):

  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::containsCharacters):

  • platform/graphics/freetype/UTF16UChar32Iterator.h: Added.

(WebCore):
(UTF16UChar32Iterator):
(WebCore::UTF16UChar32Iterator::UTF16UChar32Iterator):
(WebCore::UTF16UChar32Iterator::end):
(WebCore::UTF16UChar32Iterator::next):

LayoutTests:

Added a pixel test for rendering non-BMP characters.

  • platform/gtk/fonts/non-bmp-characters.html: Added.
  • platform/gtk/platform/gtk/fonts/non-bmp-characters-expected.png: Added.
  • platform/gtk/platform/gtk/fonts/non-bmp-characters-expected.txt: Added.
Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r141119 r141122  
     12013-01-29  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [Freetype] Cannot use characters outside the BMP
     4        https://bugs.webkit.org/show_bug.cgi?id=108102
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Added a pixel test for rendering non-BMP characters.
     9
     10        * platform/gtk/fonts/non-bmp-characters.html: Added.
     11        * platform/gtk/platform/gtk/fonts/non-bmp-characters-expected.png: Added.
     12        * platform/gtk/platform/gtk/fonts/non-bmp-characters-expected.txt: Added.
     13
    1142013-01-29  Alexis Menard  <alexis@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r141121 r141122  
     12013-01-29  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [Freetype] Cannot use characters outside the BMP
     4        https://bugs.webkit.org/show_bug.cgi?id=108102
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Test: platform/gtk/fonts/non-bmp-characters.html
     9
     10        Instead of never handling surrogate pairs when dealing with UChar arrays,
     11        abstract way the logic for this into UTF16UChar32Iterator and use it
     12        everywhere in Freetype. This allows the Freetype backend to render
     13        non-BMP characters which are always represented as surrogate pairs in
     14        UTF-16.
     15
     16        * GNUmakefile.list.am: Added UTF16UChar32Iterator to the source list.
     17        * platform/graphics/freetype/FontCacheFreeType.cpp:
     18        (WebCore::createFontConfigPatternForCharacters): Use the new iterator.
     19        (WebCore::FontCache::getFontDataForCharacters): Ditto.
     20        * platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
     21        (WebCore::GlyphPage::fill): Ditto. Remove the early return when dealing
     22        with non-BMP data.
     23        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     24        (WebCore::SimpleFontData::containsCharacters): Use the new iterator.
     25        * platform/graphics/freetype/UTF16UChar32Iterator.h: Added. An iterator that
     26        extracts UChar32 from UTF-16 UChar arrays.
     27
     28        * GNUmakefile.list.am:
     29        * platform/graphics/freetype/FontCacheFreeType.cpp:
     30        (WebCore::createFontConfigPatternForCharacters):
     31        (WebCore::FontCache::getFontDataForCharacters):
     32        * platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
     33        (WebCore::GlyphPage::fill):
     34        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     35        (WebCore::SimpleFontData::containsCharacters):
     36        * platform/graphics/freetype/UTF16UChar32Iterator.h: Added.
     37        (WebCore):
     38        (UTF16UChar32Iterator):
     39        (WebCore::UTF16UChar32Iterator::UTF16UChar32Iterator):
     40        (WebCore::UTF16UChar32Iterator::end):
     41        (WebCore::UTF16UChar32Iterator::next):
     42
     43        * GNUmakefile.list.am:
     44        * platform/graphics/freetype/FontCacheFreeType.cpp:
     45        (WebCore::createFontConfigPatternForCharacters):
     46        * platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
     47        (WebCore::GlyphPage::fill):
     48        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     49        (WebCore::SimpleFontData::containsCharacters):
     50        * platform/graphics/freetype/UTF16UChar32Iterator.h: Added.
     51        (WebCore):
     52        (UTF16UChar32Iterator):
     53        (WebCore::UTF16UChar32Iterator::UTF16UChar32Iterator):
     54        (WebCore::UTF16UChar32Iterator::end):
     55        (WebCore::UTF16UChar32Iterator::next):
     56
    1572013-01-29  Glenn Hartmann  <hartmanng@chromium.org>
    258
  • trunk/Source/WebCore/GNUmakefile.list.am

    r141063 r141122  
    42354235        Source/WebCore/platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp \
    42364236        Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp \
     4237        Source/WebCore/platform/graphics/freetype/UTF16UChar32Iterator.h \
    42374238        Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaperBase.cpp \
    42384239        Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaperBase.h \
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r130160 r141122  
    2727#include "RefPtrCairo.h"
    2828#include "SimpleFontData.h"
     29#include "UTF16UChar32Iterator.h"
    2930#include <cairo-ft.h>
    3031#include <cairo.h>
     
    4243}
    4344
    44 FcPattern* createFontConfigPatternForCharacters(const UChar* characters, int length)
     45FcPattern* createFontConfigPatternForCharacters(const UChar* characters, int bufferLength)
    4546{
    4647    FcPattern* pattern = FcPatternCreate();
    47 
    4848    FcCharSet* fontConfigCharSet = FcCharSetCreate();
    49     for (int i = 0; i < length; ++i) {
    50         if (U16_IS_SURROGATE(characters[i]) && U16_IS_SURROGATE_LEAD(characters[i])
    51                 && i != length - 1 && U16_IS_TRAIL(characters[i + 1])) {
    52             FcCharSetAddChar(fontConfigCharSet, U16_GET_SUPPLEMENTARY(characters[i], characters[i+1]));
    53             i++;
    54         } else
    55             FcCharSetAddChar(fontConfigCharSet, characters[i]);
    56     }
     49
     50    UTF16UChar32Iterator iterator(characters, bufferLength);
     51    UChar32 character = iterator.next();
     52    while (character != iterator.end()) {
     53        FcCharSetAddChar(fontConfigCharSet, character);
     54        character = iterator.next();
     55    }
     56
    5757    FcPatternAddCharSet(pattern, FC_CHARSET, fontConfigCharSet);
    5858    FcCharSetDestroy(fontConfigCharSet);
  • trunk/Source/WebCore/platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp

    r90041 r141122  
    3333
    3434#include "SimpleFontData.h"
     35#include "UTF16UChar32Iterator.h"
    3536#include <cairo-ft.h>
    3637#include <cairo.h>
     
    4142bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
    4243{
    43     // The bufferLength will be greater than the glyph page size if the buffer has Unicode supplementary characters.
    44     // We won't support this for now.
    45     if (bufferLength > GlyphPage::size)
    46         return false;
    47 
    4844    cairo_scaled_font_t* scaledFont = fontData->platformData().scaledFont();
    4945    ASSERT(scaledFont);
     
    5450
    5551    bool haveGlyphs = false;
     52    UTF16UChar32Iterator iterator(buffer, bufferLength);
    5653    for (unsigned i = 0; i < length; i++) {
    57         Glyph glyph = FcFreeTypeCharIndex(face, buffer[i]);
     54        UChar32 character = iterator.next();
     55        if (character == iterator.end())
     56            break;
     57
     58        Glyph glyph = FcFreeTypeCharIndex(face, character);
    5859        if (!glyph)
    5960            setGlyphDataForIndex(offset + i, 0, 0);
  • trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp

    r140111 r141122  
    4040#include "FontDescription.h"
    4141#include "GlyphBuffer.h"
     42#include "UTF16UChar32Iterator.h"
    4243#include <cairo-ft.h>
    4344#include <cairo.h>
     
    103104}
    104105
    105 bool SimpleFontData::containsCharacters(const UChar* characters, int length) const
     106bool SimpleFontData::containsCharacters(const UChar* characters, int bufferLength) const
    106107{
    107108    ASSERT(m_platformData.scaledFont());
     
    110111        return false;
    111112
    112     for (int i = 0; i < length; i++) {
    113         if (FcFreeTypeCharIndex(face, characters[i]) == 0) {
     113    UTF16UChar32Iterator iterator(characters, bufferLength);
     114    UChar32 character = iterator.next();
     115    while (character != iterator.end()) {
     116        if (!FcFreeTypeCharIndex(face, character)) {
    114117            cairo_ft_scaled_font_unlock_face(m_platformData.scaledFont());
    115118            return false;
    116119        }
     120        character = iterator.next();
    117121    }
    118122
Note: See TracChangeset for help on using the changeset viewer.