| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov | 3 * Copyright (C) 2006 Alexey Proskuryakov |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const float smallCapsFontSizeMultiplier = 0.7f; | 50 const float smallCapsFontSizeMultiplier = 0.7f; |
| 51 const float emphasisMarkFontSizeMultiplier = 0.5f; | 51 const float emphasisMarkFontSizeMultiplier = 0.5f; |
| 52 | 52 |
| 53 #if OS(LINUX) || OS(ANDROID) | 53 #if OS(LINUX) || OS(ANDROID) |
| 54 // This is the largest VDMX table which we'll try to load and parse. | 54 // This is the largest VDMX table which we'll try to load and parse. |
| 55 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB | 55 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, | 58 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, |
| 59 PassRefPtr<CustomFontData> customData, | 59 PassRefPtr<CustomFontData> customData, |
| 60 bool isTextOrientationFallback, | 60 bool isTextOrientationFallback) |
| 61 bool subpixelAscentDescent) | |
| 62 : m_maxCharWidth(-1), | 61 : m_maxCharWidth(-1), |
| 63 m_avgCharWidth(-1), | 62 m_avgCharWidth(-1), |
| 64 m_platformData(platformData), | 63 m_platformData(platformData), |
| 65 m_isTextOrientationFallback(isTextOrientationFallback), | 64 m_isTextOrientationFallback(isTextOrientationFallback), |
| 66 m_verticalData(nullptr), | 65 m_verticalData(nullptr), |
| 67 m_hasVerticalGlyphs(false), | 66 m_hasVerticalGlyphs(false), |
| 68 m_customFontData(std::move(customData)) { | 67 m_customFontData(std::move(customData)) { |
| 69 platformInit(subpixelAscentDescent); | 68 platformInit(); |
| 70 platformGlyphInit(); | 69 platformGlyphInit(); |
| 71 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { | 70 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { |
| 72 m_verticalData = platformData.verticalData(); | 71 m_verticalData = platformData.verticalData(); |
| 73 m_hasVerticalGlyphs = | 72 m_hasVerticalGlyphs = |
| 74 m_verticalData.get() && m_verticalData->hasVerticalMetrics(); | 73 m_verticalData.get() && m_verticalData->hasVerticalMetrics(); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, | 77 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, |
| 79 PassRefPtr<OpenTypeVerticalData> verticalData) | 78 PassRefPtr<OpenTypeVerticalData> verticalData) |
| 80 : m_platformData(platformData), | 79 : m_platformData(platformData), |
| 81 m_isTextOrientationFallback(false), | 80 m_isTextOrientationFallback(false), |
| 82 m_verticalData(verticalData), | 81 m_verticalData(verticalData), |
| 83 m_hasVerticalGlyphs(false) {} | 82 m_hasVerticalGlyphs(false) {} |
| 84 | 83 |
| 85 void SimpleFontData::platformInit(bool subpixelAscentDescent) { | 84 void SimpleFontData::platformInit() { |
| 86 if (!m_platformData.size()) { | 85 if (!m_platformData.size()) { |
| 87 m_fontMetrics.reset(); | 86 m_fontMetrics.reset(); |
| 88 m_avgCharWidth = 0; | 87 m_avgCharWidth = 0; |
| 89 m_maxCharWidth = 0; | 88 m_maxCharWidth = 0; |
| 90 return; | 89 return; |
| 91 } | 90 } |
| 92 | 91 |
| 93 SkPaint::FontMetrics metrics; | 92 SkPaint::FontMetrics metrics; |
| 94 | 93 |
| 95 m_platformData.setupPaint(&m_paint); | 94 m_platformData.setupPaint(&m_paint); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 126 float ascent; | 125 float ascent; |
| 127 float descent; | 126 float descent; |
| 128 | 127 |
| 129 // Beware those who step here: This code is designed to match Win32 font | 128 // Beware those who step here: This code is designed to match Win32 font |
| 130 // metrics *exactly* except: | 129 // metrics *exactly* except: |
| 131 // - the adjustment of ascent/descent on Linux/Android | 130 // - the adjustment of ascent/descent on Linux/Android |
| 132 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts | 131 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts |
| 133 if (isVDMXValid) { | 132 if (isVDMXValid) { |
| 134 ascent = vdmxAscent; | 133 ascent = vdmxAscent; |
| 135 descent = -vdmxDescent; | 134 descent = -vdmxDescent; |
| 136 } else if (subpixelAscentDescent && | 135 } else { |
| 137 (-metrics.fAscent < 3 || | |
| 138 -metrics.fAscent + metrics.fDescent < 2)) { | |
| 139 // For tiny fonts, the rounding of fAscent and fDescent results in equal | |
| 140 // baseline for different types of text baselines (crbug.com/338908). | |
| 141 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. | |
| 142 ascent = -metrics.fAscent; | 136 ascent = -metrics.fAscent; |
| 143 descent = metrics.fDescent; | 137 descent = metrics.fDescent; |
| 144 } else { | |
| 145 ascent = SkScalarRoundToScalar(-metrics.fAscent); | |
| 146 descent = SkScalarRoundToScalar(metrics.fDescent); | |
| 147 | |
| 148 int overflowInflationForAscent = ascent < -metrics.fAscent ? 1 : 0; | |
| 149 int overflowInflationForDescent = descent < metrics.fDescent ? 1 : 0; | |
| 150 if (overflowInflationForDescent) { | |
| 151 #if OS(LINUX) || OS(ANDROID) | |
| 152 // When subpixel positioning is enabled, if the descent is rounded down, | |
| 153 // the descent part of the glyph may be truncated when displayed in a | |
| 154 // 'overflow: hidden' container. To avoid that, borrow 1 unit from the | |
| 155 // ascent when possible. | |
| 156 if (platformData().getFontRenderStyle().useSubpixelPositioning && | |
| 157 ascent >= 1) { | |
| 158 ++descent; | |
| 159 --ascent; | |
| 160 // We should inflate overflow 1 more pixel for ascent instead. | |
| 161 overflowInflationForDescent = 0; | |
| 162 ++overflowInflationForAscent; | |
| 163 } | |
| 164 #endif | |
| 165 } | |
| 166 m_fontMetrics.setVisualOverflowInflations(overflowInflationForAscent, | |
| 167 overflowInflationForDescent); | |
| 168 } | 138 } |
| 169 | 139 |
| 170 #if OS(MACOSX) | 140 #if OS(MACOSX) |
| 171 // We are preserving this ascent hack to match Safari's ascent adjustment | 141 // We are preserving this ascent hack to match Safari's ascent adjustment |
| 172 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. | 142 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. |
| 173 // We need to adjust Times, Helvetica, and Courier to closely match the | 143 // We need to adjust Times, Helvetica, and Courier to closely match the |
| 174 // vertical metrics of their Microsoft counterparts that are the de facto | 144 // vertical metrics of their Microsoft counterparts that are the de facto |
| 175 // web standard. The AppKit adjustment of 20% is too big and is | 145 // web standard. The AppKit adjustment of 20% is too big and is |
| 176 // incorrectly added to line spacing, so we use a 15% adjustment instead | 146 // incorrectly added to line spacing, so we use a 15% adjustment instead |
| 177 // and add it to the ascent. | 147 // and add it to the ascent. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { | 359 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { |
| 390 if (!m_platformData.size()) | 360 if (!m_platformData.size()) |
| 391 return 0; | 361 return 0; |
| 392 | 362 |
| 393 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); | 363 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); |
| 394 | 364 |
| 395 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); | 365 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); |
| 396 } | 366 } |
| 397 | 367 |
| 398 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |