| 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 "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 10 #include "ppapi/proxy/connection.h" | 10 #include "ppapi/proxy/connection.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 using blink::WebCanvas; | 36 using blink::WebCanvas; |
| 37 | 37 |
| 38 namespace content { | 38 namespace content { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Same as WebPreferences::kCommonScript. I'd use that directly here, but get an | 42 // Same as WebPreferences::kCommonScript. I'd use that directly here, but get an |
| 43 // undefined reference linker error. | 43 // undefined reference linker error. |
| 44 const char kCommonScript[] = "Zyyy"; | 44 const char kCommonScript[] = "Zyyy"; |
| 45 | 45 |
| 46 string16 GetFontFromMap( | 46 base::string16 GetFontFromMap( |
| 47 const webkit_glue::ScriptFontFamilyMap& map, | 47 const webkit_glue::ScriptFontFamilyMap& map, |
| 48 const std::string& script) { | 48 const std::string& script) { |
| 49 webkit_glue::ScriptFontFamilyMap::const_iterator it = | 49 webkit_glue::ScriptFontFamilyMap::const_iterator it = |
| 50 map.find(script); | 50 map.find(script); |
| 51 if (it != map.end()) | 51 if (it != map.end()) |
| 52 return it->second; | 52 return it->second; |
| 53 return string16(); | 53 return base::string16(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Splits a PP_BrowserFont_Trusted_TextRun into a sequence or LTR and RTL | 56 // Splits a PP_BrowserFont_Trusted_TextRun into a sequence or LTR and RTL |
| 57 // WebTextRuns that can be used for WebKit. Normally WebKit does this for us, | 57 // WebTextRuns that can be used for WebKit. Normally WebKit does this for us, |
| 58 // but the font drawing and measurement routines we call happen after this | 58 // but the font drawing and measurement routines we call happen after this |
| 59 // step. So for correct rendering of RTL content, we need to do it ourselves. | 59 // step. So for correct rendering of RTL content, we need to do it ourselves. |
| 60 class TextRunCollection { | 60 class TextRunCollection { |
| 61 public: | 61 public: |
| 62 explicit TextRunCollection(const PP_BrowserFont_Trusted_TextRun& run) | 62 explicit TextRunCollection(const PP_BrowserFont_Trusted_TextRun& run) |
| 63 : bidi_(NULL), | 63 : bidi_(NULL), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 if (U_SUCCESS(uerror)) | 78 if (U_SUCCESS(uerror)) |
| 79 num_runs_ = ubidi_countRuns(bidi_, &uerror); | 79 num_runs_ = ubidi_countRuns(bidi_, &uerror); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 ~TextRunCollection() { | 83 ~TextRunCollection() { |
| 84 if (bidi_) | 84 if (bidi_) |
| 85 ubidi_close(bidi_); | 85 ubidi_close(bidi_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 const string16& text() const { return text_; } | 88 const base::string16& text() const { return text_; } |
| 89 int num_runs() const { return num_runs_; } | 89 int num_runs() const { return num_runs_; } |
| 90 | 90 |
| 91 // Returns a WebTextRun with the info for the run at the given index. | 91 // Returns a WebTextRun with the info for the run at the given index. |
| 92 // The range covered by the run is in the two output params. | 92 // The range covered by the run is in the two output params. |
| 93 WebTextRun GetRunAt(int index, int32_t* run_start, int32_t* run_len) const { | 93 WebTextRun GetRunAt(int index, int32_t* run_start, int32_t* run_len) const { |
| 94 DCHECK(index < num_runs_); | 94 DCHECK(index < num_runs_); |
| 95 if (bidi_) { | 95 if (bidi_) { |
| 96 bool run_rtl = !!ubidi_getVisualRun(bidi_, index, run_start, run_len); | 96 bool run_rtl = !!ubidi_getVisualRun(bidi_, index, run_start, run_len); |
| 97 return WebTextRun(string16(&text_[*run_start], *run_len), | 97 return WebTextRun(base::string16(&text_[*run_start], *run_len), |
| 98 run_rtl, true); | 98 run_rtl, true); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Override run, return the single one. | 101 // Override run, return the single one. |
| 102 DCHECK(index == 0); | 102 DCHECK(index == 0); |
| 103 *run_start = 0; | 103 *run_start = 0; |
| 104 *run_len = static_cast<int32_t>(text_.size()); | 104 *run_len = static_cast<int32_t>(text_.size()); |
| 105 return override_run_; | 105 return override_run_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 // Will be null if we skipped autodetection. | 109 // Will be null if we skipped autodetection. |
| 110 UBiDi* bidi_; | 110 UBiDi* bidi_; |
| 111 | 111 |
| 112 // Text of all the runs. | 112 // Text of all the runs. |
| 113 string16 text_; | 113 base::string16 text_; |
| 114 | 114 |
| 115 int num_runs_; | 115 int num_runs_; |
| 116 | 116 |
| 117 // When the content specifies override_direction (bidi_ is null) then this | 117 // When the content specifies override_direction (bidi_ is null) then this |
| 118 // will contain the single text run for WebKit. | 118 // will contain the single text run for WebKit. |
| 119 WebTextRun override_run_; | 119 WebTextRun override_run_; |
| 120 | 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(TextRunCollection); | 121 DISALLOW_COPY_AND_ASSIGN(TextRunCollection); |
| 122 }; | 122 }; |
| 123 | 123 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 COMPILE_ASSERT(WebFontDescription::GenericFamilySansSerif == | 160 COMPILE_ASSERT(WebFontDescription::GenericFamilySansSerif == |
| 161 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), | 161 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), |
| 162 SansSerifFamily); | 162 SansSerifFamily); |
| 163 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == | 163 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == |
| 164 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), | 164 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), |
| 165 MonospaceFamily); | 165 MonospaceFamily); |
| 166 | 166 |
| 167 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. | 167 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. |
| 168 | 168 |
| 169 WebFontDescription result; | 169 WebFontDescription result; |
| 170 string16 resolved_family; | 170 base::string16 resolved_family; |
| 171 if (!face_name || face_name->value().empty()) { | 171 if (!face_name || face_name->value().empty()) { |
| 172 // Resolve the generic family. | 172 // Resolve the generic family. |
| 173 switch (font.family) { | 173 switch (font.family) { |
| 174 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 174 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
| 175 resolved_family = GetFontFromMap(prefs.serif_font_family_map, | 175 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
| 176 kCommonScript); | 176 kCommonScript); |
| 177 break; | 177 break; |
| 178 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: | 178 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: |
| 179 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map, | 179 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map, |
| 180 kCommonScript); | 180 kCommonScript); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 419 |
| 420 // Advance to the next run. Note that we avoid doing this for the last run | 420 // Advance to the next run. Note that we avoid doing this for the last run |
| 421 // since it's unnecessary, measuring text is slow, and most of the time | 421 // since it's unnecessary, measuring text is slow, and most of the time |
| 422 // there will be only one run anyway. | 422 // there will be only one run anyway. |
| 423 if (i != runs.num_runs() - 1) | 423 if (i != runs.num_runs() - 1) |
| 424 web_position.x += font_->calculateWidth(run); | 424 web_position.x += font_->calculateWidth(run); |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 | 427 |
| 428 } // namespace content | 428 } // namespace content |
| OLD | NEW |