diff options
author | arthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 22:54:20 +0000 |
---|---|---|
committer | arthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 22:54:20 +0000 |
commit | 1c4464ac557ad0e99dbd7fb13bdb1ca0ed1812cf (patch) | |
tree | 4f063172373b4893032341107c728750fb081fc8 /chrome | |
parent | 0011a07feb55bba4bf0cf3c93d00240eda06c11a (diff) | |
download | chromium_src-1c4464ac557ad0e99dbd7fb13bdb1ca0ed1812cf.zip chromium_src-1c4464ac557ad0e99dbd7fb13bdb1ca0ed1812cf.tar.gz chromium_src-1c4464ac557ad0e99dbd7fb13bdb1ca0ed1812cf.tar.bz2 |
Fix RTL and complex script title in print preview header/footer.
Mac fixes is not there yet since RenderText does not support Mac for now.
BUG=108599
TEST=print preview pages in different languages
Review URL: https://chromiumcodereview.appspot.com/9111042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index b31cd85..1a06ad6 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -49,6 +49,10 @@ #include "skia/ext/vector_canvas.h" #include "skia/ext/vector_platform_device_skia.h" #include "third_party/skia/include/core/SkTypeface.h" +#if defined(OS_WIN) // Currently Windows only +#include "ui/gfx/canvas.h" +#include "ui/gfx/render_text.h" +#endif // USE_SKIA && defined(OS_WIN) #elif defined(OS_MACOSX) #include <CoreGraphics/CGContext.h> @@ -394,6 +398,65 @@ SkPoint GetHeaderFooterPosition( return point; } +#if defined(USE_SKIA) && defined(OS_WIN) +void PrintHeaderFooterByRenderText( + const string16& text, + WebKit::WebCanvas* canvas, + HeaderFooterPaint paint, + float webkit_scale_factor, + const PageSizeMargins& page_layout, + printing::HorizontalHeaderFooterPosition horizontal_position, + printing::VerticalHeaderFooterPosition vertical_position, + double offset_to_baseline) { + // TODO(arthurhsu): Following code works on Windows only so far. + // See crbug.com/108599 and its blockers for more information. + scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateRenderText()); + render_text->SetText(text); + int font_size = printing::kSettingHeaderFooterFontSize / webkit_scale_factor; + render_text->SetFontSize(font_size); + gfx::Size text_size = render_text->GetStringSize(); + int text_height = text_size.height(); + int y_offset = text_height - font_size; + SkScalar margin_left = page_layout.margin_left / webkit_scale_factor; + SkScalar margin_top = page_layout.margin_top / webkit_scale_factor; + SkScalar content_height = page_layout.content_height / webkit_scale_factor; + + int text_width = text_size.width(); + SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, + horizontal_position, + vertical_position, offset_to_baseline, + SkScalarToDouble(text_width)); + point.set(point.x() + margin_left, point.y() + margin_top); + // Workaround clipping issue of RenderText by adjusting the y_offset to make + // sure that display rect overlaps with content area. + if (vertical_position == printing::TOP) { + // Bottom of display rect must overlap with content. + int display_rect_y = point.y() - y_offset + text_height; + int content_y = margin_top + 1; + if (display_rect_y < content_y) { + y_offset = point.y() + text_height - content_y; + } + } else { // BOTTOM + // Top of display rect must overlap with content. + int display_rect_y = point.y() - y_offset; + int content_y = margin_top + content_height - 1; + if (display_rect_y > content_y) { + y_offset = point.y() - content_y; + } + } + + gfx::Rect rect(point.x(), point.y() - y_offset, text_width, text_height); + render_text->SetDisplayRect(rect); + int save_count = canvas->save(); + canvas->translate(-margin_left, -margin_top); + { + gfx::Canvas gfx_canvas(canvas); + render_text->Draw(&gfx_canvas); + } + canvas->restoreToCount(save_count); +} +#endif + // Given a text, the positions, and the paint object, this method gets the // coordinates and prints the text at those coordinates on the canvas. void PrintHeaderFooterText( @@ -406,6 +469,12 @@ void PrintHeaderFooterText( printing::VerticalHeaderFooterPosition vertical_position, double offset_to_baseline) { #if defined(USE_SKIA) +#if defined(OS_WIN) + PrintHeaderFooterByRenderText(text, canvas, paint, webkit_scale_factor, + page_layout, horizontal_position, vertical_position, offset_to_baseline); +#else + // TODO(arthurhsu): following code has issues with i18n BiDi, see + // crbug.com/108599. size_t text_byte_length = text.length() * sizeof(char16); double text_width_in_points = SkScalarToDouble(paint.measureText( text.c_str(), text_byte_length)); @@ -417,6 +486,7 @@ void PrintHeaderFooterText( paint.getTextSize() / webkit_scale_factor)); canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), paint); +#endif // USE_SKIA && OS_WIN #elif defined(OS_MACOSX) ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( |