John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | 95e854f | 2015-06-13 00:58:06 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | 764ec51 | 2016-03-14 13:35:12 -0400 | [diff] [blame] | 7 | #include "core/fpdfapi/fpdf_render/render_int.h" |
Lei Zhang | e5b0bd1 | 2015-06-19 17:15:41 -0700 | [diff] [blame] | 8 | |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_font/cpdf_type3char.h" |
| 12 | #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 15 | #include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 16 | #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 17 | #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 18 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 19 | #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
| 20 | #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" |
| 21 | #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" |
Dan Sinclair | 764ec51 | 2016-03-14 13:35:12 -0400 | [diff] [blame] | 22 | #include "core/fpdfapi/fpdf_page/pageint.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 23 | #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 24 | #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| 25 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 26 | #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" |
npm | eadff19 | 2016-09-01 13:21:37 -0700 | [diff] [blame] | 27 | #include "core/fpdfapi/fpdf_render/cpdf_type3cache.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 28 | #include "core/fpdfapi/fpdf_render/include/cpdf_progressiverenderer.h" |
| 29 | #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
| 30 | #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" |
| 31 | #include "core/fpdfapi/include/cpdf_modulemgr.h" |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 32 | #include "core/fpdfdoc/include/cpdf_occontext.h" |
npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 33 | #include "core/fxge/include/cfx_fontcache.h" |
npm | 9ada2d8 | 2016-08-10 07:51:38 -0700 | [diff] [blame] | 34 | #include "core/fxge/include/cfx_fxgedevice.h" |
| 35 | #include "core/fxge/include/cfx_graphstatedata.h" |
npm | 660de3c | 2016-08-08 08:18:29 -0700 | [diff] [blame] | 36 | #include "core/fxge/include/cfx_pathdata.h" |
npm | 9ada2d8 | 2016-08-10 07:51:38 -0700 | [diff] [blame] | 37 | #include "core/fxge/include/cfx_renderdevice.h" |
Lei Zhang | a9fa50f | 2015-11-10 09:45:32 -0800 | [diff] [blame] | 38 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | : m_pPDFDoc(pPDFDoc), m_pFontCache(new CFX_FontCache) {} |
| 41 | |
| 42 | CPDF_DocRenderData::~CPDF_DocRenderData() { |
| 43 | Clear(TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | void CPDF_DocRenderData::Clear(FX_BOOL bRelease) { |
| 47 | for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) { |
| 48 | auto curr_it = it++; |
| 49 | CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second; |
| 50 | if (bRelease || cache->use_count() < 2) { |
| 51 | delete cache->get(); |
| 52 | delete cache; |
| 53 | m_Type3FaceMap.erase(curr_it); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | } |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) { |
| 58 | auto curr_it = it++; |
| 59 | CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second; |
| 60 | if (bRelease || value->use_count() < 2) { |
| 61 | delete value->get(); |
| 62 | delete value; |
| 63 | m_TransferFuncMap.erase(curr_it); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | } |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | if (m_pFontCache) { |
| 68 | if (bRelease) { |
| 69 | delete m_pFontCache; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 70 | m_pFontCache = nullptr; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 71 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | m_pFontCache->FreeCache(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | } |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 76 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) { |
| 78 | CPDF_CountedObject<CPDF_Type3Cache>* pCache; |
| 79 | auto it = m_Type3FaceMap.find(pFont); |
| 80 | if (it == m_Type3FaceMap.end()) { |
| 81 | CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont); |
| 82 | pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3); |
| 83 | m_Type3FaceMap[pFont] = pCache; |
| 84 | } else { |
| 85 | pCache = it->second; |
| 86 | } |
| 87 | return pCache->AddRef(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
Lei Zhang | fa6eb28 | 2015-06-19 17:17:54 -0700 | [diff] [blame] | 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) { |
| 91 | auto it = m_Type3FaceMap.find(pFont); |
| 92 | if (it != m_Type3FaceMap.end()) |
| 93 | it->second->RemoveRef(); |
| 94 | } |
Lei Zhang | fa6eb28 | 2015-06-19 17:17:54 -0700 | [diff] [blame] | 95 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 96 | CPDF_RenderOptions::CPDF_RenderOptions() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | : m_ColorMode(RENDER_COLOR_NORMAL), |
| 98 | m_Flags(RENDER_CLEARTYPE), |
| 99 | m_Interpolation(0), |
| 100 | m_AddFlags(0), |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 101 | m_pOCContext(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | m_dwLimitCacheSize(1024 * 1024 * 100), |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 103 | m_HalftoneLimit(-1), |
| 104 | m_bDrawAnnots(false) {} |
| 105 | |
| 106 | CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs) |
| 107 | : m_ColorMode(rhs.m_ColorMode), |
| 108 | m_BackColor(rhs.m_BackColor), |
| 109 | m_ForeColor(rhs.m_ForeColor), |
| 110 | m_Flags(rhs.m_Flags), |
| 111 | m_Interpolation(rhs.m_Interpolation), |
| 112 | m_AddFlags(rhs.m_AddFlags), |
| 113 | m_pOCContext(rhs.m_pOCContext), |
| 114 | m_dwLimitCacheSize(rhs.m_dwLimitCacheSize), |
| 115 | m_HalftoneLimit(rhs.m_HalftoneLimit), |
| 116 | m_bDrawAnnots(rhs.m_bDrawAnnots) {} |
| 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const { |
| 119 | if (m_ColorMode == RENDER_COLOR_NORMAL) { |
| 120 | return argb; |
| 121 | } |
| 122 | if (m_ColorMode == RENDER_COLOR_ALPHA) { |
| 123 | return argb; |
| 124 | } |
| 125 | int a, r, g, b; |
| 126 | ArgbDecode(argb, a, r, g, b); |
| 127 | int gray = FXRGB2GRAY(r, g, b); |
| 128 | if (m_ColorMode == RENDER_COLOR_TWOCOLOR) { |
| 129 | int color = (r - gray) * (r - gray) + (g - gray) * (g - gray) + |
| 130 | (b - gray) * (b - gray); |
| 131 | if (gray < 35 && color < 20) { |
| 132 | return ArgbEncode(a, m_ForeColor); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | if (gray > 221 && color < 20) { |
| 135 | return ArgbEncode(a, m_BackColor); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | return argb; |
| 138 | } |
| 139 | int fr = FXSYS_GetRValue(m_ForeColor); |
| 140 | int fg = FXSYS_GetGValue(m_ForeColor); |
| 141 | int fb = FXSYS_GetBValue(m_ForeColor); |
| 142 | int br = FXSYS_GetRValue(m_BackColor); |
| 143 | int bg = FXSYS_GetGValue(m_BackColor); |
| 144 | int bb = FXSYS_GetBValue(m_BackColor); |
| 145 | r = (br - fr) * gray / 255 + fr; |
| 146 | g = (bg - fg) * gray / 255 + fg; |
| 147 | b = (bb - fb) * gray / 255 + fb; |
| 148 | return ArgbEncode(a, r, g, b); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } |
Tom Sepez | 09dc51a | 2015-01-29 18:16:16 -0800 | [diff] [blame] | 150 | |
| 151 | // static |
| 152 | int CPDF_RenderStatus::s_CurrentRecursionDepth = 0; |
| 153 | |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 154 | CPDF_RenderStatus::CPDF_RenderStatus() |
| 155 | : m_pFormResource(nullptr), |
| 156 | m_pPageResource(nullptr), |
| 157 | m_pContext(nullptr), |
| 158 | m_bStopped(FALSE), |
| 159 | m_pDevice(nullptr), |
| 160 | m_pCurObj(nullptr), |
| 161 | m_pStopObj(nullptr), |
| 162 | m_HalftoneLimit(0), |
| 163 | m_bPrint(FALSE), |
| 164 | m_Transparency(0), |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 165 | m_bDropObjects(FALSE), |
| 166 | m_bStdCS(FALSE), |
| 167 | m_GroupFamily(0), |
| 168 | m_bLoadMask(FALSE), |
| 169 | m_pType3Char(nullptr), |
| 170 | m_T3FillColor(0), |
| 171 | m_curBlend(FXDIB_BLEND_NORMAL) {} |
Tom Sepez | 09dc51a | 2015-01-29 18:16:16 -0800 | [diff] [blame] | 172 | |
Dan Sinclair | 764ec51 | 2016-03-14 13:35:12 -0400 | [diff] [blame] | 173 | CPDF_RenderStatus::~CPDF_RenderStatus() {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | |
| 175 | FX_BOOL CPDF_RenderStatus::Initialize(CPDF_RenderContext* pContext, |
| 176 | CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 177 | const CFX_Matrix* pDeviceMatrix, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | const CPDF_PageObject* pStopObj, |
| 179 | const CPDF_RenderStatus* pParentState, |
| 180 | const CPDF_GraphicStates* pInitialStates, |
| 181 | const CPDF_RenderOptions* pOptions, |
| 182 | int transparency, |
| 183 | FX_BOOL bDropObjects, |
| 184 | CPDF_Dictionary* pFormResource, |
| 185 | FX_BOOL bStdCS, |
| 186 | CPDF_Type3Char* pType3Char, |
| 187 | FX_ARGB fill_color, |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 188 | uint32_t GroupFamily, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | FX_BOOL bLoadMask) { |
| 190 | m_pContext = pContext; |
| 191 | m_pDevice = pDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | m_bPrint = m_pDevice->GetDeviceClass() != FXDC_DISPLAY; |
| 193 | if (pDeviceMatrix) { |
| 194 | m_DeviceMatrix = *pDeviceMatrix; |
| 195 | } |
| 196 | m_pStopObj = pStopObj; |
| 197 | if (pOptions) { |
| 198 | m_Options = *pOptions; |
| 199 | } |
| 200 | m_bDropObjects = bDropObjects; |
| 201 | m_bStdCS = bStdCS; |
| 202 | m_T3FillColor = fill_color; |
| 203 | m_pType3Char = pType3Char; |
| 204 | m_GroupFamily = GroupFamily; |
| 205 | m_bLoadMask = bLoadMask; |
| 206 | m_pFormResource = pFormResource; |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 207 | m_pPageResource = m_pContext->GetPageResources(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | if (pInitialStates && !m_pType3Char) { |
| 209 | m_InitialStates.CopyStates(*pInitialStates); |
| 210 | if (pParentState) { |
tsepez | ca90b87 | 2016-08-31 10:41:00 -0700 | [diff] [blame] | 211 | if (!m_InitialStates.m_ColorState.HasFillColor()) { |
| 212 | m_InitialStates.m_ColorState.SetFillRGB( |
| 213 | pParentState->m_InitialStates.m_ColorState.GetFillRGB()); |
| 214 | m_InitialStates.m_ColorState.GetMutableFillColor()->Copy( |
| 215 | pParentState->m_InitialStates.m_ColorState.GetFillColor()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | } |
tsepez | ca90b87 | 2016-08-31 10:41:00 -0700 | [diff] [blame] | 217 | if (!m_InitialStates.m_ColorState.HasStrokeColor()) { |
| 218 | m_InitialStates.m_ColorState.SetStrokeRGB( |
| 219 | pParentState->m_InitialStates.m_ColorState.GetFillRGB()); |
| 220 | m_InitialStates.m_ColorState.GetMutableStrokeColor()->Copy( |
| 221 | pParentState->m_InitialStates.m_ColorState.GetStrokeColor()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } else { |
| 225 | m_InitialStates.DefaultStates(); |
| 226 | } |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 227 | m_pImageRenderer.reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | m_Transparency = transparency; |
| 229 | return TRUE; |
| 230 | } |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 231 | void CPDF_RenderStatus::RenderObjectList( |
| 232 | const CPDF_PageObjectHolder* pObjectHolder, |
| 233 | const CFX_Matrix* pObj2Device) { |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 234 | #if defined _SKIA_SUPPORT_ |
| 235 | DebugVerifyDeviceIsPreMultiplied(); |
| 236 | #endif |
Tom Sepez | d5e7b35 | 2016-02-29 11:24:29 -0800 | [diff] [blame] | 237 | CFX_FloatRect clip_rect(m_pDevice->GetClipBox()); |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 238 | CFX_Matrix device2object; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | device2object.SetReverse(*pObj2Device); |
| 240 | device2object.TransformRect(clip_rect); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 241 | |
| 242 | for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) { |
| 243 | if (pCurObj.get() == m_pStopObj) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | m_bStopped = TRUE; |
| 245 | return; |
| 246 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 247 | if (!pCurObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | continue; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 249 | |
| 250 | if (pCurObj->m_Left > clip_rect.right || |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | pCurObj->m_Right < clip_rect.left || |
| 252 | pCurObj->m_Bottom > clip_rect.top || |
| 253 | pCurObj->m_Top < clip_rect.bottom) { |
| 254 | continue; |
| 255 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 256 | RenderSingleObject(pCurObj.get(), pObj2Device); |
| 257 | if (m_bStopped) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | } |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 260 | #if defined _SKIA_SUPPORT_ |
| 261 | DebugVerifyDeviceIsPreMultiplied(); |
| 262 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | } |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 264 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 265 | void CPDF_RenderStatus::RenderSingleObject(CPDF_PageObject* pObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 266 | const CFX_Matrix* pObj2Device) { |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 267 | #if defined _SKIA_SUPPORT_ |
| 268 | DebugVerifyDeviceIsPreMultiplied(); |
| 269 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 271 | if (++s_CurrentRecursionDepth > kRenderMaxRecursionDepth) { |
| 272 | return; |
| 273 | } |
| 274 | m_pCurObj = pObj; |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 275 | if (m_Options.m_pOCContext && pObj->m_ContentMark) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | if (!m_Options.m_pOCContext->CheckObjectVisible(pObj)) { |
| 277 | return; |
| 278 | } |
| 279 | } |
| 280 | ProcessClipPath(pObj->m_ClipPath, pObj2Device); |
| 281 | if (ProcessTransparency(pObj, pObj2Device)) { |
| 282 | return; |
| 283 | } |
| 284 | ProcessObjectNoClip(pObj, pObj2Device); |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 285 | #if defined _SKIA_SUPPORT_ |
| 286 | DebugVerifyDeviceIsPreMultiplied(); |
| 287 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 289 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 290 | FX_BOOL CPDF_RenderStatus::ContinueSingleObject(CPDF_PageObject* pObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 291 | const CFX_Matrix* pObj2Device, |
| 292 | IFX_Pause* pPause) { |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 293 | if (m_pImageRenderer) { |
| 294 | if (m_pImageRenderer->Continue(pPause)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | return TRUE; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 296 | |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 297 | if (!m_pImageRenderer->m_Result) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | DrawObjWithBackground(pObj, pObj2Device); |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 299 | m_pImageRenderer.reset(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 300 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 302 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | m_pCurObj = pObj; |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 304 | if (m_Options.m_pOCContext && pObj->m_ContentMark && |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 305 | !m_Options.m_pOCContext->CheckObjectVisible(pObj)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | return FALSE; |
| 307 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 308 | |
| 309 | ProcessClipPath(pObj->m_ClipPath, pObj2Device); |
| 310 | if (ProcessTransparency(pObj, pObj2Device)) |
| 311 | return FALSE; |
| 312 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 313 | if (pObj->IsImage()) { |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 314 | m_pImageRenderer.reset(new CPDF_ImageRenderer); |
| 315 | if (!m_pImageRenderer->Start(this, pObj, pObj2Device, FALSE)) { |
| 316 | if (!m_pImageRenderer->m_Result) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | DrawObjWithBackground(pObj, pObj2Device); |
dsinclair | d647a6b | 2016-04-26 13:13:20 -0700 | [diff] [blame] | 318 | m_pImageRenderer.reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 320 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | return ContinueSingleObject(pObj, pObj2Device, pPause); |
| 322 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 323 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 324 | ProcessObjectNoClip(pObj, pObj2Device); |
| 325 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 326 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 327 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 328 | FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, |
| 329 | const CFX_Matrix* pObj2Device, |
| 330 | FX_BOOL bLogical, |
| 331 | FX_RECT& rect) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | rect = pObj->GetBBox(pObj2Device); |
| 333 | FX_RECT rtClip = m_pDevice->GetClipBox(); |
| 334 | if (!bLogical) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 335 | CFX_Matrix dCTM = m_pDevice->GetCTM(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | FX_FLOAT a = FXSYS_fabs(dCTM.a); |
| 337 | FX_FLOAT d = FXSYS_fabs(dCTM.d); |
| 338 | if (a != 1.0f || d != 1.0f) { |
| 339 | rect.right = rect.left + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Width() * a); |
| 340 | rect.bottom = rect.top + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Height() * d); |
| 341 | rtClip.right = |
| 342 | rtClip.left + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Width() * a); |
| 343 | rtClip.bottom = |
| 344 | rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d); |
| 345 | } |
| 346 | } |
| 347 | rect.Intersect(rtClip); |
| 348 | return rect.IsEmpty(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 349 | } |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 350 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 351 | void CPDF_RenderStatus::ProcessObjectNoClip(CPDF_PageObject* pObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 352 | const CFX_Matrix* pObj2Device) { |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 353 | #if defined _SKIA_SUPPORT_ |
| 354 | DebugVerifyDeviceIsPreMultiplied(); |
| 355 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | FX_BOOL bRet = FALSE; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 357 | switch (pObj->GetType()) { |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 358 | case CPDF_PageObject::TEXT: |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 359 | bRet = ProcessText(pObj->AsText(), pObj2Device, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 361 | case CPDF_PageObject::PATH: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 362 | bRet = ProcessPath(pObj->AsPath(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 364 | case CPDF_PageObject::IMAGE: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 365 | bRet = ProcessImage(pObj->AsImage(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 367 | case CPDF_PageObject::SHADING: |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 368 | ProcessShading(pObj->AsShading(), pObj2Device); |
| 369 | return; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 370 | case CPDF_PageObject::FORM: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 371 | bRet = ProcessForm(pObj->AsForm(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 372 | break; |
| 373 | } |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 374 | if (!bRet) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | DrawObjWithBackground(pObj, pObj2Device); |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 376 | #if defined _SKIA_SUPPORT_ |
| 377 | DebugVerifyDeviceIsPreMultiplied(); |
| 378 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | } |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 380 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 381 | FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(CPDF_PageObject* pObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 382 | const CFX_Matrix* pObj2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 383 | FX_BOOL bRet = FALSE; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 384 | switch (pObj->GetType()) { |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 385 | case CPDF_PageObject::PATH: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 386 | bRet = ProcessPath(pObj->AsPath(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 388 | case CPDF_PageObject::IMAGE: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 389 | bRet = ProcessImage(pObj->AsImage(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 391 | case CPDF_PageObject::FORM: |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 392 | bRet = ProcessForm(pObj->AsForm(), pObj2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 394 | default: |
| 395 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | } |
| 397 | return bRet; |
| 398 | } |
| 399 | void CPDF_RenderStatus::GetScaledMatrix(CFX_Matrix& matrix) const { |
| 400 | CFX_Matrix dCTM = m_pDevice->GetCTM(); |
| 401 | matrix.a *= FXSYS_fabs(dCTM.a); |
| 402 | matrix.d *= FXSYS_fabs(dCTM.d); |
| 403 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 404 | |
| 405 | void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 406 | const CFX_Matrix* pObj2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | FX_RECT rect; |
| 408 | if (GetObjectClippedRect(pObj, pObj2Device, FALSE, rect)) { |
| 409 | return; |
| 410 | } |
| 411 | int res = 300; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 412 | if (pObj->IsImage() && |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
| 414 | res = 0; |
| 415 | } |
| 416 | CPDF_ScaledRenderBuffer buffer; |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 417 | if (!buffer.Initialize(m_pContext, m_pDevice, rect, pObj, &m_Options, res)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | return; |
| 419 | } |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 420 | CFX_Matrix matrix = *pObj2Device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | matrix.Concat(*buffer.GetMatrix()); |
| 422 | GetScaledMatrix(matrix); |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 423 | CPDF_Dictionary* pFormResource = nullptr; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 424 | if (pObj->IsForm()) { |
| 425 | const CPDF_FormObject* pFormObj = pObj->AsForm(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 426 | if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 427 | pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 428 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | } |
| 430 | CPDF_RenderStatus status; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 431 | status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr, |
| 432 | nullptr, nullptr, &m_Options, m_Transparency, |
| 433 | m_bDropObjects, pFormResource); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | status.RenderSingleObject(pObj, &matrix); |
| 435 | buffer.OutputToDevice(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 436 | } |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 437 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 438 | FX_BOOL CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 439 | const CFX_Matrix* pObj2Device) { |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 440 | #if defined _SKIA_SUPPORT_ |
| 441 | DebugVerifyDeviceIsPreMultiplied(); |
| 442 | #endif |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 443 | CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictFor("OC"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | if (pOC && m_Options.m_pOCContext && |
| 445 | !m_Options.m_pOCContext->CheckOCGVisible(pOC)) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 446 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 447 | } |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 448 | CFX_Matrix matrix = pFormObj->m_FormMatrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | matrix.Concat(*pObj2Device); |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 450 | CPDF_Dictionary* pResources = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 452 | pResources = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | } |
| 454 | CPDF_RenderStatus status; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 455 | status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | &m_Options, m_Transparency, m_bDropObjects, pResources, |
| 457 | FALSE); |
| 458 | status.m_curBlend = m_curBlend; |
| 459 | m_pDevice->SaveState(); |
weili | 44105d8 | 2016-07-06 18:10:35 -0700 | [diff] [blame] | 460 | status.RenderObjectList(pFormObj->m_pForm.get(), &matrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | m_bStopped = status.m_bStopped; |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 462 | m_pDevice->RestoreState(false); |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 463 | #if defined _SKIA_SUPPORT_ |
| 464 | DebugVerifyDeviceIsPreMultiplied(); |
| 465 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | } |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 468 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 469 | FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | if (matrix.a == 0 || matrix.d == 0) { |
| 471 | return matrix.b != 0 && matrix.c != 0; |
| 472 | } |
| 473 | if (matrix.b == 0 || matrix.c == 0) { |
| 474 | return matrix.a != 0 && matrix.d != 0; |
| 475 | } |
| 476 | return TRUE; |
| 477 | } |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 478 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 479 | FX_BOOL CPDF_RenderStatus::ProcessPath(CPDF_PathObject* pPathObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 480 | const CFX_Matrix* pObj2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | int FillType = pPathObj->m_FillType; |
| 482 | FX_BOOL bStroke = pPathObj->m_bStroke; |
| 483 | ProcessPathPattern(pPathObj, pObj2Device, FillType, bStroke); |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 484 | if (FillType == 0 && !bStroke) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 485 | return TRUE; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 486 | |
| 487 | uint32_t fill_argb = FillType ? GetFillArgb(pPathObj) : 0; |
| 488 | uint32_t stroke_argb = bStroke ? GetStrokeArgb(pPathObj) : 0; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 489 | CFX_Matrix path_matrix = pPathObj->m_Matrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | path_matrix.Concat(*pObj2Device); |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 491 | if (!IsAvailableMatrix(path_matrix)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | return TRUE; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 493 | |
| 494 | if (FillType && (m_Options.m_Flags & RENDER_RECT_AA)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | FillType |= FXFILL_RECT_AA; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 496 | if (m_Options.m_Flags & RENDER_FILL_FULLCOVER) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | FillType |= FXFILL_FULLCOVER; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 498 | if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | FillType |= FXFILL_NOPATHSMOOTH; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 500 | if (bStroke) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 501 | FillType |= FX_FILL_STROKE; |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 502 | |
| 503 | const CPDF_PageObject* pPageObj = |
| 504 | static_cast<const CPDF_PageObject*>(pPathObj); |
| 505 | if (pPageObj->m_GeneralState.GetStrokeAdjust()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | FillType |= FX_STROKE_ADJUST; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 507 | if (m_pType3Char) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | FillType |= FX_FILL_TEXT_MODE; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 509 | |
tsepez | 7c9f0a1 | 2016-09-06 13:02:55 -0700 | [diff] [blame] | 510 | CFX_GraphState graphState = pPathObj->m_GraphState; |
thestig | 2f30766 | 2016-06-13 15:02:05 -0700 | [diff] [blame] | 511 | if (m_Options.m_Flags & RENDER_THINLINE) |
tsepez | 4d9df42 | 2016-08-31 10:26:38 -0700 | [diff] [blame] | 512 | graphState.SetLineWidth(0); |
| 513 | return m_pDevice->DrawPathWithBlend( |
| 514 | pPathObj->m_Path.GetObject(), &path_matrix, graphState.GetObject(), |
| 515 | fill_argb, stroke_argb, FillType, m_curBlend); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | } |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 517 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | CPDF_TransferFunc* CPDF_RenderStatus::GetTransferFunc(CPDF_Object* pObj) const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 519 | ASSERT(pObj); |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 520 | CPDF_DocRenderData* pDocCache = m_pContext->GetDocument()->GetRenderData(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 521 | return pDocCache ? pDocCache->GetTransferFunc(pObj) : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 523 | |
| 524 | FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | FX_BOOL bType3) const { |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 526 | const CPDF_ColorState* pColorState = &pObj->m_ColorState; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | if (m_pType3Char && !bType3 && |
| 528 | (!m_pType3Char->m_bColored || |
| 529 | (m_pType3Char->m_bColored && |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 530 | (!*pColorState || pColorState->GetFillColor()->IsNull())))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 531 | return m_T3FillColor; |
| 532 | } |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 533 | if (!*pColorState || pColorState->GetFillColor()->IsNull()) |
| 534 | pColorState = &m_InitialStates.m_ColorState; |
| 535 | |
| 536 | FX_COLORREF rgb = pColorState->GetFillRGB(); |
| 537 | if (rgb == (uint32_t)-1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | return 0; |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 539 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 540 | int32_t alpha = |
| 541 | static_cast<int32_t>((pObj->m_GeneralState.GetFillAlpha() * 255)); |
| 542 | if (pObj->m_GeneralState.GetTR()) { |
| 543 | if (!pObj->m_GeneralState.GetTransferFunc()) { |
| 544 | pObj->m_GeneralState.SetTransferFunc( |
| 545 | GetTransferFunc(pObj->m_GeneralState.GetTR())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 546 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 547 | if (pObj->m_GeneralState.GetTransferFunc()) |
| 548 | rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 549 | } |
| 550 | return m_Options.TranslateColor(ArgbEncode(alpha, rgb)); |
| 551 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 552 | |
| 553 | FX_ARGB CPDF_RenderStatus::GetStrokeArgb(CPDF_PageObject* pObj) const { |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 554 | const CPDF_ColorState* pColorState = &pObj->m_ColorState; |
| 555 | if (m_pType3Char && |
| 556 | (!m_pType3Char->m_bColored || |
| 557 | (m_pType3Char->m_bColored && |
| 558 | (!*pColorState || pColorState->GetStrokeColor()->IsNull())))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | return m_T3FillColor; |
| 560 | } |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 561 | if (!*pColorState || pColorState->GetStrokeColor()->IsNull()) |
| 562 | pColorState = &m_InitialStates.m_ColorState; |
| 563 | |
| 564 | FX_COLORREF rgb = pColorState->GetStrokeRGB(); |
| 565 | if (rgb == (uint32_t)-1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 566 | return 0; |
tsepez | f40c6f1 | 2016-09-06 11:45:32 -0700 | [diff] [blame] | 567 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 568 | int32_t alpha = static_cast<int32_t>(pObj->m_GeneralState.GetStrokeAlpha() * |
| 569 | 255); // not rounded. |
| 570 | if (pObj->m_GeneralState.GetTR()) { |
| 571 | if (!pObj->m_GeneralState.GetTransferFunc()) { |
| 572 | pObj->m_GeneralState.SetTransferFunc( |
| 573 | GetTransferFunc(pObj->m_GeneralState.GetTR())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 574 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 575 | if (pObj->m_GeneralState.GetTransferFunc()) |
| 576 | rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 577 | } |
| 578 | return m_Options.TranslateColor(ArgbEncode(alpha, rgb)); |
| 579 | } |
| 580 | void CPDF_RenderStatus::ProcessClipPath(CPDF_ClipPath ClipPath, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 581 | const CFX_Matrix* pObj2Device) { |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 582 | if (!ClipPath) { |
| 583 | if (m_LastClipPath) { |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 584 | m_pDevice->RestoreState(true); |
tsepez | d24c3a6 | 2016-08-29 14:42:36 -0700 | [diff] [blame] | 585 | m_LastClipPath.SetNull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 586 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 587 | return; |
| 588 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 589 | if (m_LastClipPath == ClipPath) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | return; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 591 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | m_LastClipPath = ClipPath; |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 593 | m_pDevice->RestoreState(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | int nClipPath = ClipPath.GetPathCount(); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 595 | for (int i = 0; i < nClipPath; ++i) { |
tsepez | 7d2a8d9 | 2016-06-08 11:51:23 -0700 | [diff] [blame] | 596 | const CFX_PathData* pPathData = ClipPath.GetPath(i).GetObject(); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 597 | if (!pPathData) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | continue; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 599 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 600 | if (pPathData->GetPointCount() == 0) { |
| 601 | CFX_PathData EmptyPath; |
| 602 | EmptyPath.AppendRect(-1, -1, 0, 0); |
| 603 | int fill_mode = FXFILL_WINDING; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 604 | m_pDevice->SetClip_PathFill(&EmptyPath, nullptr, fill_mode); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | } else { |
| 606 | int ClipType = ClipPath.GetClipType(i); |
| 607 | m_pDevice->SetClip_PathFill(pPathData, pObj2Device, ClipType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 608 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | } |
| 610 | int textcount = ClipPath.GetTextCount(); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 611 | if (textcount == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | return; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 613 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | if (m_pDevice->GetDeviceClass() == FXDC_DISPLAY && |
| 615 | !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)) { |
| 616 | return; |
| 617 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 618 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 619 | std::unique_ptr<CFX_PathData> pTextClippingPath; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 620 | for (int i = 0; i < textcount; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | CPDF_TextObject* pText = ClipPath.GetText(i); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 622 | if (pText) { |
| 623 | if (!pTextClippingPath) |
| 624 | pTextClippingPath.reset(new CFX_PathData); |
| 625 | ProcessText(pText, pObj2Device, pTextClippingPath.get()); |
| 626 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 627 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 628 | |
| 629 | if (!pTextClippingPath) |
| 630 | continue; |
| 631 | |
| 632 | int fill_mode = FXFILL_WINDING; |
| 633 | if (m_Options.m_Flags & RENDER_NOTEXTSMOOTH) |
| 634 | fill_mode |= FXFILL_NOPATHSMOOTH; |
| 635 | m_pDevice->SetClip_PathFill(pTextClippingPath.get(), nullptr, fill_mode); |
| 636 | pTextClippingPath.reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 639 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | void CPDF_RenderStatus::DrawClipPath(CPDF_ClipPath ClipPath, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 641 | const CFX_Matrix* pObj2Device) { |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 642 | if (!ClipPath) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | return; |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | int fill_mode = 0; |
| 646 | if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) { |
| 647 | fill_mode |= FXFILL_NOPATHSMOOTH; |
| 648 | } |
| 649 | int nClipPath = ClipPath.GetPathCount(); |
| 650 | int i; |
| 651 | for (i = 0; i < nClipPath; i++) { |
tsepez | 7d2a8d9 | 2016-06-08 11:51:23 -0700 | [diff] [blame] | 652 | const CFX_PathData* pPathData = ClipPath.GetPath(i).GetObject(); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 653 | if (!pPathData) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 655 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | CFX_GraphStateData stroke_state; |
| 657 | if (m_Options.m_Flags & RENDER_THINLINE) { |
| 658 | stroke_state.m_LineWidth = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 659 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 660 | m_pDevice->DrawPath(pPathData, pObj2Device, &stroke_state, 0, 0xffff0000, |
| 661 | fill_mode); |
| 662 | } |
| 663 | } |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 664 | FX_BOOL CPDF_RenderStatus::SelectClipPath(const CPDF_PathObject* pPathObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 665 | const CFX_Matrix* pObj2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | FX_BOOL bStroke) { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 667 | CFX_Matrix path_matrix = pPathObj->m_Matrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | path_matrix.Concat(*pObj2Device); |
| 669 | if (bStroke) { |
tsepez | 85a65b3 | 2016-09-07 09:35:36 -0700 | [diff] [blame] | 670 | CFX_GraphState graphState = pPathObj->m_GraphState; |
| 671 | if (m_Options.m_Flags & RENDER_THINLINE) |
| 672 | graphState.SetLineWidth(0); |
tsepez | 7d2a8d9 | 2016-06-08 11:51:23 -0700 | [diff] [blame] | 673 | return m_pDevice->SetClip_PathStroke(pPathObj->m_Path.GetObject(), |
tsepez | 85a65b3 | 2016-09-07 09:35:36 -0700 | [diff] [blame] | 674 | &path_matrix, graphState.GetObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | } |
| 676 | int fill_mode = pPathObj->m_FillType; |
| 677 | if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) { |
| 678 | fill_mode |= FXFILL_NOPATHSMOOTH; |
| 679 | } |
tsepez | 7d2a8d9 | 2016-06-08 11:51:23 -0700 | [diff] [blame] | 680 | return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix, |
| 681 | fill_mode); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 682 | } |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 683 | FX_BOOL CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 684 | const CFX_Matrix* pObj2Device) { |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 685 | #if defined _SKIA_SUPPORT_ |
| 686 | DebugVerifyDeviceIsPreMultiplied(); |
| 687 | #endif |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 688 | int blend_type = pPageObj->m_GeneralState.GetBlendType(); |
| 689 | if (blend_type == FXDIB_BLEND_UNSUPPORTED) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 690 | return TRUE; |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 691 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | CPDF_Dictionary* pSMaskDict = |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 693 | ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | if (pSMaskDict) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 695 | if (pPageObj->IsImage() && |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 696 | pPageObj->AsImage()->GetImage()->GetDict()->KeyExist("SMask")) { |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 697 | pSMaskDict = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 700 | CPDF_Dictionary* pFormResource = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | FX_FLOAT group_alpha = 1.0f; |
| 702 | int Transparency = m_Transparency; |
| 703 | FX_BOOL bGroupTransparent = FALSE; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 704 | if (pPageObj->IsForm()) { |
| 705 | const CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 706 | group_alpha = pFormObj->m_GeneralState.GetFillAlpha(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | Transparency = pFormObj->m_pForm->m_Transparency; |
Lei Zhang | b0748bb | 2015-10-19 12:11:49 -0700 | [diff] [blame] | 708 | bGroupTransparent = !!(Transparency & PDFTRANS_ISOLATED); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | if (pFormObj->m_pForm->m_pFormDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 710 | pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
tsepez | 83d2351 | 2016-08-26 14:56:39 -0700 | [diff] [blame] | 713 | bool bTextClip = |
| 714 | (pPageObj->m_ClipPath && pPageObj->m_ClipPath.GetTextCount() && |
| 715 | m_pDevice->GetDeviceClass() == FXDC_DISPLAY && |
| 716 | !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)); |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 717 | if ((m_Options.m_Flags & RENDER_OVERPRINT) && pPageObj->IsImage() && |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 718 | pPageObj->m_GeneralState.GetFillOP() && |
| 719 | pPageObj->m_GeneralState.GetStrokeOP()) { |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 720 | CPDF_Document* pDocument = nullptr; |
| 721 | CPDF_Page* pPage = nullptr; |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 722 | if (m_pContext->GetPageCache()) { |
| 723 | pPage = m_pContext->GetPageCache()->GetPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 724 | pDocument = pPage->m_pDocument; |
| 725 | } else { |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 726 | pDocument = pPageObj->AsImage()->GetImage()->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | } |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 728 | CPDF_Dictionary* pPageResources = pPage ? pPage->m_pPageResources : nullptr; |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 729 | CPDF_Object* pCSObj = pPageObj->AsImage() |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 730 | ->GetImage() |
| 731 | ->GetStream() |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 732 | ->GetDict() |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 733 | ->GetDirectObjectFor("ColorSpace"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 734 | CPDF_ColorSpace* pColorSpace = |
| 735 | pDocument->LoadColorSpace(pCSObj, pPageResources); |
| 736 | if (pColorSpace) { |
| 737 | int format = pColorSpace->GetFamily(); |
| 738 | if (format == PDFCS_DEVICECMYK || format == PDFCS_SEPARATION || |
| 739 | format == PDFCS_DEVICEN) { |
| 740 | blend_type = FXDIB_BLEND_DARKEN; |
| 741 | } |
| 742 | pDocument->GetPageData()->ReleaseColorSpace(pCSObj); |
| 743 | } |
| 744 | } |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 745 | if (!pSMaskDict && group_alpha == 1.0f && blend_type == FXDIB_BLEND_NORMAL && |
| 746 | !bTextClip && !bGroupTransparent) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | return FALSE; |
| 748 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 749 | bool isolated = !!(Transparency & PDFTRANS_ISOLATED); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | if (m_bPrint) { |
| 751 | FX_BOOL bRet = FALSE; |
| 752 | int rendCaps = m_pDevice->GetRenderCaps(); |
| 753 | if (!((Transparency & PDFTRANS_ISOLATED) || pSMaskDict || bTextClip) && |
| 754 | (rendCaps & FXRC_BLEND_MODE)) { |
| 755 | int oldBlend = m_curBlend; |
| 756 | m_curBlend = blend_type; |
| 757 | bRet = DrawObjWithBlend(pPageObj, pObj2Device); |
| 758 | m_curBlend = oldBlend; |
| 759 | } |
| 760 | if (!bRet) { |
| 761 | DrawObjWithBackground(pPageObj, pObj2Device); |
| 762 | } |
| 763 | return TRUE; |
| 764 | } |
| 765 | FX_RECT rect = pPageObj->GetBBox(pObj2Device); |
| 766 | rect.Intersect(m_pDevice->GetClipBox()); |
| 767 | if (rect.IsEmpty()) { |
| 768 | return TRUE; |
| 769 | } |
| 770 | CFX_Matrix deviceCTM = m_pDevice->GetCTM(); |
| 771 | FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a); |
| 772 | FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d); |
| 773 | int width = FXSYS_round((FX_FLOAT)rect.Width() * scaleX); |
| 774 | int height = FXSYS_round((FX_FLOAT)rect.Height() * scaleY); |
| 775 | CFX_FxgeDevice bitmap_device; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 776 | std::unique_ptr<CFX_DIBitmap> oriDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 778 | oriDevice.reset(new CFX_DIBitmap); |
| 779 | if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | return TRUE; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 781 | m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 782 | } |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 783 | if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get())) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 785 | CFX_DIBitmap* bitmap = bitmap_device.GetBitmap(); |
| 786 | bitmap->Clear(0); |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 787 | CFX_Matrix new_matrix = *pObj2Device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 788 | new_matrix.TranslateI(-rect.left, -rect.top); |
| 789 | new_matrix.Scale(scaleX, scaleY); |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 790 | std::unique_ptr<CFX_DIBitmap> pTextMask; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 791 | if (bTextClip) { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 792 | pTextMask.reset(new CFX_DIBitmap); |
| 793 | if (!pTextMask->Create(width, height, FXDIB_8bppMask)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 794 | return TRUE; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 795 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | pTextMask->Clear(0); |
| 797 | CFX_FxgeDevice text_device; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 798 | text_device.Attach(pTextMask.get(), false, nullptr, false); |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 799 | for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 801 | if (!textobj) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | break; |
| 803 | } |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 804 | CFX_Matrix text_matrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 805 | textobj->GetTextMatrix(&text_matrix); |
| 806 | CPDF_TextRenderer::DrawTextPath( |
| 807 | &text_device, textobj->m_nChars, textobj->m_pCharCodes, |
tsepez | 5960143 | 2016-08-29 14:26:57 -0700 | [diff] [blame] | 808 | textobj->m_pCharPos, textobj->m_TextState.GetFont(), |
| 809 | textobj->m_TextState.GetFontSize(), &text_matrix, &new_matrix, |
tsepez | 7d2a8d9 | 2016-06-08 11:51:23 -0700 | [diff] [blame] | 810 | textobj->m_GraphState.GetObject(), (FX_ARGB)-1, 0, nullptr, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | CPDF_RenderStatus bitmap_render; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 814 | bitmap_render.Initialize(m_pContext, &bitmap_device, nullptr, m_pStopObj, |
| 815 | nullptr, nullptr, &m_Options, 0, m_bDropObjects, |
| 816 | pFormResource, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | bitmap_render.ProcessObjectNoClip(pPageObj, &new_matrix); |
| 818 | m_bStopped = bitmap_render.m_bStopped; |
| 819 | if (pSMaskDict) { |
tsepez | e106b50 | 2016-09-02 16:53:09 -0700 | [diff] [blame] | 820 | CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 821 | smask_matrix.Concat(*pObj2Device); |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 822 | std::unique_ptr<CFX_DIBSource> pSMaskSource( |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 823 | LoadSMask(pSMaskDict, &rect, &smask_matrix)); |
| 824 | if (pSMaskSource) |
| 825 | bitmap->MultiplyAlpha(pSMaskSource.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 826 | } |
| 827 | if (pTextMask) { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 828 | bitmap->MultiplyAlpha(pTextMask.get()); |
| 829 | pTextMask.reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | } |
caryclark | 36e258b | 2016-06-02 08:59:20 -0700 | [diff] [blame] | 831 | int32_t blitAlpha = 255; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 832 | if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) { |
caryclark | 36e258b | 2016-06-02 08:59:20 -0700 | [diff] [blame] | 833 | blitAlpha = (int32_t)(group_alpha * 255); |
| 834 | #ifndef _SKIA_SUPPORT_ |
| 835 | bitmap->MultiplyAlpha(blitAlpha); |
| 836 | blitAlpha = 255; |
| 837 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 838 | } |
| 839 | Transparency = m_Transparency; |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 840 | if (pPageObj->IsForm()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 841 | Transparency |= PDFTRANS_GROUP; |
| 842 | } |
caryclark | 36e258b | 2016-06-02 08:59:20 -0700 | [diff] [blame] | 843 | CompositeDIBitmap(bitmap, rect.left, rect.top, 0, blitAlpha, blend_type, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | Transparency); |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 845 | #if defined _SKIA_SUPPORT_ |
| 846 | DebugVerifyDeviceIsPreMultiplied(); |
| 847 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 848 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 849 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 850 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 851 | CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, |
| 852 | const FX_RECT& rect, |
| 853 | int& left, |
| 854 | int& top, |
| 855 | FX_BOOL bBackAlphaRequired) { |
| 856 | FX_RECT bbox = rect; |
| 857 | bbox.Intersect(m_pDevice->GetClipBox()); |
| 858 | left = bbox.left; |
| 859 | top = bbox.top; |
| 860 | CFX_Matrix deviceCTM = m_pDevice->GetCTM(); |
| 861 | FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a); |
| 862 | FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d); |
| 863 | int width = FXSYS_round(bbox.Width() * scaleX); |
| 864 | int height = FXSYS_round(bbox.Height() * scaleY); |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 865 | std::unique_ptr<CFX_DIBitmap> pBackdrop(new CFX_DIBitmap); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 866 | if (bBackAlphaRequired && !m_bDropObjects) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | pBackdrop->Create(width, height, FXDIB_Argb); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 868 | else |
| 869 | m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height); |
| 870 | |
| 871 | if (!pBackdrop->GetBuffer()) |
| 872 | return nullptr; |
| 873 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 874 | FX_BOOL bNeedDraw; |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 875 | if (pBackdrop->HasAlpha()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 877 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 879 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | if (!bNeedDraw) { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 881 | m_pDevice->GetDIBits(pBackdrop.get(), left, top); |
| 882 | return pBackdrop.release(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 883 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 884 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 885 | CFX_Matrix FinalMatrix = m_DeviceMatrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | FinalMatrix.TranslateI(-left, -top); |
| 887 | FinalMatrix.Scale(scaleX, scaleY); |
| 888 | pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff); |
| 889 | CFX_FxgeDevice device; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 890 | device.Attach(pBackdrop.get(), false, nullptr, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 892 | return pBackdrop.release(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 893 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 894 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer, |
| 896 | const CPDF_PageObject* pObj, |
| 897 | const CPDF_RenderOptions* pOptions, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 898 | CFX_Matrix* pFinalMatrix) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | CFX_FxgeDevice device; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 900 | device.Attach(pBuffer, false, nullptr, false); |
Tom Sepez | 76510e4 | 2015-06-03 16:19:04 -0700 | [diff] [blame] | 901 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | FX_RECT rect(0, 0, device.GetWidth(), device.GetHeight()); |
| 903 | device.FillRect(&rect, 0xffffffff); |
| 904 | Render(&device, pObj, pOptions, pFinalMatrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 906 | CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates( |
| 907 | const CPDF_GraphicStates* pSrcStates, |
| 908 | FX_BOOL bStroke) { |
tsepez | ca90b87 | 2016-08-31 10:41:00 -0700 | [diff] [blame] | 909 | if (!pSrcStates) |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 910 | return nullptr; |
tsepez | ca90b87 | 2016-08-31 10:41:00 -0700 | [diff] [blame] | 911 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 912 | CPDF_GraphicStates* pStates = new CPDF_GraphicStates; |
| 913 | pStates->CopyStates(*pSrcStates); |
tsepez | 987f3ee | 2016-08-26 15:17:12 -0700 | [diff] [blame] | 914 | const CPDF_Color* pObjColor = bStroke |
tsepez | adbd329 | 2016-08-29 14:07:28 -0700 | [diff] [blame] | 915 | ? pSrcStates->m_ColorState.GetStrokeColor() |
| 916 | : pSrcStates->m_ColorState.GetFillColor(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | if (!pObjColor->IsNull()) { |
tsepez | ca90b87 | 2016-08-31 10:41:00 -0700 | [diff] [blame] | 918 | pStates->m_ColorState.SetFillRGB( |
| 919 | bStroke ? pSrcStates->m_ColorState.GetStrokeRGB() |
| 920 | : pSrcStates->m_ColorState.GetFillRGB()); |
| 921 | pStates->m_ColorState.SetStrokeRGB(pStates->m_ColorState.GetFillRGB()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 922 | } |
| 923 | return pStates; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 924 | } |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 925 | |
Tom Sepez | 979ddd8 | 2015-12-17 13:41:13 -0800 | [diff] [blame] | 926 | CPDF_RenderContext::CPDF_RenderContext(CPDF_Page* pPage) |
| 927 | : m_pDocument(pPage->m_pDocument), |
| 928 | m_pPageResources(pPage->m_pPageResources), |
jaepark | 844c4b2 | 2016-07-26 12:35:22 -0700 | [diff] [blame] | 929 | m_pPageCache(pPage->GetRenderCache()) {} |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 930 | |
Tom Sepez | 979ddd8 | 2015-12-17 13:41:13 -0800 | [diff] [blame] | 931 | CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc, |
| 932 | CPDF_PageRenderCache* pPageCache) |
jaepark | 844c4b2 | 2016-07-26 12:35:22 -0700 | [diff] [blame] | 933 | : m_pDocument(pDoc), m_pPageResources(nullptr), m_pPageCache(pPageCache) {} |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 934 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 935 | CPDF_RenderContext::~CPDF_RenderContext() {} |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 936 | |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 937 | void CPDF_RenderContext::AppendLayer(CPDF_PageObjectHolder* pObjectHolder, |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 938 | const CFX_Matrix* pObject2Device) { |
| 939 | Layer* pLayer = m_Layers.AddSpace(); |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 940 | pLayer->m_pObjectHolder = pObjectHolder; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 941 | if (pObject2Device) { |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 942 | pLayer->m_Matrix = *pObject2Device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 943 | } else { |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 944 | pLayer->m_Matrix.SetIdentity(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 946 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, |
| 948 | const CPDF_RenderOptions* pOptions, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 949 | const CFX_Matrix* pLastMatrix) { |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 950 | Render(pDevice, nullptr, pOptions, pLastMatrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 951 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 952 | void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, |
| 953 | const CPDF_PageObject* pStopObj, |
| 954 | const CPDF_RenderOptions* pOptions, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 955 | const CFX_Matrix* pLastMatrix) { |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 956 | int count = m_Layers.GetSize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | for (int j = 0; j < count; j++) { |
| 958 | pDevice->SaveState(); |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 959 | Layer* pLayer = m_Layers.GetDataPtr(j); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | if (pLastMatrix) { |
Tom Sepez | 71fdc34 | 2016-01-22 12:06:32 -0800 | [diff] [blame] | 961 | CFX_Matrix FinalMatrix = pLayer->m_Matrix; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 962 | FinalMatrix.Concat(*pLastMatrix); |
| 963 | CPDF_RenderStatus status; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 964 | status.Initialize(this, pDevice, pLastMatrix, pStopObj, nullptr, nullptr, |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 965 | pOptions, pLayer->m_pObjectHolder->m_Transparency, |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 966 | FALSE, nullptr); |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 967 | status.RenderObjectList(pLayer->m_pObjectHolder, &FinalMatrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 968 | if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { |
| 969 | m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize); |
| 970 | } |
| 971 | if (status.m_bStopped) { |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 972 | pDevice->RestoreState(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 973 | break; |
| 974 | } |
| 975 | } else { |
| 976 | CPDF_RenderStatus status; |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 977 | status.Initialize(this, pDevice, nullptr, pStopObj, nullptr, nullptr, |
| 978 | pOptions, pLayer->m_pObjectHolder->m_Transparency, |
| 979 | FALSE, nullptr); |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 980 | status.RenderObjectList(pLayer->m_pObjectHolder, &pLayer->m_Matrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 981 | if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { |
| 982 | m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize); |
| 983 | } |
| 984 | if (status.m_bStopped) { |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 985 | pDevice->RestoreState(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 986 | break; |
| 987 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 988 | } |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 989 | pDevice->RestoreState(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 990 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 991 | } |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 992 | |
| 993 | CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( |
| 994 | CPDF_RenderContext* pContext, |
| 995 | CFX_RenderDevice* pDevice, |
| 996 | const CPDF_RenderOptions* pOptions) |
| 997 | : m_Status(Ready), |
| 998 | m_pContext(pContext), |
| 999 | m_pDevice(pDevice), |
| 1000 | m_pOptions(pOptions), |
| 1001 | m_LayerIndex(0), |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1002 | m_pCurrentLayer(nullptr) {} |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1003 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1004 | CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1005 | if (m_pRenderStatus) |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 1006 | m_pDevice->RestoreState(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1007 | } |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1008 | |
| 1009 | void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { |
| 1010 | if (!m_pContext || !m_pDevice || m_Status != Ready) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | m_Status = Failed; |
| 1012 | return; |
| 1013 | } |
| 1014 | m_Status = ToBeContinued; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | Continue(pPause); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1016 | } |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1017 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1019 | while (m_Status == ToBeContinued) { |
| 1020 | if (!m_pCurrentLayer) { |
| 1021 | if (m_LayerIndex >= m_pContext->CountLayers()) { |
| 1022 | m_Status = Done; |
| 1023 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1024 | } |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1025 | m_pCurrentLayer = m_pContext->GetLayer(m_LayerIndex); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1026 | m_LastObjectRendered = |
| 1027 | m_pCurrentLayer->m_pObjectHolder->GetPageObjectList()->end(); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1028 | m_pRenderStatus.reset(new CPDF_RenderStatus()); |
| 1029 | m_pRenderStatus->Initialize( |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 1030 | m_pContext, m_pDevice, nullptr, nullptr, nullptr, nullptr, m_pOptions, |
| 1031 | m_pCurrentLayer->m_pObjectHolder->m_Transparency, FALSE, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1032 | m_pDevice->SaveState(); |
Tom Sepez | d5e7b35 | 2016-02-29 11:24:29 -0800 | [diff] [blame] | 1033 | m_ClipRect = CFX_FloatRect(m_pDevice->GetClipBox()); |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1034 | CFX_Matrix device2object; |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1035 | device2object.SetReverse(m_pCurrentLayer->m_Matrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1036 | device2object.TransformRect(m_ClipRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1037 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1038 | CPDF_PageObjectList::iterator iter; |
| 1039 | CPDF_PageObjectList::iterator iterEnd = |
| 1040 | m_pCurrentLayer->m_pObjectHolder->GetPageObjectList()->end(); |
| 1041 | if (m_LastObjectRendered != iterEnd) { |
| 1042 | iter = m_LastObjectRendered; |
| 1043 | ++iter; |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1044 | } else { |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1045 | iter = m_pCurrentLayer->m_pObjectHolder->GetPageObjectList()->begin(); |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1046 | } |
| 1047 | int nObjsToGo = kStepLimit; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1048 | while (iter != iterEnd) { |
| 1049 | CPDF_PageObject* pCurObj = iter->get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | if (pCurObj && pCurObj->m_Left <= m_ClipRect.right && |
| 1051 | pCurObj->m_Right >= m_ClipRect.left && |
| 1052 | pCurObj->m_Bottom <= m_ClipRect.top && |
| 1053 | pCurObj->m_Top >= m_ClipRect.bottom) { |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1054 | if (m_pRenderStatus->ContinueSingleObject( |
| 1055 | pCurObj, &m_pCurrentLayer->m_Matrix, pPause)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1056 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1057 | } |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1058 | if (pCurObj->IsImage() && |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1059 | m_pRenderStatus->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1060 | m_pContext->GetPageCache()->CacheOptimization( |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 1061 | m_pRenderStatus->m_Options.m_dwLimitCacheSize); |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1062 | } |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1063 | if (pCurObj->IsForm() || pCurObj->IsShading()) { |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1064 | nObjsToGo = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1065 | } else { |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1066 | --nObjsToGo; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1067 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1068 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1069 | m_LastObjectRendered = iter; |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1070 | if (nObjsToGo == 0) { |
| 1071 | if (pPause && pPause->NeedToPauseNow()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | return; |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1073 | nObjsToGo = kStepLimit; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1074 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1075 | ++iter; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1076 | } |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 1077 | if (m_pCurrentLayer->m_pObjectHolder->IsParsed()) { |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1078 | m_pRenderStatus.reset(); |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 1079 | m_pDevice->RestoreState(false); |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1080 | m_pCurrentLayer = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1081 | m_LayerIndex++; |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1082 | if (pPause && pPause->NeedToPauseNow()) { |
| 1083 | return; |
| 1084 | } |
| 1085 | } else { |
Tom Sepez | 32c7081 | 2016-02-16 17:15:32 -0800 | [diff] [blame] | 1086 | m_pCurrentLayer->m_pObjectHolder->ContinueParse(pPause); |
| 1087 | if (!m_pCurrentLayer->m_pObjectHolder->IsParsed()) |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1088 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1089 | } |
| 1090 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1091 | } |
Tom Sepez | e6a5138 | 2016-02-16 09:17:44 -0800 | [diff] [blame] | 1092 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { |
| 1094 | if (!pObj) |
| 1095 | return nullptr; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1096 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1097 | auto it = m_TransferFuncMap.find(pObj); |
| 1098 | if (it != m_TransferFuncMap.end()) { |
| 1099 | CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; |
Tom Sepez | 3403db9 | 2015-06-15 16:58:19 -0700 | [diff] [blame] | 1100 | return pTransferCounter->AddRef(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 1103 | std::unique_ptr<CPDF_Function> pFuncs[3]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1104 | FX_BOOL bUniTransfer = TRUE; |
| 1105 | FX_BOOL bIdentity = TRUE; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 1106 | if (CPDF_Array* pArray = pObj->AsArray()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | bUniTransfer = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1108 | if (pArray->GetCount() < 3) |
| 1109 | return nullptr; |
| 1110 | |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 1111 | for (uint32_t i = 0; i < 3; ++i) { |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 1112 | pFuncs[2 - i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1113 | if (!pFuncs[2 - i]) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1114 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } else { |
thestig | 490d612 | 2016-05-23 14:56:02 -0700 | [diff] [blame] | 1117 | pFuncs[0] = CPDF_Function::Load(pObj); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1118 | if (!pFuncs[0]) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1119 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1120 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1121 | CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc(m_pPDFDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1122 | CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = |
| 1123 | new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer); |
| 1124 | m_TransferFuncMap[pObj] = pTransferCounter; |
| 1125 | static const int kMaxOutputs = 16; |
| 1126 | FX_FLOAT output[kMaxOutputs]; |
| 1127 | FXSYS_memset(output, 0, sizeof(output)); |
| 1128 | FX_FLOAT input; |
| 1129 | int noutput; |
| 1130 | for (int v = 0; v < 256; ++v) { |
| 1131 | input = (FX_FLOAT)v / 255.0f; |
| 1132 | if (bUniTransfer) { |
| 1133 | if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) |
| 1134 | pFuncs[0]->Call(&input, 1, output, noutput); |
| 1135 | int o = FXSYS_round(output[0] * 255); |
| 1136 | if (o != v) |
| 1137 | bIdentity = FALSE; |
| 1138 | for (int i = 0; i < 3; ++i) { |
| 1139 | pTransfer->m_Samples[i * 256 + v] = o; |
| 1140 | } |
| 1141 | } else { |
| 1142 | for (int i = 0; i < 3; ++i) { |
| 1143 | if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) { |
| 1144 | pFuncs[i]->Call(&input, 1, output, noutput); |
| 1145 | int o = FXSYS_round(output[0] * 255); |
| 1146 | if (o != v) |
| 1147 | bIdentity = FALSE; |
| 1148 | pTransfer->m_Samples[i * 256 + v] = o; |
| 1149 | } else { |
| 1150 | pTransfer->m_Samples[i * 256 + v] = v; |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1155 | |
| 1156 | pTransfer->m_bIdentity = bIdentity; |
| 1157 | return pTransferCounter->AddRef(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1158 | } |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1159 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1160 | void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { |
| 1161 | auto it = m_TransferFuncMap.find(pObj); |
| 1162 | if (it != m_TransferFuncMap.end()) |
| 1163 | it->second->RemoveRef(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1164 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1165 | |
| 1166 | CPDF_DeviceBuffer::CPDF_DeviceBuffer() |
| 1167 | : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} |
| 1168 | |
Dan Sinclair | 764ec51 | 2016-03-14 13:35:12 -0400 | [diff] [blame] | 1169 | CPDF_DeviceBuffer::~CPDF_DeviceBuffer() {} |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, |
| 1172 | CFX_RenderDevice* pDevice, |
| 1173 | FX_RECT* pRect, |
| 1174 | const CPDF_PageObject* pObj, |
| 1175 | int max_dpi) { |
| 1176 | m_pDevice = pDevice; |
| 1177 | m_pContext = pContext; |
| 1178 | m_Rect = *pRect; |
| 1179 | m_pObject = pObj; |
| 1180 | m_Matrix.TranslateI(-pRect->left, -pRect->top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1181 | #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1182 | int horz_size = pDevice->GetDeviceCaps(FXDC_HORZ_SIZE); |
| 1183 | int vert_size = pDevice->GetDeviceCaps(FXDC_VERT_SIZE); |
| 1184 | if (horz_size && vert_size && max_dpi) { |
| 1185 | int dpih = |
| 1186 | pDevice->GetDeviceCaps(FXDC_PIXEL_WIDTH) * 254 / (horz_size * 10); |
| 1187 | int dpiv = |
| 1188 | pDevice->GetDeviceCaps(FXDC_PIXEL_HEIGHT) * 254 / (vert_size * 10); |
| 1189 | if (dpih > max_dpi) { |
| 1190 | m_Matrix.Scale((FX_FLOAT)(max_dpi) / dpih, 1.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1191 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1192 | if (dpiv > max_dpi) { |
| 1193 | m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv); |
| 1194 | } |
| 1195 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1196 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1197 | CFX_Matrix ctm = m_pDevice->GetCTM(); |
| 1198 | FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); |
| 1199 | FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); |
| 1200 | m_Matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0); |
| 1201 | CFX_FloatRect rect(*pRect); |
| 1202 | m_Matrix.TransformRect(rect); |
thestig | ad5ac75 | 2016-08-09 12:09:22 -0700 | [diff] [blame] | 1203 | FX_RECT bitmap_rect = rect.GetOuterRect(); |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1204 | m_pBitmap.reset(new CFX_DIBitmap); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1205 | m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb); |
| 1206 | return TRUE; |
| 1207 | } |
| 1208 | void CPDF_DeviceBuffer::OutputToDevice() { |
| 1209 | if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) { |
| 1210 | if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1211 | m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1212 | } else { |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1213 | m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1214 | m_Rect.Width(), m_Rect.Height()); |
| 1215 | } |
| 1216 | } else { |
| 1217 | CFX_DIBitmap buffer; |
| 1218 | m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(), |
| 1219 | m_pBitmap->GetHeight()); |
thestig | 4997b22 | 2016-06-07 10:46:22 -0700 | [diff] [blame] | 1220 | m_pContext->GetBackground(&buffer, m_pObject, nullptr, &m_Matrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1221 | buffer.CompositeBitmap(0, 0, buffer.GetWidth(), buffer.GetHeight(), |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1222 | m_pBitmap.get(), 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1223 | m_pDevice->StretchDIBits(&buffer, m_Rect.left, m_Rect.top, m_Rect.Width(), |
| 1224 | m_Rect.Height()); |
| 1225 | } |
| 1226 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1227 | |
| 1228 | CPDF_ScaledRenderBuffer::CPDF_ScaledRenderBuffer() {} |
| 1229 | |
| 1230 | CPDF_ScaledRenderBuffer::~CPDF_ScaledRenderBuffer() {} |
| 1231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1232 | #define _FPDFAPI_IMAGESIZE_LIMIT_ (30 * 1024 * 1024) |
| 1233 | FX_BOOL CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext, |
| 1234 | CFX_RenderDevice* pDevice, |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1235 | const FX_RECT& pRect, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1236 | const CPDF_PageObject* pObj, |
| 1237 | const CPDF_RenderOptions* pOptions, |
| 1238 | int max_dpi) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1239 | m_pDevice = pDevice; |
| 1240 | if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) { |
| 1241 | return TRUE; |
| 1242 | } |
| 1243 | m_pContext = pContext; |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1244 | m_Rect = pRect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1245 | m_pObject = pObj; |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1246 | m_Matrix.TranslateI(-pRect.left, -pRect.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1247 | int horz_size = pDevice->GetDeviceCaps(FXDC_HORZ_SIZE); |
| 1248 | int vert_size = pDevice->GetDeviceCaps(FXDC_VERT_SIZE); |
| 1249 | if (horz_size && vert_size && max_dpi) { |
| 1250 | int dpih = |
| 1251 | pDevice->GetDeviceCaps(FXDC_PIXEL_WIDTH) * 254 / (horz_size * 10); |
| 1252 | int dpiv = |
| 1253 | pDevice->GetDeviceCaps(FXDC_PIXEL_HEIGHT) * 254 / (vert_size * 10); |
| 1254 | if (dpih > max_dpi) { |
| 1255 | m_Matrix.Scale((FX_FLOAT)(max_dpi) / dpih, 1.0f); |
| 1256 | } |
| 1257 | if (dpiv > max_dpi) { |
| 1258 | m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv); |
| 1259 | } |
| 1260 | } |
Lei Zhang | 5044cab | 2015-11-10 10:09:33 -0800 | [diff] [blame] | 1261 | m_pBitmapDevice.reset(new CFX_FxgeDevice); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1262 | FXDIB_Format dibFormat = FXDIB_Rgb; |
| 1263 | int32_t bpp = 24; |
| 1264 | if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_ALPHA_OUTPUT) { |
| 1265 | dibFormat = FXDIB_Argb; |
| 1266 | bpp = 32; |
| 1267 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1268 | while (1) { |
Tom Sepez | d5e7b35 | 2016-02-29 11:24:29 -0800 | [diff] [blame] | 1269 | CFX_FloatRect rect(pRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1270 | m_Matrix.TransformRect(rect); |
thestig | ad5ac75 | 2016-08-09 12:09:22 -0700 | [diff] [blame] | 1271 | FX_RECT bitmap_rect = rect.GetOuterRect(); |
Tom Sepez | d5e7b35 | 2016-02-29 11:24:29 -0800 | [diff] [blame] | 1272 | int32_t iWidth = bitmap_rect.Width(); |
| 1273 | int32_t iHeight = bitmap_rect.Height(); |
| 1274 | int32_t iPitch = (iWidth * bpp + 31) / 32 * 4; |
| 1275 | if (iWidth * iHeight < 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1276 | return FALSE; |
Tom Sepez | d5e7b35 | 2016-02-29 11:24:29 -0800 | [diff] [blame] | 1277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1278 | if (iPitch * iHeight <= _FPDFAPI_IMAGESIZE_LIMIT_ && |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 1279 | m_pBitmapDevice->Create(iWidth, iHeight, dibFormat, nullptr)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1280 | break; |
| 1281 | } |
| 1282 | m_Matrix.Scale(0.5f, 0.5f); |
| 1283 | } |
| 1284 | m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions, |
| 1285 | &m_Matrix); |
| 1286 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1287 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | void CPDF_ScaledRenderBuffer::OutputToDevice() { |
| 1289 | if (m_pBitmapDevice) { |
| 1290 | m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left, |
| 1291 | m_Rect.top, m_Rect.Width(), m_Rect.Height()); |
| 1292 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1293 | } |
caryclark | a27d49a | 2016-07-06 10:20:25 -0700 | [diff] [blame] | 1294 | |
| 1295 | #if defined _SKIA_SUPPORT_ |
| 1296 | void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const { |
| 1297 | m_pDevice->DebugVerifyBitmapIsPreMultiplied(); |
| 1298 | } |
| 1299 | #endif |