• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  * Copyright (C) 2014 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef FontTraits_h
28 #define FontTraits_h
29 
30 #include "wtf/Assertions.h"
31 
32 namespace WebCore {
33 
34 enum FontWeight {
35     FontWeight100,
36     FontWeight200,
37     FontWeight300,
38     FontWeight400,
39     FontWeight500,
40     FontWeight600,
41     FontWeight700,
42     FontWeight800,
43     FontWeight900,
44     FontWeightNormal = FontWeight400,
45     FontWeightBold = FontWeight700
46 };
47 
48 // Numeric values matching OS/2 & Windows Metrics usWidthClass table.
49 // https://www.microsoft.com/typography/otspec/os2.htm
50 enum FontStretch {
51     FontStretchUltraCondensed = 1,
52     FontStretchExtraCondensed = 2,
53     FontStretchCondensed = 3,
54     FontStretchSemiCondensed = 4,
55     FontStretchNormal = 5,
56     FontStretchSemiExpanded = 6,
57     FontStretchExpanded = 7,
58     FontStretchExtraExpanded = 8,
59     FontStretchUltraExpanded = 9
60 };
61 
62 enum FontStyle {
63     FontStyleNormal = 0,
64     FontStyleItalic = 1
65 };
66 
67 enum FontVariant {
68     FontVariantNormal = 0,
69     FontVariantSmallCaps = 1
70 };
71 
72 typedef unsigned FontTraitsMask;
73 
74 struct FontTraits {
FontTraitsFontTraits75     FontTraits(FontStyle style, FontVariant variant, FontWeight weight, FontStretch stretch)
76         : m_style(style), m_variant(variant), m_weight(weight), m_stretch(stretch), m_filler(0)
77     {
78         ASSERT(!m_filler);
79         ASSERT(!(m_mask >> 10));
80     }
FontTraitsFontTraits81     FontTraits(FontTraitsMask mask)
82         : m_mask(mask)
83     {
84         ASSERT(!m_filler);
85         ASSERT(!(m_mask >> 10));
86     }
styleFontTraits87     FontStyle style() const { return static_cast<FontStyle>(m_style); }
variantFontTraits88     FontVariant variant() const { return static_cast<FontVariant>(m_variant); }
weightFontTraits89     FontWeight weight() const { return static_cast<FontWeight>(m_weight); }
stretchFontTraits90     FontStretch stretch() const { return static_cast<FontStretch>(m_stretch); }
maskFontTraits91     FontTraitsMask mask() const { return m_mask; }
92 
93     union {
94         struct {
95             unsigned m_style : 1;
96             unsigned m_variant : 1;
97             unsigned m_weight : 4;
98             unsigned m_stretch : 4;
99             unsigned m_filler : 22;
100         };
101         unsigned m_mask;
102     };
103 };
104 
105 } // namespace WebCore
106 #endif // FontTraits_h
107