<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to turn “line” segment into “curve” segment with code?]]></title><description><![CDATA[<p dir="auto">this is part of my tool (for testing the code below I created the test glyph only with rectangle contour in it):</p>
<pre><code>def interpolation(v1, v2, t):
    return v1 * (1 - t) + v2 * t

def interpolatePoint(p1,p2,t):
    p1x,p1y = p1.position
    p2x,p2y = p2.position
    return  interpolation(p1x, p2x, t), interpolation(p1y, p2y, t)

def turnLineIntoCubicBez(segment, contour):
    if segment.index == 0:
        prevPoint = contour.points[-1]
    else:
        prevPoint = contour.segments[segment.index - 1].points[-1]
    point = segment.points[-1]
    h1x, h1y = interpolatePoint(prevPoint,point,1/3)
    h2x, h2y = interpolatePoint(prevPoint,point,1-1/3)

    contour.insertPoint(prevPoint.index,(h1x, h1y),type="offcurve")
    contour.insertPoint(prevPoint.index,(h2x, h2y),type="offcurve")

g = CurrentGlyph()
c = g.contours[0]
s = c.segments[0]
turnLineIntoCubicBez(s, c)
</code></pre>
<p dir="auto">It is basically meant to add offcurve points to the line segment, so the segment turns into the curve.<br />
Ofcourse, I got an error an and RF crashes, because the segment of "line" type cannot have offcurve points. What is the best way to achieve this (line turning into the curve) in a proper way?</p>
<p dir="auto">Best<br />
R</p>
]]></description><link>https://forum.robofont.com/topic/909/how-to-turn-line-segment-into-curve-segment-with-code</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 20:24:50 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/909.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 14 Nov 2020 15:31:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to turn “line” segment into “curve” segment with code? on Sat, 14 Nov 2020 20:01:18 GMT]]></title><description><![CDATA[<p dir="auto">this is part of my tool (for testing the code below I created the test glyph only with rectangle contour in it):</p>
<pre><code>def interpolation(v1, v2, t):
    return v1 * (1 - t) + v2 * t

def interpolatePoint(p1,p2,t):
    p1x,p1y = p1.position
    p2x,p2y = p2.position
    return  interpolation(p1x, p2x, t), interpolation(p1y, p2y, t)

def turnLineIntoCubicBez(segment, contour):
    if segment.index == 0:
        prevPoint = contour.points[-1]
    else:
        prevPoint = contour.segments[segment.index - 1].points[-1]
    point = segment.points[-1]
    h1x, h1y = interpolatePoint(prevPoint,point,1/3)
    h2x, h2y = interpolatePoint(prevPoint,point,1-1/3)

    contour.insertPoint(prevPoint.index,(h1x, h1y),type="offcurve")
    contour.insertPoint(prevPoint.index,(h2x, h2y),type="offcurve")

g = CurrentGlyph()
c = g.contours[0]
s = c.segments[0]
turnLineIntoCubicBez(s, c)
</code></pre>
<p dir="auto">It is basically meant to add offcurve points to the line segment, so the segment turns into the curve.<br />
Ofcourse, I got an error an and RF crashes, because the segment of "line" type cannot have offcurve points. What is the best way to achieve this (line turning into the curve) in a proper way?</p>
<p dir="auto">Best<br />
R</p>
]]></description><link>https://forum.robofont.com/post/3514</link><guid isPermaLink="true">https://forum.robofont.com/post/3514</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Sat, 14 Nov 2020 20:01:18 GMT</pubDate></item><item><title><![CDATA[Reply to How to turn “line” segment into “curve” segment with code? on Sat, 14 Nov 2020 15:35:53 GMT]]></title><description><![CDATA[<p dir="auto">first thing that I can think of is to use Pen protocol to redraw whole glyph with this particular line turned into the curve, but is it the <strong>"best"</strong> way?</p>
]]></description><link>https://forum.robofont.com/post/3515</link><guid isPermaLink="true">https://forum.robofont.com/post/3515</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Sat, 14 Nov 2020 15:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to turn “line” segment into “curve” segment with code? on Sat, 14 Nov 2020 21:36:11 GMT]]></title><description><![CDATA[<p dir="auto">hello <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/207">@RafaŁ-Buchner</a>,</p>
<p dir="auto">have a look at the <a href="http://github.com/typemytype/batchRoboFontExtension/blob/master/Batch.roboFontExt/lib/variableFontGenerator/__init__.py#L383" rel="nofollow">Batch extension source code</a>, it has a <code>CompatibleContourPointPen</code> which takes a list of segment types to match.</p>
<p dir="auto">this seems to work (you’ll need to have the Batch extension installed):</p>
<pre><code class="language-python">from variableFontGenerator import CompatibleContourPointPen

glyph = CurrentGlyph()

for contour in glyph:
    pointTypes = ['curve' for segment in contour]
    pen = CompatibleContourPointPen(pointTypes)
    contour.drawPoints(pen)
    contour.naked().clear()
    pen.drawPoints(contour.naked())
</code></pre>
<p dir="auto">cheers!</p>
]]></description><link>https://forum.robofont.com/post/3516</link><guid isPermaLink="true">https://forum.robofont.com/post/3516</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Sat, 14 Nov 2020 21:36:11 GMT</pubDate></item><item><title><![CDATA[Reply to How to turn “line” segment into “curve” segment with code? on Sat, 14 Nov 2020 21:39:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/22">@gferreira</a> said in <a href="/post/3516">How to turn the "line" segment into the "curve" segment with the code?</a>:</p>
<blockquote>
<p dir="auto">from variableFontGenerator import CompatibleContourPointPen</p>
<p dir="auto">glyph = CurrentGlyph()</p>
<p dir="auto">for contour in glyph:<br />
pointTypes = ['curve' for segment in contour]<br />
pen = CompatibleContourPointPen(pointTypes)<br />
contour.drawPoints(pen)<br />
contour.naked().clear()<br />
pen.drawPoints(contour.naked())</p>
</blockquote>
<p dir="auto">Thanks Gustavo!!!<br />
It works like a charm!</p>
]]></description><link>https://forum.robofont.com/post/3517</link><guid isPermaLink="true">https://forum.robofont.com/post/3517</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Sat, 14 Nov 2020 21:39:03 GMT</pubDate></item><item><title><![CDATA[Reply to How to turn “line” segment into “curve” segment with code? on Sat, 14 Nov 2020 21:22:42 GMT]]></title><description><![CDATA[<p dir="auto">don't know the context but you can also use the <code>MathGlyphPen</code> from <a href="https://github.com/robotools/fontMath/blob/master/Lib/fontMath/mathGlyph.py#L345" rel="nofollow">fontMath</a> to convert all line segments to curve segments</p>
]]></description><link>https://forum.robofont.com/post/3518</link><guid isPermaLink="true">https://forum.robofont.com/post/3518</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Sat, 14 Nov 2020 21:22:42 GMT</pubDate></item></channel></rss>