| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/unicode/CharacterNames.h" | 41 #include "wtf/unicode/CharacterNames.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 | 43 |
| 44 #include <unicode/uscript.h> | 44 #include <unicode/uscript.h> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 class Font; | 48 class Font; |
| 49 class GlyphBuffer; | 49 class GlyphBufferWithOffsets; |
| 50 class SimpleFontData; | 50 class SimpleFontData; |
| 51 | 51 |
| 52 class HarfBuzzShaper FINAL { | 52 class HarfBuzzShaper FINAL { |
| 53 public: | 53 public: |
| 54 enum ForTextEmphasisOrNot { | 54 enum ForTextEmphasisOrNot { |
| 55 NotForTextEmphasis, | 55 NotForTextEmphasis, |
| 56 ForTextEmphasis | 56 ForTextEmphasis |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 HarfBuzzShaper(const Font*, const TextRun&, ForTextEmphasisOrNot = NotForTex
tEmphasis, HashSet<const SimpleFontData*>* fallbackFonts = 0); | 59 HarfBuzzShaper(const Font*, const TextRun&, ForTextEmphasisOrNot = NotForTex
tEmphasis, HashSet<const SimpleFontData*>* fallbackFonts = 0); |
| 60 | 60 |
| 61 void setDrawRange(int from, int to); | 61 void setDrawRange(int from, int to); |
| 62 bool shape(GlyphBuffer* = 0); | 62 bool shape(GlyphBuffer* = 0); |
| 63 FloatPoint adjustStartPoint(const FloatPoint&); | |
| 64 float totalWidth() { return m_totalWidth; } | 63 float totalWidth() { return m_totalWidth; } |
| 65 int offsetForPosition(float targetX); | 64 int offsetForPosition(float targetX); |
| 66 FloatRect selectionRect(const FloatPoint&, int height, int from, int to); | 65 FloatRect selectionRect(const FloatPoint&, int height, int from, int to); |
| 67 FloatBoxExtent glyphBoundingBox() const { return m_glyphBoundingBox; } | 66 FloatBoxExtent glyphBoundingBox() const { return m_glyphBoundingBox; } |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 class HarfBuzzRun { | 69 class HarfBuzzRun { |
| 71 public: | 70 public: |
| 72 HarfBuzzRun(const HarfBuzzRun&); | 71 HarfBuzzRun(const HarfBuzzRun&); |
| 73 ~HarfBuzzRun(); | 72 ~HarfBuzzRun(); |
| 74 | 73 |
| 75 static PassOwnPtr<HarfBuzzRun> create(const SimpleFontData* fontData, un
signed startIndex, unsigned numCharacters, hb_direction_t direction, hb_script_t
script) | 74 static PassOwnPtr<HarfBuzzRun> create(const SimpleFontData* fontData, un
signed startIndex, unsigned numCharacters, hb_direction_t direction, hb_script_t
script) |
| 76 { | 75 { |
| 77 return adoptPtr(new HarfBuzzRun(fontData, startIndex, numCharacters,
direction, script)); | 76 return adoptPtr(new HarfBuzzRun(fontData, startIndex, numCharacters,
direction, script)); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void applyShapeResult(hb_buffer_t*); | 79 void applyShapeResult(hb_buffer_t*); |
| 81 void setGlyphAndPositions(unsigned index, uint16_t glyphId, float advanc
e, float offsetX, float offsetY); | 80 void setGlyphAndPositions(unsigned index, uint16_t glyphId, float advanc
e, float offsetX, float offsetY); |
| 82 void setWidth(float width) { m_width = width; } | 81 void setWidth(float width) { m_width = width; } |
| 83 | 82 |
| 84 int characterIndexForXPosition(float targetX); | 83 int characterIndexForXPosition(float targetX); |
| 85 float xPositionForOffset(unsigned offset); | 84 float xPositionForOffset(unsigned offset); |
| 86 | 85 |
| 87 const SimpleFontData* fontData() { return m_fontData; } | 86 const SimpleFontData* fontData() { return m_fontData; } |
| 88 unsigned startIndex() const { return m_startIndex; } | 87 unsigned startIndex() const { return m_startIndex; } |
| 89 unsigned numCharacters() const { return m_numCharacters; } | 88 unsigned numCharacters() const { return m_numCharacters; } |
| 90 unsigned numGlyphs() const { return m_numGlyphs; } | 89 unsigned numGlyphs() const { return m_numGlyphs; } |
| 91 uint16_t* glyphs() { return &m_glyphs[0]; } | 90 uint16_t* glyphs() { return &m_glyphs[0]; } |
| 92 float* advances() { return &m_advances[0]; } | 91 float* advances() { return &m_advances[0]; } |
| 93 FloatPoint* offsets() { return &m_offsets[0]; } | 92 FloatSize* offsets() { return &m_offsets[0]; } |
| 94 bool hasGlyphToCharacterIndexes() const | 93 bool hasGlyphToCharacterIndexes() const |
| 95 { | 94 { |
| 96 return m_glyphToCharacterIndexes.size() > 0; | 95 return m_glyphToCharacterIndexes.size() > 0; |
| 97 } | 96 } |
| 98 uint16_t* glyphToCharacterIndexes() | 97 uint16_t* glyphToCharacterIndexes() |
| 99 { | 98 { |
| 100 return &m_glyphToCharacterIndexes[0]; | 99 return &m_glyphToCharacterIndexes[0]; |
| 101 } | 100 } |
| 102 float width() { return m_width; } | 101 float width() { return m_width; } |
| 103 hb_direction_t direction() { return m_direction; } | 102 hb_direction_t direction() { return m_direction; } |
| 104 bool rtl() { return m_direction == HB_DIRECTION_RTL; } | 103 bool rtl() { return m_direction == HB_DIRECTION_RTL; } |
| 105 hb_script_t script() { return m_script; } | 104 hb_script_t script() { return m_script; } |
| 106 | 105 |
| 107 private: | 106 private: |
| 108 HarfBuzzRun(const SimpleFontData*, unsigned startIndex, unsigned numChar
acters, hb_direction_t, hb_script_t); | 107 HarfBuzzRun(const SimpleFontData*, unsigned startIndex, unsigned numChar
acters, hb_direction_t, hb_script_t); |
| 109 | 108 |
| 110 const SimpleFontData* m_fontData; | 109 const SimpleFontData* m_fontData; |
| 111 unsigned m_startIndex; | 110 unsigned m_startIndex; |
| 112 size_t m_numCharacters; | 111 size_t m_numCharacters; |
| 113 unsigned m_numGlyphs; | 112 unsigned m_numGlyphs; |
| 114 hb_direction_t m_direction; | 113 hb_direction_t m_direction; |
| 115 hb_script_t m_script; | 114 hb_script_t m_script; |
| 116 Vector<uint16_t, 256> m_glyphs; | 115 Vector<uint16_t, 256> m_glyphs; |
| 117 Vector<float, 256> m_advances; | 116 Vector<float, 256> m_advances; |
| 118 Vector<uint16_t, 256> m_glyphToCharacterIndexes; | 117 Vector<uint16_t, 256> m_glyphToCharacterIndexes; |
| 119 Vector<FloatPoint, 256> m_offsets; | 118 Vector<FloatSize, 256> m_offsets; |
| 120 float m_width; | 119 float m_width; |
| 121 }; | 120 }; |
| 122 | 121 |
| 123 int determineWordBreakSpacing(); | 122 int determineWordBreakSpacing(); |
| 124 // setPadding sets a number of pixels to be distributed across the TextRun. | 123 // setPadding sets a number of pixels to be distributed across the TextRun. |
| 125 // WebKit uses this to justify text. | 124 // WebKit uses this to justify text. |
| 126 void setPadding(int); | 125 void setPadding(int); |
| 127 | 126 |
| 128 void setFontFeatures(); | 127 void setFontFeatures(); |
| 129 | 128 |
| 130 bool createHarfBuzzRuns(); | 129 bool createHarfBuzzRuns(); |
| 131 bool shapeHarfBuzzRuns(); | 130 bool shapeHarfBuzzRuns(); |
| 132 bool fillGlyphBuffer(GlyphBuffer*); | 131 bool fillGlyphBuffer(GlyphBuffer*); |
| 133 void fillGlyphBufferFromHarfBuzzRun(GlyphBuffer*, HarfBuzzRun*, FloatPoint&
firstOffsetOfNextRun); | 132 void fillGlyphBufferFromHarfBuzzRun(GlyphBufferWithOffsets*, HarfBuzzRun*); |
| 134 void fillGlyphBufferForTextEmphasis(GlyphBuffer*, HarfBuzzRun* currentRun); | 133 void fillGlyphBufferForTextEmphasis(GlyphBuffer*, HarfBuzzRun* currentRun); |
| 135 void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*); | 134 void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*); |
| 136 void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const Si
mpleFontData*, UScriptCode); | 135 void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const Si
mpleFontData*, UScriptCode); |
| 137 | 136 |
| 138 const Font* m_font; | 137 const Font* m_font; |
| 139 OwnPtr<UChar[]> m_normalizedBuffer; | 138 OwnPtr<UChar[]> m_normalizedBuffer; |
| 140 unsigned m_normalizedBufferLength; | 139 unsigned m_normalizedBufferLength; |
| 141 const TextRun& m_run; | 140 const TextRun& m_run; |
| 142 | 141 |
| 143 float m_wordSpacingAdjustment; // Delta adjustment (pixels) for each word br
eak. | 142 float m_wordSpacingAdjustment; // Delta adjustment (pixels) for each word br
eak. |
| 144 float m_padding; // Pixels to be distributed over the line at word breaks. | 143 float m_padding; // Pixels to be distributed over the line at word breaks. |
| 145 float m_padPerWordBreak; // Pixels to be added to each word break. | 144 float m_padPerWordBreak; // Pixels to be added to each word break. |
| 146 float m_padError; // m_padPerWordBreak might have a fractional component. Si
nce we only add a whole number of padding pixels at each word break we accumulat
e error. This is the number of pixels that we are behind so far. | 145 float m_padError; // m_padPerWordBreak might have a fractional component. Si
nce we only add a whole number of padding pixels at each word break we accumulat
e error. This is the number of pixels that we are behind so far. |
| 147 float m_letterSpacing; // Pixels to be added after each glyph. | 146 float m_letterSpacing; // Pixels to be added after each glyph. |
| 148 | 147 |
| 149 Vector<hb_feature_t, 4> m_features; | 148 Vector<hb_feature_t, 4> m_features; |
| 150 Vector<OwnPtr<HarfBuzzRun>, 16> m_harfBuzzRuns; | 149 Vector<OwnPtr<HarfBuzzRun>, 16> m_harfBuzzRuns; |
| 151 | 150 |
| 152 FloatPoint m_startOffset; | |
| 153 | |
| 154 int m_fromIndex; | 151 int m_fromIndex; |
| 155 int m_toIndex; | 152 int m_toIndex; |
| 156 | 153 |
| 157 ForTextEmphasisOrNot m_forTextEmphasis; | 154 ForTextEmphasisOrNot m_forTextEmphasis; |
| 158 | 155 |
| 159 float m_totalWidth; | 156 float m_totalWidth; |
| 160 FloatBoxExtent m_glyphBoundingBox; | 157 FloatBoxExtent m_glyphBoundingBox; |
| 161 HashSet<const SimpleFontData*>* m_fallbackFonts; | 158 HashSet<const SimpleFontData*>* m_fallbackFonts; |
| 162 | 159 |
| 163 friend struct CachedShapingResults; | 160 friend struct CachedShapingResults; |
| 164 }; | 161 }; |
| 165 | 162 |
| 166 } // namespace blink | 163 } // namespace blink |
| 167 | 164 |
| 168 #endif // HarfBuzzShaper_h | 165 #endif // HarfBuzzShaper_h |
| OLD | NEW |