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 "content/child/browser_font_resource_trusted.h" | 5 #include "content/child/browser_font_resource_trusted.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/common/web_preferences.h" | 9 #include "content/public/common/web_preferences.h" |
10 #include "ppapi/c/dev/ppb_font_dev.h" | |
11 #include "ppapi/proxy/connection.h" | 10 #include "ppapi/proxy/connection.h" |
12 #include "ppapi/shared_impl/ppapi_preferences.h" | 11 #include "ppapi/shared_impl/ppapi_preferences.h" |
13 #include "ppapi/shared_impl/var.h" | 12 #include "ppapi/shared_impl/var.h" |
14 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
15 #include "ppapi/thunk/ppb_image_data_api.h" | 14 #include "ppapi/thunk/ppb_image_data_api.h" |
16 #include "ppapi/thunk/thunk.h" | 15 #include "ppapi/thunk/thunk.h" |
17 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
18 #include "third_party/WebKit/public/platform/WebCanvas.h" | 17 #include "third_party/WebKit/public/platform/WebCanvas.h" |
19 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 18 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
20 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 19 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // The range covered by the run is in the two output params. | 90 // The range covered by the run is in the two output params. |
92 WebTextRun GetRunAt(int index, int32_t* run_start, int32_t* run_len) const { | 91 WebTextRun GetRunAt(int index, int32_t* run_start, int32_t* run_len) const { |
93 DCHECK(index < num_runs_); | 92 DCHECK(index < num_runs_); |
94 if (bidi_) { | 93 if (bidi_) { |
95 bool run_rtl = !!ubidi_getVisualRun(bidi_, index, run_start, run_len); | 94 bool run_rtl = !!ubidi_getVisualRun(bidi_, index, run_start, run_len); |
96 return WebTextRun(base::string16(&text_[*run_start], *run_len), | 95 return WebTextRun(base::string16(&text_[*run_start], *run_len), |
97 run_rtl, true); | 96 run_rtl, true); |
98 } | 97 } |
99 | 98 |
100 // Override run, return the single one. | 99 // Override run, return the single one. |
101 DCHECK(index == 0); | 100 DCHECK_EQ(0, index); |
102 *run_start = 0; | 101 *run_start = 0; |
103 *run_len = static_cast<int32_t>(text_.size()); | 102 *run_len = static_cast<int32_t>(text_.size()); |
104 return override_run_; | 103 return override_run_; |
105 } | 104 } |
106 | 105 |
107 private: | 106 private: |
108 // Will be null if we skipped autodetection. | 107 // Will be null if we skipped autodetection. |
109 UBiDi* bidi_; | 108 UBiDi* bidi_; |
110 | 109 |
111 // Text of all the runs. | 110 // Text of all the runs. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 WebFontDescription PPFontDescToWebFontDesc( | 142 WebFontDescription PPFontDescToWebFontDesc( |
144 const PP_BrowserFont_Trusted_Description& font, | 143 const PP_BrowserFont_Trusted_Description& font, |
145 const ppapi::Preferences& prefs) { | 144 const ppapi::Preferences& prefs) { |
146 // Verify that the enums match so we can just static cast. | 145 // Verify that the enums match so we can just static cast. |
147 static_assert(static_cast<int>(WebFontDescription::Weight100) == | 146 static_assert(static_cast<int>(WebFontDescription::Weight100) == |
148 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), | 147 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), |
149 "font Weight100"); | 148 "font Weight100"); |
150 static_assert(static_cast<int>(WebFontDescription::Weight900) == | 149 static_assert(static_cast<int>(WebFontDescription::Weight900) == |
151 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), | 150 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), |
152 "font Weight900"); | 151 "font Weight900"); |
153 static_assert(WebFontDescription::GenericFamilyStandard == | 152 static_assert( |
154 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), | 153 WebFontDescription::GenericFamilyStandard == |
155 "FamilyStandard"); | 154 PP_FAMILY_TO_WEB_FAMILY(PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT), |
156 static_assert(WebFontDescription::GenericFamilySerif == | 155 "FamilyStandard"); |
157 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SERIF), | 156 static_assert( |
158 "FamilySerif"); | 157 WebFontDescription::GenericFamilySerif == |
159 static_assert(WebFontDescription::GenericFamilySansSerif == | 158 PP_FAMILY_TO_WEB_FAMILY(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF), |
160 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), | 159 "FamilySerif"); |
161 "FamilySansSerif"); | 160 static_assert( |
162 static_assert(WebFontDescription::GenericFamilyMonospace == | 161 WebFontDescription::GenericFamilySansSerif == |
163 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), | 162 PP_FAMILY_TO_WEB_FAMILY(PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF), |
164 "FamilyMonospace"); | 163 "FamilySansSerif"); |
| 164 static_assert( |
| 165 WebFontDescription::GenericFamilyMonospace == |
| 166 PP_FAMILY_TO_WEB_FAMILY(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE), |
| 167 "FamilyMonospace"); |
165 | 168 |
166 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. | 169 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. |
167 | 170 |
168 WebFontDescription result; | 171 WebFontDescription result; |
169 base::string16 resolved_family; | 172 base::string16 resolved_family; |
170 if (!face_name || face_name->value().empty()) { | 173 if (!face_name || face_name->value().empty()) { |
171 // Resolve the generic family. | 174 // Resolve the generic family. |
172 switch (font.family) { | 175 switch (font.family) { |
173 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 176 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
174 resolved_family = GetFontFromMap(prefs.serif_font_family_map, | 177 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 441 |
439 // Advance to the next run. Note that we avoid doing this for the last run | 442 // Advance to the next run. Note that we avoid doing this for the last run |
440 // since it's unnecessary, measuring text is slow, and most of the time | 443 // since it's unnecessary, measuring text is slow, and most of the time |
441 // there will be only one run anyway. | 444 // there will be only one run anyway. |
442 if (i != runs.num_runs() - 1) | 445 if (i != runs.num_runs() - 1) |
443 web_position.x += font_->calculateWidth(run); | 446 web_position.x += font_->calculateWidth(run); |
444 } | 447 } |
445 } | 448 } |
446 | 449 |
447 } // namespace content | 450 } // namespace content |
OLD | NEW |