Plug in for drawing gradient handles

Discussion about writing code for Inkscape.
capellan
Posts: 5
Joined: Sun Aug 06, 2017 1:39 am

Plug in for drawing gradient handles

Postby capellan » Sun Aug 06, 2017 2:02 am

Greetings from Santiago,

After looking for this information all around the web, I decided to ask experts.
This is my first post in this forum.

Does Inkscape API provide access to actual coordinate points of
gradient handles? Does exists a plugin that could draw these handles
in a different layer?

Take a look at attached png image. A Radial gradient handle has a L shape
and a Linear gradient handle is a single line.

I am using this information for importing SVG files with gradients into
my android application.

Thanks in advance

Al

200x200_gradients_01.zip
SVG and PNG files with lines draw in the exact position of gradient handles
(16.27 KiB) Downloaded 299 times

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Mon Aug 07, 2017 6:45 am

Does Inkscape API provide access to actual coordinate points of
gradient handles?


- No, it doesn't, as far as I know.

Does exists a plugin that could draw these handles
in a different layer?


- You mean, for visualization? I don't know of any, but that's probably not too difficult to do. We already have 'visualize path' with 'draw handles' and 'number nodes', these should be similar.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

capellan
Posts: 5
Joined: Sun Aug 06, 2017 1:39 am

Re: Plug in for drawing gradient handles

Postby capellan » Mon Aug 07, 2017 3:07 pm

Many thanks for your answer, Moini. I found information about the Inkscape extensions that you mentioned in this webpage: http://tavmjong.free.fr/INKSCAPE/MANUAL.html

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Tue Aug 08, 2017 2:54 am

You can make a feature request (sounds like it might be useful to some) here: https://bugs.launchpad.net/inkscape, but if you need fast results, and know some python, read the SVG source or use the XML editor to determine how gradient handle positions are set, and then write a function that draws those. You can make use of some prepared functions in the helper files.
If you keep your drawings simple (no transformed groups, for example, using one Inkscape version consistently for your files), then this shouldn't be too difficult to do.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Tue Aug 08, 2017 2:55 am

Some people on IRC may also be able to guide you a bit.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

capellan
Posts: 5
Joined: Sun Aug 06, 2017 1:39 am

Re: Plug in for drawing gradient handles

Postby capellan » Tue Aug 08, 2017 4:37 am

Great! Thanks a lot for your guidance

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Tue Aug 08, 2017 11:15 am

Probably there was one point of info missing, judging from your post to the mailing list (btw. the Inkscape source code lives at https://gitlab.com/inkscape/inkscape/). You can access the SVG's source code from inside the extensions. In the source code, the handles' coordinates are set as attributes for the gradient in the defs section. You need to do the parsing yourself.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

capellan
Posts: 5
Joined: Sun Aug 06, 2017 1:39 am

Re: Plug in for drawing gradient handles

Postby capellan » Tue Aug 08, 2017 3:36 pm

Do you mean that internally, Inkscape only stores gradient handles like this?

Code: Select all

<radialGradient
       inkscape:collect="always"
       xlink:href="#linearGradient4296"
       id="radialGradient4312"
       cx="95.666649"
       cy="987.04877"
       r="95"
       gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.62319928,0.62388171,-1.0181927,1.0170788,1017.3415,-88.883758)"


We could calculate the actual position of the L shaped handle for this Radial Gradient
multiplying the gradient center (95.666649,987.04877) the gradient vector (190.666649,987.04877)
and the gradient normal (95.666649,892.04877) by the gradient transform matrix:
(0.62319928,0.62388171,-1.0181927,1.0170788,1017.3415,-88.883758)

Then, we multiply the result with next transformation, and so on until
gradient coordinates falls in it's correct position.

But please notice, Inkscape already calculate and shows this information within it's GUI.
Hopefully, Inkscape Developers have made accessible this information using
Inkscape Python API.

Alejandro

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Tue Aug 08, 2017 10:09 pm

They haven't.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

capellan
Posts: 5
Joined: Sun Aug 06, 2017 1:39 am

Re: Plug in for drawing gradient handles

Postby capellan » Wed Aug 09, 2017 10:20 am

Then, I will raise a bug report asking for this feature.
Meanwhile, probably will create an application, just
for this purpose.

Many Thanks again, Moini, for your help!

Alejandro

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Plug in for drawing gradient handles

Postby Moini » Wed Aug 09, 2017 11:27 am

When you have written such an extension, would you perhaps share it on the Inkscape website? It would be put here: https://inkscape.org/en/download/addons/ when you upload it within the 'Extensions' category.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “Programming”