diff options
author | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 17:22:21 +0000 |
---|---|---|
committer | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 17:22:21 +0000 |
commit | f64d7a352dd29bb7bc386fc1e829a764cdc9f64e (patch) | |
tree | 11cf115dcb989391b24729eb00f438ad895e50fb | |
parent | 6c511d3b56ca0c74838e2650f326ec6a617a4350 (diff) | |
download | chromium_src-f64d7a352dd29bb7bc386fc1e829a764cdc9f64e.zip chromium_src-f64d7a352dd29bb7bc386fc1e829a764cdc9f64e.tar.gz chromium_src-f64d7a352dd29bb7bc386fc1e829a764cdc9f64e.tar.bz2 |
A better fix for scaling issue.
Instead of using TLS and static function, pass scaling in the skia dictionary.
BUG=125499
TEST=Make sure printing is working.
Review URL: https://chromiumcodereview.appspot.com/10387022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136055 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 46 | ||||
-rw-r--r-- | printing/custom_scaling.cc | 37 | ||||
-rw-r--r-- | printing/custom_scaling.h | 33 | ||||
-rw-r--r-- | printing/metafile_skia_wrapper.cc | 22 | ||||
-rw-r--r-- | printing/metafile_skia_wrapper.h | 6 | ||||
-rw-r--r-- | printing/printing.gyp | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 4 |
7 files changed, 40 insertions, 110 deletions
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 8f2e3f4..7b1916b 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -12,7 +12,6 @@ #include "base/win/scoped_hdc.h" #include "base/win/scoped_select_object.h" #include "chrome/common/print_messages.h" -#include "printing/custom_scaling.h" #include "printing/metafile.h" #include "printing/metafile_impl.h" #include "printing/metafile_skia_wrapper.h" @@ -118,41 +117,11 @@ void PrintWebViewHelper::PrintPageInternal( gfx::Size page_size_in_dpi; gfx::Rect content_area_in_dpi; - // If we are printing PDF, it may not fit into metafile using 72dpi. - // (Metafile is based on screen resolution here.) - // (See http://code.google.com/p/chromium-os/issues/detail?id=16088) - // If PDF plugin encounter this issue it will save custom scale in TLS, - // so we can apply the same scaling factor here. - // If will do so ONLY if default scaling does not work. - // TODO(gene): We should revisit this solution for the next versions. - // Two possible solutions: - // We can create metafile of the right size (or resizable) - // https://code.google.com/p/chromium/issues/detail?id=126037 - // or - // We should return scale factor all the way from the plugin: - // webkit::ppapi::PluginInstance::PrintPDFOutput - scale calculated here - // webkit::ppapi::PluginInstance::PrintPageHelper - // webkit::ppapi::PluginInstance::PrintPage - // webkit::ppapi::WebPluginImpl::printPage - // WebKit::WebPluginContainerImpl::printPage - // WebKit::ChromePluginPrintContext::spoolPage - always return 1.0 scale - // WebKit::WebFrameImpl::printPage - // PrintWebViewHelper::RenderPage - // PrintWebViewHelper::PrintPageInternal - - printing::ClearCustomPrintingPageScale(); - // Render page for printing. metafile.reset(RenderPage(params.params, page_number, frame, false, metafile.get(), &actual_shrink, &page_size_in_dpi, &content_area_in_dpi)); - double custom_scale; - if (printing::GetCustomPrintingPageScale(&custom_scale)) { - actual_shrink = custom_scale; - printing::ClearCustomPrintingPageScale(); - } - // Close the device context to retrieve the compiled metafile. if (!metafile->FinishDocument()) NOTREACHED(); @@ -286,9 +255,18 @@ Metafile* PrintWebViewHelper::RenderPage( if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { NOTREACHED() << "Printing page " << page_number << " failed."; } else { - // Update the dpi adjustment with the "page |actual_shrink|" calculated in - // webkit. - *actual_shrink /= (webkit_scale_factor * css_scale_factor); + // While rendering certain plugins (PDF) to metafile, we might need to + // set custom scale factor. Update |actual_shrink| with custom scale + // if it is set on canvas. + // TODO(gene): We should revisit this solution for the next versions. + // Consider creating metafile of the right size (or resizable) + // https://code.google.com/p/chromium/issues/detail?id=126037 + if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( + *canvas, actual_shrink)) { + // Update the dpi adjustment with the "page |actual_shrink|" calculated in + // webkit. + *actual_shrink /= (webkit_scale_factor * css_scale_factor); + } } bool result = metafile->FinishPage(); diff --git a/printing/custom_scaling.cc b/printing/custom_scaling.cc deleted file mode 100644 index dead79c..0000000 --- a/printing/custom_scaling.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "printing/custom_scaling.h" - -#include "base/threading/thread_local.h" - -namespace printing { - -static base::ThreadLocalPointer<double> gPrintingPageScale; - -bool GetCustomPrintingPageScale(double* scale) { - double* ptr = gPrintingPageScale.Get(); - if (ptr != NULL) { - *scale = *ptr; - } - return ptr != NULL; -} - -void SetCustomPrintingPageScale(double scale) { - ClearCustomPrintingPageScale(); - double* ptr = new double; - *ptr = scale; - gPrintingPageScale.Set(ptr); -} - -void ClearCustomPrintingPageScale() { - double* ptr = gPrintingPageScale.Get(); - if (ptr != NULL) { - delete ptr; - } - gPrintingPageScale.Set(NULL); -} - -} // namespace printing - diff --git a/printing/custom_scaling.h b/printing/custom_scaling.h deleted file mode 100644 index 3f46d2e..0000000 --- a/printing/custom_scaling.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PRINTING_CUSTOM_SCALING_H_ -#define PRINTING_CUSTOM_SCALING_H_ - -#include "printing/printing_export.h" - -namespace printing { - -// This set of function allows plugin to set custom printing scale in the -// thread local storage. It is a hack to pass scale through this, but -// alternative is to do major refactoring to pass this scale factor all the -// from plugin through webkit to the upper level. -// We should definitely revisit this approach in favor of better implementation -// later. In the mean time, this looks like a simplest way fixing printing -// issues now. - -// Gets custom printing scale from the TLS. Return false if it has not been -// set. -PRINTING_EXPORT bool GetCustomPrintingPageScale(double* scale); - -// Sets custom printing scale in TLS. -PRINTING_EXPORT void SetCustomPrintingPageScale(double scale); - -// Clears custom printing scale in TLS. -PRINTING_EXPORT void ClearCustomPrintingPageScale(); - -} // namespace printing - -#endif // PRINTING_CUSTOM_SCALING_H_ - diff --git a/printing/metafile_skia_wrapper.cc b/printing/metafile_skia_wrapper.cc index ee24a66..d4634ef 100644 --- a/printing/metafile_skia_wrapper.cc +++ b/printing/metafile_skia_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ namespace printing { namespace { const char* kMetafileKey = "CrMetafile"; +const char* kCustomScaleKey = "CrCustomScale"; } // namespace @@ -38,6 +39,25 @@ Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { return static_cast<MetafileSkiaWrapper*>(value)->metafile_; } +// static +void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas, + double scale) { + SkMetaData& meta = skia::getMetaData(canvas); + meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale)); +} + +// static +bool MetafileSkiaWrapper::GetCustomScaleOnCanvas(const SkCanvas& canvas, + double* scale) { + SkMetaData& meta = skia::getMetaData(canvas); + SkScalar value; + if (!meta.findScalar(kCustomScaleKey, &value)) + return false; + + *scale = SkScalarToFloat(value); + return true; +} + MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) : metafile_(metafile) { } diff --git a/printing/metafile_skia_wrapper.h b/printing/metafile_skia_wrapper.h index 9010449..42bbc5f 100644 --- a/printing/metafile_skia_wrapper.h +++ b/printing/metafile_skia_wrapper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,6 +24,10 @@ class PRINTING_EXPORT MetafileSkiaWrapper : public SkRefCnt { static Metafile* GetMetafileFromCanvas(const SkCanvas& canvas); + // Methods to set and retrieve custom scale factor for metafile from canvas. + static void SetCustomScaleOnCanvas(const SkCanvas& canvas, double scale); + static bool GetCustomScaleOnCanvas(const SkCanvas& canvas, double* scale); + private: explicit MetafileSkiaWrapper(Metafile* metafile); diff --git a/printing/printing.gyp b/printing/printing.gyp index c9c9790..7d02e60 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -32,8 +32,6 @@ 'backend/print_backend_consts.cc', 'backend/print_backend_consts.h', 'backend/print_backend_dummy.cc', - 'custom_scaling.cc', - 'custom_scaling.h', 'emf_win.cc', 'emf_win.h', 'image.cc', diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 140d7af..9ea522c 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -38,7 +38,6 @@ #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_buffer_api.h" -#include "printing/custom_scaling.h" #include "printing/units.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkRect.h" @@ -1485,7 +1484,8 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, if (dynamic_scale < page_scale) { page_scale = dynamic_scale; - printing::SetCustomPrintingPageScale(page_scale); + printing::MetafileSkiaWrapper::SetCustomScaleOnCanvas(*canvas, + page_scale); } gfx::ScaleDC(dc, page_scale); |