Home | History | Annotate | Download | only in fonts
      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 blink {
     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 FontTraitsBitfield;
     73 
     74 struct FontTraits {
     75     FontTraits(FontStyle style, FontVariant variant, FontWeight weight, FontStretch stretch)
     76     {
     77         m_traits.m_style = style;
     78         m_traits.m_variant = variant;
     79         m_traits.m_weight = weight;
     80         m_traits.m_stretch = stretch;
     81         m_traits.m_filler = 0;
     82         ASSERT(!(m_bitfield >> 10));
     83     }
     84     FontTraits(FontTraitsBitfield bitfield)
     85         : m_bitfield(bitfield)
     86     {
     87         ASSERT(!m_traits.m_filler);
     88         ASSERT(!(m_bitfield >> 10));
     89     }
     90     FontStyle style() const { return static_cast<FontStyle>(m_traits.m_style); }
     91     FontVariant variant() const { return static_cast<FontVariant>(m_traits.m_variant); }
     92     FontWeight weight() const { return static_cast<FontWeight>(m_traits.m_weight); }
     93     FontStretch stretch() const { return static_cast<FontStretch>(m_traits.m_stretch); }
     94     FontTraitsBitfield bitfield() const { return m_bitfield; }
     95 
     96     union {
     97         struct {
     98             unsigned m_style : 1;
     99             unsigned m_variant : 1;
    100             unsigned m_weight : 4;
    101             unsigned m_stretch : 4;
    102             unsigned m_filler : 22;
    103         } m_traits;
    104         FontTraitsBitfield m_bitfield;
    105     };
    106 };
    107 
    108 } // namespace blink
    109 #endif // FontTraits_h
    110