| 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 "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "pageint.h" | 8 #include "pageint.h" |
| 9 | 9 |
| 10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) : | 10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) |
| 11 m_pPatternObj(NULL), m_PatternType(PATTERN_TILING), m_pDocument(NULL), m_bFo
rceClear(FALSE) | 11 : m_pPatternObj(NULL), |
| 12 { | 12 m_PatternType(PATTERN_TILING), |
| 13 if (pParentMatrix) { | 13 m_pDocument(NULL), |
| 14 m_ParentMatrix = *pParentMatrix; | 14 m_bForceClear(FALSE) { |
| 15 } | 15 if (pParentMatrix) { |
| 16 } | 16 m_ParentMatrix = *pParentMatrix; |
| 17 CPDF_Pattern::~CPDF_Pattern() | 17 } |
| 18 { | 18 } |
| 19 } | 19 CPDF_Pattern::~CPDF_Pattern() {} |
| 20 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatter
nObj, const CFX_AffineMatrix* parentMatrix) : | 20 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, |
| 21 CPDF_Pattern(parentMatrix) | 21 CPDF_Object* pPatternObj, |
| 22 { | 22 const CFX_AffineMatrix* parentMatrix) |
| 23 m_PatternType = PATTERN_TILING; | 23 : CPDF_Pattern(parentMatrix) { |
| 24 m_pPatternObj = pPatternObj; | 24 m_PatternType = PATTERN_TILING; |
| 25 m_pDocument = pDoc; | 25 m_pPatternObj = pPatternObj; |
| 26 m_pDocument = pDoc; |
| 27 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 28 ASSERT(pDict != NULL); |
| 29 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); |
| 30 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; |
| 31 if (parentMatrix) { |
| 32 m_Pattern2Form.Concat(*parentMatrix); |
| 33 } |
| 34 m_pForm = NULL; |
| 35 } |
| 36 CPDF_TilingPattern::~CPDF_TilingPattern() { |
| 37 delete m_pForm; |
| 38 m_pForm = NULL; |
| 39 } |
| 40 FX_BOOL CPDF_TilingPattern::Load() { |
| 41 if (m_pForm != NULL) { |
| 42 return TRUE; |
| 43 } |
| 44 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 45 if (pDict == NULL) { |
| 46 return FALSE; |
| 47 } |
| 48 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; |
| 49 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); |
| 50 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); |
| 51 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { |
| 52 return FALSE; |
| 53 } |
| 54 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; |
| 55 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); |
| 56 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); |
| 57 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); |
| 58 return TRUE; |
| 59 } |
| 60 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, |
| 61 CPDF_Object* pPatternObj, |
| 62 FX_BOOL bShading, |
| 63 const CFX_AffineMatrix* parentMatrix) |
| 64 : CPDF_Pattern(parentMatrix) { |
| 65 m_PatternType = PATTERN_SHADING; |
| 66 m_pPatternObj = bShading ? NULL : pPatternObj; |
| 67 m_pDocument = pDoc; |
| 68 m_bShadingObj = bShading; |
| 69 if (!bShading) { |
| 26 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 70 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 27 ASSERT(pDict != NULL); | 71 ASSERT(pDict != NULL); |
| 28 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); | 72 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); |
| 29 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; | 73 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); |
| 30 if (parentMatrix) { | 74 if (parentMatrix) { |
| 31 m_Pattern2Form.Concat(*parentMatrix); | 75 m_Pattern2Form.Concat(*parentMatrix); |
| 32 } | 76 } |
| 33 m_pForm = NULL; | 77 } else { |
| 34 } | 78 m_pShadingObj = pPatternObj; |
| 35 CPDF_TilingPattern::~CPDF_TilingPattern() | 79 } |
| 36 { | 80 m_ShadingType = 0; |
| 37 delete m_pForm; | 81 m_pCS = NULL; |
| 38 m_pForm = NULL; | 82 m_nFuncs = 0; |
| 39 } | 83 for (int i = 0; i < 4; i++) { |
| 40 FX_BOOL CPDF_TilingPattern::Load() | 84 m_pFunctions[i] = NULL; |
| 41 { | 85 } |
| 42 if (m_pForm != NULL) { | 86 m_pCountedCS = NULL; |
| 43 return TRUE; | 87 } |
| 44 } | 88 CPDF_ShadingPattern::~CPDF_ShadingPattern() { |
| 45 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 89 Clear(); |
| 46 if (pDict == NULL) { | 90 } |
| 47 return FALSE; | 91 void CPDF_ShadingPattern::Clear() { |
| 48 } | 92 for (int i = 0; i < m_nFuncs; i++) { |
| 49 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; | 93 delete m_pFunctions[i]; |
| 50 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); | 94 m_pFunctions[i] = NULL; |
| 51 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); | 95 } |
| 52 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { | 96 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; |
| 53 return FALSE; | 97 if (pCS && m_pDocument) { |
| 54 } | 98 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); |
| 55 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; | 99 } |
| 56 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); | 100 m_ShadingType = 0; |
| 57 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); | 101 m_pCS = NULL; |
| 58 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); | 102 m_pCountedCS = NULL; |
| 103 m_nFuncs = 0; |
| 104 } |
| 105 FX_BOOL CPDF_ShadingPattern::Load() { |
| 106 if (m_ShadingType != 0) { |
| 59 return TRUE; | 107 return TRUE; |
| 60 } | 108 } |
| 61 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatt
ernObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix) : CPDF_Pattern(p
arentMatrix) | 109 CPDF_Dictionary* pShadingDict = |
| 62 { | 110 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; |
| 63 m_PatternType = PATTERN_SHADING; | 111 if (pShadingDict == NULL) { |
| 64 m_pPatternObj = bShading ? NULL : pPatternObj; | 112 return FALSE; |
| 65 m_pDocument = pDoc; | 113 } |
| 66 m_bShadingObj = bShading; | 114 if (m_nFuncs) { |
| 67 if (!bShading) { | 115 for (int i = 0; i < m_nFuncs; i++) |
| 68 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 116 delete m_pFunctions[i]; |
| 69 ASSERT(pDict != NULL); | 117 m_nFuncs = 0; |
| 70 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); | 118 } |
| 71 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); | 119 CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function")); |
| 72 if (parentMatrix) { | 120 if (pFunc) { |
| 73 m_Pattern2Form.Concat(*parentMatrix); | 121 if (pFunc->GetType() == PDFOBJ_ARRAY) { |
| 74 } | 122 m_nFuncs = ((CPDF_Array*)pFunc)->GetCount(); |
| 123 if (m_nFuncs > 4) { |
| 124 m_nFuncs = 4; |
| 125 } |
| 126 for (int i = 0; i < m_nFuncs; i++) { |
| 127 m_pFunctions[i] = |
| 128 CPDF_Function::Load(((CPDF_Array*)pFunc)->GetElementValue(i)); |
| 129 } |
| 75 } else { | 130 } else { |
| 76 m_pShadingObj = pPatternObj; | 131 m_pFunctions[0] = CPDF_Function::Load(pFunc); |
| 77 } | 132 m_nFuncs = 1; |
| 78 m_ShadingType = 0; | 133 } |
| 79 m_pCS = NULL; | 134 } |
| 80 m_nFuncs = 0; | 135 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); |
| 81 for (int i = 0; i < 4; i ++) { | 136 if (pCSObj == NULL) { |
| 82 m_pFunctions[i] = NULL; | 137 return FALSE; |
| 83 } | 138 } |
| 84 m_pCountedCS = NULL; | 139 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
| 85 } | 140 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); |
| 86 CPDF_ShadingPattern::~CPDF_ShadingPattern() | 141 if (m_pCS) { |
| 87 { | 142 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
| 88 Clear(); | 143 } |
| 89 } | 144 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); |
| 90 void CPDF_ShadingPattern::Clear() | 145 return TRUE; |
| 91 { | 146 } |
| 92 for (int i = 0; i < m_nFuncs; i ++) { | 147 FX_BOOL CPDF_ShadingPattern::Reload() { |
| 93 delete m_pFunctions[i]; | 148 Clear(); |
| 94 m_pFunctions[i] = NULL; | 149 return Load(); |
| 95 } | 150 } |
| 96 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; | 151 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
| 97 if (pCS && m_pDocument) { | 152 CPDF_Function** pFuncs, |
| 98 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 153 int nFuncs, |
| 99 } | 154 CPDF_ColorSpace* pCS) { |
| 100 m_ShadingType = 0; | 155 m_Stream.LoadAllData(pShadingStream); |
| 101 m_pCS = NULL; | 156 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); |
| 102 m_pCountedCS = NULL; | 157 m_pFuncs = pFuncs; |
| 103 m_nFuncs = 0; | 158 m_nFuncs = nFuncs; |
| 104 } | 159 m_pCS = pCS; |
| 105 FX_BOOL CPDF_ShadingPattern::Load() | 160 CPDF_Dictionary* pDict = pShadingStream->GetDict(); |
| 106 { | 161 m_nCoordBits = pDict->GetInteger(FX_BSTRC("BitsPerCoordinate")); |
| 107 if (m_ShadingType != 0) { | 162 m_nCompBits = pDict->GetInteger(FX_BSTRC("BitsPerComponent")); |
| 108 return TRUE; | 163 m_nFlagBits = pDict->GetInteger(FX_BSTRC("BitsPerFlag")); |
| 109 } | 164 if (!m_nCoordBits || !m_nCompBits) { |
| 110 CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : N
ULL; | 165 return FALSE; |
| 111 if (pShadingDict == NULL) { | 166 } |
| 112 return FALSE; | 167 int nComps = pCS->CountComponents(); |
| 113 } | 168 if (nComps > 8) { |
| 114 if (m_nFuncs) { | 169 return FALSE; |
| 115 for (int i = 0; i < m_nFuncs; i ++) | 170 } |
| 116 delete m_pFunctions[i]; | 171 m_nComps = nFuncs ? 1 : nComps; |
| 117 m_nFuncs = 0; | 172 if (((int)m_nComps < 0) || m_nComps > 8) { |
| 118 } | 173 return FALSE; |
| 119 CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function")); | 174 } |
| 120 if (pFunc) { | 175 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; |
| 121 if (pFunc->GetType() == PDFOBJ_ARRAY) { | 176 m_CompMax = (1 << m_nCompBits) - 1; |
| 122 m_nFuncs = ((CPDF_Array*)pFunc)->GetCount(); | 177 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); |
| 123 if (m_nFuncs > 4) { | 178 if (pDecode == NULL || pDecode->GetCount() != 4 + m_nComps * 2) { |
| 124 m_nFuncs = 4; | 179 return FALSE; |
| 125 } | 180 } |
| 126 for (int i = 0; i < m_nFuncs; i ++) { | 181 m_xmin = pDecode->GetNumber(0); |
| 127 m_pFunctions[i] = CPDF_Function::Load(((CPDF_Array*)pFunc)->GetE
lementValue(i)); | 182 m_xmax = pDecode->GetNumber(1); |
| 128 } | 183 m_ymin = pDecode->GetNumber(2); |
| 129 } else { | 184 m_ymax = pDecode->GetNumber(3); |
| 130 m_pFunctions[0] = CPDF_Function::Load(pFunc); | 185 for (FX_DWORD i = 0; i < m_nComps; i++) { |
| 131 m_nFuncs = 1; | 186 m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4); |
| 132 } | 187 m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5); |
| 133 } | 188 } |
| 134 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); | 189 return TRUE; |
| 135 if (pCSObj == NULL) { | 190 } |
| 136 return FALSE; | 191 FX_DWORD CPDF_MeshStream::GetFlag() { |
| 137 } | 192 return m_BitStream.GetBits(m_nFlagBits) & 0x03; |
| 138 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 193 } |
| 139 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); | 194 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) { |
| 140 if (m_pCS) { | 195 if (m_nCoordBits == 32) { |
| 141 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 196 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * |
| 142 } | 197 (m_xmax - m_xmin) / (double)m_CoordMax); |
| 143 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); | 198 y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * |
| 144 return TRUE; | 199 (m_ymax - m_ymin) / (double)m_CoordMax); |
| 145 } | 200 } else { |
| 146 FX_BOOL CPDF_ShadingPattern::Reload() | 201 x = m_xmin + |
| 147 { | 202 m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_CoordMax; |
| 148 Clear(); | 203 y = m_ymin + |
| 149 return Load(); | 204 m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_CoordMax; |
| 150 } | 205 } |
| 151 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, CPDF_Function** pFunc
s, int nFuncs, CPDF_ColorSpace* pCS) | 206 } |
| 152 { | 207 void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) { |
| 153 m_Stream.LoadAllData(pShadingStream); | 208 FX_DWORD i; |
| 154 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); | 209 FX_FLOAT color_value[8]; |
| 155 m_pFuncs = pFuncs; | 210 for (i = 0; i < m_nComps; i++) { |
| 156 m_nFuncs = nFuncs; | 211 color_value[i] = m_ColorMin[i] + |
| 157 m_pCS = pCS; | 212 m_BitStream.GetBits(m_nCompBits) * |
| 158 CPDF_Dictionary* pDict = pShadingStream->GetDict(); | 213 (m_ColorMax[i] - m_ColorMin[i]) / m_CompMax; |
| 159 m_nCoordBits = pDict->GetInteger(FX_BSTRC("BitsPerCoordinate")); | 214 } |
| 160 m_nCompBits = pDict->GetInteger(FX_BSTRC("BitsPerComponent")); | 215 if (m_nFuncs) { |
| 161 m_nFlagBits = pDict->GetInteger(FX_BSTRC("BitsPerFlag")); | 216 static const int kMaxResults = 8; |
| 162 if (!m_nCoordBits || !m_nCompBits) { | 217 FX_FLOAT result[kMaxResults]; |
| 163 return FALSE; | 218 int nResults; |
| 164 } | 219 FXSYS_memset(result, 0, sizeof(result)); |
| 165 int nComps = pCS->CountComponents(); | 220 for (FX_DWORD i = 0; i < m_nFuncs; i++) { |
| 166 if (nComps > 8) { | 221 if (m_pFuncs[i] && m_pFuncs[i]->CountOutputs() <= kMaxResults) { |
| 167 return FALSE; | 222 m_pFuncs[i]->Call(color_value, 1, result, nResults); |
| 168 } | 223 } |
| 169 m_nComps = nFuncs ? 1 : nComps; | 224 } |
| 170 if (((int)m_nComps < 0) || m_nComps > 8) { | 225 m_pCS->GetRGB(result, r, g, b); |
| 171 return FALSE; | 226 } else { |
| 172 } | 227 m_pCS->GetRGB(color_value, r, g, b); |
| 173 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; | 228 } |
| 174 m_CompMax = (1 << m_nCompBits) - 1; | 229 } |
| 175 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); | 230 FX_DWORD CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex, |
| 176 if (pDecode == NULL || pDecode->GetCount() != 4 + m_nComps * 2) { | 231 CFX_AffineMatrix* pObject2Bitmap) { |
| 177 return FALSE; | 232 FX_DWORD flag = GetFlag(); |
| 178 } | 233 GetCoords(vertex.x, vertex.y); |
| 179 m_xmin = pDecode->GetNumber(0); | 234 pObject2Bitmap->Transform(vertex.x, vertex.y); |
| 180 m_xmax = pDecode->GetNumber(1); | 235 GetColor(vertex.r, vertex.g, vertex.b); |
| 181 m_ymin = pDecode->GetNumber(2); | 236 m_BitStream.ByteAlign(); |
| 182 m_ymax = pDecode->GetNumber(3); | 237 return flag; |
| 183 for (FX_DWORD i = 0; i < m_nComps; i ++) { | 238 } |
| 184 m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4); | 239 FX_BOOL CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex, |
| 185 m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5); | 240 int count, |
| 186 } | 241 CFX_AffineMatrix* pObject2Bitmap) { |
| 187 return TRUE; | 242 for (int i = 0; i < count; i++) { |
| 188 } | 243 if (m_BitStream.IsEOF()) { |
| 189 FX_DWORD CPDF_MeshStream::GetFlag() | 244 return FALSE; |
| 190 { | 245 } |
| 191 return m_BitStream.GetBits(m_nFlagBits) & 0x03; | 246 GetCoords(vertex[i].x, vertex[i].y); |
| 192 } | 247 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); |
| 193 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) | 248 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); |
| 194 { | |
| 195 if (m_nCoordBits == 32) { | |
| 196 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_
xmin) / (double)m_CoordMax); | |
| 197 y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_
ymin) / (double)m_CoordMax); | |
| 198 } else { | |
| 199 x = m_xmin + m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_C
oordMax; | |
| 200 y = m_ymin + m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_C
oordMax; | |
| 201 } | |
| 202 } | |
| 203 void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) | |
| 204 { | |
| 205 FX_DWORD i; | |
| 206 FX_FLOAT color_value[8]; | |
| 207 for (i = 0; i < m_nComps; i ++) { | |
| 208 color_value[i] = m_ColorMin[i] + m_BitStream.GetBits(m_nCompBits) * (m_C
olorMax[i] - m_ColorMin[i]) / m_CompMax; | |
| 209 } | |
| 210 if (m_nFuncs) { | |
| 211 static const int kMaxResults = 8; | |
| 212 FX_FLOAT result[kMaxResults]; | |
| 213 int nResults; | |
| 214 FXSYS_memset(result, 0, sizeof(result)); | |
| 215 for (FX_DWORD i = 0; i < m_nFuncs; i ++) { | |
| 216 if (m_pFuncs[i] && m_pFuncs[i]->CountOutputs() <= kMaxResults) { | |
| 217 m_pFuncs[i]->Call(color_value, 1, result, nResults); | |
| 218 } | |
| 219 } | |
| 220 m_pCS->GetRGB(result, r, g, b); | |
| 221 } else { | |
| 222 m_pCS->GetRGB(color_value, r, g, b); | |
| 223 } | |
| 224 } | |
| 225 FX_DWORD CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* p
Object2Bitmap) | |
| 226 { | |
| 227 FX_DWORD flag = GetFlag(); | |
| 228 GetCoords(vertex.x, vertex.y); | |
| 229 pObject2Bitmap->Transform(vertex.x, vertex.y); | |
| 230 GetColor(vertex.r, vertex.g, vertex.b); | |
| 231 m_BitStream.ByteAlign(); | 249 m_BitStream.ByteAlign(); |
| 232 return flag; | 250 } |
| 233 } | 251 return TRUE; |
| 234 FX_BOOL CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex, int count, CFX_Af
fineMatrix* pObject2Bitmap) | 252 } |
| 235 { | 253 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, |
| 236 for (int i = 0; i < count; i ++) { | 254 int type, |
| 237 if (m_BitStream.IsEOF()) { | 255 const CFX_AffineMatrix* pMatrix, |
| 238 return FALSE; | 256 CPDF_Function** pFuncs, |
| 239 } | 257 int nFuncs, |
| 240 GetCoords(vertex[i].x, vertex[i].y); | 258 CPDF_ColorSpace* pCS) { |
| 241 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); | 259 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM || |
| 242 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); | 260 pFuncs == NULL || pCS == NULL) { |
| 243 m_BitStream.ByteAlign(); | 261 return CFX_FloatRect(0, 0, 0, 0); |
| 244 } | 262 } |
| 245 return TRUE; | 263 CPDF_MeshStream stream; |
| 246 } | 264 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) { |
| 247 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, int type, const CFX_AffineMa
trix* pMatrix, | 265 return CFX_FloatRect(0, 0, 0, 0); |
| 248 CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpac
e* pCS) | 266 } |
| 249 { | 267 CFX_FloatRect rect; |
| 250 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM || pFuncs == NULL
|| pCS == NULL) { | 268 FX_BOOL bStarted = FALSE; |
| 251 return CFX_FloatRect(0, 0, 0, 0); | 269 FX_BOOL bGouraud = type == 4 || type == 5; |
| 252 } | 270 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); |
| 253 CPDF_MeshStream stream; | 271 int full_color_count = (type == 6 || type == 7) ? 4 : 1; |
| 254 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) { | 272 while (!stream.m_BitStream.IsEOF()) { |
| 255 return CFX_FloatRect(0, 0, 0, 0); | 273 FX_DWORD flag = 0; |
| 256 } | 274 if (type != 5) { |
| 257 CFX_FloatRect rect; | 275 flag = stream.GetFlag(); |
| 258 FX_BOOL bStarted = FALSE; | 276 } |
| 259 FX_BOOL bGouraud = type == 4 || type == 5; | 277 int point_count = full_point_count, color_count = full_color_count; |
| 260 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); | 278 if (!bGouraud && flag) { |
| 261 int full_color_count = (type == 6 || type == 7) ? 4 : 1; | 279 point_count -= 4; |
| 262 while (!stream.m_BitStream.IsEOF()) { | 280 color_count -= 2; |
| 263 FX_DWORD flag = 0; | 281 } |
| 264 if (type != 5) { | 282 for (int i = 0; i < point_count; i++) { |
| 265 flag = stream.GetFlag(); | 283 FX_FLOAT x, y; |
| 266 } | 284 stream.GetCoords(x, y); |
| 267 int point_count = full_point_count, color_count = full_color_count; | 285 if (bStarted) { |
| 268 if (!bGouraud && flag) { | 286 rect.UpdateRect(x, y); |
| 269 point_count -= 4; | 287 } else { |
| 270 color_count -= 2; | 288 rect.InitRect(x, y); |
| 271 } | 289 bStarted = TRUE; |
| 272 for (int i = 0; i < point_count; i ++) { | 290 } |
| 273 FX_FLOAT x, y; | 291 } |
| 274 stream.GetCoords(x, y); | 292 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
| 275 if (bStarted) { | 293 color_count); |
| 276 rect.UpdateRect(x, y); | 294 if (bGouraud) { |
| 277 } else { | 295 stream.m_BitStream.ByteAlign(); |
| 278 rect.InitRect(x, y); | 296 } |
| 279 bStarted = TRUE; | 297 } |
| 280 } | 298 rect.Transform(pMatrix); |
| 281 } | 299 return rect; |
| 282 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * color
_count); | 300 } |
| 283 if (bGouraud) { | |
| 284 stream.m_BitStream.ByteAlign(); | |
| 285 } | |
| 286 } | |
| 287 rect.Transform(pMatrix); | |
| 288 return rect; | |
| 289 } | |
| OLD | NEW |