OLD | NEW |
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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "core/rendering/svg/SVGTextMetrics.h" | 22 #include "core/rendering/svg/SVGTextMetrics.h" |
23 | 23 |
24 #include "core/rendering/svg/RenderSVGInlineText.h" | 24 #include "core/rendering/svg/RenderSVGInlineText.h" |
25 | 25 |
26 namespace blink { | 26 namespace blink { |
27 | 27 |
28 SVGTextMetrics::SVGTextMetrics() | 28 SVGTextMetrics::SVGTextMetrics() |
29 : m_width(0) | 29 : m_width(0) |
30 , m_height(0) | 30 , m_height(0) |
31 , m_length(0) | 31 , m_length(0) |
32 , m_glyph(0) | |
33 { | 32 { |
34 } | 33 } |
35 | 34 |
36 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) | 35 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) |
37 : m_width(0) | 36 : m_width(0) |
38 , m_height(0) | 37 , m_height(0) |
39 , m_length(1) | 38 , m_length(1) |
40 , m_glyph(0) | |
41 { | 39 { |
42 } | 40 } |
43 | 41 |
44 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* textRenderer, const TextRun&
run) | 42 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* textRenderer, const TextRun&
run) |
45 { | 43 { |
46 ASSERT(textRenderer); | 44 ASSERT(textRenderer); |
47 | 45 |
48 float scalingFactor = textRenderer->scalingFactor(); | 46 float scalingFactor = textRenderer->scalingFactor(); |
49 ASSERT(scalingFactor); | 47 ASSERT(scalingFactor); |
50 | 48 |
51 const Font& scaledFont = textRenderer->scaledFont(); | 49 const Font& scaledFont = textRenderer->scaledFont(); |
52 int length = 0; | |
53 | 50 |
54 // Calculate width/height using the scaled font, divide this result by the s
calingFactor afterwards. | 51 // Calculate width/height using the scaled font, divide this result by the s
calingFactor afterwards. |
55 m_width = scaledFont.width(run, length, m_glyph) / scalingFactor; | 52 m_width = scaledFont.width(run) / scalingFactor; |
56 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; | 53 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; |
57 | 54 |
58 ASSERT(length >= 0); | 55 ASSERT(run.length() >= 0); |
59 m_length = static_cast<unsigned>(length); | 56 m_length = static_cast<unsigned>(run.length()); |
60 } | 57 } |
61 | 58 |
62 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) | 59 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) |
63 { | 60 { |
64 ASSERT(text->style()); | 61 ASSERT(text->style()); |
65 return constructTextRun(text, position, length, text->style()->direction()); | 62 return constructTextRun(text, position, length, text->style()->direction()); |
66 } | 63 } |
67 | 64 |
68 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length, TextDirection textDirection) | 65 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length, TextDirection textDirection) |
69 { | 66 { |
(...skipping 29 matching lines...) Expand all Loading... |
99 ASSERT(text); | 96 ASSERT(text); |
100 return SVGTextMetrics(text, constructTextRun(text, position, length, textDir
ection)); | 97 return SVGTextMetrics(text, constructTextRun(text, position, length, textDir
ection)); |
101 } | 98 } |
102 | 99 |
103 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) | 100 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) |
104 { | 101 { |
105 ASSERT(text); | 102 ASSERT(text); |
106 return SVGTextMetrics(text, constructTextRun(text, position, length)); | 103 return SVGTextMetrics(text, constructTextRun(text, position, length)); |
107 } | 104 } |
108 | 105 |
109 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width, Glyph glyphNameGlyphId) | 106 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width) |
110 { | 107 { |
111 ASSERT(text); | 108 ASSERT(text); |
112 | 109 |
113 float scalingFactor = text->scalingFactor(); | 110 float scalingFactor = text->scalingFactor(); |
114 ASSERT(scalingFactor); | 111 ASSERT(scalingFactor); |
115 | 112 |
116 m_width = width / scalingFactor; | 113 m_width = width / scalingFactor; |
117 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; | 114 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; |
118 m_glyph = 0; | |
119 | 115 |
120 m_length = length; | 116 m_length = length; |
121 } | 117 } |
122 | 118 |
123 } | 119 } |
OLD | NEW |