| 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> new_count = m_PointCount; |
| 177 if (!AllocPointCount(new_count)) { | 167 new_count += addPoints; |
| 178 return FALSE; | 168 m_PointCount = new_count.ValueOrDie(); |
| 179 } | 169 AllocPointCount(m_PointCount); |
| 180 m_PointCount = new_count; | |
| 181 return TRUE; | |
| 182 } | 170 } |
| 183 FX_BOOL CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* p
Matrix) | 171 void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMat
rix) |
| 184 { | 172 { |
| 185 int old_count = m_PointCount; | 173 int old_count = m_PointCount; |
| 186 if (!AddPointCount(pSrc->m_PointCount)) { | 174 AddPointCount(pSrc->m_PointCount); |
| 187 return FALSE; | 175 FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount *
sizeof(FX_PATHPOINT)); |
| 176 if (pMatrix) { |
| 177 for (int i = 0; i < pSrc->m_PointCount; i ++) { |
| 178 pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_
count + i].m_PointY); |
| 179 } |
| 188 } | 180 } |
| 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 } | 181 } |
| 198 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag) | 182 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag) |
| 199 { | 183 { |
| 200 ASSERT(index < m_PointCount); | 184 ASSERT(index < m_PointCount); |
| 201 m_pPoints[index].m_PointX = x; | 185 m_pPoints[index].m_PointX = x; |
| 202 m_pPoints[index].m_PointY = y; | 186 m_pPoints[index].m_PointY = y; |
| 203 m_pPoints[index].m_Flag = flag; | 187 m_pPoints[index].m_Flag = flag; |
| 204 } | 188 } |
| 205 FX_BOOL CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right,
FX_FLOAT top) | 189 void CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX
_FLOAT top) |
| 206 { | 190 { |
| 207 int old_count = m_PointCount; | 191 int old_count = m_PointCount; |
| 208 if (!AddPointCount(5)) { | 192 AddPointCount(5); |
| 209 return FALSE; | |
| 210 } | |
| 211 FX_PATHPOINT* pPoints = m_pPoints + old_count; | 193 FX_PATHPOINT* pPoints = m_pPoints + old_count; |
| 212 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left; | 194 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left; |
| 213 pPoints[2].m_PointX = pPoints[3].m_PointX = right; | 195 pPoints[2].m_PointX = pPoints[3].m_PointX = right; |
| 214 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom; | 196 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom; |
| 215 pPoints[1].m_PointY = pPoints[2].m_PointY = top; | 197 pPoints[1].m_PointY = pPoints[2].m_PointY = top; |
| 216 pPoints[0].m_Flag = FXPT_MOVETO; | 198 pPoints[0].m_Flag = FXPT_MOVETO; |
| 217 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO; | 199 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO; |
| 218 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; | 200 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; |
| 219 return TRUE; | |
| 220 } | 201 } |
| 221 CFX_FloatRect CFX_PathData::GetBoundingBox() const | 202 CFX_FloatRect CFX_PathData::GetBoundingBox() const |
| 222 { | 203 { |
| 223 CFX_FloatRect rect; | 204 CFX_FloatRect rect; |
| 224 if (m_PointCount) { | 205 if (m_PointCount) { |
| 225 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY); | 206 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY); |
| 226 for (int i = 1; i < m_PointCount; i ++) { | 207 for (int i = 1; i < m_PointCount; i ++) { |
| 227 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY); | 208 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY); |
| 228 } | 209 } |
| 229 } | 210 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 564 } |
| 584 if (pRect) { | 565 if (pRect) { |
| 585 pRect->left = x[0]; | 566 pRect->left = x[0]; |
| 586 pRect->right = x[2]; | 567 pRect->right = x[2]; |
| 587 pRect->bottom = y[0]; | 568 pRect->bottom = y[0]; |
| 588 pRect->top = y[2]; | 569 pRect->top = y[2]; |
| 589 pRect->Normalize(); | 570 pRect->Normalize(); |
| 590 } | 571 } |
| 591 return TRUE; | 572 return TRUE; |
| 592 } | 573 } |
| 593 FX_BOOL CFX_PathData::Copy(const CFX_PathData &src) | 574 void CFX_PathData::Copy(const CFX_PathData &src) |
| 594 { | 575 { |
| 595 if (!SetPointCount(src.m_PointCount)) { | 576 SetPointCount(src.m_PointCount); |
| 596 return FALSE; | |
| 597 } | |
| 598 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); | 577 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount
); |
| 599 return TRUE; | |
| 600 } | 578 } |
| 601 CFX_GraphStateData::CFX_GraphStateData() | 579 CFX_GraphStateData::CFX_GraphStateData() |
| 602 { | 580 { |
| 603 m_LineCap = LineCapButt; | 581 m_LineCap = LineCapButt; |
| 604 m_DashCount = 0; | 582 m_DashCount = 0; |
| 605 m_DashArray = NULL; | 583 m_DashArray = NULL; |
| 606 m_DashPhase = 0; | 584 m_DashPhase = 0; |
| 607 m_LineJoin = LineJoinMiter; | 585 m_LineJoin = LineJoinMiter; |
| 608 m_MiterLimit = 10 * 1.0f; | 586 m_MiterLimit = 10 * 1.0f; |
| 609 m_LineWidth = 1.0f; | 587 m_LineWidth = 1.0f; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 620 if (m_DashArray) { | 598 if (m_DashArray) { |
| 621 FX_Free(m_DashArray); | 599 FX_Free(m_DashArray); |
| 622 } | 600 } |
| 623 m_DashArray = NULL; | 601 m_DashArray = NULL; |
| 624 m_DashPhase = src.m_DashPhase; | 602 m_DashPhase = src.m_DashPhase; |
| 625 m_LineJoin = src.m_LineJoin; | 603 m_LineJoin = src.m_LineJoin; |
| 626 m_MiterLimit = src.m_MiterLimit; | 604 m_MiterLimit = src.m_MiterLimit; |
| 627 m_LineWidth = src.m_LineWidth; | 605 m_LineWidth = src.m_LineWidth; |
| 628 if (m_DashCount) { | 606 if (m_DashCount) { |
| 629 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount); | 607 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)); | 608 FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLO
AT)); |
| 634 } | 609 } |
| 635 } | 610 } |
| 636 CFX_GraphStateData::~CFX_GraphStateData() | 611 CFX_GraphStateData::~CFX_GraphStateData() |
| 637 { | 612 { |
| 638 if (m_DashArray) { | 613 if (m_DashArray) { |
| 639 FX_Free(m_DashArray); | 614 FX_Free(m_DashArray); |
| 640 } | 615 } |
| 641 } | 616 } |
| 642 void CFX_GraphStateData::SetDashCount(int count) | 617 void CFX_GraphStateData::SetDashCount(int count) |
| 643 { | 618 { |
| 644 if (m_DashArray) { | 619 if (m_DashArray) { |
| 645 FX_Free(m_DashArray); | 620 FX_Free(m_DashArray); |
| 646 } | 621 } |
| 647 m_DashArray = NULL; | 622 m_DashArray = NULL; |
| 648 m_DashCount = count; | 623 m_DashCount = count; |
| 649 if (count == 0) { | 624 if (count == 0) { |
| 650 return; | 625 return; |
| 651 } | 626 } |
| 652 m_DashArray = FX_Alloc(FX_FLOAT, count); | 627 m_DashArray = FX_Alloc(FX_FLOAT, count); |
| 653 } | 628 } |
| OLD | NEW |