Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2007 Nicholas Shanks <contact (at) nickshanks.com>
      3  * Copyright (C) 2008 Apple 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  *
      9  * 1.  Redistributions of source code must retain the above copyright
     10  *     notice, this list of conditions and the following disclaimer.
     11  * 2.  Redistributions in binary form must reproduce the above copyright
     12  *     notice, this list of conditions and the following disclaimer in the
     13  *     documentation and/or other materials provided with the distribution.
     14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     15  *     its contributors may be used to endorse or promote products derived
     16  *     from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "core/platform/graphics/FontDescription.h"
     32 
     33 namespace WebCore {
     34 
     35 struct SameSizeAsFontDescription {
     36     FontFamily familyList;
     37     RefPtr<FontFeatureSettings> m_featureSettings;
     38     float sizes[2];
     39     // FXIME: Make them fit into one word.
     40     uint32_t bitfields;
     41     uint32_t bitfields2 : 8;
     42 };
     43 
     44 COMPILE_ASSERT(sizeof(FontDescription) == sizeof(SameSizeAsFontDescription), FontDescription_should_stay_small);
     45 
     46 FontWeight FontDescription::lighterWeight(void) const
     47 {
     48     switch (m_weight) {
     49         case FontWeight100:
     50         case FontWeight200:
     51         case FontWeight300:
     52         case FontWeight400:
     53         case FontWeight500:
     54             return FontWeight100;
     55 
     56         case FontWeight600:
     57         case FontWeight700:
     58             return FontWeight400;
     59 
     60         case FontWeight800:
     61         case FontWeight900:
     62             return FontWeight700;
     63     }
     64     ASSERT_NOT_REACHED();
     65     return FontWeightNormal;
     66 }
     67 
     68 FontWeight FontDescription::bolderWeight(void) const
     69 {
     70     switch (m_weight) {
     71         case FontWeight100:
     72         case FontWeight200:
     73         case FontWeight300:
     74             return FontWeight400;
     75 
     76         case FontWeight400:
     77         case FontWeight500:
     78             return FontWeight700;
     79 
     80         case FontWeight600:
     81         case FontWeight700:
     82         case FontWeight800:
     83         case FontWeight900:
     84             return FontWeight900;
     85     }
     86     ASSERT_NOT_REACHED();
     87     return FontWeightNormal;
     88 }
     89 
     90 FontTraitsMask FontDescription::traitsMask() const
     91 {
     92     return static_cast<FontTraitsMask>((m_italic ? FontStyleItalicMask : FontStyleNormalMask)
     93             | (m_smallCaps ? FontVariantSmallCapsMask : FontVariantNormalMask)
     94             | (FontWeight100Mask << (m_weight - FontWeight100)));
     95 
     96 }
     97 
     98 FontDescription FontDescription::makeNormalFeatureSettings() const
     99 {
    100     FontDescription normalDescription(*this);
    101     normalDescription.setFeatureSettings(0);
    102     return normalDescription;
    103 }
    104 
    105 } // namespace WebCore
    106