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

Side by Side Diff: Source/core/rendering/svg/SVGTextMetrics.cpp

Issue 181443002: Use glyph-ids for lookups of SVG font kerning-pairs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Vector<...>::append -> Vector<...>::appendVector. Created 6 years, 10 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 | Annotate | Revision Log
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
(...skipping 12 matching lines...) Expand all
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
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 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/SVGTextMetrics.h ('k') | Source/core/rendering/svg/SVGTextMetricsBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698