Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1689)

Unified Diff: Source/core/svg/SVGGlyphMap.h

Issue 181443002: Use glyph-ids for lookups of SVG font kerning-pairs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Vector<...>::append -> Vector<...>::appendVector. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGFontElement.cpp ('k') | Source/platform/fonts/Font.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGGlyphMap.h
diff --git a/Source/core/svg/SVGGlyphMap.h b/Source/core/svg/SVGGlyphMap.h
index 8e20f0644ca99495c52a663c0d664ab0c063bafb..d46489cfd722eeb4238e3d77ac5e67a8893ea63e 100644
--- a/Source/core/svg/SVGGlyphMap.h
+++ b/Source/core/svg/SVGGlyphMap.h
@@ -21,6 +21,7 @@
#define SVGGlyphMap_h
#if ENABLE(SVG_FONTS)
+#include "core/svg/SVGParserUtilities.h"
#include "platform/fonts/Latin1TextIterator.h"
#include "platform/fonts/SVGGlyph.h"
#include "platform/text/SurrogatePairAwareTextIterator.h"
@@ -49,16 +50,16 @@ class SVGGlyphMap {
public:
SVGGlyphMap() : m_currentPriority(0) { }
- void addGlyph(const String& glyphName, const String& unicodeString, SVGGlyph glyph)
+ void addGlyph(const String& glyphIdentifier, const String& unicodeString, SVGGlyph glyph)
{
- ASSERT(!glyphName.isEmpty() || !unicodeString.isEmpty());
+ ASSERT(!glyphIdentifier.isEmpty() || !unicodeString.isEmpty());
- bool hasGlyphName = !glyphName.isEmpty();
+ bool hasGlyphIdentifier = !glyphIdentifier.isEmpty();
if (unicodeString.isEmpty()) {
- // Register named glyph in the named glyph map and in the glyph table.
- ASSERT(hasGlyphName);
+ // Register glyphs with 'id's in the id glyph map and in the glyph table.
+ ASSERT(hasGlyphIdentifier);
appendToGlyphTable(glyph);
- m_namedGlyphs.add(glyphName, glyph.tableEntry);
+ m_idGlyphs.add(glyphIdentifier, glyph.tableEntry);
return;
}
@@ -83,8 +84,10 @@ public:
// If the glyph is named, also add it to the named glyph name, and to the glyph table in both cases.
appendToGlyphTable(lastGlyph);
- if (hasGlyphName)
- m_namedGlyphs.add(glyphName, lastGlyph.tableEntry);
+ if (!lastGlyph.glyphName.isEmpty())
+ m_namedGlyphs.add(lastGlyph.glyphName, lastGlyph.tableEntry);
+ if (hasGlyphIdentifier)
+ m_idGlyphs.add(glyphIdentifier, lastGlyph.tableEntry);
}
void appendToGlyphTable(SVGGlyph& glyph)
@@ -120,13 +123,48 @@ public:
std::sort(glyphs.begin(), glyphs.end(), compareGlyphPriority);
}
+ void collectGlyphsForStringExact(const String& string, Vector<SVGGlyph>& glyphs) const
+ {
+ unsigned length = string.length();
+
+ if (!length)
+ return;
+
+ RefPtr<GlyphMapNode> node;
+ if (string.is8Bit()) {
+ Latin1TextIterator textIterator(string.characters8(), 0, length, length);
+ node = findNode(textIterator);
+ } else {
+ SurrogatePairAwareTextIterator textIterator(string.characters16(), 0, length, length);
+ node = findNode(textIterator);
+ }
+
+ if (node)
+ glyphs.appendVector(node->glyphs);
+ }
+
+ void collectGlyphsForUnicodeRange(const UnicodeRange& unicodeRange, Vector<SVGGlyph>& glyphs) const
+ {
+ for (unsigned character = unicodeRange.first; character <= unicodeRange.second; ++character) {
+ if (RefPtr<GlyphMapNode> node = m_rootLayer.get(character))
+ glyphs.appendVector(node->glyphs);
+ }
+ }
+
void clear()
{
m_rootLayer.clear();
m_glyphTable.clear();
+ m_idGlyphs.clear();
+ m_namedGlyphs.clear();
m_currentPriority = 0;
}
+ void dropNamedGlyphMap()
+ {
+ m_namedGlyphs.clear();
+ }
+
const SVGGlyph& svgGlyphForGlyph(Glyph glyph) const
{
if (!glyph || glyph > m_glyphTable.size()) {
@@ -136,6 +174,11 @@ public:
return m_glyphTable[glyph - 1];
}
+ const SVGGlyph& glyphIdentifierForAltGlyphReference(const String& glyphIdentifier) const
+ {
+ return svgGlyphForGlyph(m_idGlyphs.get(glyphIdentifier));
+ }
+
const SVGGlyph& glyphIdentifierForGlyphName(const String& glyphName) const
{
return svgGlyphForGlyph(m_namedGlyphs.get(glyphName));
@@ -164,6 +207,25 @@ private:
}
template<typename Iterator>
+ PassRefPtr<GlyphMapNode> findNode(Iterator& textIterator) const
+ {
+ const GlyphMapLayer* currentLayer = &m_rootLayer;
+
+ RefPtr<GlyphMapNode> node;
+ UChar32 character = 0;
+ unsigned clusterLength = 0;
+ while (textIterator.consume(character, clusterLength)) {
+ node = currentLayer->get(character);
+ if (!node)
+ break;
+ currentLayer = &node->children;
+ textIterator.advance(clusterLength);
+ }
+
+ return node.release();
+ }
+
+ template<typename Iterator>
void collectGlyphsForIterator(Iterator& textIterator, Vector<SVGGlyph>& glyphs)
{
GlyphMapLayer* currentLayer = &m_rootLayer;
@@ -183,6 +245,7 @@ private:
GlyphMapLayer m_rootLayer;
Vector<SVGGlyph> m_glyphTable;
HashMap<String, Glyph> m_namedGlyphs;
+ HashMap<String, Glyph> m_idGlyphs;
int m_currentPriority;
};
« no previous file with comments | « Source/core/svg/SVGFontElement.cpp ('k') | Source/platform/fonts/Font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698