| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/shared_impl/private/ppb_font_shared.h" | 5 #include "ppapi/shared_impl/private/ppb_font_shared.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ppapi/c/dev/ppb_font_dev.h" | 10 #include "ppapi/c/dev/ppb_font_dev.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 using WebKit::WebFont; | 33 using WebKit::WebFont; |
| 34 using WebKit::WebFontDescription; | 34 using WebKit::WebFontDescription; |
| 35 using WebKit::WebRect; | 35 using WebKit::WebRect; |
| 36 using WebKit::WebTextRun; | 36 using WebKit::WebTextRun; |
| 37 using WebKit::WebCanvas; | 37 using WebKit::WebCanvas; |
| 38 | 38 |
| 39 namespace ppapi { | 39 namespace ppapi { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // The font family maps are from ISO 15924 script code to font. "Zyyy" is the |
| 44 // ISO 15924 script code for undetermined script aka Common. It's the default |
| 45 // used on WebKit's side to get/set a font setting when no script is specified. |
| 46 const char kCommonScript[] = "Zyyy"; |
| 47 |
| 48 string16 GetFontFromMap( |
| 49 const webkit_glue::WebPreferences::ScriptFontFamilyMap& map, |
| 50 const std::string& script) { |
| 51 webkit_glue::WebPreferences::ScriptFontFamilyMap::const_iterator it = |
| 52 map.find(script); |
| 53 if (it != map.end()) |
| 54 return it->second; |
| 55 return string16(); |
| 56 } |
| 57 |
| 43 // Converts the given PP_TextRun to a TextRun, returning true on success. | 58 // Converts the given PP_TextRun to a TextRun, returning true on success. |
| 44 // False means the input was invalid. | 59 // False means the input was invalid. |
| 45 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 60 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
| 46 WebKitForwarding::Font::TextRun* output) { | 61 WebKitForwarding::Font::TextRun* output) { |
| 47 StringVar* text_string = StringVar::FromPPVar(run->text); | 62 StringVar* text_string = StringVar::FromPPVar(run->text); |
| 48 if (!text_string) | 63 if (!text_string) |
| 49 return false; | 64 return false; |
| 50 | 65 |
| 51 output->text = text_string->value(); | 66 output->text = text_string->value(); |
| 52 output->rtl = run->rtl == PP_TRUE ? true : false; | 67 output->rtl = run->rtl == PP_TRUE ? true : false; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == | 100 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == |
| 86 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), | 101 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), |
| 87 MonospaceFamily); | 102 MonospaceFamily); |
| 88 | 103 |
| 89 WebFontDescription result; | 104 WebFontDescription result; |
| 90 string16 resolved_family; | 105 string16 resolved_family; |
| 91 if (face.empty()) { | 106 if (face.empty()) { |
| 92 // Resolve the generic family. | 107 // Resolve the generic family. |
| 93 switch (font.family) { | 108 switch (font.family) { |
| 94 case PP_FONTFAMILY_SERIF: | 109 case PP_FONTFAMILY_SERIF: |
| 95 resolved_family = prefs.serif_font_family; | 110 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
| 111 kCommonScript); |
| 96 break; | 112 break; |
| 97 case PP_FONTFAMILY_SANSSERIF: | 113 case PP_FONTFAMILY_SANSSERIF: |
| 98 resolved_family = prefs.sans_serif_font_family; | 114 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map, |
| 115 kCommonScript); |
| 99 break; | 116 break; |
| 100 case PP_FONTFAMILY_MONOSPACE: | 117 case PP_FONTFAMILY_MONOSPACE: |
| 101 resolved_family = prefs.fixed_font_family; | 118 resolved_family = GetFontFromMap(prefs.fixed_font_family_map, |
| 119 kCommonScript); |
| 102 break; | 120 break; |
| 103 case PP_FONTFAMILY_DEFAULT: | 121 case PP_FONTFAMILY_DEFAULT: |
| 104 default: | 122 default: |
| 105 resolved_family = prefs.standard_font_family; | 123 resolved_family = GetFontFromMap(prefs.standard_font_family_map, |
| 124 kCommonScript); |
| 106 break; | 125 break; |
| 107 } | 126 } |
| 108 } else { | 127 } else { |
| 109 // Use the exact font. | 128 // Use the exact font. |
| 110 resolved_family = UTF8ToUTF16(face); | 129 resolved_family = UTF8ToUTF16(face); |
| 111 } | 130 } |
| 112 result.family = resolved_family; | 131 result.family = resolved_family; |
| 113 | 132 |
| 114 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); | 133 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); |
| 115 | 134 |
| 116 if (font.size == 0) { | 135 if (font.size == 0) { |
| 117 // Resolve the default font size, using the resolved family to see if | 136 // Resolve the default font size, using the resolved family to see if |
| 118 // we should use the fixed or regular font size. It's difficult at this | 137 // we should use the fixed or regular font size. It's difficult at this |
| 119 // level to detect if the requested font is fixed width, so we only apply | 138 // level to detect if the requested font is fixed width, so we only apply |
| 120 // the alternate font size to the default fixed font family. | 139 // the alternate font size to the default fixed font family. |
| 121 if (StringToLowerASCII(resolved_family) == | 140 if (StringToLowerASCII(resolved_family) == |
| 122 StringToLowerASCII(prefs.fixed_font_family)) | 141 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map, |
| 142 kCommonScript))) |
| 123 result.size = static_cast<float>(prefs.default_fixed_font_size); | 143 result.size = static_cast<float>(prefs.default_fixed_font_size); |
| 124 else | 144 else |
| 125 result.size = static_cast<float>(prefs.default_font_size); | 145 result.size = static_cast<float>(prefs.default_font_size); |
| 126 } else { | 146 } else { |
| 127 // Use the exact size. | 147 // Use the exact size. |
| 128 result.size = static_cast<float>(font.size); | 148 result.size = static_cast<float>(font.size); |
| 129 } | 149 } |
| 130 | 150 |
| 131 result.italic = font.italic != PP_FALSE; | 151 result.italic = font.italic != PP_FALSE; |
| 132 result.smallCaps = font.small_caps != PP_FALSE; | 152 result.smallCaps = font.small_caps != PP_FALSE; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 uint32_t char_offset) { | 414 uint32_t char_offset) { |
| 395 int32_t result = -1; | 415 int32_t result = -1; |
| 396 WebKitForwarding::Font::TextRun run; | 416 WebKitForwarding::Font::TextRun run; |
| 397 if (PPTextRunToTextRun(text, &run)) { | 417 if (PPTextRunToTextRun(text, &run)) { |
| 398 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); | 418 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); |
| 399 } | 419 } |
| 400 return result; | 420 return result; |
| 401 } | 421 } |
| 402 | 422 |
| 403 } // namespace ppapi | 423 } // namespace ppapi |
| 404 | |
| OLD | NEW |