Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp

Issue 1513363002: Remove CFX_AffineMatrix/CPDF_Matrix (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_AffineMatrix* 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(FX_BSTRC("Coords")); 23 CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords"));
24 if (pCoords == NULL) { 24 if (pCoords == NULL) {
25 return; 25 return;
26 } 26 }
(...skipping 12 matching lines...) Expand all
39 if (pArray) { 39 if (pArray) {
40 bStartExtend = pArray->GetInteger(0); 40 bStartExtend = pArray->GetInteger(0);
41 bEndExtend = pArray->GetInteger(1); 41 bEndExtend = pArray->GetInteger(1);
42 } 42 }
43 int width = pBitmap->GetWidth(); 43 int width = pBitmap->GetWidth();
44 int height = pBitmap->GetHeight(); 44 int height = pBitmap->GetHeight();
45 FX_FLOAT x_span = end_x - start_x; 45 FX_FLOAT x_span = end_x - start_x;
46 FX_FLOAT y_span = end_y - start_y; 46 FX_FLOAT y_span = end_y - start_y;
47 FX_FLOAT axis_len_square = 47 FX_FLOAT axis_len_square =
48 FXSYS_Mul(x_span, x_span) + FXSYS_Mul(y_span, y_span); 48 FXSYS_Mul(x_span, x_span) + FXSYS_Mul(y_span, y_span);
49 CFX_AffineMatrix matrix; 49 CFX_Matrix matrix;
50 matrix.SetReverse(*pObject2Bitmap); 50 matrix.SetReverse(*pObject2Bitmap);
51 int total_results = 0; 51 int total_results = 0;
52 for (int j = 0; j < nFuncs; j++) { 52 for (int j = 0; j < nFuncs; j++) {
53 if (pFuncs[j]) { 53 if (pFuncs[j]) {
54 total_results += pFuncs[j]->CountOutputs(); 54 total_results += pFuncs[j]->CountOutputs();
55 } 55 }
56 } 56 }
57 if (pCS->CountComponents() > total_results) { 57 if (pCS->CountComponents() > total_results) {
58 total_results = pCS->CountComponents(); 58 total_results = pCS->CountComponents();
59 } 59 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (!bEndExtend) { 97 if (!bEndExtend) {
98 continue; 98 continue;
99 } 99 }
100 index = SHADING_STEPS - 1; 100 index = SHADING_STEPS - 1;
101 } 101 }
102 dib_buf[column] = rgb_array[index]; 102 dib_buf[column] = rgb_array[index];
103 } 103 }
104 } 104 }
105 } 105 }
106 static void DrawRadialShading(CFX_DIBitmap* pBitmap, 106 static void DrawRadialShading(CFX_DIBitmap* pBitmap,
107 CFX_AffineMatrix* 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(FX_BSTRC("Coords")); 114 CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords"));
115 if (pCoords == NULL) { 115 if (pCoords == NULL) {
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_AffineMatrix matrix; 124 CFX_Matrix matrix;
125 matrix.SetReverse(*pObject2Bitmap); 125 matrix.SetReverse(*pObject2Bitmap);
126 FX_FLOAT t_min = 0, t_max = 1.0f; 126 FX_FLOAT t_min = 0, t_max = 1.0f;
127 CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Domain")); 127 CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Domain"));
128 if (pArray) { 128 if (pArray) {
129 t_min = pArray->GetNumber(0); 129 t_min = pArray->GetNumber(0);
130 t_max = pArray->GetNumber(1); 130 t_max = pArray->GetNumber(1);
131 } 131 }
132 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; 132 FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE;
133 pArray = pDict->GetArray(FX_BSTRC("Extend")); 133 pArray = pDict->GetArray(FX_BSTRC("Extend"));
134 if (pArray) { 134 if (pArray) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (!bEndExtend) { 235 if (!bEndExtend) {
236 continue; 236 continue;
237 } 237 }
238 index = SHADING_STEPS - 1; 238 index = SHADING_STEPS - 1;
239 } 239 }
240 dib_buf[column] = rgb_array[index]; 240 dib_buf[column] = rgb_array[index];
241 } 241 }
242 } 242 }
243 } 243 }
244 static void DrawFuncShading(CFX_DIBitmap* pBitmap, 244 static void DrawFuncShading(CFX_DIBitmap* pBitmap,
245 CFX_AffineMatrix* pObject2Bitmap, 245 CFX_Matrix* pObject2Bitmap,
246 CPDF_Dictionary* pDict, 246 CPDF_Dictionary* pDict,
247 CPDF_Function** pFuncs, 247 CPDF_Function** pFuncs,
248 int nFuncs, 248 int nFuncs,
249 CPDF_ColorSpace* pCS, 249 CPDF_ColorSpace* pCS,
250 int alpha) { 250 int alpha) {
251 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); 251 ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
252 CPDF_Array* pDomain = pDict->GetArray(FX_BSTRC("Domain")); 252 CPDF_Array* pDomain = pDict->GetArray(FX_BSTRC("Domain"));
253 FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f; 253 FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f;
254 if (pDomain) { 254 if (pDomain) {
255 xmin = pDomain->GetNumber(0); 255 xmin = pDomain->GetNumber(0);
256 xmax = pDomain->GetNumber(1); 256 xmax = pDomain->GetNumber(1);
257 ymin = pDomain->GetNumber(2); 257 ymin = pDomain->GetNumber(2);
258 ymax = pDomain->GetNumber(3); 258 ymax = pDomain->GetNumber(3);
259 } 259 }
260 CFX_AffineMatrix mtDomain2Target = pDict->GetMatrix(FX_BSTRC("Matrix")); 260 CFX_Matrix mtDomain2Target = pDict->GetMatrix(FX_BSTRC("Matrix"));
261 CFX_AffineMatrix matrix, reverse_matrix; 261 CFX_Matrix matrix, reverse_matrix;
262 matrix.SetReverse(*pObject2Bitmap); 262 matrix.SetReverse(*pObject2Bitmap);
263 reverse_matrix.SetReverse(mtDomain2Target); 263 reverse_matrix.SetReverse(mtDomain2Target);
264 matrix.Concat(reverse_matrix); 264 matrix.Concat(reverse_matrix);
265 int width = pBitmap->GetWidth(); 265 int width = pBitmap->GetWidth();
266 int height = pBitmap->GetHeight(); 266 int height = pBitmap->GetHeight();
267 int pitch = pBitmap->GetPitch(); 267 int pitch = pBitmap->GetPitch();
268 int total_results = 0; 268 int total_results = 0;
269 for (int j = 0; j < nFuncs; j++) { 269 for (int j = 0; j < nFuncs; j++) {
270 if (pFuncs[j]) { 270 if (pFuncs[j]) {
271 total_results += pFuncs[j]->CountOutputs(); 271 total_results += pFuncs[j]->CountOutputs();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 G += g_unit; 404 G += g_unit;
405 B += b_unit; 405 B += b_unit;
406 FXARGB_SETDIB(dib_buf, 406 FXARGB_SETDIB(dib_buf,
407 FXARGB_MAKE(alpha, (int32_t)(R * 255), (int32_t)(G * 255), 407 FXARGB_MAKE(alpha, (int32_t)(R * 255), (int32_t)(G * 255),
408 (int32_t)(B * 255))); 408 (int32_t)(B * 255)));
409 dib_buf += 4; 409 dib_buf += 4;
410 } 410 }
411 } 411 }
412 } 412 }
413 static void DrawFreeGouraudShading(CFX_DIBitmap* pBitmap, 413 static void DrawFreeGouraudShading(CFX_DIBitmap* pBitmap,
414 CFX_AffineMatrix* pObject2Bitmap, 414 CFX_Matrix* pObject2Bitmap,
415 CPDF_Stream* pShadingStream, 415 CPDF_Stream* pShadingStream,
416 CPDF_Function** pFuncs, 416 CPDF_Function** pFuncs,
417 int nFuncs, 417 int nFuncs,
418 CPDF_ColorSpace* pCS, 418 CPDF_ColorSpace* pCS,
419 int alpha) { 419 int alpha) {
420 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); 420 ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
421 421
422 CPDF_MeshStream stream; 422 CPDF_MeshStream stream;
423 if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) 423 if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS))
424 return; 424 return;
(...skipping 13 matching lines...) Expand all
438 if (flag == 1) { 438 if (flag == 1) {
439 triangle[0] = triangle[1]; 439 triangle[0] = triangle[1];
440 } 440 }
441 triangle[1] = triangle[2]; 441 triangle[1] = triangle[2];
442 triangle[2] = vertex; 442 triangle[2] = vertex;
443 } 443 }
444 DrawGouraud(pBitmap, alpha, triangle); 444 DrawGouraud(pBitmap, alpha, triangle);
445 } 445 }
446 } 446 }
447 static void DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap, 447 static void DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap,
448 CFX_AffineMatrix* pObject2Bitmap, 448 CFX_Matrix* pObject2Bitmap,
449 CPDF_Stream* pShadingStream, 449 CPDF_Stream* pShadingStream,
450 CPDF_Function** pFuncs, 450 CPDF_Function** pFuncs,
451 int nFuncs, 451 int nFuncs,
452 CPDF_ColorSpace* pCS, 452 CPDF_ColorSpace* pCS,
453 int alpha) { 453 int alpha) {
454 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); 454 ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
455 455
456 int row_verts = pShadingStream->GetDict()->GetInteger("VerticesPerRow"); 456 int row_verts = pShadingStream->GetDict()->GetInteger("VerticesPerRow");
457 if (row_verts < 2) 457 if (row_verts < 2)
458 return; 458 return;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 stream.m_nCompBits == 12 || stream.m_nCompBits == 16); 741 stream.m_nCompBits == 12 || stream.m_nCompBits == 16);
742 742
743 FX_BOOL bFlagBits = (stream.m_nFlagBits == 2 || stream.m_nFlagBits == 4 || 743 FX_BOOL bFlagBits = (stream.m_nFlagBits == 2 || stream.m_nFlagBits == 4 ||
744 stream.m_nFlagBits == 8); 744 stream.m_nFlagBits == 8);
745 745
746 return bCoorBits && bCompBits && bFlagBits; 746 return bCoorBits && bCompBits && bFlagBits;
747 } 747 }
748 748
749 static void DrawCoonPatchMeshes(FX_BOOL bTensor, 749 static void DrawCoonPatchMeshes(FX_BOOL bTensor,
750 CFX_DIBitmap* pBitmap, 750 CFX_DIBitmap* pBitmap,
751 CFX_AffineMatrix* pObject2Bitmap, 751 CFX_Matrix* pObject2Bitmap,
752 CPDF_Stream* pShadingStream, 752 CPDF_Stream* pShadingStream,
753 CPDF_Function** pFuncs, 753 CPDF_Function** pFuncs,
754 int nFuncs, 754 int nFuncs,
755 CPDF_ColorSpace* pCS, 755 CPDF_ColorSpace* pCS,
756 int fill_mode, 756 int fill_mode,
757 int alpha) { 757 int alpha) {
758 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); 758 ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
759 759
760 CFX_FxgeDevice device; 760 CFX_FxgeDevice device;
761 device.Attach(pBitmap); 761 device.Attach(pBitmap);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 C2.FromPoints(coords[3].x, coords[3].y, coords[4].x, coords[4].y, 819 C2.FromPoints(coords[3].x, coords[3].y, coords[4].x, coords[4].y,
820 coords[5].x, coords[5].y, coords[6].x, coords[6].y); 820 coords[5].x, coords[5].y, coords[6].x, coords[6].y);
821 D1.FromPoints(coords[0].x, coords[0].y, coords[1].x, coords[1].y, 821 D1.FromPoints(coords[0].x, coords[0].y, coords[1].x, coords[1].y,
822 coords[2].x, coords[2].y, coords[3].x, coords[3].y); 822 coords[2].x, coords[2].y, coords[3].x, coords[3].y);
823 D2.FromPoints(coords[9].x, coords[9].y, coords[8].x, coords[8].y, 823 D2.FromPoints(coords[9].x, coords[9].y, coords[8].x, coords[8].y,
824 coords[7].x, coords[7].y, coords[6].x, coords[6].y); 824 coords[7].x, coords[7].y, coords[6].x, coords[6].y);
825 patch.Draw(1, 1, 0, 0, C1, C2, D1, D2); 825 patch.Draw(1, 1, 0, 0, C1, C2, D1, D2);
826 } 826 }
827 } 827 }
828 void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, 828 void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
829 CFX_AffineMatrix* 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 == NULL) {
838 return; 838 return;
839 } 839 }
(...skipping 14 matching lines...) Expand all
854 (int32_t)(B * 255)); 854 (int32_t)(B * 255));
855 } 855 }
856 } 856 }
857 if (pDict->KeyExist(FX_BSTRC("BBox"))) { 857 if (pDict->KeyExist(FX_BSTRC("BBox"))) {
858 CFX_FloatRect rect = pDict->GetRect(FX_BSTRC("BBox")); 858 CFX_FloatRect rect = pDict->GetRect(FX_BSTRC("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_AffineMatrix 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() == NULL) {
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:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 if (bAlphaMode) { 906 if (bAlphaMode) {
907 pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha); 907 pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha);
908 } 908 }
909 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) { 909 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
910 pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor); 910 pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor);
911 } 911 }
912 buffer.OutputToDevice(); 912 buffer.OutputToDevice();
913 } 913 }
914 void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern, 914 void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern,
915 CPDF_PageObject* pPageObj, 915 CPDF_PageObject* pPageObj,
916 const CFX_AffineMatrix* pObj2Device, 916 const CFX_Matrix* pObj2Device,
917 FX_BOOL bStroke) { 917 FX_BOOL bStroke) {
918 if (!pattern->Load()) { 918 if (!pattern->Load()) {
919 return; 919 return;
920 } 920 }
921 m_pDevice->SaveState(); 921 m_pDevice->SaveState();
922 if (pPageObj->m_Type == PDFPAGE_PATH) { 922 if (pPageObj->m_Type == PDFPAGE_PATH) {
923 if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) { 923 if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) {
924 m_pDevice->RestoreState(); 924 m_pDevice->RestoreState();
925 return; 925 return;
926 } 926 }
927 } else if (pPageObj->m_Type == PDFPAGE_IMAGE) { 927 } else if (pPageObj->m_Type == PDFPAGE_IMAGE) {
928 FX_RECT rect = pPageObj->GetBBox(pObj2Device); 928 FX_RECT rect = pPageObj->GetBBox(pObj2Device);
929 m_pDevice->SetClip_Rect(&rect); 929 m_pDevice->SetClip_Rect(&rect);
930 } else { 930 } else {
931 return; 931 return;
932 } 932 }
933 FX_RECT rect; 933 FX_RECT rect;
934 if (GetObjectClippedRect(pPageObj, pObj2Device, FALSE, rect)) { 934 if (GetObjectClippedRect(pPageObj, pObj2Device, FALSE, rect)) {
935 m_pDevice->RestoreState(); 935 m_pDevice->RestoreState();
936 return; 936 return;
937 } 937 }
938 CFX_AffineMatrix matrix = pattern->m_Pattern2Form; 938 CFX_Matrix matrix = pattern->m_Pattern2Form;
939 matrix.Concat(*pObj2Device); 939 matrix.Concat(*pObj2Device);
940 GetScaledMatrix(matrix); 940 GetScaledMatrix(matrix);
941 int alpha = pPageObj->m_GeneralState.GetAlpha(bStroke); 941 int alpha = pPageObj->m_GeneralState.GetAlpha(bStroke);
942 DrawShading(pattern, &matrix, rect, alpha, 942 DrawShading(pattern, &matrix, rect, alpha,
943 m_Options.m_ColorMode == RENDER_COLOR_ALPHA); 943 m_Options.m_ColorMode == RENDER_COLOR_ALPHA);
944 m_pDevice->RestoreState(); 944 m_pDevice->RestoreState();
945 } 945 }
946 FX_BOOL CPDF_RenderStatus::ProcessShading(CPDF_ShadingObject* pShadingObj, 946 FX_BOOL CPDF_RenderStatus::ProcessShading(CPDF_ShadingObject* pShadingObj,
947 const CFX_AffineMatrix* pObj2Device) { 947 const CFX_Matrix* pObj2Device) {
948 FX_RECT rect = pShadingObj->GetBBox(pObj2Device); 948 FX_RECT rect = pShadingObj->GetBBox(pObj2Device);
949 FX_RECT clip_box = m_pDevice->GetClipBox(); 949 FX_RECT clip_box = m_pDevice->GetClipBox();
950 rect.Intersect(clip_box); 950 rect.Intersect(clip_box);
951 if (rect.IsEmpty()) { 951 if (rect.IsEmpty()) {
952 return TRUE; 952 return TRUE;
953 } 953 }
954 CFX_AffineMatrix matrix = pShadingObj->m_Matrix; 954 CFX_Matrix matrix = pShadingObj->m_Matrix;
955 matrix.Concat(*pObj2Device); 955 matrix.Concat(*pObj2Device);
956 DrawShading(pShadingObj->m_pShading, &matrix, rect, 956 DrawShading(pShadingObj->m_pShading, &matrix, rect,
957 pShadingObj->m_GeneralState.GetAlpha(FALSE), 957 pShadingObj->m_GeneralState.GetAlpha(FALSE),
958 m_Options.m_ColorMode == RENDER_COLOR_ALPHA); 958 m_Options.m_ColorMode == RENDER_COLOR_ALPHA);
959 return TRUE; 959 return TRUE;
960 } 960 }
961 static CFX_DIBitmap* DrawPatternBitmap(CPDF_Document* pDoc, 961 static CFX_DIBitmap* DrawPatternBitmap(CPDF_Document* pDoc,
962 CPDF_PageRenderCache* pCache, 962 CPDF_PageRenderCache* pCache,
963 CPDF_TilingPattern* pPattern, 963 CPDF_TilingPattern* pPattern,
964 const CFX_AffineMatrix* pObject2Device, 964 const CFX_Matrix* pObject2Device,
965 int width, 965 int width,
966 int height, 966 int height,
967 int flags) { 967 int flags) {
968 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; 968 CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
969 if (!pBitmap->Create(width, height, 969 if (!pBitmap->Create(width, height,
970 pPattern->m_bColored ? FXDIB_Argb : FXDIB_8bppMask)) { 970 pPattern->m_bColored ? FXDIB_Argb : FXDIB_8bppMask)) {
971 delete pBitmap; 971 delete pBitmap;
972 return NULL; 972 return NULL;
973 } 973 }
974 CFX_FxgeDevice bitmap_device; 974 CFX_FxgeDevice bitmap_device;
975 bitmap_device.Attach(pBitmap); 975 bitmap_device.Attach(pBitmap);
976 pBitmap->Clear(0); 976 pBitmap->Clear(0);
977 CFX_FloatRect cell_bbox = pPattern->m_BBox; 977 CFX_FloatRect cell_bbox = pPattern->m_BBox;
978 pPattern->m_Pattern2Form.TransformRect(cell_bbox); 978 pPattern->m_Pattern2Form.TransformRect(cell_bbox);
979 pObject2Device->TransformRect(cell_bbox); 979 pObject2Device->TransformRect(cell_bbox);
980 CFX_FloatRect bitmap_rect(0.0f, 0.0f, (FX_FLOAT)width, (FX_FLOAT)height); 980 CFX_FloatRect bitmap_rect(0.0f, 0.0f, (FX_FLOAT)width, (FX_FLOAT)height);
981 CFX_AffineMatrix mtAdjust; 981 CFX_Matrix mtAdjust;
982 mtAdjust.MatchRect(bitmap_rect, cell_bbox); 982 mtAdjust.MatchRect(bitmap_rect, cell_bbox);
983 CFX_AffineMatrix mtPattern2Bitmap = *pObject2Device; 983 CFX_Matrix mtPattern2Bitmap = *pObject2Device;
984 mtPattern2Bitmap.Concat(mtAdjust); 984 mtPattern2Bitmap.Concat(mtAdjust);
985 CPDF_RenderOptions options; 985 CPDF_RenderOptions options;
986 if (!pPattern->m_bColored) { 986 if (!pPattern->m_bColored) {
987 options.m_ColorMode = RENDER_COLOR_ALPHA; 987 options.m_ColorMode = RENDER_COLOR_ALPHA;
988 } 988 }
989 flags |= RENDER_FORCE_HALFTONE; 989 flags |= RENDER_FORCE_HALFTONE;
990 options.m_Flags = flags; 990 options.m_Flags = flags;
991 CPDF_RenderContext context; 991 CPDF_RenderContext context;
992 context.Create(pDoc, pCache, NULL); 992 context.Create(pDoc, pCache, NULL);
993 context.DrawObjectList(&bitmap_device, pPattern->m_pForm, &mtPattern2Bitmap, 993 context.DrawObjectList(&bitmap_device, pPattern->m_pForm, &mtPattern2Bitmap,
994 &options); 994 &options);
995 return pBitmap; 995 return pBitmap;
996 } 996 }
997 void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, 997 void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
998 CPDF_PageObject* pPageObj, 998 CPDF_PageObject* pPageObj,
999 const CFX_AffineMatrix* pObj2Device, 999 const CFX_Matrix* pObj2Device,
1000 FX_BOOL bStroke) { 1000 FX_BOOL bStroke) {
1001 if (!pPattern->Load()) { 1001 if (!pPattern->Load()) {
1002 return; 1002 return;
1003 } 1003 }
1004 m_pDevice->SaveState(); 1004 m_pDevice->SaveState();
1005 if (pPageObj->m_Type == PDFPAGE_PATH) { 1005 if (pPageObj->m_Type == PDFPAGE_PATH) {
1006 if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) { 1006 if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) {
1007 m_pDevice->RestoreState(); 1007 m_pDevice->RestoreState();
1008 return; 1008 return;
1009 } 1009 }
1010 } else if (pPageObj->m_Type == PDFPAGE_IMAGE) { 1010 } else if (pPageObj->m_Type == PDFPAGE_IMAGE) {
1011 FX_RECT rect = pPageObj->GetBBox(pObj2Device); 1011 FX_RECT rect = pPageObj->GetBBox(pObj2Device);
1012 m_pDevice->SetClip_Rect(&rect); 1012 m_pDevice->SetClip_Rect(&rect);
1013 } else { 1013 } else {
1014 return; 1014 return;
1015 } 1015 }
1016 FX_RECT clip_box = m_pDevice->GetClipBox(); 1016 FX_RECT clip_box = m_pDevice->GetClipBox();
1017 if (clip_box.IsEmpty()) { 1017 if (clip_box.IsEmpty()) {
1018 m_pDevice->RestoreState(); 1018 m_pDevice->RestoreState();
1019 return; 1019 return;
1020 } 1020 }
1021 CFX_Matrix dCTM = m_pDevice->GetCTM(); 1021 CFX_Matrix dCTM = m_pDevice->GetCTM();
1022 FX_FLOAT sa = FXSYS_fabs(dCTM.a); 1022 FX_FLOAT sa = FXSYS_fabs(dCTM.a);
1023 FX_FLOAT sd = FXSYS_fabs(dCTM.d); 1023 FX_FLOAT sd = FXSYS_fabs(dCTM.d);
1024 clip_box.right = clip_box.left + (int32_t)FXSYS_ceil(clip_box.Width() * sa); 1024 clip_box.right = clip_box.left + (int32_t)FXSYS_ceil(clip_box.Width() * sa);
1025 clip_box.bottom = clip_box.top + (int32_t)FXSYS_ceil(clip_box.Height() * sd); 1025 clip_box.bottom = clip_box.top + (int32_t)FXSYS_ceil(clip_box.Height() * sd);
1026 CFX_AffineMatrix mtPattern2Device = pPattern->m_Pattern2Form; 1026 CFX_Matrix mtPattern2Device = pPattern->m_Pattern2Form;
1027 mtPattern2Device.Concat(*pObj2Device); 1027 mtPattern2Device.Concat(*pObj2Device);
1028 GetScaledMatrix(mtPattern2Device); 1028 GetScaledMatrix(mtPattern2Device);
1029 FX_BOOL bAligned = FALSE; 1029 FX_BOOL bAligned = FALSE;
1030 if (pPattern->m_BBox.left == 0 && pPattern->m_BBox.bottom == 0 && 1030 if (pPattern->m_BBox.left == 0 && pPattern->m_BBox.bottom == 0 &&
1031 pPattern->m_BBox.right == pPattern->m_XStep && 1031 pPattern->m_BBox.right == pPattern->m_XStep &&
1032 pPattern->m_BBox.top == pPattern->m_YStep && 1032 pPattern->m_BBox.top == pPattern->m_YStep &&
1033 (mtPattern2Device.IsScaled() || mtPattern2Device.Is90Rotated())) { 1033 (mtPattern2Device.IsScaled() || mtPattern2Device.Is90Rotated())) {
1034 bAligned = TRUE; 1034 bAligned = TRUE;
1035 } 1035 }
1036 CFX_FloatRect cell_bbox = pPattern->m_BBox; 1036 CFX_FloatRect cell_bbox = pPattern->m_BBox;
1037 mtPattern2Device.TransformRect(cell_bbox); 1037 mtPattern2Device.TransformRect(cell_bbox);
1038 int width = (int)FXSYS_ceil(cell_bbox.Width()); 1038 int width = (int)FXSYS_ceil(cell_bbox.Width());
1039 int height = (int)FXSYS_ceil(cell_bbox.Height()); 1039 int height = (int)FXSYS_ceil(cell_bbox.Height());
1040 if (width == 0) { 1040 if (width == 0) {
1041 width = 1; 1041 width = 1;
1042 } 1042 }
1043 if (height == 0) { 1043 if (height == 0) {
1044 height = 1; 1044 height = 1;
1045 } 1045 }
1046 int min_col, max_col, min_row, max_row; 1046 int min_col, max_col, min_row, max_row;
1047 CFX_AffineMatrix mtDevice2Pattern; 1047 CFX_Matrix mtDevice2Pattern;
1048 mtDevice2Pattern.SetReverse(mtPattern2Device); 1048 mtDevice2Pattern.SetReverse(mtPattern2Device);
1049 CFX_FloatRect clip_box_p(clip_box); 1049 CFX_FloatRect clip_box_p(clip_box);
1050 clip_box_p.Transform(&mtDevice2Pattern); 1050 clip_box_p.Transform(&mtDevice2Pattern);
1051 min_col = (int)FXSYS_ceil( 1051 min_col = (int)FXSYS_ceil(
1052 FXSYS_Div(clip_box_p.left - pPattern->m_BBox.right, pPattern->m_XStep)); 1052 FXSYS_Div(clip_box_p.left - pPattern->m_BBox.right, pPattern->m_XStep));
1053 max_col = (int)FXSYS_floor( 1053 max_col = (int)FXSYS_floor(
1054 FXSYS_Div(clip_box_p.right - pPattern->m_BBox.left, pPattern->m_XStep)); 1054 FXSYS_Div(clip_box_p.right - pPattern->m_BBox.left, pPattern->m_XStep));
1055 min_row = (int)FXSYS_ceil( 1055 min_row = (int)FXSYS_ceil(
1056 FXSYS_Div(clip_box_p.bottom - pPattern->m_BBox.top, pPattern->m_YStep)); 1056 FXSYS_Div(clip_box_p.bottom - pPattern->m_BBox.top, pPattern->m_YStep));
1057 max_row = (int)FXSYS_floor( 1057 max_row = (int)FXSYS_floor(
1058 FXSYS_Div(clip_box_p.top - pPattern->m_BBox.bottom, pPattern->m_YStep)); 1058 FXSYS_Div(clip_box_p.top - pPattern->m_BBox.bottom, pPattern->m_YStep));
1059 if (width > clip_box.Width() || height > clip_box.Height() || 1059 if (width > clip_box.Width() || height > clip_box.Height() ||
1060 width * height > clip_box.Width() * clip_box.Height()) { 1060 width * height > clip_box.Width() * clip_box.Height()) {
1061 CPDF_GraphicStates* pStates = NULL; 1061 CPDF_GraphicStates* pStates = NULL;
1062 if (!pPattern->m_bColored) { 1062 if (!pPattern->m_bColored) {
1063 pStates = CloneObjStates(pPageObj, bStroke); 1063 pStates = CloneObjStates(pPageObj, bStroke);
1064 } 1064 }
1065 CPDF_Dictionary* pFormResource = NULL; 1065 CPDF_Dictionary* pFormResource = NULL;
1066 if (pPattern->m_pForm->m_pFormDict) { 1066 if (pPattern->m_pForm->m_pFormDict) {
1067 pFormResource = 1067 pFormResource =
1068 pPattern->m_pForm->m_pFormDict->GetDict(FX_BSTRC("Resources")); 1068 pPattern->m_pForm->m_pFormDict->GetDict(FX_BSTRC("Resources"));
1069 } 1069 }
1070 for (int col = min_col; col <= max_col; col++) 1070 for (int col = min_col; col <= max_col; col++)
1071 for (int row = min_row; row <= max_row; row++) { 1071 for (int row = min_row; row <= max_row; row++) {
1072 FX_FLOAT orig_x, orig_y; 1072 FX_FLOAT orig_x, orig_y;
1073 orig_x = col * pPattern->m_XStep; 1073 orig_x = col * pPattern->m_XStep;
1074 orig_y = row * pPattern->m_YStep; 1074 orig_y = row * pPattern->m_YStep;
1075 mtPattern2Device.Transform(orig_x, orig_y); 1075 mtPattern2Device.Transform(orig_x, orig_y);
1076 CFX_AffineMatrix matrix = *pObj2Device; 1076 CFX_Matrix matrix = *pObj2Device;
1077 matrix.Translate(orig_x - mtPattern2Device.e, 1077 matrix.Translate(orig_x - mtPattern2Device.e,
1078 orig_y - mtPattern2Device.f); 1078 orig_y - mtPattern2Device.f);
1079 m_pDevice->SaveState(); 1079 m_pDevice->SaveState();
1080 CPDF_RenderStatus status; 1080 CPDF_RenderStatus status;
1081 status.Initialize(m_pContext, m_pDevice, NULL, NULL, this, pStates, 1081 status.Initialize(m_pContext, m_pDevice, NULL, NULL, this, pStates,
1082 &m_Options, pPattern->m_pForm->m_Transparency, 1082 &m_Options, pPattern->m_pForm->m_Transparency,
1083 m_bDropObjects, pFormResource); 1083 m_bDropObjects, pFormResource);
1084 status.RenderObjectList(pPattern->m_pForm, &matrix); 1084 status.RenderObjectList(pPattern->m_pForm, &matrix);
1085 m_pDevice->RestoreState(); 1085 m_pDevice->RestoreState();
1086 } 1086 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 } 1178 }
1179 CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255, 1179 CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255,
1180 FXDIB_BLEND_NORMAL, FALSE); 1180 FXDIB_BLEND_NORMAL, FALSE);
1181 m_pDevice->RestoreState(); 1181 m_pDevice->RestoreState();
1182 delete pPatternBitmap; 1182 delete pPatternBitmap;
1183 } 1183 }
1184 void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, 1184 void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj,
1185 const CFX_AffineMatrix* pObj2Device, 1185 const CFX_Matrix* pObj2Device,
1186 CPDF_Color* pColor, 1186 CPDF_Color* pColor,
1187 FX_BOOL bStroke) { 1187 FX_BOOL bStroke) {
1188 CPDF_Pattern* pattern = pColor->GetPattern(); 1188 CPDF_Pattern* pattern = pColor->GetPattern();
1189 if (pattern == NULL) { 1189 if (pattern == NULL) {
1190 return; 1190 return;
1191 } 1191 }
1192 if (pattern->m_PatternType == PATTERN_TILING) { 1192 if (pattern->m_PatternType == PATTERN_TILING) {
1193 DrawTilingPattern((CPDF_TilingPattern*)pattern, pPathObj, pObj2Device, 1193 DrawTilingPattern((CPDF_TilingPattern*)pattern, pPathObj, pObj2Device,
1194 bStroke); 1194 bStroke);
1195 } else { 1195 } else {
1196 DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device, 1196 DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device,
1197 bStroke); 1197 bStroke);
1198 } 1198 }
1199 } 1199 }
1200 void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, 1200 void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj,
1201 const CFX_AffineMatrix* pObj2Device, 1201 const CFX_Matrix* pObj2Device,
1202 int& filltype, 1202 int& filltype,
1203 FX_BOOL& bStroke) { 1203 FX_BOOL& bStroke) {
1204 if (filltype) { 1204 if (filltype) {
1205 CPDF_Color& FillColor = *pPathObj->m_ColorState.GetFillColor(); 1205 CPDF_Color& FillColor = *pPathObj->m_ColorState.GetFillColor();
1206 if (FillColor.m_pCS && FillColor.m_pCS->GetFamily() == PDFCS_PATTERN) { 1206 if (FillColor.m_pCS && FillColor.m_pCS->GetFamily() == PDFCS_PATTERN) {
1207 DrawPathWithPattern(pPathObj, pObj2Device, &FillColor, FALSE); 1207 DrawPathWithPattern(pPathObj, pObj2Device, &FillColor, FALSE);
1208 filltype = 0; 1208 filltype = 0;
1209 } 1209 }
1210 } 1210 }
1211 if (bStroke) { 1211 if (bStroke) {
1212 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); 1212 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor();
1213 if (StrokeColor.m_pCS && StrokeColor.m_pCS->GetFamily() == PDFCS_PATTERN) { 1213 if (StrokeColor.m_pCS && StrokeColor.m_pCS->GetFamily() == PDFCS_PATTERN) {
1214 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); 1214 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE);
1215 bStroke = FALSE; 1215 bStroke = FALSE;
1216 } 1216 }
1217 } 1217 }
1218 } 1218 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698