Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@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 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 26 | #include "core/CSSValueKeywords.h" |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 27 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 28 | #include "platform/fonts/FontDescription.h" |
Ben Murdoch | 6f543c7 | 2014-04-16 11:17:22 +0100 | [diff] [blame] | 29 | #include "platform/heap/Handle.h" |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 30 | #include "wtf/PassRefPtr.h" |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | class CSSValue; |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 35 | class FontSelector; |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 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. |
Torne (Richard Coles) | f6b7aed | 2014-06-09 12:01:17 +0100 | [diff] [blame] | 46 | void initForStyleResolve(const Document&, RenderStyle*); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 47 | |
| 48 | void setInitial(float effectiveZoom); |
| 49 | |
| 50 | void didChangeFontParameters(bool); |
| 51 | |
| 52 | void inheritFrom(const FontDescription&); |
| 53 | void fromSystemFont(CSSValueID, float effectiveZoom); |
| 54 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 55 | void setFontFamilyInitial(); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 56 | void setFontFamilyInherit(const FontDescription&); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 57 | void setFontFamilyValue(CSSValue*); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 58 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 59 | void setFontSizeInitial(); |
| 60 | void setFontSizeInherit(const FontDescription&); |
| 61 | void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 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); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 75 | void setStyle(FontStyle); |
| 76 | void setVariant(FontVariant); |
| 77 | void setTextRendering(TextRenderingMode); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 78 | void setKerning(FontDescription::Kerning); |
| 79 | void setFontSmoothing(FontSmoothingMode); |
| 80 | |
| 81 | // FIXME: These need to just vend a Font object eventually. |
Ben Murdoch | 6f543c7 | 2014-04-16 11:17:22 +0100 | [diff] [blame] | 82 | void createFont(PassRefPtrWillBeRawPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 83 | // FIXME: This is nearly static, should either made fully static or decomposed into |
| 84 | // FontBuilder calls at the callsite. |
Ben Murdoch | 6f543c7 | 2014-04-16 11:17:22 +0100 | [diff] [blame] | 85 | void createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector>, RenderStyle*); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 86 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 87 | bool fontSizeHasViewportUnits() { return m_fontSizehasViewportUnits; } |
| 88 | |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 43e7502 | 2014-03-21 14:26:12 +0000 | [diff] [blame] | 94 | static FontDescription::GenericFamilyType initialGenericFamily() { return FontDescription::NoFamily; } |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 101 | friend class FontDescriptionChangeScope; |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 102 | |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 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); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 110 | void updateComputedSize(RenderStyle*, const RenderStyle* parentStyle); |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 111 | |
| 112 | float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize); |
| 113 | |
| 114 | const Document* m_document; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 115 | bool m_fontSizehasViewportUnits; |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 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; |
Torne (Richard Coles) | 43e7502 | 2014-03-21 14:26:12 +0000 | [diff] [blame] | 129 | |
| 130 | friend class FontBuilderTest; |
Ben Murdoch | 0019e4e | 2013-07-18 11:57:54 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } |
| 134 | |
| 135 | #endif |