Home | History | Annotate | Download | only in resolver
      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 "core/platform/graphics/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     void clear();
     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(float effectiveZoom);
     56     void setFontFamilyInherit(const FontDescription&);
     57     void setFontFamilyValue(CSSValue*, float effectiveZoom);
     58 
     59     void setFontSizeInitial(float effectiveZoom);
     60     void setFontSizeInherit(const FontDescription&, float effectiveZoom);
     61     void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle, float effectiveZoom);
     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 setItalic(FontItalic);
     76     void setSmallCaps(FontSmallCaps);
     77     void setTextRenderingMode(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(PassRefPtr<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(PassRefPtr<FontSelector>, RenderStyle*);
     86 
     87     // FIXME: These should not be necessary eventually.
     88     void setFontDirty(bool fontDirty) { m_fontDirty = fontDirty; }
     89     // FIXME: This is only used by an ASSERT in StyleResolver. Remove?
     90     bool fontDirty() const { return m_fontDirty; }
     91 
     92     friend class FontDescriptionChangeScope;
     93 private:
     94 
     95     // FIXME: "size" arg should be first for consistency with other similar functions.
     96     void setSize(FontDescription&, float effectiveZoom, float size);
     97     void checkForOrientationChange(RenderStyle*);
     98     // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
     99     void checkForGenericFamilyChange(RenderStyle*, const RenderStyle* parentStyle);
    100     void checkForZoomChange(RenderStyle*, const RenderStyle* parentStyle);
    101 
    102     float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize);
    103 
    104     const Document* m_document;
    105     bool m_useSVGZoomRules;
    106     // FIXME: This member is here on a short-term lease. The plan is to remove
    107     // any notion of RenderStyle from here, allowing FontBuilder to build Font objects
    108     // directly, rather than as a byproduct of calling RenderStyle::setFontDescription.
    109     // FontDescriptionChangeScope should be the only consumer of this member.
    110     // If you're using it, U R DOIN IT WRONG.
    111     RenderStyle* m_style;
    112 
    113     // Fontbuilder is responsbile for creating the Font()
    114     // object on RenderStyle from various other font-related
    115     // properties on RenderStyle. Whenever one of those
    116     // is changed, FontBuilder tracks the need to update
    117     // style->font() with this bool.
    118     bool m_fontDirty;
    119 };
    120 
    121 }
    122 
    123 #endif
    124