| 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 | #include "vdrawable.h" |
| 20 | #include "vdasher.h" |
| 21 | #include "vraster.h" |
| 22 |
| 23 | void VDrawable::preprocess(const VRect &clip) |
| 24 | { |
| 25 | if (mFlag & (DirtyState::Path)) { |
| 26 | if (mStroke.enable) { |
| 27 | if (mStroke.mDash.size()) { |
| 28 | VDasher dasher(mStroke.mDash.data(), mStroke.mDash.size()); |
| 29 | mPath = dasher.dashed(mPath); |
| 30 | } |
| 31 | mRasterizer.rasterize(std::move(mPath), mStroke.cap, mStroke.join, |
| 32 | mStroke.width, mStroke.meterLimit, clip); |
| 33 | } else { |
| 34 | mRasterizer.rasterize(std::move(mPath), mFillRule, clip); |
| 35 | } |
| 36 | mPath = {}; |
| 37 | mFlag &= ~DirtyFlag(DirtyState::Path); |
| 38 | } |
| 39 | } |
| 40 |
| 41 | VRle VDrawable::rle() |
| 42 | { |
| 43 | return mRasterizer.rle(); |
| 44 | } |
| 45 |
| 46 | void VDrawable::setStrokeInfo(CapStyle cap, JoinStyle join, float meterLimit, |
| 47 | float strokeWidth) |
| 48 | { |
| 49 | if ((mStroke.cap == cap) && (mStroke.join == join) && |
| 50 | vCompare(mStroke.meterLimit, meterLimit) && |
| 51 | vCompare(mStroke.width, strokeWidth)) |
| 52 | return; |
| 53 |
| 54 | mStroke.enable = true; |
| 55 | mStroke.cap = cap; |
| 56 | mStroke.join = join; |
| 57 | mStroke.meterLimit = meterLimit; |
| 58 | mStroke.width = strokeWidth; |
| 59 | mFlag |= DirtyState::Path; |
| 60 | } |
| 61 |
| 62 | void VDrawable::setDashInfo(float *array, uint size) |
| 63 | { |
| 64 | bool hasChanged = false; |
| 65 |
| 66 | if (mStroke.mDash.size() == size) { |
| 67 | for (uint i = 0; i < size; i++) { |
| 68 | if (!vCompare(mStroke.mDash[i], array[i])) { |
| 69 | hasChanged = true; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | } else { |
| 74 | hasChanged = true; |
| 75 | } |
| 76 |
| 77 | if (!hasChanged) return; |
| 78 |
| 79 | mStroke.mDash.clear(); |
| 80 |
| 81 | for (uint i = 0; i < size; i++) { |
| 82 | mStroke.mDash.push_back(array[i]); |
| 83 | } |
| 84 | if (mStroke.mDash.size() == 1) { |
| 85 | mStroke.mDash.push_back(20); |
| 86 | } |
| 87 | mFlag |= DirtyState::Path; |
| 88 | } |
| 89 |
| 90 | void VDrawable::setPath(const VPath &path) |
| 91 | { |
| 92 | mPath = path; |
| 93 | mFlag |= DirtyState::Path; |
| 94 | } |
| 95 |