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 <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Zardshard 2023-08-16 13:47:31 -04:00 committed by waddlesplash
parent 52050c56f6
commit 6936878097
2 changed files with 31 additions and 12 deletions

View File

@ -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 <revol@free.fr>
* 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);
}

View File

@ -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;