diff options
-rw-r--r-- | third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp | 6 | ||||
-rw-r--r-- | third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp | 32 |
2 files changed, 22 insertions, 16 deletions
diff --git a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp index e740665..9dcf816 100644 --- a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp +++ b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp @@ -305,16 +305,16 @@ static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user const size_t tableSize = typeface->getTableSize(tag); if (!tableSize) { - return 0; + return nullptr; } char* buffer = reinterpret_cast<char*>(fastMalloc(tableSize)); if (!buffer) - return 0; + return nullptr; size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer); if (tableSize != actualSize) { fastFree(buffer); - return 0; + return nullptr; } return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_WRITABLE, buffer, fastFree); diff --git a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp index 8e08064..d1548e7 100644 --- a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp +++ b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp @@ -45,6 +45,7 @@ #include "wtf/MathExtras.h" #include "wtf/text/Unicode.h" +#include <algorithm> #include <list> #include <map> #include <string> @@ -231,7 +232,7 @@ static inline unsigned countGraphemesInCluster(const UChar* str, cursorPos = cursorPosIterator->next(); numGraphemes++; } - return numGraphemes < 0 ? 0 : numGraphemes; + return std::max(0, numGraphemes); } static inline void addEmphasisMark(GlyphBuffer* buffer, @@ -664,12 +665,17 @@ void HarfBuzzShaper::setExpansion(float padding) m_expansionPerOpportunity = 0; } +static inline hb_feature_t createFeature(uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint32_t value = 0) +{ + return { HB_TAG(c1, c2, c3, c4), value, 0 /* start */, static_cast<unsigned>(-1) /* end */ }; +} + void HarfBuzzShaper::setFontFeatures() { const FontDescription& description = m_font->fontDescription(); - static hb_feature_t noKern = { HB_TAG('k', 'e', 'r', 'n'), 0, 0, static_cast<unsigned>(-1) }; - static hb_feature_t noVkrn = { HB_TAG('v', 'k', 'r', 'n'), 0, 0, static_cast<unsigned>(-1) }; + static hb_feature_t noKern = createFeature('k', 'e', 'r', 'n'); + static hb_feature_t noVkrn = createFeature('v', 'k', 'r', 'n'); switch (description.kerning()) { case FontDescription::NormalKerning: // kern/vkrn are enabled by default @@ -681,8 +687,8 @@ void HarfBuzzShaper::setFontFeatures() break; } - static hb_feature_t noClig = { HB_TAG('c', 'l', 'i', 'g'), 0, 0, static_cast<unsigned>(-1) }; - static hb_feature_t noLiga = { HB_TAG('l', 'i', 'g', 'a'), 0, 0, static_cast<unsigned>(-1) }; + static hb_feature_t noClig = createFeature('c', 'l', 'i', 'g'); + static hb_feature_t noLiga = createFeature('l', 'i', 'g', 'a'); switch (description.commonLigaturesState()) { case FontDescription::DisabledLigaturesState: m_features.append(noLiga); @@ -694,7 +700,7 @@ void HarfBuzzShaper::setFontFeatures() case FontDescription::NormalLigaturesState: break; } - static hb_feature_t dlig = { HB_TAG('d', 'l', 'i', 'g'), 1, 0, static_cast<unsigned>(-1) }; + static hb_feature_t dlig = createFeature('d', 'l', 'i', 'g', 1); switch (description.discretionaryLigaturesState()) { case FontDescription::DisabledLigaturesState: // dlig is off by default @@ -705,7 +711,7 @@ void HarfBuzzShaper::setFontFeatures() case FontDescription::NormalLigaturesState: break; } - static hb_feature_t hlig = { HB_TAG('h', 'l', 'i', 'g'), 1, 0, static_cast<unsigned>(-1) }; + static hb_feature_t hlig = createFeature('h', 'l', 'i', 'g', 1); switch (description.historicalLigaturesState()) { case FontDescription::DisabledLigaturesState: // hlig is off by default @@ -716,7 +722,7 @@ void HarfBuzzShaper::setFontFeatures() case FontDescription::NormalLigaturesState: break; } - static hb_feature_t noCalt = { HB_TAG('c', 'a', 'l', 't'), 0, 0, static_cast<unsigned>(-1) }; + static hb_feature_t noCalt = createFeature('c', 'a', 'l', 't'); switch (description.contextualLigaturesState()) { case FontDescription::DisabledLigaturesState: m_features.append(noCalt); @@ -728,9 +734,9 @@ void HarfBuzzShaper::setFontFeatures() break; } - static hb_feature_t hwid = { HB_TAG('h', 'w', 'i', 'd'), 1, 0, static_cast<unsigned>(-1) }; - static hb_feature_t twid = { HB_TAG('t', 'w', 'i', 'd'), 1, 0, static_cast<unsigned>(-1) }; - static hb_feature_t qwid = { HB_TAG('q', 'w', 'i', 'd'), 1, 0, static_cast<unsigned>(-1) }; + static hb_feature_t hwid = createFeature('h', 'w', 'i', 'd', 1); + static hb_feature_t twid = createFeature('t', 'w', 'i', 'd', 1); + static hb_feature_t qwid = createFeature('q', 'w', 'i', 'd', 1); switch (description.widthVariant()) { case HalfWidth: m_features.append(hwid); @@ -1087,7 +1093,7 @@ void HarfBuzzShaper::shapeResult(ShapeResult* result, unsigned index, hb_glyph_info_t* glyphInfos = hb_buffer_get_glyph_infos(harfBuzzBuffer, 0); hb_glyph_position_t* glyphPositions = hb_buffer_get_glyph_positions(harfBuzzBuffer, 0); - float totalAdvance = 0; + float totalAdvance = 0.0f; FloatPoint glyphOrigin; float offsetX, offsetY; float* directionOffset = m_font->fontDescription().isVerticalAnyUpright() ? &offsetY : &offsetX; @@ -1134,7 +1140,7 @@ void HarfBuzzShaper::shapeResult(ShapeResult* result, unsigned index, glyphOrigin += FloatSize(advance + offsetX, offsetY); } - run->m_width = totalAdvance > 0.0 ? totalAdvance : 0.0; + run->m_width = std::max(0.0f, totalAdvance); result->m_width += run->m_width; result->m_numGlyphs += numGlyphs; result->m_runs[index] = run.release(); |