David PHAM-VAN

Fix Windows print margins

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 ## 5.6.2 3 ## 5.6.2
4 4
5 - Fix Windows string encoding 5 - Fix Windows string encoding
  6 +- Fix Windows print margins
6 7
7 ## 5.6.2 8 ## 5.6.2
8 9
@@ -287,7 +287,8 @@ void print_job::raster_pdf(const uint8_t data[], @@ -287,7 +287,8 @@ void print_job::raster_pdf(const uint8_t data[],
287 auto bitmap = FPDFBitmap_Create(bWidth, bHeight, 0); 287 auto bitmap = FPDFBitmap_Create(bWidth, bHeight, 0);
288 FPDFBitmap_FillRect(bitmap, 0, 0, bWidth, bHeight, 0xffffffff); 288 FPDFBitmap_FillRect(bitmap, 0, 0, bWidth, bHeight, 0xffffffff);
289 289
290 - FPDF_RenderPageBitmap(bitmap, page, 0, 0, bWidth, bHeight, 0, FPDF_ANNOT); 290 + FPDF_RenderPageBitmap(bitmap, page, 0, 0, bWidth, bHeight, 0,
  291 + FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);
291 292
292 uint8_t* p = static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)); 293 uint8_t* p = static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap));
293 auto stride = FPDFBitmap_GetStride(bitmap); 294 auto stride = FPDFBitmap_GetStride(bitmap);
@@ -218,6 +218,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { @@ -218,6 +218,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) {
218 } 218 }
219 219
220 auto pages = FPDF_GetPageCount(doc); 220 auto pages = FPDF_GetPageCount(doc);
  221 + auto marginLeft = GetDeviceCaps(hDC, PHYSICALOFFSETX);
  222 + auto marginTop = GetDeviceCaps(hDC, PHYSICALOFFSETY);
221 223
222 for (auto pageNum = 0; pageNum < pages; pageNum++) { 224 for (auto pageNum = 0; pageNum < pages; pageNum++) {
223 r = StartPage(hDC); 225 r = StartPage(hDC);
@@ -234,7 +236,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { @@ -234,7 +236,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) {
234 int bWidth = static_cast<int>(pdfWidth * dpiX); 236 int bWidth = static_cast<int>(pdfWidth * dpiX);
235 int bHeight = static_cast<int>(pdfHeight * dpiY); 237 int bHeight = static_cast<int>(pdfHeight * dpiY);
236 238
237 - FPDF_RenderPage(hDC, page, 0, 0, bWidth, bHeight, 0, FPDF_ANNOT); 239 + FPDF_RenderPage(hDC, page, -marginLeft, -marginTop, bWidth, bHeight, 0,
  240 + FPDF_ANNOT | FPDF_PRINTING);
238 FPDF_ClosePage(page); 241 FPDF_ClosePage(page);
239 r = EndPage(hDC); 242 r = EndPage(hDC);
240 } 243 }