1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIother.m_ If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USm_ 22 * 23 */ 24 25 #ifndef FontDescription_h 26 #define FontDescription_h 27 28 #include "FontFamily.h" 29 #include "FontRenderingMode.h" 30 #include "FontTraitsMask.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 class FontDescription { 49 public: 50 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily, 51 MonospaceFamily, CursiveFamily, FantasyFamily }; 52 FontDescription()53 FontDescription() 54 : m_specifiedSize(0) 55 , m_computedSize(0) 56 , m_italic(false) 57 , m_smallCaps(false) 58 , m_isAbsoluteSize(false) 59 , m_weight(FontWeightNormal) 60 , m_genericFamily(NoFamily) 61 , m_usePrinterFont(false) 62 , m_renderingMode(NormalRenderingMode) 63 , m_keywordSize(0) 64 { 65 } 66 67 bool operator==(const FontDescription&) const; 68 bool operator!=(const FontDescription& other) const { return !(*this == other); } 69 family()70 const FontFamily& family() const { return m_familyList; } firstFamily()71 FontFamily& firstFamily() { return m_familyList; } specifiedSize()72 float specifiedSize() const { return m_specifiedSize; } computedSize()73 float computedSize() const { return m_computedSize; } italic()74 bool italic() const { return m_italic; } computedPixelSize()75 int computedPixelSize() const { return int(m_computedSize + 0.5f); } smallCaps()76 bool smallCaps() const { return m_smallCaps; } isAbsoluteSize()77 bool isAbsoluteSize() const { return m_isAbsoluteSize; } weight()78 FontWeight weight() const { return static_cast<FontWeight>(m_weight); } 79 FontWeight lighterWeight() const; 80 FontWeight bolderWeight() const; genericFamily()81 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); } usePrinterFont()82 bool usePrinterFont() const { return m_usePrinterFont; } renderingMode()83 FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); } keywordSize()84 unsigned keywordSize() const { return m_keywordSize; } 85 86 FontTraitsMask traitsMask() const; 87 setFamily(const FontFamily & family)88 void setFamily(const FontFamily& family) { m_familyList = family; } setComputedSize(float s)89 void setComputedSize(float s) { m_computedSize = s; } setSpecifiedSize(float s)90 void setSpecifiedSize(float s) { m_specifiedSize = s; } setItalic(bool i)91 void setItalic(bool i) { m_italic = i; } setSmallCaps(bool c)92 void setSmallCaps(bool c) { m_smallCaps = c; } setIsAbsoluteSize(bool s)93 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; } setWeight(FontWeight w)94 void setWeight(FontWeight w) { m_weight = w; } setGenericFamily(GenericFamilyType genericFamily)95 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; } setUsePrinterFont(bool p)96 void setUsePrinterFont(bool p) { m_usePrinterFont = p; } setRenderingMode(FontRenderingMode mode)97 void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; } setKeywordSize(unsigned s)98 void setKeywordSize(unsigned s) { m_keywordSize = s; } 99 100 private: 101 FontFamily m_familyList; // The list of font families to be used. 102 103 float m_specifiedSize; // Specified CSS value. Independent of rendering issues such as integer 104 // rounding, minimum font sizes, and zooming. 105 float m_computedSize; // Computed size adjusted for the minimum font size and the zoom factor. 106 107 bool m_italic : 1; 108 bool m_smallCaps : 1; 109 bool m_isAbsoluteSize : 1; // Whether or not CSS specified an explicit size 110 // (logical sizes like "medium" don't count). 111 unsigned m_weight : 8; // FontWeight 112 unsigned m_genericFamily : 3; // GenericFamilyType 113 bool m_usePrinterFont : 1; 114 115 unsigned m_renderingMode : 1; // Used to switch between CG and GDI text on Windows. 116 117 unsigned m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium). If so, 118 // then we can accurately translate across different generic families to adjust for different preference settings 119 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>). 120 }; 121 122 inline bool FontDescription::operator==(const FontDescription& other) const 123 { 124 return m_familyList == other.m_familyList 125 && m_specifiedSize == other.m_specifiedSize 126 && m_computedSize == other.m_computedSize 127 && m_italic == other.m_italic 128 && m_smallCaps == other.m_smallCaps 129 && m_isAbsoluteSize == other.m_isAbsoluteSize 130 && m_weight == other.m_weight 131 && m_genericFamily == other.m_genericFamily 132 && m_usePrinterFont == other.m_usePrinterFont 133 && m_renderingMode == other.m_renderingMode 134 && m_keywordSize == other.m_keywordSize; 135 } 136 137 } 138 139 #endif 140