From 47130ea91179bd19a05e84bef300e3ede20665d9 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Mon, 24 Feb 2025 17:36:40 +0100 Subject: [PATCH] ttf_loader: handling contours starting with OFF_CURVE It might happen that the first point doesn't belong to the contour - such cases were observed as artifacts till now. @Issue: https://github.com/thorvg/thorvg/issues/3268 --- src/loaders/ttf/tvgTtfReader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/loaders/ttf/tvgTtfReader.cpp b/src/loaders/ttf/tvgTtfReader.cpp index 19dcd6e0..0a91e028 100644 --- a/src/loaders/ttf/tvgTtfReader.cpp +++ b/src/loaders/ttf/tvgTtfReader.cpp @@ -479,13 +479,13 @@ bool TtfReader::convert(Shape* shape, TtfGlyphMetrics& gmetrics, const Point& of for (uint32_t i = 0; i < cntrsCnt; ++i) { //contour must start with move to + bool offCurve = !(flags[begin] & ON_CURVE); + Point ptsBegin = offCurve ? (pts[begin] + pts[endPts[i]]) * 0.5f : pts[begin]; pathCmds.push(PathCommand::MoveTo); - pathPts.push(pts[begin]); + pathPts.push(ptsBegin); - bool offCurve = false; - auto last = (endPts[i] - begin) + 1; - - for (uint32_t x = 1; x < last; ++x) { + auto cnt = endPts[i] - begin + 1; + for (uint32_t x = 1; x < cnt; ++x) { if (flags[begin + x] & ON_CURVE) { if (offCurve) { pathCmds.push(PathCommand::CubicTo); @@ -511,9 +511,9 @@ bool TtfReader::convert(Shape* shape, TtfGlyphMetrics& gmetrics, const Point& of } if (offCurve) { pathCmds.push(PathCommand::CubicTo); - pathPts.push(pathPts.last() + (2.0f/3.0f) * (pts[begin + last - 1] - pathPts.last())); - pathPts.push(pts[begin] + (2.0f/3.0f) * (pts[begin + last - 1] - pts[begin])); - pathPts.push(pts[begin]); + pathPts.push(pathPts.last() + (2.0f/3.0f) * (pts[begin + cnt - 1] - pathPts.last())); + pathPts.push(ptsBegin + (2.0f/3.0f) * (pts[begin + cnt - 1] - ptsBegin)); + pathPts.push(ptsBegin); } //contour must end with close pathCmds.push(PathCommand::Close);