OLD | NEW |
(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, |
| 20 OldstyleNums |
| 21 }; |
| 22 |
| 23 enum NumericSpacing { |
| 24 NormalSpacing = 0, |
| 25 ProportionalNums, |
| 26 TabularNums |
| 27 }; |
| 28 |
| 29 enum NumericFraction { |
| 30 NormalFraction = 0, |
| 31 DiagonalFractions, |
| 32 StackedFractions |
| 33 }; |
| 34 |
| 35 enum Ordinal { |
| 36 OrdinalOff = 0, |
| 37 OrdinalOn |
| 38 }; |
| 39 |
| 40 enum SlashedZero { |
| 41 SlashedZeroOff = 0, |
| 42 SlashedZeroOn |
| 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 numericFigureValue() const { return static_cast<NumericFigure>
(m_fields.m_numericFigure); } |
| 59 NumericSpacing numericSpacingValue() const { return static_cast<NumericSpaci
ng>(m_fields.m_numericSpacing); } |
| 60 NumericFraction numericFractionValue() const { return static_cast<NumericFra
ction>(m_fields.m_numericFraction); } |
| 61 Ordinal ordinalValue() const { return static_cast<Ordinal>(m_fields.m_ordina
l); }; |
| 62 SlashedZero slashedZeroValue() const { return static_cast<SlashedZero>(m_fie
lds.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(BitFields) == sizeof(unsigned), "Mapped union types mus
t 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 |
OLD | NEW |