| 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 "render_int.h" | 7 #include "render_int.h" |
| 8 | 8 |
| 9 #include "core/include/fpdfapi/fpdf_pageobj.h" | 9 #include "core/include/fpdfapi/fpdf_pageobj.h" |
| 10 #include "core/include/fpdfapi/fpdf_render.h" | 10 #include "core/include/fpdfapi/fpdf_render.h" |
| 11 #include "core/include/fxge/fx_ge.h" | 11 #include "core/include/fxge/fx_ge.h" |
| 12 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 12 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 13 | 13 |
| 14 #define SHADING_STEPS 256 | 14 #define SHADING_STEPS 256 |
| 15 static void DrawAxialShading(CFX_DIBitmap* pBitmap, | 15 static void DrawAxialShading(CFX_DIBitmap* pBitmap, |
| 16 CFX_Matrix* pObject2Bitmap, | 16 CFX_Matrix* pObject2Bitmap, |
| 17 CPDF_Dictionary* pDict, | 17 CPDF_Dictionary* pDict, |
| 18 CPDF_Function** pFuncs, | 18 CPDF_Function** pFuncs, |
| 19 int nFuncs, | 19 int nFuncs, |
| 20 CPDF_ColorSpace* pCS, | 20 CPDF_ColorSpace* pCS, |
| 21 int alpha) { | 21 int alpha) { |
| 22 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 22 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 23 CPDF_Array* pCoords = pDict->GetArray("Coords"); | 23 CPDF_Array* pCoords = pDict->GetArray("Coords"); |
| 24 if (pCoords == NULL) { | 24 if (!pCoords) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 FX_FLOAT start_x = pCoords->GetNumber(0); | 27 FX_FLOAT start_x = pCoords->GetNumber(0); |
| 28 FX_FLOAT start_y = pCoords->GetNumber(1); | 28 FX_FLOAT start_y = pCoords->GetNumber(1); |
| 29 FX_FLOAT end_x = pCoords->GetNumber(2); | 29 FX_FLOAT end_x = pCoords->GetNumber(2); |
| 30 FX_FLOAT end_y = pCoords->GetNumber(3); | 30 FX_FLOAT end_y = pCoords->GetNumber(3); |
| 31 FX_FLOAT t_min = 0, t_max = 1.0f; | 31 FX_FLOAT t_min = 0, t_max = 1.0f; |
| 32 CPDF_Array* pArray = pDict->GetArray("Domain"); | 32 CPDF_Array* pArray = pDict->GetArray("Domain"); |
| 33 if (pArray) { | 33 if (pArray) { |
| 34 t_min = pArray->GetNumber(0); | 34 t_min = pArray->GetNumber(0); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 static void DrawRadialShading(CFX_DIBitmap* pBitmap, | 106 static void DrawRadialShading(CFX_DIBitmap* pBitmap, |
| 107 CFX_Matrix* pObject2Bitmap, | 107 CFX_Matrix* pObject2Bitmap, |
| 108 CPDF_Dictionary* pDict, | 108 CPDF_Dictionary* pDict, |
| 109 CPDF_Function** pFuncs, | 109 CPDF_Function** pFuncs, |
| 110 int nFuncs, | 110 int nFuncs, |
| 111 CPDF_ColorSpace* pCS, | 111 CPDF_ColorSpace* pCS, |
| 112 int alpha) { | 112 int alpha) { |
| 113 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 113 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 114 CPDF_Array* pCoords = pDict->GetArray("Coords"); | 114 CPDF_Array* pCoords = pDict->GetArray("Coords"); |
| 115 if (pCoords == NULL) { | 115 if (!pCoords) { |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 FX_FLOAT start_x = pCoords->GetNumber(0); | 118 FX_FLOAT start_x = pCoords->GetNumber(0); |
| 119 FX_FLOAT start_y = pCoords->GetNumber(1); | 119 FX_FLOAT start_y = pCoords->GetNumber(1); |
| 120 FX_FLOAT start_r = pCoords->GetNumber(2); | 120 FX_FLOAT start_r = pCoords->GetNumber(2); |
| 121 FX_FLOAT end_x = pCoords->GetNumber(3); | 121 FX_FLOAT end_x = pCoords->GetNumber(3); |
| 122 FX_FLOAT end_y = pCoords->GetNumber(4); | 122 FX_FLOAT end_y = pCoords->GetNumber(4); |
| 123 FX_FLOAT end_r = pCoords->GetNumber(5); | 123 FX_FLOAT end_r = pCoords->GetNumber(5); |
| 124 CFX_Matrix matrix; | 124 CFX_Matrix matrix; |
| 125 matrix.SetReverse(*pObject2Bitmap); | 125 matrix.SetReverse(*pObject2Bitmap); |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 } | 827 } |
| 828 void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, | 828 void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, |
| 829 CFX_Matrix* pMatrix, | 829 CFX_Matrix* pMatrix, |
| 830 FX_RECT& clip_rect, | 830 FX_RECT& clip_rect, |
| 831 int alpha, | 831 int alpha, |
| 832 FX_BOOL bAlphaMode) { | 832 FX_BOOL bAlphaMode) { |
| 833 CPDF_Function** pFuncs = pPattern->m_pFunctions; | 833 CPDF_Function** pFuncs = pPattern->m_pFunctions; |
| 834 int nFuncs = pPattern->m_nFuncs; | 834 int nFuncs = pPattern->m_nFuncs; |
| 835 CPDF_Dictionary* pDict = pPattern->m_pShadingObj->GetDict(); | 835 CPDF_Dictionary* pDict = pPattern->m_pShadingObj->GetDict(); |
| 836 CPDF_ColorSpace* pColorSpace = pPattern->m_pCS; | 836 CPDF_ColorSpace* pColorSpace = pPattern->m_pCS; |
| 837 if (pColorSpace == NULL) { | 837 if (!pColorSpace) { |
| 838 return; | 838 return; |
| 839 } | 839 } |
| 840 FX_ARGB background = 0; | 840 FX_ARGB background = 0; |
| 841 if (!pPattern->m_bShadingObj && | 841 if (!pPattern->m_bShadingObj && |
| 842 pPattern->m_pShadingObj->GetDict()->KeyExist("Background")) { | 842 pPattern->m_pShadingObj->GetDict()->KeyExist("Background")) { |
| 843 CPDF_Array* pBackColor = | 843 CPDF_Array* pBackColor = |
| 844 pPattern->m_pShadingObj->GetDict()->GetArray("Background"); | 844 pPattern->m_pShadingObj->GetDict()->GetArray("Background"); |
| 845 if (pBackColor && | 845 if (pBackColor && |
| 846 pBackColor->GetCount() >= (FX_DWORD)pColorSpace->CountComponents()) { | 846 pBackColor->GetCount() >= (FX_DWORD)pColorSpace->CountComponents()) { |
| 847 CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); | 847 CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); |
| 848 for (int i = 0; i < pColorSpace->CountComponents(); i++) { | 848 for (int i = 0; i < pColorSpace->CountComponents(); i++) { |
| 849 comps[i] = pBackColor->GetNumber(i); | 849 comps[i] = pBackColor->GetNumber(i); |
| 850 } | 850 } |
| 851 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; | 851 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; |
| 852 pColorSpace->GetRGB(comps, R, G, B); | 852 pColorSpace->GetRGB(comps, R, G, B); |
| 853 background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), | 853 background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), |
| 854 (int32_t)(B * 255)); | 854 (int32_t)(B * 255)); |
| 855 } | 855 } |
| 856 } | 856 } |
| 857 if (pDict->KeyExist("BBox")) { | 857 if (pDict->KeyExist("BBox")) { |
| 858 CFX_FloatRect rect = pDict->GetRect("BBox"); | 858 CFX_FloatRect rect = pDict->GetRect("BBox"); |
| 859 rect.Transform(pMatrix); | 859 rect.Transform(pMatrix); |
| 860 clip_rect.Intersect(rect.GetOutterRect()); | 860 clip_rect.Intersect(rect.GetOutterRect()); |
| 861 } | 861 } |
| 862 CPDF_DeviceBuffer buffer; | 862 CPDF_DeviceBuffer buffer; |
| 863 buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); | 863 buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); |
| 864 CFX_Matrix FinalMatrix = *pMatrix; | 864 CFX_Matrix FinalMatrix = *pMatrix; |
| 865 FinalMatrix.Concat(*buffer.GetMatrix()); | 865 FinalMatrix.Concat(*buffer.GetMatrix()); |
| 866 CFX_DIBitmap* pBitmap = buffer.GetBitmap(); | 866 CFX_DIBitmap* pBitmap = buffer.GetBitmap(); |
| 867 if (pBitmap->GetBuffer() == NULL) { | 867 if (!pBitmap->GetBuffer()) { |
| 868 return; | 868 return; |
| 869 } | 869 } |
| 870 pBitmap->Clear(background); | 870 pBitmap->Clear(background); |
| 871 int fill_mode = m_Options.m_Flags; | 871 int fill_mode = m_Options.m_Flags; |
| 872 switch (pPattern->m_ShadingType) { | 872 switch (pPattern->m_ShadingType) { |
| 873 case kInvalidShading: | 873 case kInvalidShading: |
| 874 case kMaxShading: | 874 case kMaxShading: |
| 875 return; | 875 return; |
| 876 case kFunctionBasedShading: | 876 case kFunctionBasedShading: |
| 877 DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, | 877 DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 CFX_DIBitmap* pEnlargedBitmap = | 1114 CFX_DIBitmap* pEnlargedBitmap = |
| 1115 DrawPatternBitmap(m_pContext->m_pDocument, m_pContext->m_pPageCache, | 1115 DrawPatternBitmap(m_pContext->m_pDocument, m_pContext->m_pPageCache, |
| 1116 pPattern, pObj2Device, 8, 8, m_Options.m_Flags); | 1116 pPattern, pObj2Device, 8, 8, m_Options.m_Flags); |
| 1117 pPatternBitmap = pEnlargedBitmap->StretchTo(width, height); | 1117 pPatternBitmap = pEnlargedBitmap->StretchTo(width, height); |
| 1118 delete pEnlargedBitmap; | 1118 delete pEnlargedBitmap; |
| 1119 } else { | 1119 } else { |
| 1120 pPatternBitmap = DrawPatternBitmap( | 1120 pPatternBitmap = DrawPatternBitmap( |
| 1121 m_pContext->m_pDocument, m_pContext->m_pPageCache, pPattern, | 1121 m_pContext->m_pDocument, m_pContext->m_pPageCache, pPattern, |
| 1122 pObj2Device, width, height, m_Options.m_Flags); | 1122 pObj2Device, width, height, m_Options.m_Flags); |
| 1123 } | 1123 } |
| 1124 if (pPatternBitmap == NULL) { | 1124 if (!pPatternBitmap) { |
| 1125 m_pDevice->RestoreState(); | 1125 m_pDevice->RestoreState(); |
| 1126 return; | 1126 return; |
| 1127 } | 1127 } |
| 1128 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) { | 1128 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) { |
| 1129 pPatternBitmap->ConvertColorScale(m_Options.m_ForeColor, | 1129 pPatternBitmap->ConvertColorScale(m_Options.m_ForeColor, |
| 1130 m_Options.m_BackColor); | 1130 m_Options.m_BackColor); |
| 1131 } | 1131 } |
| 1132 FX_ARGB fill_argb = GetFillArgb(pPageObj); | 1132 FX_ARGB fill_argb = GetFillArgb(pPageObj); |
| 1133 int clip_width = clip_box.right - clip_box.left; | 1133 int clip_width = clip_box.right - clip_box.left; |
| 1134 int clip_height = clip_box.bottom - clip_box.top; | 1134 int clip_height = clip_box.bottom - clip_box.top; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255, | 1178 CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255, |
| 1179 FXDIB_BLEND_NORMAL, FALSE); | 1179 FXDIB_BLEND_NORMAL, FALSE); |
| 1180 m_pDevice->RestoreState(); | 1180 m_pDevice->RestoreState(); |
| 1181 delete pPatternBitmap; | 1181 delete pPatternBitmap; |
| 1182 } | 1182 } |
| 1183 void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, | 1183 void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, |
| 1184 const CFX_Matrix* pObj2Device, | 1184 const CFX_Matrix* pObj2Device, |
| 1185 CPDF_Color* pColor, | 1185 CPDF_Color* pColor, |
| 1186 FX_BOOL bStroke) { | 1186 FX_BOOL bStroke) { |
| 1187 CPDF_Pattern* pattern = pColor->GetPattern(); | 1187 CPDF_Pattern* pattern = pColor->GetPattern(); |
| 1188 if (pattern == NULL) { | 1188 if (!pattern) { |
| 1189 return; | 1189 return; |
| 1190 } | 1190 } |
| 1191 if (pattern->m_PatternType == PATTERN_TILING) { | 1191 if (pattern->m_PatternType == PATTERN_TILING) { |
| 1192 DrawTilingPattern((CPDF_TilingPattern*)pattern, pPathObj, pObj2Device, | 1192 DrawTilingPattern((CPDF_TilingPattern*)pattern, pPathObj, pObj2Device, |
| 1193 bStroke); | 1193 bStroke); |
| 1194 } else { | 1194 } else { |
| 1195 DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device, | 1195 DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device, |
| 1196 bStroke); | 1196 bStroke); |
| 1197 } | 1197 } |
| 1198 } | 1198 } |
| 1199 void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, | 1199 void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, |
| 1200 const CFX_Matrix* pObj2Device, | 1200 const CFX_Matrix* pObj2Device, |
| 1201 int& filltype, | 1201 int& filltype, |
| 1202 FX_BOOL& bStroke) { | 1202 FX_BOOL& bStroke) { |
| 1203 if (filltype) { | 1203 if (filltype) { |
| 1204 CPDF_Color& FillColor = *pPathObj->m_ColorState.GetFillColor(); | 1204 CPDF_Color& FillColor = *pPathObj->m_ColorState.GetFillColor(); |
| 1205 if (FillColor.m_pCS && FillColor.m_pCS->GetFamily() == PDFCS_PATTERN) { | 1205 if (FillColor.m_pCS && FillColor.m_pCS->GetFamily() == PDFCS_PATTERN) { |
| 1206 DrawPathWithPattern(pPathObj, pObj2Device, &FillColor, FALSE); | 1206 DrawPathWithPattern(pPathObj, pObj2Device, &FillColor, FALSE); |
| 1207 filltype = 0; | 1207 filltype = 0; |
| 1208 } | 1208 } |
| 1209 } | 1209 } |
| 1210 if (bStroke) { | 1210 if (bStroke) { |
| 1211 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); | 1211 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); |
| 1212 if (StrokeColor.m_pCS && StrokeColor.m_pCS->GetFamily() == PDFCS_PATTERN) { | 1212 if (StrokeColor.m_pCS && StrokeColor.m_pCS->GetFamily() == PDFCS_PATTERN) { |
| 1213 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); | 1213 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); |
| 1214 bStroke = FALSE; | 1214 bStroke = FALSE; |
| 1215 } | 1215 } |
| 1216 } | 1216 } |
| 1217 } | 1217 } |
| OLD | NEW |