Fix outline preview of contour tool.

The purpose of this fix is to correct the outline preview of the
Contour Tool when:
- is used with custom brush,
- with alpha content,
- and pixel perfect mode OFF.

Before this fix, the outline was being printed more than twice in some
places (only noticed with alpha content), giving a bad appearance.
This commit is contained in:
Gaspar Capello 2019-06-03 11:54:35 -03:00 committed by David Capello
parent be74723e37
commit 62802cfbdf
2 changed files with 43 additions and 59 deletions

View File

@ -68,47 +68,32 @@ public:
};
class IntertwineAsLines : public Intertwine {
Stroke m_lastPointPrinted;
Stroke m_pts;
void saveLastPointAndDoPointshape(ToolLoop* loop, const Stroke& stroke) {
m_lastPointPrinted = stroke;
doPointshapePoint(stroke[0].x, stroke[0].y, loop);
}
public:
bool snapByAngle() override { return true; }
void prepareIntertwine() override {
m_pts.reset();
}
void joinStroke(ToolLoop* loop, const Stroke& stroke) override {
if (loop->getTracePolicy() == TracePolicy::Last)
m_pts.reset();
if (stroke.size() == 0)
return;
if (stroke.size() == 1) {
saveLastPointAndDoPointshape(loop, stroke);
else if (stroke.size() == 1) {
if (m_pts.empty())
m_pts = stroke;
doPointshapePoint(stroke[0].x, stroke[0].y, loop);
return;
}
else if (stroke.size() >= 2) {
if (stroke.size() == 2 && stroke[0] == stroke[1]) {
if (m_lastPointPrinted.empty()) {
saveLastPointAndDoPointshape(loop, stroke);
return;
}
else {
if (m_lastPointPrinted[0] != stroke[0] ||
loop->getTracePolicy() == TracePolicy::Last) {
saveLastPointAndDoPointshape(loop, stroke);
return;
}
}
}
else {
doc::AlgoLineWithAlgoPixel lineAlgo = getLineAlgo(loop);
for (int c=0; c+1<stroke.size(); ++c) {
lineAlgo(
stroke[c].x,
stroke[c].y,
stroke[c+1].x,
stroke[c+1].y,
lineAlgo(stroke[c].x, stroke[c].y,
stroke[c+1].x, stroke[c+1].y,
(void*)&m_pts,
(AlgoPixel)&addPointsWithoutDuplicatingLastOne);
}
@ -126,12 +111,6 @@ public:
for (int c=start; c<m_pts.size(); ++c)
doPointshapePoint(m_pts[c].x, m_pts[c].y, loop);
ASSERT(!m_lastPointPrinted.empty());
m_lastPointPrinted[0] = m_pts[m_pts.size()-1];
}
m_pts.reset();
}
// Closed shape (polygon outline)
// Note: Contour tool was getting into the condition with no need, so
// we add the && !isFreehand to detect this circunstance.
@ -144,6 +123,7 @@ public:
stroke[0].x, stroke[0].y, loop);
}
}
}
void fillStroke(ToolLoop* loop, const Stroke& stroke) override {
if (stroke.size() < 3) {

View File

@ -255,6 +255,10 @@ void ToolLoopManager::doLoopStep(bool lastStep)
m_toolLoop->validateDstImage(gfx::Region(m_toolLoop->getDstImage()->bounds()));
}
}
else if (m_toolLoop->getBrush()->type() == kImageBrushType) {
m_toolLoop->invalidateDstImage();
m_toolLoop->validateDstImage(gfx::Region(m_toolLoop->getDstImage()->bounds()));
}
m_toolLoop->validateDstImage(m_dirtyArea);