OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "xfa/fxgraphics/cfx_path.h" |
| 8 |
| 9 #include "xfa/fxgraphics/cfx_path_generator.h" |
| 10 |
| 11 CFX_Path::CFX_Path() { |
| 12 m_generator = nullptr; |
| 13 } |
| 14 |
| 15 FX_ERR CFX_Path::Create() { |
| 16 if (m_generator) |
| 17 return FX_ERR_Property_Invalid; |
| 18 |
| 19 m_generator = new CFX_PathGenerator; |
| 20 m_generator->Create(); |
| 21 return FX_ERR_Succeeded; |
| 22 } |
| 23 |
| 24 CFX_Path::~CFX_Path() { |
| 25 delete m_generator; |
| 26 } |
| 27 |
| 28 FX_ERR CFX_Path::MoveTo(FX_FLOAT x, FX_FLOAT y) { |
| 29 if (!m_generator) |
| 30 return FX_ERR_Property_Invalid; |
| 31 m_generator->MoveTo(x, y); |
| 32 return FX_ERR_Succeeded; |
| 33 } |
| 34 |
| 35 FX_ERR CFX_Path::LineTo(FX_FLOAT x, FX_FLOAT y) { |
| 36 if (!m_generator) |
| 37 return FX_ERR_Property_Invalid; |
| 38 m_generator->LineTo(x, y); |
| 39 return FX_ERR_Succeeded; |
| 40 } |
| 41 |
| 42 FX_ERR CFX_Path::BezierTo(FX_FLOAT ctrlX1, |
| 43 FX_FLOAT ctrlY1, |
| 44 FX_FLOAT ctrlX2, |
| 45 FX_FLOAT ctrlY2, |
| 46 FX_FLOAT toX, |
| 47 FX_FLOAT toY) { |
| 48 if (!m_generator) |
| 49 return FX_ERR_Property_Invalid; |
| 50 m_generator->BezierTo(ctrlX1, ctrlY1, ctrlX2, ctrlY2, toX, toY); |
| 51 return FX_ERR_Succeeded; |
| 52 } |
| 53 |
| 54 FX_ERR CFX_Path::ArcTo(FX_FLOAT left, |
| 55 FX_FLOAT top, |
| 56 FX_FLOAT width, |
| 57 FX_FLOAT height, |
| 58 FX_FLOAT startAngle, |
| 59 FX_FLOAT sweepAngle) { |
| 60 if (!m_generator) |
| 61 return FX_ERR_Property_Invalid; |
| 62 m_generator->ArcTo(left + width / 2, top + height / 2, width / 2, height / 2, |
| 63 startAngle, sweepAngle); |
| 64 return FX_ERR_Succeeded; |
| 65 } |
| 66 |
| 67 FX_ERR CFX_Path::Close() { |
| 68 if (!m_generator) |
| 69 return FX_ERR_Property_Invalid; |
| 70 m_generator->Close(); |
| 71 return FX_ERR_Succeeded; |
| 72 } |
| 73 |
| 74 FX_ERR CFX_Path::AddLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2) { |
| 75 if (!m_generator) |
| 76 return FX_ERR_Property_Invalid; |
| 77 m_generator->AddLine(x1, y1, x2, y2); |
| 78 return FX_ERR_Succeeded; |
| 79 } |
| 80 |
| 81 FX_ERR CFX_Path::AddBezier(FX_FLOAT startX, |
| 82 FX_FLOAT startY, |
| 83 FX_FLOAT ctrlX1, |
| 84 FX_FLOAT ctrlY1, |
| 85 FX_FLOAT ctrlX2, |
| 86 FX_FLOAT ctrlY2, |
| 87 FX_FLOAT endX, |
| 88 FX_FLOAT endY) { |
| 89 if (!m_generator) |
| 90 return FX_ERR_Property_Invalid; |
| 91 m_generator->AddBezier(startX, startY, ctrlX1, ctrlY1, ctrlX2, ctrlY2, endX, |
| 92 endY); |
| 93 return FX_ERR_Succeeded; |
| 94 } |
| 95 |
| 96 FX_ERR CFX_Path::AddRectangle(FX_FLOAT left, |
| 97 FX_FLOAT top, |
| 98 FX_FLOAT width, |
| 99 FX_FLOAT height) { |
| 100 if (!m_generator) |
| 101 return FX_ERR_Property_Invalid; |
| 102 m_generator->AddRectangle(left, top, left + width, top + height); |
| 103 return FX_ERR_Succeeded; |
| 104 } |
| 105 |
| 106 FX_ERR CFX_Path::AddEllipse(FX_FLOAT left, |
| 107 FX_FLOAT top, |
| 108 FX_FLOAT width, |
| 109 FX_FLOAT height) { |
| 110 if (!m_generator) |
| 111 return FX_ERR_Property_Invalid; |
| 112 m_generator->AddEllipse(left + width / 2, top + height / 2, width / 2, |
| 113 height / 2); |
| 114 return FX_ERR_Succeeded; |
| 115 } |
| 116 |
| 117 FX_ERR CFX_Path::AddEllipse(const CFX_RectF& rect) { |
| 118 if (!m_generator) |
| 119 return FX_ERR_Property_Invalid; |
| 120 m_generator->AddEllipse(rect.left + rect.Width() / 2, |
| 121 rect.top + rect.Height() / 2, rect.Width() / 2, |
| 122 rect.Height() / 2); |
| 123 return FX_ERR_Succeeded; |
| 124 } |
| 125 |
| 126 FX_ERR CFX_Path::AddArc(FX_FLOAT left, |
| 127 FX_FLOAT top, |
| 128 FX_FLOAT width, |
| 129 FX_FLOAT height, |
| 130 FX_FLOAT startAngle, |
| 131 FX_FLOAT sweepAngle) { |
| 132 if (!m_generator) |
| 133 return FX_ERR_Property_Invalid; |
| 134 m_generator->AddArc(left + width / 2, top + height / 2, width / 2, height / 2, |
| 135 startAngle, sweepAngle); |
| 136 return FX_ERR_Succeeded; |
| 137 } |
| 138 |
| 139 FX_ERR CFX_Path::AddPie(FX_FLOAT left, |
| 140 FX_FLOAT top, |
| 141 FX_FLOAT width, |
| 142 FX_FLOAT height, |
| 143 FX_FLOAT startAngle, |
| 144 FX_FLOAT sweepAngle) { |
| 145 if (!m_generator) |
| 146 return FX_ERR_Property_Invalid; |
| 147 m_generator->AddPie(left + width / 2, top + height / 2, width / 2, height / 2, |
| 148 startAngle, sweepAngle); |
| 149 return FX_ERR_Succeeded; |
| 150 } |
| 151 |
| 152 FX_ERR CFX_Path::AddSubpath(CFX_Path* path) { |
| 153 if (!m_generator) |
| 154 return FX_ERR_Property_Invalid; |
| 155 m_generator->AddPathData(path->GetPathData()); |
| 156 return FX_ERR_Succeeded; |
| 157 } |
| 158 |
| 159 FX_ERR CFX_Path::Clear() { |
| 160 if (!m_generator) |
| 161 return FX_ERR_Property_Invalid; |
| 162 m_generator->GetPathData()->SetPointCount(0); |
| 163 return FX_ERR_Succeeded; |
| 164 } |
| 165 |
| 166 FX_BOOL CFX_Path::IsEmpty() { |
| 167 if (!m_generator) |
| 168 return FX_ERR_Property_Invalid; |
| 169 if (m_generator->GetPathData()->GetPointCount() == 0) { |
| 170 return TRUE; |
| 171 } |
| 172 return FALSE; |
| 173 } |
| 174 |
| 175 CFX_PathData* CFX_Path::GetPathData() { |
| 176 if (!m_generator) |
| 177 return nullptr; |
| 178 return m_generator->GetPathData(); |
| 179 } |
OLD | NEW |