Bug 265911 - Simplify conversion of quadratic bezier segments
Summary: Simplify conversion of quadratic bezier segments
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-12-05 15:26 PST by Ahmad Saleem
Modified: 2023-12-12 15:27 PST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2023-12-05 15:26:52 PST
hi Team,

While going through Blink's commits, I came across following simplification commit:

Blink Commit: https://chromium.googlesource.com/chromium/blink/+/a2034c0f6210c1e9f5897340a37e29873575ed2e

WebKit Source: https://searchfox.org/wubkat/rev/1a7afa1ea1ff078e0856c604cc572aa47d35f2eb/Source/WebCore/svg/SVGPathParser.cpp#197 etc.

Locally following compiles:

static FloatPoint blendPoints(const FloatPoint& p1, const FloatPoint& p2)
{
    const float oneOverThree = 1 / 3.f;
    return FloatPoint((p1.x() + 2 * p2.x()) * oneOverThree, (p1.y() + 2 * p2.y()) * oneOverThree);
}

and

static FloatPoint reflectedPoint(const FloatPoint& reflectIn, const FloatPoint& pointToReflect)
{
    return FloatPoint(2 * reflectIn.x() - pointToReflect.x(), 2 * reflectIn.y() - pointToReflect.y());
}

and then following modified:

bool SVGPathParser::parseCurveToQuadraticSmoothSegment()
{
    auto result = m_source.parseCurveToQuadraticSmoothSegment();
    if (!result)
        return false;
    if (m_lastCommand != SVGPathSegType::CurveToQuadraticAbs
        && m_lastCommand != SVGPathSegType::CurveToQuadraticRel
        && m_lastCommand != SVGPathSegType::CurveToQuadraticSmoothAbs
        && m_lastCommand != SVGPathSegType::CurveToQuadraticSmoothRel)
        m_controlPoint = m_currentPoint;
    if (m_pathParsingMode == NormalizedParsing) {
        if (m_mode == RelativeCoordinates) {
            result->targetPoint += m_currentPoint;
        }
        m_controlPoint = reflectedPoint(m_currentPoint, m_controlPoint);
        FloatPoint point1 = blendPoints(m_currentPoint, m_controlPoint);
        FloatPoint point2 = blendPoints(result->targetPoint, m_controlPoint);
        m_consumer.curveToCubic(point1, point2, result->targetPoint, AbsoluteCoordinates);
        m_currentPoint = result->targetPoint;
    } else
        m_consumer.curveToQuadraticSmooth(result->targetPoint, m_mode);

and

bool SVGPathParser::parseCurveToQuadraticSegment()
{
    auto result = m_source.parseCurveToQuadraticSegment();
    if (!result)
        return false;
    if (m_pathParsingMode == NormalizedParsing) {
        m_controlPoint = result->point1;
        if (m_mode == RelativeCoordinates) {
            m_controlPoint += m_currentPoint;
            result->targetPoint += m_currentPoint;
        }
        result->point1 = blendPoints(m_currentPoint, m_controlPoint);
        FloatPoint point2 = blendPoints(result->targetPoint, m_controlPoint);
        m_consumer.curveToCubic(result->point1, point2, result->targetPoint, AbsoluteCoordinates);
        m_currentPoint = result->targetPoint;
    } else
        m_consumer.curveToQuadratic(result->point1, result->targetPoint, m_mode);
    return true;
}

___

Just wanted to raise and ask for input, if it is worth merging.

Thanks!
Comment 1 Radar WebKit Bug Importer 2023-12-12 15:27:17 PST
<rdar://problem/119578490>