Add RenderDeviceDriverIface::GetDeviceType(). Split this off from RenderDeviceDriverIface::GetDeviceCaps(). - Add enum class DeviceType. - Remove FXDC_DEVICE_CLASS, FXDC_DISPLAY, and FXDC_PRINTER. Change-Id: I0c18b0c243896c6fe8c3fc2ff16c2f2306dfe04c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56592 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp index a0dcfdb..865f72a 100644 --- a/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -115,8 +115,10 @@ else if (GetRenderOptions().GetOptions().bForceHalftone) m_ResampleOptions.bHalftone = true; - if (m_pRenderStatus->GetRenderDevice()->GetDeviceClass() != FXDC_DISPLAY) + if (m_pRenderStatus->GetRenderDevice()->GetDeviceType() != + DeviceType::kDisplay) { HandleFilters(); + } if (GetRenderOptions().GetOptions().bNoImageSmooth) m_ResampleOptions.bNoSmoothing = true;
diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp index 2bbe9ef..ccecc7b 100644 --- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp +++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
@@ -83,7 +83,7 @@ pCurObj->GetRect().top >= m_ClipRect.bottom) { if (m_pOptions->GetOptions().bBreakForMasks && pCurObj->IsImage() && pCurObj->AsImage()->GetImage()->IsMask()) { - if (m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { + if (m_pDevice->GetDeviceType() == DeviceType::kPrinter) { m_LastObjectRendered = iter; m_pRenderStatus->ProcessClipPath(pCurObj->m_ClipPath, m_pCurrentLayer->m_Matrix);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 403bdd4..e670544 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1009,7 +1009,7 @@ void CPDF_RenderStatus::Initialize(const CPDF_RenderStatus* pParentState, const CPDF_GraphicStates* pInitialStates) { - m_bPrint = m_pDevice->GetDeviceClass() != FXDC_DISPLAY; + m_bPrint = m_pDevice->GetDeviceType() != DeviceType::kDisplay; m_pPageResource.Reset(m_pContext->GetPageResources()); if (pInitialStates && !m_pType3Char) { m_InitialStates.CopyStates(*pInitialStates); @@ -1185,10 +1185,9 @@ return; int res = 300; - if (pObj->IsImage() && - m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { + if (pObj->IsImage() && m_pDevice->GetDeviceType() == DeviceType::kPrinter) res = 0; - } + CPDF_ScaledRenderBuffer buffer; if (!buffer.Initialize(m_pContext.Get(), m_pDevice, rect, pObj, &m_Options, res)) { @@ -1378,7 +1377,7 @@ if (ClipPath.GetTextCount() == 0) return; - if (m_pDevice->GetDeviceClass() == FXDC_DISPLAY && + if (m_pDevice->GetDeviceType() == DeviceType::kDisplay && !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)) { return; } @@ -1465,7 +1464,7 @@ bool bTextClip = (pPageObj->m_ClipPath.HasRef() && pPageObj->m_ClipPath.GetTextCount() > 0 && - m_pDevice->GetDeviceClass() == FXDC_DISPLAY && + m_pDevice->GetDeviceType() == DeviceType::kDisplay && !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)); if (m_Options.GetOptions().bOverprint && pPageObj->IsImage() && pPageObj->m_GeneralState.GetFillOP() && @@ -1796,10 +1795,10 @@ if (pdfium::ContainsValue(m_Type3FontCache, pType3Font)) return true; - int device_class = m_pDevice->GetDeviceClass(); + DeviceType device_type = m_pDevice->GetDeviceType(); FX_ARGB fill_argb = GetFillArgbForType3(textobj); int fill_alpha = FXARGB_A(fill_argb); - if (device_class != FXDC_DISPLAY && fill_alpha < 255) + if (device_type != DeviceType::kDisplay && fill_alpha < 255) return false; CFX_Matrix text_matrix = textobj->GetTextMatrix(); @@ -1810,7 +1809,7 @@ // Must come before |glyphs|, because |glyphs| points into |refTypeCache|. CPDF_RefType3Cache refTypeCache(pType3Font); std::vector<TextGlyphPos> glyphs; - if (device_class == FXDC_DISPLAY) + if (device_type == DeviceType::kDisplay) glyphs.resize(textobj->GetCharCodes().size()); for (size_t iChar = 0; iChar < textobj->GetCharCodes().size(); ++iChar) { @@ -1896,7 +1895,7 @@ m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); } } else if (pType3Char->GetBitmap()) { - if (device_class == FXDC_DISPLAY) { + if (device_type == DeviceType::kDisplay) { RetainPtr<CPDF_Type3Cache> pCache = GetCachedType3(pType3Font); refTypeCache.m_dwCount++; CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix);
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index a4381f9..b74d699 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -438,7 +438,7 @@ if (annot_flags & pdfium::annotation_flags::kHidden) return; - bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || + bool bPrinting = pDevice->GetDeviceType() == DeviceType::kPrinter || (pOptions && pOptions->GetOptions().bPrintPreview); if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0) { return;
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 8569208..ff2897a 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1166,10 +1166,12 @@ } #endif // !defined(OS_MACOSX) +DeviceType CFX_AggDeviceDriver::GetDeviceType() const { + return DeviceType::kDisplay; +} + int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { - case FXDC_DEVICE_CLASS: - return FXDC_DISPLAY; case FXDC_PIXEL_WIDTH: return m_pBitmap->GetWidth(); case FXDC_PIXEL_HEIGHT:
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h index ecbf1d9..7104e21 100644 --- a/core/fxge/agg/fx_agg_driver.h +++ b/core/fxge/agg/fx_agg_driver.h
@@ -42,7 +42,8 @@ void InitPlatform(); void DestroyPlatform(); - // RenderDeviceDriverIface + // RenderDeviceDriverIface: + DeviceType GetDeviceType() const override; int GetDeviceCaps(int caps_id) const override; void SaveState() override; void RestoreState(bool bKeepSaved) override;
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp index 2769f24..63582ed 100644 --- a/core/fxge/cfx_renderdevice.cpp +++ b/core/fxge/cfx_renderdevice.cpp
@@ -410,7 +410,7 @@ m_Height = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_HEIGHT); m_bpp = m_pDeviceDriver->GetDeviceCaps(FXDC_BITS_PIXEL); m_RenderCaps = m_pDeviceDriver->GetDeviceCaps(FXDC_RENDER_CAPS); - m_DeviceClass = m_pDeviceDriver->GetDeviceCaps(FXDC_DEVICE_CLASS); + m_DeviceType = m_pDeviceDriver->GetDeviceType(); if (!m_pDeviceDriver->GetClipBox(&m_ClipBox)) { m_ClipBox.left = 0; m_ClipBox.top = 0; @@ -867,7 +867,7 @@ uint32_t fill_color, uint32_t text_flags) { int nativetext_flags = text_flags; - if (m_DeviceClass != FXDC_DISPLAY) { + if (m_DeviceType != DeviceType::kDisplay) { if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { if (ShouldDrawDeviceText(pFont, text_flags) && m_pDeviceDriver->DrawDeviceText( @@ -888,7 +888,7 @@ CFX_Matrix text2Device = mtText2Device; char2device.Scale(font_size, -font_size); if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f || - ((m_DeviceClass == FXDC_PRINTER) && + (m_DeviceType == DeviceType::kPrinter && !(text_flags & FXTEXT_PRINTIMAGETEXT))) { if (pFont->GetFaceRec()) { int nPathFlags = @@ -900,7 +900,7 @@ int anti_alias = FT_RENDER_MODE_MONO; bool bNormal = false; if ((text_flags & FXTEXT_NOSMOOTH) == 0) { - if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { + if (m_DeviceType == DeviceType::kDisplay && m_bpp > 1) { if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { // Some Freetype implementations (like the one packaged with Fedora) do // not support hinting due to patents 6219025, 6239783, 6307566,
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index 96bba2e..be845d3 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h
@@ -14,16 +14,14 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/unowned_ptr.h" #include "core/fxge/fx_dib.h" +#include "core/fxge/renderdevicedriver_iface.h" -#define FXDC_DEVICE_CLASS 1 #define FXDC_PIXEL_WIDTH 2 #define FXDC_PIXEL_HEIGHT 3 #define FXDC_BITS_PIXEL 4 #define FXDC_HORZ_SIZE 5 #define FXDC_VERT_SIZE 6 #define FXDC_RENDER_CAPS 7 -#define FXDC_DISPLAY 1 -#define FXDC_PRINTER 2 #define FXRC_GET_BITS 0x01 #define FXRC_BIT_MASK 0x02 @@ -64,7 +62,6 @@ class CFX_ImageRenderer; class CFX_PathData; class PauseIndicatorIface; -class RenderDeviceDriverIface; struct CFX_Color; enum class BorderStyle { SOLID, DASH, BEVELED, INSET, UNDERLINE }; @@ -119,7 +116,7 @@ int GetWidth() const { return m_Width; } int GetHeight() const { return m_Height; } - int GetDeviceClass() const { return m_DeviceClass; } + DeviceType GetDeviceType() const { return m_DeviceType; } int GetRenderCaps() const { return m_RenderCaps; } int GetDeviceCaps(int id) const; RetainPtr<CFX_DIBitmap> GetBitmap() const; @@ -309,7 +306,7 @@ int m_Height = 0; int m_bpp = 0; int m_RenderCaps = 0; - int m_DeviceClass = 0; + DeviceType m_DeviceType = DeviceType::kUnknown; FX_RECT m_ClipBox; std::unique_ptr<RenderDeviceDriverIface> m_pDeviceDriver; };
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h index 0360074..7524f90 100644 --- a/core/fxge/renderdevicedriver_iface.h +++ b/core/fxge/renderdevicedriver_iface.h
@@ -26,10 +26,17 @@ class TextCharPos; struct FX_RECT; +enum class DeviceType : uint8_t { + kUnknown, + kDisplay, + kPrinter, +}; + class RenderDeviceDriverIface { public: virtual ~RenderDeviceDriverIface(); + virtual DeviceType GetDeviceType() const = 0; virtual int GetDeviceCaps(int caps_id) const = 0; virtual bool StartRendering();
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index faad434..9f6b1b4 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1703,11 +1703,12 @@ return true; } +DeviceType CFX_SkiaDeviceDriver::GetDeviceType() const { + return DeviceType::kDisplay; +} + int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { - case FXDC_DEVICE_CLASS: - return FXDC_DISPLAY; - #ifdef _SKIA_SUPPORT_ case FXDC_PIXEL_WIDTH: return m_pCanvas->imageInfo().width();
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index e9b2472..a4d83ad 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h
@@ -36,6 +36,7 @@ ~CFX_SkiaDeviceDriver() override; /** Options */ + DeviceType GetDeviceType() const override; int GetDeviceCaps(int caps_id) const override; /** Save and restore all graphic states */
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 6177089..a73c903 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp
@@ -704,8 +704,8 @@ return pdfium::MakeUnique<CWin32Platform>(); } -CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) - : m_hDC(hDC), m_DeviceClass(device_class) { +CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, DeviceType device_type) + : m_hDC(hDC), m_DeviceType(device_type) { auto* pPlatform = static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform()); SetStretchBltMode(hDC, pPlatform->m_bHalfTone ? HALFTONE : COLORONCOLOR); @@ -726,7 +726,7 @@ m_Width = ::GetDeviceCaps(m_hDC, HORZRES); m_Height = ::GetDeviceCaps(m_hDC, VERTRES); } - if (m_DeviceClass != FXDC_DISPLAY) { + if (m_DeviceType != DeviceType::kDisplay) { m_RenderCaps = FXRC_BIT_MASK; } else { m_RenderCaps = FXRC_GET_BITS | FXRC_BIT_MASK; @@ -735,10 +735,12 @@ CGdiDeviceDriver::~CGdiDeviceDriver() = default; +DeviceType CGdiDeviceDriver::GetDeviceType() const { + return m_DeviceType; +} + int CGdiDeviceDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { - case FXDC_DEVICE_CLASS: - return m_DeviceClass; case FXDC_PIXEL_WIDTH: return m_Width; case FXDC_PIXEL_HEIGHT: @@ -767,7 +769,7 @@ const FX_RECT& src_rect, int left, int top) { - if (m_DeviceClass == FXDC_PRINTER) { + if (m_DeviceType == DeviceType::kPrinter) { RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true); if (!pBitmap) return false; @@ -826,7 +828,7 @@ SetStretchBltMode(m_hDC, COLORONCOLOR); } RetainPtr<CFX_DIBitmap> pToStrechBitmap = pBitmap; - if (m_DeviceClass == FXDC_PRINTER && + if (m_DeviceType == DeviceType::kPrinter && ((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() > (int64_t)abs(dest_width) * abs(dest_height))) { pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height, @@ -987,9 +989,9 @@ return false; if (pPlatform->m_GdiplusExt.IsAvailable()) { - if (bDrawAlpha || - ((m_DeviceClass != FXDC_PRINTER && !(fill_mode & FXFILL_FULLCOVER)) || - (pGraphState && !pGraphState->m_DashArray.empty()))) { + if (bDrawAlpha || ((m_DeviceType != DeviceType::kPrinter && + !(fill_mode & FXFILL_FULLCOVER)) || + (pGraphState && !pGraphState->m_DashArray.empty()))) { if (!((!pMatrix || !pMatrix->WillScale()) && pGraphState && pGraphState->m_LineWidth == 1.0f && (pPathData->GetPoints().size() == 5 || @@ -1132,7 +1134,7 @@ } CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC) - : CGdiDeviceDriver(hDC, FXDC_DISPLAY) { + : CGdiDeviceDriver(hDC, DeviceType::kDisplay) { auto* pPlatform = static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform()); if (pPlatform->m_GdiplusExt.IsAvailable()) {
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index c373dad..f0ad867 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp
@@ -55,7 +55,7 @@ #endif CGdiPrinterDriver::CGdiPrinterDriver(HDC hDC) - : CGdiDeviceDriver(hDC, FXDC_PRINTER), + : CGdiDeviceDriver(hDC, DeviceType::kPrinter), m_HorzSize(::GetDeviceCaps(m_hDC, HORZSIZE)), m_VertSize(::GetDeviceCaps(m_hDC, VERTSIZE)) {} @@ -387,10 +387,12 @@ EndRendering(); } +DeviceType CPSPrinterDriver::GetDeviceType() const { + return DeviceType::kPrinter; +} + int CPSPrinterDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { - case FXDC_DEVICE_CLASS: - return FXDC_PRINTER; case FXDC_PIXEL_WIDTH: return m_Width; case FXDC_PIXEL_HEIGHT: @@ -527,10 +529,12 @@ EndRendering(); } +DeviceType CTextOnlyPrinterDriver::GetDeviceType() const { + return DeviceType::kPrinter; +} + int CTextOnlyPrinterDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { - case FXDC_DEVICE_CLASS: - return FXDC_PRINTER; case FXDC_PIXEL_WIDTH: return m_Width; case FXDC_PIXEL_HEIGHT:
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index 02c2e63..77d746e 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h
@@ -73,10 +73,11 @@ class CGdiDeviceDriver : public RenderDeviceDriverIface { protected: - CGdiDeviceDriver(HDC hDC, int device_class); + CGdiDeviceDriver(HDC hDC, DeviceType device_type); ~CGdiDeviceDriver() override; // RenderDeviceDriverIface: + DeviceType GetDeviceType() const override; int GetDeviceCaps(int caps_id) const override; void SaveState() override; void RestoreState(bool bKeepSaved) override; @@ -126,7 +127,7 @@ int m_Width; int m_Height; int m_nBitsPerPixel; - const int m_DeviceClass; + const DeviceType m_DeviceType; int m_RenderCaps; }; @@ -224,6 +225,7 @@ private: // RenderDeviceDriverIface: + DeviceType GetDeviceType() const override; int GetDeviceCaps(int caps_id) const override; bool StartRendering() override; void EndRendering() override; @@ -289,6 +291,7 @@ private: // RenderDeviceDriverIface: + DeviceType GetDeviceType() const override; int GetDeviceCaps(int caps_id) const override; void SaveState() override {} void RestoreState(bool bKeepSaved) override {}
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index d172a75..8cf515c 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp
@@ -125,7 +125,8 @@ auto pOwnedList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); CPDF_AnnotList* pList = pOwnedList.get(); pContext->m_pAnnots = std::move(pOwnedList); - bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; + bool bPrinting = + pContext->m_pDevice->GetDeviceType() != DeviceType::kDisplay; pList->DisplayAnnots(pPage, pContext->m_pContext.get(), bPrinting, &matrix, false, nullptr); } @@ -508,7 +509,7 @@ pDst->CompositeBitmap(0, 0, size_x_bm, size_y_bm, pSrc, 0, 0, BlendMode::kNormal, nullptr, false); - if (device->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { + if (device->GetDeviceType() == DeviceType::kPrinter) { device->StretchDIBits(pDst, mask_area.left, mask_area.top, size_x_bm, size_y_bm); } else { @@ -606,7 +607,7 @@ } else if (bNewBitmap) { CFX_WindowsRenderDevice WinDC(dc, &kEncoderIface); bool bitsStretched = false; - if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { + if (WinDC.GetDeviceType() == DeviceType::kPrinter) { auto pDst = pdfium::MakeRetain<CFX_DIBitmap>(); if (pDst->Create(size_x, size_y, FXDIB_Rgb32)) { memset(pDst->GetBuffer(), -1, pBitmap->GetPitch() * size_y);