28#include "glChartCanvas.h"
29#include "ocpn_frame.h"
30#include "ocpn_print.h"
39bool MyPrintout::OnPrintPage(
int page) {
42 if (page == 1) DrawPageOne(dc);
49bool MyPrintout::OnBeginDocument(
int startPage,
int endPage) {
50 if (!wxPrintout::OnBeginDocument(startPage, endPage))
return false;
55void MyPrintout::GetPageInfo(
int* minPage,
int* maxPage,
int* selPageFrom,
63bool MyPrintout::HasPage(
int pageNum) {
return (pageNum == 1); }
65void MyPrintout::DrawPageOne(wxDC *dc) {
68 gFrame->GetFocusCanvas()->GetClientSize(&sx, &sy);
78 maxX += (2 * marginX);
79 maxY += (2 * marginY);
86 float scaleX = (float)(w / maxX);
87 float scaleY = (float)(h / maxY);
90 float actualScale = wxMin(scaleX, scaleY);
93 float posX = (float)((w - (maxX * actualScale)) / 2.0);
94 float posY = (float)((h - (maxY * actualScale)) / 2.0);
96 posX = wxMax(posX, marginX);
97 posY = wxMax(posY, marginY);
100 dc->SetUserScale(actualScale, actualScale);
101 dc->SetDeviceOrigin((
long)posX, (
long)posY);
107 if (m_GLbmp.IsOk()) {
109 mdc.SelectObject(m_GLbmp);
110 dc->Blit(0, 0, m_GLbmp.GetWidth(), m_GLbmp.GetHeight(), &mdc, 0, 0);
111 mdc.SelectObject(wxNullBitmap);
117 mdc.SelectObject(*(gFrame->GetFocusCanvas()->pscratch_bm));
119 dc->Blit(0, 0, gFrame->GetFocusCanvas()->pscratch_bm->GetWidth(),
120 gFrame->GetFocusCanvas()->pscratch_bm->GetHeight(), &mdc, 0, 0);
122 mdc.SelectObject(wxNullBitmap);
126void MyPrintout::GenerateGLbmp() {
129 int gsx = gFrame->GetFocusCanvas()->GetglCanvas()->GetSize().x;
130 int gsy = gFrame->GetFocusCanvas()->GetglCanvas()->GetSize().y;
132 unsigned char *buffer = (
unsigned char *)malloc(gsx * gsy * 4);
133 glReadPixels(0, 0, gsx, gsy, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
135 unsigned char *e = (
unsigned char *)malloc(gsx * gsy * 3);
138 for (
int p = 0; p < gsx * gsy; p++) {
139 e[3 * p + 0] = buffer[4 * p + 0];
140 e[3 * p + 1] = buffer[4 * p + 1];
141 e[3 * p + 2] = buffer[4 * p + 2];
146 wxImage image(gsx, gsy);
148 wxImage mir_imag = image.Mirror(
false);
149 m_GLbmp = wxBitmap(mir_imag);