Chromium Code Reviews| 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 "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 #include "pageint.h" | 10 #include "pageint.h" |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1285 ReleaseColorSpace(); | 1285 ReleaseColorSpace(); |
| 1286 } | 1286 } |
| 1287 void CPDF_Color::ReleaseBuffer() | 1287 void CPDF_Color::ReleaseBuffer() |
| 1288 { | 1288 { |
| 1289 if (!m_pBuffer) { | 1289 if (!m_pBuffer) { |
| 1290 return; | 1290 return; |
| 1291 } | 1291 } |
| 1292 if (m_pCS->GetFamily() == PDFCS_PATTERN) { | 1292 if (m_pCS->GetFamily() == PDFCS_PATTERN) { |
| 1293 PatternValue* pvalue = (PatternValue*)m_pBuffer; | 1293 PatternValue* pvalue = (PatternValue*)m_pBuffer; |
| 1294 CPDF_Pattern* pPattern = pvalue->m_pPattern; | 1294 CPDF_Pattern* pPattern = pvalue->m_pPattern; |
| 1295 if (pPattern && pPattern->m_pDocument) { | 1295 if (pPattern && m_pDocument) { |
| 1296 pPattern->SaveColor(NULL); | 1296 CPDF_DocPageData *pPageData = m_pDocument->GetPageData(); |
| 1297 pPattern->m_pDocument->GetPageData()->ReleasePattern(pPattern->m_pPa tternObj); | 1297 if (!pPageData->IsForceClear()) { |
|
jun_fang
2014/09/01 22:44:03
need to check whether pPageData is NULL?
| |
| 1298 pPageData->ReleasePattern(pPattern->m_pPatternObj); | |
| 1299 } | |
| 1298 } | 1300 } |
| 1299 } | 1301 } |
| 1300 FX_Free(m_pBuffer); | 1302 FX_Free(m_pBuffer); |
| 1301 m_pBuffer = NULL; | 1303 m_pBuffer = NULL; |
| 1302 } | 1304 } |
| 1303 void CPDF_Color::ReleaseColorSpace() | 1305 void CPDF_Color::ReleaseColorSpace() |
| 1304 { | 1306 { |
| 1305 if (m_pCS && m_pCS->m_pDocument && m_pCS->GetArray()) { | 1307 if (m_pDocument && m_pCS && m_pCS->GetArray()) { |
| 1306 m_pCS->m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray()); | 1308 m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray()); |
| 1307 m_pCS = NULL; | 1309 m_pCS = NULL; |
| 1310 m_pDocument = NULL; | |
| 1308 } | 1311 } |
| 1309 } | 1312 } |
| 1310 void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) | 1313 void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) |
| 1311 { | 1314 { |
| 1312 if (m_pCS == pCS) { | 1315 if (m_pCS == pCS) { |
| 1313 if (m_pBuffer == NULL) { | 1316 if (m_pBuffer == NULL) { |
| 1314 m_pBuffer = pCS->CreateBuf(); | 1317 m_pBuffer = pCS->CreateBuf(); |
| 1315 } | 1318 } |
| 1316 ReleaseColorSpace(); | 1319 ReleaseColorSpace(); |
| 1317 m_pCS = pCS; | 1320 m_pCS = pCS; |
| 1321 m_pDocument = pCS->m_pDocument; | |
| 1318 return; | 1322 return; |
| 1319 } | 1323 } |
| 1320 ReleaseBuffer(); | 1324 ReleaseBuffer(); |
| 1321 ReleaseColorSpace(); | 1325 ReleaseColorSpace(); |
| 1322 m_pCS = pCS; | 1326 m_pCS = pCS; |
| 1327 m_pDocument = pCS->m_pDocument; | |
| 1323 if (m_pCS) { | 1328 if (m_pCS) { |
| 1324 m_pBuffer = pCS->CreateBuf(); | 1329 m_pBuffer = pCS->CreateBuf(); |
| 1325 pCS->GetDefaultColor(m_pBuffer); | 1330 pCS->GetDefaultColor(m_pBuffer); |
| 1326 } | 1331 } |
| 1327 } | 1332 } |
| 1328 void CPDF_Color::SetValue(FX_FLOAT* comps) | 1333 void CPDF_Color::SetValue(FX_FLOAT* comps) |
| 1329 { | 1334 { |
| 1330 if (m_pBuffer == NULL) { | 1335 if (m_pBuffer == NULL) { |
| 1331 return; | 1336 return; |
| 1332 } | 1337 } |
| 1333 if (m_pCS->GetFamily() != PDFCS_PATTERN) { | 1338 if (m_pCS->GetFamily() != PDFCS_PATTERN) { |
| 1334 FXSYS_memcpy32(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FL OAT)); | 1339 FXSYS_memcpy32(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FL OAT)); |
| 1335 } | 1340 } |
| 1336 } | 1341 } |
| 1337 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) | 1342 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) |
| 1338 { | 1343 { |
| 1339 if (ncomps > MAX_PATTERN_COLORCOMPS) { | 1344 if (ncomps > MAX_PATTERN_COLORCOMPS) { |
| 1340 return; | 1345 return; |
| 1341 } | 1346 } |
| 1342 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) { | 1347 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) { |
| 1343 if (m_pBuffer) { | 1348 if (m_pBuffer) { |
| 1344 FX_Free(m_pBuffer); | 1349 FX_Free(m_pBuffer); |
| 1345 } | 1350 } |
| 1346 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); | 1351 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); |
| 1347 m_pBuffer = m_pCS->CreateBuf(); | 1352 m_pBuffer = m_pCS->CreateBuf(); |
| 1348 } | 1353 } |
| 1349 CPDF_DocPageData* pDocPageData = NULL; | |
| 1350 PatternValue* pvalue = (PatternValue*)m_pBuffer; | 1354 PatternValue* pvalue = (PatternValue*)m_pBuffer; |
| 1351 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { | 1355 if (pvalue->m_pPattern && m_pDocument) { |
| 1352 pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData(); | 1356 CPDF_DocPageData *pDocPageData = m_pDocument->GetPageData(); |
| 1353 pvalue->m_pPattern->SaveColor(NULL); | 1357 if (pDocPageData && pDocPageData->IsForceClear()) { |
|
jun_fang
2014/09/01 22:44:03
should be "!pDocPageData->IsForceClear()"?
| |
| 1354 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); | 1358 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); |
| 1359 } | |
| 1355 } | 1360 } |
| 1356 pvalue->m_nComps = ncomps; | 1361 pvalue->m_nComps = ncomps; |
| 1357 pvalue->m_pPattern = pPattern; | 1362 pvalue->m_pPattern = pPattern; |
| 1358 if (pPattern) { | |
| 1359 pPattern->SaveColor(this); | |
| 1360 } | |
| 1361 if (ncomps) { | 1363 if (ncomps) { |
| 1362 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT)); | 1364 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT)); |
| 1363 } | 1365 } |
| 1364 } | 1366 } |
| 1365 void CPDF_Color::Copy(const CPDF_Color* pSrc) | 1367 void CPDF_Color::Copy(const CPDF_Color* pSrc) |
| 1366 { | 1368 { |
| 1367 ReleaseBuffer(); | 1369 ReleaseBuffer(); |
| 1368 ReleaseColorSpace(); | 1370 ReleaseColorSpace(); |
| 1369 m_pCS = pSrc->m_pCS; | 1371 m_pCS = pSrc->m_pCS; |
| 1370 if (m_pCS && m_pCS->m_pDocument) { | 1372 if (m_pCS && m_pCS->m_pDocument) { |
| 1371 CPDF_Array* pArray = m_pCS->GetArray(); | 1373 CPDF_Array* pArray = m_pCS->GetArray(); |
| 1372 if (pArray) { | 1374 if (pArray) { |
| 1373 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y); | 1375 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y); |
| 1374 } | 1376 } |
| 1375 } | 1377 } |
| 1376 if (m_pCS == NULL) { | 1378 if (m_pCS == NULL) { |
| 1377 return; | 1379 return; |
| 1378 } | 1380 } |
| 1379 m_pBuffer = m_pCS->CreateBuf(); | 1381 m_pBuffer = m_pCS->CreateBuf(); |
| 1380 FXSYS_memcpy32(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize()); | 1382 FXSYS_memcpy32(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize()); |
| 1381 if (m_pCS->GetFamily() == PDFCS_PATTERN) { | 1383 if (m_pCS->GetFamily() == PDFCS_PATTERN) { |
| 1382 PatternValue* pvalue = (PatternValue*)m_pBuffer; | 1384 PatternValue* pvalue = (PatternValue*)m_pBuffer; |
| 1383 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { | 1385 if (pvalue->m_pPattern && m_pDocument) { |
| 1384 pvalue->m_pPattern = pvalue->m_pPattern->m_pDocument->GetPageData()- >GetPattern(pvalue->m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_Par entMatrix); | 1386 pvalue->m_pPattern = m_pDocument->GetPageData()->GetPattern(pvalue-> m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_ParentMatrix); |
| 1385 } | 1387 } |
| 1386 } | 1388 } |
| 1387 } | 1389 } |
| 1388 FX_BOOL CPDF_Color::GetRGB(int& R, int& G, int& B) const | 1390 FX_BOOL CPDF_Color::GetRGB(int& R, int& G, int& B) const |
| 1389 { | 1391 { |
| 1390 if (m_pCS == NULL || m_pBuffer == NULL) { | 1392 if (m_pCS == NULL || m_pBuffer == NULL) { |
| 1391 return FALSE; | 1393 return FALSE; |
| 1392 } | 1394 } |
| 1393 FX_FLOAT r=0.0f, g=0.0f, b=0.0f; | 1395 FX_FLOAT r=0.0f, g=0.0f, b=0.0f; |
| 1394 if (!m_pCS->GetRGB(m_pBuffer, r, g, b)) { | 1396 if (!m_pCS->GetRGB(m_pBuffer, r, g, b)) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1422 PatternValue* pvalue = (PatternValue*)m_pBuffer; | 1424 PatternValue* pvalue = (PatternValue*)m_pBuffer; |
| 1423 return pvalue->m_nComps ? pvalue->m_Comps : NULL; | 1425 return pvalue->m_nComps ? pvalue->m_Comps : NULL; |
| 1424 } | 1426 } |
| 1425 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const | 1427 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const |
| 1426 { | 1428 { |
| 1427 if (m_pCS != other.m_pCS || m_pCS == NULL) { | 1429 if (m_pCS != other.m_pCS || m_pCS == NULL) { |
| 1428 return FALSE; | 1430 return FALSE; |
| 1429 } | 1431 } |
| 1430 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; | 1432 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; |
| 1431 } | 1433 } |
| OLD | NEW |