xref: /aosp_15_r20/external/pdfium/core/fpdfapi/render/cpdf_renderoptions.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fpdfapi/render/cpdf_renderoptions.h"
8 
9 namespace {
10 
11 constexpr uint32_t kCacheSizeLimitBytes = 100 * 1024 * 1024;
12 
13 }  // namespace
14 
15 CPDF_RenderOptions::Options::Options() = default;
16 
17 CPDF_RenderOptions::Options::Options(const CPDF_RenderOptions::Options& rhs) =
18     default;
19 
20 CPDF_RenderOptions::Options& CPDF_RenderOptions::Options::operator=(
21     const CPDF_RenderOptions::Options& rhs) = default;
22 
CPDF_RenderOptions()23 CPDF_RenderOptions::CPDF_RenderOptions() {
24   // TODO(thestig): Make constexpr to initialize |m_Options| once C++14 is
25   // available.
26   m_Options.bClearType = true;
27 }
28 
29 CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs) = default;
30 
31 CPDF_RenderOptions::~CPDF_RenderOptions() = default;
32 
TranslateColor(FX_ARGB argb) const33 FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
34   if (ColorModeIs(kNormal))
35     return argb;
36   if (ColorModeIs(kAlpha))
37     return argb;
38 
39   int a;
40   int r;
41   int g;
42   int b;
43   std::tie(a, r, g, b) = ArgbDecode(argb);
44   int gray = FXRGB2GRAY(r, g, b);
45   return ArgbEncode(a, gray, gray, gray);
46 }
47 
TranslateObjectColor(FX_ARGB argb,CPDF_PageObject::Type object_type,RenderType render_type) const48 FX_ARGB CPDF_RenderOptions::TranslateObjectColor(
49     FX_ARGB argb,
50     CPDF_PageObject::Type object_type,
51     RenderType render_type) const {
52   if (!ColorModeIs(kForcedColor))
53     return TranslateColor(argb);
54 
55   switch (object_type) {
56     case CPDF_PageObject::Type::kPath:
57       return render_type == RenderType::kFill ? m_ColorScheme.path_fill_color
58                                               : m_ColorScheme.path_stroke_color;
59     case CPDF_PageObject::Type::kText:
60       return render_type == RenderType::kFill ? m_ColorScheme.text_fill_color
61                                               : m_ColorScheme.text_stroke_color;
62     default:
63       return argb;
64   }
65 }
66 
GetCacheSizeLimit() const67 uint32_t CPDF_RenderOptions::GetCacheSizeLimit() const {
68   return kCacheSizeLimitBytes;
69 }
70 
CheckOCGDictVisible(const CPDF_Dictionary * pOC) const71 bool CPDF_RenderOptions::CheckOCGDictVisible(const CPDF_Dictionary* pOC) const {
72   return !m_pOCContext || m_pOCContext->CheckOCGDictVisible(pOC);
73 }
74 
CheckPageObjectVisible(const CPDF_PageObject * pPageObj) const75 bool CPDF_RenderOptions::CheckPageObjectVisible(
76     const CPDF_PageObject* pPageObj) const {
77   return !m_pOCContext || m_pOCContext->CheckPageObjectVisible(pPageObj);
78 }
79