30 static unsigned hash(
const QChar& c) {
return c.unicode(); }
31 static bool equal(
const QChar& a,
const QChar& b) {
return a == b; }
32 static const bool safeToCompareToEmptyOrDeleted =
false;
35 static const bool emptyValueIsZero =
true;
36 static const bool needsDestruction =
false;
37 static const bool needsRef =
false;
38 static QChar deletedValue() {
return QChar(-1); }
39 static bool isDeletedValue(
const QChar&) {
return false; }
40 static QChar constructDeletedValue(QChar*) {
return QChar(-1); }
42 template<>
struct DefaultHash<QChar>
44 typedef QCharHash Hash;
52 typedef HashMap<UChar, RefPtr<GlyphMapNode> > GlyphMapLayer;
55 struct GlyphMapNode :
public RefCounted<GlyphMapNode> {
59 static PassRefPtr<GlyphMapNode>
create() {
return adoptRef(
new GlyphMapNode); }
61 Vector<SVGGlyphIdentifier> glyphs;
63 GlyphMapLayer children;
69 SVGGlyphMap() : m_currentPriority(0) { }
71 void add(
const String&
string,
const SVGGlyphIdentifier& glyph)
73 size_t len =
string.length();
74 GlyphMapLayer* currentLayer = &m_rootLayer;
76 RefPtr<GlyphMapNode> node;
77 for (
size_t i = 0; i < len; i++) {
78 UChar curChar =
string[i];
79 node = currentLayer->get(curChar);
81 node = GlyphMapNode::create();
82 currentLayer->set(curChar, node);
84 currentLayer = &node->children;
88 node->glyphs.append(glyph);
89 node->glyphs.last().priority = m_currentPriority++;
90 node->glyphs.last().nameLength = len;
91 node->glyphs.last().isValid =
true;
95 static inline bool compareGlyphPriority(
const SVGGlyphIdentifier& first,
const SVGGlyphIdentifier& second)
97 return first.priority < second.priority;
100 void get(
const String& string, Vector<SVGGlyphIdentifier>& glyphs)
102 GlyphMapLayer* currentLayer = &m_rootLayer;
104 for (
size_t i = 0; i <
string.length(); i++) {
105 UChar curChar =
string[i];
106 RefPtr<GlyphMapNode> node = currentLayer->get(curChar);
109 glyphs.append(node->glyphs);
110 currentLayer = &node->children;
112 std::sort(glyphs.begin(), glyphs.end(), compareGlyphPriority);
118 m_currentPriority = 0;
122 GlyphMapLayer m_rootLayer;
123 int m_currentPriority;
128 #endif // ENABLE(SVG_FONTS)
131 #endif //SVGGlyphMap_h
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)