| 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 <unicode/uscript.h> |
| 8 |
| 7 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 10 #include "ppapi/c/dev/ppb_font_dev.h" | 12 #include "ppapi/c/dev/ppb_font_dev.h" |
| 11 #include "ppapi/shared_impl/ppapi_preferences.h" | 13 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 12 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
| 13 #include "ppapi/thunk/enter.h" | 15 #include "ppapi/thunk/enter.h" |
| 14 #include "ppapi/thunk/ppb_image_data_api.h" | 16 #include "ppapi/thunk/ppb_image_data_api.h" |
| 15 #include "ppapi/thunk/thunk.h" | 17 #include "ppapi/thunk/thunk.h" |
| 16 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 using WebKit::WebFont; | 35 using WebKit::WebFont; |
| 34 using WebKit::WebFontDescription; | 36 using WebKit::WebFontDescription; |
| 35 using WebKit::WebRect; | 37 using WebKit::WebRect; |
| 36 using WebKit::WebTextRun; | 38 using WebKit::WebTextRun; |
| 37 using WebKit::WebCanvas; | 39 using WebKit::WebCanvas; |
| 38 | 40 |
| 39 namespace ppapi { | 41 namespace ppapi { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 45 const char* kCommonScript = uscript_getShortName(USCRIPT_COMMON); |
| 46 |
| 47 string16 GetFontFromMap(const WebPreferences::ScriptFontFamilyMap& map, |
| 48 const std::string& script) { |
| 49 WebPreferences::ScriptFontFamilyMap::const_iterator it = map.find(script); |
| 50 if (it != map.end()) |
| 51 return it->second; |
| 52 return string16(); |
| 53 } |
| 54 |
| 43 // Converts the given PP_TextRun to a TextRun, returning true on success. | 55 // Converts the given PP_TextRun to a TextRun, returning true on success. |
| 44 // False means the input was invalid. | 56 // False means the input was invalid. |
| 45 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 57 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
| 46 WebKitForwarding::Font::TextRun* output) { | 58 WebKitForwarding::Font::TextRun* output) { |
| 47 StringVar* text_string = StringVar::FromPPVar(run->text); | 59 StringVar* text_string = StringVar::FromPPVar(run->text); |
| 48 if (!text_string) | 60 if (!text_string) |
| 49 return false; | 61 return false; |
| 50 | 62 |
| 51 output->text = text_string->value(); | 63 output->text = text_string->value(); |
| 52 output->rtl = run->rtl == PP_TRUE ? true : false; | 64 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 == | 97 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == |
| 86 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), | 98 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), |
| 87 MonospaceFamily); | 99 MonospaceFamily); |
| 88 | 100 |
| 89 WebFontDescription result; | 101 WebFontDescription result; |
| 90 string16 resolved_family; | 102 string16 resolved_family; |
| 91 if (face.empty()) { | 103 if (face.empty()) { |
| 92 // Resolve the generic family. | 104 // Resolve the generic family. |
| 93 switch (font.family) { | 105 switch (font.family) { |
| 94 case PP_FONTFAMILY_SERIF: | 106 case PP_FONTFAMILY_SERIF: |
| 95 resolved_family = prefs.serif_font_family; | 107 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
| 108 kCommonScript); |
| 96 break; | 109 break; |
| 97 case PP_FONTFAMILY_SANSSERIF: | 110 case PP_FONTFAMILY_SANSSERIF: |
| 98 resolved_family = prefs.sans_serif_font_family; | 111 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map, |
| 112 kCommonScript); |
| 99 break; | 113 break; |
| 100 case PP_FONTFAMILY_MONOSPACE: | 114 case PP_FONTFAMILY_MONOSPACE: |
| 101 resolved_family = prefs.fixed_font_family; | 115 resolved_family = GetFontFromMap(prefs.fixed_font_family_map, |
| 116 kCommonScript); |
| 102 break; | 117 break; |
| 103 case PP_FONTFAMILY_DEFAULT: | 118 case PP_FONTFAMILY_DEFAULT: |
| 104 default: | 119 default: |
| 105 resolved_family = prefs.standard_font_family; | 120 resolved_family = GetFontFromMap(prefs.standard_font_family_map, |
| 121 kCommonScript); |
| 106 break; | 122 break; |
| 107 } | 123 } |
| 108 } else { | 124 } else { |
| 109 // Use the exact font. | 125 // Use the exact font. |
| 110 resolved_family = UTF8ToUTF16(face); | 126 resolved_family = UTF8ToUTF16(face); |
| 111 } | 127 } |
| 112 result.family = resolved_family; | 128 result.family = resolved_family; |
| 113 | 129 |
| 114 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); | 130 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); |
| 115 | 131 |
| 116 if (font.size == 0) { | 132 if (font.size == 0) { |
| 117 // Resolve the default font size, using the resolved family to see if | 133 // 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 | 134 // 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 | 135 // 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. | 136 // the alternate font size to the default fixed font family. |
| 121 if (StringToLowerASCII(resolved_family) == | 137 if (StringToLowerASCII(resolved_family) == |
| 122 StringToLowerASCII(prefs.fixed_font_family)) | 138 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map, |
| 139 kCommonScript))) |
| 123 result.size = static_cast<float>(prefs.default_fixed_font_size); | 140 result.size = static_cast<float>(prefs.default_fixed_font_size); |
| 124 else | 141 else |
| 125 result.size = static_cast<float>(prefs.default_font_size); | 142 result.size = static_cast<float>(prefs.default_font_size); |
| 126 } else { | 143 } else { |
| 127 // Use the exact size. | 144 // Use the exact size. |
| 128 result.size = static_cast<float>(font.size); | 145 result.size = static_cast<float>(font.size); |
| 129 } | 146 } |
| 130 | 147 |
| 131 result.italic = font.italic != PP_FALSE; | 148 result.italic = font.italic != PP_FALSE; |
| 132 result.smallCaps = font.small_caps != PP_FALSE; | 149 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) { | 411 uint32_t char_offset) { |
| 395 int32_t result = -1; | 412 int32_t result = -1; |
| 396 WebKitForwarding::Font::TextRun run; | 413 WebKitForwarding::Font::TextRun run; |
| 397 if (PPTextRunToTextRun(text, &run)) { | 414 if (PPTextRunToTextRun(text, &run)) { |
| 398 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); | 415 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); |
| 399 } | 416 } |
| 400 return result; | 417 return result; |
| 401 } | 418 } |
| 402 | 419 |
| 403 } // namespace ppapi | 420 } // namespace ppapi |
| 404 | |
| OLD | NEW |