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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 #include "core/rendering/svg/RenderSVGInlineText.h" | 24 #include "core/rendering/svg/RenderSVGInlineText.h" |
25 #include "core/rendering/svg/SVGTextRunRenderingContext.h" | 25 #include "core/rendering/svg/SVGTextRunRenderingContext.h" |
26 | 26 |
27 namespace WebCore { | 27 namespace WebCore { |
28 | 28 |
29 SVGTextMetrics::SVGTextMetrics() | 29 SVGTextMetrics::SVGTextMetrics() |
30 : m_width(0) | 30 : m_width(0) |
31 , m_height(0) | 31 , m_height(0) |
32 , m_length(0) | 32 , m_length(0) |
| 33 , m_glyph(0) |
33 { | 34 { |
34 } | 35 } |
35 | 36 |
36 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) | 37 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) |
37 : m_width(0) | 38 : m_width(0) |
38 , m_height(0) | 39 , m_height(0) |
39 , m_length(1) | 40 , m_length(1) |
| 41 , m_glyph(0) |
40 { | 42 { |
41 } | 43 } |
42 | 44 |
43 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* textRenderer, const TextRun&
run) | 45 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* textRenderer, const TextRun&
run) |
44 { | 46 { |
45 ASSERT(textRenderer); | 47 ASSERT(textRenderer); |
46 | 48 |
47 float scalingFactor = textRenderer->scalingFactor(); | 49 float scalingFactor = textRenderer->scalingFactor(); |
48 ASSERT(scalingFactor); | 50 ASSERT(scalingFactor); |
49 | 51 |
50 const Font& scaledFont = textRenderer->scaledFont(); | 52 const Font& scaledFont = textRenderer->scaledFont(); |
51 int length = 0; | 53 int length = 0; |
52 | 54 |
53 // Calculate width/height using the scaled font, divide this result by the s
calingFactor afterwards. | 55 // Calculate width/height using the scaled font, divide this result by the s
calingFactor afterwards. |
54 m_width = scaledFont.width(run, length, m_glyph.name) / scalingFactor; | 56 m_width = scaledFont.width(run, length, m_glyph) / scalingFactor; |
55 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; | 57 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; |
56 | 58 |
57 m_glyph.unicodeString = run.is8Bit() ? String(run.characters8(), length) : S
tring(run.characters16(), length); | |
58 m_glyph.isValid = true; | |
59 | |
60 ASSERT(length >= 0); | 59 ASSERT(length >= 0); |
61 m_length = static_cast<unsigned>(length); | 60 m_length = static_cast<unsigned>(length); |
62 } | 61 } |
63 | 62 |
64 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) | 63 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) |
65 { | 64 { |
66 RenderStyle* style = text->style(); | 65 RenderStyle* style = text->style(); |
67 ASSERT(style); | 66 ASSERT(style); |
68 | 67 |
69 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if
non-zero. | 68 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if
non-zero. |
(...skipping 24 matching lines...) Expand all Loading... |
94 ASSERT(run.charactersLength() >= run.length()); | 93 ASSERT(run.charactersLength() >= run.length()); |
95 return run; | 94 return run; |
96 } | 95 } |
97 | 96 |
98 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) | 97 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) |
99 { | 98 { |
100 ASSERT(text); | 99 ASSERT(text); |
101 return SVGTextMetrics(text, constructTextRun(text, position, length)); | 100 return SVGTextMetrics(text, constructTextRun(text, position, length)); |
102 } | 101 } |
103 | 102 |
104 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width, const String& glyphName) | 103 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width, Glyph glyphNameGlyphId) |
105 { | 104 { |
106 ASSERT(text); | 105 ASSERT(text); |
107 | 106 |
108 bool needsContext = textRunNeedsRenderingContext(text->style()->font()); | 107 bool needsContext = textRunNeedsRenderingContext(text->style()->font()); |
109 float scalingFactor = text->scalingFactor(); | 108 float scalingFactor = text->scalingFactor(); |
110 ASSERT(scalingFactor); | 109 ASSERT(scalingFactor); |
111 | 110 |
112 m_width = width / scalingFactor; | 111 m_width = width / scalingFactor; |
113 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; | 112 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; |
114 if (needsContext) { | 113 m_glyph = needsContext ? glyphNameGlyphId : 0; |
115 m_glyph.isValid = true; | |
116 m_glyph.unicodeString = text->substring(position, length); | |
117 m_glyph.name = glyphName; | |
118 } | |
119 | 114 |
120 m_length = length; | 115 m_length = length; |
121 } | 116 } |
122 | 117 |
123 } | 118 } |
OLD | NEW |