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

Unified Diff: third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp

Issue 2427773002: Fixing superscript and subscript baseline for tiny fonts in SVG
Patch Set: Rebaseline layout tests. Created 4 years, 1 month 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 | « third_party/WebKit/Source/platform/fonts/SimpleFontData.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp b/third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp
index fbd7abc24615d9ccf030fb99fbf747c994e31ee2..2c66c022bbdf688af773a3aa029358e84ae599a8 100644
--- a/third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp
+++ b/third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp
@@ -130,6 +130,13 @@ void SimpleFontData::platformInit(bool subpixelAscentDescent) {
float ascent;
float descent;
+ // For tiny fonts, the rounding of fAscent and fDescent results in equal
+ // baseline for different types of text baselines (crbug.com/338908).
+ // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic.
+ subpixelAscentDescent =
eae 2016/11/04 18:25:28 Please use a different name here to avoid the appe
zakerinasab 2016/11/07 18:40:26 Done.
+ subpixelAscentDescent &&
+ (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2);
+
// Beware those who step here: This code is designed to match Win32 font
// metrics *exactly* except:
// - the adjustment of ascent/descent on Linux/Android
@@ -138,17 +145,10 @@ void SimpleFontData::platformInit(bool subpixelAscentDescent) {
ascent = vdmxAscent;
descent = -vdmxDescent;
} else {
- // For tiny fonts, the rounding of fAscent and fDescent results in equal
- // baseline for different types of text baselines (crbug.com/338908).
- // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic.
- if (subpixelAscentDescent &&
- (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2)) {
- ascent = -metrics.fAscent;
- descent = metrics.fDescent;
- } else {
- ascent = SkScalarRoundToScalar(-metrics.fAscent);
- descent = SkScalarRoundToScalar(metrics.fDescent);
- }
+ ascent = subpixelAscentDescent ? -metrics.fAscent
+ : SkScalarRoundToScalar(-metrics.fAscent);
+ descent = subpixelAscentDescent ? metrics.fDescent
+ : SkScalarRoundToScalar(metrics.fDescent);
#if OS(LINUX) || OS(ANDROID)
// When subpixel positioning is enabled, if the descent is rounded down, the
// descent part of the glyph may be truncated when displayed in a 'overflow:
@@ -176,8 +176,11 @@ void SimpleFontData::platformInit(bool subpixelAscentDescent) {
DEFINE_STATIC_LOCAL(AtomicString, courierName, ("Courier"));
String familyName = m_platformData.fontFamilyName();
if (familyName == timesName || familyName == helveticaName ||
- familyName == courierName)
- ascent += floorf(((ascent + descent) * 0.15f) + 0.5f);
+ familyName == courierName) {
+ ascent += subpixelAscentDescent
+ ? ((ascent + descent) * 0.15f)
+ : floorf(((ascent + descent) * 0.15f) + 0.5f);
+ }
#endif
m_fontMetrics.setAscent(ascent);
@@ -348,6 +351,12 @@ PassRefPtr<SimpleFontData> SimpleFontData::emphasisMarkFontData(
return m_derivedFontData->emphasisMark;
}
+PassRefPtr<SimpleFontData> SimpleFontData::subpixelAscentDescentFontData()
+ const {
+ return SimpleFontData::create(m_platformData, m_customFontData,
+ m_isTextOrientationFallback, true);
+}
+
bool SimpleFontData::isTextOrientationFallbackOf(
const SimpleFontData* fontData) const {
if (!isTextOrientationFallback() || !fontData->m_derivedFontData)
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/SimpleFontData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698