| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_font.h" | 5 #include "webkit/glue/plugins/pepper_font.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/ppapi/c/pp_rect.h" | 9 #include "third_party/ppapi/c/pp_rect.h" |
| 10 #include "third_party/ppapi/c/ppb_font.h" | 10 #include "third_party/ppapi/c/ppb_font.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace pepper { | 30 namespace pepper { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool IsPPFontDescriptionValid(const PP_FontDescription& desc) { | 34 bool IsPPFontDescriptionValid(const PP_FontDescription& desc) { |
| 35 // Check validity of UTF-8. | 35 // Check validity of UTF-8. |
| 36 if (desc.face.type != PP_VARTYPE_STRING && desc.face.type != PP_VARTYPE_VOID) | 36 if (desc.face.type != PP_VARTYPE_STRING && desc.face.type != PP_VARTYPE_VOID) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 // Check enum ranges. |
| 39 if (static_cast<int>(desc.family) < PP_FONTFAMILY_DEFAULT || | 40 if (static_cast<int>(desc.family) < PP_FONTFAMILY_DEFAULT || |
| 40 static_cast<int>(desc.family) > PP_FONTFAMILY_MONOSPACE) | 41 static_cast<int>(desc.family) > PP_FONTFAMILY_MONOSPACE) |
| 41 return false; | 42 return false; |
| 42 if (static_cast<int>(desc.weight) < PP_FONTWEIGHT_100 || | 43 if (static_cast<int>(desc.weight) < PP_FONTWEIGHT_100 || |
| 43 static_cast<int>(desc.weight) > PP_FONTWEIGHT_900) | 44 static_cast<int>(desc.weight) > PP_FONTWEIGHT_900) |
| 44 return false; | 45 return false; |
| 45 | 46 |
| 47 // Check for excessive sizes which may cause layout to get confused. |
| 48 if (desc.size() > 200) |
| 49 return false; |
| 50 |
| 46 return true; | 51 return true; |
| 47 } | 52 } |
| 48 | 53 |
| 49 // The PP_* version lacks "None", so is just one value shifted from the | 54 // The PP_* version lacks "None", so is just one value shifted from the |
| 50 // WebFontDescription version. These values are checked in | 55 // WebFontDescription version. These values are checked in |
| 51 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a | 56 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a |
| 52 // macro so it can also be used in the COMPILE_ASSERTS. | 57 // macro so it can also be used in the COMPILE_ASSERTS. |
| 53 #define PP_FONTFAMILY_TO_WEB_FONTFAMILY(f) \ | 58 #define PP_FONTFAMILY_TO_WEB_FONTFAMILY(f) \ |
| 54 static_cast<WebFontDescription::GenericFamily>(f + 1) | 59 static_cast<WebFontDescription::GenericFamily>(f + 1) |
| 55 | 60 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 return -1; | 281 return -1; |
| 277 if (char_offset >= run.text.length()) | 282 if (char_offset >= run.text.length()) |
| 278 return -1; | 283 return -1; |
| 279 | 284 |
| 280 WebFloatRect rect = font_->selectionRectForText( | 285 WebFloatRect rect = font_->selectionRectForText( |
| 281 run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset); | 286 run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset); |
| 282 return static_cast<int>(rect.width); | 287 return static_cast<int>(rect.width); |
| 283 } | 288 } |
| 284 | 289 |
| 285 } // namespace pepper | 290 } // namespace pepper |
| OLD | NEW |