blob: 2a611a01b1c2a31526bad189755e5dbad5decd19 [file] [log] [blame]
Ben Murdoch0019e4e2013-07-18 11:57:54 +01001/*
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)5d92fed2014-06-20 14:52:37 +010026#include "core/CSSValueKeywords.h"
Ben Murdoch0019e4e2013-07-18 11:57:54 +010027
Torne (Richard Coles)f79f16f2013-10-31 11:16:44 +000028#include "platform/fonts/FontDescription.h"
Ben Murdoch6f543c72014-04-16 11:17:22 +010029#include "platform/heap/Handle.h"
Ben Murdoch0019e4e2013-07-18 11:57:54 +010030#include "wtf/PassRefPtr.h"
31
32namespace WebCore {
33
34class CSSValue;
Ben Murdoch0019e4e2013-07-18 11:57:54 +010035class FontSelector;
Ben Murdoch0019e4e2013-07-18 11:57:54 +010036class RenderStyle;
37
38class FontDescriptionChangeScope;
39
40class FontBuilder {
41 WTF_MAKE_NONCOPYABLE(FontBuilder); WTF_MAKE_FAST_ALLOCATED;
42public:
43 FontBuilder();
44
45 // FIXME: The name is probably wrong, but matches StyleResolverState callsite for consistency.
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +010046 void initForStyleResolve(const Document&, RenderStyle*);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010047
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)d5428f32014-03-18 10:21:16 +000055 void setFontFamilyInitial();
Ben Murdoch0019e4e2013-07-18 11:57:54 +010056 void setFontFamilyInherit(const FontDescription&);
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000057 void setFontFamilyValue(CSSValue*);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010058
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000059 void setFontSizeInitial();
60 void setFontSizeInherit(const FontDescription&);
61 void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010062
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)d5428f32014-03-18 10:21:16 +000075 void setStyle(FontStyle);
76 void setVariant(FontVariant);
77 void setTextRendering(TextRenderingMode);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010078 void setKerning(FontDescription::Kerning);
79 void setFontSmoothing(FontSmoothingMode);
80
81 // FIXME: These need to just vend a Font object eventually.
Ben Murdoch6f543c72014-04-16 11:17:22 +010082 void createFont(PassRefPtrWillBeRawPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010083 // FIXME: This is nearly static, should either made fully static or decomposed into
84 // FontBuilder calls at the callsite.
Ben Murdoch6f543c72014-04-16 11:17:22 +010085 void createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector>, RenderStyle*);
Ben Murdoch0019e4e2013-07-18 11:57:54 +010086
Torne (Richard Coles)09380292014-02-21 12:17:33 +000087 bool fontSizeHasViewportUnits() { return m_fontSizehasViewportUnits; }
88
Ben Murdoch0019e4e2013-07-18 11:57:54 +010089 // 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)43e75022014-03-21 14:26:12 +000094 static FontDescription::GenericFamilyType initialGenericFamily() { return FontDescription::NoFamily; }
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000095 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 Murdoch0019e4e2013-07-18 11:57:54 +0100101 friend class FontDescriptionChangeScope;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000102
Ben Murdoch0019e4e2013-07-18 11:57:54 +0100103private:
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)d5428f32014-03-18 10:21:16 +0000110 void updateComputedSize(RenderStyle*, const RenderStyle* parentStyle);
Ben Murdoch0019e4e2013-07-18 11:57:54 +0100111
112 float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize);
113
114 const Document* m_document;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000115 bool m_fontSizehasViewportUnits;
Ben Murdoch0019e4e2013-07-18 11:57:54 +0100116 // 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)43e75022014-03-21 14:26:12 +0000129
130 friend class FontBuilderTest;
Ben Murdoch0019e4e2013-07-18 11:57:54 +0100131};
132
133}
134
135#endif