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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return false; | 295 return false; |
296 | 296 |
297 // Check for excessive sizes which may cause layout to get confused. | 297 // Check for excessive sizes which may cause layout to get confused. |
298 if (desc.size > 200) | 298 if (desc.size > 200) |
299 return false; | 299 return false; |
300 | 300 |
301 return true; | 301 return true; |
302 } | 302 } |
303 | 303 |
304 // static | 304 // static |
305 PP_Resource PPB_Font_Shared::CreateAsImpl( | 305 PP_Resource PPB_Font_Shared::Create(ResourceObjectType type, |
306 PP_Instance instance, | 306 PP_Instance instance, |
307 const PP_FontDescription_Dev& description, | 307 const PP_FontDescription_Dev& description, |
308 const ::ppapi::Preferences& prefs) { | 308 const ::ppapi::Preferences& prefs) { |
309 if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description)) | 309 if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description)) |
310 return 0; | 310 return 0; |
311 return (new PPB_Font_Shared(InitAsImpl(), instance, description, | 311 return (new PPB_Font_Shared(type, instance, description, |
312 prefs))->GetReference(); | 312 prefs))->GetReference(); |
313 } | 313 } |
314 | 314 |
315 // static | 315 PPB_Font_Shared::PPB_Font_Shared(ResourceObjectType type, |
316 PP_Resource PPB_Font_Shared::CreateAsProxy( | 316 PP_Instance instance, |
317 PP_Instance instance, | |
318 const PP_FontDescription_Dev& description, | |
319 const ::ppapi::Preferences& prefs) { | |
320 if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description)) | |
321 return 0; | |
322 return (new PPB_Font_Shared(InitAsProxy(), instance, description, | |
323 prefs))->GetReference(); | |
324 } | |
325 | |
326 PPB_Font_Shared::PPB_Font_Shared(const InitAsImpl&, | |
327 PP_Instance pp_instance, | |
328 const PP_FontDescription_Dev& desc, | 317 const PP_FontDescription_Dev& desc, |
329 const ::ppapi::Preferences& prefs) | 318 const ::ppapi::Preferences& prefs) |
330 : Resource(pp_instance) { | 319 : Resource(type, instance) { |
331 Initialize(desc, prefs); | 320 StringVar* face_name = StringVar::FromPPVar(desc.face); |
332 } | 321 font_impl_.reset(new FontImpl( |
333 | 322 desc, face_name ? face_name->value() : std::string(), prefs)); |
334 PPB_Font_Shared::PPB_Font_Shared(const InitAsProxy&, | |
335 PP_Instance pp_instance, | |
336 const PP_FontDescription_Dev& desc, | |
337 const ::ppapi::Preferences& prefs) | |
338 : Resource(HostResource::MakeInstanceOnly(pp_instance)) { | |
339 Initialize(desc, prefs); | |
340 } | 323 } |
341 | 324 |
342 PPB_Font_Shared::~PPB_Font_Shared() { | 325 PPB_Font_Shared::~PPB_Font_Shared() { |
343 } | 326 } |
344 | 327 |
345 ::ppapi::thunk::PPB_Font_API* PPB_Font_Shared::AsPPB_Font_API() { | 328 ::ppapi::thunk::PPB_Font_API* PPB_Font_Shared::AsPPB_Font_API() { |
346 return this; | 329 return this; |
347 } | 330 } |
348 | 331 |
349 PP_Bool PPB_Font_Shared::Describe(PP_FontDescription_Dev* description, | 332 PP_Bool PPB_Font_Shared::Describe(PP_FontDescription_Dev* description, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 int32_t PPB_Font_Shared::PixelOffsetForCharacter(const PP_TextRun_Dev* text, | 401 int32_t PPB_Font_Shared::PixelOffsetForCharacter(const PP_TextRun_Dev* text, |
419 uint32_t char_offset) { | 402 uint32_t char_offset) { |
420 int32_t result = -1; | 403 int32_t result = -1; |
421 WebKitForwarding::Font::TextRun run; | 404 WebKitForwarding::Font::TextRun run; |
422 if (PPTextRunToTextRun(text, &run)) { | 405 if (PPTextRunToTextRun(text, &run)) { |
423 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); | 406 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); |
424 } | 407 } |
425 return result; | 408 return result; |
426 } | 409 } |
427 | 410 |
428 void PPB_Font_Shared::Initialize(const PP_FontDescription_Dev& desc, | |
429 const ::ppapi::Preferences& prefs) { | |
430 StringVar* face_name = StringVar::FromPPVar(desc.face); | |
431 | |
432 font_impl_.reset(new FontImpl( | |
433 desc, face_name ? face_name->value() : std::string(), prefs)); | |
434 } | |
435 | |
436 } // namespace ppapi | 411 } // namespace ppapi |
437 | 412 |
OLD | NEW |