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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGTextMetrics.cpp

Issue 1825613005: More explicit SVGTextMetrics construction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@svg-metrics-cleanup-2
Patch Set: Created 4 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
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "core/layout/svg/SVGTextMetrics.h" 20 #include "core/layout/svg/SVGTextMetrics.h"
21 21
22 #include "core/layout/api/LineLayoutSVGInlineText.h"
23 #include "platform/fonts/FontOrientation.h" 22 #include "platform/fonts/FontOrientation.h"
24 23
25 namespace blink { 24 namespace blink {
26 25
27 SVGTextMetrics::SVGTextMetrics() 26 SVGTextMetrics::SVGTextMetrics()
28 : m_width(0) 27 : m_width(0)
29 , m_height(0) 28 , m_height(0)
30 , m_length(0) 29 , m_length(0)
31 { 30 {
32 } 31 }
33 32
33 SVGTextMetrics::SVGTextMetrics(unsigned length, float width, float height)
34 : m_width(width)
35 , m_height(height)
36 , m_length(length)
37 {
38 }
39
34 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) 40 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType)
35 : m_width(0) 41 : SVGTextMetrics(1, 0, 0)
36 , m_height(0)
37 , m_length(1)
38 { 42 {
39 } 43 }
40 44
41 SVGTextMetrics::SVGTextMetrics(LineLayoutSVGInlineText textLayoutItem, unsigned length, float width)
42 {
43 ASSERT(textLayoutItem);
44
45 float scalingFactor = textLayoutItem.scalingFactor();
46 ASSERT(scalingFactor);
47
48 m_width = width / scalingFactor;
49 m_height = textLayoutItem.scaledFont().getFontMetrics().floatHeight() / scal ingFactor;
50
51 m_length = length;
52 }
53
54 float SVGTextMetrics::advance(FontOrientation orientation) const 45 float SVGTextMetrics::advance(FontOrientation orientation) const
55 { 46 {
56 switch (orientation) { 47 switch (orientation) {
57 case FontOrientation::Horizontal: 48 case FontOrientation::Horizontal:
58 case FontOrientation::VerticalRotated: 49 case FontOrientation::VerticalRotated:
59 return width(); 50 return width();
60 case FontOrientation::VerticalUpright: 51 case FontOrientation::VerticalUpright:
61 return height(); 52 return height();
62 default: 53 default:
63 ASSERT_NOT_REACHED(); 54 ASSERT_NOT_REACHED();
64 return width(); 55 return width();
65 } 56 }
66 } 57 }
67 58
68 } // namespace blink 59 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698