1 // Copyright 2016 PDFium Authors. All rights reserved.
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
CPDF_RenderOptions()20 CPDF_RenderOptions::CPDF_RenderOptions() {
21 // TODO(thestig): Make constexpr to initialize |m_Options| once C++14 is
22 // available.
23 m_Options.bClearType = true;
24 }
25
26 CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs) = default;
27
28 CPDF_RenderOptions::~CPDF_RenderOptions() = default;
29
TranslateColor(FX_ARGB argb) const30 FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
31 if (ColorModeIs(kNormal))
32 return argb;
33 if (ColorModeIs(kAlpha))
34 return argb;
35
36 int a;
37 int r;
38 int g;
39 int b;
40 std::tie(a, r, g, b) = ArgbDecode(argb);
41 int gray = FXRGB2GRAY(r, g, b);
42 return ArgbEncode(a, gray, gray, gray);
43 }
44
TranslateObjectColor(FX_ARGB argb,CPDF_PageObject::Type object_type,RenderType render_type) const45 FX_ARGB CPDF_RenderOptions::TranslateObjectColor(
46 FX_ARGB argb,
47 CPDF_PageObject::Type object_type,
48 RenderType render_type) const {
49 if (!ColorModeIs(kForcedColor))
50 return TranslateColor(argb);
51
52 switch (object_type) {
53 case CPDF_PageObject::Type::PATH:
54 return render_type == RenderType::kFill ? m_ColorScheme.path_fill_color
55 : m_ColorScheme.path_stroke_color;
56 case CPDF_PageObject::Type::TEXT:
57 return render_type == RenderType::kFill ? m_ColorScheme.text_fill_color
58 : m_ColorScheme.text_stroke_color;
59 default:
60 return argb;
61 }
62 }
63
GetCacheSizeLimit() const64 uint32_t CPDF_RenderOptions::GetCacheSizeLimit() const {
65 return kCacheSizeLimitBytes;
66 }
67