File: font_variant_alternates.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 (108 lines) | stat: -rw-r--r-- 3,822 bytes parent folder | download | duplicates (7)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_VARIANT_ALTERNATES_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_VARIANT_ALTERNATES_H_

#include <optional>

#include "base/dcheck_is_on.h"
#include "base/functional/function_ref.h"
#include "third_party/blink/renderer/platform/fonts/resolved_font_features.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"

namespace blink {

class PLATFORM_EXPORT FontVariantAlternates
    : public RefCounted<FontVariantAlternates> {
 public:
  static scoped_refptr<FontVariantAlternates> Create() {
    return base::AdoptRef(new FontVariantAlternates());
  }

  void SetStylistic(AtomicString);
  void SetHistoricalForms();
  void SetSwash(AtomicString);
  void SetOrnaments(AtomicString);
  void SetAnnotation(AtomicString);

  void SetStyleset(Vector<AtomicString>);
  void SetCharacterVariant(Vector<AtomicString>);

  const AtomicString* Stylistic() const {
    return stylistic_ ? &(*stylistic_) : nullptr;
  }
  bool HistoricalForms() const { return historical_forms_; }
  const AtomicString* Swash() const { return swash_ ? &(*swash_) : nullptr; }
  const AtomicString* Ornaments() const {
    return ornaments_ ? &(*ornaments_) : nullptr;
  }
  const AtomicString* Annotation() const {
    return annotation_ ? &(*annotation_) : nullptr;
  }

  const Vector<AtomicString>& Styleset() const { return styleset_; }
  const Vector<AtomicString>& CharacterVariant() const {
    return character_variant_;
  }

  using ResolverFunction =
      base::FunctionRef<Vector<uint32_t>(const AtomicString&)>;
  /* Resolves the internal feature configuration with aliases against resolution
   * functions to get the actual OpenType feature indices for each alias.
   * Produces a resolved copy on which it is possible to call
   * GetResolvedFontFeatures(). Can be called with empty resolution functions
   * for converting just the historical-forms flag to a resolved OpenType
   * feature. */
  scoped_refptr<FontVariantAlternates> Resolve(
      ResolverFunction resolve_stylistic,
      ResolverFunction resolve_styleset_,
      ResolverFunction resolve_character_variant,
      ResolverFunction resolve_swash,
      ResolverFunction resolve_ornaments,
      ResolverFunction resolve_annotation) const;

  const ResolvedFontFeatures& GetResolvedFontFeatures() const;

  unsigned GetHash() const;

  bool IsNormal() const;

  bool operator==(const FontVariantAlternates& other) const;
  bool operator!=(const FontVariantAlternates& other) const {
    return !(*this == other);
  }

 private:
  FontVariantAlternates();

  // RefCounted<> has a deleted copy constructor. Since we're inheriting
  // from it, we can't re-enable it and have to manually implement a
  // Clone() method for the case of making a changed copy in
  // CSSFontSelector.
  static scoped_refptr<FontVariantAlternates> Clone(
      const FontVariantAlternates& other);

  std::optional<AtomicString> stylistic_ = std::nullopt;
  std::optional<AtomicString> swash_ = std::nullopt;
  std::optional<AtomicString> ornaments_ = std::nullopt;
  std::optional<AtomicString> annotation_ = std::nullopt;

  Vector<AtomicString> styleset_;
  Vector<AtomicString> character_variant_;
  bool historical_forms_ = false;

  ResolvedFontFeatures resolved_features_;

#if DCHECK_IS_ON()
  bool is_resolved_ = false;
#endif
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_VARIANT_ALTERNATES_H_