Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontVariantNumeric.h

Issue 1955723004: Implement font-variant-numeric (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove whitespace and clarified TODOs Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 FontVariantNumeric_h
6 #define FontVariantNumeric_h
7
8 #include "wtf/Allocator.h"
9
10 namespace blink {
11
12 class FontVariantNumeric {
13 STACK_ALLOCATED();
14
15 public:
16
17 enum NumericFigure {
18 NormalFigure = 0,
19 LiningNums = 1,
20 OldstyleNums = 2
21 };
22
23 enum NumericSpacing {
24 NormalSpacing = 0,
25 ProportionalNums = 1,
26 TabularNums = 2
27 };
28
29 enum NumericFraction {
30 NormalFraction = 0,
31 DiagonalFractions = 1,
32 StackedFractions = 2
33 };
34
35 enum Ordinal {
36 OrdinalOff = 0,
37 OrdinalOn = 1
38 };
39
40 enum SlashedZero {
41 SlashedZeroOff = 0,
42 SlashedZeroOn = 1
43 };
44
45 FontVariantNumeric() : m_fieldsAsUnsigned(0) { }
46
47 static FontVariantNumeric initializeFromUnsigned(unsigned initValue)
48 {
49 return FontVariantNumeric(initValue);
50 }
51
52 void setNumericFigure(NumericFigure figure) { m_fields.m_numericFigure = fig ure; };
53 void setNumericSpacing(NumericSpacing spacing) { m_fields.m_numericSpacing = spacing; };
54 void setNumericFraction(NumericFraction fraction) { m_fields.m_numericFracti on = fraction; };
55 void setOrdinal(Ordinal ordinal) { m_fields.m_ordinal = ordinal; };
56 void setSlashedZero(SlashedZero slashedZero) { m_fields.m_slashedZero = slas hedZero; };
57
58 NumericFigure numericFigure() const { return static_cast<NumericFigure>(m_fi elds.m_numericFigure); }
eae 2016/05/09 16:31:58 Methods and enums should use names that differ by
drott 2016/05/10 10:59:06 Suffixed with Value() for all accessors.
59 NumericSpacing numericSpacing() const { return static_cast<NumericSpacing>(m _fields.m_numericSpacing); }
60 NumericFraction numericFraction() const { return static_cast<NumericFraction >(m_fields.m_numericFraction); }
61 Ordinal ordinal() const { return static_cast<Ordinal>(m_fields.m_ordinal); } ;
62 SlashedZero slashedZero() const { return static_cast<SlashedZero>(m_fields.m _slashedZero); }
63
64 bool isAllNormal() { return !m_fieldsAsUnsigned; }
65
66 bool operator==(const FontVariantNumeric& other) const
67 {
68 return m_fieldsAsUnsigned == other.m_fieldsAsUnsigned;
69 }
70
71 private:
72 FontVariantNumeric(unsigned initValue) : m_fieldsAsUnsigned(initValue) { }
73
74 struct BitFields {
75 unsigned m_numericFigure : 2;
76 unsigned m_numericSpacing : 2;
77 unsigned m_numericFraction : 2;
78 unsigned m_ordinal : 1;
79 unsigned m_slashedZero : 1;
80 };
81
82
83 union {
84 BitFields m_fields;
85 unsigned m_fieldsAsUnsigned;
86 };
87 static_assert(sizeof(m_fields) == sizeof(m_fieldsAsUnsigned), "Mapped union types must match in size.");
88
89 // Used in setVariant to store the value in m_fields.m_variantNumeric;
90 friend class FontDescription;
91 };
92
93 }
94
95 #endif // FontVariantNumeric_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698