blob: 7b5dec9e1d50ad24149e3545ca7a71410ce928bb [file] [log] [blame]
[email protected]76ac8d92012-09-07 20:12:571// 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
avic89eb8d42015-12-23 08:08:188#include <stddef.h>
9
[email protected]76ac8d92012-09-07 20:12:5710#include <string>
11#include <vector>
12
avic89eb8d42015-12-23 08:08:1813#include "base/macros.h"
[email protected]76ac8d92012-09-07 20:12:5714#include "ui/gfx/font.h"
[email protected]8c17e13d2014-07-19 03:01:3915#include "ui/gfx/font_fallback.h"
[email protected]76ac8d92012-09-07 20:12:5716
17namespace gfx {
18
19// Internals of font_fallback_win.cc exposed for testing.
20namespace 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]4ffa7892013-09-27 16:56:0627void GFX_EXPORT ParseFontLinkEntry(const std::string& entry,
[email protected]76ac8d92012-09-07 20:12:5728 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]4ffa7892013-09-27 16:56:0633void GFX_EXPORT ParseFontFamilyString(const std::string& family,
[email protected]76ac8d92012-09-07 20:12:5734 std::vector<std::string>* font_names);
35
[email protected]76ac8d92012-09-07 20:12:5736// 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]4ffa7892013-09-27 16:56:0638class GFX_EXPORT LinkedFontsIterator {
[email protected]76ac8d92012-09-07 20:12:5739 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]8c17e13d2014-07-19 03:01:3982} // 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.
kulshine521a202016-07-06 21:56:2787bool GFX_EXPORT GetFallbackFont(const Font& font,
88 const wchar_t* text,
89 int text_length,
90 Font* result);
[email protected]8c17e13d2014-07-19 03:01:3991
[email protected]76ac8d92012-09-07 20:12:5792} // namespace gfx
93
94#endif // UI_GFX_FONT_FALLBACK_WIN_H_