LCOV - code coverage report
Current view: top level - core/vg - SPVectorPath.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 151 151 100.0 %
Date: 2024-05-12 00:16:13 Functions: 58 58 100.0 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org>
       3             : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             : Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : of this software and associated documentation files (the "Software"), to deal
       7             : in the Software without restriction, including without limitation the rights
       8             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : copies of the Software, and to permit persons to whom the Software is
      10             : furnished to do so, subject to the following conditions:
      11             : 
      12             : The above copyright notice and this permission notice shall be included in
      13             : all copies or substantial portions of the Software.
      14             : 
      15             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             : THE SOFTWARE.
      22             : **/
      23             : 
      24             : #include "SPVectorPath.h"
      25             : #include "SPData.h"
      26             : #include "SPMemory.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::vg {
      29             : 
      30      547728 : VectorPath::VectorPath() { }
      31             : 
      32          75 : VectorPath::VectorPath(size_t count) {
      33          75 :         _data.getWriter().reserve(count);
      34          75 : }
      35             : 
      36          25 : bool VectorPath::init() {
      37          25 :         return true;
      38             : }
      39             : 
      40         600 : bool VectorPath::init(StringView path) {
      41         600 :         _data.clear();
      42             : 
      43         600 :         return _data.getWriter().readFromPathString(path);
      44             : }
      45             : 
      46          25 : bool VectorPath::init(FilePath &&str) {
      47          25 :         _data.clear();
      48             : 
      49          25 :         return _data.getWriter().readFromFile(str.get());
      50             : }
      51             : 
      52      541106 : bool VectorPath::init(BytesView data) {
      53      541106 :         _data.clear();
      54             : 
      55      541106 :         return _data.getWriter().readFromBytes(data);
      56             : }
      57             : 
      58          25 : bool VectorPath::init(const PathData<memory::StandartInterface> &data) {
      59          25 :         _data.clear();
      60          25 :         _data = data;
      61          25 :         return true;
      62             : }
      63             : 
      64          25 : bool VectorPath::init(const PathData<memory::PoolInterface> &data) {
      65          25 :         _data.clear();
      66          25 :         _data.params = data.params;
      67          25 :         _data.points = makeSpanView(data.points).vec<Interface>();
      68          25 :         _data.commands = makeSpanView(data.commands).vec<Interface>();
      69          25 :         return true;
      70             : }
      71             : 
      72         325 : VectorPath::VectorPath(const VectorPath &path) : _data(path._data) { }
      73             : 
      74          25 : VectorPath &VectorPath::operator=(const VectorPath &path) {
      75          25 :         _data = path._data;
      76          25 :         return *this;
      77             : }
      78             : 
      79      547678 : VectorPath::VectorPath(VectorPath &&path) : _data(move(path._data)) { }
      80             : 
      81          25 : VectorPath &VectorPath::operator=(VectorPath &&path) {
      82          25 :         _data = move(path._data);
      83          25 :         return *this;
      84             : }
      85             : 
      86          25 : VectorPath & VectorPath::addPath(const VectorPath &path) {
      87          25 :         _data.getWriter().addPath(path._data);
      88          25 :         return *this;
      89             : }
      90             : 
      91          25 : VectorPath & VectorPath::addPath(StringView str) {
      92          25 :         _data.getWriter().addPath(str);
      93          25 :         return *this;
      94             : }
      95             : 
      96          25 : VectorPath & VectorPath::addPath(BytesView data) {
      97          25 :         _data.getWriter().addPath(data);
      98          25 :         return *this;
      99             : }
     100             : 
     101          25 : size_t VectorPath::count() const {
     102          25 :         return _data.commands.size();
     103             : }
     104             : 
     105        5447 : VectorPath & VectorPath::openForWriting(const Callback<void(PathWriter &)> &cb) {
     106        5447 :         auto writer = _data.getWriter();
     107        5447 :         cb(writer);
     108        5447 :         return *this;
     109             : }
     110             : 
     111        1150 : VectorPath & VectorPath::setFillColor(const Color4B &color) {
     112        1150 :         _data.params.fillColor = color;
     113        1150 :         return *this;
     114             : }
     115         175 : VectorPath & VectorPath::setFillColor(const Color3B &color, bool preserveOpacity) {
     116         175 :         _data.params.fillColor = Color4B(color, preserveOpacity?_data.params.fillColor.a:255);
     117         175 :         return *this;
     118             : }
     119          50 : VectorPath & VectorPath::setFillColor(const Color &color, bool preserveOpacity) {
     120          50 :         _data.params.fillColor = Color4B(color, preserveOpacity?_data.params.fillColor.a:255);
     121          50 :         return *this;
     122             : }
     123      486900 : const Color4B &VectorPath::getFillColor() const {
     124      486900 :         return _data.params.fillColor;
     125             : }
     126             : 
     127        1125 : VectorPath & VectorPath::setStrokeColor(const Color4B &color) {
     128        1125 :         _data.params.strokeColor = color;
     129        1125 :         return *this;
     130             : }
     131         625 : VectorPath & VectorPath::setStrokeColor(const Color3B &color, bool preserveOpacity) {
     132         625 :         _data.params.strokeColor = Color4B(color, preserveOpacity?_data.params.fillColor.a:255);
     133         625 :         return *this;
     134             : }
     135          50 : VectorPath & VectorPath::setStrokeColor(const Color &color, bool preserveOpacity) {
     136          50 :         _data.params.strokeColor = Color4B(color, preserveOpacity?_data.params.fillColor.a:255);
     137          50 :         return *this;
     138             : }
     139      425335 : const Color4B &VectorPath::getStrokeColor() const {
     140      425335 :         return _data.params.strokeColor;
     141             : }
     142             : 
     143         454 : VectorPath & VectorPath::setFillOpacity(uint8_t value) {
     144         454 :         _data.params.fillColor.a = value;
     145         454 :         return *this;
     146             : }
     147       57334 : uint8_t VectorPath::getFillOpacity() const {
     148       57334 :         return _data.params.fillColor.a;
     149             : }
     150             : 
     151         200 : VectorPath & VectorPath::setStrokeOpacity(uint8_t value) {
     152         200 :         _data.params.strokeColor.a = value;
     153         200 :         return *this;
     154             : }
     155          50 : uint8_t VectorPath::getStrokeOpacity() const {
     156          50 :         return _data.params.strokeColor.a;
     157             : }
     158             : 
     159      425675 : VectorPath & VectorPath::setStrokeWidth(float width) {
     160      425675 :         _data.params.strokeWidth = width;
     161      425675 :         return *this;
     162             : }
     163             : 
     164      554156 : float VectorPath::getStrokeWidth() const {
     165      554156 :         return _data.params.strokeWidth;
     166             : }
     167             : 
     168       45021 : VectorPath &VectorPath::setWindingRule(Winding value) {
     169       45021 :         _data.params.winding = value;
     170       45021 :         return *this;
     171             : }
     172      102610 : vg::Winding VectorPath::getWindingRule() const {
     173      102610 :         return _data.params.winding;
     174             : }
     175             : 
     176          75 : VectorPath &VectorPath::setLineCup(LineCup value) {
     177          75 :         _data.params.lineCup = value;
     178          75 :         return *this;
     179             : }
     180          25 : vg::LineCup VectorPath::getLineCup() const {
     181          25 :         return _data.params.lineCup;
     182             : }
     183             : 
     184          75 : VectorPath &VectorPath::setLineJoin(LineJoin value) {
     185          75 :         _data.params.lineJoin = value;
     186          75 :         return *this;
     187             : }
     188          25 : vg::LineJoin VectorPath::getLineJoin() const {
     189          25 :         return _data.params.lineJoin;
     190             : }
     191             : 
     192          25 : VectorPath &VectorPath::setMiterLimit(float value) {
     193          25 :         _data.params.miterLimit = value;
     194          25 :         return *this;
     195             : }
     196          25 : float VectorPath::getMiterLimit() const {
     197          25 :         return _data.params.miterLimit;
     198             : }
     199             : 
     200       77896 : VectorPath & VectorPath::setStyle(DrawStyle s) {
     201       77896 :         _data.params.style = s;
     202       77896 :         return *this;
     203             : }
     204             : 
     205     1049856 : vg::DrawStyle VectorPath::getStyle() const {
     206     1049856 :         return _data.params.style;
     207             : }
     208             : 
     209      190643 : VectorPath &VectorPath::setAntialiased(bool val) {
     210      190643 :         _data.params.isAntialiased = val;
     211      190643 :         return *this;
     212             : }
     213      662731 : bool VectorPath::isAntialiased() const {
     214      662731 :         return _data.params.isAntialiased;
     215             : }
     216             : 
     217      541056 : VectorPath & VectorPath::setTransform(const Mat4 &t) {
     218      541056 :         _data.params.transform = t;
     219      541056 :         return *this;
     220             : }
     221         100 : VectorPath & VectorPath::applyTransform(const Mat4 &t) {
     222         100 :         _data.params.transform *= t;
     223         100 :         return *this;
     224             : }
     225      998230 : const Mat4 &VectorPath::getTransform() const {
     226      998230 :         return _data.params.transform;
     227             : }
     228             : 
     229          25 : VectorPath & VectorPath::clear() {
     230          25 :         if (!empty()) {
     231          25 :                 _data.clear();
     232             :         }
     233          25 :         return *this;
     234             : }
     235             : 
     236         925 : VectorPath & VectorPath::setParams(const PathParams &p) {
     237         925 :         _data.params = p;
     238         925 :         return *this;
     239             : }
     240             : 
     241         925 : PathParams VectorPath::getParams() const {
     242         925 :         return _data.params;
     243             : }
     244             : 
     245         850 : bool VectorPath::empty() const {
     246         850 :         return _data.commands.empty();
     247             : }
     248             : 
     249          25 : void VectorPath::reserve(size_t s) {
     250          25 :         _data.getWriter().reserve(s);
     251          25 : }
     252             : 
     253      128446 : const Interface::VectorType<Command> &VectorPath::getCommands() const {
     254      128446 :         return _data.commands;
     255             : }
     256             : 
     257      128454 : const Interface::VectorType<CommandData> &VectorPath::getPoints() const {
     258      128454 :         return _data.points;
     259             : }
     260             : 
     261       70950 : Interface::BytesType VectorPath::encode() const {
     262       70950 :         return _data.encode<Interface>();
     263             : }
     264             : 
     265       71625 : Interface::StringType VectorPath::toString(bool newline) const {
     266       71625 :         return _data.toString<Interface>();
     267             : }
     268             : 
     269          25 : size_t VectorPath::commandsCount() const {
     270          25 :         return _data.commands.size();
     271             : }
     272          25 : size_t VectorPath::dataCount() const {
     273          25 :         return _data.points.size();
     274             : }
     275             : 
     276         175 : PathWriter VectorPath::getWriter() {
     277         175 :         return PathWriter(_data);
     278             : }
     279             : 
     280             : }

Generated by: LCOV version 1.14