| 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 "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/common/web_preferences.h" | 9 #include "content/public/common/web_preferences.h" |
| 10 #include "ppapi/c/dev/ppb_font_dev.h" | 10 #include "ppapi/c/dev/ppb_font_dev.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 SkCanvas* canvas = image->GetPlatformCanvas(); | 312 SkCanvas* canvas = image->GetPlatformCanvas(); |
| 313 bool needs_unmapping = false; | 313 bool needs_unmapping = false; |
| 314 if (!canvas) { | 314 if (!canvas) { |
| 315 needs_unmapping = true; | 315 needs_unmapping = true; |
| 316 image->Map(); | 316 image->Map(); |
| 317 canvas = image->GetPlatformCanvas(); | 317 canvas = image->GetPlatformCanvas(); |
| 318 if (!canvas) | 318 if (!canvas) |
| 319 return result; // Failure mapping. | 319 return result; // Failure mapping. |
| 320 } | 320 } |
| 321 | 321 |
| 322 DrawTextToCanvas(canvas, *text, position, color, clip, image_data_is_opaque); | 322 if (!PP_ToBool(image_data_is_opaque)) { |
| 323 // Ideally, LCD text should be configured at canvas creation time using |
| 324 // SkSurfaceProps. But because the API exposes image_data_is_opaque per |
| 325 // draw text call (allowing clients to essentially change their mind), |
| 326 // we have to handle it here. |
| 327 SkImageInfo info; |
| 328 size_t row_bytes; |
| 329 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); |
| 330 if (!pixels) |
| 331 return result; |
| 332 |
| 333 SkBitmap bm; |
| 334 if (!bm.installPixels(info, pixels, row_bytes)) |
| 335 return result; |
| 336 |
| 337 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
| 338 SkCanvas temp_canvas(bm, props); |
| 339 |
| 340 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); |
| 341 } else { |
| 342 DrawTextToCanvas(canvas, *text, position, color, clip); |
| 343 } |
| 323 | 344 |
| 324 if (needs_unmapping) | 345 if (needs_unmapping) |
| 325 image->Unmap(); | 346 image->Unmap(); |
| 326 return PP_TRUE; | 347 return PP_TRUE; |
| 327 } | 348 } |
| 328 | 349 |
| 329 int32_t BrowserFontResource_Trusted::MeasureText( | 350 int32_t BrowserFontResource_Trusted::MeasureText( |
| 330 const PP_BrowserFont_Trusted_TextRun* text) { | 351 const PP_BrowserFont_Trusted_TextRun* text) { |
| 331 WebTextRun run; | 352 WebTextRun run; |
| 332 if (!PPTextRunToWebTextRun(*text, &run)) | 353 if (!PPTextRunToWebTextRun(*text, &run)) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 405 } |
| 385 } | 406 } |
| 386 return -1; // Requested a char beyond the end. | 407 return -1; // Requested a char beyond the end. |
| 387 } | 408 } |
| 388 | 409 |
| 389 void BrowserFontResource_Trusted::DrawTextToCanvas( | 410 void BrowserFontResource_Trusted::DrawTextToCanvas( |
| 390 SkCanvas* destination, | 411 SkCanvas* destination, |
| 391 const PP_BrowserFont_Trusted_TextRun& text, | 412 const PP_BrowserFont_Trusted_TextRun& text, |
| 392 const PP_Point* position, | 413 const PP_Point* position, |
| 393 uint32_t color, | 414 uint32_t color, |
| 394 const PP_Rect* clip, | 415 const PP_Rect* clip) { |
| 395 PP_Bool image_data_is_opaque) { | |
| 396 // Convert position and clip. | 416 // Convert position and clip. |
| 397 WebFloatPoint web_position(static_cast<float>(position->x), | 417 WebFloatPoint web_position(static_cast<float>(position->x), |
| 398 static_cast<float>(position->y)); | 418 static_cast<float>(position->y)); |
| 399 WebRect web_clip; | 419 WebRect web_clip; |
| 400 if (!clip) { | 420 if (!clip) { |
| 401 // Use entire canvas. SkCanvas doesn't have a size on it, so we just use | 421 // Use entire canvas. SkCanvas doesn't have a size on it, so we just use |
| 402 // the current clip bounds. | 422 // the current clip bounds. |
| 403 SkRect skclip; | 423 SkRect skclip; |
| 404 destination->getClipBounds(&skclip); | 424 destination->getClipBounds(&skclip); |
| 405 web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft, | 425 web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft, |
| 406 skclip.fBottom - skclip.fTop); | 426 skclip.fBottom - skclip.fTop); |
| 407 } else { | 427 } else { |
| 408 web_clip = WebRect(clip->point.x, clip->point.y, | 428 web_clip = WebRect(clip->point.x, clip->point.y, |
| 409 clip->size.width, clip->size.height); | 429 clip->size.width, clip->size.height); |
| 410 } | 430 } |
| 411 | 431 |
| 412 TextRunCollection runs(text); | 432 TextRunCollection runs(text); |
| 413 for (int i = 0; i < runs.num_runs(); i++) { | 433 for (int i = 0; i < runs.num_runs(); i++) { |
| 414 int32_t run_begin = 0; | 434 int32_t run_begin = 0; |
| 415 int32_t run_len = 0; | 435 int32_t run_len = 0; |
| 416 WebTextRun run = runs.GetRunAt(i, &run_begin, &run_len); | 436 WebTextRun run = runs.GetRunAt(i, &run_begin, &run_len); |
| 417 font_->drawText(destination, run, web_position, color, web_clip, | 437 font_->drawText(destination, run, web_position, color, web_clip); |
| 418 PP_ToBool(image_data_is_opaque)); | |
| 419 | 438 |
| 420 // Advance to the next run. Note that we avoid doing this for the last run | 439 // Advance to the next run. Note that we avoid doing this for the last run |
| 421 // since it's unnecessary, measuring text is slow, and most of the time | 440 // since it's unnecessary, measuring text is slow, and most of the time |
| 422 // there will be only one run anyway. | 441 // there will be only one run anyway. |
| 423 if (i != runs.num_runs() - 1) | 442 if (i != runs.num_runs() - 1) |
| 424 web_position.x += font_->calculateWidth(run); | 443 web_position.x += font_->calculateWidth(run); |
| 425 } | 444 } |
| 426 } | 445 } |
| 427 | 446 |
| 428 } // namespace content | 447 } // namespace content |
| OLD | NEW |