Browse Source

Fix drawing glitch when line width < 1px

tags/r14.0.0
Timothy Pearson 6 years ago
parent
commit
6953f22381
4 changed files with 102 additions and 2 deletions
  1. 8
    0
      tdegtk/tdegtk-draw.cpp
  2. 77
    1
      tdegtk/tqtcairopainter.cpp
  3. 1
    1
      tests/Makefile.am
  4. 16
    0
      tests/test-painter.cpp

+ 8
- 0
tdegtk/tdegtk-draw.cpp View File

@@ -1602,6 +1602,7 @@ tdegtk_draw_common_background (DRAW_ARGS)
tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default));
}

#ifdef GTK_TYPE_LEVEL_BAR
else if (gtk_widget_path_is_type(path, GTK_TYPE_LEVEL_BAR)) {
TQStringList objectTypes;
objectTypes.append(TQPROGRESSBAR_OBJECT_NAME_STRING);
@@ -1618,6 +1619,9 @@ tdegtk_draw_common_background (DRAW_ARGS)
DRAW_FILLED_RECTANGLE_OVER_ENTIRE_AREA(p, brush)
}
}
#else // GTK_TYPE_LEVEL_BAR
#warning GTK_TYPE_LEVEL_BAR not available in this version of GTK! Level bars will not be drawn as a result!
#endif // GTK_TYPE_LEVEL_BAR

else if (gtk_widget_path_is_type(path, GTK_TYPE_COMBO_BOX)) {
// Do nothing
@@ -1860,6 +1864,7 @@ tdegtk_draw_common_frame (DRAW_ARGS)
tqApp->style().drawPrimitive(TQStyle::PE_PanelTabWidget, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget));
}

#ifdef GTK_TYPE_LEVEL_BAR
else if (gtk_widget_path_is_type(path, GTK_TYPE_LEVEL_BAR)) {
const GtkAllocation allocation = Gtk::gtk_widget_get_allocation(widget);

@@ -1887,6 +1892,9 @@ tdegtk_draw_common_frame (DRAW_ARGS)
tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p2, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default));
}
}
#else // GTK_TYPE_LEVEL_BAR
#warning GTK_TYPE_LEVEL_BAR not available in this version of GTK! Level bars will not be drawn as a result!
#endif // GTK_TYPE_LEVEL_BAR

else if ((gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BACKGROUND))
|| (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_BOX))

+ 77
- 1
tdegtk/tqtcairopainter.cpp View File

@@ -756,6 +756,24 @@ void TQt3CairoPaintDevice::drawPolygon(const TQPointArray* pointarray, bool wind
cairo_close_path(FASTEST_AVAILABLE_PAINTER);
}
dualStrokePen();

// WARNING
// The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines!
// See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details.
// This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn.
if (m_pen.width() < 1) {
cairo_save(FASTEST_AVAILABLE_PAINTER);
cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1);
for (i=0;i<pointarray->count();i++) {
pointarray->point(i, &x, &y);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
}
cairo_stroke(FASTEST_AVAILABLE_PAINTER);
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
}
}
cairo_restore(FASTEST_AVAILABLE_PAINTER);
@@ -1354,8 +1372,32 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
if (FASTEST_AVAILABLE_PAINTER) {
cairo_save(FASTEST_AVAILABLE_PAINTER);
if (m_pen.style() != TQPen::NoPen) {
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
bool has_current_point = cairo_has_current_point(FASTEST_AVAILABLE_PAINTER);
double cr_x2;
double cr_y2;
cairo_get_current_point(FASTEST_AVAILABLE_PAINTER, &cr_x2, &cr_y2);
int x2 = cr_x2-CAIRO_PEN_PIXEL_OFFSET;
int y2 = cr_y2-CAIRO_PEN_PIXEL_OFFSET;

cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
dualStrokePen();

// WARNING
// The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines!
// See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details.
// This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn.
if (m_pen.width() < 1) {
cairo_save(FASTEST_AVAILABLE_PAINTER);
cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_stroke(FASTEST_AVAILABLE_PAINTER);
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
}
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
@@ -1367,6 +1409,23 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
dualStrokePen();

// WARNING
// The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines!
// See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details.
// This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn.
if (m_pen.width() < 1) {
cairo_save(FASTEST_AVAILABLE_PAINTER);
cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_stroke(FASTEST_AVAILABLE_PAINTER);
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
}
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
@@ -1459,6 +1518,23 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
dualStrokePen();

// WARNING
// The Cairo anti-aliasing code fights back--HARD--when drawing 0px lines!
// See http://projecthamster.wordpress.com/2009/12/22/getting-sharp-pixels-and-actually-something-drawn-using-cairo/ for more details.
// This code works around the problem by overstriking the line end points with a single pixel, thereby ensuring they are properly drawn.
if (m_pen.width() < 1) {
cairo_save(FASTEST_AVAILABLE_PAINTER);
cairo_set_line_cap(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(FASTEST_AVAILABLE_PAINTER, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_width(FASTEST_AVAILABLE_PAINTER, 1);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x+CAIRO_PEN_PIXEL_OFFSET, y+CAIRO_PEN_PIXEL_OFFSET);
cairo_move_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_line_to(FASTEST_AVAILABLE_PAINTER, x2+CAIRO_PEN_PIXEL_OFFSET, y2+CAIRO_PEN_PIXEL_OFFSET);
cairo_stroke(FASTEST_AVAILABLE_PAINTER);
cairo_restore(FASTEST_AVAILABLE_PAINTER);
}
}
}
}

+ 1
- 1
tests/Makefile.am View File

@@ -31,7 +31,7 @@ test_painter_CXXFLAGS = \
$(GTK3_CFLAGS)

test_painter_LDADD = \
$(TDEGTK_LIBADD) ../tdegtk/libtqtcairo.la $(all_libraries) $(CAIRO_LIBS) $(GTK3_LIBS) $(LIB_QT)
$(TDEGTK_LIBADD) ../tdegtk/libtqtcairo.la $(all_libraries) $(CAIRO_LIBS) $(GTK3_LIBS) $(LIB_QT) $(LIB_TDEUI)

test_painter_LDFLAGS = \
$(TDEGTK_LDFLAGS) \

+ 16
- 0
tests/test-painter.cpp View File

@@ -71,6 +71,22 @@ void runTests(TQPaintDevice* pd) {
{
p.setPen( TQt::blue ); // set blue pen, 0 pixel width
p.drawLine(140,140, 160,160);
p.setPen( TQt::blue ); // set blue pen, 0 pixel width
p.drawLine(470,140, 480,160);
p.setPen( TQt::blue ); // set blue pen, 0 pixel width
p.drawLine(470,170, 490,170);
p.setPen( TQPen(TQt::blue, 1) ); // set blue pen, 1 pixel width
p.drawLine(470,180, 490,180);
p.setPen( TQPen(TQt::blue, 2) ); // set blue pen, 2 pixel width
p.drawLine(470,190, 490,190);
p.setPen( TQPen(TQt::blue, 3) ); // set blue pen, 3 pixel width
p.drawLine(470,200, 490,200);
p.setPen( TQPen(TQt::blue, 4) ); // set blue pen, 4 pixel width
p.drawLine(470,210, 490,210);
p.setPen( TQPen(TQt::blue, 5) ); // set blue pen, 5 pixel width
p.drawLine(470,220, 490,220);
p.setPen( TQPen(TQt::blue, 6) ); // set blue pen, 6 pixel width
p.drawLine(470,230, 490,230);
}

// Point tests

Loading…
Cancel
Save