Changeset 89988 in webkit


Ignore:
Timestamp:
Jun 28, 2011 11:01:53 PM (13 years ago)
Author:
bashi@chromium.org
Message:

2011-06-28 Kenichi Ishibashi <bashi@chromium.org>

Reviewed by Tony Chang.

[Chromium] Remove dependencies on harfbuzz from FontPlatformDataLinux and FontLinux
https://bugs.webkit.org/show_bug.cgi?id=62530

  • Moved codes of FontLinux which depend on harfbuzz APIs to ComplexTextController. Removed Some methods of ComplexTextController(advances() and logClusters()) since they are no longer needed.
  • Moved RefCountedHarfbuzzFace from FontPlatformDataLinux to HarfbuzzSkia and renamed it to HarfbuzzFace.

No new tests because there is no behavior change (The existing tests should cover the changes).

  • platform/graphics/chromium/ComplexTextControllerLinux.cpp: (WebCore::ComplexTextController::ComplexTextController): Added arguments so eliminating setter invocations. (WebCore::ComplexTextController::setupForRTL): Added. (WebCore::ComplexTextController::setupFontForScriptRun): Adopt the change of HarfbuzzFace class. (WebCore::ComplexTextController::setGlyphPositions): Use m_item.log_clusters instead of removed method. (WebCore::ComplexTextController::glyphIndexForXPositionInScriptRun): Added. (WebCore::ComplexTextController::offsetForPosition): Ditto. (WebCore::ComplexTextController::selectionRect): Ditto.
  • platform/graphics/chromium/ComplexTextControllerLinux.h: (WebCore::ComplexTextController::width):
  • platform/graphics/chromium/FontLinux.cpp: Removed truncateFixedPointToInteger(). (WebCore::Font::drawComplexText): Removed setter invocations of ComplexTextController. (WebCore::Font::floatWidthForComplexText): Ditto. (WebCore::Font::offsetForPositionForComplexText): Moved harfbuzz dependent code to ComplexTextController. (WebCore::Font::selectionRectForComplexText): Ditto.
  • platform/graphics/chromium/FontPlatformDataLinux.cpp: (WebCore::FontPlatformData::harfbuzzFace): Wrapped up HB_FaceRec in HarfbuzzFace class.
  • platform/graphics/chromium/FontPlatformDataLinux.h: Moved RefCountedHarfbuzzFace class and renamed to HarfbuzzFace.
  • platform/graphics/chromium/HarfbuzzSkia.cpp: (WebCore::allocHarfbuzzFont): Moved from ComplexTextControllerLinux.cpp. (WebCore::HarfbuzzFace::HarfbuzzFace): Added. (WebCore::HarfbuzzFace::~HarfbuzzFace): Added.
  • platform/graphics/chromium/HarfbuzzSkia.h: (WebCore::HarfbuzzFace::create): Added. (WebCore::HarfbuzzFace::face): Added.
  • platform/graphics/skia/GlyphPageTreeNodeSkia.cpp: (WebCore::substituteWithVerticalGlyphs): Adopt the change of HarfbuzzFace class.
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r89987 r89988  
     12011-06-28  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        [Chromium] Remove dependencies on harfbuzz from FontPlatformDataLinux and FontLinux
     6        https://bugs.webkit.org/show_bug.cgi?id=62530
     7
     8        - Moved codes of FontLinux which depend on harfbuzz APIs to ComplexTextController.  Removed Some methods of ComplexTextController(advances() and logClusters()) since they are no longer needed.
     9        - Moved RefCountedHarfbuzzFace from FontPlatformDataLinux to HarfbuzzSkia and renamed it to HarfbuzzFace.
     10
     11        No new tests because there is no behavior change (The existing tests should cover the changes).
     12
     13        * platform/graphics/chromium/ComplexTextControllerLinux.cpp:
     14        (WebCore::ComplexTextController::ComplexTextController): Added arguments so eliminating setter invocations.
     15        (WebCore::ComplexTextController::setupForRTL): Added.
     16        (WebCore::ComplexTextController::setupFontForScriptRun): Adopt the change of HarfbuzzFace class.
     17        (WebCore::ComplexTextController::setGlyphPositions): Use m_item.log_clusters instead of removed method.
     18        (WebCore::ComplexTextController::glyphIndexForXPositionInScriptRun): Added.
     19        (WebCore::ComplexTextController::offsetForPosition): Ditto.
     20        (WebCore::ComplexTextController::selectionRect): Ditto.
     21        * platform/graphics/chromium/ComplexTextControllerLinux.h:
     22        (WebCore::ComplexTextController::width):
     23        * platform/graphics/chromium/FontLinux.cpp: Removed truncateFixedPointToInteger().
     24        (WebCore::Font::drawComplexText): Removed setter invocations of ComplexTextController.
     25        (WebCore::Font::floatWidthForComplexText): Ditto.
     26        (WebCore::Font::offsetForPositionForComplexText): Moved harfbuzz dependent code to ComplexTextController.
     27        (WebCore::Font::selectionRectForComplexText): Ditto.
     28        * platform/graphics/chromium/FontPlatformDataLinux.cpp:
     29        (WebCore::FontPlatformData::harfbuzzFace): Wrapped up HB_FaceRec in HarfbuzzFace class.
     30        * platform/graphics/chromium/FontPlatformDataLinux.h: Moved RefCountedHarfbuzzFace class and renamed to HarfbuzzFace.
     31        * platform/graphics/chromium/HarfbuzzSkia.cpp:
     32        (WebCore::allocHarfbuzzFont): Moved from ComplexTextControllerLinux.cpp.
     33        (WebCore::HarfbuzzFace::HarfbuzzFace): Added.
     34        (WebCore::HarfbuzzFace::~HarfbuzzFace): Added.
     35        * platform/graphics/chromium/HarfbuzzSkia.h:
     36        (WebCore::HarfbuzzFace::create): Added.
     37        (WebCore::HarfbuzzFace::face): Added.
     38        * platform/graphics/skia/GlyphPageTreeNodeSkia.cpp:
     39        (WebCore::substituteWithVerticalGlyphs): Adopt  the change of HarfbuzzFace class.
     40
    1412011-06-28  Roland Steiner  <rolandsteiner@chromium.org>
    242
  • trunk/Source/WebCore/platform/graphics/chromium/ComplexTextControllerLinux.cpp

    r88139 r89988  
    3232#include "ComplexTextControllerLinux.h"
    3333
     34#include "FloatRect.h"
    3435#include "Font.h"
    3536#include "TextRun.h"
     37
     38extern "C" {
     39#include "harfbuzz-unicode.h"
     40}
    3641
    3742#include <unicode/normlzr.h>
     
    4752}
    4853
    49 ComplexTextController::ComplexTextController(const TextRun& run, unsigned startingX, unsigned startingY, const Font* font)
     54ComplexTextController::ComplexTextController(const TextRun& run, unsigned startingX, unsigned startingY, unsigned wordSpacing, unsigned letterSpacing, unsigned padding, const Font* font)
    5055    : m_font(font)
    5156    , m_run(getNormalizedTextRun(run, m_normalizedRun, m_normalizedBuffer))
    52     , m_wordSpacingAdjustment(0)
    53     , m_padding(0)
    54     , m_padPerWordBreak(0)
    55     , m_padError(0)
    56     , m_letterSpacing(0)
    5757{
    5858    // Do not use |run| inside this constructor. Use |m_run| instead.
     
    7777    reset(startingX);
    7878    m_startingY = startingY;
     79
     80    setWordSpacingAdjustment(wordSpacing);
     81    setLetterSpacingAdjustment(letterSpacing);
     82    setPadding(padding);
    7983}
    8084
     
    119123{
    120124    m_padding = padding;
     125    m_padError = 0;
    121126    if (!m_padding)
    122127        return;
     
    142147    m_indexOfNextScriptRun = 0;
    143148    m_offsetX = offset;
     149}
     150
     151void ComplexTextController::setupForRTL()
     152{
     153    int padding = m_padding;
     154    // FIXME: this causes us to shape the text twice -- once to compute the width and then again
     155    // below when actually rendering. Change ComplexTextController to match platform/mac and
     156    // platform/chromium/win by having it store the shaped runs, so we can reuse the results.
     157    reset(m_offsetX + widthOfFullRun());
     158    // We need to set the padding again because ComplexTextController layout consumed the value.
     159    // Fixing the above problem would help here too.
     160    setPadding(padding);
    144161}
    145162
     
    203220    const FontData* fontData = m_font->glyphDataForCharacter(m_item.string[m_item.item.pos], false, fontDataVariant).fontData;
    204221    const FontPlatformData& platformData = fontData->fontDataForCharacter(' ')->platformData();
    205     m_item.face = platformData.harfbuzzFace();
     222    m_item.face = platformData.harfbuzzFace()->face();
    206223    void* opaquePlatformData = const_cast<FontPlatformData*>(&platformData);
    207224    m_item.font->userData = opaquePlatformData;
     
    216233    m_item.font->x_scale = scale;
    217234    m_item.font->y_scale = scale;
    218 }
    219 
    220 HB_FontRec* ComplexTextController::allocHarfbuzzFont()
    221 {
    222     HB_FontRec* font = reinterpret_cast<HB_FontRec*>(fastMalloc(sizeof(HB_FontRec)));
    223     memset(font, 0, sizeof(HB_FontRec));
    224     font->klass = &harfbuzzSkiaClass;
    225     font->userData = 0;
    226 
    227     return font;
    228235}
    229236
     
    298305    // Glyphs are positioned starting from m_offsetX; in RTL mode they go leftwards from there.
    299306    for (size_t i = 0; i < m_item.num_glyphs; ++i) {
    300         while (static_cast<unsigned>(logClustersIndex) < m_item.item.length && logClusters()[logClustersIndex] < i)
     307        while (static_cast<unsigned>(logClustersIndex) < m_item.item.length && m_item.log_clusters[logClustersIndex] < i)
    301308            logClustersIndex++;
    302309
     
    400407}
    401408
     409int ComplexTextController::glyphIndexForXPositionInScriptRun(int targetX) const
     410{
     411    // Iterate through the glyphs in logical order, seeing whether targetX falls between the previous
     412    // position and halfway through the current glyph.
     413    // FIXME: this code probably belongs in ComplexTextController.
     414    int lastX = offsetX() - (rtl() ? -m_pixelWidth : m_pixelWidth);
     415    for (int glyphIndex = 0; static_cast<unsigned>(glyphIndex) < length(); ++glyphIndex) {
     416        int advance = truncateFixedPointToInteger(m_item.advances[glyphIndex]);
     417        int nextX = static_cast<int>(positions()[glyphIndex].x()) + advance / 2;
     418        if (std::min(nextX, lastX) <= targetX && targetX <= std::max(nextX, lastX))
     419            return glyphIndex;
     420        lastX = nextX;
     421    }
     422
     423    return length() - 1;
     424}
     425
     426int ComplexTextController::offsetForPosition(int targetX)
     427{
     428    unsigned basePosition = 0;
     429
     430    int x = offsetX();
     431    while (nextScriptRun()) {
     432        int nextX = offsetX();
     433
     434        if (std::min(x, nextX) <= targetX && targetX <= std::max(x, nextX)) {
     435            // The x value in question is within this script run.
     436            const int glyphIndex = glyphIndexForXPositionInScriptRun(targetX);
     437
     438            // Now that we have a glyph index, we have to turn that into a
     439            // code-point index. Because of ligatures, several code-points may
     440            // have gone into a single glyph. We iterate over the clusters log
     441            // and find the first code-point which contributed to the glyph.
     442
     443            // Some shapers (i.e. Khmer) will produce cluster logs which report
     444            // that /no/ code points contributed to certain glyphs. Because of
     445            // this, we take any code point which contributed to the glyph in
     446            // question, or any subsequent glyph. If we run off the end, then
     447            // we take the last code point.
     448            for (unsigned j = 0; j < numCodePoints(); ++j) {
     449                if (m_item.log_clusters[j] >= glyphIndex)
     450                    return basePosition + j;
     451            }
     452
     453            return basePosition + numCodePoints() - 1;
     454        }
     455
     456        basePosition += numCodePoints();
     457    }
     458
     459    return basePosition;
     460}
     461
     462FloatRect ComplexTextController::selectionRect(const FloatPoint& point, int height, int from, int to)
     463{
     464    int fromX = -1, toX = -1;
     465    // Iterate through the script runs in logical order, searching for the run covering the positions of interest.
     466    while (nextScriptRun() && (fromX == -1 || toX == -1)) {
     467        if (fromX == -1 && from >= 0 && static_cast<unsigned>(from) < numCodePoints()) {
     468            // |from| is within this script run. So we index the clusters log to
     469            // find which glyph this code-point contributed to and find its x
     470            // position.
     471            int glyph = m_item.log_clusters[from];
     472            fromX = positions()[glyph].x();
     473            if (rtl())
     474                fromX += truncateFixedPointToInteger(m_item.advances[glyph]);
     475        } else
     476            from -= numCodePoints();
     477
     478        if (toX == -1 && to >= 0 && static_cast<unsigned>(to) < numCodePoints()) {
     479            int glyph = m_item.log_clusters[to];
     480            toX = positions()[glyph].x();
     481            if (rtl())
     482                toX += truncateFixedPointToInteger(m_item.advances[glyph]);
     483        } else
     484            to -= numCodePoints();
     485    }
     486
     487    // The position in question might be just after the text.
     488    if (fromX == -1)
     489        fromX = offsetX();
     490    if (toX == -1)
     491        toX = offsetX();
     492
     493    ASSERT(fromX != -1 && toX != -1);
     494
     495    if (fromX < toX)
     496        return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
     497
     498    return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
     499}
     500
    402501} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/ComplexTextControllerLinux.h

    r85013 r89988  
    3737#include "TextRun.h"
    3838
     39extern "C" {
     40#include "harfbuzz-shaper.h"
     41}
     42
    3943#include <unicode/uchar.h>
    4044#include <wtf/OwnArrayPtr.h>
     
    6266class ComplexTextController {
    6367public:
    64     ComplexTextController(const TextRun&, unsigned, unsigned, const Font*);
     68    ComplexTextController(const TextRun&, unsigned startingX, unsigned startingY, unsigned wordSpacing, unsigned letterSpacing, unsigned padding, const Font*);
    6569    ~ComplexTextController();
    6670
     
    8690    int letterSpacing() const { return m_letterSpacing; }
    8791
    88     // Set the x offset for the next script run. This affects the values in
    89     // |xPositions|
     92    void setupForRTL();
    9093    bool rtl() const { return m_run.rtl(); }
    9194    const uint16_t* glyphs() const { return m_glyphs16; }
     
    99102    const SkPoint* positions() const { return m_positions; }
    100103
    101     // Get the advances (widths) for each glyph.
    102     const HB_Fixed* advances() const { return m_item.advances; }
    103 
    104     // Return the width (in px) of the current script run.
    105     const unsigned width() const { return m_pixelWidth; }
    106 
    107     // Return the cluster log for the current script run. For example:
    108     //   script run: f i a n c é  (fi gets ligatured)
    109     //   log clutrs: 0 0 1 2 3 4
    110     // So, for each input code point, the log tells you which output glyph was
    111     // generated for it.
    112     const unsigned short* logClusters() const { return m_item.log_clusters; }
    113 
    114104    // return the number of code points in the current script run
    115105    const unsigned numCodePoints() const { return m_item.item.length; }
     
    120110    const FontPlatformData* fontPlatformDataForScriptRun() { return reinterpret_cast<FontPlatformData*>(m_item.font->userData); }
    121111
     112    int offsetForPosition(int);
     113    FloatRect selectionRect(const FloatPoint&, int height, int from , int to);
     114
    122115private:
     116    // Return the width (in px) of the current script run.
     117    unsigned width() const { return m_pixelWidth; }
     118
    123119    void setupFontForScriptRun();
    124     HB_FontRec* allocHarfbuzzFont();
    125120    void deleteGlyphArrays();
    126121    void createGlyphArrays(int);
     
    134129    // This matches the logic in RenderBlock::findNextLineBreak
    135130    static bool isCodepointSpace(HB_UChar16 c) { return c == ' ' || c == '\t'; }
     131
     132    int glyphIndexForXPositionInScriptRun(int targetX) const;
    136133
    137134    const Font* const m_font;
  • trunk/Source/WebCore/platform/graphics/chromium/FontLinux.cpp

    r89250 r89988  
    166166}
    167167
    168 // Harfbuzz uses 26.6 fixed point values for pixel offsets. However, we don't
    169 // handle subpixel positioning so this function is used to truncate Harfbuzz
    170 // values to a number of pixels.
    171 static int truncateFixedPointToInteger(HB_Fixed value)
    172 {
    173     return value >> 6;
    174 }
    175 
    176168static void setupForTextPainting(SkPaint* paint, SkColor color)
    177169{
     
    206198    }
    207199
    208     ComplexTextController controller(run, point.x(), point.y(), this);
    209     controller.setWordSpacingAdjustment(wordSpacing());
    210     controller.setLetterSpacingAdjustment(letterSpacing());
    211     controller.setPadding(run.expansion());
    212 
    213     if (run.rtl()) {
    214         // FIXME: this causes us to shape the text twice -- once to compute the width and then again
    215         // below when actually rendering.  Change ComplexTextController to match platform/mac and
    216         // platform/chromium/win by having it store the shaped runs, so we can reuse the results.
    217         controller.reset(point.x() + controller.widthOfFullRun());
    218         // We need to set the padding again because ComplexTextController layout consumed the value.
    219         // Fixing the above problem would help here too.
    220         controller.setPadding(run.expansion());
    221     }
     200    ComplexTextController controller(run, point.x(), point.y(), wordSpacing(), letterSpacing(), run.expansion(), this);
     201
     202    if (run.rtl())
     203        controller.setupForRTL();
    222204
    223205    while (controller.nextScriptRun()) {
     
    243225float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const
    244226{
    245     ComplexTextController controller(run, 0, 0, this);
    246     controller.setWordSpacingAdjustment(wordSpacing());
    247     controller.setLetterSpacingAdjustment(letterSpacing());
    248     controller.setPadding(run.expansion());
     227    ComplexTextController controller(run, 0, 0, wordSpacing(), letterSpacing(), run.expansion(), this);
    249228    return controller.widthOfFullRun();
    250 }
    251 
    252 static int glyphIndexForXPositionInScriptRun(const ComplexTextController& controller, int targetX)
    253 {
    254     // Iterate through the glyphs in logical order, seeing whether targetX falls between the previous
    255     // position and halfway through the current glyph.
    256     // FIXME: this code probably belongs in ComplexTextController.
    257     int lastX = controller.offsetX() - (controller.rtl() ? -controller.width() : controller.width());
    258     for (int glyphIndex = 0; static_cast<unsigned>(glyphIndex) < controller.length(); ++glyphIndex) {
    259         int advance = truncateFixedPointToInteger(controller.advances()[glyphIndex]);
    260         int nextX = static_cast<int>(controller.positions()[glyphIndex].x()) + advance / 2;
    261         if (std::min(nextX, lastX) <= targetX && targetX <= std::max(nextX, lastX))
    262             return glyphIndex;
    263         lastX = nextX;
    264     }
    265 
    266     return controller.length() - 1;
    267229}
    268230
     
    277239    // (Mac code ignores includePartialGlyphs, and they don't know what it's
    278240    // supposed to do, so we just ignore it as well.)
    279     ComplexTextController controller(run, 0, 0, this);
    280     controller.setWordSpacingAdjustment(wordSpacing());
    281     controller.setLetterSpacingAdjustment(letterSpacing());
    282     controller.setPadding(run.expansion());
    283     if (run.rtl()) {
    284         // See FIXME in drawComplexText.
    285         controller.reset(controller.widthOfFullRun());
    286         controller.setPadding(run.expansion());
    287     }
    288 
    289     unsigned basePosition = 0;
    290 
    291     int x = controller.offsetX();
    292     while (controller.nextScriptRun()) {
    293         int nextX = controller.offsetX();
    294 
    295         if (std::min(x, nextX) <= targetX && targetX <= std::max(x, nextX)) {
    296             // The x value in question is within this script run.
    297             const int glyphIndex = glyphIndexForXPositionInScriptRun(controller, targetX);
    298 
    299             // Now that we have a glyph index, we have to turn that into a
    300             // code-point index. Because of ligatures, several code-points may
    301             // have gone into a single glyph. We iterate over the clusters log
    302             // and find the first code-point which contributed to the glyph.
    303 
    304             // Some shapers (i.e. Khmer) will produce cluster logs which report
    305             // that /no/ code points contributed to certain glyphs. Because of
    306             // this, we take any code point which contributed to the glyph in
    307             // question, or any subsequent glyph. If we run off the end, then
    308             // we take the last code point.
    309             const unsigned short* log = controller.logClusters();
    310             for (unsigned j = 0; j < controller.numCodePoints(); ++j) {
    311                 if (log[j] >= glyphIndex)
    312                     return basePosition + j;
    313             }
    314 
    315             return basePosition + controller.numCodePoints() - 1;
    316         }
    317 
    318         basePosition += controller.numCodePoints();
    319     }
    320 
    321     return basePosition;
     241    ComplexTextController controller(run, 0, 0, wordSpacing(), letterSpacing(), run.expansion(), this);
     242    if (run.rtl())
     243        controller.setupForRTL();
     244    return controller.offsetForPosition(targetX);
    322245}
    323246
     
    327250                                            int from, int to) const
    328251{
    329     int fromX = -1, toX = -1;
    330     ComplexTextController controller(run, 0, 0, this);
    331     controller.setWordSpacingAdjustment(wordSpacing());
    332     controller.setLetterSpacingAdjustment(letterSpacing());
    333     controller.setPadding(run.expansion());
    334     if (run.rtl()) {
    335         // See FIXME in drawComplexText.
    336         controller.reset(controller.widthOfFullRun());
    337         controller.setPadding(run.expansion());
    338     }
    339 
    340     // Iterate through the script runs in logical order, searching for the run covering the positions of interest.
    341     while (controller.nextScriptRun() && (fromX == -1 || toX == -1)) {
    342         if (fromX == -1 && from >= 0 && static_cast<unsigned>(from) < controller.numCodePoints()) {
    343             // |from| is within this script run. So we index the clusters log to
    344             // find which glyph this code-point contributed to and find its x
    345             // position.
    346             int glyph = controller.logClusters()[from];
    347             fromX = controller.positions()[glyph].x();
    348             if (controller.rtl())
    349                 fromX += truncateFixedPointToInteger(controller.advances()[glyph]);
    350         } else
    351             from -= controller.numCodePoints();
    352 
    353         if (toX == -1 && to >= 0 && static_cast<unsigned>(to) < controller.numCodePoints()) {
    354             int glyph = controller.logClusters()[to];
    355             toX = controller.positions()[glyph].x();
    356             if (controller.rtl())
    357                 toX += truncateFixedPointToInteger(controller.advances()[glyph]);
    358         } else
    359             to -= controller.numCodePoints();
    360     }
    361 
    362     // The position in question might be just after the text.
    363     if (fromX == -1)
    364         fromX = controller.offsetX();
    365     if (toX == -1)
    366         toX = controller.offsetX();
    367 
    368     ASSERT(fromX != -1 && toX != -1);
    369 
    370     if (fromX < toX)
    371         return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
    372 
    373     return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
     252    ComplexTextController controller(run, 0, 0, wordSpacing(), letterSpacing(), run.expansion(), this);
     253    if (run.rtl())
     254        controller.setupForRTL();
     255    return controller.selectionRect(point, height, from, to);
    374256}
    375257
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataLinux.cpp

    r83020 r89988  
    3232#include "FontPlatformData.h"
    3333
    34 #include "HarfbuzzSkia.h"
    3534#include "NotImplemented.h"
    3635#include "PlatformBridge.h"
     
    6261{
    6362    isSkiaSubpixelGlyphs = isSubpixelGlyphs;
    64 }
    65 
    66 FontPlatformData::RefCountedHarfbuzzFace::~RefCountedHarfbuzzFace()
    67 {
    68     HB_FreeFace(m_harfbuzzFace);
    6963}
    7064
     
    230224}
    231225
    232 HB_FaceRec_* FontPlatformData::harfbuzzFace() const
     226HarfbuzzFace* FontPlatformData::harfbuzzFace() const
    233227{
    234228    if (!m_harfbuzzFace)
    235         m_harfbuzzFace = RefCountedHarfbuzzFace::create(HB_NewFace(const_cast<FontPlatformData*>(this), harfbuzzSkiaGetTable));
    236 
    237     return m_harfbuzzFace->face();
     229        m_harfbuzzFace = HarfbuzzFace::create(const_cast<FontPlatformData*>(this));
     230
     231    return m_harfbuzzFace.get();
    238232}
    239233
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataLinux.h

    r80654 r89988  
    3434#include "FontOrientation.h"
    3535#include "FontRenderStyle.h"
     36#include "HarfbuzzSkia.h"
    3637#include "TextOrientation.h"
    3738#include <wtf/Forward.h>
     
    4344class SkTypeface;
    4445typedef uint32_t SkFontID;
    45 
    46 struct HB_FaceRec_;
    4746
    4847namespace WebCore {
     
    129128#endif
    130129
    131     HB_FaceRec_* harfbuzzFace() const;
     130    HarfbuzzFace* harfbuzzFace() const;
    132131
    133132    // -------------------------------------------------------------------------
     
    139138
    140139private:
    141     class RefCountedHarfbuzzFace : public RefCounted<RefCountedHarfbuzzFace> {
    142     public:
    143         static PassRefPtr<RefCountedHarfbuzzFace> create(HB_FaceRec_* harfbuzzFace)
    144         {
    145             return adoptRef(new RefCountedHarfbuzzFace(harfbuzzFace));
    146         }
    147 
    148         ~RefCountedHarfbuzzFace();
    149 
    150         HB_FaceRec_* face() const { return m_harfbuzzFace; }
    151 
    152     private:
    153         RefCountedHarfbuzzFace(HB_FaceRec_* harfbuzzFace) : m_harfbuzzFace(harfbuzzFace)
    154         {
    155         }
    156 
    157         HB_FaceRec_* m_harfbuzzFace;
    158     };
    159 
    160140    void querySystemForRenderStyle();
    161141
     
    170150    TextOrientation m_textOrientation;
    171151    FontRenderStyle m_style;
    172     mutable RefPtr<RefCountedHarfbuzzFace> m_harfbuzzFace;
     152    mutable RefPtr<HarfbuzzFace> m_harfbuzzFace;
    173153
    174154    SkTypeface* hashTableDeletedFontValue() const { return reinterpret_cast<SkTypeface*>(-1); }
  • trunk/Source/WebCore/platform/graphics/chromium/HarfbuzzSkia.cpp

    r86171 r89988  
    198198};
    199199
     200HB_Font_* allocHarfbuzzFont()
     201{
     202    HB_Font_* font = reinterpret_cast<HB_Font_*>(fastMalloc(sizeof(HB_Font_)));
     203    memset(font, 0, sizeof(HB_Font_));
     204    font->klass = &harfbuzzSkiaClass;
     205    font->userData = 0;
     206
     207    return font;
     208}
     209
    200210HB_Error harfbuzzSkiaGetTable(void* voidface, const HB_Tag tag, HB_Byte* buffer, HB_UInt* len)
    201211{
     
    217227}
    218228
     229HarfbuzzFace::HarfbuzzFace(FontPlatformData* platformData)
     230{
     231    m_harfbuzzFace = HB_NewFace(platformData, harfbuzzSkiaGetTable);
     232}
     233
     234HarfbuzzFace::~HarfbuzzFace()
     235{
     236    HB_FreeFace(m_harfbuzzFace);
     237}
     238
    219239}  // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/HarfbuzzSkia.h

    r46144 r89988  
    3232#define HarfbuzzSkia_h
    3333
    34 extern "C" {
    35 #include "harfbuzz-shaper.h"
    36 #include "harfbuzz-unicode.h"
    37 }
     34#include <wtf/RefCounted.h>
     35#include <wtf/RefPtr.h>
     36
     37struct HB_FaceRec_;
     38struct HB_Font_;
    3839
    3940namespace WebCore {
    40     HB_Error harfbuzzSkiaGetTable(void* voidface, const HB_Tag, HB_Byte* buffer, HB_UInt* len);
    41     extern const HB_FontClass harfbuzzSkiaClass;
     41
     42class FontPlatformData;
     43
     44class HarfbuzzFace : public RefCounted<HarfbuzzFace> {
     45public:
     46    static PassRefPtr<HarfbuzzFace> create(FontPlatformData* platformData)
     47    {
     48        return adoptRef(new HarfbuzzFace(platformData));
     49    }
     50
     51    ~HarfbuzzFace();
     52
     53    HB_FaceRec_* face() const { return m_harfbuzzFace; }
     54
     55private:
     56    explicit HarfbuzzFace(FontPlatformData*);
     57
     58    HB_FaceRec_* m_harfbuzzFace;
     59};
     60
     61// FIXME: Remove this asymmetric alloc/free function.
     62// We'll remove this once we move to the new Harfbuzz API.
     63HB_Font_* allocHarfbuzzFont();
     64
    4265}  // namespace WebCore
    4366
  • trunk/Source/WebCore/platform/graphics/skia/GlyphPageTreeNodeSkia.cpp

    r80610 r89988  
    4040#include "SkUtils.h"
    4141
     42extern "C" {
     43#include "harfbuzz-shaper.h"
     44}
     45
    4246namespace WebCore {
    4347
    4448static int substituteWithVerticalGlyphs(const SimpleFontData* fontData, uint16_t* glyphs, unsigned bufferLength)
    4549{
    46     HB_FaceRec_* hbFace = fontData->platformData().harfbuzzFace();
     50    HB_FaceRec_* hbFace = fontData->platformData().harfbuzzFace()->face();
    4751    if (!hbFace->gsub) {
    4852        // if there is no GSUB table, treat it as not covered
Note: See TracChangeset for help on using the changeset viewer.