OLD | NEW |
| (Empty) |
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 #include "ui/gfx/font_fallback.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 // Internals of font_fallback_win.cc exposed for testing. | |
17 namespace internal { | |
18 | |
19 // Parses comma separated SystemLink |entry|, per the format described here: | |
20 // http://msdn.microsoft.com/en-us/goglobal/bb688134.aspx | |
21 // | |
22 // Sets |filename| and |font_name| respectively. If a field is not present | |
23 // or could not be parsed, the corresponding parameter will be cleared. | |
24 void GFX_EXPORT ParseFontLinkEntry(const std::string& entry, | |
25 std::string* filename, | |
26 std::string* font_name); | |
27 | |
28 // Parses a font |family| in the format "FamilyFoo & FamilyBar (TrueType)". | |
29 // Splits by '&' and strips off the trailing parenthesized expression. | |
30 void GFX_EXPORT ParseFontFamilyString(const std::string& family, | |
31 std::vector<std::string>* font_names); | |
32 | |
33 // Iterator over linked fallback fonts for a given font. The linked font chain | |
34 // comes from the Windows registry, but gets cached between uses. | |
35 class GFX_EXPORT LinkedFontsIterator { | |
36 public: | |
37 // Instantiates the iterator over the linked font chain for |font|. The first | |
38 // item will be |font| itself. | |
39 explicit LinkedFontsIterator(Font font); | |
40 virtual ~LinkedFontsIterator(); | |
41 | |
42 // Sets the font that would be returned by the next call to |NextFont()|, | |
43 // useful for inserting one-time entries into the iterator chain. | |
44 void SetNextFont(Font font); | |
45 | |
46 // Gets the next font in the link chain, if available, and increments the | |
47 // iterator. Returns |true| on success or |false| if the iterator is past | |
48 // last item (in that case, the value of |font| should not be used). If | |
49 // |SetNextFont()| was called, returns the font set that way and clears it. | |
50 bool NextFont(Font* font); | |
51 | |
52 protected: | |
53 // Retrieves the list of linked fonts. Protected and virtual so that it may | |
54 // be overridden by tests. | |
55 virtual const std::vector<Font>* GetLinkedFonts() const; | |
56 | |
57 private: | |
58 // Original font whose linked fonts are being iterated over. | |
59 Font original_font_; | |
60 | |
61 // Font that was set via |SetNextFont()|. | |
62 Font next_font_; | |
63 | |
64 // Indicates whether |SetNextFont()| was called. | |
65 bool next_font_set_; | |
66 | |
67 // The font most recently returned by |NextFont()|. | |
68 Font current_font_; | |
69 | |
70 // List of linked fonts; weak pointer. | |
71 const std::vector<Font>* linked_fonts_; | |
72 | |
73 // Index of the current entry in the |linked_fonts_| list. | |
74 size_t linked_font_index_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(LinkedFontsIterator); | |
77 }; | |
78 | |
79 } // namespace internal | |
80 | |
81 // Finds a fallback font to render the specified |text| with respect to an | |
82 // initial |font|. Returns the resulting font via out param |result|. Returns | |
83 // |true| if a fallback font was found. | |
84 bool GetUniscribeFallbackFont(const Font& font, | |
85 const wchar_t* text, | |
86 int text_length, | |
87 Font* result); | |
88 | |
89 } // namespace gfx | |
90 | |
91 #endif // UI_GFX_FONT_FALLBACK_WIN_H_ | |
OLD | NEW |