| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 #define SHADING_STEPS 256 | 41 #define SHADING_STEPS 256 |
| 42 void DrawAxialShading(CFX_DIBitmap* pBitmap, | 42 void DrawAxialShading(CFX_DIBitmap* pBitmap, |
| 43 CFX_Matrix* pObject2Bitmap, | 43 CFX_Matrix* pObject2Bitmap, |
| 44 CPDF_Dictionary* pDict, | 44 CPDF_Dictionary* pDict, |
| 45 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 45 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 46 CPDF_ColorSpace* pCS, | 46 CPDF_ColorSpace* pCS, |
| 47 int alpha) { | 47 int alpha) { |
| 48 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 48 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 49 CPDF_Array* pCoords = pDict->GetArrayBy("Coords"); | 49 CPDF_Array* pCoords = pDict->GetArrayFor("Coords"); |
| 50 if (!pCoords) { | 50 if (!pCoords) { |
| 51 return; | 51 return; |
| 52 } | 52 } |
| 53 FX_FLOAT start_x = pCoords->GetNumberAt(0); | 53 FX_FLOAT start_x = pCoords->GetNumberAt(0); |
| 54 FX_FLOAT start_y = pCoords->GetNumberAt(1); | 54 FX_FLOAT start_y = pCoords->GetNumberAt(1); |
| 55 FX_FLOAT end_x = pCoords->GetNumberAt(2); | 55 FX_FLOAT end_x = pCoords->GetNumberAt(2); |
| 56 FX_FLOAT end_y = pCoords->GetNumberAt(3); | 56 FX_FLOAT end_y = pCoords->GetNumberAt(3); |
| 57 FX_FLOAT t_min = 0, t_max = 1.0f; | 57 FX_FLOAT t_min = 0, t_max = 1.0f; |
| 58 CPDF_Array* pArray = pDict->GetArrayBy("Domain"); | 58 CPDF_Array* pArray = pDict->GetArrayFor("Domain"); |
| 59 if (pArray) { | 59 if (pArray) { |
| 60 t_min = pArray->GetNumberAt(0); | 60 t_min = pArray->GetNumberAt(0); |
| 61 t_max = pArray->GetNumberAt(1); | 61 t_max = pArray->GetNumberAt(1); |
| 62 } | 62 } |
| 63 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; | 63 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; |
| 64 pArray = pDict->GetArrayBy("Extend"); | 64 pArray = pDict->GetArrayFor("Extend"); |
| 65 if (pArray) { | 65 if (pArray) { |
| 66 bStartExtend = pArray->GetIntegerAt(0); | 66 bStartExtend = pArray->GetIntegerAt(0); |
| 67 bEndExtend = pArray->GetIntegerAt(1); | 67 bEndExtend = pArray->GetIntegerAt(1); |
| 68 } | 68 } |
| 69 int width = pBitmap->GetWidth(); | 69 int width = pBitmap->GetWidth(); |
| 70 int height = pBitmap->GetHeight(); | 70 int height = pBitmap->GetHeight(); |
| 71 FX_FLOAT x_span = end_x - start_x; | 71 FX_FLOAT x_span = end_x - start_x; |
| 72 FX_FLOAT y_span = end_y - start_y; | 72 FX_FLOAT y_span = end_y - start_y; |
| 73 FX_FLOAT axis_len_square = (x_span * x_span) + (y_span * y_span); | 73 FX_FLOAT axis_len_square = (x_span * x_span) + (y_span * y_span); |
| 74 CFX_Matrix matrix; | 74 CFX_Matrix matrix; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void DrawRadialShading(CFX_DIBitmap* pBitmap, | 123 void DrawRadialShading(CFX_DIBitmap* pBitmap, |
| 124 CFX_Matrix* pObject2Bitmap, | 124 CFX_Matrix* pObject2Bitmap, |
| 125 CPDF_Dictionary* pDict, | 125 CPDF_Dictionary* pDict, |
| 126 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 126 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 127 CPDF_ColorSpace* pCS, | 127 CPDF_ColorSpace* pCS, |
| 128 int alpha) { | 128 int alpha) { |
| 129 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 129 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 130 CPDF_Array* pCoords = pDict->GetArrayBy("Coords"); | 130 CPDF_Array* pCoords = pDict->GetArrayFor("Coords"); |
| 131 if (!pCoords) { | 131 if (!pCoords) { |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 FX_FLOAT start_x = pCoords->GetNumberAt(0); | 134 FX_FLOAT start_x = pCoords->GetNumberAt(0); |
| 135 FX_FLOAT start_y = pCoords->GetNumberAt(1); | 135 FX_FLOAT start_y = pCoords->GetNumberAt(1); |
| 136 FX_FLOAT start_r = pCoords->GetNumberAt(2); | 136 FX_FLOAT start_r = pCoords->GetNumberAt(2); |
| 137 FX_FLOAT end_x = pCoords->GetNumberAt(3); | 137 FX_FLOAT end_x = pCoords->GetNumberAt(3); |
| 138 FX_FLOAT end_y = pCoords->GetNumberAt(4); | 138 FX_FLOAT end_y = pCoords->GetNumberAt(4); |
| 139 FX_FLOAT end_r = pCoords->GetNumberAt(5); | 139 FX_FLOAT end_r = pCoords->GetNumberAt(5); |
| 140 CFX_Matrix matrix; | 140 CFX_Matrix matrix; |
| 141 matrix.SetReverse(*pObject2Bitmap); | 141 matrix.SetReverse(*pObject2Bitmap); |
| 142 FX_FLOAT t_min = 0, t_max = 1.0f; | 142 FX_FLOAT t_min = 0, t_max = 1.0f; |
| 143 CPDF_Array* pArray = pDict->GetArrayBy("Domain"); | 143 CPDF_Array* pArray = pDict->GetArrayFor("Domain"); |
| 144 if (pArray) { | 144 if (pArray) { |
| 145 t_min = pArray->GetNumberAt(0); | 145 t_min = pArray->GetNumberAt(0); |
| 146 t_max = pArray->GetNumberAt(1); | 146 t_max = pArray->GetNumberAt(1); |
| 147 } | 147 } |
| 148 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; | 148 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; |
| 149 pArray = pDict->GetArrayBy("Extend"); | 149 pArray = pDict->GetArrayFor("Extend"); |
| 150 if (pArray) { | 150 if (pArray) { |
| 151 bStartExtend = pArray->GetIntegerAt(0); | 151 bStartExtend = pArray->GetIntegerAt(0); |
| 152 bEndExtend = pArray->GetIntegerAt(1); | 152 bEndExtend = pArray->GetIntegerAt(1); |
| 153 } | 153 } |
| 154 uint32_t total_results = | 154 uint32_t total_results = |
| 155 std::max(CountOutputs(funcs), pCS->CountComponents()); | 155 std::max(CountOutputs(funcs), pCS->CountComponents()); |
| 156 CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); | 156 CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); |
| 157 FX_FLOAT* pResults = result_array; | 157 FX_FLOAT* pResults = result_array; |
| 158 FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); | 158 FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); |
| 159 uint32_t rgb_array[SHADING_STEPS]; | 159 uint32_t rgb_array[SHADING_STEPS]; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 void DrawFuncShading(CFX_DIBitmap* pBitmap, | 252 void DrawFuncShading(CFX_DIBitmap* pBitmap, |
| 253 CFX_Matrix* pObject2Bitmap, | 253 CFX_Matrix* pObject2Bitmap, |
| 254 CPDF_Dictionary* pDict, | 254 CPDF_Dictionary* pDict, |
| 255 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 255 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 256 CPDF_ColorSpace* pCS, | 256 CPDF_ColorSpace* pCS, |
| 257 int alpha) { | 257 int alpha) { |
| 258 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 258 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 259 CPDF_Array* pDomain = pDict->GetArrayBy("Domain"); | 259 CPDF_Array* pDomain = pDict->GetArrayFor("Domain"); |
| 260 FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f; | 260 FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f; |
| 261 if (pDomain) { | 261 if (pDomain) { |
| 262 xmin = pDomain->GetNumberAt(0); | 262 xmin = pDomain->GetNumberAt(0); |
| 263 xmax = pDomain->GetNumberAt(1); | 263 xmax = pDomain->GetNumberAt(1); |
| 264 ymin = pDomain->GetNumberAt(2); | 264 ymin = pDomain->GetNumberAt(2); |
| 265 ymax = pDomain->GetNumberAt(3); | 265 ymax = pDomain->GetNumberAt(3); |
| 266 } | 266 } |
| 267 CFX_Matrix mtDomain2Target = pDict->GetMatrixBy("Matrix"); | 267 CFX_Matrix mtDomain2Target = pDict->GetMatrixFor("Matrix"); |
| 268 CFX_Matrix matrix, reverse_matrix; | 268 CFX_Matrix matrix, reverse_matrix; |
| 269 matrix.SetReverse(*pObject2Bitmap); | 269 matrix.SetReverse(*pObject2Bitmap); |
| 270 reverse_matrix.SetReverse(mtDomain2Target); | 270 reverse_matrix.SetReverse(mtDomain2Target); |
| 271 matrix.Concat(reverse_matrix); | 271 matrix.Concat(reverse_matrix); |
| 272 int width = pBitmap->GetWidth(); | 272 int width = pBitmap->GetWidth(); |
| 273 int height = pBitmap->GetHeight(); | 273 int height = pBitmap->GetHeight(); |
| 274 int pitch = pBitmap->GetPitch(); | 274 int pitch = pBitmap->GetPitch(); |
| 275 uint32_t total_results = | 275 uint32_t total_results = |
| 276 std::max(CountOutputs(funcs), pCS->CountComponents()); | 276 std::max(CountOutputs(funcs), pCS->CountComponents()); |
| 277 CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); | 277 CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 443 |
| 444 void DrawLatticeGouraudShading( | 444 void DrawLatticeGouraudShading( |
| 445 CFX_DIBitmap* pBitmap, | 445 CFX_DIBitmap* pBitmap, |
| 446 CFX_Matrix* pObject2Bitmap, | 446 CFX_Matrix* pObject2Bitmap, |
| 447 CPDF_Stream* pShadingStream, | 447 CPDF_Stream* pShadingStream, |
| 448 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 448 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 449 CPDF_ColorSpace* pCS, | 449 CPDF_ColorSpace* pCS, |
| 450 int alpha) { | 450 int alpha) { |
| 451 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 451 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 452 | 452 |
| 453 int row_verts = pShadingStream->GetDict()->GetIntegerBy("VerticesPerRow"); | 453 int row_verts = pShadingStream->GetDict()->GetIntegerFor("VerticesPerRow"); |
| 454 if (row_verts < 2) | 454 if (row_verts < 2) |
| 455 return; | 455 return; |
| 456 | 456 |
| 457 CPDF_MeshStream stream(kLatticeFormGouraudTriangleMeshShading, funcs, | 457 CPDF_MeshStream stream(kLatticeFormGouraudTriangleMeshShading, funcs, |
| 458 pShadingStream, pCS); | 458 pShadingStream, pCS); |
| 459 if (!stream.Load()) | 459 if (!stream.Load()) |
| 460 return; | 460 return; |
| 461 | 461 |
| 462 std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( | 462 std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( |
| 463 FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); | 463 FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 int alpha, | 848 int alpha, |
| 849 FX_BOOL bAlphaMode) { | 849 FX_BOOL bAlphaMode) { |
| 850 const auto& funcs = pPattern->GetFuncs(); | 850 const auto& funcs = pPattern->GetFuncs(); |
| 851 CPDF_Dictionary* pDict = pPattern->GetShadingObject()->GetDict(); | 851 CPDF_Dictionary* pDict = pPattern->GetShadingObject()->GetDict(); |
| 852 CPDF_ColorSpace* pColorSpace = pPattern->GetCS(); | 852 CPDF_ColorSpace* pColorSpace = pPattern->GetCS(); |
| 853 if (!pColorSpace) | 853 if (!pColorSpace) |
| 854 return; | 854 return; |
| 855 | 855 |
| 856 FX_ARGB background = 0; | 856 FX_ARGB background = 0; |
| 857 if (!pPattern->IsShadingObject() && pDict->KeyExist("Background")) { | 857 if (!pPattern->IsShadingObject() && pDict->KeyExist("Background")) { |
| 858 CPDF_Array* pBackColor = pDict->GetArrayBy("Background"); | 858 CPDF_Array* pBackColor = pDict->GetArrayFor("Background"); |
| 859 if (pBackColor && | 859 if (pBackColor && |
| 860 pBackColor->GetCount() >= pColorSpace->CountComponents()) { | 860 pBackColor->GetCount() >= pColorSpace->CountComponents()) { |
| 861 CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); | 861 CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); |
| 862 for (uint32_t i = 0; i < pColorSpace->CountComponents(); i++) | 862 for (uint32_t i = 0; i < pColorSpace->CountComponents(); i++) |
| 863 comps[i] = pBackColor->GetNumberAt(i); | 863 comps[i] = pBackColor->GetNumberAt(i); |
| 864 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; | 864 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; |
| 865 pColorSpace->GetRGB(comps, R, G, B); | 865 pColorSpace->GetRGB(comps, R, G, B); |
| 866 background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), | 866 background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), |
| 867 (int32_t)(B * 255)); | 867 (int32_t)(B * 255)); |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 if (pDict->KeyExist("BBox")) { | 870 if (pDict->KeyExist("BBox")) { |
| 871 CFX_FloatRect rect = pDict->GetRectBy("BBox"); | 871 CFX_FloatRect rect = pDict->GetRectFor("BBox"); |
| 872 rect.Transform(pMatrix); | 872 rect.Transform(pMatrix); |
| 873 clip_rect.Intersect(rect.GetOuterRect()); | 873 clip_rect.Intersect(rect.GetOuterRect()); |
| 874 } | 874 } |
| 875 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING && | 875 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING && |
| 876 m_pDevice->GetDeviceDriver()->DrawShading(pPattern, pMatrix, clip_rect, | 876 m_pDevice->GetDeviceDriver()->DrawShading(pPattern, pMatrix, clip_rect, |
| 877 alpha, bAlphaMode)) { | 877 alpha, bAlphaMode)) { |
| 878 return; | 878 return; |
| 879 } | 879 } |
| 880 CPDF_DeviceBuffer buffer; | 880 CPDF_DeviceBuffer buffer; |
| 881 buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); | 881 buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 pPattern->y_step()); | 1048 pPattern->y_step()); |
| 1049 | 1049 |
| 1050 if (width > clip_box.Width() || height > clip_box.Height() || | 1050 if (width > clip_box.Width() || height > clip_box.Height() || |
| 1051 width * height > clip_box.Width() * clip_box.Height()) { | 1051 width * height > clip_box.Width() * clip_box.Height()) { |
| 1052 CPDF_GraphicStates* pStates = nullptr; | 1052 CPDF_GraphicStates* pStates = nullptr; |
| 1053 if (!pPattern->colored()) | 1053 if (!pPattern->colored()) |
| 1054 pStates = CloneObjStates(pPageObj, bStroke); | 1054 pStates = CloneObjStates(pPageObj, bStroke); |
| 1055 | 1055 |
| 1056 CPDF_Dictionary* pFormResource = nullptr; | 1056 CPDF_Dictionary* pFormResource = nullptr; |
| 1057 if (pPattern->form()->m_pFormDict) | 1057 if (pPattern->form()->m_pFormDict) |
| 1058 pFormResource = pPattern->form()->m_pFormDict->GetDictBy("Resources"); | 1058 pFormResource = pPattern->form()->m_pFormDict->GetDictFor("Resources"); |
| 1059 | 1059 |
| 1060 for (int col = min_col; col <= max_col; col++) | 1060 for (int col = min_col; col <= max_col; col++) |
| 1061 for (int row = min_row; row <= max_row; row++) { | 1061 for (int row = min_row; row <= max_row; row++) { |
| 1062 FX_FLOAT orig_x, orig_y; | 1062 FX_FLOAT orig_x, orig_y; |
| 1063 orig_x = col * pPattern->x_step(); | 1063 orig_x = col * pPattern->x_step(); |
| 1064 orig_y = row * pPattern->y_step(); | 1064 orig_y = row * pPattern->y_step(); |
| 1065 mtPattern2Device.Transform(orig_x, orig_y); | 1065 mtPattern2Device.Transform(orig_x, orig_y); |
| 1066 CFX_Matrix matrix = *pObj2Device; | 1066 CFX_Matrix matrix = *pObj2Device; |
| 1067 matrix.Translate(orig_x - mtPattern2Device.e, | 1067 matrix.Translate(orig_x - mtPattern2Device.e, |
| 1068 orig_y - mtPattern2Device.f); | 1068 orig_y - mtPattern2Device.f); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 if (bStroke) { | 1208 if (bStroke) { |
| 1209 const CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); | 1209 const CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); |
| 1210 if (StrokeColor.IsPattern()) { | 1210 if (StrokeColor.IsPattern()) { |
| 1211 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); | 1211 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); |
| 1212 bStroke = FALSE; | 1212 bStroke = FALSE; |
| 1213 } | 1213 } |
| 1214 } | 1214 } |
| 1215 } | 1215 } |
| OLD | NEW |