| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 static const size_t kMaxVDMXTableSize = 1024 * 1024; // 1 MB | 55 static const size_t kMaxVDMXTableSize = 1024 * 1024; // 1 MB |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 SimpleFontData::SimpleFontData(const FontPlatformData& platform_data, | 58 SimpleFontData::SimpleFontData(const FontPlatformData& platform_data, |
| 59 PassRefPtr<CustomFontData> custom_data, | 59 PassRefPtr<CustomFontData> custom_data, |
| 60 bool is_text_orientation_fallback, | 60 bool is_text_orientation_fallback, |
| 61 bool subpixel_ascent_descent) | 61 bool subpixel_ascent_descent) |
| 62 : max_char_width_(-1), | 62 : max_char_width_(-1), |
| 63 avg_char_width_(-1), | 63 avg_char_width_(-1), |
| 64 platform_data_(platform_data), | 64 platform_data_(platform_data), |
| 65 vertical_data_(nullptr), |
| 66 custom_font_data_(std::move(custom_data)), |
| 65 is_text_orientation_fallback_(is_text_orientation_fallback), | 67 is_text_orientation_fallback_(is_text_orientation_fallback), |
| 66 vertical_data_(nullptr), | |
| 67 has_vertical_glyphs_(false), | 68 has_vertical_glyphs_(false), |
| 68 custom_font_data_(std::move(custom_data)) { | 69 visual_overflow_inflation_for_ascent_(0), |
| 70 visual_overflow_inflation_for_descent_(0) { |
| 69 PlatformInit(subpixel_ascent_descent); | 71 PlatformInit(subpixel_ascent_descent); |
| 70 PlatformGlyphInit(); | 72 PlatformGlyphInit(); |
| 71 if (platform_data.IsVerticalAnyUpright() && !is_text_orientation_fallback) { | 73 if (platform_data.IsVerticalAnyUpright() && !is_text_orientation_fallback) { |
| 72 vertical_data_ = platform_data.VerticalData(); | 74 vertical_data_ = platform_data.VerticalData(); |
| 73 has_vertical_glyphs_ = | 75 has_vertical_glyphs_ = |
| 74 vertical_data_.Get() && vertical_data_->HasVerticalMetrics(); | 76 vertical_data_.Get() && vertical_data_->HasVerticalMetrics(); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 SimpleFontData::SimpleFontData(const FontPlatformData& platform_data, | 80 SimpleFontData::SimpleFontData(const FontPlatformData& platform_data, |
| 79 PassRefPtr<OpenTypeVerticalData> vertical_data) | 81 PassRefPtr<OpenTypeVerticalData> vertical_data) |
| 80 : platform_data_(platform_data), | 82 : platform_data_(platform_data), |
| 83 vertical_data_(vertical_data), |
| 81 is_text_orientation_fallback_(false), | 84 is_text_orientation_fallback_(false), |
| 82 vertical_data_(vertical_data), | 85 has_vertical_glyphs_(false), |
| 83 has_vertical_glyphs_(false) {} | 86 visual_overflow_inflation_for_ascent_(0), |
| 87 visual_overflow_inflation_for_descent_(0) {} |
| 84 | 88 |
| 85 void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) { | 89 void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) { |
| 86 if (!platform_data_.size()) { | 90 if (!platform_data_.size()) { |
| 87 font_metrics_.Reset(); | 91 font_metrics_.Reset(); |
| 88 avg_char_width_ = 0; | 92 avg_char_width_ = 0; |
| 89 max_char_width_ = 0; | 93 max_char_width_ = 0; |
| 90 return; | 94 return; |
| 91 } | 95 } |
| 92 | 96 |
| 93 SkPaint::FontMetrics metrics; | 97 SkPaint::FontMetrics metrics; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 float ascent; | 131 float ascent; |
| 128 float descent; | 132 float descent; |
| 129 | 133 |
| 130 // Beware those who step here: This code is designed to match Win32 font | 134 // Beware those who step here: This code is designed to match Win32 font |
| 131 // metrics *exactly* except: | 135 // metrics *exactly* except: |
| 132 // - the adjustment of ascent/descent on Linux/Android | 136 // - the adjustment of ascent/descent on Linux/Android |
| 133 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts | 137 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts |
| 134 if (is_vdmx_valid) { | 138 if (is_vdmx_valid) { |
| 135 ascent = vdmx_ascent; | 139 ascent = vdmx_ascent; |
| 136 descent = -vdmx_descent; | 140 descent = -vdmx_descent; |
| 137 } else { | 141 } else if (subpixel_ascent_descent && |
| 142 (-metrics.fAscent < 3 || |
| 143 -metrics.fAscent + metrics.fDescent < 2)) { |
| 138 // For tiny fonts, the rounding of fAscent and fDescent results in equal | 144 // For tiny fonts, the rounding of fAscent and fDescent results in equal |
| 139 // baseline for different types of text baselines (crbug.com/338908). | 145 // baseline for different types of text baselines (crbug.com/338908). |
| 140 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. | 146 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. |
| 141 if (subpixel_ascent_descent && | 147 ascent = -metrics.fAscent; |
| 142 (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2)) { | 148 descent = metrics.fDescent; |
| 143 ascent = -metrics.fAscent; | 149 } else { |
| 144 descent = metrics.fDescent; | 150 ascent = SkScalarRoundToScalar(-metrics.fAscent); |
| 145 } else { | 151 descent = SkScalarRoundToScalar(metrics.fDescent); |
| 146 ascent = SkScalarRoundToScalar(-metrics.fAscent); | 152 |
| 147 descent = SkScalarRoundToScalar(metrics.fDescent); | 153 if (ascent < -metrics.fAscent) |
| 154 visual_overflow_inflation_for_ascent_ = 1; |
| 155 if (descent < metrics.fDescent) { |
| 156 visual_overflow_inflation_for_descent_ = 1; |
| 157 #if OS(LINUX) || OS(ANDROID) |
| 158 // When subpixel positioning is enabled, if the descent is rounded down, |
| 159 // the descent part of the glyph may be truncated when displayed in a |
| 160 // 'overflow: hidden' container. To avoid that, borrow 1 unit from the |
| 161 // ascent when possible. |
| 162 if (PlatformData().GetFontRenderStyle().use_subpixel_positioning && |
| 163 ascent >= 1) { |
| 164 ++descent; |
| 165 --ascent; |
| 166 // We should inflate overflow 1 more pixel for ascent instead. |
| 167 visual_overflow_inflation_for_descent_ = 0; |
| 168 ++visual_overflow_inflation_for_ascent_; |
| 169 } |
| 170 #endif |
| 148 } | 171 } |
| 149 #if OS(LINUX) || OS(ANDROID) | |
| 150 // When subpixel positioning is enabled, if the descent is rounded down, the | |
| 151 // descent part of the glyph may be truncated when displayed in a 'overflow: | |
| 152 // hidden' container. To avoid that, borrow 1 unit from the ascent when | |
| 153 // possible. | |
| 154 // FIXME: This can be removed if sub-pixel ascent/descent is supported. | |
| 155 if (PlatformData().GetFontRenderStyle().use_subpixel_positioning && | |
| 156 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { | |
| 157 ++descent; | |
| 158 --ascent; | |
| 159 } | |
| 160 #endif | |
| 161 } | 172 } |
| 162 | 173 |
| 163 #if OS(MACOSX) | 174 #if OS(MACOSX) |
| 164 // We are preserving this ascent hack to match Safari's ascent adjustment | 175 // We are preserving this ascent hack to match Safari's ascent adjustment |
| 165 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. | 176 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. |
| 166 // We need to adjust Times, Helvetica, and Courier to closely match the | 177 // We need to adjust Times, Helvetica, and Courier to closely match the |
| 167 // vertical metrics of their Microsoft counterparts that are the de facto | 178 // vertical metrics of their Microsoft counterparts that are the de facto |
| 168 // web standard. The AppKit adjustment of 20% is too big and is | 179 // web standard. The AppKit adjustment of 20% is too big and is |
| 169 // incorrectly added to line spacing, so we use a 15% adjustment instead | 180 // incorrectly added to line spacing, so we use a 15% adjustment instead |
| 170 // and add it to the ascent. | 181 // and add it to the ascent. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const { | 393 float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const { |
| 383 if (!platform_data_.size()) | 394 if (!platform_data_.size()) |
| 384 return 0; | 395 return 0; |
| 385 | 396 |
| 386 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); | 397 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); |
| 387 | 398 |
| 388 return SkiaTextMetrics(&paint_).GetSkiaWidthForGlyph(glyph); | 399 return SkiaTextMetrics(&paint_).GetSkiaWidthForGlyph(glyph); |
| 389 } | 400 } |
| 390 | 401 |
| 391 } // namespace blink | 402 } // namespace blink |
| OLD | NEW |