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 "core/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPair* table, | 90 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPair* table, |
| 91 size_t count, | 91 size_t count, |
| 92 const CFX_ByteStringC& abbr) { | 92 const CFX_ByteStringC& abbr) { |
| 93 auto it = std::find_if( | 93 auto it = std::find_if( |
| 94 table, table + count, | 94 table, table + count, |
| 95 [abbr](const PDF_AbbrPair& pair) { return pair.abbr == abbr; }); | 95 [abbr](const PDF_AbbrPair& pair) { return pair.abbr == abbr; }); |
| 96 return it != table + count ? CFX_ByteStringC(it->full_name) | 96 return it != table + count ? CFX_ByteStringC(it->full_name) |
| 97 : CFX_ByteStringC(); | 97 : CFX_ByteStringC(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, | 100 CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading, |
| 101 ShadingType type, | 101 const CFX_Matrix& matrix) { |
| 102 const CFX_Matrix& matrix, | 102 ShadingType type = pShading->GetShadingType(); |
| 103 CPDF_Function** pFuncs, | 103 CPDF_Stream* pStream = ToStream(pShading->GetShadingObject()); |
| 104 int nFuncs, | 104 CPDF_ColorSpace* pCS = pShading->GetCS(); |
| 105 CPDF_ColorSpace* pCS) { | 105 if (!pStream || !pCS) |
| 106 if (!pStream || !pFuncs || !pCS) | |
| 107 return CFX_FloatRect(0, 0, 0, 0); | 106 return CFX_FloatRect(0, 0, 0, 0); |
| 108 | 107 |
| 109 CPDF_MeshStream stream; | 108 CPDF_MeshStream stream(pShading->GetFuncs(), pCS); |
| 110 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) | 109 if (!stream.Load(pStream)) |
| 111 return CFX_FloatRect(0, 0, 0, 0); | 110 return CFX_FloatRect(0, 0, 0, 0); |
| 112 | 111 |
| 113 CFX_FloatRect rect; | 112 CFX_FloatRect rect; |
| 114 bool bStarted = false; | 113 bool bStarted = false; |
| 115 bool bGouraud = type == kFreeFormGouraudTriangleMeshShading || | 114 bool bGouraud = type == kFreeFormGouraudTriangleMeshShading || |
| 116 type == kLatticeFormGouraudTriangleMeshShading; | 115 type == kLatticeFormGouraudTriangleMeshShading; |
| 117 | 116 |
| 118 int point_count = kSingleCoordinatePair; | 117 int point_count = kSingleCoordinatePair; |
| 119 if (type == kTensorProductPatchMeshShading) | 118 if (type == kTensorProductPatchMeshShading) |
| 120 point_count = kTensorCoordinatePairs; | 119 point_count = kTensorCoordinatePairs; |
| 121 else if (type == kCoonsPatchMeshShading) | 120 else if (type == kCoonsPatchMeshShading) |
| 122 point_count = kCoonsCoordinatePairs; | 121 point_count = kCoonsCoordinatePairs; |
| 123 | 122 |
| 124 int color_count = kSingleColorPerPatch; | 123 int color_count = kSingleColorPerPatch; |
| 125 if (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading) | 124 if (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading) |
| 126 color_count = kQuadColorsPerPatch; | 125 color_count = kQuadColorsPerPatch; |
| 127 | 126 |
| 128 while (!stream.m_BitStream.IsEOF()) { | 127 while (!stream.BitStream()->IsEOF()) { |
| 129 uint32_t flag = 0; | 128 uint32_t flag = 0; |
| 130 if (type != kLatticeFormGouraudTriangleMeshShading) | 129 if (type != kLatticeFormGouraudTriangleMeshShading) |
| 131 flag = stream.GetFlag(); | 130 flag = stream.GetFlag(); |
| 132 | 131 |
| 133 if (!bGouraud && flag) { | 132 if (!bGouraud && flag) { |
| 134 point_count -= 4; | 133 point_count -= 4; |
| 135 color_count -= 2; | 134 color_count -= 2; |
| 136 } | 135 } |
| 137 | 136 |
| 138 for (int i = 0; i < point_count; i++) { | 137 for (int i = 0; i < point_count; i++) { |
| 139 FX_FLOAT x; | 138 FX_FLOAT x; |
| 140 FX_FLOAT y; | 139 FX_FLOAT y; |
| 141 stream.GetCoords(x, y); | 140 stream.GetCoords(x, y); |
| 142 if (bStarted) { | 141 if (bStarted) { |
| 143 rect.UpdateRect(x, y); | 142 rect.UpdateRect(x, y); |
| 144 } else { | 143 } else { |
| 145 rect.InitRect(x, y); | 144 rect.InitRect(x, y); |
| 146 bStarted = true; | 145 bStarted = true; |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 148 stream.BitStream()->SkipBits(stream.comps() * stream.CompBits() * |
|
Tom Sepez
2016/05/23 19:09:33
pre-existing: this multiply scares me, m_nCompBits
Lei Zhang
2016/05/23 19:26:20
Switched to FX_SAFE_UINT32.
| |
| 150 color_count); | 149 color_count); |
| 151 if (bGouraud) | 150 if (bGouraud) |
| 152 stream.m_BitStream.ByteAlign(); | 151 stream.BitStream()->ByteAlign(); |
| 153 } | 152 } |
| 154 rect.Transform(&matrix); | 153 rect.Transform(&matrix); |
| 155 return rect; | 154 return rect; |
| 156 } | 155 } |
| 157 | 156 |
| 158 } // namespace | 157 } // namespace |
| 159 | 158 |
| 160 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr) { | 159 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr) { |
| 161 return PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), | 160 return PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), |
| 162 abbr); | 161 abbr); |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 | 1079 |
| 1081 void CPDF_StreamContentParser::Handle_ShadeFill() { | 1080 void CPDF_StreamContentParser::Handle_ShadeFill() { |
| 1082 CPDF_Pattern* pPattern = FindPattern(GetString(0), true); | 1081 CPDF_Pattern* pPattern = FindPattern(GetString(0), true); |
| 1083 if (!pPattern) | 1082 if (!pPattern) |
| 1084 return; | 1083 return; |
| 1085 | 1084 |
| 1086 CPDF_ShadingPattern* pShading = pPattern->AsShadingPattern(); | 1085 CPDF_ShadingPattern* pShading = pPattern->AsShadingPattern(); |
| 1087 if (!pShading) | 1086 if (!pShading) |
| 1088 return; | 1087 return; |
| 1089 | 1088 |
| 1090 if (!pShading->m_bShadingObj || !pShading->Load()) | 1089 if (!pShading->IsShadingObject() || !pShading->Load()) |
| 1091 return; | 1090 return; |
| 1092 | 1091 |
| 1093 std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject); | 1092 std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject); |
| 1094 pObj->m_pShading = pShading; | 1093 pObj->m_pShading = pShading; |
| 1095 SetGraphicStates(pObj.get(), FALSE, FALSE, FALSE); | 1094 SetGraphicStates(pObj.get(), FALSE, FALSE, FALSE); |
| 1096 pObj->m_Matrix = m_pCurStates->m_CTM; | 1095 pObj->m_Matrix = m_pCurStates->m_CTM; |
| 1097 pObj->m_Matrix.Concat(m_mtContentToUser); | 1096 pObj->m_Matrix.Concat(m_mtContentToUser); |
| 1098 CFX_FloatRect bbox = | 1097 CFX_FloatRect bbox = |
| 1099 pObj->m_ClipPath.IsNull() ? m_BBox : pObj->m_ClipPath.GetClipBox(); | 1098 pObj->m_ClipPath.IsNull() ? m_BBox : pObj->m_ClipPath.GetClipBox(); |
| 1100 if (pShading->IsMeshShading()) { | 1099 if (pShading->IsMeshShading()) |
| 1101 bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj), | 1100 bbox.Intersect(GetShadingBBox(pShading, pObj->m_Matrix)); |
| 1102 pShading->m_ShadingType, pObj->m_Matrix, | |
| 1103 pShading->m_pFunctions, pShading->m_nFuncs, | |
| 1104 pShading->m_pCS)); | |
| 1105 } | |
| 1106 pObj->m_Left = bbox.left; | 1101 pObj->m_Left = bbox.left; |
| 1107 pObj->m_Right = bbox.right; | 1102 pObj->m_Right = bbox.right; |
| 1108 pObj->m_Top = bbox.top; | 1103 pObj->m_Top = bbox.top; |
| 1109 pObj->m_Bottom = bbox.bottom; | 1104 pObj->m_Bottom = bbox.bottom; |
| 1110 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); | 1105 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); |
| 1111 } | 1106 } |
| 1112 | 1107 |
| 1113 void CPDF_StreamContentParser::Handle_SetCharSpace() { | 1108 void CPDF_StreamContentParser::Handle_SetCharSpace() { |
| 1114 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0); | 1109 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0); |
| 1115 } | 1110 } |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1698 } else { | 1693 } else { |
| 1699 PDF_ReplaceAbbr(pElement); | 1694 PDF_ReplaceAbbr(pElement); |
| 1700 } | 1695 } |
| 1701 } | 1696 } |
| 1702 break; | 1697 break; |
| 1703 } | 1698 } |
| 1704 default: | 1699 default: |
| 1705 break; | 1700 break; |
| 1706 } | 1701 } |
| 1707 } | 1702 } |
| OLD | NEW |