KHtml

css_webfont.h
1 /*
2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2007, 2008 Nikolas Zimmermann <[email protected]>
4  * Copyright (C) 2009 Germain Garand <[email protected]>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef css_webfont_h
29 #define css_webfont_h
30 
31 #include "dom/dom_string.h"
32 #include "misc/shared.h"
33 #include "misc/loader.h"
34 #include "css/css_valueimpl.h"
35 
36 #include <wtf/HashMap.h>
37 #include <wtf/RefPtr.h>
38 #include <wtf/HashSet.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefCounted.h>
41 #include <wtf/Vector.h>
42 
43 #include <QHash>
44 
45 namespace DOM
46 {
47 
48 class CSSFontFace;
49 class CSSFontFaceRuleImpl;
50 class CSSFontSelector;
51 class CSSSegmentedFontFace;
52 class DocumentImpl;
53 class DocLoader;
54 class FontDef;
55 
56 enum {
57  FontStyleNormalBit = 0,
58  FontStyleItalicBit,
59  FontVariantNormalBit,
60  FontVariantSmallCapsBit,
61  FontWeight100Bit,
62  FontWeight200Bit,
63  FontWeight300Bit,
64  FontWeight400Bit,
65  FontWeight500Bit,
66  FontWeight600Bit,
67  FontWeight700Bit,
68  FontWeight800Bit,
69  FontWeight900Bit,
70  FontTraitsMaskWidth
71 };
72 
73 enum FontTraitsMask {
74  FontStyleNormalMask = 1 << FontStyleNormalBit,
75  FontStyleItalicMask = 1 << FontStyleItalicBit,
76  FontStyleMask = FontStyleNormalMask | FontStyleItalicMask,
77 
78  FontVariantNormalMask = 1 << FontVariantNormalBit,
79  FontVariantSmallCapsMask = 1 << FontVariantSmallCapsBit,
80  FontVariantMask = FontVariantNormalMask | FontVariantSmallCapsMask,
81 
82  FontWeight100Mask = 1 << FontWeight100Bit,
83  FontWeight200Mask = 1 << FontWeight200Bit,
84  FontWeight300Mask = 1 << FontWeight300Bit,
85  FontWeight400Mask = 1 << FontWeight400Bit,
86  FontWeight500Mask = 1 << FontWeight500Bit,
87  FontWeight600Mask = 1 << FontWeight600Bit,
88  FontWeight700Mask = 1 << FontWeight700Bit,
89  FontWeight800Mask = 1 << FontWeight800Bit,
90  FontWeight900Mask = 1 << FontWeight900Bit,
91  FontWeightMask = FontWeight100Mask | FontWeight200Mask | FontWeight300Mask | FontWeight400Mask | FontWeight500Mask | FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask
92 };
93 
94 class CSSSegmentedFontFace : public khtml::Shared<CSSSegmentedFontFace>
95 {
96 public:
97  CSSSegmentedFontFace(CSSFontSelector *);
98  ~CSSSegmentedFontFace();
99 
100  bool isLoaded() const;
101  bool isValid() const;
102  CSSFontSelector *fontSelector() const
103  {
104  return m_fontSelector;
105  }
106 
107  void fontLoaded(CSSFontFace *);
108 
109  void appendFontFace(CSSFontFace);
110 
111 // FontData* getFontData(const FontDescription&);
112 
113 private:
114 
115 // void pruneTable();
116 
117  CSSFontSelector *m_fontSelector;
118 // HashMap<unsigned, SegmentedFontData*> m_fontDataTable;
119 // WTF::Vector<WTF::RefPtr<CSSFontFace>, 1> m_fontFaces;
120 };
121 
122 class CSSFontFaceSource : public khtml::CachedObjectClient
123 {
124 public:
125  CSSFontFaceSource(const DOMString &, bool distant = false);
126  virtual ~CSSFontFaceSource();
127 
128  bool isLoaded() const;
129  bool isValid() const;
130 
131  DOMString string() const
132  {
133  return m_string;
134  }
135 
136  void setFontFace(CSSFontFace *face)
137  {
138  m_face = face;
139  }
140 
141  void notifyFinished(khtml::CachedObject *finishedObj) override;
142  void refLoader();
143 
144 // SimpleFontData* getFontData(const FontDef&, bool syntheticBold, bool syntheticItalic, CSSFontSelector*);
145 // void pruneTable();
146 
147 #if 0
148  // ENABLE(SVG_FONTS)
149  SVGFontFaceElement *svgFontFaceElement() const
150  {
151  return m_svgFontFaceElement;
152  }
153  void setSVGFontFaceElement(SVGFontFaceElement *element)
154  {
155  m_svgFontFaceElement = element;
156  }
157 #endif
158 
159 private:
160  DOMString m_string; // URI for remote, built-in font name for local.
161  khtml::CachedFont *m_font; // For remote fonts, a pointer to our cached resource.
162  CSSFontFace *m_face; // Our owning font face.
163  int m_id; // Qt identifier for the Application font.
164  bool m_refed;
165  bool m_distant;
166 // HashMap<unsigned, SimpleFontData*> m_fontDataTable; // The hash key is composed of size synthetic styles.
167 
168 #if 0
169  // ENABLE(SVG_FONTS)
170  SVGFontFaceElement *m_svgFontFaceElement;
171  RefPtr<SVGFontElement> m_externalSVGFontElement;
172 #endif
173 };
174 
175 class CSSFontFace : public khtml::Shared<CSSFontFace>
176 {
177 public:
178  CSSFontFace(FontTraitsMask traitsMask, CSSFontSelector *fs)
179  : m_traitsMask(traitsMask), m_fontSelector(fs), m_refed(false), m_installed(false)
180  {
181  }
182  ~CSSFontFace();
183 
184  FontTraitsMask traitsMask() const
185  {
186  return m_traitsMask;
187  }
188 
189  /*
190  struct UnicodeRange;
191 
192  void addRange(UChar32 from, UChar32 to) { m_ranges.append(UnicodeRange(from, to)); }
193  const Vector<UnicodeRange>& ranges() const { return m_ranges; }
194  */
195  void addedToSegmentedFontFace(CSSSegmentedFontFace *);
196  void removedFromSegmentedFontFace(CSSSegmentedFontFace *);
197 
198  bool isLoaded() const;
199  bool isValid() const;
200 
201  void setInstalled();
202  bool installed() const;
203 
204  void addSource(CSSFontFaceSource *);
205 
206  void fontLoaded(CSSFontFaceSource *);
207  void addFamilyName(const DOMString &name)
208  {
209  m_names.append(name);
210  }
211  WTF::Vector<DOMString> familyNames() const
212  {
213  return m_names;
214  }
215  CSSFontSelector *fontSelector() const
216  {
217  return m_fontSelector;
218  }
219  void refLoaders(); // start loading all sources
220 
221 // SimpleFontData* getFontData(const FontDef&, bool syntheticBold, bool syntheticItalic);
222 
223  /*
224  struct UnicodeRange {
225  UnicodeRange(UChar32 from, UChar32 to)
226  : m_from(from)
227  , m_to(to)
228  {
229  }
230 
231  UChar32 from() const { return m_from; }
232  UChar32 to() const { return m_to; }
233 
234  private:
235  UChar32 m_from;
236  UChar32 m_to;
237  };
238  */
239 
240 private:
241  FontTraitsMask m_traitsMask;
242 // Vector<UnicodeRange> m_ranges;
243 // HashSet<CSSSegmentedFontFace*> m_segmentedFontFaces;
244  WTF::Vector<DOMString> m_names;
245  WTF::Vector<CSSFontFaceSource *> m_sources;
246  CSSFontSelector *m_fontSelector;
247  bool m_refed;
248  bool m_installed; // Successfully added into application font db
249 };
250 
251 class CSSFontSelector : public khtml::Shared<CSSFontSelector>
252 {
253 public:
254  CSSFontSelector(DocumentImpl *);
255  virtual ~CSSFontSelector();
256 
257 // virtual FontData* getFontData(const FontDef& fontDescription, const DOMString& familyName);
258  void requestFamilyName(const DOMString &familyName);
259  void clearDocument()
260  {
261  m_document = nullptr;
262  }
263  void addFontFaceRule(const CSSFontFaceRuleImpl *);
264  void fontLoaded();
265  virtual void fontCacheInvalidated();
266  bool isEmpty() const;
267  khtml::DocLoader *docLoader() const;
268 
269 private:
270 
271  DocumentImpl *m_document;
272 // HashMap<DOMString, Vector<RefPtr<CSSFontFace> >*, CaseFoldingHash> m_fontFaces;
273 // WTF::HashMap<DOMString, WTF::Vector<WTF::RefPtr<CSSFontFace> >*, CaseFoldingHash> m_locallyInstalledFontFaces;
274  QHash<DOMString, CSSFontFace *> m_locallyInstalledFontFaces;
275 // HashMap<DOMString, HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >*, CaseFoldingHash> m_fonts;
276 };
277 
278 } // namespace DOM
279 
280 #endif // css_webfont_h
a cached font
Definition: loader.h:493
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This library provides a full-featured HTML parser and widget.
bool isValid(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.