| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // 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. |
| 56 m_width = scaledFont.width(run, length, m_glyph) / scalingFactor; | 56 m_width = scaledFont.width(run, length, m_glyph) / scalingFactor; |
| 57 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; | 57 m_height = scaledFont.fontMetrics().floatHeight() / scalingFactor; |
| 58 | 58 |
| 59 ASSERT(length >= 0); | 59 ASSERT(length >= 0); |
| 60 m_length = static_cast<unsigned>(length); | 60 m_length = static_cast<unsigned>(length); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) | 63 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length) |
| 64 { | 64 { |
| 65 ASSERT(text->style()); |
| 66 return constructTextRun(text, position, length, text->style()->direction()); |
| 67 } |
| 68 |
| 69 TextRun SVGTextMetrics::constructTextRun(RenderSVGInlineText* text, unsigned pos
ition, unsigned length, TextDirection textDirection) |
| 70 { |
| 65 RenderStyle* style = text->style(); | 71 RenderStyle* style = text->style(); |
| 66 ASSERT(style); | 72 ASSERT(style); |
| 67 | 73 |
| 68 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if
non-zero. | 74 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if
non-zero. |
| 69 , 0 // length, will be set below if non-zero. | 75 , 0 // length, will be set below if non-zero. |
| 70 , 0 // xPos, only relevant with allowTabs=true | 76 , 0 // xPos, only relevant with allowTabs=true |
| 71 , 0 // padding, only relevant for justified text, not relevant f
or SVG | 77 , 0 // padding, only relevant for justified text, not relevant f
or SVG |
| 72 , TextRun::AllowTrailingExpansion | 78 , TextRun::AllowTrailingExpansion |
| 73 , style->direction() | 79 , textDirection |
| 74 , isOverride(style->unicodeBidi()) /* directionalOverride */); | 80 , isOverride(style->unicodeBidi()) /* directionalOverride */); |
| 75 | 81 |
| 76 if (length) { | 82 if (length) { |
| 77 if (text->is8Bit()) | 83 if (text->is8Bit()) |
| 78 run.setText(text->characters8() + position, length); | 84 run.setText(text->characters8() + position, length); |
| 79 else | 85 else |
| 80 run.setText(text->characters16() + position, length); | 86 run.setText(text->characters16() + position, length); |
| 81 } | 87 } |
| 82 | 88 |
| 83 if (textRunNeedsRenderingContext(style->font())) | 89 if (textRunNeedsRenderingContext(style->font())) |
| 84 run.setRenderingContext(SVGTextRunRenderingContext::create(text)); | 90 run.setRenderingContext(SVGTextRunRenderingContext::create(text)); |
| 85 | 91 |
| 86 run.disableRoundingHacks(); | 92 run.disableRoundingHacks(); |
| 87 | 93 |
| 88 // We handle letter & word spacing ourselves. | 94 // We handle letter & word spacing ourselves. |
| 89 run.disableSpacing(); | 95 run.disableSpacing(); |
| 90 | 96 |
| 91 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. | 97 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. |
| 92 run.setCharactersLength(text->textLength() - position); | 98 run.setCharactersLength(text->textLength() - position); |
| 93 ASSERT(run.charactersLength() >= run.length()); | 99 ASSERT(run.charactersLength() >= run.length()); |
| 94 return run; | 100 return run; |
| 95 } | 101 } |
| 96 | 102 |
| 103 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length, TextDirection textDirection) |
| 104 { |
| 105 ASSERT(text); |
| 106 return SVGTextMetrics(text, constructTextRun(text, position, length, textDir
ection)); |
| 107 } |
| 108 |
| 97 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) | 109 SVGTextMetrics SVGTextMetrics::measureCharacterRange(RenderSVGInlineText* text,
unsigned position, unsigned length) |
| 98 { | 110 { |
| 99 ASSERT(text); | 111 ASSERT(text); |
| 100 return SVGTextMetrics(text, constructTextRun(text, position, length)); | 112 return SVGTextMetrics(text, constructTextRun(text, position, length)); |
| 101 } | 113 } |
| 102 | 114 |
| 103 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width, Glyph glyphNameGlyphId) | 115 SVGTextMetrics::SVGTextMetrics(RenderSVGInlineText* text, unsigned position, uns
igned length, float width, Glyph glyphNameGlyphId) |
| 104 { | 116 { |
| 105 ASSERT(text); | 117 ASSERT(text); |
| 106 | 118 |
| 107 bool needsContext = textRunNeedsRenderingContext(text->style()->font()); | 119 bool needsContext = textRunNeedsRenderingContext(text->style()->font()); |
| 108 float scalingFactor = text->scalingFactor(); | 120 float scalingFactor = text->scalingFactor(); |
| 109 ASSERT(scalingFactor); | 121 ASSERT(scalingFactor); |
| 110 | 122 |
| 111 m_width = width / scalingFactor; | 123 m_width = width / scalingFactor; |
| 112 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; | 124 m_height = text->scaledFont().fontMetrics().floatHeight() / scalingFactor; |
| 113 m_glyph = needsContext ? glyphNameGlyphId : 0; | 125 m_glyph = needsContext ? glyphNameGlyphId : 0; |
| 114 | 126 |
| 115 m_length = length; | 127 m_length = length; |
| 116 } | 128 } |
| 117 | 129 |
| 118 } | 130 } |
| OLD | NEW |