Chromium Code Reviews| 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 "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "webkit/glue/webpreferences.h" | 38 #include "webkit/glue/webpreferences.h" |
| 39 | 39 |
| 40 #if defined(OS_POSIX) | 40 #if defined(OS_POSIX) |
| 41 #include "base/process_util.h" | 41 #include "base/process_util.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(USE_SKIA) | 44 #if defined(USE_SKIA) |
| 45 #include "skia/ext/vector_canvas.h" | 45 #include "skia/ext/vector_canvas.h" |
| 46 #include "skia/ext/vector_platform_device_skia.h" | 46 #include "skia/ext/vector_platform_device_skia.h" |
| 47 #include "third_party/skia/include/core/SkTypeface.h" | 47 #include "third_party/skia/include/core/SkTypeface.h" |
| 48 #if !defined(OS_MACOSX) // USE_SKIA && !OS_MACOSX | |
| 49 #include "ui/gfx/canvas_skia.h" | |
| 50 #include "ui/gfx/render_text.h" | |
| 51 #endif // USE_SKIA && !defined(OS_MACOSX) | |
| 48 #elif defined(OS_MACOSX) | 52 #elif defined(OS_MACOSX) |
| 49 #include <CoreGraphics/CGContext.h> | 53 #include <CoreGraphics/CGContext.h> |
| 50 | 54 |
| 51 #include "base/mac/scoped_cftyperef.h" | 55 #include "base/mac/scoped_cftyperef.h" |
| 52 #include "base/sys_string_conversions.h" | 56 #include "base/sys_string_conversions.h" |
| 53 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" | 57 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" |
| 54 #endif | 58 #endif |
| 55 | 59 |
| 56 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
| 57 using base::mac::ScopedCFTypeRef; | 61 using base::mac::ScopedCFTypeRef; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 void PrintHeaderFooterText( | 387 void PrintHeaderFooterText( |
| 384 string16 text, | 388 string16 text, |
| 385 WebKit::WebCanvas* canvas, | 389 WebKit::WebCanvas* canvas, |
| 386 HeaderFooterPaint paint, | 390 HeaderFooterPaint paint, |
| 387 float webkit_scale_factor, | 391 float webkit_scale_factor, |
| 388 const PageSizeMargins& page_layout, | 392 const PageSizeMargins& page_layout, |
| 389 printing::HorizontalHeaderFooterPosition horizontal_position, | 393 printing::HorizontalHeaderFooterPosition horizontal_position, |
| 390 printing::VerticalHeaderFooterPosition vertical_position, | 394 printing::VerticalHeaderFooterPosition vertical_position, |
| 391 double offset_to_baseline) { | 395 double offset_to_baseline) { |
| 392 #if defined(USE_SKIA) | 396 #if defined(USE_SKIA) |
| 397 #if !defined(OS_MACOSX) // RenderText does not support Mac yet. | |
| 398 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateRenderText()); | |
| 399 DCHECK(render_text.get()); | |
| 400 render_text->SetText(text); | |
| 401 render_text->SetFontSize(printing::kSettingHeaderFooterFontSize); | |
| 402 gfx::CanvasSkia gfx_canvas(canvas); | |
| 403 SkISize device_size = gfx_canvas.GetSkCanvas()->getDeviceSize(); | |
| 404 int height = render_text->GetFont().GetHeight() + | |
| 405 printing::kSettingHeaderFooterInterstice + 1; | |
| 406 int y = (vertical_position == printing::TOP) ? 1 - height : | |
| 407 device_size.height() - 1; | |
| 408 gfx::Rect rect(0, y, device_size.width(), height); | |
|
vandebo (ex-Chrome)
2012/02/03 18:36:45
As far as I can tell, this moves where the headers
| |
| 409 render_text->SetDisplayRect(rect); | |
| 410 switch (horizontal_position) { | |
| 411 case printing::LEFT: | |
| 412 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 413 break; | |
| 414 case printing::RIGHT: | |
| 415 render_text->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | |
| 416 break; | |
| 417 case printing::CENTER: | |
| 418 render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 419 break; | |
| 420 default: | |
| 421 NOTREACHED(); | |
| 422 break; | |
| 423 } | |
| 424 render_text->Draw(&gfx_canvas); | |
| 425 #else | |
| 426 // TODO(arthurhsu): following code has issues with i18n BiDi, see | |
| 427 // crbug.com/108599. Need to remove it and use RenderText | |
| 428 // code above once RenderText supports Mac. | |
| 393 size_t text_byte_length = text.length() * sizeof(char16); | 429 size_t text_byte_length = text.length() * sizeof(char16); |
| 394 double text_width_in_points = SkScalarToDouble(paint.measureText( | 430 double text_width_in_points = SkScalarToDouble(paint.measureText( |
| 395 text.c_str(), text_byte_length)); | 431 text.c_str(), text_byte_length)); |
| 396 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, | 432 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, |
| 397 horizontal_position, | 433 horizontal_position, |
| 398 vertical_position, offset_to_baseline, | 434 vertical_position, offset_to_baseline, |
| 399 text_width_in_points); | 435 text_width_in_points); |
| 400 paint.setTextSize(SkDoubleToScalar( | 436 paint.setTextSize(SkDoubleToScalar( |
| 401 paint.getTextSize() / webkit_scale_factor)); | 437 paint.getTextSize() / webkit_scale_factor)); |
| 402 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), | 438 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), |
| 403 paint); | 439 paint); |
| 440 #endif // USE_SKIA && !OS_MACOSX | |
| 404 #elif defined(OS_MACOSX) | 441 #elif defined(OS_MACOSX) |
| 405 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); | 442 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); |
| 406 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( | 443 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( |
| 407 CFAttributedStringCreate(NULL, cf_text, paint)); | 444 CFAttributedStringCreate(NULL, cf_text, paint)); |
| 408 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString( | 445 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString( |
| 409 cf_attr_text)); | 446 cf_attr_text)); |
| 410 double text_width_in_points = | 447 double text_width_in_points = |
| 411 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor; | 448 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor; |
| 412 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, | 449 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, |
| 413 page_layout, horizontal_position, | 450 page_layout, horizontal_position, |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1774 DCHECK(IsRendering()); | 1811 DCHECK(IsRendering()); |
| 1775 return prep_frame_view_->GetPrintCanvasSize(); | 1812 return prep_frame_view_->GetPrintCanvasSize(); |
| 1776 } | 1813 } |
| 1777 | 1814 |
| 1778 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1815 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1779 prep_frame_view_.reset(); | 1816 prep_frame_view_.reset(); |
| 1780 metafile_.reset(); | 1817 metafile_.reset(); |
| 1781 pages_to_render_.clear(); | 1818 pages_to_render_.clear(); |
| 1782 error_ = PREVIEW_ERROR_NONE; | 1819 error_ = PREVIEW_ERROR_NONE; |
| 1783 } | 1820 } |
| OLD | NEW |