Signature Widget Resize Scale

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

JereMiami
Posts: 86
Joined: Mon Nov 03, 2014 12:17 am

Signature Widget Resize Scale

Post by JereMiami » Thu Sep 22, 2022 1:51 pm

Suppose you want to resize a signature created from one signature widget to display in a smaller/larger signature widget. How would you do that? What am I missing here?

Code: Select all

   put the pathdata of widget "Signature1" into p
   ---how do I resize p to fit the rect of "Signature 2"--
   set the pathData of widget "Signature2" to p
   

Klaus
Posts: 13035
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Signature Widget Resize Scale

Post by Klaus » Thu Sep 22, 2022 3:30 pm

Looks like resizing, even the SAME widget, is not supported.

stam
Posts: 1521
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Signature Widget Resize Scale

Post by stam » Thu Sep 22, 2022 4:15 pm

You *can* set the pathData, so i'd imagine with some clever transform this my be feasible? but doing the math will be a pain...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 7762
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Signature Widget Resize Scale

Post by richmond62 » Thu Sep 22, 2022 4:47 pm

I wonder if you can export a signature as an SVG file?

stam
Posts: 1521
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Signature Widget Resize Scale

Post by stam » Thu Sep 22, 2022 5:21 pm

richmond62 wrote:
Thu Sep 22, 2022 4:47 pm
I wonder if you can export a signature as an SVG file?
Don't have much time to check now, but the pathData is an array with 3 keys for each point: color, path and width.
You can export the path to an svg widget and it is then resizeable, but my quick hack below only produces the thinnest outline of the path - it's so thin it's barely visible, but it's definitely in the SVG widget and resizeable:

Code: Select all

on mouseUp
     local tPath, tArray
     put the pathData of widget "signature" into tArray
     repeat for each element tElement in tArray
          put tElement["path"] & space after tPath
     end repeat
     delete the last char of tPath
     set the iconPath of widget "svg" to tPath
end mouseUp
I'm not particularly knowledgable on SVG paths, but if there is some way to include the width in the iconPath of the SVG widget, then it should be very doable...

S.

JereMiami
Posts: 86
Joined: Mon Nov 03, 2014 12:17 am

Re: Signature Widget Resize Scale

Post by JereMiami » Thu Sep 22, 2022 6:16 pm

Stam,

Same thing here. Very faint in the svg with that code. Here is code from the old lesson. Anyone have any luck with the code from this lesson?

Code: Select all

function svgFileData pSignature
  local tPathData

  put the pathData of pSignature into tPathData

  local tSVG
  put "<svg xmlns=" & quote & "http://www.w3.org/2000/svg" & quote & ">" & return into tSVG

   repeat for each element tElement in tPathData
      put "<path d=" & quote & tElement["path"] & quote after tSVG
      put " stroke=" & quote & "rgb(" & item 1 to 3 of tElement["color"] & ")" & quote after tSVG
		put " stroke-opacity=" & quote & round(item 4 of tElement["color"] / 255) & quote after tSVG
		put " stroke-width=" & quote & tElement["width"] & quote after tSVG
		put "/>" & return after tSVG
	end repeat
	put "</svg>" after tSVG
	return tSVG
end svgFileData

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3695
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Signature Widget Resize Scale

Post by bn » Thu Sep 22, 2022 8:13 pm

JereMiami wrote:
Thu Sep 22, 2022 6:16 pm
Same thing here. Very faint in the svg with that code. Here is code from the old lesson. Anyone have any luck with the code from this lesson?
I assume that you want to import the svg - file to a drawing.

I changed the svg-header to one I lifted from an export from Affinity, because Affinity could read your original data but drawingSVGCompile choked on it.
It is in the field of the stack. I change width and height to 200 200 in that header. It is the width and height of the signature widget in that stack.
Have a look at this stack.

convertSignature to SVG Image.livecode.zip
(1.77 KiB) Downloaded 24 times

Kind regards
Bernd

JereMiami
Posts: 86
Joined: Mon Nov 03, 2014 12:17 am

Re: Signature Widget Resize Scale

Post by JereMiami » Thu Sep 22, 2022 8:45 pm

Bernd,

Impressive. Nice job.

stam
Posts: 1521
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Signature Widget Resize Scale

Post by stam » Fri Sep 23, 2022 8:31 am

bn wrote:
Thu Sep 22, 2022 8:13 pm
I changed the svg-header to one I lifted from an export from Affinity, because Affinity could read your original data but drawingSVGCompile choked on it.
It is in the field of the stack. I change width and height to 200 200 in that header. It is the width and height of the signature widget in that stack.
Have a look at this stack.
Amazing, thanks Bernd!
pretty simple to automatically replace the viewBox rect with the dimensions of the current signature...

Does drawingSVGCompile always need this header and a viewBox size then?

If that's the case is it worth asking for an enhancement request so the up-to-date header is automatically inserted and the dimensions of the source can be taken as parameters?

S.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3695
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Signature Widget Resize Scale

Post by bn » Fri Sep 23, 2022 8:53 am

Stam,
I do not know what exactly drawingSVGCompile did not like in the original header of the lesson.
I just noticed that the lesson header worked when selecting the file in Finder an hitting space (Mac) and opening it in Affinity. And that drawingSVGCompile did import with the exported Affinity header.
Headers in SVG (and SVG data) are a pain because of the many variants.
I do know that drawingSVGCompile uses the viewBox to scale the drawing.

Mark Waddingham did an amazing job to come up with the drawing library.

Kind regards
Bernd

JereMiami
Posts: 86
Joined: Mon Nov 03, 2014 12:17 am

Re: Signature Widget Resize Scale

Post by JereMiami » Sat Sep 24, 2022 10:32 pm

Is it possible to get this to work on mobile?

I noticed that I get to the last line of code containing drawingSvgCompile and it fails because XML is not an extension for mobile. Any workaround?

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: Signature Widget Resize Scale

Post by bobcole » Sat Sep 24, 2022 10:33 pm

from Bernd:
I do not know what exactly drawingSVGCompile did not like in the original header of the lesson.
Bernd's sample stack contains the xml header from the Affinity app; it works well.
I tried to skinny down that xml and came up with this minimal header:

Code: Select all

<?xml version="1.0"?>
<svg viewBox="0 0 280 91">
Taking out either the xml version or the svg viewBox causes the conversion to fail.
Attached is my stack which uses Bernd's logic.Thanks, Bernd.
Bob

Signature to Image.livecode.zip
(27.4 KiB) Downloaded 14 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3695
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Signature Widget Resize Scale

Post by bn » Sat Sep 24, 2022 10:53 pm

JereMiami wrote:
Sat Sep 24, 2022 10:32 pm
Is it possible to get this to work on mobile?

I noticed that I get to the last line of code containing drawingSvgCompile and it fails because XML is not an extension for mobile. Any workaround?
You would have to include com.livecode.library.drawing in the standalone builder.

com.livecode.library.drawing needs the xml external. It has instructions for the Standalone builder to include it when building a standalone.

This is untested but should work since the xml external is according to the dictionary "mac, windows, linux, ios, android"

I do not know enough about building standalones for mobile, maybe someone in the know could chime in.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3695
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Signature Widget Resize Scale

Post by bn » Sat Sep 24, 2022 10:56 pm

bobcole wrote:
Sat Sep 24, 2022 10:33 pm
I tried to skinny down that xml and came up with this minimal header:

Code: Select all

<?xml version="1.0"?>
<svg viewBox="0 0 280 91">
Taking out either the xml version or the svg viewBox causes the conversion to fail.
Attached is my stack which uses Bernd's logic.Thanks, Bernd.
Bob
Thank you Bob for figuring this out.

Kind regards
Bernd

JereMiami
Posts: 86
Joined: Mon Nov 03, 2014 12:17 am

Re: Signature Widget Resize Scale

Post by JereMiami » Sat Sep 24, 2022 11:23 pm

It totally worked.

For those developing for mobile, include the "drawing" extension (in addition to the "signature" extension), and all will be as it should be for that last line of code including the drawingSvgCompile function.

Excellent work and thanks so much again!!!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”