Title: [200364] trunk/Source/WebCore
- Revision
- 200364
- Author
- [email protected]
- Date
- 2016-05-03 01:18:13 -0700 (Tue, 03 May 2016)
Log Message
[OpenType] OpenTypeVerticalData object should not be created if the font is not OpenType
https://bugs.webkit.org/show_bug.cgi?id=157172
Reviewed by Michael Catanzaro.
It's a bit weird that the object is always created and has an isOpenType() method to check whether it's an
OpenType or not. The caller is always deleting the object when it's not an OpenType, so it would be better if
the create method returned nullptr instead of creating the object when the font is not OpenType.
* platform/graphics/FontCache.cpp:
(WebCore::FontCache::verticalData): Do not use isOpenType(), we can now simply use the return value of OpenTypeVerticalData::create().
* platform/graphics/opentype/OpenTypeVerticalData.cpp:
(WebCore::loadHmtxTable): Moved to a helper funtion that returns false if the font is not OpenType.
(WebCore::OpenTypeVerticalData::create): Try to load the Hmtx table, and create the object if succeeded or
return nullptr otherwise.
(WebCore::OpenTypeVerticalData::OpenTypeVerticalData): Receive the advanceWidths as constructor parameter.
(WebCore::OpenTypeVerticalData::loadMetrics): Load all other tables.
* platform/graphics/opentype/OpenTypeVerticalData.h:
(WebCore::OpenTypeVerticalData::isOpenType): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (200363 => 200364)
--- trunk/Source/WebCore/ChangeLog 2016-05-03 07:19:07 UTC (rev 200363)
+++ trunk/Source/WebCore/ChangeLog 2016-05-03 08:18:13 UTC (rev 200364)
@@ -1,3 +1,25 @@
+2016-05-03 Carlos Garcia Campos <[email protected]>
+
+ [OpenType] OpenTypeVerticalData object should not be created if the font is not OpenType
+ https://bugs.webkit.org/show_bug.cgi?id=157172
+
+ Reviewed by Michael Catanzaro.
+
+ It's a bit weird that the object is always created and has an isOpenType() method to check whether it's an
+ OpenType or not. The caller is always deleting the object when it's not an OpenType, so it would be better if
+ the create method returned nullptr instead of creating the object when the font is not OpenType.
+
+ * platform/graphics/FontCache.cpp:
+ (WebCore::FontCache::verticalData): Do not use isOpenType(), we can now simply use the return value of OpenTypeVerticalData::create().
+ * platform/graphics/opentype/OpenTypeVerticalData.cpp:
+ (WebCore::loadHmtxTable): Moved to a helper funtion that returns false if the font is not OpenType.
+ (WebCore::OpenTypeVerticalData::create): Try to load the Hmtx table, and create the object if succeeded or
+ return nullptr otherwise.
+ (WebCore::OpenTypeVerticalData::OpenTypeVerticalData): Receive the advanceWidths as constructor parameter.
+ (WebCore::OpenTypeVerticalData::loadMetrics): Load all other tables.
+ * platform/graphics/opentype/OpenTypeVerticalData.h:
+ (WebCore::OpenTypeVerticalData::isOpenType): Deleted.
+
2016-05-02 Darin Adler <[email protected]>
Change IDL enumerations to be nested in their C++ class instead of at WebCore namespace level
Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (200363 => 200364)
--- trunk/Source/WebCore/platform/graphics/FontCache.cpp 2016-05-03 07:19:07 UTC (rev 200363)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp 2016-05-03 08:18:13 UTC (rev 200364)
@@ -317,11 +317,9 @@
RefPtr<OpenTypeVerticalData> FontCache::verticalData(const FontPlatformData& platformData)
{
- auto addResult = fontVerticalDataCache().add(platformData, nullptr);
- if (addResult.isNewEntry) {
- RefPtr<OpenTypeVerticalData> data = ""
- addResult.iterator->value = data->isOpenType() ? WTFMove(data) : nullptr;
- }
+ auto addResult = fontVerticalDataCache().ensure(platformData, [&platformData] {
+ return OpenTypeVerticalData::create(platformData);
+ });
return addResult.iterator->value;
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp (200363 => 200364)
--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp 2016-05-03 07:19:07 UTC (rev 200363)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp 2016-05-03 08:18:13 UTC (rev 200364)
@@ -379,39 +379,52 @@
} // namespace OpenType
-OpenTypeVerticalData::OpenTypeVerticalData(const FontPlatformData& platformData)
- : m_defaultVertOriginY(0)
+static bool loadHmtxTable(const FontPlatformData& platformData, Vector<uint16_t>& advanceWidths)
{
- loadMetrics(platformData);
- loadVerticalGlyphSubstitutions(platformData);
-}
-
-void OpenTypeVerticalData::loadMetrics(const FontPlatformData& platformData)
-{
- // Load hhea and hmtx to get x-component of vertical origins.
- // If these tables are missing, it's not an OpenType font.
RefPtr<SharedBuffer> buffer = platformData.openTypeTable(OpenType::HheaTag);
const OpenType::HheaTable* hhea = OpenType::validateTable<OpenType::HheaTable>(buffer);
if (!hhea)
- return;
+ return false;
uint16_t countHmtxEntries = hhea->numberOfHMetrics;
if (!countHmtxEntries) {
LOG_ERROR("Invalid numberOfHMetrics");
- return;
+ return false;
}
buffer = platformData.openTypeTable(OpenType::HmtxTag);
const OpenType::HmtxTable* hmtx = OpenType::validateTable<OpenType::HmtxTable>(buffer, countHmtxEntries);
if (!hmtx) {
LOG_ERROR("hhea exists but hmtx does not (or broken)");
- return;
+ return false;
}
- m_advanceWidths.resize(countHmtxEntries);
+
+ advanceWidths.resize(countHmtxEntries);
for (uint16_t i = 0; i < countHmtxEntries; ++i)
- m_advanceWidths[i] = hmtx->entries[i].advanceWidth;
+ advanceWidths[i] = hmtx->entries[i].advanceWidth;
+ return true;
+}
+RefPtr<OpenTypeVerticalData> OpenTypeVerticalData::create(const FontPlatformData& platformData)
+{
+ // Load hhea and hmtx to get x-component of vertical origins. If these tables are missing, it's not an OpenType font.
+ Vector<uint16_t> advanceWidths;
+ if (!loadHmtxTable(platformData, advanceWidths))
+ return nullptr;
+
+ return adoptRef(new OpenTypeVerticalData(platformData, WTFMove(advanceWidths)));
+}
+
+OpenTypeVerticalData::OpenTypeVerticalData(const FontPlatformData& platformData, Vector<uint16_t>&& advanceWidths)
+ : m_advanceWidths(WTFMove(advanceWidths))
+{
+ loadMetrics(platformData);
+ loadVerticalGlyphSubstitutions(platformData);
+}
+
+void OpenTypeVerticalData::loadMetrics(const FontPlatformData& platformData)
+{
// Load vhea first. This table is required for fonts that support vertical flow.
- buffer = platformData.openTypeTable(OpenType::VheaTag);
+ RefPtr<SharedBuffer> buffer = platformData.openTypeTable(OpenType::VheaTag);
const OpenType::VheaTable* vhea = OpenType::validateTable<OpenType::VheaTable>(buffer);
if (!vhea)
return;
Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h (200363 => 200364)
--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h 2016-05-03 07:19:07 UTC (rev 200363)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h 2016-05-03 08:18:13 UTC (rev 200364)
@@ -41,19 +41,15 @@
class OpenTypeVerticalData : public RefCounted<OpenTypeVerticalData> {
public:
- static PassRefPtr<OpenTypeVerticalData> create(const FontPlatformData& platformData)
- {
- return adoptRef(new OpenTypeVerticalData(platformData));
- }
+ static RefPtr<OpenTypeVerticalData> create(const FontPlatformData&);
- bool isOpenType() const { return !m_advanceWidths.isEmpty(); }
bool hasVerticalMetrics() const { return !m_advanceHeights.isEmpty(); }
float advanceHeight(const Font*, Glyph) const;
void getVerticalTranslationsForGlyphs(const Font*, const Glyph*, size_t, float* outXYArray) const;
void substituteWithVerticalGlyphs(const Font*, GlyphPage*) const;
private:
- explicit OpenTypeVerticalData(const FontPlatformData&);
+ explicit OpenTypeVerticalData(const FontPlatformData&, Vector<uint16_t>&& advanceWidths);
void loadMetrics(const FontPlatformData&);
void loadVerticalGlyphSubstitutions(const FontPlatformData&);
@@ -63,7 +59,7 @@
Vector<uint16_t> m_advanceWidths;
Vector<uint16_t> m_advanceHeights;
Vector<int16_t> m_topSideBearings;
- int16_t m_defaultVertOriginY;
+ int16_t m_defaultVertOriginY { 0 };
HashMap<Glyph, int16_t> m_vertOriginY;
};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes