Merge point function crashes

Abraham Lee <[email protected]> Tue, 5 Mar 2019 09:06:17 -0700
Newsgroups gmane.comp.fonts.fontforge.devel
Message-ID <CAHAQwh1nxfatQffc8GKqRSDPcX0b6ATnKdYtJmtda=dWdUo6WQ@mail.gmail.com>
--===============1165137181175890867==
Content-Type: multipart/alternative; boundary="0000000000005fcb0605835b0e5d"

--0000000000005fcb0605835b0e5d
Content-Type: text/plain; charset="UTF-8"

Devs,

I'm discovering more and more all the time how powerful the python
interface is. So, to anyone and everyone developing it, thank you! I've
been able to do some wonderful things with it both in standalone scripts
and in plugins while working in the GUI.

The other day I ran into a crash while attempting to merge an on-curve
point. Let's say I create a contour in the following way:

import fontforge, psMat
cntr = fontforge.contour()
cntr.moveTo(0, 100)
cntr.lineTo(100, 100)
cntr.cubicTo(120, 100, 140, 80, 140, 60)
cntr.cubicTo(140, 30,100, 0, 0, 0)
print cntr

... which shows this:
<Contour(cubic)
  (0,100) on
  (100,100) on
  (120,100) off
  (140,80) off
  (140,60) on
  (140,30) off
  (100,0) off
  (0,0) on
>

There are several on-curve points with this simple contour. Now, let's say
the contour is transformed (e.g. skewed) and the points that were
previously extrema are no longer:

ang = 8  # degrees, clockwise
angrad = ang*3.14159/180
cntr.transform(psMat.skew(angrad))
print cntr

... which shows this now:
<Contour(cubic)
  (14.0537,100) on
  (114.054,100) on
  (134.054,100) off
  (151.243,80) off
  (148.433,60) on
  (144.216,30) off
  (100,0) off
  (0,0) on
>

There are no extrema points on the curves anymore. Now, let's add extrema
back onto the contour:

cntr.addExtrema('all')
print cntr

... which now shows:
<Contour(cubic)
  (14.0537,100) on
  (114.054,100) on
  (132.603,100) off
  (148.735,82.7958) off
  (148.735,64.3438) on
  (148.735,62.901) off
  (148.636,61.4505) off
  (148.433,60) on
  (144.216,30) off
  (100,0) off
  (0,0) on
>

The on-curve point at (148.735,64.3438) is now the new extrema. I no longer
want the non-extrema on-curve point at (148.433, 60) anymore, so we attempt
to merge it:

pos  = 7 # this is the 0-based position
cntr.merge(pos)

... and then the crash happens. I haven't been able to narrow down, at
least on my input-side, what could be causing the full program crash. I
usually can find that I've done something non-obviously wrong with my code,
but this has me stumped.

There's that problem, and then there's a follow on one. As described in the
docs, "merge" should be able to accept a single integer or a list of
integers. Looking at the source code for the function suggests similarly.
However, when a list (or an array of any kind, like tuple) is supplied, the
function throws an error saying that it accepts only a single integer.

I searched the repo at the current master branch and also at the snapshot
commit of the current release of FF, but the code seems to be the same that
drives the merge function. So, I'm not sure how to proceed. I can try to
code up my own merge function, but I'd rather not if I can avoid it ;-)

Any thoughts?

Best,
Abraham

--0000000000005fcb0605835b0e5d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">Devs,<div><br></div><div>I&#39;=
m discovering more and more all the time how powerful the python interface =
is. So, to anyone and everyone developing it, thank you! I&#39;ve been able=
 to do some wonderful things with it both in standalone scripts and in plug=
ins while working in the GUI.</div><div><br></div><div>The other day I ran =
into a crash while attempting to merge an on-curve point. Let&#39;s say I c=
reate a contour in the following way:</div><div><br></div><div>import fontf=
orge, psMat</div><div>cntr =3D fontforge.contour()</div><div>cntr.moveTo(0,=
 100)</div><div>cntr.lineTo(100, 100)</div><div>cntr.cubicTo(120, 100, 140,=
 80, 140, 60)</div><div>cntr.cubicTo(140, 30,100, 0, 0, 0)</div><div>print =
cntr</div><div><br></div><div>... which shows this:</div><div>&lt;Contour(c=
ubic)</div><div>=C2=A0 (0,100) on</div><div>=C2=A0 (100,100) on</div><div>=
=C2=A0 (120,100) off</div><div>=C2=A0 (140,80) off</div><div>=C2=A0 (140,60=
) on</div><div>=C2=A0 (140,30) off</div><div>=C2=A0 (100,0) off</div><div>=
=C2=A0 (0,0) on</div><div>&gt;</div><div><br></div><div>There are several o=
n-curve points with this simple contour. Now, let&#39;s say the contour is =
transformed (e.g. skewed) and the points that were previously extrema are n=
o longer:</div><div><br></div><div>ang =3D 8=C2=A0 # degrees, clockwise</di=
v><div>angrad =3D ang*3.14159/180</div><div>cntr.transform(psMat.skew(angra=
d))</div><div>print cntr</div><div><br></div><div>... which shows this now:=
</div><div><div>&lt;Contour(cubic)</div><div>=C2=A0 (14.0537,100) on</div><=
div>=C2=A0 (114.054,100) on</div><div>=C2=A0 (134.054,100) off</div><div>=
=C2=A0 (151.243,80) off</div><div>=C2=A0 (148.433,60) on</div><div>=C2=A0 (=
144.216,30) off</div><div>=C2=A0 (100,0) off</div><div>=C2=A0 (0,0) on</div=
><div>&gt;</div></div><div><br></div><div>There are no extrema points on th=
e curves anymore. Now, let&#39;s add extrema back onto the contour:</div><d=
iv><br></div><div>cntr.addExtrema(&#39;all&#39;)</div><div>print cntr</div>=
<div><br></div><div>... which now shows:</div><div><div>&lt;Contour(cubic)<=
/div><div>=C2=A0 (14.0537,100) on</div><div>=C2=A0 (114.054,100) on</div><d=
iv>=C2=A0 (132.603,100) off</div><div>=C2=A0 (148.735,82.7958) off</div><di=
v>=C2=A0 (148.735,64.3438) on</div><div>=C2=A0 (148.735,62.901) off</div><d=
iv>=C2=A0 (148.636,61.4505) off</div><div>=C2=A0 (148.433,60) on</div><div>=
=C2=A0 (144.216,30) off</div><div>=C2=A0 (100,0) off</div><div>=C2=A0 (0,0)=
 on</div><div>&gt;</div></div><div><br></div><div>The on-curve point at (14=
8.735,64.3438) is now the new extrema. I no longer want the non-extrema on-=
curve point at (148.433, 60) anymore, so we attempt to merge it:</div><div>=
<br></div><div>pos=C2=A0 =3D 7 # this is the 0-based position</div><div>cnt=
r.merge(pos)</div><div><br></div><div>... and then the crash happens. I hav=
en&#39;t been able to narrow down, at least on my input-side, what could be=
 causing the full program crash. I usually can find that I&#39;ve done some=
thing non-obviously wrong with my code, but this has me stumped.=C2=A0</div=
><div><br></div><div>There&#39;s that problem, and then there&#39;s a follo=
w on one. As described in the docs, &quot;merge&quot; should be able to acc=
ept a single integer or a list of integers. Looking at the source code for =
the function suggests similarly. However, when a list (or an array of any k=
ind, like tuple) is supplied, the function throws an error saying that it a=
ccepts only a single integer.</div><div><br></div><div>I searched the repo =
at the current master branch and also at the snapshot commit of the current=
 release of FF, but the code seems to be the same that drives the merge fun=
ction. So, I&#39;m not sure how to proceed. I can try to code up my own mer=
ge function, but I&#39;d rather not if I can avoid it ;-)<br></div><div><br=
></div><div>Any thoughts?</div><div><br></div><div>Best,</div><div>Abraham<=
/div></div></div></div></div></div></div></div>

--0000000000005fcb0605835b0e5d--


--===============1165137181175890867==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============1165137181175890867==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
fontforge-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fontforge-devel
http://fontforge.10959.n7.nabble.com/Developer-f3.html

--===============1165137181175890867==--