| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #ifndef VDASHER_H |
| 20 | #define VDASHER_H |
| 21 | #include "vpath.h" |
| 22 |
| 23 | V_BEGIN_NAMESPACE |
| 24 |
| 25 | class VDasher { |
| 26 | public: |
| 27 | VDasher(const float *dashArray, size_t size); |
| 28 | VPath dashed(const VPath &path); |
| 29 |
| 30 | private: |
| 31 | void moveTo(const VPointF &p); |
| 32 | void lineTo(const VPointF &p); |
| 33 | void cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e); |
| 34 | void close(); |
| 35 | void addLine(const VPointF &p); |
| 36 | void addCubic(const VPointF &cp1, const VPointF &cp2, const VPointF &e); |
| 37 | void updateActiveSegment(); |
| 38 |
| 39 | private: |
| 40 | struct Dash { |
| 41 | float length; |
| 42 | float gap; |
| 43 | }; |
| 44 | const VDasher::Dash *mDashArray; |
| 45 | size_t mArraySize{0}; |
| 46 | VPointF mCurPt; |
| 47 | size_t mIndex{0}; /* index to the dash Array */ |
| 48 | float mCurrentLength; |
| 49 | bool mDiscard; |
| 50 | float mDashOffset{0}; |
| 51 | VPath mResult; |
| 52 | bool mStartNewSegment=true; |
| 53 | }; |
| 54 |
| 55 | V_END_NAMESPACE |
| 56 |
| 57 | #endif // VDASHER_H |
| 58 |