Commit cc3b39d4 authored by Adrian Johnson's avatar Adrian Johnson

make pdftocairo-win32.cc a standalone .cc file

instead of #including it in pdftocairo.cc
parent 700205af
......@@ -21,6 +21,7 @@ if (HAVE_CAIRO)
# pdftocairo
set(pdftocairo_SOURCES ${common_srcs}
pdftocairo.cc
pdftocairo-win32.cc
${CMAKE_SOURCE_DIR}/poppler/CairoFontEngine.cc
${CMAKE_SOURCE_DIR}/poppler/CairoOutputDev.cc
${CMAKE_SOURCE_DIR}/poppler/CairoRescaleBox.cc
......
......@@ -107,7 +107,8 @@ pdftoppm_SOURCES = \
pdftoppm.cc
pdftocairo_SOURCES = \
pdftocairo.cc
pdftocairo.cc \
pdftocairo-win32.cc
if BUILD_CAIRO_OUTPUT
if USE_CMS
......
#include <cairo.h>
#ifdef CAIRO_HAS_WIN32_SURFACE
#include <cairo-win32.h>
static void win32GetFitToPageTransform(cairo_matrix_t *m)
{
if (!print)
return;
#include "parseargs.h"
#include "pdftocairo-win32.h"
static HDC hdc;
HDC hdc = cairo_win32_surface_get_dc(surface);
void win32GetFitToPageTransform(cairo_matrix_t *m)
{
int logx = GetDeviceCaps(hdc, LOGPIXELSX);
int logy = GetDeviceCaps(hdc, LOGPIXELSY);
cairo_matrix_scale (m, logx / 72.0, logy / 72.0);
......@@ -68,9 +72,6 @@ static const Win32Option win32DuplexMode[] =
static void parseDuplex(DEVMODEA *devmode, GooString *mode)
{
if (duplex)
fprintf(stderr, "Warning: duplex mode is specified both as standalone and printer options\n");
int win32Duplex;
const Win32Option *option = win32DuplexMode;
while (option->name) {
......@@ -88,7 +89,7 @@ static void parseDuplex(DEVMODEA *devmode, GooString *mode)
devmode->dmFields |= DM_DUPLEX;
}
static void fillCommonPrinterOptions(DEVMODEA *devmode, double w, double h)
static void fillCommonPrinterOptions(DEVMODEA *devmode, double w, double h, GBool duplex)
{
devmode->dmPaperWidth = w * 254.0 / 72.0;
devmode->dmPaperLength = h * 254.0 / 72.0;
......@@ -100,10 +101,10 @@ static void fillCommonPrinterOptions(DEVMODEA *devmode, double w, double h)
}
}
static void fillPrinterOptions(DEVMODEA *devmode)
static void fillPrinterOptions(DEVMODEA *devmode, GBool duplex, GooString *printOpt)
{
//printOpt format is: <opt1>=<val1>,<opt2>=<val2>,...
const char *nextOpt = printOpt.getCString();
const char *nextOpt = printOpt->getCString();
while (nextOpt && *nextOpt)
{
const char *comma = strchr(nextOpt, ',');
......@@ -129,28 +130,33 @@ static void fillPrinterOptions(DEVMODEA *devmode)
if (opt.cmp("source") == 0) {
parseSource(devmode, &value);
} else if (opt.cmp("duplex") == 0) {
parseDuplex(devmode, &value);
if (duplex) {
fprintf(stderr, "Warning: duplex mode is specified both as standalone and printer options\n");
} else {
parseDuplex(devmode, &value);
}
} else {
fprintf(stderr, "Warning: unknown printer option \"%s\"\n", opt.getCString());
}
}
}
static void win32BeginDocument(GooString *inputFileName, GooString *outputFileName, double w, double h)
cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputFileName,
double w, double h,
GooString *printer,
GooString *printOpt,
GBool duplex)
{
if (!print)
return;
if (printer.getCString()[0] == 0)
if (printer->getCString()[0] == 0)
{
DWORD szName = 0;
GetDefaultPrinterA(NULL, &szName);
char *devname = (char*)gmalloc(szName);
GetDefaultPrinterA(devname, &szName);
printer.Set(devname);
printer->Set(devname);
gfree(devname);
}
char *cPrinter = printer.getCString();
char *cPrinter = printer->getCString();
//Query the size of the DEVMODE struct
LONG szProp = DocumentPropertiesA(NULL, NULL, cPrinter, NULL, NULL, 0);
......@@ -169,9 +175,9 @@ static void win32BeginDocument(GooString *inputFileName, GooString *outputFileNa
fprintf(stderr, "Error: Printer \"%s\" not found", cPrinter);
exit(99);
}
fillCommonPrinterOptions(devmode, w, h);
fillPrinterOptions(devmode);
HDC hdc = CreateDCA(NULL, cPrinter, NULL, devmode);
fillCommonPrinterOptions(devmode, w, h, duplex);
fillPrinterOptions(devmode, duplex, printOpt);
hdc = CreateDCA(NULL, cPrinter, NULL, devmode);
gfree(devmode);
if (!hdc)
{
......@@ -194,30 +200,24 @@ static void win32BeginDocument(GooString *inputFileName, GooString *outputFileNa
fprintf(stderr, "Error: StartDoc failed");
exit(99);
}
surface = cairo_win32_printing_surface_create(hdc);
return cairo_win32_printing_surface_create(hdc);
}
static void win32BeginPage(double w, double h)
void win32BeginPage(double w, double h)
{
if (!print)
return;
StartPage(cairo_win32_surface_get_dc(surface));
StartPage(hdc);
}
static void win32EndPage(GooString *imageFileName)
void win32EndPage(GooString *imageFileName)
{
if (!print)
return;
EndPage(cairo_win32_surface_get_dc(surface));
EndPage(hdc);
}
static void win32EndDocument()
void win32EndDocument()
{
if (!print)
return;
HDC hdc = cairo_win32_surface_get_dc(surface);
EndDoc(hdc);
DeleteDC(hdc);
}
#endif // CAIRO_HAS_WIN32_SURFACE
#include <cairo.h>
#include "goo/gmem.h"
#include "goo/gtypes.h"
#include "goo/gtypes_p.h"
#include "goo/GooString.h"
#ifdef CAIRO_HAS_WIN32_SURFACE
#include <cairo-win32.h>
void win32GetFitToPageTransform(cairo_matrix_t *m);
cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputFileName,
double w, double h,
GooString *printer,
GooString *printOpt,
GBool duplex);
void win32BeginPage(double w, double h);
void win32EndPage(GooString *imageFileName);
void win32EndDocument();
#endif // CAIRO_HAS_WIN32_SURFACE
......@@ -71,6 +71,8 @@
#include <cairo-svg.h>
#endif
#include "pdftocairo-win32.h"
static GBool png = gFalse;
static GBool jpeg = gFalse;
......@@ -267,10 +269,6 @@ static int icc_data_size;
static cmsHPROFILE profile;
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
#include "pdftocairo-win32.cc"
#endif
void writePageImage(GooString *filename)
{
ImgWriter *writer = 0;
......@@ -486,7 +484,8 @@ static void getFitToPageTransform(double page_w, double page_h,
cairo_matrix_scale (m, scale, scale);
}
#ifdef CAIRO_HAS_WIN32_SURFACE
win32GetFitToPageTransform(m);
if (print)
win32GetFitToPageTransform(m);
#endif
}
......@@ -541,7 +540,8 @@ static void beginDocument(GooString *inputFileName, GooString *outputFileName, d
#endif
}
#ifdef CAIRO_HAS_WIN32_SURFACE
win32BeginDocument(inputFileName, outputFileName, w, h);
if (print)
surface = win32BeginDocument(inputFileName, outputFileName, w, h, &printer, &printOpt, duplex);
#endif
}
}
......@@ -565,8 +565,10 @@ static void beginPage(double w, double h)
if (pdf)
cairo_pdf_surface_set_size (surface, w, h);
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
win32BeginPage(w, h);
if (print)
win32BeginPage(w, h);
#endif
cairo_surface_set_fallback_resolution (surface, x_resolution, y_resolution);
......@@ -638,9 +640,12 @@ static void endPage(GooString *imageFileName)
if (printing) {
cairo_surface_show_page(surface);
#ifdef CAIRO_HAS_WIN32_SURFACE
win32EndPage(imageFileName);
if (print)
win32EndPage(imageFileName);
#endif
} else {
writePageImage(imageFileName);
cairo_surface_finish(surface);
......@@ -658,7 +663,8 @@ static void endDocument()
if (printing) {
#ifdef CAIRO_HAS_WIN32_SURFACE
win32EndDocument();
if (print)
win32EndDocument();
#endif
cairo_surface_finish(surface);
status = cairo_surface_status(surface);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment