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()23CPDF_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) const33FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const { 34 if (ColorModeIs(kNormal)) 35 return argb; 36 if (ColorModeIs(kAlpha)) 37 return argb; 38 39 const FX_BGRA_STRUCT<uint8_t> bgra = ArgbToBGRAStruct(argb); 40 const int gray = FXRGB2GRAY(bgra.red, bgra.green, bgra.blue); 41 return ArgbEncode(bgra.alpha, gray, gray, gray); 42 } 43 TranslateObjectFillColor(FX_ARGB argb,CPDF_PageObject::Type object_type) const44FX_ARGB CPDF_RenderOptions::TranslateObjectFillColor( 45 FX_ARGB argb, 46 CPDF_PageObject::Type object_type) const { 47 if (!ColorModeIs(kForcedColor)) { 48 return TranslateColor(argb); 49 } 50 switch (object_type) { 51 case CPDF_PageObject::Type::kPath: 52 return m_ColorScheme.path_fill_color; 53 case CPDF_PageObject::Type::kText: 54 return m_ColorScheme.text_fill_color; 55 default: 56 return argb; 57 } 58 } 59 TranslateObjectStrokeColor(FX_ARGB argb,CPDF_PageObject::Type object_type) const60FX_ARGB CPDF_RenderOptions::TranslateObjectStrokeColor( 61 FX_ARGB argb, 62 CPDF_PageObject::Type object_type) const { 63 if (!ColorModeIs(kForcedColor)) { 64 return TranslateColor(argb); 65 } 66 switch (object_type) { 67 case CPDF_PageObject::Type::kPath: 68 return m_ColorScheme.path_stroke_color; 69 case CPDF_PageObject::Type::kText: 70 return m_ColorScheme.text_stroke_color; 71 default: 72 return argb; 73 } 74 } 75 GetCacheSizeLimit() const76uint32_t CPDF_RenderOptions::GetCacheSizeLimit() const { 77 return kCacheSizeLimitBytes; 78 } 79 CheckOCGDictVisible(const CPDF_Dictionary * pOC) const80bool CPDF_RenderOptions::CheckOCGDictVisible(const CPDF_Dictionary* pOC) const { 81 return !m_pOCContext || m_pOCContext->CheckOCGDictVisible(pOC); 82 } 83 CheckPageObjectVisible(const CPDF_PageObject * pPageObj) const84bool CPDF_RenderOptions::CheckPageObjectVisible( 85 const CPDF_PageObject* pPageObj) const { 86 return !m_pOCContext || m_pOCContext->CheckPageObjectVisible(pPageObj); 87 } 88