- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gfx / font_fallback_win.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_GFX_FONT_FALLBACK_WIN_H_
6 #define UI_GFX_FONT_FALLBACK_WIN_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "ui/gfx/font.h"
12
13 namespace gfx {
14
15 // Internals of font_fallback_win.cc exposed for testing.
16 namespace internal {
17
18 // Parses comma separated SystemLink |entry|, per the format described here:
19 // http://msdn.microsoft.com/en-us/goglobal/bb688134.aspx
20 //
21 // Sets |filename| and |font_name| respectively. If a field is not present
22 // or could not be parsed, the corresponding parameter will be cleared.
23 void GFX_EXPORT ParseFontLinkEntry(const std::string& entry,
24                                   std::string* filename,
25                                   std::string* font_name);
26
27 // Parses a font |family| in the format "FamilyFoo & FamilyBar (TrueType)".
28 // Splits by '&' and strips off the trailing parenthesized expression.
29 void GFX_EXPORT ParseFontFamilyString(const std::string& family,
30                                      std::vector<std::string>* font_names);
31
32 }  // namespace internal
33
34 // Iterator over linked fallback fonts for a given font. The linked font chain
35 // comes from the Windows registry, but gets cached between uses.
36 class GFX_EXPORT LinkedFontsIterator {
37  public:
38   // Instantiates the iterator over the linked font chain for |font|. The first
39   // item will be |font| itself.
40   explicit LinkedFontsIterator(Font font);
41   virtual ~LinkedFontsIterator();
42
43   // Sets the font that would be returned by the next call to |NextFont()|,
44   // useful for inserting one-time entries into the iterator chain.
45   void SetNextFont(Font font);
46
47   // Gets the next font in the link chain, if available, and increments the
48   // iterator. Returns |true| on success or |false| if the iterator is past
49   // last item (in that case, the value of |font| should not be used). If
50   // |SetNextFont()| was called, returns the font set that way and clears it.
51   bool NextFont(Font* font);
52
53  protected:
54   // Retrieves the list of linked fonts. Protected and virtual so that it may
55   // be overridden by tests.
56   virtual const std::vector<Font>* GetLinkedFonts() const;
57
58  private:
59   // Original font whose linked fonts are being iterated over.
60   Font original_font_;
61
62   // Font that was set via |SetNextFont()|.
63   Font next_font_;
64
65   // Indicates whether |SetNextFont()| was called.
66   bool next_font_set_;
67
68   // The font most recently returned by |NextFont()|.
69   Font current_font_;
70
71   // List of linked fonts; weak pointer.
72   const std::vector<Font>* linked_fonts_;
73
74   // Index of the current entry in the |linked_fonts_| list.
75   size_t linked_font_index_;
76
77   DISALLOW_COPY_AND_ASSIGN(LinkedFontsIterator);
78 };
79
80 }  // namespace gfx
81
82 #endif  // UI_GFX_FONT_FALLBACK_WIN_H_