Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 26 matching lines...) Expand all Loading... | |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 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" | |
| 48 #elif defined(OS_MACOSX) | 47 #elif defined(OS_MACOSX) |
| 49 #include <CoreGraphics/CGContext.h> | 48 #include <CoreGraphics/CGContext.h> |
| 50 | 49 |
| 51 #include "base/mac/scoped_cftyperef.h" | 50 #include "base/mac/scoped_cftyperef.h" |
| 52 #include "base/sys_string_conversions.h" | 51 #include "base/sys_string_conversions.h" |
| 53 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" | 52 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" |
| 54 #endif | 53 #endif |
| 55 | 54 |
| 56 #if defined(OS_MACOSX) | 55 #if defined(OS_MACOSX) |
| 57 using base::mac::ScopedCFTypeRef; | 56 using base::mac::ScopedCFTypeRef; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 void PrintHeaderFooterText( | 216 void PrintHeaderFooterText( |
| 218 string16 text, | 217 string16 text, |
| 219 WebKit::WebCanvas* canvas, | 218 WebKit::WebCanvas* canvas, |
| 220 HeaderFooterPaint paint, | 219 HeaderFooterPaint paint, |
| 221 float webkit_scale_factor, | 220 float webkit_scale_factor, |
| 222 const PageSizeMargins& page_layout, | 221 const PageSizeMargins& page_layout, |
| 223 printing::HorizontalHeaderFooterPosition horizontal_position, | 222 printing::HorizontalHeaderFooterPosition horizontal_position, |
| 224 printing::VerticalHeaderFooterPosition vertical_position, | 223 printing::VerticalHeaderFooterPosition vertical_position, |
| 225 double offset_to_baseline) { | 224 double offset_to_baseline) { |
| 226 #if defined(USE_SKIA) | 225 #if defined(USE_SKIA) |
| 227 size_t text_byte_length = text.length() * sizeof(char16); | 226 // Convert text to glyphs first. |
| 228 double text_width_in_points = SkScalarToDouble(paint.measureText( | 227 std::vector<uint16_t> glyphs; |
|
jungshik at Google
2012/01/06 22:38:45
Just using an array of glyphs does not work well b
| |
| 229 text.c_str(), text_byte_length)); | 228 if (!PrintWebViewHelper::ConvertTextToGlyphs(paint.getTypeface(), |
| 230 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, | 229 text, &glyphs)) { |
| 231 horizontal_position, | 230 // Conversion failed, fall back to draw text. |
| 232 vertical_position, offset_to_baseline, | 231 size_t text_byte_length = text.length() * sizeof(char16); |
| 233 text_width_in_points); | 232 double text_width_in_points = SkScalarToDouble(paint.measureText( |
| 234 paint.setTextSize(SkDoubleToScalar( | 233 text.c_str(), text_byte_length)); |
| 235 paint.getTextSize() / webkit_scale_factor)); | 234 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, |
| 236 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), | 235 horizontal_position, |
| 237 paint); | 236 vertical_position, |
| 237 offset_to_baseline, | |
| 238 text_width_in_points); | |
| 239 paint.setTextSize(SkDoubleToScalar( | |
| 240 paint.getTextSize() / webkit_scale_factor)); | |
| 241 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), | |
| 242 paint); | |
| 243 } else { | |
| 244 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 245 size_t glyphs_byte_length = glyphs.size() * sizeof(uint16_t); | |
| 246 double text_width_in_points = SkScalarToDouble(paint.measureText( | |
| 247 &glyphs[0], glyphs_byte_length)); | |
| 248 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, | |
| 249 horizontal_position, | |
| 250 vertical_position, | |
| 251 offset_to_baseline, | |
| 252 text_width_in_points); | |
| 253 paint.setTextSize(SkDoubleToScalar( | |
| 254 paint.getTextSize() / webkit_scale_factor)); | |
| 255 canvas->drawText(&glyphs[0], glyphs_byte_length, point.x(), point.y(), | |
| 256 paint); | |
| 257 } | |
| 238 #elif defined(OS_MACOSX) | 258 #elif defined(OS_MACOSX) |
| 239 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); | 259 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); |
| 240 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( | 260 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( |
| 241 CFAttributedStringCreate(NULL, cf_text, paint)); | 261 CFAttributedStringCreate(NULL, cf_text, paint)); |
| 242 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString( | 262 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString( |
| 243 cf_attr_text)); | 263 cf_attr_text)); |
| 244 double text_width_in_points = | 264 double text_width_in_points = |
| 245 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor; | 265 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor; |
| 246 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, | 266 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, |
| 247 page_layout, horizontal_position, | 267 page_layout, horizontal_position, |
| (...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1557 DCHECK(IsRendering()); | 1577 DCHECK(IsRendering()); |
| 1558 return prep_frame_view_->GetPrintCanvasSize(); | 1578 return prep_frame_view_->GetPrintCanvasSize(); |
| 1559 } | 1579 } |
| 1560 | 1580 |
| 1561 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1581 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1562 prep_frame_view_.reset(); | 1582 prep_frame_view_.reset(); |
| 1563 metafile_.reset(); | 1583 metafile_.reset(); |
| 1564 pages_to_render_.clear(); | 1584 pages_to_render_.clear(); |
| 1565 error_ = PREVIEW_ERROR_NONE; | 1585 error_ = PREVIEW_ERROR_NONE; |
| 1566 } | 1586 } |
| OLD | NEW |