Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 8fdbe96

Browse files
committed
[[ Bug 13220 ]] Make sure we give Cairo a minimal path - if lineTo is followed by close and lineTo target is original moveTo of subpath, then ignore the last lineTo.
1 parent dc2667e commit 8fdbe96

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

docs/notes/bugfix-13220.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Polyline with same starting point as ending point draws as degenerate dot in PDF printing.

revpdfprinter/src/revpdfprinter.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818

1919
#include <cairo-pdf.h>
2020
#include <stdio.h>
21+
#include <float.h>
2122

2223
////////////////////////////////////////////////////////////////////////////////
2324

@@ -750,26 +751,47 @@ void transform_point(double &x, double &y, const MCCustomPrinterTransform &p_tra
750751
x = t_x;
751752
}
752753

754+
// MW-2014-08-19: [[ Bug 13220 ]] It seems Cairo doesn't like (M p) (L _)* (L p) (C)
755+
// as it ends up treating it is as a degenerate point. Therefore we clean up this
756+
// case - if there is a lineTo which returns to the original moveTo then a close
757+
// it ignores the final lineTo.
753758
bool MCPDFPrintingDevice::draw_path(const MCCustomPrinterPath &p_path)
754759
{
755760
bool t_success = true;
756761

757762
MCCustomPrinterPathCommand *t_commands = p_path.commands;
758763
MCCustomPrinterPoint *t_points = p_path.coords;
759764

765+
double t_first_x, t_first_y;
766+
t_first_x = t_first_y = DBL_MAX;
767+
768+
double t_last_x, t_last_y;
769+
t_last_x = t_last_y = DBL_MAX;
770+
760771
while (t_success && *t_commands != kMCCustomPrinterPathEnd)
761772
{
762773
switch (*t_commands++)
763774
{
764775
case kMCCustomPrinterPathMoveTo:
765776
{
766777
cairo_move_to(m_context, t_points->x, t_points->y);
778+
t_first_x = t_points -> x;
779+
t_first_y = t_points -> y;
767780
t_points++;
768781
}
769782
break;
770783
case kMCCustomPrinterPathLineTo:
771784
{
772-
cairo_line_to(m_context, t_points->x, t_points->y);
785+
if (t_last_x != t_points -> x || t_last_y != t_points -> y)
786+
{
787+
if (*t_commands != kMCCustomPrinterPathClose ||
788+
(t_first_x != t_points -> x || t_first_y != t_points -> y))
789+
{
790+
cairo_line_to(m_context, t_points->x, t_points->y);
791+
t_last_x = t_points -> x;
792+
t_last_y = t_points -> y;
793+
}
794+
}
773795
t_points++;
774796
}
775797
break;

0 commit comments

Comments
 (0)