File: layout_locale.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 (115 lines) | stat: -rw-r--r-- 4,161 bytes parent folder | download | duplicates (6)
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
// Copyright 2016 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_TEXT_LAYOUT_LOCALE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_LAYOUT_LOCALE_H_

#include "base/memory/raw_ptr.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/text/hyphenation.h"
#include "third_party/blink/renderer/platform/text/quotes_data.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/case_map.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"

#include <unicode/uscript.h>

struct hb_language_impl_t;

namespace blink {

// A Unicode Line Break Style Identifier (key "lb".)
// https://www.unicode.org/reports/tr35/#UnicodeLineBreakStyleIdentifier
enum class LineBreakStrictness : uint8_t { kDefault, kNormal, kStrict, kLoose };

class PLATFORM_EXPORT LayoutLocale : public RefCounted<LayoutLocale> {
  USING_FAST_MALLOC(LayoutLocale);

 public:
  static const LayoutLocale* Get(const AtomicString& locale);
  static const LayoutLocale& GetDefault();
  static const LayoutLocale& GetSystem();
  static const LayoutLocale& ValueOrDefault(const LayoutLocale* locale) {
    return locale ? *locale : GetDefault();
  }

  bool operator==(const LayoutLocale& other) const {
    return string_ == other.string_;
  }
  bool operator!=(const LayoutLocale& other) const {
    return string_ != other.string_;
  }

  const AtomicString& LocaleString() const { return string_; }
  static const AtomicString& LocaleString(const LayoutLocale* locale) {
    return locale ? locale->string_ : g_null_atom;
  }
  operator const AtomicString&() const { return string_; }
  std::string Ascii() const { return string_.Ascii(); }

  const hb_language_impl_t* HarfbuzzLanguage() const {
    return harfbuzz_language_;
  }
  const char* LocaleForSkFontMgr() const;
  UScriptCode GetScript() const { return script_; }

  // Disambiguation of the Unified Han Ideographs.
  UScriptCode GetScriptForHan() const;
  bool HasScriptForHan() const;
  static const LayoutLocale* LocaleForHan(const LayoutLocale*);
  const char* LocaleForHanForSkFontMgr() const;

  // The normalized locale data to construct |CaseMap| from.
  const CaseMap::Locale& CaseMapLocale() const {
    if (case_map_computed_)
      return locale_for_case_map_;
    ComputeCaseMapLocale();
    return locale_for_case_map_;
  }

  Hyphenation* GetHyphenation() const;
  scoped_refptr<QuotesData> GetQuotesData() const;

  AtomicString LocaleWithBreakKeyword(LineBreakStrictness,
                                      bool use_phrase = false) const;

  static scoped_refptr<LayoutLocale> CreateForTesting(const AtomicString&);
  static void SetHyphenationForTesting(const AtomicString&,
                                       scoped_refptr<Hyphenation>);

  static void AcceptLanguagesChanged(const String&);

  static void ClearForTesting();

 private:
  explicit LayoutLocale(const AtomicString&);

  void ComputeScriptForHan() const;
  void ComputeCaseMapLocale() const;

  AtomicString string_;
  mutable std::string string_for_sk_font_mgr_;
  mutable CaseMap::Locale locale_for_case_map_;
  mutable scoped_refptr<Hyphenation> hyphenation_;
  mutable scoped_refptr<QuotesData> quotes_data_;

  // hb_language_t is defined in hb.h, which not all files can include.
  raw_ptr<const hb_language_impl_t> harfbuzz_language_;

  UScriptCode script_;
  mutable UScriptCode script_for_han_;

  mutable unsigned has_script_for_han_ : 1;
  mutable unsigned hyphenation_computed_ : 1;
  mutable unsigned quotes_data_computed_ : 1;
  mutable unsigned case_map_computed_ : 1;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_LAYOUT_LOCALE_H_