Add PDF printing support (issue #1478).

This commit is contained in:
Alexei Bykov
2015-03-24 18:40:08 +03:00
committed by Marshall Greenblatt
parent b6e5310bce
commit 85f83680d7
42 changed files with 1039 additions and 24 deletions

View File

@ -16,6 +16,7 @@
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
#include "libcef_dll/ctocpp/client_ctocpp.h"
#include "libcef_dll/ctocpp/navigation_entry_visitor_ctocpp.h"
#include "libcef_dll/ctocpp/pdf_print_callback_ctocpp.h"
#include "libcef_dll/ctocpp/run_file_dialog_callback_ctocpp.h"
#include "libcef_dll/transfer_util.h"
@ -307,6 +308,36 @@ void CEF_CALLBACK browser_host_print(struct _cef_browser_host_t* self) {
CefBrowserHostCppToC::Get(self)->Print();
}
void CEF_CALLBACK browser_host_print_to_pdf(struct _cef_browser_host_t* self,
const cef_string_t* path, const struct _cef_pdf_print_settings_t* settings,
cef_pdf_print_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return;
// Verify param: settings; type: struct_byref_const
DCHECK(settings);
if (!settings)
return;
// Unverified params: callback
// Translate param: settings; type: struct_byref_const
CefPdfPrintSettings settingsObj;
if (settings)
settingsObj.Set(*settings, false);
// Execute
CefBrowserHostCppToC::Get(self)->PrintToPDF(
CefString(path),
settingsObj,
CefPdfPrintCallbackCToCpp::Wrap(callback));
}
void CEF_CALLBACK browser_host_find(struct _cef_browser_host_t* self,
int identifier, const cef_string_t* searchText, int forward, int matchCase,
int findNext) {
@ -881,6 +912,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
GetStruct()->run_file_dialog = browser_host_run_file_dialog;
GetStruct()->start_download = browser_host_start_download;
GetStruct()->print = browser_host_print;
GetStruct()->print_to_pdf = browser_host_print_to_pdf;
GetStruct()->find = browser_host_find;
GetStruct()->stop_finding = browser_host_stop_finding;
GetStruct()->show_dev_tools = browser_host_show_dev_tools;

View File

@ -0,0 +1,61 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/pdf_print_callback_cpptoc.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK pdf_print_callback_on_pdf_print_finished(
struct _cef_pdf_print_callback_t* self, const cef_string_t* path, int ok) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return;
// Execute
CefPdfPrintCallbackCppToC::Get(self)->OnPdfPrintFinished(
CefString(path),
ok?true:false);
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefPdfPrintCallbackCppToC::CefPdfPrintCallbackCppToC() {
GetStruct()->on_pdf_print_finished = pdf_print_callback_on_pdf_print_finished;
}
template<> CefRefPtr<CefPdfPrintCallback> CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::UnwrapDerived(
CefWrapperType type, cef_pdf_print_callback_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
#ifndef NDEBUG
template<> base::AtomicRefCount CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::DebugObjCt = 0;
#endif
template<> CefWrapperType CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::kWrapperType =
WT_PDF_PRINT_CALLBACK;

View File

@ -0,0 +1,37 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_
#pragma once
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "include/cef_client.h"
#include "include/capi/cef_client_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefPdfPrintCallbackCppToC
: public CefCppToC<CefPdfPrintCallbackCppToC, CefPdfPrintCallback,
cef_pdf_print_callback_t> {
public:
CefPdfPrintCallbackCppToC();
};
#endif // USING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_

View File

@ -104,6 +104,22 @@ void CEF_CALLBACK print_handler_on_print_reset(
CefPrintHandlerCppToC::Get(self)->OnPrintReset();
}
cef_size_t CEF_CALLBACK print_handler_get_pdf_paper_size(
struct _cef_print_handler_t* self, int device_units_per_inch) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return CefSize();
// Execute
cef_size_t _retval = CefPrintHandlerCppToC::Get(self)->GetPdfPaperSize(
device_units_per_inch);
// Return type: simple
return _retval;
}
} // namespace
@ -114,6 +130,7 @@ CefPrintHandlerCppToC::CefPrintHandlerCppToC() {
GetStruct()->on_print_dialog = print_handler_on_print_dialog;
GetStruct()->on_print_job = print_handler_on_print_job;
GetStruct()->on_print_reset = print_handler_on_print_reset;
GetStruct()->get_pdf_paper_size = print_handler_get_pdf_paper_size;
}
template<> CefRefPtr<CefPrintHandler> CefCppToC<CefPrintHandlerCppToC,