Chromium Code Reviews| Index: Source/platform/fonts/shaping/HarfBuzzShaper.h |
| diff --git a/Source/platform/fonts/shaping/HarfBuzzShaper.h b/Source/platform/fonts/shaping/HarfBuzzShaper.h |
| index 4f12c76ddf3774c9f996273ceaaa96237c5a6810..4022cba6cb88a21847c5f7ce7dc276990b786f4f 100644 |
| --- a/Source/platform/fonts/shaping/HarfBuzzShaper.h |
| +++ b/Source/platform/fonts/shaping/HarfBuzzShaper.h |
| @@ -49,53 +49,64 @@ namespace blink { |
| class Font; |
| class GlyphBuffer; |
| class SimpleFontData; |
| +class HarfBuzzShaper; |
| -class PLATFORM_EXPORT HarfBuzzShaper final : public Shaper { |
| +class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> { |
| public: |
| - HarfBuzzShaper(const Font*, const TextRun&, const GlyphData* emphasisData = nullptr, |
| - HashSet<const SimpleFontData*>* fallbackFonts = nullptr, FloatRect* = nullptr); |
| - |
| - void setDrawRange(int from, int to); |
| - bool shape(GlyphBuffer* = 0); |
| - float totalWidth() { return m_totalWidth; } |
| + ShapeResult(): m_width(0), m_numGlyphs(0) { } |
| + ~ShapeResult(); |
| + |
| + float width() { return m_width; } |
| + FloatRect bounds() { return m_glyphBoundingBox; } |
| + float fillGlyphBuffer(GlyphBuffer*, float initialAdvance, unsigned from, |
| + unsigned to, unsigned runOffset = 0); |
| + float fillGlyphBufferForTextEmphasis(GlyphBuffer*, float initialAdvance, |
| + const TextRun&, const GlyphData*, unsigned from, unsigned to, |
| + unsigned runOffset = 0); |
| + FloatRect selectionRect(const FloatPoint&, int height, unsigned from, |
| + unsigned to); |
| int offsetForPosition(float targetX); |
| - FloatRect selectionRect(const FloatPoint&, int height, int from, int to); |
| - |
| - unsigned numberOfRunsForTesting() const |
| - { |
| - return m_harfBuzzRuns.size(); |
| - } |
| + unsigned numCharacters() const { return m_numCharacters; } |
| + unsigned numberOfRunsForTesting() const; |
| bool runInfoForTesting(unsigned runIndex, unsigned& startIndex, |
| - unsigned& numGlyphs, hb_script_t& script) |
| - { |
| - if (runIndex < m_harfBuzzRuns.size()) { |
| - startIndex = m_harfBuzzRuns[runIndex]->startIndex(); |
| - numGlyphs = m_harfBuzzRuns[runIndex]->numGlyphs(); |
| - script = m_harfBuzzRuns[runIndex]->script(); |
| - return true; |
| - } |
| - return false; |
| - } |
| + unsigned& numGlyphs, hb_script_t&); |
| + uint16_t glyphForTesting(unsigned runIndex, size_t glyphIndex); |
| + float advanceForTesting(unsigned runIndex, size_t glyphIndex); |
| - uint16_t glyphForTesting(unsigned runIndex, size_t glyphIndex) |
| - { |
| - return m_harfBuzzRuns[runIndex]->glyphData(glyphIndex).glyph; |
| - } |
| +private: |
| + struct RunInfo; |
| - float advanceForTesting(unsigned runIndex, size_t glyphIndex) |
| - { |
| - return m_harfBuzzRuns[runIndex]->glyphData(glyphIndex).advance; |
| - } |
| + template<TextDirection> |
| + float fillGlyphBufferForRun(GlyphBuffer*, const RunInfo*, |
| + float initialAdvance, unsigned from, unsigned to, unsigned runOffset); |
| + float fillGlyphBufferForTextEmphasisRun(GlyphBuffer*, const RunInfo*, |
| + const TextRun&, const GlyphData*, float initialAdvance, unsigned from, |
| + unsigned to, unsigned runOffset); |
| -private: |
| - struct HarfBuzzRunGlyphData { |
| - uint16_t glyph; |
| - uint16_t characterIndex; |
| - float advance; |
| - FloatSize offset; |
| - }; |
| + float m_width; |
| + FloatRect m_glyphBoundingBox; |
| + Vector<RunInfo*> m_runs; |
| + |
| + unsigned m_numCharacters; |
| + unsigned m_numGlyphs : 31; |
| + |
| + // Overall direction for the TextRun, dictates which order each individual |
| + // sub run (represented by RunInfo structs in the m_runs vector) can have a |
|
drott
2015/06/23 12:45:52
...a different text direction?
|
| + // different text direction. |
| + unsigned m_direction : 1; |
| + |
| + friend class HarfBuzzShaper; |
| +}; |
| +class PLATFORM_EXPORT HarfBuzzShaper final : public Shaper { |
| +public: |
| + HarfBuzzShaper(const Font*, const TextRun&, |
| + HashSet<const SimpleFontData*>* fallbackFonts = nullptr); |
| + PassRefPtr<ShapeResult> shapeResult(); |
| + ~HarfBuzzShaper() { } |
| + |
| +private: |
| class PLATFORM_EXPORT HarfBuzzRun { |
| public: |
| HarfBuzzRun(const HarfBuzzRun&); |
| @@ -106,22 +117,11 @@ private: |
| return adoptPtr(new HarfBuzzRun(fontData, startIndex, numCharacters, direction, script)); |
| } |
| - void applyShapeResult(hb_buffer_t*); |
| - void setGlyphAndPositions(unsigned index, uint16_t glyphId, float advance, float offsetX, float offsetY); |
| - void setWidth(float width) { m_width = width; } |
| - void addAdvance(unsigned index, float advance); |
| - |
| - int characterIndexForXPosition(float targetX); |
| - float xPositionForOffset(unsigned offset); |
| - |
| const SimpleFontData* fontData() { return m_fontData; } |
| unsigned startIndex() const { return m_startIndex; } |
| unsigned numCharacters() const { return m_numCharacters; } |
| unsigned numGlyphs() const { return m_numGlyphs; } |
| - Vector<HarfBuzzRunGlyphData, 256>& glyphData() { return m_glyphData; } |
| - HarfBuzzRunGlyphData& glyphData(size_t glyphIndex) { return m_glyphData[glyphIndex]; } |
| - size_t glyphToCharacterIndex(size_t i) const { return m_startIndex + m_glyphData[i].characterIndex; } |
| - float width() { return m_width; } |
| + void setNumGlyphs(unsigned num) { m_numGlyphs = num; } |
| hb_direction_t direction() { return m_direction; } |
| bool rtl() { return m_direction == HB_DIRECTION_RTL; } |
| hb_script_t script() { return m_script; } |
| @@ -135,25 +135,17 @@ private: |
| unsigned m_numGlyphs; |
| hb_direction_t m_direction; |
| hb_script_t m_script; |
| - Vector<HarfBuzzRunGlyphData, 256> m_glyphData; |
| - float m_width; |
| }; |
| float nextExpansionPerOpportunity(); |
| - // setPadding sets a number of pixels to be distributed across the TextRun. |
| - // WebKit uses this to justify text. |
| void setExpansion(float); |
| - |
| void setFontFeatures(); |
| bool createHarfBuzzRuns(); |
| bool createHarfBuzzRunsForSingleCharacter(); |
| - bool shapeHarfBuzzRuns(); |
| - bool fillGlyphBuffer(GlyphBuffer*); |
| - float fillGlyphBufferFromHarfBuzzRun(GlyphBuffer*, HarfBuzzRun*, float initialAdvance); |
| - float fillGlyphBufferForTextEmphasis(GlyphBuffer*, HarfBuzzRun*, float initialAdvance); |
| - void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*); |
| - float adjustSpacing(HarfBuzzRun*, size_t glyphIndex, unsigned currentCharacterIndex, float& offsetX, float& totalAdvance); |
| + bool shapeHarfBuzzRuns(ShapeResult*); |
| + void shapeResult(ShapeResult*, unsigned, HarfBuzzRun*, hb_buffer_t*); |
| + float adjustSpacing(ShapeResult::RunInfo*, size_t glyphIndex, unsigned currentCharacterIndex, float& offsetX, float& totalAdvance); |
| void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const SimpleFontData*, UScriptCode); |
| OwnPtr<UChar[]> m_normalizedBuffer; |
| @@ -165,13 +157,6 @@ private: |
| Vector<hb_feature_t, 4> m_features; |
| Vector<OwnPtr<HarfBuzzRun>, 16> m_harfBuzzRuns; |
| - |
| - int m_fromIndex; |
| - int m_toIndex; |
| - |
| - float m_totalWidth; |
| - |
| - friend struct CachedShapingResults; |
| }; |
| } // namespace blink |