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