Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3763)

Unified Diff: chrome/utility/chrome_content_utility_client.cc

Issue 255543006: Printing on Windows via PDF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tidy Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/utility/chrome_content_utility_client.cc
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 1ca9c94f4627ae2a1d24b09ca4ea12bcb5ef532c..ecd9ac50506ceae9f492ad95a6290c5f6f138fcc 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -170,7 +170,7 @@ class PdfFunctionsBase {
const base::FilePath& pdf_module_path,
const base::ScopedNativeLibrary& pdf_lib) {
return true;
- };
+ }
private:
// Exported by PDF plugin.
@@ -365,6 +365,8 @@ bool ChromeContentUtilityClient::OnMessageReceived(
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile,
OnRenderPDFPagesToMetafile)
+ IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFToMetafile,
+ OnRenderPDFToMetafile)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster,
OnRenderPDFPagesToPWGRaster)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
@@ -590,6 +592,69 @@ void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile(
ReleaseProcessIfNeeded();
}
+#if defined(OS_WIN)
+void ChromeContentUtilityClient::OnRenderPDFToMetafile(
+ base::PlatformFile pdf_transit,
+ const base::FilePath& metafile_path,
+ const printing::PdfRenderSettings& settings) {
+ base::PlatformFile pdf_file =
+ IPC::PlatformFileForTransitToPlatformFile(pdf_transit);
+ bool succeeded = false;
+ int highest_rendered_page_number = -1;
+ double scale_factor = 1.0;
+
+ if (!g_pdf_lib.Get().IsValid())
+ return;
+
+ DWORD length = ::GetFileSize(pdf_file, NULL);
+ if (length == INVALID_FILE_SIZE)
+ return;
+
+ std::vector<uint8> buffer;
+ buffer.resize(length);
+ DWORD bytes_read = 0;
+ if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) ||
+ (bytes_read != length)) {
+ return;
+ }
+
+ int total_page_count = 0;
+ if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(),
+ &total_page_count, NULL)) {
+ return;
+ }
+
+ for (int i = 0; i < total_page_count; ++i) {
+ printing::Emf metafile;
+ metafile.InitToFile(
+ metafile_path.InsertBeforeExtensionASCII(base::StringPrintf(".%d", i)));
+ scale_factor = gfx::CalculatePageScale(
+ metafile.context(), settings.area().right(), settings.area().bottom());
+ gfx::ScaleDC(metafile.context(), scale_factor);
+ metafile.StartPage(gfx::Size(), gfx::Rect(), 1);
+ if (g_pdf_lib.Get().RenderPDFPageToDC(
+ &buffer.front(), buffer.size(), i, metafile.context(),
+ settings.dpi(), settings.dpi(), settings.area().x(),
+ settings.area().y(), settings.area().width(),
+ settings.area().height(), true, false, true, true,
+ settings.autorotate())) {
+ if (highest_rendered_page_number < i)
+ highest_rendered_page_number = i;
+ }
+ metafile.FinishPage();
+ metafile.FinishDocument();
+ }
+
+ if (highest_rendered_page_number >= 0) {
+ Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded(
+ highest_rendered_page_number, scale_factor));
Vitaly Buka (NO REVIEWS) 2014/05/14 03:51:18 Actually with this approach we could send success
+ } else {
+ Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed());
+ }
+ ReleaseProcessIfNeeded();
+}
+#endif // defined(OS_WIN)
+
void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster(
IPC::PlatformFileForTransit pdf_transit,
const printing::PdfRenderSettings& settings,

Powered by Google App Engine
This is Rietveld 408576698