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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 size_t row_bytes; | 334 size_t row_bytes; |
335 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); | 335 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); |
336 if (!pixels) | 336 if (!pixels) |
337 return result; | 337 return result; |
338 | 338 |
339 SkBitmap bm; | 339 SkBitmap bm; |
340 if (!bm.installPixels(info, pixels, row_bytes)) | 340 if (!bm.installPixels(info, pixels, row_bytes)) |
341 return result; | 341 return result; |
342 | 342 |
343 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 343 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
344 SkCanvas temp_canvas(bm, props); | 344 cc::PaintCanvas temp_canvas(bm, props); |
345 | 345 |
346 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); | 346 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); |
347 } else { | 347 } else { |
348 DrawTextToCanvas(canvas, *text, position, color, clip); | 348 cc::PaintCanvas temp_canvas(canvas); |
| 349 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); |
349 } | 350 } |
350 | 351 |
351 if (needs_unmapping) | 352 if (needs_unmapping) |
352 image->Unmap(); | 353 image->Unmap(); |
353 return PP_TRUE; | 354 return PP_TRUE; |
354 } | 355 } |
355 | 356 |
356 int32_t BrowserFontResource_Trusted::MeasureText( | 357 int32_t BrowserFontResource_Trusted::MeasureText( |
357 const PP_BrowserFont_Trusted_TextRun* text) { | 358 const PP_BrowserFont_Trusted_TextRun* text) { |
358 WebTextRun run; | 359 WebTextRun run; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } else { | 408 } else { |
408 // Character is past this run, account for the pixels and continue | 409 // Character is past this run, account for the pixels and continue |
409 // looking. | 410 // looking. |
410 cur_pixel_offset += font_->calculateWidth(run); | 411 cur_pixel_offset += font_->calculateWidth(run); |
411 } | 412 } |
412 } | 413 } |
413 return -1; // Requested a char beyond the end. | 414 return -1; // Requested a char beyond the end. |
414 } | 415 } |
415 | 416 |
416 void BrowserFontResource_Trusted::DrawTextToCanvas( | 417 void BrowserFontResource_Trusted::DrawTextToCanvas( |
417 SkCanvas* destination, | 418 cc::PaintCanvas* destination, |
418 const PP_BrowserFont_Trusted_TextRun& text, | 419 const PP_BrowserFont_Trusted_TextRun& text, |
419 const PP_Point* position, | 420 const PP_Point* position, |
420 uint32_t color, | 421 uint32_t color, |
421 const PP_Rect* clip) { | 422 const PP_Rect* clip) { |
422 // Convert position and clip. | 423 // Convert position and clip. |
423 WebFloatPoint web_position(static_cast<float>(position->x), | 424 WebFloatPoint web_position(static_cast<float>(position->x), |
424 static_cast<float>(position->y)); | 425 static_cast<float>(position->y)); |
425 WebRect web_clip; | 426 WebRect web_clip; |
426 if (!clip) { | 427 if (!clip) { |
427 // Use entire canvas. SkCanvas doesn't have a size on it, so we just use | 428 // Use entire canvas. PaintCanvas doesn't have a size on it, so we just use |
428 // the current clip bounds. | 429 // the current clip bounds. |
429 SkRect skclip = destination->getLocalClipBounds(); | 430 SkRect skclip = destination->getLocalClipBounds(); |
430 web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft, | 431 web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft, |
431 skclip.fBottom - skclip.fTop); | 432 skclip.fBottom - skclip.fTop); |
432 } else { | 433 } else { |
433 web_clip = WebRect(clip->point.x, clip->point.y, | 434 web_clip = WebRect(clip->point.x, clip->point.y, |
434 clip->size.width, clip->size.height); | 435 clip->size.width, clip->size.height); |
435 } | 436 } |
436 | 437 |
437 TextRunCollection runs(text); | 438 TextRunCollection runs(text); |
438 for (int i = 0; i < runs.num_runs(); i++) { | 439 for (int i = 0; i < runs.num_runs(); i++) { |
439 int32_t run_begin = 0; | 440 int32_t run_begin = 0; |
440 int32_t run_len = 0; | 441 int32_t run_len = 0; |
441 WebTextRun run = runs.GetRunAt(i, &run_begin, &run_len); | 442 WebTextRun run = runs.GetRunAt(i, &run_begin, &run_len); |
442 font_->drawText(destination, run, web_position, color, web_clip); | 443 font_->drawText(destination, run, web_position, color, web_clip); |
443 | 444 |
444 // Advance to the next run. Note that we avoid doing this for the last run | 445 // Advance to the next run. Note that we avoid doing this for the last run |
445 // since it's unnecessary, measuring text is slow, and most of the time | 446 // since it's unnecessary, measuring text is slow, and most of the time |
446 // there will be only one run anyway. | 447 // there will be only one run anyway. |
447 if (i != runs.num_runs() - 1) | 448 if (i != runs.num_runs() - 1) |
448 web_position.x += font_->calculateWidth(run); | 449 web_position.x += font_->calculateWidth(run); |
449 } | 450 } |
450 } | 451 } |
451 | 452 |
452 } // namespace content | 453 } // namespace content |
OLD | NEW |