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