PDF Polygons with cutouts

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
ees
In need of some credit
In need of some credit
Posts: 7
Joined: Mon May 22, 2017 7:37 pm

PDF Polygons with cutouts

Post by ees »

Hello,
Is it a known issue that cutouts of polygons will not be written to a pdf? I know the following is not enough code to reproduce the problem, but I just want to give a general idea of what I am doing and ask whether or not it should work or if this is a known issue. All of this is legacy code, I am not sure why it was done this way, or if it is the best way to do it. It does work correctly on the screen though.

Basically, it creates a polygon, and subtracts some cutouts. Then, (and this is the part that seems a little iffy), it create a rectangle that is the extent of the polygon. It sets the clipping region to the original polygon, and draws the rectangle. Wx automatically clips the rectangle and the correct result including cutouts is drawn to the screen. However in the pdf, I am just getting the rectangle with no clipping.

Here are snippets of code. (Again, I know it is not enough to reproduce the problem, I'm just asking if it is expected to be able to work this way for the pdf.)

Code: Select all

// Create the polygon.
(*addr_graphics_region).mWX_region = new wxRegion(number_of_positions,(wxPoint *) position_array,wxWINDING_RULE);

// Create a cutout.  May be several of these.
(*addr_graphics_region).mWX_region->Subtract(*((*addr_subtract_graphics_region).mWX_region));

// Create the rectangle.
    wxCoord x;
    wxCoord y;
    wxCoord w;
    wxCoord h;

    (*addr_graphics_region).mWX_region->GetBox(x,y,w,h);

    rect_position_array[0].x_coord = x;
    rect_position_array[0].y_coord = y;
    rect_position_array[1].x_coord = x+w;
    rect_position_array[1].y_coord = y;
    rect_position_array[2].x_coord = x+w;
    rect_position_array[2].y_coord = y+h;
    rect_position_array[3].x_coord = x;
    rect_position_array[3].y_coord = y+h;
    rect_position_array[4].x_coord = x;
    rect_position_array[4].y_coord = y;

// Set the clipping region.
dc->SetDeviceClippingRegion(*((*addr_graphics_region).mWX_region));

// Draw the rectangle.
dc->DrawPolygon(5,(wxPoint *) rect_position_array,0,0,wxODDEVEN_RULE);

Thanks for your help and for all of your work on wx.

Ed
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: PDF Polygons with cutouts

Post by doublemax »

It's unclear which component you're using. wxPDFDocument?
What type is "dc" in the code you've shown?
Use the source, Luke!
ees
In need of some credit
In need of some credit
Posts: 7
Joined: Mon May 22, 2017 7:37 pm

Re: PDF Polygons with cutouts

Post by ees »

Hi,
Yes, I'm using wxPDFDocument. I believe it is a wxPDFdc. It is the dc that gets passed in automatically to my Print routine. Here is some more code. This is all new to me so maybe I got something basic wrong.

Code: Select all

wxPrintData PrintData;
write_pdf_file__load_print_data(pdf_file_p,&PrintData); // Just calls PrintData->SetFilename
wxPdfPrinter printer(&PrintData);

itiPrintout *printout = NULL;

printout = new itiPrintoutDesign(&entry_edit_pair, &PrintData);

printout->SetOutputFilename(pdf_file_p->file_attribute.file_pathname);

printout->SetPrintToPDF(true);

if (!printer.Print(PantheonFrame::GetInstance(), printout, false))
    {
        if (wxPrinter::GetLastError() == wxPRINTER_ERROR)
        {
            wxMessageBox(_T("There was a problem printing.\nPerhaps your current printer is not set correctly?"), _T("Printing"), wxOK);
        }
    }

itiPrintout::itiPrintout(const wxPrintData *pPrintData,const wxString& title) :
    wxPrintout(title),
    mpPrintData(*pPrintData),
    mStartPage(0),
    mEndPage(0),
    mTotalPages(0),
    mPrintToPDF(false),
    mColor(pPrintData->GetColour())
{
}

bool itiPrintout::Print(int page, wxDC *dc) // I'm assuming a wxPdfDC gets passed in here.
{
    dc->SetDeviceOrigin(0,0);
    dc->SetClippingRegion(0,0,9000,6000); // These values are hardcoded for now until I get everything else working.

    dc->SetFont(*wxNORMAL_FONT) ;
    
    DrawDbObjects(dc); // This does the heavy lifting.  

    dc->SetFont(*wxNORMAL_FONT) ;
    dc->DestroyClippingRegion();

    return true;
}

Thanks,

Ed
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF Polygons with cutouts

Post by utelle »

ees wrote:Yes, I'm using wxPDFDocument. I believe it is a wxPDFdc. It is the dc that gets passed in automatically to my Print routine. Here is some more code. This is all new to me so maybe I got something basic wrong.
I haven't inspected your code snippets in detail ... probably they are all right. However, the problem you observed is unfortunately a deficiency of the wxPdfDC class. Currently, only rectangular clipping regions are supported/implemented. Since wxPdfDocument itself supports more complex clipping regions, it shouldn't be too hard to support them in wxPdfDC as well. But it has to be implemented ...

Regards,

Ulrich
ees
In need of some credit
In need of some credit
Posts: 7
Joined: Mon May 22, 2017 7:37 pm

Re: PDF Polygons with cutouts

Post by ees »

Thanks Ulrich,
Is there any kind of timetable? Or is it a low priority? (Which I would totally understand.)

Ed
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF Polygons with cutouts

Post by utelle »

ees wrote:Is there any kind of timetable? Or is it a low priority? (Which I would totally understand.)
The wxPdfDC class already exists for several years and you are the first reporting this deficiency. That is, probably not many users are affected.

Since I was not aware of this deficiency, there is currently no time schedule. I'll try to dedicate some time to solving this issue, but I can't predict how long it will take. Maybe you could open an issue for it on GitHub. Then you will be automatically informed, when it is implemented.

Regards,

Ulrich
ees
In need of some credit
In need of some credit
Posts: 7
Joined: Mon May 22, 2017 7:37 pm

Re: PDF Polygons with cutouts

Post by ees »

Sounds good.

Thanks Ulrich.

Ed
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: PDF Polygons with cutouts

Post by utelle »

I spent some time on inspecting the internals of how the wxDC class does implement clipping.

Unfortunately, the wxRegion class that is used to define complex clipping regions, has no interface methods to access the precise definition of the clipping region. One can get only the bounding box of the clipping region (that's what wxPdfDC currently uses), or a bitmap representation of the clipping region. PDF is a vector format, that is, a clippling region given as a bitmap isn't particularly useful.

I'm sorry, but I don't see a realistic chance to support complex clipping regions for wxPdfDC.

For complex tasks I would recommend to use wxPdfDocument directly instead of using wxPdfDC.

Regards,

Ulrich
Post Reply