File: font_list_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,440 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_FONT_LIST_IMPL_H_
#define UI_GFX_FONT_LIST_IMPL_H_

#include <string>
#include <vector>

#include "base/memory/ref_counted.h"
#include "ui/gfx/font.h"

namespace gfx {

// FontListImpl is designed to provide the implementation of FontList and
// intended to be used only from FontList.  You must not use this class
// directly.
//
// FontListImpl represents a list of fonts either in the form of Font vector or
// in the form of a string representing font names, styles, and size.
//
// FontListImpl could be initialized either way without conversion to the other
// form. The conversion to the other form is done only when asked to get the
// other form.
//
// For the format of font description string, see font_list.h for details.
class FontListImpl : public base::RefCounted<FontListImpl> {
 public:
  // Creates a font list from a string representing font names, styles, and
  // size.
  explicit FontListImpl(const std::string& font_description_string);

  // Creates a font list from font names, styles, size and weight.
  FontListImpl(const std::vector<std::string>& font_names,
               int font_style,
               int font_size,
               Font::Weight font_weight);

  // Creates a font list from a Font vector.
  // All fonts in this vector should have the same style and size.
  explicit FontListImpl(const std::vector<Font>& fonts);

  // Creates a font list from a Font.
  explicit FontListImpl(const Font& font);

  // Returns a new FontListImpl with the same font names but resized and the
  // given style and weight. |size_delta| is the size in pixels to add to the
  // current font size. |font_style| specifies the new style, which is a
  // bitmask of the values: Font::ITALIC and Font::UNDERLINE.
  FontListImpl* Derive(int size_delta,
                       int font_style,
                       Font::Weight weight) const;

  // Returns the height of this font list, which is max(ascent) + max(descent)
  // for all the fonts in the font list.
  int GetHeight() const;

  // Returns the baseline of this font list, which is max(baseline) for all the
  // fonts in the font list.
  int GetBaseline() const;

  // Returns the cap height of this font list.
  // Currently returns the cap height of the primary font.
  int GetCapHeight() const;

  // Returns the expected number of horizontal pixels needed to display the
  // specified length of characters. Call GetStringWidth() to retrieve the
  // actual number.
  int GetExpectedTextWidth(int length) const;

  // Returns the |Font::FontStyle| style flags for this font list.
  int GetFontStyle() const;

  // Returns the font size in pixels.
  int GetFontSize() const;

  // Returns the font weight.
  Font::Weight GetFontWeight() const;

  // Returns the Font vector.
  const std::vector<Font>& GetFonts() const;

  // Returns the first font in the list.
  const Font& GetPrimaryFont() const;

 private:
  friend class base::RefCounted<FontListImpl>;

  ~FontListImpl();

  // Extracts common font height and baseline into |common_height_| and
  // |common_baseline_|.
  void CacheCommonFontHeightAndBaseline() const;

  // Extracts font style and size into |font_style_| and |font_size_|.
  void CacheFontStyleAndSize() const;

  // A vector of Font. If FontListImpl is constructed with font description
  // string, |fonts_| is not initialized during construction. Instead, it is
  // computed lazily when user asked to get the font vector.
  mutable std::vector<Font> fonts_;

  // A string representing font names, styles, and sizes.
  // Please refer to the comments before class declaration for details on string
  // format.
  // If FontListImpl is constructed with a vector of font,
  // |font_description_string_| is not initialized during construction. Instead,
  // it is computed lazily when user asked to get the font description string.
  //
  // TODO(derat): Remove laziness so that this can be removed.
  mutable std::string font_description_string_;

  // The cached common height and baseline of the fonts in the font list.
  mutable int common_height_;
  mutable int common_baseline_;

  // Cached font style and size.
  mutable int font_style_;
  mutable int font_size_;
  mutable Font::Weight font_weight_;
};

}  // namespace gfx

#endif  // UI_GFX_FONT_LIST_IMPL_H_