• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGGlyphMap.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Apple, Inc
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef SVGGlyphMap_h
21 #define SVGGlyphMap_h
22 
23 #if ENABLE(SVG_FONTS)
24 #include "SVGGlyphElement.h"
25 
26 namespace WTF
27 {
28  struct QCharHash
29  {
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;
33  };
34  template<> struct HashTraits<QChar> : public GenericHashTraits<QChar> {
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); }
41  };
42  template<> struct DefaultHash<QChar>
43  {
44  typedef QCharHash Hash;
45  };
46 }
47 
48 namespace WebCore {
49 
50  struct GlyphMapNode;
51 
52  typedef HashMap<UChar, RefPtr<GlyphMapNode> > GlyphMapLayer;
53 
54 
55  struct GlyphMapNode : public RefCounted<GlyphMapNode> {
56  private:
57  GlyphMapNode() { }
58  public:
59  static PassRefPtr<GlyphMapNode> create() { return adoptRef(new GlyphMapNode); }
60 
61  Vector<SVGGlyphIdentifier> glyphs;
62 
63  GlyphMapLayer children;
64  };
65 
66  class SVGGlyphMap {
67 
68  public:
69  SVGGlyphMap() : m_currentPriority(0) { }
70 
71  void add(const String& string, const SVGGlyphIdentifier& glyph)
72  {
73  size_t len = string.length();
74  GlyphMapLayer* currentLayer = &m_rootLayer;
75 
76  RefPtr<GlyphMapNode> node;
77  for (size_t i = 0; i < len; i++) {
78  UChar curChar = string[i];
79  node = currentLayer->get(curChar);
80  if (!node) {
81  node = GlyphMapNode::create();
82  currentLayer->set(curChar, node);
83  }
84  currentLayer = &node->children;
85  }
86 
87  if (node) {
88  node->glyphs.append(glyph);
89  node->glyphs.last().priority = m_currentPriority++;
90  node->glyphs.last().nameLength = len;
91  node->glyphs.last().isValid = true;
92  }
93  }
94 
95  static inline bool compareGlyphPriority(const SVGGlyphIdentifier& first, const SVGGlyphIdentifier& second)
96  {
97  return first.priority < second.priority;
98  }
99 
100  void get(const String& string, Vector<SVGGlyphIdentifier>& glyphs)
101  {
102  GlyphMapLayer* currentLayer = &m_rootLayer;
103 
104  for (size_t i = 0; i < string.length(); i++) {
105  UChar curChar = string[i];
106  RefPtr<GlyphMapNode> node = currentLayer->get(curChar);
107  if (!node)
108  break;
109  glyphs.append(node->glyphs);
110  currentLayer = &node->children;
111  }
112  std::sort(glyphs.begin(), glyphs.end(), compareGlyphPriority);
113  }
114 
115  void clear()
116  {
117  m_rootLayer.clear();
118  m_currentPriority = 0;
119  }
120 
121  private:
122  GlyphMapLayer m_rootLayer;
123  int m_currentPriority;
124  };
125 
126 }
127 
128 #endif // ENABLE(SVG_FONTS)
129 
130 
131 #endif //SVGGlyphMap_h
add
KGuiItem add()
clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
GenericHashTraits
SVGGlyphElement.h
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal