28#include "glChartCanvas.h"
29#include "ocpn_frame.h"
30#include "ocpn_print.h"
38bool MyPrintout::OnPrintPage(
int page) {
41 if (page == 1) DrawPageOne(dc);
48bool MyPrintout::OnBeginDocument(
int startPage,
int endPage) {
49 if (!wxPrintout::OnBeginDocument(startPage, endPage))
return false;
54void MyPrintout::GetPageInfo(
int* minPage,
int* maxPage,
int* selPageFrom,
62bool MyPrintout::HasPage(
int pageNum) {
return (pageNum == 1); }
64void MyPrintout::DrawPageOne(wxDC* dc) {
67 gFrame->GetFocusCanvas()->GetClientSize(&sx, &sy);
77 maxX += (2 * marginX);
78 maxY += (2 * marginY);
85 float scaleX = (float)(w / maxX);
86 float scaleY = (float)(h / maxY);
89 float actualScale = wxMin(scaleX, scaleY);
92 float posX = (float)((w - (maxX * actualScale)) / 2.0);
93 float posY = (float)((h - (maxY * actualScale)) / 2.0);
95 posX = wxMax(posX, marginX);
96 posY = wxMax(posY, marginY);
99 dc->SetUserScale(actualScale, actualScale);
100 dc->SetDeviceOrigin((
long)posX, (
long)posY);
106 if (m_GLbmp.IsOk()) {
108 mdc.SelectObject(m_GLbmp);
109 dc->Blit(0, 0, m_GLbmp.GetWidth(), m_GLbmp.GetHeight(), &mdc, 0, 0);
110 mdc.SelectObject(wxNullBitmap);
116 mdc.SelectObject(*(gFrame->GetFocusCanvas()->pscratch_bm));
118 dc->Blit(0, 0, gFrame->GetFocusCanvas()->pscratch_bm->GetWidth(),
119 gFrame->GetFocusCanvas()->pscratch_bm->GetHeight(), &mdc, 0, 0);
121 mdc.SelectObject(wxNullBitmap);
125void MyPrintout::GenerateGLbmp() {
128 int gsx = gFrame->GetFocusCanvas()->GetglCanvas()->GetSize().x;
129 int gsy = gFrame->GetFocusCanvas()->GetglCanvas()->GetSize().y;
131 unsigned char* buffer = (
unsigned char*)malloc(gsx * gsy * 4);
132 glReadPixels(0, 0, gsx, gsy, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
134 unsigned char* e = (
unsigned char*)malloc(gsx * gsy * 3);
137 for (
int p = 0; p < gsx * gsy; p++) {
138 e[3 * p + 0] = buffer[4 * p + 0];
139 e[3 * p + 1] = buffer[4 * p + 1];
140 e[3 * p + 2] = buffer[4 * p + 2];
145 wxImage image(gsx, gsy);
147 wxImage mir_imag = image.Mirror(
false);
148 m_GLbmp = wxBitmap(mir_imag);