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

Side by Side Diff: webkit/port/platform/graphics/UniscribeHelperTextRun.cpp

Issue 10785: Debase our Uniscribe code. This moves FontUtils and all our Uniscribe code fr... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/src/webkit/port/platform/UniscribeStateTextRun.cpp:r3734-4217,4606-5108,5177-5263
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27 #include "UniscribeHelperTextRun.h"
28 #include "UniscribeStateTextRun.h"
29 28
30 #include "ChromiumBridge.h" 29 #include "ChromiumBridge.h"
31 #include "Font.h" 30 #include "Font.h"
32 #include "SimpleFontData.h" 31 #include "SimpleFontData.h"
33 32
34 UniscribeStateTextRun::UniscribeStateTextRun(const WebCore::TextRun& run, 33 namespace WebCore {
35 const WebCore::Font& font) 34
36 : UniscribeState(run.characters(), run.length(), run.rtl(), 35 UniscribeHelperTextRun::UniscribeHelperTextRun(const WebCore::TextRun& run,
37 font.primaryFont()->platformData().hfont(), 36 const WebCore::Font& font)
38 font.primaryFont()->platformData().scriptCache(), 37 : UniscribeHelper(run.characters(), run.length(), run.rtl(),
39 font.primaryFont()->platformData().scriptFontProperties()), 38 font.primaryFont()->platformData().hfont(),
40 font_(&font), 39 font.primaryFont()->platformData().scriptCache(),
41 font_index_(0) { 40 font.primaryFont()->platformData().scriptFontProperties())
42 set_directional_override(run.directionalOverride()); 41 , m_font(&font)
43 set_letter_spacing(font.letterSpacing()); 42 , m_fontIndex(0)
44 set_space_width(font.spaceWidth()); 43 {
45 set_word_spacing(font.wordSpacing()); 44 setDirectionalOverride(run.directionalOverride());
46 set_ascent(font.primaryFont()->ascent()); 45 setLetterSpacing(font.letterSpacing());
46 setSpaceWidth(font.spaceWidth());
47 setWordSpacing(font.wordSpacing());
48 setAscent(font.primaryFont()->ascent());
47 49
48 Init(); 50 Init();
49 51
50 // Padding is the amount to add to make justification happen. This 52 // Padding is the amount to add to make justification happen. This
51 // should be done after Init() so all the runs are already measured. 53 // should be done after Init() so all the runs are already measured.
52 if (run.padding() > 0) 54 if (run.padding() > 0)
53 Justify(run.padding()); 55 Justify(run.padding());
54 } 56 }
55 57
56 UniscribeStateTextRun::UniscribeStateTextRun( 58 UniscribeHelperTextRun::UniscribeHelperTextRun(
57 const wchar_t* input, 59 const wchar_t* input,
58 int input_length, 60 int inputLength,
59 bool is_rtl, 61 bool isRtl,
60 HFONT hfont, 62 HFONT hfont,
61 SCRIPT_CACHE* script_cache, 63 SCRIPT_CACHE* scriptCache,
62 SCRIPT_FONTPROPERTIES* font_properties) 64 SCRIPT_FONTPROPERTIES* fontProperties)
63 : UniscribeState(input, input_length, is_rtl, hfont, 65 : UniscribeHelper(input, inputLength, isRtl, hfont,
64 script_cache, font_properties), 66 scriptCache, fontProperties)
65 font_(NULL), 67 , m_font(NULL)
66 font_index_(-1) { 68 , m_fontIndex(-1)
69 {
67 } 70 }
68 71
69 void UniscribeStateTextRun::TryToPreloadFont(HFONT font) { 72 void UniscribeHelperTextRun::TryToPreloadFont(HFONT font)
70 // Ask the browser to get the font metrics for this font. 73 {
71 // That will preload the font and it should now be accessible 74 // Ask the browser to get the font metrics for this font.
72 // from the renderer. 75 // That will preload the font and it should now be accessible
73 WebCore::ChromiumBridge::ensureFontLoaded(font); 76 // from the renderer.
77 WebCore::ChromiumBridge::ensureFontLoaded(font);
74 } 78 }
75 79
76 bool UniscribeStateTextRun::NextWinFontData( 80 bool UniscribeHelperTextRun::NextWinFontData(
77 HFONT* hfont, 81 HFONT* hfont,
78 SCRIPT_CACHE** script_cache, 82 SCRIPT_CACHE** scriptCache,
79 SCRIPT_FONTPROPERTIES** font_properties, 83 SCRIPT_FONTPROPERTIES** fontProperties,
80 int* ascent) { 84 int* ascent)
81 // This check is necessary because NextWinFontData can be 85 {
82 // called again after we already ran out of fonts. fontDataAt 86 // This check is necessary because NextWinFontData can be called again
83 // behaves in a strange manner when the difference between 87 // after we already ran out of fonts. fontDataAt behaves in a strange
84 // param passed and # of fonts stored in WebKit::Font is 88 // manner when the difference between param passed and # of fonts stored in
85 // larger than one. We can avoid this check by setting 89 // WebKit::Font is larger than one. We can avoid this check by setting
86 // font_index_ to # of elements in hfonts_ when we run out 90 // font_index_ to # of elements in hfonts_ when we run out of font. In that
87 // of font. In that case, we'd have to go through a couple of 91 // case, we'd have to go through a couple of more checks before returning
88 // more checks before returning false. 92 // false.
89 if (font_index_ == -1 || !font_) 93 if (m_fontIndex == -1 || !m_font)
90 return false; 94 return false;
91 95
92 // If the font data for a fallback font requested is not 96 // If the font data for a fallback font requested is not yet retrieved, add
93 // yet retrieved, add them to our vectors. Note that '>' rather 97 // them to our vectors. Note that '>' rather than '>=' is used to test that
94 // than '>=' is used to test that condition. primaryFont is not 98 // condition. primaryFont is not stored in hfonts_, and friends so that
95 // stored in hfonts_, and friends so that indices for fontDataAt 99 // indices for fontDataAt and our vectors for font data are 1 off from each
96 // and our vectors for font data are 1 off from each other. 100 // other. That is, when fully populated, hfonts_ and friends have one font
97 // That is, when fully populated, hfonts_ and friends have 101 // fewer than what's contained in font_.
98 // one font fewer than what's contained in font_. 102 if (static_cast<size_t>(++m_fontIndex) > m_hfonts.size()) {
99 if (static_cast<size_t>(++font_index_) > hfonts_->size()) { 103 const WebCore::FontData *fontData = m_font->fontDataAt(m_fontIndex);
100 const WebCore::FontData *font_data; 104 if (!fontData) {
101 font_data = font_->fontDataAt(font_index_); 105 // Ran out of fonts.
102 if (!font_data) { 106 m_fontIndex = -1;
103 // run out of fonts 107 return false;
104 font_index_ = -1; 108 }
105 return false; 109
110 // TODO(ericroman): this won't work for SegmentedFontData
111 // http://b/issue?id=1007335
112 const WebCore::SimpleFontData* simpleFontData =
113 fontData->fontDataForCharacter(' ');
114
115 m_hfonts.append(simpleFontData->platformData().hfont());
116 m_scriptCaches.append(
117 simpleFontData->platformData().scriptCache());
118 m_fontProperties.append(
119 simpleFontData->platformData().scriptFontProperties());
120 m_ascents.append(simpleFontData->ascent());
106 } 121 }
107 122
108 // TODO(ericroman): this won't work for SegmentedFontData 123 *hfont = m_hfonts[m_fontIndex - 1];
109 // http://b/issue?id=1007335 124 *scriptCache = m_scriptCaches[m_fontIndex - 1];
110 const WebCore::SimpleFontData* simple_font_data = 125 *fontProperties = m_fontProperties[m_fontIndex - 1];
111 font_data->fontDataForCharacter(' '); 126 *ascent = m_ascents[m_fontIndex - 1];
112 127 return true;
113 hfonts_->push_back(simple_font_data->platformData().hfont());
114 script_caches_->push_back(simple_font_data->platformData().scriptCache());
115 font_properties_->push_back(simple_font_data->platformData().scriptFontPrope rties());
116 ascents_->push_back(simple_font_data->ascent());
117 }
118
119 *hfont = hfonts_[font_index_ - 1];
120 *script_cache = script_caches_[font_index_ - 1];
121 *font_properties = font_properties_[font_index_ - 1];
122 *ascent = ascents_[font_index_ - 1];
123 return true;
124 } 128 }
125 129
126 void UniscribeStateTextRun::ResetFontIndex() { 130 void UniscribeHelperTextRun::ResetFontIndex()
127 font_index_ = 0; 131 {
132 m_fontIndex = 0;
128 } 133 }
134
135 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698