| 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 "../../../../third_party/base/numerics/safe_math.h" |
| 7 #include "../../../include/fxcrt/fx_basic.h" | 8 #include "../../../include/fxcrt/fx_basic.h" |
| 8 #include "../../../include/fxge/fx_ge.h" | 9 #include "../../../include/fxge/fx_ge.h" |
| 10 |
| 9 CFX_ClipRgn::CFX_ClipRgn(int width, int height) | 11 CFX_ClipRgn::CFX_ClipRgn(int width, int height) |
| 10 { | 12 { |
| 11 m_Type = RectI; | 13 m_Type = RectI; |
| 12 m_Box.left = m_Box.top = 0; | 14 m_Box.left = m_Box.top = 0; |
| 13 m_Box.right = width; | 15 m_Box.right = width; |
| 14 m_Box.bottom = height; | 16 m_Box.bottom = height; |
| 15 } | 17 } |
| 16 CFX_ClipRgn::CFX_ClipRgn(const FX_RECT& rect) | 18 CFX_ClipRgn::CFX_ClipRgn(const FX_RECT& rect) |
| 17 { | 19 { |
| 18 m_Type = RectI; | 20 m_Type = RectI; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 { | 115 { |
| 114 m_PointCount = m_AllocCount = 0; | 116 m_PointCount = m_AllocCount = 0; |
| 115 m_pPoints = NULL; | 117 m_pPoints = NULL; |
| 116 } | 118 } |
| 117 CFX_PathData::~CFX_PathData() | 119 CFX_PathData::~CFX_PathData() |
| 118 { | 120 { |
| 119 if (m_pPoints) { | 121 if (m_pPoints) { |
| 120 FX_Free(m_pPoints); | 122 FX_Free(m_pPoints); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 FX_BOOL CFX_PathData::SetPointCount(int nPoints) | 125 void CFX_PathData::SetPointCount(int nPoints) |
| 124 { | 126 { |
| 125 m_PointCount = nPoints; | 127 m_PointCount = nPoints; |
| 126 if (m_AllocCount < nPoints) { | 128 if (m_AllocCount < nPoints) { |
| 127 if (m_pPoints) { | 129 if (m_pPoints) { |
| 128 FX_Free(m_pPoints); | 130 FX_Free(m_pPoints); |
| 129 m_pPoints = NULL; | 131 m_pPoints = NULL; |
| 130 } | 132 } |
| 131 m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints); | 133 m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints); |
| 132 if (!m_pPoints) { | |
| 133 return FALSE; | |
| 134 } | |
| 135 m_AllocCount = nPoints; | 134 m_AllocCount = nPoints; |
| 136 } | 135 } |
| 137 return TRUE; | |
| 138 } | 136 } |
| 139 FX_BOOL CFX_PathData::AllocPointCount(int nPoints) | 137 void CFX_PathData::AllocPointCount(int nPoints) |
| 140 { | 138 { |
| 141 if (m_AllocCount < nPoints) { | 139 if (m_AllocCount < nPoints) { |
| 142 FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints); | 140 FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints); |
| 143 if (!pNewBuf) { | |
| 144 return FALSE; | |
| 145 } | |
| 146 if (m_PointCount) { | 141 if (m_PointCount) { |
| 147 FXSYS_memcpy32(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOIN
T)); | 142 FXSYS_memcpy32(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOIN
T)); |
| 148 } | 143 } |
| 149 if (m_pPoints) { | 144 if (m_pPoints) { |
| 150 FX_Free(m_pPoints); | 145 FX_Free(m_pPoints); |
| 151 } | 146 } |
| 152 m_pPoints = pNewBuf; | 147 m_pPoints = pNewBuf; |
| 153 m_AllocCount = nPoints; | 148 m_AllocCount = nPoints; |
| 154 } | 149 } |
| 155 return TRUE; | |
| 156 } | 150 } |
| 157 CFX_PathData::CFX_PathData(const CFX_PathData& src) | 151 CFX_PathData::CFX_PathData(const CFX_PathData& src) |
| 158 { | 152 { |
| 159 m_pPoints = NULL; | |
| 160 m_PointCount = m_AllocCount = src.m_PointCount; | 153 m_PointCount = m_AllocCount = src.m_PointCount; |
| 161 m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount); | 154 m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount); |
| 162 if (!m_pPoints) { | |
| 163 return; | |
| 164 } | |
| 165 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); | 155 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); |
| 166 } | 156 } |
| 167 void CFX_PathData::TrimPoints(int nPoints) | 157 void CFX_PathData::TrimPoints(int nPoints) |
| 168 { | 158 { |
| 169 if (m_PointCount <= nPoints) { | 159 if (m_PointCount <= nPoints) { |
| 170 return; | 160 return; |
| 171 } | 161 } |
| 172 SetPointCount(nPoints); | 162 SetPointCount(nPoints); |
| 173 } | 163 } |
| 174 FX_BOOL CFX_PathData::AddPointCount(int addPoints) | 164 void CFX_PathData::AddPointCount(int addPoints) |
| 175 { | 165 { |
| 176 int new_count = m_PointCount + addPoints; | 166 pdfium::base::CheckedNumeric<int> safe_new_count = m_PointCount; |
| 177 if (!AllocPointCount(new_count)) { | 167 safe_new_count += addPoints; |
| 178 return FALSE; | 168 int new_count = safe_new_count.ValueOrDie(); |
| 179 } | 169 AllocPointCount(new_count); |
| 180 m_PointCount = new_count; | 170 m_PointCount = new_count; |
| 181 return TRUE; | |
| 182 } | 171 } |
| 183 FX_BOOL CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* p
Matrix) | 172 void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMat
rix) |
| 184 { | 173 { |
| 185 int old_count = m_PointCount; | 174 int old_count = m_PointCount; |
| 186 if (!AddPointCount(pSrc->m_PointCount)) { | 175 AddPointCount(pSrc->m_PointCount); |
| 187 return FALSE; | 176 FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount *
sizeof(FX_PATHPOINT)); |
| 177 if (pMatrix) { |
| 178 for (int i = 0; i < pSrc->m_PointCount; i ++) { |
| 179 pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_
count + i].m_PointY); |
| 180 } |
| 188 } | 181 } |
| 189 FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount *
sizeof(FX_PATHPOINT)); | |
| 190 if (pMatrix == NULL) { | |
| 191 return TRUE; | |
| 192 } | |
| 193 for (int i = 0; i < pSrc->m_PointCount; i ++) { | |
| 194 pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_coun
t + i].m_PointY); | |
| 195 } | |
| 196 return TRUE; | |
| 197 } | 182 } |
| 198 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag) | 183 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag) |
| 199 { | 184 { |
| 200 ASSERT(index < m_PointCount); | 185 ASSERT(index < m_PointCount); |
| 201 m_pPoints[index].m_PointX = x; | 186 m_pPoints[index].m_PointX = x; |
| 202 m_pPoints[index].m_PointY = y; | 187 m_pPoints[index].m_PointY = y; |
| 203 m_pPoints[index].m_Flag = flag; | 188 m_pPoints[index].m_Flag = flag; |
| 204 } | 189 } |
| 205 FX_BOOL CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right,
FX_FLOAT top) | 190 void CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX
_FLOAT top) |
| 206 { | 191 { |
| 207 int old_count = m_PointCount; | 192 int old_count = m_PointCount; |
| 208 if (!AddPointCount(5)) { | 193 AddPointCount(5); |
| 209 return FALSE; | |
| 210 } | |
| 211 FX_PATHPOINT* pPoints = m_pPoints + old_count; | 194 FX_PATHPOINT* pPoints = m_pPoints + old_count; |
| 212 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left; | 195 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left; |
| 213 pPoints[2].m_PointX = pPoints[3].m_PointX = right; | 196 pPoints[2].m_PointX = pPoints[3].m_PointX = right; |
| 214 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom; | 197 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom; |
| 215 pPoints[1].m_PointY = pPoints[2].m_PointY = top; | 198 pPoints[1].m_PointY = pPoints[2].m_PointY = top; |
| 216 pPoints[0].m_Flag = FXPT_MOVETO; | 199 pPoints[0].m_Flag = FXPT_MOVETO; |
| 217 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO; | 200 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO; |
| 218 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; | 201 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; |
| 219 return TRUE; | |
| 220 } | 202 } |
| 221 CFX_FloatRect CFX_PathData::GetBoundingBox() const | 203 CFX_FloatRect CFX_PathData::GetBoundingBox() const |
| 222 { | 204 { |
| 223 CFX_FloatRect rect; | 205 CFX_FloatRect rect; |
| 224 if (m_PointCount) { | 206 if (m_PointCount) { |
| 225 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY); | 207 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY); |
| 226 for (int i = 1; i < m_PointCount; i ++) { | 208 for (int i = 1; i < m_PointCount; i ++) { |
| 227 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY); | 209 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY); |
| 228 } | 210 } |
| 229 } | 211 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 565 } |
| 584 if (pRect) { | 566 if (pRect) { |
| 585 pRect->left = x[0]; | 567 pRect->left = x[0]; |
| 586 pRect->right = x[2]; | 568 pRect->right = x[2]; |
| 587 pRect->bottom = y[0]; | 569 pRect->bottom = y[0]; |
| 588 pRect->top = y[2]; | 570 pRect->top = y[2]; |
| 589 pRect->Normalize(); | 571 pRect->Normalize(); |
| 590 } | 572 } |
| 591 return TRUE; | 573 return TRUE; |
| 592 } | 574 } |
| 593 FX_BOOL CFX_PathData::Copy(const CFX_PathData &src) | 575 void CFX_PathData::Copy(const CFX_PathData &src) |
| 594 { | 576 { |
| 595 if (!SetPointCount(src.m_PointCount)) { | 577 SetPointCount(src.m_PointCount); |
| 596 return FALSE; | |
| 597 } | |
| 598 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); | 578 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); |
| 599 return TRUE; | |
| 600 } | 579 } |
| 601 CFX_GraphStateData::CFX_GraphStateData() | 580 CFX_GraphStateData::CFX_GraphStateData() |
| 602 { | 581 { |
| 603 m_LineCap = LineCapButt; | 582 m_LineCap = LineCapButt; |
| 604 m_DashCount = 0; | 583 m_DashCount = 0; |
| 605 m_DashArray = NULL; | 584 m_DashArray = NULL; |
| 606 m_DashPhase = 0; | 585 m_DashPhase = 0; |
| 607 m_LineJoin = LineJoinMiter; | 586 m_LineJoin = LineJoinMiter; |
| 608 m_MiterLimit = 10 * 1.0f; | 587 m_MiterLimit = 10 * 1.0f; |
| 609 m_LineWidth = 1.0f; | 588 m_LineWidth = 1.0f; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 620 if (m_DashArray) { | 599 if (m_DashArray) { |
| 621 FX_Free(m_DashArray); | 600 FX_Free(m_DashArray); |
| 622 } | 601 } |
| 623 m_DashArray = NULL; | 602 m_DashArray = NULL; |
| 624 m_DashPhase = src.m_DashPhase; | 603 m_DashPhase = src.m_DashPhase; |
| 625 m_LineJoin = src.m_LineJoin; | 604 m_LineJoin = src.m_LineJoin; |
| 626 m_MiterLimit = src.m_MiterLimit; | 605 m_MiterLimit = src.m_MiterLimit; |
| 627 m_LineWidth = src.m_LineWidth; | 606 m_LineWidth = src.m_LineWidth; |
| 628 if (m_DashCount) { | 607 if (m_DashCount) { |
| 629 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount); | 608 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount); |
| 630 if (!m_DashArray) { | |
| 631 return; | |
| 632 } | |
| 633 FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLO
AT)); | 609 FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLO
AT)); |
| 634 } | 610 } |
| 635 } | 611 } |
| 636 CFX_GraphStateData::~CFX_GraphStateData() | 612 CFX_GraphStateData::~CFX_GraphStateData() |
| 637 { | 613 { |
| 638 if (m_DashArray) { | 614 if (m_DashArray) { |
| 639 FX_Free(m_DashArray); | 615 FX_Free(m_DashArray); |
| 640 } | 616 } |
| 641 } | 617 } |
| 642 void CFX_GraphStateData::SetDashCount(int count) | 618 void CFX_GraphStateData::SetDashCount(int count) |
| 643 { | 619 { |
| 644 if (m_DashArray) { | 620 if (m_DashArray) { |
| 645 FX_Free(m_DashArray); | 621 FX_Free(m_DashArray); |
| 646 } | 622 } |
| 647 m_DashArray = NULL; | 623 m_DashArray = NULL; |
| 648 m_DashCount = count; | 624 m_DashCount = count; |
| 649 if (count == 0) { | 625 if (count == 0) { |
| 650 return; | 626 return; |
| 651 } | 627 } |
| 652 m_DashArray = FX_Alloc(FX_FLOAT, count); | 628 m_DashArray = FX_Alloc(FX_FLOAT, count); |
| 653 } | 629 } |
| OLD | NEW |