| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007 Apple 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 | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 | |
| 28 #include "UniscribeStateTextRun.h" | |
| 29 | |
| 30 #include "ChromiumBridge.h" | |
| 31 #include "Font.h" | |
| 32 #include "SimpleFontData.h" | |
| 33 | |
| 34 UniscribeStateTextRun::UniscribeStateTextRun(const WebCore::TextRun& run, | |
| 35 const WebCore::Font& font) | |
| 36 : UniscribeState(run.characters(), run.length(), run.rtl(), | |
| 37 font.primaryFont()->platformData().hfont(), | |
| 38 font.primaryFont()->platformData().scriptCache(), | |
| 39 font.primaryFont()->platformData().scriptFontProperties()), | |
| 40 font_(&font), | |
| 41 font_index_(0) { | |
| 42 set_directional_override(run.directionalOverride()); | |
| 43 set_letter_spacing(font.letterSpacing()); | |
| 44 set_space_width(font.spaceWidth()); | |
| 45 set_word_spacing(font.wordSpacing()); | |
| 46 set_ascent(font.primaryFont()->ascent()); | |
| 47 | |
| 48 Init(); | |
| 49 | |
| 50 // Padding is the amount to add to make justification happen. This | |
| 51 // should be done after Init() so all the runs are already measured. | |
| 52 if (run.padding() > 0) | |
| 53 Justify(run.padding()); | |
| 54 } | |
| 55 | |
| 56 UniscribeStateTextRun::UniscribeStateTextRun( | |
| 57 const wchar_t* input, | |
| 58 int input_length, | |
| 59 bool is_rtl, | |
| 60 HFONT hfont, | |
| 61 SCRIPT_CACHE* script_cache, | |
| 62 SCRIPT_FONTPROPERTIES* font_properties) | |
| 63 : UniscribeState(input, input_length, is_rtl, hfont, | |
| 64 script_cache, font_properties), | |
| 65 font_(NULL), | |
| 66 font_index_(-1) { | |
| 67 } | |
| 68 | |
| 69 void UniscribeStateTextRun::TryToPreloadFont(HFONT font) { | |
| 70 // Ask the browser to get the font metrics for this font. | |
| 71 // That will preload the font and it should now be accessible | |
| 72 // from the renderer. | |
| 73 WebCore::ChromiumBridge::ensureFontLoaded(font); | |
| 74 } | |
| 75 | |
| 76 bool UniscribeStateTextRun::NextWinFontData( | |
| 77 HFONT* hfont, | |
| 78 SCRIPT_CACHE** script_cache, | |
| 79 SCRIPT_FONTPROPERTIES** font_properties, | |
| 80 int* ascent) { | |
| 81 // This check is necessary because NextWinFontData can be | |
| 82 // called again after we already ran out of fonts. fontDataAt | |
| 83 // behaves in a strange manner when the difference between | |
| 84 // param passed and # of fonts stored in WebKit::Font is | |
| 85 // larger than one. We can avoid this check by setting | |
| 86 // font_index_ to # of elements in hfonts_ when we run out | |
| 87 // of font. In that case, we'd have to go through a couple of | |
| 88 // more checks before returning false. | |
| 89 if (font_index_ == -1 || !font_) | |
| 90 return false; | |
| 91 | |
| 92 // If the font data for a fallback font requested is not | |
| 93 // yet retrieved, add them to our vectors. Note that '>' rather | |
| 94 // than '>=' is used to test that condition. primaryFont is not | |
| 95 // stored in hfonts_, and friends so that indices for fontDataAt | |
| 96 // and our vectors for font data are 1 off from each other. | |
| 97 // That is, when fully populated, hfonts_ and friends have | |
| 98 // one font fewer than what's contained in font_. | |
| 99 if (static_cast<size_t>(++font_index_) > hfonts_->size()) { | |
| 100 const WebCore::FontData *font_data; | |
| 101 font_data = font_->fontDataAt(font_index_); | |
| 102 if (!font_data) { | |
| 103 // run out of fonts | |
| 104 font_index_ = -1; | |
| 105 return false; | |
| 106 } | |
| 107 | |
| 108 // TODO(ericroman): this won't work for SegmentedFontData | |
| 109 // http://b/issue?id=1007335 | |
| 110 const WebCore::SimpleFontData* simple_font_data = | |
| 111 font_data->fontDataForCharacter(' '); | |
| 112 | |
| 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 } | |
| 125 | |
| 126 void UniscribeStateTextRun::ResetFontIndex() { | |
| 127 font_index_ = 0; | |
| 128 } | |
| OLD | NEW |