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.
5 #ifndef UI_GFX_FONT_FALLBACK_WIN_H_
6 #define UI_GFX_FONT_FALLBACK_WIN_H_
11 #include "ui/gfx/font.h"
12 #include "ui/gfx/font_fallback.h"
16 // Internals of font_fallback_win.cc exposed for testing.
19 // Parses comma separated SystemLink |entry|, per the format described here:
20 // http://msdn.microsoft.com/en-us/goglobal/bb688134.aspx
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
);
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
);
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
{
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();
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
);
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
);
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;
58 // Original font whose linked fonts are being iterated over.
61 // Font that was set via |SetNextFont()|.
64 // Indicates whether |SetNextFont()| was called.
67 // The font most recently returned by |NextFont()|.
70 // List of linked fonts; weak pointer.
71 const std::vector
<Font
>* linked_fonts_
;
73 // Index of the current entry in the |linked_fonts_| list.
74 size_t linked_font_index_
;
76 DISALLOW_COPY_AND_ASSIGN(LinkedFontsIterator
);
79 } // namespace internal
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
,
91 #endif // UI_GFX_FONT_FALLBACK_WIN_H_