File: font_variant_numeric.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 (106 lines) | stat: -rw-r--r-- 3,122 bytes parent folder | download | duplicates (8)
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
// 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_FONTS_FONT_VARIANT_NUMERIC_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_VARIANT_NUMERIC_H_

#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace WTF {
class String;
}  // namespace WTF

namespace blink {

class FontVariantNumeric {
  STACK_ALLOCATED();

 public:
  enum NumericFigure { kNormalFigure = 0, kLiningNums, kOldstyleNums };
  static WTF::String ToString(NumericFigure);

  enum NumericSpacing { kNormalSpacing = 0, kProportionalNums, kTabularNums };
  static WTF::String ToString(NumericSpacing);

  enum NumericFraction {
    kNormalFraction = 0,
    kDiagonalFractions,
    kStackedFractions
  };
  static WTF::String ToString(NumericFraction);

  enum Ordinal { kOrdinalOff = 0, kOrdinalOn };
  static WTF::String ToString(Ordinal);

  enum SlashedZero { kSlashedZeroOff = 0, kSlashedZeroOn };
  static WTF::String ToString(SlashedZero);

  FontVariantNumeric() : fields_as_unsigned_(0) {}

  static FontVariantNumeric InitializeFromUnsigned(unsigned init_value) {
    return FontVariantNumeric(init_value);
  }

  void SetNumericFigure(NumericFigure figure) {
    fields_.numeric_figure_ = figure;
  }
  void SetNumericSpacing(NumericSpacing spacing) {
    fields_.numeric_spacing_ = spacing;
  }
  void SetNumericFraction(NumericFraction fraction) {
    fields_.numeric_fraction_ = fraction;
  }
  void SetOrdinal(Ordinal ordinal) { fields_.ordinal_ = ordinal; }
  void SetSlashedZero(SlashedZero slashed_zero) {
    fields_.slashed_zero_ = slashed_zero;
  }

  NumericFigure NumericFigureValue() const {
    return static_cast<NumericFigure>(fields_.numeric_figure_);
  }
  NumericSpacing NumericSpacingValue() const {
    return static_cast<NumericSpacing>(fields_.numeric_spacing_);
  }
  NumericFraction NumericFractionValue() const {
    return static_cast<NumericFraction>(fields_.numeric_fraction_);
  }
  Ordinal OrdinalValue() const {
    return static_cast<Ordinal>(fields_.ordinal_);
  }
  SlashedZero SlashedZeroValue() const {
    return static_cast<SlashedZero>(fields_.slashed_zero_);
  }

  bool IsAllNormal() { return !fields_as_unsigned_; }

  bool operator==(const FontVariantNumeric& other) const {
    return fields_as_unsigned_ == other.fields_as_unsigned_;
  }

  WTF::String ToString() const;

 private:
  FontVariantNumeric(unsigned init_value) : fields_as_unsigned_(init_value) {}

  struct BitFields {
    unsigned numeric_figure_ : 2;
    unsigned numeric_spacing_ : 2;
    unsigned numeric_fraction_ : 2;
    unsigned ordinal_ : 1;
    unsigned slashed_zero_ : 1;
  };

  union {
    BitFields fields_;
    unsigned fields_as_unsigned_;
  };
  static_assert(sizeof(BitFields) == sizeof(unsigned),
                "Mapped union types must match in size.");

  // Used in SetVariant to store the value in m_fields.m_variantNumeric;
  friend class FontDescription;
};
}

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_VARIANT_NUMERIC_H_