2 * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "UniscribeHelperTextRun.h"
35 #include "PlatformSupport.h"
36 #include "SimpleFontData.h"
41 UniscribeHelperTextRun::UniscribeHelperTextRun(const TextRun& run,
43 : UniscribeHelper(run.characters(), run.length(), run.rtl(),
44 font.primaryFont()->platformData().hfont(),
45 font.primaryFont()->platformData().scriptCache(),
46 font.primaryFont()->platformData().scriptFontProperties(),
47 font.primaryFont()->spaceGlyph())
51 setDirectionalOverride(run.directionalOverride());
52 setLetterSpacing(font.letterSpacing());
53 setSpaceWidth(font.spaceWidth());
54 setWordSpacing(font.wordSpacing());
55 setAscent(font.fontMetrics().ascent());
59 // Expansion is the amount to add to make justification happen. This
60 // should be done after Init() so all the runs are already measured.
61 if (run.expansion() > 0)
62 justify(run.expansion());
65 UniscribeHelperTextRun::UniscribeHelperTextRun(
70 SCRIPT_CACHE* scriptCache,
71 SCRIPT_FONTPROPERTIES* fontProperties)
72 : UniscribeHelper(input, inputLength, isRtl, hfont,
73 scriptCache, fontProperties, 0)
79 void UniscribeHelperTextRun::tryToPreloadFont(HFONT font)
81 // Ask the browser to get the font metrics for this font.
82 // That will preload the font and it should now be accessible
84 PlatformSupport::ensureFontLoaded(font);
87 bool UniscribeHelperTextRun::nextWinFontData(
89 SCRIPT_CACHE** scriptCache,
90 SCRIPT_FONTPROPERTIES** fontProperties,
93 // This check is necessary because NextWinFontData can be called again
94 // after we already ran out of fonts. fontDataAt behaves in a strange
95 // manner when the difference between param passed and # of fonts stored in
96 // WebKit::Font is larger than one. We can avoid this check by setting
97 // font_index_ to # of elements in hfonts_ when we run out of font. In that
98 // case, we'd have to go through a couple of more checks before returning
100 if (m_fontIndex == -1 || !m_font)
103 // If the font data for a fallback font requested is not yet retrieved, add
104 // them to our vectors. Note that '>' rather than '>=' is used to test that
105 // condition. primaryFont is not stored in hfonts_, and friends so that
106 // indices for fontDataAt and our vectors for font data are 1 off from each
107 // other. That is, when fully populated, hfonts_ and friends have one font
108 // fewer than what's contained in font_.
109 if (static_cast<size_t>(++m_fontIndex) > m_hfonts.size()) {
110 const FontData *fontData = m_font->fontDataAt(m_fontIndex);
117 // FIXME: this won't work for SegmentedFontData
118 // http://crbug.com/6425
119 const SimpleFontData* simpleFontData =
120 fontData->fontDataForCharacter(' ');
122 m_hfonts.append(simpleFontData->platformData().hfont());
123 m_scriptCaches.append(simpleFontData->platformData().scriptCache());
124 m_fontProperties.append(simpleFontData->platformData().scriptFontProperties());
125 m_ascents.append(simpleFontData->fontMetrics().ascent());
128 *hfont = m_hfonts[m_fontIndex - 1];
129 *scriptCache = m_scriptCaches[m_fontIndex - 1];
130 *fontProperties = m_fontProperties[m_fontIndex - 1];
131 *ascent = m_ascents[m_fontIndex - 1];
135 void UniscribeHelperTextRun::resetFontIndex()
140 } // namespace WebCore