提交 0633830c 编写于 作者: A Adam Barth

Remove the last remnants of CSS

This patch also lets us remove FontFamilyNames, which is one of two
remaining clients of jinja2.
上级 25d50e80
......@@ -30,9 +30,9 @@
#include "sky/engine/core/Init.h"
#include "gen/sky/platform/FontFamilyNames.h"
#include "sky/engine/platform/Partitions.h"
#include "sky/engine/platform/PlatformThreadData.h"
#include "sky/engine/wtf/text/StringImpl.h"
#include "sky/engine/wtf/text/StringStatics.h"
namespace blink {
......@@ -42,8 +42,6 @@ void CoreInitializer::init()
ASSERT(!m_isInited);
m_isInited = true;
FontFamilyNames::init();
// It would make logical sense to do this in WTF::initialize() but there are
// ordering dependencies, e.g. about "xmlns".
WTF::StringStatics::init();
......
......@@ -11,17 +11,6 @@ sky_core_files = [
"compositing/Scene.h",
"compositing/SceneBuilder.cpp",
"compositing/SceneBuilder.h",
"css/CSSFontSelector.cpp",
"css/CSSFontSelector.h",
"css/CSSSegmentedFontFace.cpp",
"css/CSSSegmentedFontFace.h",
"css/FontFaceCache.cpp",
"css/FontFaceCache.h",
"css/FontSize.cpp",
"css/FontSize.h",
"css/StyleColor.h",
"css/resolver/FontBuilder.cpp",
"css/resolver/FontBuilder.h",
"dom/Microtask.cpp",
"dom/Microtask.h",
"editing/CompositionUnderline.h",
......@@ -195,6 +184,7 @@ sky_core_files = [
"rendering/style/StyleBackgroundData.h",
"rendering/style/StyleBoxData.cpp",
"rendering/style/StyleBoxData.h",
"rendering/style/StyleColor.h",
"rendering/style/StyleDifference.h",
"rendering/style/StyleFilterData.cpp",
"rendering/style/StyleFilterData.h",
......
/*
* Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
* (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/core/css/CSSFontSelector.h"
#include "gen/sky/platform/RuntimeEnabledFeatures.h"
#include "sky/engine/core/css/CSSSegmentedFontFace.h"
#include "sky/engine/platform/fonts/FontCache.h"
#include "sky/engine/platform/fonts/SimpleFontData.h"
#include "sky/engine/wtf/text/AtomicString.h"
namespace blink {
CSSFontSelector::CSSFontSelector()
{
FontCache::fontCache()->addClient(this);
}
CSSFontSelector::~CSSFontSelector()
{
#if !ENABLE(OILPAN)
FontCache::fontCache()->removeClient(this);
#endif
}
void CSSFontSelector::fontFaceInvalidated()
{
}
void CSSFontSelector::fontCacheInvalidated()
{
}
static AtomicString familyNameFromSettings(const GenericFontFamilySettings& settings, const FontDescription& fontDescription, const AtomicString& genericFamilyName)
{
#if OS(ANDROID)
if (fontDescription.genericFamily() == FontDescription::StandardFamily)
return FontCache::getGenericFamilyNameForScript(FontFamilyNames::webkit_standard, fontDescription);
if (genericFamilyName.startsWith("-webkit-"))
return FontCache::getGenericFamilyNameForScript(genericFamilyName, fontDescription);
#else
UScriptCode script = fontDescription.script();
if (fontDescription.genericFamily() == FontDescription::StandardFamily)
return settings.standard(script);
if (genericFamilyName == FontFamilyNames::webkit_serif)
return settings.serif(script);
if (genericFamilyName == FontFamilyNames::webkit_sans_serif)
return settings.sansSerif(script);
if (genericFamilyName == FontFamilyNames::webkit_cursive)
return settings.cursive(script);
if (genericFamilyName == FontFamilyNames::webkit_fantasy)
return settings.fantasy(script);
if (genericFamilyName == FontFamilyNames::webkit_monospace)
return settings.fixed(script);
if (genericFamilyName == FontFamilyNames::webkit_pictograph)
return settings.pictograph(script);
if (genericFamilyName == FontFamilyNames::webkit_standard)
return settings.standard(script);
#endif
return emptyAtom;
}
PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName)
{
if (CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, familyName))
return face->getFontData(fontDescription);
// Try to return the correct font based off our settings, in case we were handed the generic font family name.
AtomicString settingsFamilyName = familyNameFromSettings(m_genericFontFamilySettings, fontDescription, familyName);
if (settingsFamilyName.isEmpty())
return nullptr;
return FontCache::fontCache()->getFontData(fontDescription, settingsFamilyName);
}
void CSSFontSelector::willUseFontData(const FontDescription& fontDescription, const AtomicString& family, UChar32 character)
{
CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, family);
if (face)
face->willUseFontData(fontDescription, character);
}
bool CSSFontSelector::isPlatformFontAvailable(const FontDescription& fontDescription, const AtomicString& passedFamily)
{
AtomicString family = familyNameFromSettings(m_genericFontFamilySettings, fontDescription, passedFamily);
if (family.isEmpty())
family = passedFamily;
return FontCache::fontCache()->isPlatformFontAvailable(fontDescription, family);
}
}
/*
* Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_CORE_CSS_CSSFONTSELECTOR_H_
#define SKY_ENGINE_CORE_CSS_CSSFONTSELECTOR_H_
#include "sky/engine/core/css/FontFaceCache.h"
#include "sky/engine/platform/fonts/FontSelector.h"
#include "sky/engine/platform/fonts/GenericFontFamilySettings.h"
#include "sky/engine/wtf/Forward.h"
#include "sky/engine/wtf/HashMap.h"
#include "sky/engine/wtf/HashSet.h"
namespace blink {
class CSSFontFace;
class CSSFontFaceRule;
class CSSSegmentedFontFace;
class FontDescription;
class StyleRuleFontFace;
class CSSFontSelector final : public FontSelector {
public:
static PassRefPtr<CSSFontSelector> create()
{
return adoptRef(new CSSFontSelector());
}
virtual ~CSSFontSelector();
virtual unsigned version() const override { return m_fontFaceCache.version(); }
virtual PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString&) override;
virtual void willUseFontData(const FontDescription&, const AtomicString& family, UChar32) override;
bool isPlatformFontAvailable(const FontDescription&, const AtomicString& family);
void fontFaceInvalidated();
// FontCacheClient implementation
virtual void fontCacheInvalidated() override;
FontFaceCache* fontFaceCache() { return &m_fontFaceCache; }
const GenericFontFamilySettings& genericFontFamilySettings() const { return m_genericFontFamilySettings; }
private:
explicit CSSFontSelector();
void dispatchInvalidationCallbacks();
FontFaceCache m_fontFaceCache;
GenericFontFamilySettings m_genericFontFamilySettings;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_CSS_CSSFONTSELECTOR_H_
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/core/css/CSSSegmentedFontFace.h"
#include "gen/sky/platform/RuntimeEnabledFeatures.h"
#include "sky/engine/core/css/CSSFontSelector.h"
#include "sky/engine/platform/fonts/FontCache.h"
#include "sky/engine/platform/fonts/FontDescription.h"
#include "sky/engine/platform/fonts/FontFaceCreationParams.h"
#include "sky/engine/platform/fonts/SegmentedFontData.h"
#include "sky/engine/platform/fonts/SimpleFontData.h"
namespace blink {
CSSSegmentedFontFace::CSSSegmentedFontFace(CSSFontSelector* fontSelector, FontTraits traits)
: m_fontSelector(fontSelector)
, m_traits(traits)
{
}
CSSSegmentedFontFace::~CSSSegmentedFontFace()
{
pruneTable();
}
void CSSSegmentedFontFace::pruneTable()
{
// Make sure the glyph page tree prunes out all uses of this custom font.
if (m_fontDataTable.isEmpty())
return;
m_fontDataTable.clear();
}
bool CSSSegmentedFontFace::isValid() const
{
return false;
}
PassRefPtr<FontData> CSSSegmentedFontFace::getFontData(const FontDescription& fontDescription)
{
if (!isValid())
return nullptr;
FontTraits desiredTraits = fontDescription.traits();
FontCacheKey key = fontDescription.cacheKey(FontFaceCreationParams(), desiredTraits);
RefPtr<SegmentedFontData>& fontData = m_fontDataTable.add(key.hash(), nullptr).storedValue->value;
if (fontData && fontData->numRanges())
return fontData; // No release, we have a reference to an object in the cache which should retain the ref count it has.
if (!fontData)
fontData = SegmentedFontData::create();
FontDescription requestedFontDescription(fontDescription);
requestedFontDescription.setTraits(m_traits);
requestedFontDescription.setSyntheticBold(m_traits.weight() < FontWeight600 && desiredTraits.weight() >= FontWeight600);
requestedFontDescription.setSyntheticItalic(m_traits.style() == FontStyleNormal && desiredTraits.style() == FontStyleItalic);
if (fontData->numRanges())
return fontData; // No release, we have a reference to an object in the cache which should retain the ref count it has.
return nullptr;
}
bool CSSSegmentedFontFace::isLoading() const
{
return false;
}
bool CSSSegmentedFontFace::isLoaded() const
{
return true;
}
void CSSSegmentedFontFace::willUseFontData(const FontDescription& fontDescription, UChar32 character)
{
}
bool CSSSegmentedFontFace::checkFont(const String& text) const
{
return true;
}
}
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_CORE_CSS_CSSSEGMENTEDFONTFACE_H_
#define SKY_ENGINE_CORE_CSS_CSSSEGMENTEDFONTFACE_H_
#include "sky/engine/platform/fonts/FontTraits.h"
#include "sky/engine/wtf/HashMap.h"
#include "sky/engine/wtf/ListHashSet.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/Vector.h"
#include "sky/engine/wtf/text/WTFString.h"
namespace blink {
class CSSFontSelector;
class FontData;
class FontDescription;
class FontFace;
class SegmentedFontData;
class CSSSegmentedFontFace final : public RefCounted<CSSSegmentedFontFace> {
public:
static PassRefPtr<CSSSegmentedFontFace> create(CSSFontSelector* selector, FontTraits traits)
{
return adoptRef(new CSSSegmentedFontFace(selector, traits));
}
~CSSSegmentedFontFace();
CSSFontSelector* fontSelector() const { return m_fontSelector; }
FontTraits traits() const { return m_traits; }
bool isEmpty() const { return true; }
PassRefPtr<FontData> getFontData(const FontDescription&);
bool checkFont(const String&) const;
void willUseFontData(const FontDescription&, UChar32);
private:
CSSSegmentedFontFace(CSSFontSelector*, FontTraits);
void pruneTable();
bool isValid() const;
bool isLoading() const;
bool isLoaded() const;
RawPtr<CSSFontSelector> m_fontSelector;
FontTraits m_traits;
HashMap<unsigned, RefPtr<SegmentedFontData> > m_fontDataTable;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_CSS_CSSSEGMENTEDFONTFACE_H_
/*
* Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/core/css/FontFaceCache.h"
#include "gen/sky/platform/FontFamilyNames.h"
#include "sky/engine/core/css/CSSFontSelector.h"
#include "sky/engine/core/css/CSSSegmentedFontFace.h"
#include "sky/engine/platform/fonts/FontDescription.h"
#include "sky/engine/wtf/text/AtomicString.h"
namespace blink {
FontFaceCache::FontFaceCache()
: m_version(0)
{
}
void FontFaceCache::remove(const StyleRuleFontFace* fontFaceRule)
{
}
void FontFaceCache::removeFontFace(FontFace* fontFace, bool cssConnected)
{
}
void FontFaceCache::clearAll()
{
}
static inline bool compareFontFaces(CSSSegmentedFontFace* first, CSSSegmentedFontFace* second, FontTraits desiredTraits)
{
const FontTraits& firstTraits = first->traits();
const FontTraits& secondTraits = second->traits();
bool firstHasDesiredVariant = firstTraits.variant() == desiredTraits.variant();
bool secondHasDesiredVariant = secondTraits.variant() == desiredTraits.variant();
if (firstHasDesiredVariant != secondHasDesiredVariant)
return firstHasDesiredVariant;
// We need to check font-variant css property for CSS2.1 compatibility.
if (desiredTraits.variant() == FontVariantSmallCaps) {
// Prefer a font that has indicated that it can only support small-caps to a font that claims to support
// all variants. The specialized font is more likely to be true small-caps and not require synthesis.
bool firstRequiresSmallCaps = firstTraits.variant() == FontVariantSmallCaps;
bool secondRequiresSmallCaps = secondTraits.variant() == FontVariantSmallCaps;
if (firstRequiresSmallCaps != secondRequiresSmallCaps)
return firstRequiresSmallCaps;
}
bool firstHasDesiredStyle = firstTraits.style() == desiredTraits.style();
bool secondHasDesiredStyle = secondTraits.style() == desiredTraits.style();
if (firstHasDesiredStyle != secondHasDesiredStyle)
return firstHasDesiredStyle;
if (desiredTraits.style() == FontStyleItalic) {
// Prefer a font that has indicated that it can only support italics to a font that claims to support
// all styles. The specialized font is more likely to be the one the author wants used.
bool firstRequiresItalics = firstTraits.style() == FontStyleItalic;
bool secondRequiresItalics = secondTraits.style() == FontStyleItalic;
if (firstRequiresItalics != secondRequiresItalics)
return firstRequiresItalics;
}
if (secondTraits.weight() == desiredTraits.weight())
return false;
if (firstTraits.weight() == desiredTraits.weight())
return true;
// http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-matching-algorithm says :
// - If the desired weight is less than 400, weights below the desired weight are checked in descending order followed by weights above the desired weight in ascending order until a match is found.
// - If the desired weight is greater than 500, weights above the desired weight are checked in ascending order followed by weights below the desired weight in descending order until a match is found.
// - If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
// - If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.
static const unsigned fallbackRuleSets = 9;
static const unsigned rulesPerSet = 8;
static const FontWeight weightFallbackRuleSets[fallbackRuleSets][rulesPerSet] = {
{ FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900 },
{ FontWeight100, FontWeight300, FontWeight400, FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900 },
{ FontWeight200, FontWeight100, FontWeight400, FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900 },
{ FontWeight500, FontWeight300, FontWeight200, FontWeight100, FontWeight600, FontWeight700, FontWeight800, FontWeight900 },
{ FontWeight400, FontWeight300, FontWeight200, FontWeight100, FontWeight600, FontWeight700, FontWeight800, FontWeight900 },
{ FontWeight700, FontWeight800, FontWeight900, FontWeight500, FontWeight400, FontWeight300, FontWeight200, FontWeight100 },
{ FontWeight800, FontWeight900, FontWeight600, FontWeight500, FontWeight400, FontWeight300, FontWeight200, FontWeight100 },
{ FontWeight900, FontWeight700, FontWeight600, FontWeight500, FontWeight400, FontWeight300, FontWeight200, FontWeight100 },
{ FontWeight800, FontWeight700, FontWeight600, FontWeight500, FontWeight400, FontWeight300, FontWeight200, FontWeight100 }
};
unsigned ruleSetIndex = static_cast<unsigned>(desiredTraits.weight());
ASSERT(ruleSetIndex < fallbackRuleSets);
const FontWeight* weightFallbackRule = weightFallbackRuleSets[ruleSetIndex];
for (unsigned i = 0; i < rulesPerSet; ++i) {
if (secondTraits.weight() == weightFallbackRule[i])
return false;
if (firstTraits.weight() == weightFallbackRule[i])
return true;
}
return false;
}
CSSSegmentedFontFace* FontFaceCache::get(const FontDescription& fontDescription, const AtomicString& family)
{
TraitsMap* familyFontFaces = m_fontFaces.get(family);
if (!familyFontFaces || familyFontFaces->isEmpty())
return 0;
FamilyToTraitsMap::AddResult traitsResult = m_fonts.add(family, nullptr);
if (!traitsResult.storedValue->value)
traitsResult.storedValue->value = adoptPtr(new TraitsMap);
FontTraits traits = fontDescription.traits();
TraitsMap::AddResult faceResult = traitsResult.storedValue->value->add(traits.bitfield(), nullptr);
if (!faceResult.storedValue->value) {
for (TraitsMap::const_iterator i = familyFontFaces->begin(); i != familyFontFaces->end(); ++i) {
CSSSegmentedFontFace* candidate = i->value.get();
FontTraits candidateTraits = candidate->traits();
if (traits.style() == FontStyleNormal && candidateTraits.style() != FontStyleNormal)
continue;
if (traits.variant() == FontVariantNormal && candidateTraits.variant() != FontVariantNormal)
continue;
if (!faceResult.storedValue->value || compareFontFaces(candidate, faceResult.storedValue->value.get(), traits))
faceResult.storedValue->value = candidate;
}
}
return faceResult.storedValue->value.get();
}
}
/*
* Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_CORE_CSS_FONTFACECACHE_H_
#define SKY_ENGINE_CORE_CSS_FONTFACECACHE_H_
#include "sky/engine/platform/heap/Handle.h"
#include "sky/engine/wtf/Forward.h"
#include "sky/engine/wtf/HashMap.h"
#include "sky/engine/wtf/ListHashSet.h"
#include "sky/engine/wtf/text/StringHash.h"
namespace blink {
class FontFace;
class CSSFontSelector;
class CSSSegmentedFontFace;
class FontDescription;
class StyleRuleFontFace;
class FontFaceCache final {
DISALLOW_ALLOCATION();
public:
FontFaceCache();
void remove(const StyleRuleFontFace*);
void clearAll();
void removeFontFace(FontFace*, bool cssConnected);
// FIXME: It's sort of weird that add/remove uses StyleRuleFontFace* as key,
// but this function uses FontDescription/family pair.
CSSSegmentedFontFace* get(const FontDescription&, const AtomicString& family);
unsigned version() const { return m_version; }
void incrementVersion() { ++m_version; }
private:
typedef HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > TraitsMap;
typedef HashMap<String, OwnPtr<TraitsMap>, CaseFoldingHash> FamilyToTraitsMap;
FamilyToTraitsMap m_fontFaces;
FamilyToTraitsMap m_fonts;
// FIXME: See if this could be ditched
// Used to compare Font instances, and the usage seems suspect.
unsigned m_version;
};
}
#endif // SKY_ENGINE_CORE_CSS_FONTFACECACHE_H_
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
* Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
* Copyright (C) Research In Motion Limited 2011. All rights reserved.
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "sky/engine/core/css/FontSize.h"
#include <algorithm>
namespace blink {
float FontSize::getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize useSmartMinimumForFontSize)
{
// Text with a 0px font size should not be visible and therefore needs to be
// exempt from minimum font size rules. Acid3 relies on this for pixel-perfect
// rendering. This is also compatible with other browsers that have minimum
// font size settings (e.g. Firefox).
if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon())
return 0.0f;
// We support two types of minimum font size. The first is a hard override that applies to
// all fonts. This is "minSize." The second type of minimum font size is a "smart minimum"
// that is applied only when the Web page can't know what size it really asked for, e.g.,
// when it uses logical sizes like "small" or expresses the font-size as a percentage of
// the user's default font setting.
// With the smart minimum, we never want to get smaller than the minimum font size to keep fonts readable.
// However we always allow the page to set an explicit pixel size that is smaller,
// since sites will mis-render otherwise (e.g., http://www.gamespot.com with a 9px minimum).
int minSize = 0;
int minLogicalSize = 0;
// Apply the hard minimum first. We only apply the hard minimum if after zooming we're still too small.
if (specifiedSize < minSize)
specifiedSize = minSize;
// Now apply the "smart minimum." This minimum is also only applied if we're still too small
// after zooming. The font size must either be relative to the user default or the original size
// must have been acceptable. In other words, we only apply the smart minimum whenever we're positive
// doing so won't disrupt the layout.
if (useSmartMinimumForFontSize && specifiedSize < minLogicalSize && (specifiedSize >= minLogicalSize || !isAbsoluteSize))
specifiedSize = minLogicalSize;
// Also clamp to a reasonable maximum to prevent insane font sizes from causing crashes on various
// platforms (I'm looking at you, Windows.)
return specifiedSize;
}
} // namespace blink
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef SKY_ENGINE_CORE_CSS_FONTSIZE_H_
#define SKY_ENGINE_CORE_CSS_FONTSIZE_H_
#include <limits>
#include <math.h>
#include "sky/engine/platform/fonts/FixedPitchFontType.h"
namespace blink {
enum ESmartMinimumForFontSize { DoNotUseSmartMinimumForFontSize, UseSmartMinimumForFontFize };
class FontSize {
private:
FontSize() { }
public:
static float getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize = UseSmartMinimumForFontFize);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_CSS_FONTSIZE_H_
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "sky/engine/core/css/resolver/FontBuilder.h"
#include "sky/engine/core/css/FontSize.h"
#include "sky/engine/core/rendering/RenderTheme.h"
#include "sky/engine/core/rendering/RenderView.h"
#include "sky/engine/platform/fonts/FontDescription.h"
#include "sky/engine/platform/text/LocaleToScriptMapping.h"
namespace blink {
// FIXME: This scoping class is a short-term fix to minimize the changes in
// Font-constructing logic.
class FontDescriptionChangeScope {
STACK_ALLOCATED();
public:
FontDescriptionChangeScope(FontBuilder* fontBuilder)
: m_fontBuilder(fontBuilder)
, m_fontDescription(fontBuilder->m_style->fontDescription())
{
}
void reset() { m_fontDescription = FontDescription(); }
void set(const FontDescription& fontDescription) { m_fontDescription = fontDescription; }
FontDescription& fontDescription() { return m_fontDescription; }
~FontDescriptionChangeScope()
{
m_fontBuilder->didChangeFontParameters(m_fontBuilder->m_style->setFontDescription(m_fontDescription));
}
private:
RawPtr<FontBuilder> m_fontBuilder;
FontDescription m_fontDescription;
};
FontBuilder::FontBuilder()
: m_fontSizehasViewportUnits(false)
, m_style(0)
, m_fontDirty(false)
{
}
void FontBuilder::initForStyleResolve(RenderStyle* style)
{
m_style = style;
m_fontDirty = false;
}
void FontBuilder::inheritFrom(const FontDescription& fontDescription)
{
FontDescriptionChangeScope scope(this);
scope.set(fontDescription);
}
void FontBuilder::didChangeFontParameters(bool changed)
{
m_fontDirty |= changed;
}
void FontBuilder::setFontFamilyInitial()
{
FontDescriptionChangeScope scope(this);
}
void FontBuilder::setFontFamilyInherit(const FontDescription& parentFontDescription)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setGenericFamily(parentFontDescription.genericFamily());
scope.fontDescription().setFamily(parentFontDescription.family());
}
void FontBuilder::setFontSizeInherit(const FontDescription& parentFontDescription)
{
FontDescriptionChangeScope scope(this);
float size = parentFontDescription.specifiedSize();
if (size < 0)
return;
scope.fontDescription().setSpecifiedSize(size);
}
void FontBuilder::setWeight(FontWeight fontWeight)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setWeight(fontWeight);
}
void FontBuilder::setStretch(FontStretch fontStretch)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setStretch(fontStretch);
}
void FontBuilder::setScript(const String& locale)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setLocale(locale);
scope.fontDescription().setScript(localeToScriptCodeForFontSelection(locale));
}
void FontBuilder::setStyle(FontStyle italic)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setStyle(italic);
}
void FontBuilder::setVariant(FontVariant smallCaps)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setVariant(smallCaps);
}
void FontBuilder::setVariantLigatures(const FontDescription::VariantLigatures& ligatures)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setVariantLigatures(ligatures);
}
void FontBuilder::setTextRendering(TextRenderingMode textRenderingMode)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setTextRendering(textRenderingMode);
}
void FontBuilder::setKerning(FontDescription::Kerning kerning)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setKerning(kerning);
}
void FontBuilder::setFontSmoothing(FontSmoothingMode foontSmoothingMode)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setFontSmoothing(foontSmoothingMode);
}
void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setFeatureSettings(settings);
}
void FontBuilder::setSize(FontDescription& fontDescription, float size)
{
fontDescription.setSpecifiedSize(size);
fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, size));
}
float FontBuilder::getComputedSizeFromSpecifiedSize(FontDescription& fontDescription, float specifiedSize)
{
return FontSize::getComputedSizeFromSpecifiedSize(fontDescription.isAbsoluteSize(), specifiedSize);
}
static void getFontAndGlyphOrientation(const RenderStyle* style, FontOrientation& fontOrientation, NonCJKGlyphOrientation& glyphOrientation)
{
// FIXME(sky): Remove this function now that we don't have writing modes.
fontOrientation = Horizontal;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
}
void FontBuilder::checkForOrientationChange(RenderStyle* style)
{
FontOrientation fontOrientation;
NonCJKGlyphOrientation glyphOrientation;
getFontAndGlyphOrientation(style, fontOrientation, glyphOrientation);
FontDescriptionChangeScope scope(this);
if (scope.fontDescription().orientation() == fontOrientation && scope.fontDescription().nonCJKGlyphOrientation() == glyphOrientation)
return;
scope.fontDescription().setNonCJKGlyphOrientation(glyphOrientation);
scope.fontDescription().setOrientation(fontOrientation);
}
void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderStyle* parentStyle)
{
FontDescriptionChangeScope scope(this);
if (scope.fontDescription().isAbsoluteSize() || !parentStyle)
return;
const FontDescription& parentFontDescription = parentStyle->fontDescription();
if (scope.fontDescription().fixedPitchFontType() == parentFontDescription.fixedPitchFontType())
return;
// For now, lump all families but monospace together.
if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFamily
&& parentFontDescription.genericFamily() != FontDescription::MonospaceFamily)
return;
// We know the parent is monospace or the child is monospace, and that font
// size was unspecified. We want to scale our font size as appropriate.
// If the font uses a keyword size, then we refetch from the table rather than
// multiplying by our scale factor.
float fixedScaleFactor = 1.0f;
float size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ?
scope.fontDescription().specifiedSize() / fixedScaleFactor :
scope.fontDescription().specifiedSize() * fixedScaleFactor;
setSize(scope.fontDescription(), size);
}
void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* parentStyle)
{
FontDescriptionChangeScope scope(this);
float computedSize = getComputedSizeFromSpecifiedSize(scope.fontDescription(), scope.fontDescription().specifiedSize());
scope.fontDescription().setComputedSize(computedSize);
}
// FIXME: style param should come first
void FontBuilder::createFont(PassRefPtr<FontSelector> fontSelector, const RenderStyle* parentStyle, RenderStyle* style)
{
if (!m_fontDirty)
return;
updateComputedSize(style, parentStyle);
checkForGenericFamilyChange(style, parentStyle);
checkForOrientationChange(style);
style->font().update(fontSelector);
m_fontDirty = false;
}
void FontBuilder::createFontForDocument(PassRefPtr<FontSelector> fontSelector, RenderStyle* documentStyle)
{
FontDescription fontDescription = FontDescription();
fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle->locale()));
// Using 14px default to match Material Design English Body1:
// http://www.google.com/design/spec/style/typography.html#typography-typeface
const int defaultFontSize = 14;
fontDescription.setSpecifiedSize(defaultFontSize);
fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, defaultFontSize));
FontOrientation fontOrientation;
NonCJKGlyphOrientation glyphOrientation;
getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation);
fontDescription.setOrientation(fontOrientation);
fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
documentStyle->setFontDescription(fontDescription);
documentStyle->font().update(fontSelector);
}
}
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef SKY_ENGINE_CORE_CSS_RESOLVER_FONTBUILDER_H_
#define SKY_ENGINE_CORE_CSS_RESOLVER_FONTBUILDER_H_
#include "sky/engine/platform/fonts/FontDescription.h"
#include "sky/engine/platform/heap/Handle.h"
#include "sky/engine/wtf/PassRefPtr.h"
namespace blink {
class FontSelector;
class RenderStyle;
class FontDescriptionChangeScope;
class FontBuilder {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(FontBuilder);
public:
FontBuilder();
// FIXME: The name is probably wrong, but matches StyleResolverState callsite for consistency.
void initForStyleResolve(RenderStyle*);
void didChangeFontParameters(bool);
void inheritFrom(const FontDescription&);
void setFontFamilyInitial();
void setFontFamilyInherit(const FontDescription&);
void setFontSizeInherit(const FontDescription&);
void setWeight(FontWeight);
void setStretch(FontStretch);
void setFeatureSettings(PassRefPtr<FontFeatureSettings>);
void setScript(const String& locale);
void setStyle(FontStyle);
void setVariant(FontVariant);
void setVariantLigatures(const FontDescription::VariantLigatures&);
void setTextRendering(TextRenderingMode);
void setKerning(FontDescription::Kerning);
void setFontSmoothing(FontSmoothingMode);
// FIXME: These need to just vend a Font object eventually.
void createFont(PassRefPtr<FontSelector>, const RenderStyle* parentStyle, RenderStyle*);
// FIXME: This is nearly static, should either made fully static or decomposed into
// FontBuilder calls at the callsite.
void createFontForDocument(PassRefPtr<FontSelector>, RenderStyle*);
bool fontSizeHasViewportUnits() { return m_fontSizehasViewportUnits; }
// FIXME: This is only used by an ASSERT in StyleResolver. Remove?
bool fontDirty() const { return m_fontDirty; }
static FontFeatureSettings* initialFeatureSettings() { return nullptr; }
static FontDescription::GenericFamilyType initialGenericFamily() { return FontDescription::NoFamily; }
static TextRenderingMode initialTextRendering() { return AutoTextRendering; }
static FontVariant initialVariant() { return FontVariantNormal; }
static FontDescription::VariantLigatures initialVariantLigatures() { return FontDescription::VariantLigatures(); }
static FontStyle initialStyle() { return FontStyleNormal; }
static FontDescription::Kerning initialKerning() { return FontDescription::AutoKerning; }
static FontSmoothingMode initialFontSmoothing() { return AutoSmoothing; }
static FontStretch initialStretch() { return FontStretchNormal; }
static FontWeight initialWeight() { return FontWeightNormal; }
friend class FontDescriptionChangeScope;
private:
// FIXME: "size" arg should be first for consistency with other similar functions.
void setSize(FontDescription&, float size);
void checkForOrientationChange(RenderStyle*);
// This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
void checkForGenericFamilyChange(RenderStyle*, const RenderStyle* parentStyle);
void updateComputedSize(RenderStyle*, const RenderStyle* parentStyle);
float getComputedSizeFromSpecifiedSize(FontDescription&, float specifiedSize);
bool m_fontSizehasViewportUnits;
// FIXME: This member is here on a short-term lease. The plan is to remove
// any notion of RenderStyle from here, allowing FontBuilder to build Font objects
// directly, rather than as a byproduct of calling RenderStyle::setFontDescription.
// FontDescriptionChangeScope should be the only consumer of this member.
// If you're using it, U R DOIN IT WRONG.
RenderStyle* m_style;
// Fontbuilder is responsbile for creating the Font()
// object on RenderStyle from various other font-related
// properties on RenderStyle. Whenever one of those
// is changed, FontBuilder tracks the need to update
// style->font() with this bool.
bool m_fontDirty;
friend class FontBuilderTest;
};
}
#endif // SKY_ENGINE_CORE_CSS_RESOLVER_FONTBUILDER_H_
......@@ -5,8 +5,8 @@
#ifndef SKY_ENGINE_CORE_RENDERING_STYLE_APPLIEDTEXTDECORATION_H_
#define SKY_ENGINE_CORE_RENDERING_STYLE_APPLIEDTEXTDECORATION_H_
#include "sky/engine/core/css/StyleColor.h"
#include "sky/engine/core/rendering/style/RenderStyleConstants.h"
#include "sky/engine/core/rendering/style/StyleColor.h"
namespace blink {
......
......@@ -25,8 +25,8 @@
#ifndef SKY_ENGINE_CORE_RENDERING_STYLE_BORDERVALUE_H_
#define SKY_ENGINE_CORE_RENDERING_STYLE_BORDERVALUE_H_
#include "sky/engine/core/css/StyleColor.h"
#include "sky/engine/core/rendering/style/RenderStyleConstants.h"
#include "sky/engine/core/rendering/style/StyleColor.h"
#include "sky/engine/platform/graphics/Color.h"
namespace blink {
......
......@@ -28,8 +28,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_CORE_CSS_STYLECOLOR_H_
#define SKY_ENGINE_CORE_CSS_STYLECOLOR_H_
#ifndef SKY_ENGINE_CORE_RENDERING_STYLE_STYLECOLOR_H_
#define SKY_ENGINE_CORE_RENDERING_STYLE_STYLECOLOR_H_
#include "sky/engine/platform/graphics/Color.h"
......@@ -66,4 +66,4 @@ inline bool operator!=(const StyleColor& a, const StyleColor& b)
} // namespace blink
#endif // SKY_ENGINE_CORE_CSS_STYLECOLOR_H_
#endif // SKY_ENGINE_CORE_RENDERING_STYLE_STYLECOLOR_H_
......@@ -25,8 +25,8 @@
#ifndef SKY_ENGINE_CORE_RENDERING_STYLE_STYLERAREINHERITEDDATA_H_
#define SKY_ENGINE_CORE_RENDERING_STYLE_STYLERAREINHERITEDDATA_H_
#include "sky/engine/core/css/StyleColor.h"
#include "sky/engine/core/rendering/style/DataRef.h"
#include "sky/engine/core/rendering/style/StyleColor.h"
#include "sky/engine/platform/Length.h"
#include "sky/engine/platform/graphics/Color.h"
#include "sky/engine/wtf/PassRefPtr.h"
......
......@@ -25,13 +25,13 @@
#ifndef SKY_ENGINE_CORE_RENDERING_STYLE_STYLERARENONINHERITEDDATA_H_
#define SKY_ENGINE_CORE_RENDERING_STYLE_STYLERARENONINHERITEDDATA_H_
#include "sky/engine/core/css/StyleColor.h"
#include "sky/engine/core/rendering/ClipPathOperation.h"
#include "sky/engine/core/rendering/style/CounterDirectives.h"
#include "sky/engine/core/rendering/style/DataRef.h"
#include "sky/engine/core/rendering/style/FillLayer.h"
#include "sky/engine/core/rendering/style/RenderStyleConstants.h"
#include "sky/engine/core/rendering/style/ShapeValue.h"
#include "sky/engine/core/rendering/style/StyleColor.h"
#include "sky/engine/platform/LengthPoint.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/PassRefPtr.h"
......
......@@ -4,11 +4,11 @@
#include "sky/engine/core/text/ParagraphBuilder.h"
#include "sky/engine/core/css/FontSize.h"
#include "sky/engine/core/rendering/RenderInline.h"
#include "sky/engine/core/rendering/RenderParagraph.h"
#include "sky/engine/core/rendering/RenderText.h"
#include "sky/engine/core/rendering/style/RenderStyle.h"
#include "sky/engine/platform/text/LocaleToScriptMapping.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
......@@ -28,6 +28,34 @@ RenderParagraph* createRenderParagraph(RenderStyle* parentStyle)
return renderParagraph;
}
float getComputedSizeFromSpecifiedSize(float specifiedSize)
{
if (specifiedSize < std::numeric_limits<float>::epsilon())
return 0.0f;
return specifiedSize;
}
void createFontForDocument(RenderStyle* style)
{
FontDescription fontDescription = FontDescription();
fontDescription.setScript(localeToScriptCodeForFontSelection(style->locale()));
// Using 14px default to match Material Design English Body1:
// http://www.google.com/design/spec/style/typography.html#typography-typeface
const float defaultFontSize = 14.0;
fontDescription.setSpecifiedSize(defaultFontSize);
fontDescription.setComputedSize(defaultFontSize);
FontOrientation fontOrientation = Horizontal;
NonCJKGlyphOrientation glyphOrientation = NonCJKGlyphOrientationVerticalRight;
fontDescription.setOrientation(fontOrientation);
fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
style->setFontDescription(fontDescription);
style->font().update(nullptr);
}
Color getColorFromARGB(int argb) {
return Color(
(argb & 0x00FF0000) >> 16,
......@@ -94,7 +122,6 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
ParagraphBuilder::ParagraphBuilder()
{
m_fontSelector = CSSFontSelector::create();
createRenderView();
m_renderParagraph = createRenderParagraph(m_renderView->style());
m_currentRenderObject = m_renderParagraph;
......@@ -145,14 +172,14 @@ void ParagraphBuilder::pushStyle(Int32List& encoded, const String& fontFamily, d
if (mask & kFontSizeMask) {
fontDescription.setSpecifiedSize(fontSize);
fontDescription.setIsAbsoluteSize(true);
fontDescription.setComputedSize(FontSize::getComputedSizeFromSpecifiedSize(true, fontSize));
fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontSize));
}
if (mask & kLetterSpacingMask)
fontDescription.setLetterSpacing(letterSpacing);
style->setFontDescription(fontDescription);
style->font().update(m_fontSelector);
style->font().update(nullptr);
}
encoded.Release();
......@@ -214,10 +241,7 @@ void ParagraphBuilder::createRenderView()
style->setRTLOrdering(LogicalOrder);
style->setZIndex(0);
style->setUserModify(READ_ONLY);
FontBuilder fontBuilder;
fontBuilder.initForStyleResolve(style.get());
fontBuilder.createFontForDocument(m_fontSelector.get(), style.get());
createFontForDocument(style.get());
m_renderView = adoptPtr(new RenderView());
m_renderView->setStyle(style.release());
......
......@@ -5,8 +5,6 @@
#ifndef SKY_ENGINE_CORE_TEXT_PARAGRAPHBUILDER_H_
#define SKY_ENGINE_CORE_TEXT_PARAGRAPHBUILDER_H_
#include "sky/engine/core/css/CSSFontSelector.h"
#include "sky/engine/core/css/resolver/FontBuilder.h"
#include "sky/engine/core/text/Paragraph.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/int32_list.h"
......@@ -39,7 +37,6 @@ private:
void createRenderView();
RefPtr<CSSFontSelector> m_fontSelector;
OwnPtr<RenderView> m_renderView;
RenderObject* m_renderParagraph;
RenderObject* m_currentRenderObject;
......
......@@ -12,24 +12,6 @@ visibility = [ ":*" ]
sky_platform_output_dir = "$root_gen_dir/sky/platform"
action("font_family_names") {
script = "../build/scripts/make_names.py"
font_family_names_in = "fonts/FontFamilyNames.in"
inputs = make_names_files + [ font_family_names_in ]
outputs = [
"$sky_platform_output_dir/FontFamilyNames.cpp",
"$sky_platform_output_dir/FontFamilyNames.h",
]
args = [
rebase_path(font_family_names_in, root_build_dir),
"--output_dir",
rebase_path(sky_platform_output_dir, root_build_dir),
]
}
action("runtime_enabled_features") {
script = "../build/scripts/make_runtime_features.py"
......@@ -55,7 +37,6 @@ action("runtime_enabled_features") {
group("make_platform_generated") {
visibility += [ ":*" ]
deps = [
":font_family_names",
":runtime_enabled_features",
]
}
......@@ -179,8 +160,6 @@ source_set("platform") {
"fonts/FontSmoothingMode.h",
"fonts/FontTraits.h",
"fonts/FontWidthVariant.h",
"fonts/GenericFontFamilySettings.cpp",
"fonts/GenericFontFamilySettings.h",
"fonts/Glyph.h",
"fonts/GlyphBuffer.h",
"fonts/GlyphMetricsMap.h",
......@@ -483,8 +462,7 @@ source_set("platform") {
}
# Add in the generated files.
sources += get_target_outputs(":font_family_names") +
get_target_outputs(":runtime_enabled_features")
sources += get_target_outputs(":runtime_enabled_features")
configs += [
"//sky/engine:config",
......
......@@ -29,8 +29,6 @@
#include "sky/engine/platform/fonts/FontCache.h"
#include "gen/sky/platform/FontFamilyNames.h"
#include "gen/sky/platform/RuntimeEnabledFeatures.h"
#include "sky/engine/platform/fonts/AlternateFontFamily.h"
#include "sky/engine/platform/fonts/FontCacheClient.h"
......
......@@ -25,7 +25,6 @@
#ifndef SKY_ENGINE_PLATFORM_FONTS_FONTDESCRIPTION_H_
#define SKY_ENGINE_PLATFORM_FONTS_FONTDESCRIPTION_H_
#include "gen/sky/platform/FontFamilyNames.h"
#include "sky/engine/platform/fonts/FixedPitchFontType.h"
#include "sky/engine/platform/fonts/FontCacheKey.h"
#include "sky/engine/platform/fonts/FontFamily.h"
......@@ -116,13 +115,6 @@ public:
static FontWeight bolderWeight(FontWeight);
GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
// only use fixed default size when there is only one font family, and that family is "monospace"
FixedPitchFontType fixedPitchFontType() const
{
if (genericFamily() == MonospaceFamily && !family().next() && family().family() == FontFamilyNames::webkit_monospace)
return FixedPitchFont;
return NonFixedPitchFont;
}
Kerning kerning() const { return static_cast<Kerning>(m_kerning); }
VariantLigatures variantLigatures() const;
LigaturesState commonLigaturesState() const { return static_cast<LigaturesState>(m_commonLigaturesState); }
......
......@@ -28,7 +28,6 @@
#include "sky/engine/platform/fonts/FontFallbackList.h"
#include "gen/sky/platform/FontFamilyNames.h"
#include "sky/engine/platform/fonts/FontCache.h"
#include "sky/engine/platform/fonts/FontDescription.h"
#include "sky/engine/platform/fonts/FontFamily.h"
......@@ -204,15 +203,6 @@ PassRefPtr<FontData> FontFallbackList::getFontData(const FontDescription& fontDe
if (result || startIndex)
return result.release();
// If it's the primary font that we couldn't find, we try the following. In all other cases, we will
// just use per-character system fallback.
if (m_fontSelector) {
// Try the user's preferred standard font.
if (RefPtr<FontData> data = m_fontSelector->getFontData(fontDescription, FontFamilyNames::webkit_standard))
return data.release();
}
// Still no result. Hand back our last resort fallback font.
return FontCache::fontCache()->getLastResortFallbackFont(fontDescription);
}
......
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/platform/fonts/GenericFontFamilySettings.h"
namespace blink {
GenericFontFamilySettings::GenericFontFamilySettings(const GenericFontFamilySettings& other)
: m_standardFontFamilyMap(other.m_standardFontFamilyMap)
, m_serifFontFamilyMap(other.m_serifFontFamilyMap)
, m_fixedFontFamilyMap(other.m_fixedFontFamilyMap)
, m_sansSerifFontFamilyMap(other.m_sansSerifFontFamilyMap)
, m_cursiveFontFamilyMap(other.m_cursiveFontFamilyMap)
, m_fantasyFontFamilyMap(other.m_fantasyFontFamilyMap)
, m_pictographFontFamilyMap(other.m_pictographFontFamilyMap)
{
}
GenericFontFamilySettings& GenericFontFamilySettings::operator=(const GenericFontFamilySettings& other)
{
m_standardFontFamilyMap = other.m_standardFontFamilyMap;
m_serifFontFamilyMap = other.m_serifFontFamilyMap;
m_fixedFontFamilyMap = other.m_fixedFontFamilyMap;
m_sansSerifFontFamilyMap = other.m_sansSerifFontFamilyMap;
m_cursiveFontFamilyMap = other.m_cursiveFontFamilyMap;
m_fantasyFontFamilyMap = other.m_fantasyFontFamilyMap;
m_pictographFontFamilyMap = other.m_pictographFontFamilyMap;
return *this;
}
// Sets the entry in the font map for the given script. If family is the empty string, removes the entry instead.
void GenericFontFamilySettings::setGenericFontFamilyMap(ScriptFontFamilyMap& fontMap, const AtomicString& family, UScriptCode script)
{
ScriptFontFamilyMap::iterator it = fontMap.find(static_cast<int>(script));
if (family.isEmpty()) {
if (it == fontMap.end())
return;
fontMap.remove(it);
} else if (it != fontMap.end() && it->value == family) {
return;
} else {
fontMap.set(static_cast<int>(script), family);
}
}
const AtomicString& GenericFontFamilySettings::genericFontFamilyForScript(const ScriptFontFamilyMap& fontMap, UScriptCode script) const
{
ScriptFontFamilyMap::const_iterator it = fontMap.find(static_cast<int>(script));
if (it != fontMap.end())
return it->value;
if (script != USCRIPT_COMMON)
return genericFontFamilyForScript(fontMap, USCRIPT_COMMON);
return emptyAtom;
}
const AtomicString& GenericFontFamilySettings::standard(UScriptCode script) const
{
return genericFontFamilyForScript(m_standardFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateStandard(const AtomicString& family, UScriptCode script)
{
if (family == standard())
return false;
setGenericFontFamilyMap(m_standardFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::fixed(UScriptCode script) const
{
return genericFontFamilyForScript(m_fixedFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateFixed(const AtomicString& family, UScriptCode script)
{
if (family == fixed())
return false;
setGenericFontFamilyMap(m_fixedFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::serif(UScriptCode script) const
{
return genericFontFamilyForScript(m_serifFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateSerif(const AtomicString& family, UScriptCode script)
{
if (family == serif())
return false;
setGenericFontFamilyMap(m_serifFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::sansSerif(UScriptCode script) const
{
return genericFontFamilyForScript(m_sansSerifFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateSansSerif(const AtomicString& family, UScriptCode script)
{
if (family == sansSerif())
return false;
setGenericFontFamilyMap(m_sansSerifFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::cursive(UScriptCode script) const
{
return genericFontFamilyForScript(m_cursiveFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateCursive(const AtomicString& family, UScriptCode script)
{
if (family == cursive())
return false;
setGenericFontFamilyMap(m_cursiveFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::fantasy(UScriptCode script) const
{
return genericFontFamilyForScript(m_fantasyFontFamilyMap, script);
}
bool GenericFontFamilySettings::updateFantasy(const AtomicString& family, UScriptCode script)
{
if (family == fantasy())
return false;
setGenericFontFamilyMap(m_fantasyFontFamilyMap, family, script);
return true;
}
const AtomicString& GenericFontFamilySettings::pictograph(UScriptCode script) const
{
return genericFontFamilyForScript(m_pictographFontFamilyMap, script);
}
bool GenericFontFamilySettings::updatePictograph(const AtomicString& family, UScriptCode script)
{
if (family == pictograph())
return false;
setGenericFontFamilyMap(m_pictographFontFamilyMap, family, script);
return true;
}
void GenericFontFamilySettings::reset()
{
m_standardFontFamilyMap.clear();
m_serifFontFamilyMap.clear();
m_fixedFontFamilyMap.clear();
m_sansSerifFontFamilyMap.clear();
m_cursiveFontFamilyMap.clear();
m_fantasyFontFamilyMap.clear();
m_pictographFontFamilyMap.clear();
}
} // namespace blink
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_FONTS_GENERICFONTFAMILYSETTINGS_H_
#define SKY_ENGINE_PLATFORM_FONTS_GENERICFONTFAMILYSETTINGS_H_
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/wtf/HashMap.h"
#include "sky/engine/wtf/text/AtomicString.h"
#include "sky/engine/wtf/text/AtomicStringHash.h"
#include <unicode/uscript.h>
namespace blink {
class PLATFORM_EXPORT GenericFontFamilySettings {
WTF_MAKE_FAST_ALLOCATED;
public:
GenericFontFamilySettings()
{
}
explicit GenericFontFamilySettings(const GenericFontFamilySettings&);
bool updateStandard(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& standard(UScriptCode = USCRIPT_COMMON) const;
bool updateFixed(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& fixed(UScriptCode = USCRIPT_COMMON) const;
bool updateSerif(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& serif(UScriptCode = USCRIPT_COMMON) const;
bool updateSansSerif(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& sansSerif(UScriptCode = USCRIPT_COMMON) const;
bool updateCursive(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& cursive(UScriptCode = USCRIPT_COMMON) const;
bool updateFantasy(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& fantasy(UScriptCode = USCRIPT_COMMON) const;
bool updatePictograph(const AtomicString&, UScriptCode = USCRIPT_COMMON);
const AtomicString& pictograph(UScriptCode = USCRIPT_COMMON) const;
// Only called by InternalSettings to clear font family maps.
void reset();
GenericFontFamilySettings& operator=(const GenericFontFamilySettings&);
private:
// UScriptCode uses -1 and 0 for UScriptInvalidCode and UScriptCommon.
// We need to use -2 and -3 for empty value and deleted value.
struct UScriptCodeHashTraits : WTF::GenericHashTraits<int> {
static const bool emptyValueIsZero = false;
static int emptyValue() { return -2; }
static void constructDeletedValue(int& slot, bool) { slot = -3; }
static bool isDeletedValue(int value) { return value == -3; }
};
typedef HashMap<int, AtomicString, DefaultHash<int>::Hash, UScriptCodeHashTraits> ScriptFontFamilyMap;
void setGenericFontFamilyMap(ScriptFontFamilyMap&, const AtomicString&, UScriptCode);
const AtomicString& genericFontFamilyForScript(const ScriptFontFamilyMap&, UScriptCode) const;
ScriptFontFamilyMap m_standardFontFamilyMap;
ScriptFontFamilyMap m_serifFontFamilyMap;
ScriptFontFamilyMap m_fixedFontFamilyMap;
ScriptFontFamilyMap m_sansSerifFontFamilyMap;
ScriptFontFamilyMap m_cursiveFontFamilyMap;
ScriptFontFamilyMap m_fantasyFontFamilyMap;
ScriptFontFamilyMap m_pictographFontFamilyMap;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_FONTS_GENERICFONTFAMILYSETTINGS_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册