Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: stroke dash offset support added #1607

Merged
merged 4 commits into from
Aug 23, 2023

Conversation

mgrudzinska
Copy link
Collaborator

@mgrudzinska mgrudzinska commented Aug 17, 2023

The feature is supported also in the svg loader.

@issue: #1591

@mgrudzinska mgrudzinska added the enhancement Improve features label Aug 17, 2023
@mgrudzinska mgrudzinska self-assigned this Aug 17, 2023
@mgrudzinska
Copy link
Collaborator Author

sample:

<svg viewBox="-10 0 50 55" xmlns="http://www.w3.org/2000/svg">
  <line x1="0" y1="1" x2="30" y2="1" stroke="black" />
  <line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="3.4 1.3 2 0.5" stroke-linecap="butt" />

  <line x1="0" y1="5" x2="30" y2="5" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="1.2" />
  <line x1="0" y1="6.1" x2="30" y2="6.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="8.4" />

  <line x1="0" y1="8" x2="30" y2="8" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="4.1" />
  <line x1="0" y1="9.1" x2="30" y2="9.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="11.3" />

  <line x1="0" y1="11" x2="30" y2="11" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="5.7" />
  <line x1="0" y1="12.1" x2="30" y2="12.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="12.9" />


  <line x1="0" y1="14" x2="30" y2="14" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-1.2" />
  <line x1="0" y1="15.1" x2="30" y2="15.1" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-8.4" />

  <line x1="0" y1="17" x2="30" y2="17" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-4.1" />
  <line x1="0" y1="18.1" x2="30" y2="18.1" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-11.3" />

  <line x1="0" y1="20" x2="30" y2="20" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-5.7" />
  <line x1="0" y1="21.1" x2="30" y2="21.1" stroke="red"
        stroke-dasharray="3.4 1.3 2 0.5" stroke-dashoffset="-12.9" />
  

  <line x1="0" y1="23" x2="30" y2="23" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-1.2" />
  <line x1="0" y1="24.1" x2="30" y2="24.1" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-8.4" />

  <line x1="0" y1="26" x2="30" y2="26" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-4.1" />
  <line x1="0" y1="27.1" x2="30" y2="27.1" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-11.3" />

  <line x1="0" y1="29" x2="30" y2="29" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-5.7" />
  <line x1="0" y1="30.1" x2="30" y2="30.1" stroke="green"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="-12.9" />

  
  <line x1="0" y1="32" x2="30" y2="32" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="1.2" />
  <line x1="0" y1="33.1" x2="30" y2="33.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="8.4" />

  <line x1="0" y1="35" x2="30" y2="35" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="4.1" />
  <line x1="0" y1="36.1" x2="30" y2="36.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="11.3" />

  <line x1="0" y1="38" x2="30" y2="38" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="5.7" />
  <line x1="0" y1="39.1" x2="30" y2="39.1" stroke="blue"
        stroke-dasharray="3.4 1.3 2" stroke-dashoffset="12.9" />

  
  <line x1="0" y1="41" x2="30" y2="41" stroke="black" stroke-dasharray="3.4 1.3 2"/>
</svg>

result:
Zrzut ekranu 2023-08-17 o 23 35 27

Copy link
Member

@hermet hermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. a nitpick. please check a comment.

src/loaders/svg/tvgSvgLoaderCommon.h Outdated Show resolved Hide resolved
src/lib/tvgRender.h Outdated Show resolved Hide resolved
This reverts commit 6cbc1de.
Setting def value for 'a' makes it impossible to overload
the 'stroke' api with 3 values (needed for introducing dash offset).
@mgrudzinska mgrudzinska force-pushed the mgrudzinska/dashOffset branch 2 times, most recently from 86e8b13 to 4a031a6 Compare August 18, 2023 22:01
@mgrudzinska mgrudzinska marked this pull request as ready for review August 18, 2023 22:12
Copy link
Member

@hermet hermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is beneficial to set a default value at Shape::fill() . I believe that reverting it is not a good idea.

@@ -1339,6 +1339,24 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra
TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please kill the old version of the api. I think we don't need to maintain both apis.

The feature is supported also in the svg loader.

@issue: thorvg#1591
tvg_shape_set_stroke_dash() and tvg_shape_get_stroke_dash()
require an extra argument: offset


/*!
* \brief Gets the dash pattern of the stroke.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hermet I added BETA_API - not sure whether it's necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think it's ready to official release then you don't need to add BETA_API tag. Otherwise you should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now this breaks the api compatibility.

*
* @return Result::Success when succeed, Result::FailedAllocation otherwise.
*/
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hermet our policy is that we can remove the def value from api just like that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two options:

  1. bring a new api name about stroke dash
  2. change the existing conflict api.

You know, you already suggested this change. I have no any objection of this.

Abou policy? Well... you know most apis have no default values but if it's useful for users then why not?

Copy link
Member

@hermet hermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!



/*!
* \brief Gets the dash pattern of the stroke.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now this breaks the api compatibility.

@hermet hermet merged commit cb36c25 into thorvg:main Aug 23, 2023
9 checks passed
@mgrudzinska mgrudzinska deleted the mgrudzinska/dashOffset branch April 22, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants