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

Side by Side Diff: Source/core/platform/graphics/win/UniscribeHelperTextRun.cpp

Issue 99103006: Moving GraphicsContext and dependencies from core to platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final patch - fixes Android Created 7 years 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
(Empty)
1 /*
2 * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "core/platform/graphics/win/UniscribeHelperTextRun.h"
33
34 #include "core/platform/graphics/Font.h"
35 #include "core/platform/graphics/SimpleFontData.h"
36 #include "core/platform/graphics/win/FontPlatformDataWin.h"
37 #include "platform/graphics/TextRun.h"
38
39 namespace WebCore {
40
41 UniscribeHelperTextRun::UniscribeHelperTextRun(const TextRun& run,
42 const Font& font)
43 : UniscribeHelper(0, run.length(), run.rtl(),
44 font.primaryFont()->platformData().hfont(),
45 font.primaryFont()->platformData().scriptCache(),
46 font.primaryFont()->platformData().scriptFontProperties(),
47 font.primaryFont()->spaceGlyph())
48 , m_font(&font)
49 , m_fontIndex(0)
50 {
51 if (run.is8Bit()) {
52 m_stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), run.length());
53 setInput(m_stringFor8BitRun.characters16());
54 } else {
55 setInput(run.characters16());
56 }
57
58 setDirectionalOverride(run.directionalOverride());
59 setLetterSpacing(font.letterSpacing());
60 setSpaceWidth(font.spaceWidth());
61 setWordSpacing(font.wordSpacing());
62 setAscent(font.fontMetrics().ascent());
63 setRangeProperties(font.fontDescription().featureSettings());
64
65 init();
66
67 // Expansion is the amount to add to make justification happen. This
68 // should be done after Init() so all the runs are already measured.
69 if (run.expansion() > 0)
70 justify(run.expansion());
71 }
72
73 UniscribeHelperTextRun::UniscribeHelperTextRun(
74 const wchar_t* input,
75 int inputLength,
76 bool isRtl,
77 HFONT hfont,
78 SCRIPT_CACHE* scriptCache,
79 SCRIPT_FONTPROPERTIES* fontProperties)
80 : UniscribeHelper(input, inputLength, isRtl, hfont,
81 scriptCache, fontProperties, 0)
82 , m_font(0)
83 , m_fontIndex(-1)
84 {
85 }
86
87 void UniscribeHelperTextRun::tryToPreloadFont(HFONT font)
88 {
89 // Ask the browser to get the font metrics for this font.
90 // That will preload the font and it should now be accessible
91 // from the renderer.
92 FontPlatformData::ensureFontLoaded(font);
93 }
94
95 bool UniscribeHelperTextRun::nextWinFontData(
96 HFONT& hfont,
97 SCRIPT_CACHE*& scriptCache,
98 SCRIPT_FONTPROPERTIES*& fontProperties,
99 int& ascent,
100 WORD& spaceGlyph)
101 {
102 // This check is necessary because NextWinFontData can be called again
103 // after we already ran out of fonts. fontDataAt behaves in a strange
104 // manner when the difference between param passed and # of fonts stored in
105 // blink::Font is larger than one. We can avoid this check by setting
106 // font_index_ to # of elements in hfonts_ when we run out of font. In that
107 // case, we'd have to go through a couple of more checks before returning
108 // false.
109 if (m_fontIndex == -1 || !m_font)
110 return false;
111
112 // If the font data for a fallback font requested is not yet retrieved, add
113 // them to our vectors. Note that '>' rather than '>=' is used to test that
114 // condition. primaryFont is not stored in hfonts_, and friends so that
115 // indices for fontDataAt and our vectors for font data are 1 off from each
116 // other. That is, when fully populated, hfonts_ and friends have one font
117 // fewer than what's contained in font_.
118 if (static_cast<size_t>(++m_fontIndex) > m_hfonts.size()) {
119 const FontData *fontData = m_font->fontDataAt(m_fontIndex);
120 if (!fontData) {
121 // Ran out of fonts.
122 m_fontIndex = -1;
123 return false;
124 }
125
126 // FIXME: this won't work for SegmentedFontData
127 // http://crbug.com/6425
128 const SimpleFontData* simpleFontData =
129 fontData->fontDataForCharacter(' ');
130
131 m_hfonts.append(simpleFontData->platformData().hfont());
132 m_scriptCaches.append(simpleFontData->platformData().scriptCache());
133 m_fontProperties.append(simpleFontData->platformData().scriptFontPropert ies());
134 m_ascents.append(simpleFontData->fontMetrics().ascent());
135 m_spaceGlyphs.append(simpleFontData->spaceGlyph());
136 }
137
138 hfont = m_hfonts[m_fontIndex - 1];
139 scriptCache = m_scriptCaches[m_fontIndex - 1];
140 fontProperties = m_fontProperties[m_fontIndex - 1];
141 ascent = m_ascents[m_fontIndex - 1];
142 spaceGlyph = m_spaceGlyphs[m_fontIndex - 1];
143 return true;
144 }
145
146 void UniscribeHelperTextRun::resetFontIndex()
147 {
148 m_fontIndex = 0;
149 }
150
151 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/win/UniscribeHelperTextRun.h ('k') | Source/core/platform/image-decoders/ImageDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698