On screen I paint a rectangle with 10% transparency using
Code: Select all
dc->SetBrush(wxColour(col.Red(), col.Green(), col.Blue(), 0x19));
Thank you.
Code: Select all
dc->SetBrush(wxColour(col.Red(), col.Green(), col.Blue(), 0x19));
Unfortunately, wxPdfDC currently doesn't support alpha transparency, although the underlying wxPdfDocument class does. It shouldn't be too hard to add this capability. However, it would need testing.mael15 wrote: ↑Fri Aug 23, 2019 2:01 pm On screen I paint a rectangle with 10% transparency usingWhen I create a pdf with wxPdfDc using the same code, this rectangle is not transparent. How can I make it 10% transparent?Code: Select all
dc->SetBrush(wxColour(col.Red(), col.Green(), col.Blue(), 0x19));
In the meantime I have implemented the alpha transparency support for wxPdfDC. Commit a03399b on GitHub provides the updated source code. Please give it a try.
but it does not show up in the pdf.> wxpdfdocd.dll!wxPdfDCImpl::DoDrawRectangle(int x, int y, int width, int height) Zeile 791 C++
wxmsw313ud_core_vc_x64_custom.dll!wxDC::DrawRectangle(int x, int y, int width, int height) Zeile 1170 C++
Could you please provide a small code sample for testing? TIAmael15 wrote: ↑Fri Sep 06, 2019 9:36 am Thank you!
It does not work yet. I saw the alpha value was there in SetupAlpha() inbut it does not show up in the pdf.> wxpdfdocd.dll!wxPdfDCImpl::DoDrawRectangle(int x, int y, int width, int height) Zeile 791 C++
wxmsw313ud_core_vc_x64_custom.dll!wxDC::DrawRectangle(int x, int y, int width, int height) Zeile 1170 C++
You don't have to tweak the project files. All what is required is to adjust the settings in the file wx_setup.props. Change the lines defining the options wxCompilerPrefix and wxMsvcVersionAuto, so that they look like this:mael15 wrote: ↑Fri Sep 06, 2019 9:36 am On more sidenote:
It was a bit difficult to build with Visual Studio 2019 debug dll x64. The vc15 project uses wxCompilerPrefix in the include paths, but the wxWidgets build does not. Quite a bit of tweaking was necessary to get rid of all the "142" everywhere, i.a. vc_x64_dll instead of vc142_x64_dll.
Code: Select all
<wxCompilerPrefix>vc</wxCompilerPrefix>
<wxMsvcVersionAuto></wxMsvcVersionAuto>
Sorry, most likely that has to be some improper use of the wxDC API. I just tested myself drawing transparent rectangles on a wxPdfDC ... and the resulting PDF clearly showed transparent rectangles.mael15 wrote: ↑Fri Sep 06, 2019 9:36 am It does not work yet. I saw the alpha value was there in SetupAlpha() inbut it does not show up in the pdf.> wxpdfdocd.dll!wxPdfDCImpl::DoDrawRectangle(int x, int y, int width, int height) Zeile 791 C++
wxmsw313ud_core_vc_x64_custom.dll!wxDC::DrawRectangle(int x, int y, int width, int height) Zeile 1170 C++
Code: Select all
#pragma once
#include <wx/frame.h>
#include <wx/app.h>
#include <wx/dcbuffer.h>
#include <wx/dcgraph.h>
#include <wx/pdfdocument.h>
#include "wx/pdfdc.h"
class MyPanel : public wxPanel {
public:
MyPanel(wxWindow* par) : wxPanel(par) {
Connect(wxEVT_PAINT, wxPaintEventHandler(MyPanel::OnPaint));
}
void OnPaint(wxPaintEvent& event) {
wxBufferedPaintDC dc(this);
dc.SetBrush(*wxGREY_BRUSH);
dc.Clear();
wxGCDC gcdc(dc);
draw(&gcdc);
}
void draw(wxDC *dc);
};
class MyFrame1 : public wxFrame
{
public:
MyFrame1( wxWindow* parent = NULL,
wxWindowID id = wxID_ANY,
const wxString& title = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize( 500,300 ),
long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~MyFrame1(){}
void onButtonClicked(wxCommandEvent &evt) {
wxPdfDC* dc = nullptr;
wxPdfDocument pdfDcmt;
pdfDcmt.AddPage(wxPORTRAIT, wxPAPER_A4);
int tpl = pdfDcmt.BeginTemplate();
dc = new wxPdfDC(&pdfDcmt, 210, 297);
dc->SetResolution(600);
dc->SetBackground(*wxWHITE_BRUSH);
if (dc->StartDoc(wxT("Printing ...")))
{
//OutputDebugString(wxString::Format(wxT("Seite %i wird gedruckt\n"), i));
myPan->draw(dc);
dc->EndDoc();
}
pdfDcmt.EndTemplate();
pdfDcmt.UseTemplate(tpl);
pdfDcmt.SaveAsFile(wxGetUserHome() + wxT("\\Desktop\\test.pdf"));
}
private:
MyPanel* myPan = nullptr;
};
class MyApp : public wxApp {
virtual bool OnInit();
};
Code: Select all
#include "app.h"
#include <wx/sizer.h>
#include <wx/button.h>
bool MyApp::OnInit() {
MyFrame1 *mainFrame = new MyFrame1();
mainFrame->Show();
SetTopWindow(mainFrame);
return TRUE;
}
wxIMPLEMENT_APP(MyApp);
MyFrame1::MyFrame1( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) :
wxFrame( parent, id, title, pos, size, style )
{
SetSizer(new wxBoxSizer(wxVERTICAL));
wxButton *but = new wxButton(this, wxID_ANY, wxT("create pdf"));
Bind(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame1::onButtonClicked), this);
GetSizer()->Add(but);
myPan = new MyPanel(this);
GetSizer()->Add(myPan, 1, wxEXPAND);
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
this->Centre( wxBOTH );
}
void MyPanel::draw(wxDC *dc)
{
wxSize dcSize = dc->GetSize();
dc->SetBrush(wxColour(255, 0, 0, 25));
dc->DrawCircle(dcSize.x * 0.3, dcSize.y * 0.5, dcSize.GetHeight() * 0.5);
dc->SetBrush(wxColour(0, 255, 0, 25));
dc->DrawCircle(dcSize.x * 0.7, dcSize.y * 0.5, dcSize.GetHeight() * 0.5);
}
Aaaaaah, okay, nice! I will check it first thing Monday. Thank you very much for the quick fix and have a nice weekend!
Yes, Works now!
Also very helpfulutelle wrote: ↑Fri Sep 06, 2019 11:18 am You don't have to tweak the project files. All what is required is to adjust the settings in the file wx_setup.props. Change the lines defining the options wxCompilerPrefix and wxMsvcVersionAuto, so that they look like this:
Code: Select all
<wxCompilerPrefix>vc</wxCompilerPrefix>
<wxMsvcVersionAuto></wxMsvcVersionAuto>
Thereafter building the project should work like expected.