From 9114e831cc8ae619ce541719887c5d7c2fc4e6d1 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Mon, 14 Jul 2014 13:22:47 -0700 Subject: Add support to extract viewer preference This change adds the support to extract "NumCopies", "PrintPageRange", "Duplex" viewer preferences for printing. BUG=169120 R=bo_xu@foxitsoftware.com, vitalybuka@chromium.org Review URL: https://codereview.chromium.org/345123002 --- fpdfsdk/include/fpdfview.h | 36 ++++++++++++++++++++++++++++++++++++ fpdfsdk/src/fpdfview.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/include/fpdfview.h b/fpdfsdk/include/fpdfview.h index f4f13750bc..1b7ae2e251 100644 --- a/fpdfsdk/include/fpdfview.h +++ b/fpdfsdk/include/fpdfview.h @@ -34,6 +34,7 @@ typedef void* FPDF_BOOKMARK; typedef void* FPDF_DEST; typedef void* FPDF_ACTION; typedef void* FPDF_LINK; +typedef void* FPDF_PAGERANGE; // Basic data types typedef int FPDF_BOOL; @@ -42,6 +43,14 @@ typedef unsigned long FPDF_DWORD; typedef float FS_FLOAT; +// Duplex types +typedef enum _FPDF_DUPLEXTYPE_ { + DuplexUndefined = 0, + Simplex, + DuplexFlipShortEdge, + DuplexFlipLongEdge +} FPDF_DUPLEXTYPE; + // String types typedef unsigned short FPDF_WCHAR; typedef unsigned char const* FPDF_LPCBYTE; @@ -556,6 +565,33 @@ DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap); // DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document); +// Function: FPDF_VIEWERREF_GetNumCopies +// Returns the number of copies to be printed. +// Parameters: +// document - Handle to the loaded document. +// Return value: +// The number of copies to be printed. +// +DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document); + +// Function: FPDF_VIEWERREF_GetPrintPageRange +// Page numbers to initialize print dialog box when file is printed. +// Parameters: +// document - Handle to the loaded document. +// Return value: +// The print page range to be used for printing. +// +DLLEXPORT FPDF_PAGERANGE STDCALL FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document); + +// Function: FPDF_VIEWERREF_GetDuplex +// Returns the paper handling option to be used when printing from print dialog. +// Parameters: +// document - Handle to the loaded document. +// Return value: +// The paper handling option to be used when printing. +// +DLLEXPORT FPDF_DUPLEXTYPE STDCALL FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document); + // Function: FPDF_GetNamedDestByName // get a special dest handle by the index. // Parameters: diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index a9aa9a8ff2..8a97c286aa 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -859,6 +859,37 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT documen return viewRef.PrintScaling(); } +DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) +{ + CPDF_Document* pDoc = (CPDF_Document*)document; + if (!pDoc) return 1; + CPDF_ViewerPreferences viewRef(pDoc); + return viewRef.NumCopies(); +} + +DLLEXPORT FPDF_PAGERANGE STDCALL FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) +{ + CPDF_Document* pDoc = (CPDF_Document*)document; + if (!pDoc) return NULL; + CPDF_ViewerPreferences viewRef(pDoc); + return viewRef.PrintPageRange(); +} + +DLLEXPORT FPDF_DUPLEXTYPE STDCALL FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) +{ + CPDF_Document* pDoc = (CPDF_Document*)document; + if (!pDoc) return DuplexUndefined; + CPDF_ViewerPreferences viewRef(pDoc); + CFX_ByteString duplex = viewRef.Duplex(); + if (FX_BSTRC("Simplex") == duplex) + return Simplex; + if (FX_BSTRC("DuplexFlipShortEdge") == duplex) + return DuplexFlipShortEdge; + if (FX_BSTRC("DuplexFlipLongEdge") == duplex) + return DuplexFlipLongEdge; + return DuplexUndefined; +} + DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_BYTESTRING name) { if (document == NULL) -- cgit v1.2.3