Bug 1399787 - Part 7. Implement PDFiumChild. draft
authorcku <cku@mozilla.com>
Fri, 20 Oct 2017 16:58:41 +0800
changeset 686699 488afc93b788a8f4984c2e5a81d7d0e4970cbbcb
parent 686698 e54dde525f8d3c4c38028504ee8669a6f1a14851
child 686700 b51ee5e2c406b49011d0723a05c0a0f606b02cfa
push id86258
push usercku@mozilla.com
push dateThu, 26 Oct 2017 08:49:17 +0000
bugs1399787
milestone58.0a1
Bug 1399787 - Part 7. Implement PDFiumChild. MozReview-Commit-ID: 4k4CX7rcR1H
widget/windows/PDFiumChild.cpp
--- a/widget/windows/PDFiumChild.cpp
+++ b/widget/windows/PDFiumChild.cpp
@@ -32,13 +32,36 @@ PDFiumChild::Init(base::ProcessId aParen
 
 mozilla::ipc::IPCResult
 PDFiumChild::RecvConvertToEMF(const nsString& aPDFFilePath,
                               const int& aPageWidth,
                               const int& aPageHeight)
 {
   MOZ_ASSERT(aPDFFilePath.Length() && aPageWidth != 0 && aPageHeight != 0);
 
+  PDFViaEMFPrintHelper helper;
+  if (NS_FAILED(helper.OpenDocument(NS_ConvertUTF16toUTF8(aPDFFilePath).get()))) {
+    MOZ_ASSERT_UNREACHABLE("Why the parent process passed an invalid PDF?");
+    SendFinishedEMFConversions();
+    return IPC_OK();
+  }
+
+  const int pageCount = helper.GetPageCount();
+  if (pageCount <= 0) {
+    SendFinishedEMFConversions();
+    return IPC_OK();
+  }
+
+  nsAutoString destFolder;
+  aPDFFilePath.Left(destFolder, aPDFFilePath.RFind("\\"));
+  for (int i = 0; i < pageCount; i++) {
+    nsAutoString emfFile = destFolder;
+    emfFile.AppendPrintf("\\pdfium_%d.emf", i);
+    helper.DrawPageToFile(emfFile.get(), i, aPageWidth, aPageHeight);
+    SendDoneConvertingToEMF(emfFile);
+  }
+
+  SendFinishedEMFConversions();
   return IPC_OK();
 }
 
 } // namespace widget
 } // namespace mozilla