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 "core/CSSValueKeywords.h"
     27 #include "core/css/FontSize.h"
     28 #include "platform/fonts/FontDescription.h"
     29 #include "platform/heap/Handle.h"
     30 #include "wtf/PassRefPtr.h"
     31 
     32 namespace blink {
     33 
     34 class CSSValue;
     35 class FontSelector;
     36 class RenderStyle;
     37 
     38 class FontDescriptionChangeScope;
     39 
     40 class FontBuilder {
     41     STACK_ALLOCATED();
     42     WTF_MAKE_NONCOPYABLE(FontBuilder);
     43 public:
     44     FontBuilder();
     45 
     46     // FIXME: The name is probably wrong, but matches StyleResolverState callsite for consistency.
     47     void initForStyleResolve(const Document&, RenderStyle*);
     48 
     49     void setInitial(float effectiveZoom);
     50 
     51     void didChangeFontParameters(bool);
     52 
     53     void inheritFrom(const FontDescription&);
     54     void fromSystemFont(CSSValueID, float effectiveZoom);
     55 
     56     void setFontFamilyInitial();
     57     void setFontFamilyInherit(const FontDescription&);
     58     void setFontFamilyValue(CSSValue*);
     59 
     60     void setWeight(FontWeight);
     61     void setSize(const FontDescription::Size&);
     62     void setStretch(FontStretch);
     63     void setFeatureSettings(PassRefPtr<FontFeatureSettings>);
     64     void setScript(const String& locale);
     65     void setStyle(FontStyle);
     66     void setVariant(FontVariant);
     67     void setVariantLigatures(const FontDescription::VariantLigatures&);
     68     void setTextRendering(TextRenderingMode);
     69     void setKerning(FontDescription::Kerning);
     70     void setFontSmoothing(FontSmoothingMode);
     71 
     72     // FIXME: These need to just vend a Font object eventually.
     73     void createFont(PassRefPtrWillBeRawPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*);
     74 
     75     void createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector>, RenderStyle*);
     76 
     77     // FIXME: These should not be necessary eventually.
     78     void setFontDirty(bool fontDirty) { m_fontDirty = fontDirty; }
     79     // FIXME: This is only used by an ASSERT in StyleResolver. Remove?
     80     bool fontDirty() const { return m_fontDirty; }
     81 
     82     static FontFeatureSettings* initialFeatureSettings() { return nullptr; }
     83     static FontDescription::GenericFamilyType initialGenericFamily() { return FontDescription::NoFamily; }
     84     static FontDescription::Size initialSize() { return FontDescription::Size(FontSize::initialKeywordSize(), 0.0f, false); }
     85     static TextRenderingMode initialTextRendering() { return AutoTextRendering; }
     86     static FontVariant initialVariant() { return FontVariantNormal; }
     87     static FontDescription::VariantLigatures initialVariantLigatures() { return FontDescription::VariantLigatures(); }
     88     static FontStyle initialStyle() { return FontStyleNormal; }
     89     static FontDescription::Kerning initialKerning() { return FontDescription::AutoKerning; }
     90     static FontSmoothingMode initialFontSmoothing() { return AutoSmoothing; }
     91     static FontStretch initialStretch() { return FontStretchNormal; }
     92     static FontWeight initialWeight() { return FontWeightNormal; }
     93 
     94     friend class FontDescriptionChangeScope;
     95 
     96 private:
     97 
     98     // FIXME: "size" arg should be first for consistency with other similar functions.
     99     void setSize(FontDescription&, const FontDescription::Size&);
    100     void checkForOrientationChange(RenderStyle*);
    101     // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
    102     void checkForGenericFamilyChange(RenderStyle*, const RenderStyle* parentStyle);
    103     void updateComputedSize(RenderStyle*, const RenderStyle* parentStyle);
    104     void updateComputedSize(FontDescription&, RenderStyle*);
    105 
    106     float getComputedSizeFromSpecifiedSize(FontDescription&, float effectiveZoom, float specifiedSize);
    107 
    108     RawPtrWillBeMember<const Document> m_document;
    109     // FIXME: This member is here on a short-term lease. The plan is to remove
    110     // any notion of RenderStyle from here, allowing FontBuilder to build Font objects
    111     // directly, rather than as a byproduct of calling RenderStyle::setFontDescription.
    112     // FontDescriptionChangeScope should be the only consumer of this member.
    113     // If you're using it, U R DOIN IT WRONG.
    114     RenderStyle* m_style;
    115 
    116     // Fontbuilder is responsbile for creating the Font()
    117     // object on RenderStyle from various other font-related
    118     // properties on RenderStyle. Whenever one of those
    119     // is changed, FontBuilder tracks the need to update
    120     // style->font() with this bool.
    121     bool m_fontDirty;
    122 
    123     friend class FontBuilderTest;
    124 };
    125 
    126 }
    127 
    128 #endif
    129