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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc

Issue 2764753007: [LayoutNG] Add NGLineBoxFragment (Closed)
Patch Set: Rebase again as other CLs landed faster Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/layout/ng/ng_line_height_metrics.h"
6
7 #include "core/style/ComputedStyle.h"
8
9 namespace blink {
10
11 NGLineHeightMetrics::NGLineHeightMetrics(const ComputedStyle& style,
12 FontBaseline baseline_type) {
13 const SimpleFontData* font_data = style.font().primaryFont();
14 DCHECK(font_data);
15 Initialize(font_data->getFontMetrics(), baseline_type,
16 style.computedLineHeightInFloat());
17 }
18
19 NGLineHeightMetrics::NGLineHeightMetrics(const FontMetrics& font_metrics,
20 FontBaseline baseline_type) {
21 Initialize(font_metrics, baseline_type, font_metrics.floatLineSpacing());
22 }
23
24 void NGLineHeightMetrics::Initialize(const FontMetrics& font_metrics,
25 FontBaseline baseline_type,
26 float line_height) {
27 ascent = font_metrics.floatAscent(baseline_type);
28 descent = font_metrics.floatDescent(baseline_type);
29 float half_leading = (line_height - (ascent + descent)) / 2;
30 // Ensure the top and the baseline is snapped to CSS pixel.
31 // TODO(kojii): How to handle fractional ascent isn't determined yet. Should
32 // we snap top or baseline? If baseline, top needs fractional. If top,
33 // baseline may not align across fonts.
34 ascent_and_leading = ascent + floor(half_leading);
35 descent_and_leading = line_height - ascent_and_leading;
36 }
37
38 void NGLineHeightMetrics::Unite(const NGLineHeightMetrics& other) {
39 ascent = std::max(ascent, other.ascent);
40 descent = std::max(descent, other.descent);
41 ascent_and_leading = std::max(ascent_and_leading, other.ascent_and_leading);
42 descent_and_leading =
43 std::max(descent_and_leading, other.descent_and_leading);
44 }
45
46 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698