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