[cairo] cairo dash line bug? an unexpected polygon was rendered when drawing the dash line rectangle

Lonely Hiker lonely_hiker09 at yahoo.com
Wed Jun 24 16:44:34 PDT 2009


Hi All,
 
I am new to Cairo and today i encounter a dash line problem on Win32.
 
I had some testing code for it:
 
void TestBug(cairo_t *ct)
{
 cairo_new_path(ct); 
 double dashes[] = {5.0 /*ink*/,1.0/*skip */};
 int    ndash  = sizeof (dashes)/sizeof(dashes[0]);
 double offset = 0;
 cairo_set_dash (ct, dashes, ndash, offset);
 cairo_set_source_rgb(ct,0,1.0,0);
 cairo_set_line_width(ct,1);
 cairo_move_to(ct, 808, 384);
 cairo_line_to(ct, 1283, 384);
 cairo_line_to(ct, 1283, 576);
 cairo_line_to(ct, 808, 576);
 cairo_close_path(ct);
 cairo_stroke(ct);
}
 
I ran the test application and tried to resize the window slowly so that the retangle can be cut-off. During the resizing, at some position the rendering showed this bug: it filled a huge polygon with the color that was set for the stroke and covered part of the rectangle. You can see this in the attachment.
 
I guess this is a cairo dash line bug? Any idea is appreciated.
 
Here is the test application:
 
#include "stdafx.h"
#include <cairo.h>
#include <cairo-win32.h>
#include <windowsx.h>
HINSTANCE hInst;        // current instance
ATOM    MyRegisterClass(HINSTANCE hInstance);
BOOL    InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
 MSG msg;
 MyRegisterClass(hInstance);
 if (!InitInstance (hInstance, nCmdShow)) 
 {
  return FALSE;
 }
 while (GetMessage(&msg, NULL, 0, 0)) 
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
 WNDCLASSEX wcex;
 wcex.cbSize = sizeof(WNDCLASSEX); 
 wcex.style   = CS_HREDRAW | CS_VREDRAW;
 wcex.lpfnWndProc = (WNDPROC)WndProc;
 wcex.cbClsExtra  = 0;
 wcex.cbWndExtra  = 0;
 wcex.hInstance  = hInstance;
 wcex.hIcon   = 0;//LoadIcon(hInstance, (LPCTSTR)IDI_TESTVTUNE);
 wcex.hCursor  = LoadCursor(NULL, IDC_ARROW);
 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wcex.lpszMenuName = 0;//(LPCTSTR)IDC_TESTVTUNE;
 wcex.lpszClassName = "Test cairo";//szWindowClass;
 wcex.hIconSm  = 0;//LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
 return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   hInst = hInstance; // Store instance handle in our global variable
   hWnd = CreateWindow("Test cairo", "test cairo", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd)
   {
      return FALSE;
   }
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   return TRUE;
}
void TestBug(cairo_t *ct)
{
 cairo_new_path(ct); 
 double dashes[] = {5.0 /*ink*/,1.0/*skip */};
 int    ndash  = sizeof (dashes)/sizeof(dashes[0]);
 double offset = 0;
 cairo_set_dash (ct, dashes, ndash, offset);
 cairo_set_source_rgb(ct,0,1.0,0);
 cairo_set_line_width(ct,1);
 cairo_move_to(ct, 808, 384);
 cairo_line_to(ct, 1283, 384);
 cairo_line_to(ct, 1283, 576);
 cairo_line_to(ct, 808, 576);
 cairo_close_path(ct);
 cairo_stroke(ct);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 int wmId, wmEvent;
 PAINTSTRUCT ps;
 HDC hdc;
 switch (message) 
 {
 case WM_COMMAND:
  wmId    = LOWORD(wParam); 
  wmEvent = HIWORD(wParam); 
  // Parse the menu selections:
  switch (wmId)
  {
  default:
   return DefWindowProc(hWnd, message, wParam, lParam);
  }
  break;
 case WM_PAINT:
  {
  hdc = BeginPaint(hWnd, &ps);
  cairo_surface_t *surface = cairo_win32_surface_create(hdc);
  cairo_t *cr = cairo_create(surface);
  TestBug(cr);
  cairo_destroy(cr);
  cairo_surface_destroy(surface);
  EndPaint(hWnd, &ps);
  }
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hWnd, message, wParam, lParam);
 }
 return 0;
}

Thanks in advance!!!
Nick Wu
 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20090624/4fdb1877/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DashLineBug.JPG
Type: image/pjpeg
Size: 30867 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20090624/4fdb1877/attachment-0001.bin 


More information about the cairo mailing list