tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a750f5b314cc07783358a8f8557db58abb06d186
parent d5cc33ca42b4ea666d4ea66079a85f9ecb61b23e
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Mon, 24 Nov 2025 11:51:03 +0000

Bug 2001909 - Remove some dead and broken code for windows + SkPdf. r=jfkthame

The code this was trying to use was never enabled at build time.
PrintTargetEMF got removed in bug 1503537 too, so remove WindowsEMF
while at it since it's also dead code.

For PDF output the previous patches allow using SkPdf. For the DEVMODEW
case we'd need to do something different, but keeping that code around
is not super useful.

Differential Revision: https://phabricator.services.mozilla.com/D273752

Diffstat:
Mgfx/thebes/PrintTargetWindows.cpp | 2++
Mwidget/nsIDeviceContextSpec.h | 2+-
Dwidget/windows/WindowsEMF.cpp | 94-------------------------------------------------------------------------------
Dwidget/windows/WindowsEMF.h | 106-------------------------------------------------------------------------------
Mwidget/windows/moz.build | 6------
Mwidget/windows/nsDeviceContextSpecWin.cpp | 67-------------------------------------------------------------------
6 files changed, 3 insertions(+), 274 deletions(-)

diff --git a/gfx/thebes/PrintTargetWindows.cpp b/gfx/thebes/PrintTargetWindows.cpp @@ -46,6 +46,8 @@ already_AddRefed<PrintTargetWindows> PrintTargetWindows::CreateOrNull(HDC aDC) { return nullptr; } + // TODO(emilio): Use SkPDF rather than cairo if possible? See bug 1503537 and + // bug 2001909 for some EMF code which was supposed to deal with some of this. cairo_surface_t* surface = cairo_win32_printing_surface_create(aDC); if (cairo_surface_status(surface)) { diff --git a/widget/nsIDeviceContextSpec.h b/widget/nsIDeviceContextSpec.h @@ -96,7 +96,7 @@ class nsIDeviceContextSpec : public nsISupports { nsCOMPtr<nsIPrintSettings> mPrintSettings; #ifdef MOZ_ENABLE_SKIA_PDF - // This variable is independant of nsIPrintSettings::kOutputFormatPDF (i.e. + // This variable is independent of nsIPrintSettings::kOutputFormatPDF (i.e. // save-to-PDF). If set to true, then even when we print to a printer we // output and send it PDF. bool mPrintViaSkPDF = false; diff --git a/widget/windows/WindowsEMF.cpp b/widget/windows/WindowsEMF.cpp @@ -1,94 +0,0 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "WindowsEMF.h" - -namespace mozilla { -namespace widget { - -WindowsEMF::WindowsEMF() : mEmf(nullptr), mDC(nullptr) {} - -WindowsEMF::~WindowsEMF() { ReleaseAllResource(); } - -bool WindowsEMF::InitForDrawing(const wchar_t* aMetafilePath /* = nullptr */) { - ReleaseAllResource(); - - mDC = ::CreateEnhMetaFile(nullptr, aMetafilePath, nullptr, nullptr); - return !!mDC; -} - -bool WindowsEMF::InitFromFileContents(const wchar_t* aMetafilePath) { - MOZ_ASSERT(aMetafilePath); - ReleaseAllResource(); - - mEmf = ::GetEnhMetaFileW(aMetafilePath); - return !!mEmf; -} - -bool WindowsEMF::InitFromFileContents(LPBYTE aBytes, UINT aSize) { - MOZ_ASSERT(aBytes && aSize != 0); - ReleaseAllResource(); - - mEmf = SetEnhMetaFileBits(aSize, aBytes); - - return !!mEmf; -} - -bool WindowsEMF::FinishDocument() { - if (mDC) { - mEmf = ::CloseEnhMetaFile(mDC); - mDC = nullptr; - } - return !!mEmf; -} - -void WindowsEMF::ReleaseEMFHandle() { - if (mEmf) { - ::DeleteEnhMetaFile(mEmf); - mEmf = nullptr; - } -} - -void WindowsEMF::ReleaseAllResource() { - FinishDocument(); - ReleaseEMFHandle(); -} - -bool WindowsEMF::Playback(HDC aDeviceContext, const RECT& aRect) { - DebugOnly<bool> result = FinishDocument(); - MOZ_ASSERT(result, "This function should be used after InitXXX."); - - return ::PlayEnhMetaFile(aDeviceContext, mEmf, &aRect) != 0; -} - -bool WindowsEMF::SaveToFile() { - DebugOnly<bool> result = FinishDocument(); - MOZ_ASSERT(result, "This function should be used after InitXXX."); - - ReleaseEMFHandle(); - return true; -} - -UINT WindowsEMF::GetEMFContentSize() { - DebugOnly<bool> result = FinishDocument(); - MOZ_ASSERT(result, "This function should be used after InitXXX."); - - return GetEnhMetaFileBits(mEmf, 0, NULL); -} - -bool WindowsEMF::GetEMFContentBits(LPBYTE aBytes) { - DebugOnly<bool> result = FinishDocument(); - MOZ_ASSERT(result, "This function should be used after InitXXX."); - - UINT emfSize = GetEMFContentSize(); - if (GetEnhMetaFileBits(mEmf, emfSize, aBytes) != emfSize) { - return false; - } - - return true; -} - -} // namespace widget -} // namespace mozilla diff --git a/widget/windows/WindowsEMF.h b/widget/windows/WindowsEMF.h @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_WIDGET_WINDOWSEMF_H -#define MOZILLA_WIDGET_WINDOWSEMF_H - -/* include windows.h for the HDC definitions that we need. */ -#include <windows.h> - -namespace mozilla { -namespace widget { - -/** - * Windows Enhance Metafile: https://en.wikipedia.org/wiki/Windows_Metafile - * A metafile, also called a vector image, is an image that is stored as a - * sequence of drawing commands and settings. The commands and settings - * recorded in a Metafile object can be stored in memory or saved to a file. - * - * The metafile device context is used for all drawing operations required to - * create the picture. When the system processes a GDI function associated with - * a metafile DC, it converts the function into the appropriate data and stores - * this data in a record appended to the metafile. - */ -class WindowsEMF { - public: - WindowsEMF(); - ~WindowsEMF(); - - /** - * Initializes the object with the path of a file where the EMF data stream - * should be stored. Callers are then expected to call GetDC() to draw output - * before going on to call Playback() or SaveToFile() to generate the EMF - * output. - */ - bool InitForDrawing(const wchar_t* aMetafilePath = nullptr); - - /** - * Initializes the object with an existing EMF file. Consumers cannot use - * GetDC() to obtain an HDC to modify the file. They can only use Playback(). - */ - bool InitFromFileContents(const wchar_t* aMetafilePath); - - /** - * Creates the EMF from the specified data - * - * @param aByte Pointer to a buffer that contains EMF data. - * @param aSize Specifies the size, in bytes, of aByte. - */ - bool InitFromFileContents(PBYTE aBytes, UINT aSize); - - /** - * If this object was initiaziled using InitForDrawing() then this function - * returns an HDC that can be drawn to generate the EMF output. Otherwise it - * returns null. After finishing with the HDC, consumers could call Playback() - * to draw EMF onto the given DC or call SaveToFile() to finish writing the - * EMF file. - */ - HDC GetDC() const { - MOZ_ASSERT(mDC, - "GetDC can be used only after " - "InitForDrawing/ InitFromFileContents and before" - "Playback/ SaveToFile"); - return mDC; - } - - /** - * Play the EMF's drawing commands onto the given DC. - */ - bool Playback(HDC aDeviceContext, const RECT& aRect); - - /** - * Called to generate the EMF file once a consumer has finished drawing to - * the HDC returned by GetDC(), if initializes the object with the path of a - * file. - */ - bool SaveToFile(); - - /** - * Return the size of the enhanced metafile, in bytes. - */ - UINT GetEMFContentSize(); - - /** - * Retrieves the contents of the EMF and copies them into a buffer. - * - * @param aByte the buffer to receive the data. - */ - bool GetEMFContentBits(PBYTE aBytes); - - private: - WindowsEMF(const WindowsEMF& aEMF) = delete; - bool FinishDocument(); - void ReleaseEMFHandle(); - void ReleaseAllResource(); - - /* Compiled EMF data handle. */ - HENHMETAFILE mEmf; - HDC mDC; -}; - -} // namespace widget -} // namespace mozilla - -#endif /* MOZILLA_WIDGET_WINDOWSEMF_H */ diff --git a/widget/windows/moz.build b/widget/windows/moz.build @@ -58,7 +58,6 @@ EXPORTS.mozilla.widget += [ "nsWindowLoggedMessages.h", "WinCompositorWidget.h", "WinCompositorWindowThread.h", - "WindowsEMF.h", "WindowsSMTCProvider.h", "WinEventObserver.h", "WinMessages.h", @@ -166,11 +165,6 @@ if CONFIG["NS_PRINTING"]: "nsPrintDialogUtil.cpp", ] -if CONFIG["MOZ_ENABLE_SKIA_PDF"]: - UNIFIED_SOURCES += [ - "WindowsEMF.cpp", - ] - XPIDL_SOURCES += [ "nsIAlertsServiceRust.idl", "nsIWindowsTestDebug.idl", diff --git a/widget/windows/nsDeviceContextSpecWin.cpp b/widget/windows/nsDeviceContextSpecWin.cpp @@ -32,27 +32,15 @@ #include "nsIFileStreams.h" #include "nsWindowsHelpers.h" - #include "mozilla/gfx/Logging.h" -#ifdef MOZ_ENABLE_SKIA_PDF -# include "mozilla/gfx/PrintTargetSkPDF.h" -# include "mozilla/gfx/PrintTargetEMF.h" -# include "nsIUUIDGenerator.h" -# include "nsDirectoryServiceDefs.h" -# include "nsPrintfCString.h" -# include "nsThreadUtils.h" -#endif - extern mozilla::LazyLogModule gPrintingLog; #define PR_PL(_p1) MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1) using namespace mozilla; using namespace mozilla::gfx; -#ifdef MOZ_ENABLE_SKIA_PDF using namespace mozilla::widget; -#endif static const wchar_t kDriverName[] = L"WINSPOOL"; @@ -174,14 +162,6 @@ NS_IMETHODIMP nsDeviceContextSpecWin::Init(nsIPrintSettings* aPrintSettings, nsresult rv = NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; if (aPrintSettings) { -#ifdef MOZ_ENABLE_SKIA_PDF - nsAutoString printViaPdf; - Preferences::GetString("print.print_via_pdf_encoder", printViaPdf); - if (printViaPdf.EqualsLiteral("skia-pdf")) { - mPrintViaSkPDF = true; - } -#endif - // If we're in the child or we're printing to PDF we only need information // from the print settings. if (XRE_IsContentProcess() || @@ -238,47 +218,6 @@ NS_IMETHODIMP nsDeviceContextSpecWin::Init(nsIPrintSettings* aPrintSettings, already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget() { NS_ASSERTION(mDevMode || mOutputFormat == nsIPrintSettings::kOutputFormatPDF, "DevMode can't be NULL here unless we're printing to PDF."); - -#ifdef MOZ_ENABLE_SKIA_PDF - if (mPrintViaSkPDF) { - double width, height; - mPrintSettings->GetEffectivePageSize(&width, &height); - if (width <= 0 || height <= 0) { - return nullptr; - } - - // convert twips to points - width /= TWIPS_PER_POINT_FLOAT; - height /= TWIPS_PER_POINT_FLOAT; - IntSize size = IntSize::Ceil(width, height); - - if (mOutputFormat == nsIPrintSettings::kOutputFormatPDF) { - nsString filename; - // TODO(dshin): - // - Does this handle bug 1659470? - // - Should this code path be enabled, we should use temporary files and - // then move the file in `EndDocument()`. - mPrintSettings->GetToFileName(filename); - - nsAutoCString printFile(NS_ConvertUTF16toUTF8(filename).get()); - auto skStream = MakeUnique<SkFILEWStream>(printFile.get()); - return PrintTargetSkPDF::CreateOrNull(std::move(skStream), size); - } - - if (mDevMode) { - NS_WARNING_ASSERTION(!mDriverName.IsEmpty(), "No driver!"); - HDC dc = - ::CreateDCW(mDriverName.get(), mDeviceName.get(), nullptr, mDevMode); - if (!dc) { - gfxCriticalError(gfxCriticalError::DefaultOptions(false)) - << "Failed to create device context in GetSurfaceForPrinter"; - return nullptr; - } - return PrintTargetEMF::CreateOrNull(dc, size); - } - } -#endif - if (mOutputFormat == nsIPrintSettings::kOutputFormatPDF) { double width, height; mPrintSettings->GetEffectiveSheetSize(&width, &height); @@ -343,12 +282,6 @@ RefPtr<PrintEndDocumentPromise> nsDeviceContextSpecWin::EndDocument() { return PrintEndDocumentPromise::CreateAndResolve(true, __func__); } -#ifdef MOZ_ENABLE_SKIA_PDF - if (mPrintViaSkPDF) { - return PrintEndDocumentPromise::CreateAndResolve(true, __func__); - } -#endif - MOZ_ASSERT(mTempFile, "No handle to temporary PDF file."); nsAutoString targetPath;