Mark `DeviceType::kPrinter` as Windows-only
All the printer devices are Windows-only. Mark code paths that are only
for printers as Windows-only.
Change-Id: I948393f4a2db9e1ff4351678af7d555fb6499f62
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122373
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 92d9f87..bf9891c 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -12,6 +12,7 @@
#include <memory>
#include <utility>
+#include "build/build_config.h"
#include "core/fpdfapi/page/cpdf_dib.h"
#include "core/fpdfapi/page/cpdf_docpagedata.h"
#include "core/fpdfapi/page/cpdf_image.h"
@@ -121,10 +122,12 @@
if (GetRenderOptions().GetOptions().bForceHalftone)
m_ResampleOptions.bHalftone = true;
+#if BUILDFLAG(IS_WIN)
if (m_pRenderStatus->GetRenderDevice()->GetDeviceType() ==
DeviceType::kPrinter) {
HandleFilters();
}
+#endif
if (GetRenderOptions().GetOptions().bNoImageSmooth)
m_ResampleOptions.bNoSmoothing = true;
@@ -205,6 +208,7 @@
return StartDIBBase();
}
+#if BUILDFLAG(IS_WIN)
bool CPDF_ImageRenderer::IsPrinting() const {
if (!m_pRenderStatus->IsPrint()) {
return false;
@@ -216,6 +220,22 @@
return true;
}
+void CPDF_ImageRenderer::HandleFilters() {
+ std::optional<DecoderArray> decoder_array =
+ GetDecoderArray(m_pImageObject->GetImage()->GetStream()->GetDict());
+ if (!decoder_array.has_value()) {
+ return;
+ }
+
+ for (const auto& decoder : decoder_array.value()) {
+ if (decoder.first == "DCTDecode" || decoder.first == "JPXDecode") {
+ m_ResampleOptions.bLossy = true;
+ return;
+ }
+ }
+}
+#endif // BUILDFLAG(IS_WIN)
+
FX_RECT CPDF_ImageRenderer::GetDrawRect() const {
FX_RECT rect = m_ImageMatrix.GetUnitRect().GetOuterRect();
rect.Intersect(m_pRenderStatus->GetRenderDevice()->GetClipBox());
@@ -288,10 +308,12 @@
}
bool CPDF_ImageRenderer::DrawPatternImage() {
+#if BUILDFLAG(IS_WIN)
if (IsPrinting()) {
m_Result = false;
return false;
}
+#endif
FX_RECT rect = GetDrawRect();
if (rect.IsEmpty())
@@ -334,10 +356,12 @@
}
bool CPDF_ImageRenderer::DrawMaskedImage() {
+#if BUILDFLAG(IS_WIN)
if (IsPrinting()) {
m_Result = false;
return false;
}
+#endif
FX_RECT rect = GetDrawRect();
if (rect.IsEmpty())
@@ -410,10 +434,12 @@
if ((fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) ||
(fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) {
+#if BUILDFLAG(IS_WIN)
if (IsPrinting()) {
m_Result = false;
return false;
}
+#endif
std::optional<FX_RECT> image_rect = GetUnitRect();
if (!image_rect.has_value())
@@ -457,10 +483,13 @@
return false;
}
}
+
+#if BUILDFLAG(IS_WIN)
if (IsPrinting()) {
m_Result = false;
return true;
}
+#endif
FX_RECT clip_box = m_pRenderStatus->GetRenderDevice()->GetClipBox();
FX_RECT dest_rect = clip_box;
@@ -585,20 +614,6 @@
return false;
}
-void CPDF_ImageRenderer::HandleFilters() {
- std::optional<DecoderArray> decoder_array =
- GetDecoderArray(m_pImageObject->GetImage()->GetStream()->GetDict());
- if (!decoder_array.has_value())
- return;
-
- for (const auto& decoder : decoder_array.value()) {
- if (decoder.first == "DCTDecode" || decoder.first == "JPXDecode") {
- m_ResampleOptions.bLossy = true;
- return;
- }
- }
-}
-
std::optional<FX_RECT> CPDF_ImageRenderer::GetUnitRect() const {
CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
FX_RECT image_rect = image_rect_f.GetOuterRect();
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index b718d91..add4e08 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -10,6 +10,7 @@
#include <memory>
#include <optional>
+#include "build/build_config.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
@@ -63,7 +64,10 @@
bool ContinueTransform(PauseIndicatorIface* pPause);
bool DrawMaskedImage();
bool DrawPatternImage();
+#if BUILDFLAG(IS_WIN)
bool IsPrinting() const;
+ void HandleFilters();
+#endif
FX_RECT GetDrawRect() const;
CFX_Matrix GetDrawMatrix(const FX_RECT& rect) const;
// Returns the mask, or nullptr if the mask could not be created.
@@ -73,7 +77,6 @@
const CFX_Matrix& mtNewMatrix,
const FX_RECT& rect) const;
const CPDF_RenderOptions& GetRenderOptions() const;
- void HandleFilters();
std::optional<FX_RECT> GetUnitRect() const;
bool GetDimensionsFromUnitRect(const FX_RECT& rect,
int* left,
diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
index cc2ffcc..3dfd7a1 100644
--- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp
+++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
@@ -6,6 +6,7 @@
#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
+#include "build/build_config.h"
#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/page/cpdf_imageobject.h"
#include "core/fpdfapi/page/cpdf_pageimagecache.h"
@@ -81,12 +82,14 @@
pCurObj->GetRect().top >= m_ClipRect.bottom) {
if (m_pOptions->GetOptions().bBreakForMasks && pCurObj->IsImage() &&
pCurObj->AsImage()->GetImage()->IsMask()) {
+#if BUILDFLAG(IS_WIN)
if (m_pDevice->GetDeviceType() == DeviceType::kPrinter) {
m_LastObjectRendered = iter;
m_pRenderStatus->ProcessClipPath(pCurObj->clip_path(),
m_pCurrentLayer->GetMatrix());
return;
}
+#endif
is_mask = true;
}
if (m_pRenderStatus->ContinueSingleObject(
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 7561387..a742ad2 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -177,7 +177,9 @@
void CPDF_RenderStatus::Initialize(const CPDF_RenderStatus* pParentStatus,
const CPDF_GraphicStates* pInitialStates) {
+#if BUILDFLAG(IS_WIN)
m_bPrint = m_pDevice->GetDeviceType() == DeviceType::kPrinter;
+#endif
m_pPageResource.Reset(m_pContext->GetPageResources());
if (pInitialStates && !m_pType3Char) {
m_InitialStates = *pInitialStates;
@@ -332,7 +334,7 @@
if (rect.IsEmpty())
return;
- int res = (pObj->IsImage() && m_bPrint) ? 0 : 300;
+ int res = (pObj->IsImage() && IsPrint()) ? 0 : 300;
CPDF_ScaledRenderBuffer buffer;
if (!buffer.Initialize(m_pContext, m_pDevice, rect, pObj, &m_Options, res)) {
return;
@@ -519,7 +521,7 @@
if (ClipPath.GetTextCount() == 0)
return;
- if (!m_bPrint &&
+ if (!IsPrint() &&
!(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)) {
return;
}
@@ -600,14 +602,15 @@
initial_alpha = m_InitialStates.general_state().GetFillAlpha();
}
bool bTextClip =
- (pPageObj->clip_path().HasRef() &&
- pPageObj->clip_path().GetTextCount() > 0 && !m_bPrint &&
- !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP));
+ !IsPrint() && pPageObj->clip_path().HasRef() &&
+ pPageObj->clip_path().GetTextCount() > 0 &&
+ !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP);
if (!pSMaskDict && group_alpha == 1.0f && blend_type == BlendMode::kNormal &&
!bTextClip && !bGroupTransparent && initial_alpha == 1.0f) {
return false;
}
- if (m_bPrint) {
+#if BUILDFLAG(IS_WIN)
+ if (IsPrint()) {
bool bRet = false;
int rendCaps = m_pDevice->GetRenderCaps();
if (!(transparency.IsIsolated() || pSMaskDict || bTextClip) &&
@@ -622,6 +625,7 @@
}
return true;
}
+#endif
FX_RECT rect = pPageObj->GetTransformedBBox(mtObj2Device);
rect.Intersect(m_pDevice->GetClipBox());
if (rect.IsEmpty())
@@ -890,8 +894,11 @@
FX_ARGB fill_argb = GetFillArgbForType3(textobj);
int fill_alpha = FXARGB_A(fill_argb);
- if (m_bPrint && fill_alpha < 255)
+#if BUILDFLAG(IS_WIN)
+ if (IsPrint() && fill_alpha < 255) {
return false;
+ }
+#endif
CFX_Matrix text_matrix = textobj->GetTextMatrix();
CFX_Matrix char_matrix = pType3Font->GetFontMatrix();
@@ -901,8 +908,9 @@
// Must come before |glyphs|, because |glyphs| points into |refTypeCache|.
std::set<RetainPtr<CPDF_Type3Cache>> refTypeCache;
std::vector<TextGlyphPos> glyphs;
- if (!m_bPrint)
+ if (!IsPrint()) {
glyphs.resize(textobj->GetCharCodes().size());
+ }
for (size_t iChar = 0; iChar < textobj->GetCharCodes().size(); ++iChar) {
uint32_t charcode = textobj->GetCharCodes()[iChar];
@@ -984,44 +992,51 @@
m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top);
}
} else if (pType3Char->GetBitmap()) {
- if (m_bPrint) {
+#if BUILDFLAG(IS_WIN)
+ if (IsPrint()) {
CFX_Matrix image_matrix = pType3Char->matrix() * matrix;
CPDF_ImageRenderer renderer(this);
if (renderer.Start(pType3Char->GetBitmap(), fill_argb, image_matrix,
FXDIB_ResampleOptions(), false)) {
renderer.Continue(nullptr);
}
- if (!renderer.GetResult())
+ if (!renderer.GetResult()) {
return false;
- } else {
- CPDF_Document* pDoc = pType3Font->GetDocument();
- RetainPtr<CPDF_Type3Cache> pCache =
- CPDF_DocRenderData::FromDocument(pDoc)->GetCachedType3(pType3Font);
-
- const CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, matrix);
- if (!pBitmap)
- continue;
-
- refTypeCache.insert(std::move(pCache));
-
- CFX_Point origin(FXSYS_roundf(matrix.e), FXSYS_roundf(matrix.f));
- if (glyphs.empty()) {
- FX_SAFE_INT32 left = origin.x;
- left += pBitmap->left();
- if (!left.IsValid())
- continue;
-
- FX_SAFE_INT32 top = origin.y;
- top -= pBitmap->top();
- if (!top.IsValid())
- continue;
-
- m_pDevice->SetBitMask(pBitmap->GetBitmap(), left.ValueOrDie(),
- top.ValueOrDie(), fill_argb);
- } else {
- glyphs[iChar].m_pGlyph = pBitmap;
- glyphs[iChar].m_Origin = origin;
}
+ continue;
+ }
+#endif
+
+ CPDF_Document* pDoc = pType3Font->GetDocument();
+ RetainPtr<CPDF_Type3Cache> pCache =
+ CPDF_DocRenderData::FromDocument(pDoc)->GetCachedType3(pType3Font);
+
+ const CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, matrix);
+ if (!pBitmap) {
+ continue;
+ }
+
+ refTypeCache.insert(std::move(pCache));
+
+ CFX_Point origin(FXSYS_roundf(matrix.e), FXSYS_roundf(matrix.f));
+ if (glyphs.empty()) {
+ FX_SAFE_INT32 left = origin.x;
+ left += pBitmap->left();
+ if (!left.IsValid()) {
+ continue;
+ }
+
+ FX_SAFE_INT32 top = origin.y;
+ top -= pBitmap->top();
+ if (!top.IsValid()) {
+ continue;
+ }
+
+ m_pDevice->SetBitMask(pBitmap->GetBitmap(), left.ValueOrDie(),
+ top.ValueOrDie(), fill_argb);
+ } else {
+ glyphs[iChar].m_pGlyph = pBitmap;
+ glyphs[iChar].m_Origin = origin;
}
}
}
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 8331b4a..b90c074 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -11,6 +11,7 @@
#include <utility>
#include <vector>
+#include "build/build_config.h"
#include "core/fpdfapi/page/cpdf_clippath.h"
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include "core/fpdfapi/page/cpdf_graphicstates.h"
@@ -83,7 +84,13 @@
CPDF_ColorSpace::Family GetGroupFamily() const { return m_GroupFamily; }
bool GetLoadMask() const { return m_bLoadMask; }
bool GetDropObjects() const { return m_bDropObjects; }
- bool IsPrint() const { return m_bPrint; }
+ bool IsPrint() const {
+#if BUILDFLAG(IS_WIN)
+ return m_bPrint;
+#else
+ return false;
+#endif
+ }
bool IsStopped() const { return m_bStopped; }
CPDF_RenderContext* GetContext() const { return m_pContext; }
const CPDF_Dictionary* GetFormResource() const {
@@ -197,7 +204,9 @@
UnownedPtr<const CPDF_Type3Char> m_pType3Char;
CPDF_Transparency m_Transparency;
bool m_bStopped = false;
+#if BUILDFLAG(IS_WIN)
bool m_bPrint = false;
+#endif
bool m_bDropObjects = false;
bool m_bStdCS = false;
bool m_bLoadMask = false;
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 63c5888..2fe263b 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include <utility>
+#include "build/build_config.h"
#include "constants/annotation_common.h"
#include "constants/annotation_flags.h"
#include "core/fpdfapi/page/cpdf_form.h"
@@ -467,13 +468,19 @@
if (annot_flags & pdfium::annotation_flags::kHidden)
return;
- bool bPrinting = pDevice->GetDeviceType() == DeviceType::kPrinter;
- if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0) {
+#if BUILDFLAG(IS_WIN)
+ bool is_printing = pDevice->GetDeviceType() == DeviceType::kPrinter;
+ if (is_printing && (annot_flags & pdfium::annotation_flags::kPrint) == 0) {
return;
}
- if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView)) {
+#else
+ const bool is_printing = false;
+#endif
+
+ if (!is_printing && (annot_flags & pdfium::annotation_flags::kNoView)) {
return;
}
+
RetainPtr<const CPDF_Dictionary> pBS = m_pAnnotDict->GetDictFor("BS");
char style_char;
float width;
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index ae331f7..c28e00b 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -1081,15 +1081,30 @@
}
}
+#if BUILDFLAG(IS_WIN)
+ const bool is_printer = GetDeviceType() == DeviceType::kPrinter;
+ bool try_native_text = true;
+#else
+ constexpr bool is_printer = false;
+ constexpr bool try_native_text = true;
+#endif
+
+#if BUILDFLAG(IS_WIN)
if (GetDeviceType() == DeviceType::kPrinter) {
if (ShouldDrawDeviceText(pFont, options) &&
m_pDeviceDriver->DrawDeviceText(pCharPos, pFont, mtText2Device,
font_size, fill_color, text_options)) {
return true;
}
- if (FXARGB_A(fill_color) < 255)
+ if (FXARGB_A(fill_color) < 255) {
return false;
- } else if (options.native_text) {
+ }
+
+ try_native_text = false;
+ }
+#endif
+
+ if (try_native_text && options.native_text) {
if (ShouldDrawDeviceText(pFont, options) &&
m_pDeviceDriver->DrawDeviceText(pCharPos, pFont, mtText2Device,
font_size, fill_color, text_options)) {
@@ -1100,8 +1115,7 @@
CFX_Matrix char2device = mtText2Device;
CFX_Matrix text2Device = mtText2Device;
char2device.Scale(font_size, -font_size);
- if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f ||
- GetDeviceType() == DeviceType::kPrinter) {
+ if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f || is_printer) {
if (pFont->GetFaceRec()) {
CFX_FillRenderOptions path_options;
path_options.aliased_path = !is_text_smooth;
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index 1e37a4c..d19f6b8 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -11,6 +11,7 @@
#include <memory>
+#include "build/build_config.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/span.h"
@@ -32,7 +33,9 @@
enum class DeviceType : bool {
kDisplay,
+#if BUILDFLAG(IS_WIN)
kPrinter,
+#endif
};
class RenderDeviceDriverIface {
diff --git a/fpdfsdk/cpdfsdk_renderpage.cpp b/fpdfsdk/cpdfsdk_renderpage.cpp
index b96711b..0477bfe 100644
--- a/fpdfsdk/cpdfsdk_renderpage.cpp
+++ b/fpdfsdk/cpdfsdk_renderpage.cpp
@@ -9,6 +9,7 @@
#include <memory>
#include <utility>
+#include "build/build_config.h"
#include "core/fpdfapi/page/cpdf_pageimagecache.h"
#include "core/fpdfapi/render/cpdf_pagerendercontext.h"
#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
@@ -68,13 +69,14 @@
auto pOwnedList = std::make_unique<CPDF_AnnotList>(pPage);
CPDF_AnnotList* pList = pOwnedList.get();
pContext->m_pAnnots = std::move(pOwnedList);
- bool bPrinting =
- (flags & FPDF_PRINTING) ||
- pContext->m_pDevice->GetDeviceType() == DeviceType::kPrinter;
+ bool is_printing = (flags & FPDF_PRINTING);
+#if BUILDFLAG(IS_WIN)
+ is_printing |= pContext->m_pDevice->GetDeviceType() == DeviceType::kPrinter;
+#endif
// TODO(https://crbug.com/pdfium/993) - maybe pass true here.
const bool bShowWidget = false;
- pList->DisplayAnnots(pContext->m_pContext.get(), bPrinting, matrix,
+ pList->DisplayAnnots(pContext->m_pContext.get(), is_printing, matrix,
bShowWidget);
}