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

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 2287313004: Make CPDF_TextState have a CPDF_TextStateData rather than inheriting one. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@moar_better_constness
Patch Set: Casts, Casts, New -> Emplace. Created 4 years, 3 months 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 "core/fpdfapi/fpdf_page/pageint.h" 7 #include "core/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 m_mtContentToUser = *pmtContentToUser; 228 m_mtContentToUser = *pmtContentToUser;
229 if (!m_pResources) 229 if (!m_pResources)
230 m_pResources = m_pParentResources; 230 m_pResources = m_pParentResources;
231 if (!m_pResources) 231 if (!m_pResources)
232 m_pResources = m_pPageResources; 232 m_pResources = m_pPageResources;
233 if (pBBox) 233 if (pBBox)
234 m_BBox = *pBBox; 234 m_BBox = *pBBox;
235 if (pStates) { 235 if (pStates) {
236 m_pCurStates->Copy(*pStates); 236 m_pCurStates->Copy(*pStates);
237 } else { 237 } else {
238 m_pCurStates->m_GeneralState.New(); 238 m_pCurStates->m_GeneralState.Emplace();
239 m_pCurStates->m_GraphState.New(); 239 m_pCurStates->m_GraphState.Emplace();
240 m_pCurStates->m_TextState.New(); 240 m_pCurStates->m_TextState.Emplace();
241 m_pCurStates->m_ColorState.New(); 241 m_pCurStates->m_ColorState.Emplace();
242 } 242 }
243 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { 243 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
244 m_Type3Data[i] = 0.0; 244 m_Type3Data[i] = 0.0;
245 } 245 }
246 } 246 }
247 247
248 CPDF_StreamContentParser::~CPDF_StreamContentParser() { 248 CPDF_StreamContentParser::~CPDF_StreamContentParser() {
249 ClearAllParams(); 249 ClearAllParams();
250 FX_Free(m_pPathPoints); 250 FX_Free(m_pPathPoints);
251 if (m_pLastImageDict) { 251 if (m_pLastImageDict) {
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 m_CurContentMark.SetNull(); 816 m_CurContentMark.SetNull();
817 return; 817 return;
818 } 818 }
819 m_CurContentMark.GetPrivateCopy()->DeleteLastMark(); 819 m_CurContentMark.GetPrivateCopy()->DeleteLastMark();
820 } 820 }
821 821
822 void CPDF_StreamContentParser::Handle_EndText() { 822 void CPDF_StreamContentParser::Handle_EndText() {
823 if (m_ClipTextList.empty()) 823 if (m_ClipTextList.empty())
824 return; 824 return;
825 825
826 if (TextRenderingModeIsClipMode( 826 if (TextRenderingModeIsClipMode(m_pCurStates->m_TextState.GetTextMode()))
827 m_pCurStates->m_TextState.GetObject()->m_TextMode)) {
828 m_pCurStates->m_ClipPath.AppendTexts(&m_ClipTextList); 827 m_pCurStates->m_ClipPath.AppendTexts(&m_ClipTextList);
829 } 828
830 m_ClipTextList.clear(); 829 m_ClipTextList.clear();
831 } 830 }
832 831
833 void CPDF_StreamContentParser::Handle_FillPath() { 832 void CPDF_StreamContentParser::Handle_FillPath() {
834 AddPathObject(FXFILL_WINDING, FALSE); 833 AddPathObject(FXFILL_WINDING, FALSE);
835 } 834 }
836 835
837 void CPDF_StreamContentParser::Handle_FillPathOld() { 836 void CPDF_StreamContentParser::Handle_FillPathOld() {
838 AddPathObject(FXFILL_WINDING, FALSE); 837 AddPathObject(FXFILL_WINDING, FALSE);
839 } 838 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (pShading->IsMeshShading()) 1106 if (pShading->IsMeshShading())
1108 bbox.Intersect(GetShadingBBox(pShading, pObj->m_Matrix)); 1107 bbox.Intersect(GetShadingBBox(pShading, pObj->m_Matrix));
1109 pObj->m_Left = bbox.left; 1108 pObj->m_Left = bbox.left;
1110 pObj->m_Right = bbox.right; 1109 pObj->m_Right = bbox.right;
1111 pObj->m_Top = bbox.top; 1110 pObj->m_Top = bbox.top;
1112 pObj->m_Bottom = bbox.bottom; 1111 pObj->m_Bottom = bbox.bottom;
1113 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); 1112 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj));
1114 } 1113 }
1115 1114
1116 void CPDF_StreamContentParser::Handle_SetCharSpace() { 1115 void CPDF_StreamContentParser::Handle_SetCharSpace() {
1117 m_pCurStates->m_TextState.GetPrivateCopy()->m_CharSpace = GetNumber(0); 1116 m_pCurStates->m_TextState.SetCharSpace(GetNumber(0));
1118 } 1117 }
1119 1118
1120 void CPDF_StreamContentParser::Handle_MoveTextPoint() { 1119 void CPDF_StreamContentParser::Handle_MoveTextPoint() {
1121 m_pCurStates->m_TextLineX += GetNumber(1); 1120 m_pCurStates->m_TextLineX += GetNumber(1);
1122 m_pCurStates->m_TextLineY += GetNumber(0); 1121 m_pCurStates->m_TextLineY += GetNumber(0);
1123 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX; 1122 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
1124 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY; 1123 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
1125 } 1124 }
1126 1125
1127 void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() { 1126 void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() {
1128 Handle_MoveTextPoint(); 1127 Handle_MoveTextPoint();
1129 m_pCurStates->m_TextLeading = -GetNumber(0); 1128 m_pCurStates->m_TextLeading = -GetNumber(0);
1130 } 1129 }
1131 1130
1132 void CPDF_StreamContentParser::Handle_SetFont() { 1131 void CPDF_StreamContentParser::Handle_SetFont() {
1133 FX_FLOAT fs = GetNumber(0); 1132 FX_FLOAT fs = GetNumber(0);
1134 if (fs == 0) { 1133 if (fs == 0) {
1135 fs = m_DefFontSize; 1134 fs = m_DefFontSize;
1136 } 1135 }
1137 m_pCurStates->m_TextState.GetPrivateCopy()->m_FontSize = fs; 1136 m_pCurStates->m_TextState.SetFontSize(fs);
1138 CPDF_Font* pFont = FindFont(GetString(1)); 1137 CPDF_Font* pFont = FindFont(GetString(1));
1139 if (pFont) { 1138 if (pFont) {
1140 m_pCurStates->m_TextState.SetFont(pFont); 1139 m_pCurStates->m_TextState.SetFont(pFont);
1141 } 1140 }
1142 } 1141 }
1143 1142
1144 CPDF_Object* CPDF_StreamContentParser::FindResourceObj( 1143 CPDF_Object* CPDF_StreamContentParser::FindResourceObj(
1145 const CFX_ByteString& type, 1144 const CFX_ByteString& type,
1146 const CFX_ByteString& name) { 1145 const CFX_ByteString& name) {
1147 if (!m_pResources) 1146 if (!m_pResources)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 } else { 1235 } else {
1237 m_pCurStates->m_TextY -= 1236 m_pCurStates->m_TextY -=
1238 (fInitKerning * m_pCurStates->m_TextState.GetFontSize()) / 1000; 1237 (fInitKerning * m_pCurStates->m_TextState.GetFontSize()) / 1000;
1239 } 1238 }
1240 } 1239 }
1241 if (nsegs == 0) { 1240 if (nsegs == 0) {
1242 return; 1241 return;
1243 } 1242 }
1244 const TextRenderingMode text_mode = 1243 const TextRenderingMode text_mode =
1245 pFont->IsType3Font() ? TextRenderingMode::MODE_FILL 1244 pFont->IsType3Font() ? TextRenderingMode::MODE_FILL
1246 : m_pCurStates->m_TextState.GetObject()->m_TextMode; 1245 : m_pCurStates->m_TextState.GetTextMode();
1247 { 1246 {
1248 std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject); 1247 std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject);
1249 m_pLastTextObject = pText.get(); 1248 m_pLastTextObject = pText.get();
1250 SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE); 1249 SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE);
1251 if (TextRenderingModeIsStrokeMode(text_mode)) { 1250 if (TextRenderingModeIsStrokeMode(text_mode)) {
1252 FX_FLOAT* pCTM = pText->m_TextState.GetPrivateCopy()->m_CTM; 1251 FX_FLOAT* pCTM = pText->m_TextState.GetMutableCTM();
1253 pCTM[0] = m_pCurStates->m_CTM.a; 1252 pCTM[0] = m_pCurStates->m_CTM.a;
1254 pCTM[1] = m_pCurStates->m_CTM.c; 1253 pCTM[1] = m_pCurStates->m_CTM.c;
1255 pCTM[2] = m_pCurStates->m_CTM.b; 1254 pCTM[2] = m_pCurStates->m_CTM.b;
1256 pCTM[3] = m_pCurStates->m_CTM.d; 1255 pCTM[3] = m_pCurStates->m_CTM.d;
1257 } 1256 }
1258 pText->SetSegments(pStrs, pKerning, nsegs); 1257 pText->SetSegments(pStrs, pKerning, nsegs);
1259 pText->m_PosX = m_pCurStates->m_TextX; 1258 pText->m_PosX = m_pCurStates->m_TextX;
1260 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; 1259 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise;
1261 ConvertTextSpace(pText->m_PosX, pText->m_PosY); 1260 ConvertTextSpace(pText->m_PosX, pText->m_PosY);
1262 FX_FLOAT x_advance; 1261 FX_FLOAT x_advance;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 m_pCurStates->m_TextLineX = 0; 1350 m_pCurStates->m_TextLineX = 0;
1352 m_pCurStates->m_TextLineY = 0; 1351 m_pCurStates->m_TextLineY = 0;
1353 } 1352 }
1354 1353
1355 void CPDF_StreamContentParser::OnChangeTextMatrix() { 1354 void CPDF_StreamContentParser::OnChangeTextMatrix() {
1356 CFX_Matrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f, 0.0f, 1355 CFX_Matrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f, 0.0f,
1357 0.0f); 1356 0.0f);
1358 text_matrix.Concat(m_pCurStates->m_TextMatrix); 1357 text_matrix.Concat(m_pCurStates->m_TextMatrix);
1359 text_matrix.Concat(m_pCurStates->m_CTM); 1358 text_matrix.Concat(m_pCurStates->m_CTM);
1360 text_matrix.Concat(m_mtContentToUser); 1359 text_matrix.Concat(m_mtContentToUser);
1361 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetPrivateCopy()->m_Matrix; 1360 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetMutableMatrix();
1362 pTextMatrix[0] = text_matrix.a; 1361 pTextMatrix[0] = text_matrix.a;
1363 pTextMatrix[1] = text_matrix.c; 1362 pTextMatrix[1] = text_matrix.c;
1364 pTextMatrix[2] = text_matrix.b; 1363 pTextMatrix[2] = text_matrix.b;
1365 pTextMatrix[3] = text_matrix.d; 1364 pTextMatrix[3] = text_matrix.d;
1366 } 1365 }
1367 1366
1368 void CPDF_StreamContentParser::Handle_SetTextRenderMode() { 1367 void CPDF_StreamContentParser::Handle_SetTextRenderMode() {
1369 int mode = GetInteger(0); 1368 TextRenderingMode mode;
1370 SetTextRenderingModeFromInt( 1369 if (SetTextRenderingModeFromInt(GetInteger(0), &mode))
1371 mode, &m_pCurStates->m_TextState.GetPrivateCopy()->m_TextMode); 1370 m_pCurStates->m_TextState.SetTextMode(mode);
1372 } 1371 }
1373 1372
1374 void CPDF_StreamContentParser::Handle_SetTextRise() { 1373 void CPDF_StreamContentParser::Handle_SetTextRise() {
1375 m_pCurStates->m_TextRise = GetNumber(0); 1374 m_pCurStates->m_TextRise = GetNumber(0);
1376 } 1375 }
1377 1376
1378 void CPDF_StreamContentParser::Handle_SetWordSpace() { 1377 void CPDF_StreamContentParser::Handle_SetWordSpace() {
1379 m_pCurStates->m_TextState.GetPrivateCopy()->m_WordSpace = GetNumber(0); 1378 m_pCurStates->m_TextState.SetWordSpace(GetNumber(0));
1380 } 1379 }
1381 1380
1382 void CPDF_StreamContentParser::Handle_SetHorzScale() { 1381 void CPDF_StreamContentParser::Handle_SetHorzScale() {
1383 if (m_ParamCount != 1) { 1382 if (m_ParamCount != 1) {
1384 return; 1383 return;
1385 } 1384 }
1386 m_pCurStates->m_TextHorzScale = GetNumber(0) / 100; 1385 m_pCurStates->m_TextHorzScale = GetNumber(0) / 100;
1387 OnChangeTextMatrix(); 1386 OnChangeTextMatrix();
1388 } 1387 }
1389 1388
(...skipping 27 matching lines...) Expand all
1417 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 1416 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
1418 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 1417 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
1419 } 1418 }
1420 1419
1421 void CPDF_StreamContentParser::Handle_NextLineShowText() { 1420 void CPDF_StreamContentParser::Handle_NextLineShowText() {
1422 Handle_MoveToNextLine(); 1421 Handle_MoveToNextLine();
1423 Handle_ShowText(); 1422 Handle_ShowText();
1424 } 1423 }
1425 1424
1426 void CPDF_StreamContentParser::Handle_NextLineShowText_Space() { 1425 void CPDF_StreamContentParser::Handle_NextLineShowText_Space() {
1427 m_pCurStates->m_TextState.GetPrivateCopy()->m_WordSpace = GetNumber(2); 1426 m_pCurStates->m_TextState.SetWordSpace(GetNumber(2));
1428 m_pCurStates->m_TextState.GetPrivateCopy()->m_CharSpace = GetNumber(1); 1427 m_pCurStates->m_TextState.SetCharSpace(GetNumber(1));
1429 Handle_NextLineShowText(); 1428 Handle_NextLineShowText();
1430 } 1429 }
1431 1430
1432 void CPDF_StreamContentParser::Handle_Invalid() {} 1431 void CPDF_StreamContentParser::Handle_Invalid() {}
1433 1432
1434 void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) { 1433 void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) {
1435 m_PathCurrentX = x; 1434 m_PathCurrentX = x;
1436 m_PathCurrentY = y; 1435 m_PathCurrentY = y;
1437 if (flag == FXPT_MOVETO) { 1436 if (flag == FXPT_MOVETO) {
1438 m_PathStartX = x; 1437 m_PathStartX = x;
(...skipping 25 matching lines...) Expand all
1464 } 1463 }
1465 1464
1466 void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) { 1465 void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) {
1467 int PathPointCount = m_PathPointCount; 1466 int PathPointCount = m_PathPointCount;
1468 uint8_t PathClipType = m_PathClipType; 1467 uint8_t PathClipType = m_PathClipType;
1469 m_PathPointCount = 0; 1468 m_PathPointCount = 0;
1470 m_PathClipType = 0; 1469 m_PathClipType = 0;
1471 if (PathPointCount <= 1) { 1470 if (PathPointCount <= 1) {
1472 if (PathPointCount && PathClipType) { 1471 if (PathPointCount && PathClipType) {
1473 CPDF_Path path; 1472 CPDF_Path path;
1474 path.New()->AppendRect(0, 0, 0, 0); 1473 path.Emplace()->AppendRect(0, 0, 0, 0);
1475 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE); 1474 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE);
1476 } 1475 }
1477 return; 1476 return;
1478 } 1477 }
1479 if (PathPointCount && 1478 if (PathPointCount &&
1480 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { 1479 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) {
1481 PathPointCount--; 1480 PathPointCount--;
1482 } 1481 }
1483 CPDF_Path Path; 1482 CPDF_Path Path;
1484 CFX_PathData* pPathData = Path.New(); 1483 CFX_PathData* pPathData = Path.Emplace();
1485 pPathData->SetPointCount(PathPointCount); 1484 pPathData->SetPointCount(PathPointCount);
1486 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, 1485 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints,
1487 sizeof(FX_PATHPOINT) * PathPointCount); 1486 sizeof(FX_PATHPOINT) * PathPointCount);
1488 CFX_Matrix matrix = m_pCurStates->m_CTM; 1487 CFX_Matrix matrix = m_pCurStates->m_CTM;
1489 matrix.Concat(m_mtContentToUser); 1488 matrix.Concat(m_mtContentToUser);
1490 if (bStroke || FillType) { 1489 if (bStroke || FillType) {
1491 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); 1490 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject);
1492 pPathObj->m_bStroke = bStroke; 1491 pPathObj->m_bStroke = bStroke;
1493 pPathObj->m_FillType = FillType; 1492 pPathObj->m_FillType = FillType;
1494 pPathObj->m_Path = Path; 1493 pPathObj->m_Path = Path;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 } else { 1684 } else {
1686 PDF_ReplaceAbbr(pElement); 1685 PDF_ReplaceAbbr(pElement);
1687 } 1686 }
1688 } 1687 }
1689 break; 1688 break;
1690 } 1689 }
1691 default: 1690 default:
1692 break; 1691 break;
1693 } 1692 }
1694 } 1693 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp ('k') | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698