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 "CSSValueKeywords.h" 27 28 #include "platform/fonts/FontDescription.h" 29 #include "wtf/PassRefPtr.h" 30 31 namespace WebCore { 32 33 class CSSValue; 34 class FontSelector; 35 class RenderStyle; 36 37 class FontDescriptionChangeScope; 38 39 class FontBuilder { 40 WTF_MAKE_NONCOPYABLE(FontBuilder); WTF_MAKE_FAST_ALLOCATED; 41 public: 42 FontBuilder(); 43 44 // FIXME: The name is probably wrong, but matches StyleResolverState callsite for consistency. 45 void initForStyleResolve(const Document&, RenderStyle*, bool useSVGZoomRules); 46 47 void setInitial(float effectiveZoom); 48 49 void didChangeFontParameters(bool); 50 51 void inheritFrom(const FontDescription&); 52 void fromSystemFont(CSSValueID, float effectiveZoom); 53 54 void setFontFamilyInitial(float effectiveZoom); 55 void setFontFamilyInherit(const FontDescription&); 56 void setFontFamilyValue(CSSValue*, float effectiveZoom); 57 58 void setFontSizeInitial(float effectiveZoom); 59 void setFontSizeInherit(const FontDescription&, float effectiveZoom); 60 void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle, float effectiveZoom); 61 62 void setWeight(FontWeight); 63 void setWeightBolder(); 64 void setWeightLighter(); 65 66 void setFontVariantLigaturesInitial(); 67 void setFontVariantLigaturesInherit(const FontDescription&); 68 void setFontVariantLigaturesValue(CSSValue*); 69 70 void setFeatureSettingsNormal(); 71 void setFeatureSettingsValue(CSSValue*); 72 73 void setScript(const String& locale); 74 void setItalic(FontItalic); 75 void setSmallCaps(FontSmallCaps); 76 void setTextRenderingMode(TextRenderingMode); 77 void setKerning(FontDescription::Kerning); 78 void setFontSmoothing(FontSmoothingMode); 79 80 // FIXME: These need to just vend a Font object eventually. 81 void createFont(PassRefPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*); 82 // FIXME: This is nearly static, should either made fully static or decomposed into 83 // FontBuilder calls at the callsite. 84 void createFontForDocument(PassRefPtr<FontSelector>, RenderStyle*); 85 86 // FIXME: These should not be necessary eventually. 87 void setFontDirty(bool fontDirty) { m_fontDirty = fontDirty; } 88 // FIXME: This is only used by an ASSERT in StyleResolver. Remove? 89 bool fontDirty() const { return m_fontDirty; } 90 91 friend class FontDescriptionChangeScope; 92 private: 93 94 // FIXME: "size" arg should be first for consistency with other similar functions. 95 void setSize(FontDescription&, float effectiveZoom, float size); 96 void checkForOrientationChange(RenderStyle*); 97 // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh 98 void checkForGenericFamilyChange(RenderStyle*, const RenderStyle* parentStyle); 99 void checkForZoomChange(RenderStyle*, const RenderStyle* parentStyle); 100 101 float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize); 102 103 const Document* m_document; 104 bool m_useSVGZoomRules; 105 // FIXME: This member is here on a short-term lease. The plan is to remove 106 // any notion of RenderStyle from here, allowing FontBuilder to build Font objects 107 // directly, rather than as a byproduct of calling RenderStyle::setFontDescription. 108 // FontDescriptionChangeScope should be the only consumer of this member. 109 // If you're using it, U R DOIN IT WRONG. 110 RenderStyle* m_style; 111 112 // Fontbuilder is responsbile for creating the Font() 113 // object on RenderStyle from various other font-related 114 // properties on RenderStyle. Whenever one of those 115 // is changed, FontBuilder tracks the need to update 116 // style->font() with this bool. 117 bool m_fontDirty; 118 }; 119 120 } 121 122 #endif 123