From 6936878097c7b85a6c497e1c3276bf75f646914b Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Wed, 16 Aug 2023 13:47:31 -0400 Subject: [PATCH] Icon-O-Matic: Fix bugs that occur when pasting text Fixes a small, hard-to-see bug that occurs when pasting text into Icon-O-Matic. Before when pasting, for example, an "O" into IOM, the "O" would not be completely symmetrical. There would be an extra point on one of its sides. Now that point is gone. Also fixes paths not being closed when they should be. Back to the "O" example, one of the two paths that make up the "O" would be open. Now both paths are closed. Also determines whether a point should be connected or disconnected based on whether the control points and the vertices lie on a straight line. (If a point is marked as connected, the control points and the vertex are constrained to lie on the same line.) Change-Id: I0cb9f878ac7887640288073ca253de35b3937f3b Reviewed-on: https://review.haiku-os.org/c/haiku/+/6841 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- .../styled_text/StyledTextImporter.cpp | 39 ++++++++++++++----- src/servers/app/ServerFont.cpp | 4 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/apps/icon-o-matic/import_export/styled_text/StyledTextImporter.cpp b/src/apps/icon-o-matic/import_export/styled_text/StyledTextImporter.cpp index 67be882933..d7be47dba8 100644 --- a/src/apps/icon-o-matic/import_export/styled_text/StyledTextImporter.cpp +++ b/src/apps/icon-o-matic/import_export/styled_text/StyledTextImporter.cpp @@ -1,9 +1,10 @@ /* - * Copyright 2008-2009, Haiku, Inc. All rights reserved. + * Copyright 2008-2009, 2023, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * François Revol + * Zardshard */ #include "StyledTextImporter.h" @@ -112,16 +113,33 @@ ShapeIterator::IterateBezierTo(int32 bezierCount, BPoint *bezierPts) CALLED(); if (!CurrentPath()) return B_ERROR; - BPoint start(bezierPts[0]); - if (fHasLastPoint) - start = fLastPoint; - while (bezierCount--) { - fPath->AddPoint(fOffset + bezierPts[0], - fLastPoint, fOffset + bezierPts[1], true); - fLastPoint = fOffset + bezierPts[2]; - bezierPts += 3; + + BPoint firstPoint(fLastPoint); + fLastPoint = fOffset + bezierPts[bezierCount * 3 - 1]; + + // first point + if (firstPoint == fLastPoint) { + // combine the first and the last point + fPath->AddPoint(firstPoint, + fOffset + bezierPts[bezierCount * 3 - 2], fOffset + bezierPts[0], false); + // Mark the points as disconnected for now. CleanUp will change this if necessary. + fPath->SetClosed(true); + } else { + fPath->AddPoint(firstPoint, firstPoint, fOffset + bezierPts[0], false); } - fPath->AddPoint(fLastPoint); + + // middle points + for (int i = 1; i + 2 < bezierCount * 3; i += 3) { + fPath->AddPoint(fOffset + bezierPts[i + 1], + fOffset + bezierPts[i + 0], fOffset + bezierPts[i + 2], false); + } + + // last point + if (firstPoint != fLastPoint) { + fPath->AddPoint(fLastPoint, + fOffset + bezierPts[bezierCount * 3 - 2], fLastPoint, false); + } + fHasLastPoint = true; return B_OK; } @@ -154,6 +172,7 @@ ShapeIterator::NextPath() { CALLED(); if (fPath) { + fPath->CleanUp(); fIcon->Paths()->AddItem(fPath); fShape->Paths()->AddItem(fPath); } diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 36122bfc56..182e526134 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -74,8 +74,8 @@ ConicToFunc(const FT_Vector *control, const FT_Vector *to, void *user) BPoint controls[3]; controls[0] = VectorToPoint(control); - controls[1] = VectorToPoint(to); - controls[2] = controls[1]; + controls[1] = controls[0]; + controls[2] = VectorToPoint(to); ((BShape *)user)->BezierTo(controls); return 0;