1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 4 * Copyright (C) 2013 Google Inc. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef FontBuilder_h 24 #define FontBuilder_h 25 26 #include "core/CSSValueKeywords.h" 27 28 #include "platform/fonts/FontDescription.h" 29 #include "platform/heap/Handle.h" 30 #include "wtf/PassRefPtr.h" 31 32 namespace WebCore { 33 34 class CSSValue; 35 class FontSelector; 36 class RenderStyle; 37 38 class FontDescriptionChangeScope; 39 40 class FontBuilder { 41 WTF_MAKE_NONCOPYABLE(FontBuilder); WTF_MAKE_FAST_ALLOCATED; 42 public: 43 FontBuilder(); 44 45 // FIXME: The name is probably wrong, but matches StyleResolverState callsite for consistency. 46 void initForStyleResolve(const Document&, RenderStyle*); 47 48 void setInitial(float effectiveZoom); 49 50 void didChangeFontParameters(bool); 51 52 void inheritFrom(const FontDescription&); 53 void fromSystemFont(CSSValueID, float effectiveZoom); 54 55 void setFontFamilyInitial(); 56 void setFontFamilyInherit(const FontDescription&); 57 void setFontFamilyValue(CSSValue*); 58 59 void setFontSizeInitial(); 60 void setFontSizeInherit(const FontDescription&); 61 void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle); 62 63 void setWeight(FontWeight); 64 void setWeightBolder(); 65 void setWeightLighter(); 66 67 void setFontVariantLigaturesInitial(); 68 void setFontVariantLigaturesInherit(const FontDescription&); 69 void setFontVariantLigaturesValue(CSSValue*); 70 71 void setFeatureSettingsNormal(); 72 void setFeatureSettingsValue(CSSValue*); 73 74 void setScript(const String& locale); 75 void setStyle(FontStyle); 76 void setVariant(FontVariant); 77 void setTextRendering(TextRenderingMode); 78 void setKerning(FontDescription::Kerning); 79 void setFontSmoothing(FontSmoothingMode); 80 81 // FIXME: These need to just vend a Font object eventually. 82 void createFont(PassRefPtrWillBeRawPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*); 83 // FIXME: This is nearly static, should either made fully static or decomposed into 84 // FontBuilder calls at the callsite. 85 void createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector>, RenderStyle*); 86 87 bool fontSizeHasViewportUnits() { return m_fontSizehasViewportUnits; } 88 89 // FIXME: These should not be necessary eventually. 90 void setFontDirty(bool fontDirty) { m_fontDirty = fontDirty; } 91 // FIXME: This is only used by an ASSERT in StyleResolver. Remove? 92 bool fontDirty() const { return m_fontDirty; } 93 94 static FontDescription::GenericFamilyType initialGenericFamily() { return FontDescription::NoFamily; } 95 static TextRenderingMode initialTextRendering() { return AutoTextRendering; } 96 static FontVariant initialVariant() { return FontVariantNormal; } 97 static FontStyle initialStyle() { return FontStyleNormal; } 98 static FontDescription::Kerning initialKerning() { return FontDescription::AutoKerning; } 99 static FontSmoothingMode initialFontSmoothing() { return AutoSmoothing; } 100 101 friend class FontDescriptionChangeScope; 102 103 private: 104 105 // FIXME: "size" arg should be first for consistency with other similar functions. 106 void setSize(FontDescription&, float effectiveZoom, float size); 107 void checkForOrientationChange(RenderStyle*); 108 // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh 109 void checkForGenericFamilyChange(RenderStyle*, const RenderStyle* parentStyle); 110 void updateComputedSize(RenderStyle*, const RenderStyle* parentStyle); 111 112 float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize); 113 114 const Document* m_document; 115 bool m_fontSizehasViewportUnits; 116 // FIXME: This member is here on a short-term lease. The plan is to remove 117 // any notion of RenderStyle from here, allowing FontBuilder to build Font objects 118 // directly, rather than as a byproduct of calling RenderStyle::setFontDescription. 119 // FontDescriptionChangeScope should be the only consumer of this member. 120 // If you're using it, U R DOIN IT WRONG. 121 RenderStyle* m_style; 122 123 // Fontbuilder is responsbile for creating the Font() 124 // object on RenderStyle from various other font-related 125 // properties on RenderStyle. Whenever one of those 126 // is changed, FontBuilder tracks the need to update 127 // style->font() with this bool. 128 bool m_fontDirty; 129 130 friend class FontBuilderTest; 131 }; 132 133 } 134 135 #endif 136