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_browser_font_trusted_shared.h" | 5 #include "ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/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/shared_impl/ppapi_preferences.h" | 10 #include "ppapi/shared_impl/ppapi_preferences.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 const PP_Rect* clip, | 314 const PP_Rect* clip, |
315 PP_Bool image_data_is_opaque) { | 315 PP_Bool image_data_is_opaque) { |
316 PP_Bool result = PP_FALSE; | 316 PP_Bool result = PP_FALSE; |
317 // Get and map the image data we're painting to. | 317 // Get and map the image data we're painting to. |
318 EnterResourceNoLock<PPB_ImageData_API> enter(image_data, true); | 318 EnterResourceNoLock<PPB_ImageData_API> enter(image_data, true); |
319 if (enter.failed()) | 319 if (enter.failed()) |
320 return result; | 320 return result; |
321 | 321 |
322 PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>( | 322 PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>( |
323 enter.object()); | 323 enter.object()); |
324 skia::PlatformCanvas* canvas = image->GetPlatformCanvas(); | 324 SkCanvas* canvas = image->GetPlatformCanvas(); |
325 bool needs_unmapping = false; | 325 bool needs_unmapping = false; |
326 if (!canvas) { | 326 if (!canvas) { |
327 needs_unmapping = true; | 327 needs_unmapping = true; |
328 image->Map(); | 328 image->Map(); |
329 canvas = image->GetPlatformCanvas(); | 329 canvas = image->GetPlatformCanvas(); |
330 if (!canvas) | 330 if (!canvas) |
331 return result; // Failure mapping. | 331 return result; // Failure mapping. |
332 } | 332 } |
333 | 333 |
334 DrawTextToCanvas(canvas, *text, position, color, clip, image_data_is_opaque); | 334 DrawTextToCanvas(canvas, *text, position, color, clip, image_data_is_opaque); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } else { | 392 } else { |
393 // Character is past this run, account for the pixels and continue | 393 // Character is past this run, account for the pixels and continue |
394 // looking. | 394 // looking. |
395 cur_pixel_offset += font_->calculateWidth(run); | 395 cur_pixel_offset += font_->calculateWidth(run); |
396 } | 396 } |
397 } | 397 } |
398 return -1; // Requested a char beyond the end. | 398 return -1; // Requested a char beyond the end. |
399 } | 399 } |
400 | 400 |
401 void PPB_BrowserFont_Trusted_Shared::DrawTextToCanvas( | 401 void PPB_BrowserFont_Trusted_Shared::DrawTextToCanvas( |
402 skia::PlatformCanvas* destination, | 402 SkCanvas* destination, |
403 const PP_BrowserFont_Trusted_TextRun& text, | 403 const PP_BrowserFont_Trusted_TextRun& text, |
404 const PP_Point* position, | 404 const PP_Point* position, |
405 uint32_t color, | 405 uint32_t color, |
406 const PP_Rect* clip, | 406 const PP_Rect* clip, |
407 PP_Bool image_data_is_opaque) { | 407 PP_Bool image_data_is_opaque) { |
408 // Convert position and clip. | 408 // Convert position and clip. |
409 WebFloatPoint web_position(static_cast<float>(position->x), | 409 WebFloatPoint web_position(static_cast<float>(position->x), |
410 static_cast<float>(position->y)); | 410 static_cast<float>(position->y)); |
411 WebRect web_clip; | 411 WebRect web_clip; |
412 if (!clip) { | 412 if (!clip) { |
(...skipping 18 matching lines...) Expand all Loading... |
431 | 431 |
432 // Advance to the next run. Note that we avoid doing this for the last run | 432 // Advance to the next run. Note that we avoid doing this for the last run |
433 // since it's unnecessary, measuring text is slow, and most of the time | 433 // since it's unnecessary, measuring text is slow, and most of the time |
434 // there will be only one run anyway. | 434 // there will be only one run anyway. |
435 if (i != runs.num_runs() - 1) | 435 if (i != runs.num_runs() - 1) |
436 web_position.x += font_->calculateWidth(run); | 436 web_position.x += font_->calculateWidth(run); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 } // namespace ppapi | 440 } // namespace ppapi |
OLD | NEW |