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