Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: Source/core/css/resolver/FontBuilder.cpp

Issue 943463002: Initial implementation of font-size-adjust (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add some tests which need a rebaseline to TestExpectation Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/resolver/FontBuilder.h ('k') | Source/core/css/resolver/StyleBuilderConverter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/resolver/FontBuilder.cpp
diff --git a/Source/core/css/resolver/FontBuilder.cpp b/Source/core/css/resolver/FontBuilder.cpp
index 1d5e9921b2434724f851344606e2a155cf9fcf5b..f4ac93595588604e94b3f5118cb37d9e43b2199b 100644
--- a/Source/core/css/resolver/FontBuilder.cpp
+++ b/Source/core/css/resolver/FontBuilder.cpp
@@ -2,6 +2,7 @@
* 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.
+ * Copyright (C) 2015 Collabora Ltd. 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
@@ -123,6 +124,13 @@ void FontBuilder::setSize(const FontDescription::Size& size)
setSize(m_fontDescription, size);
}
+void FontBuilder::setSizeAdjust(float aspectValue)
+{
+ set(PropertySetFlag::SizeAdjust);
+
+ m_fontDescription.setSizeAdjust(aspectValue);
+}
+
void FontBuilder::setStretch(FontStretch fontStretch)
{
set(PropertySetFlag::Stretch);
@@ -319,6 +327,29 @@ void FontBuilder::updateSpecifiedSize(FontDescription& fontDescription, const La
checkForGenericFamilyChange(style.fontDescription(), fontDescription);
}
+void FontBuilder::updateAdjustedSize(FontDescription& fontDescription, const LayoutStyle& style, FontSelector* fontSelector)
+{
+ const float sizeAdjust = fontDescription.sizeAdjust();
+ const float specifiedSize = fontDescription.specifiedSize();
+ if (!sizeAdjust || !specifiedSize)
+ return;
+
+ // We need to create a temporal Font to get xHeight of a primary font.
+ Font font(fontDescription);
+ font.update(fontSelector);
+ if (!font.fontMetrics().hasXHeight())
+ return;
+
+ float aspectValue = font.fontMetrics().xHeight() / specifiedSize;
+ float adjustedSize = (sizeAdjust / aspectValue) * specifiedSize;
+ adjustedSize = getComputedSizeFromSpecifiedSize(fontDescription, style.effectiveZoom(), adjustedSize);
+
+ float multiplier = style.textAutosizingMultiplier();
+ if (multiplier > 1)
+ adjustedSize = TextAutosizer::computeAutosizedFontSize(adjustedSize, multiplier);
+ fontDescription.setAdjustedSize(adjustedSize);
+}
+
void FontBuilder::updateComputedSize(FontDescription& fontDescription, const LayoutStyle& style)
{
float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style.effectiveZoom(), fontDescription.specifiedSize());
@@ -344,6 +375,8 @@ void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector,
description.setSpecifiedSize(m_fontDescription.specifiedSize());
description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize());
}
+ if (isSet(PropertySetFlag::SizeAdjust))
+ description.setSizeAdjust(m_fontDescription.sizeAdjust());
if (isSet(PropertySetFlag::Weight))
description.setWeight(m_fontDescription.weight());
if (isSet(PropertySetFlag::Stretch))
@@ -371,6 +404,7 @@ void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector,
updateSpecifiedSize(description, style);
updateComputedSize(description, style);
+ updateAdjustedSize(description, style, fontSelector.get());
style.setFontDescription(description);
style.font().update(fontSelector);
« no previous file with comments | « Source/core/css/resolver/FontBuilder.h ('k') | Source/core/css/resolver/StyleBuilderConverter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698