Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Other changes:
* [#667](../../issues/667) remove CalChartDoc begin and end
* [#669](../../issues/669) Put mCurrentReferencePoint into core/show
* [#671](../../issues/671) Remove GetCurrentSheet from Doc
* [#677](../../issues/677) We should have a print configuration
* [#679](../../issues/679) Fix the broken build by updating docopt

4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ add_executable(
PreferencesGeneralSetup.h
PreferencesPrintContinuitySetup.cpp
PreferencesPrintContinuitySetup.h
PreferencesPrintingSetup.cpp
PreferencesPrintingSetup.hpp
PreferencesPSPrintingSetup.cpp
PreferencesPSPrintingSetup.h
PreferencesShowModeSetup.cpp
Expand All @@ -110,6 +112,8 @@ add_executable(
PrintContinuityEditor.h
PrintContinuityPreview.cpp
PrintContinuityPreview.h
PrintingPreview.cpp
PrintingPreview.hpp
PrintPostScriptDialog.cpp
PrintPostScriptDialog.h
SetupInstruments.cpp
Expand Down
120 changes: 74 additions & 46 deletions src/CalChartDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ auto CalculatePointsPerLine(
namespace {
auto GeneratePrintField(
CalChart::Configuration const& config,
CalChartDoc const& show,
CalChart::ShowMode const& mode,
std::vector<std::string> const& labels,
CalChart::Sheet const& sheet,
int ref,
bool landscape) -> std::tuple<double, std::vector<CalChart::Draw::DrawCommand>>
Expand All @@ -429,17 +430,17 @@ namespace {
// create a field for drawing:
const auto pts = sheet.GetAllMarchers();
auto boundingBox = GetMarcherBoundingBox(pts);
auto mode = show.GetShowMode().CreateFieldForPrinting(CalChart::CoordUnits2Int(boundingBox.first.x), CalChart::CoordUnits2Int(boundingBox.second.x), landscape);
auto drawCmds = CalChart::CreateModeDrawCommandsWithBorder(config, mode, CalChart::HowToDraw::Printing);
auto printMode = mode.CreateFieldForPrinting(CalChart::CoordUnits2Int(boundingBox.first.x), CalChart::CoordUnits2Int(boundingBox.second.x), landscape);
auto drawCmds = CalChart::CreateModeDrawCommandsWithBorder(config, printMode, CalChart::HowToDraw::Printing);
CalChart::append(drawCmds,
CalChart::Draw::toDrawCommands(std::views::iota(0u, pts.size())
| std::views::transform([&](auto i) {
return pts.at(i).GetDrawCommands(ref, show.GetPointLabel(i), config);
return pts.at(i).GetDrawCommands(ref, labels.at(i), config);
})
| std::views::join)
+ mode.Offset());
+ printMode.Offset());

return { static_cast<double>(mode.Size().x), drawCmds };
return { static_cast<double>(printMode.Size().x), drawCmds };
}

auto GenerateLargePrintElements(bool landscape, wxSize page, std::string sheetName)
Expand Down Expand Up @@ -488,75 +489,97 @@ namespace {
}
}

void DrawForPrintingHelper(
void DrawForPrintingContinuity(
wxDC& dc,
wxSize pageSize,
CalChart::Configuration const& config,
CalChart::Sheet const& sheet,
bool landscape,
double scale_x,
std::vector<CalChart::Draw::DrawCommand> fieldDrawCommand)
bool landscape)
{
// set up everything to be restored after we print
SaveAndRestore::DeviceOrigin orig_dev(dc);
SaveAndRestore::UserScale orig_scale(dc);
SaveAndRestore::Font orig_font(dc);

// get the page dimensions
auto page = dc.GetSize();

// a possible future optimization would be to generate this ahead of time.
auto printLayout = CalChart::PrintContinuityLayout::Parse(sheet.GetRawPrintContinuity());
auto printDrawCommands = GenerateDrawCommands(dc, config, printLayout, wxRect(wxPoint(10, page.y * kContinuityStart[landscape]), wxSize(page.x - 20, page.y - page.y * kContinuityStart[landscape])), landscape);

dc.Clear();
dc.SetLogicalFunction(wxCOPY);

// Print the field:
auto printDrawCommands = GenerateDrawCommands(dc, config, printLayout, wxRect(wxPoint(10, pageSize.y * kContinuityStart[landscape]), wxSize(pageSize.x - 20, pageSize.y - pageSize.y * kContinuityStart[landscape])), landscape);

// set the origin and scaling for drawing the field
dc.SetDeviceOrigin(kFieldBorderOffset * page.x, kFieldTop * page.y);

// create a field for drawing:
auto scale = tDIP(page.x - 2 * kFieldBorderOffset * page.x) / scale_x;
// Because we are drawing to a bitmap, DIP isn't happening. So we compensate by changing the scaling.
dc.SetUserScale(scale, scale);
// set the page for drawing:
auto sizeX = (landscape) ? kSizeXLandscape : kSizeX;
auto sizeY = (landscape) ? kSizeYLandscape : kSizeY;
// because we are drawing to a bitmap, we manipulate the scaling factor so it just draws as normal
dc.SetUserScale(tDIP(pageSize.x) / sizeX, tDIP(pageSize.y) / sizeY);
pageSize.x = fDIP(sizeX);
pageSize.y = fDIP(sizeY);

// draw the field.
wxCalChart::Draw::DrawCommandList(dc, fieldDrawCommand);
// now draw the continuity into its own box. It uses Stack layout so needs to have a constrained area.
wxCalChart::Draw::DrawCommandList(dc,
wxCalChart::Draw::DrawSurface{
{ 0, 0 },
wxSize(pageSize.x - 20, pageSize.y * (1 - kContinuityStart[landscape])) },
std::vector{ printDrawCommands } + CalChart::Coord(10, pageSize.y * kContinuityStart[landscape]));
}

// now reset everything to draw the rest of the text
dc.SetDeviceOrigin(CalChart::Int2CoordUnits(0), CalChart::Int2CoordUnits(0));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
void DrawForPrintingElements(
wxDC& dc,
wxSize pageSize,
CalChart::Sheet const& sheet,
bool landscape)
{
// set up everything to be restored after we print
SaveAndRestore::DeviceOrigin orig_dev(dc);
SaveAndRestore::UserScale orig_scale(dc);
SaveAndRestore::Font orig_font(dc);

// set the page for drawing:
page = dc.GetSize();
auto sizeX = (landscape) ? kSizeXLandscape : kSizeX;
auto sizeY = (landscape) ? kSizeYLandscape : kSizeY;
// because we are drawing to a bitmap, we manipulate the scaling factor so it just draws as normal
dc.SetUserScale(tDIP(page.x) / sizeX, tDIP(page.y) / sizeY);
page.x = fDIP(sizeX);
page.y = fDIP(sizeY);
dc.SetUserScale(tDIP(pageSize.x) / sizeX, tDIP(pageSize.y) / sizeY);
pageSize.x = fDIP(sizeX);
pageSize.y = fDIP(sizeY);

auto drawCmds = std::vector<CalChart::Draw::DrawCommand>{};

CalChart::append(drawCmds,
CalChart::Draw::withFont(
CalChart::Font{ 16, CalChart::Font::Family::Roman, CalChart::Font::Style::Normal, CalChart::Font::Weight::Bold },
GenerateLargePrintElements(landscape, page, sheet.GetPrintNumber())));
GenerateLargePrintElements(landscape, pageSize, sheet.GetPrintNumber())));

CalChart::append(drawCmds,
CalChart::Draw::withFont(
CalChart::Font{ 8 },
GeneratePrintElements(
landscape,
page)));
pageSize)));
wxCalChart::Draw::DrawCommandList(dc, drawCmds);
// now draw the continuity into its own box. It uses Stack layout so needs to have a constrained area.
wxCalChart::Draw::DrawCommandList(dc,
wxCalChart::Draw::DrawSurface{
{ 0, 0 },
wxSize(page.x - 20, page.y * (1 - kContinuityStart[landscape])) },
std::vector{ printDrawCommands } + CalChart::Coord(10, page.y * kContinuityStart[landscape]));
}

void DrawForPrintingField(
wxDC& dc,
wxSize pageSize,
CalChart::Configuration const& config,
CalChart::ShowMode const& mode,
std::vector<std::string> const& labels,
CalChart::Sheet const& sheet,
int ref,
bool landscape)
{
auto [scale_x, fieldDrawCommand] = GeneratePrintField(config, mode, labels, sheet, ref, landscape);
// set up everything to be restored after we print
SaveAndRestore::DeviceOrigin orig_dev(dc);
SaveAndRestore::UserScale orig_scale(dc);
SaveAndRestore::Font orig_font(dc);

// create a field for drawing:
auto scale = tDIP(pageSize.x - 2 * kFieldBorderOffset * pageSize.x) / scale_x;
// Because we are drawing to a bitmap, DIP isn't happening. So we compensate by changing the scaling.
dc.SetUserScale(scale, scale);
// and because we've scaled, the offset needs to be scaled.
auto offset = CalChart::Coord(kFieldBorderOffset * pageSize.x, kFieldTop * pageSize.y) / scale;

// draw the field.
wxCalChart::Draw::DrawCommandList(dc, fieldDrawCommand + offset);
}

auto GenerateDrawCommands(wxDC& dc,
Expand Down Expand Up @@ -614,8 +637,13 @@ void DrawForPrinting(wxDC* printerdc, CalChart::Configuration const& config, Cal
wxBitmap membm(bitmapWidth, bitmapHeight);
// first convert to image
wxMemoryDC memdc(membm);
auto [scale_x, drawCmds1] = GeneratePrintField(config, show, sheet, ref, should_landscape);
DrawForPrintingHelper(memdc, config, sheet, should_landscape, scale_x, drawCmds1);
memdc.Clear();
memdc.SetLogicalFunction(wxCOPY);
memdc.SetBrush(*wxTRANSPARENT_BRUSH);

DrawForPrintingElements(memdc, memdc.GetSize(), sheet, should_landscape);
DrawForPrintingContinuity(memdc, memdc.GetSize(), config, sheet, should_landscape);
DrawForPrintingField(memdc, memdc.GetSize(), config, show.GetShowMode(), show.GetPointsLabel(), sheet, ref, should_landscape);

auto image = membm.ConvertToImage();
if (forced_landscape) {
Expand Down
24 changes: 24 additions & 0 deletions src/CalChartDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Textline;
using Textline_list = std::vector<Textline>;
class Point;
class Configuration;
class ShowMode;
}
class CalChartDoc;

Expand All @@ -62,6 +63,29 @@ auto GenerateDrawCommands(wxDC& dc,

void DrawForPrinting(wxDC* dc, CalChart::Configuration const& config, CalChartDoc const& show, CalChart::Sheet const& sheet, int ref, bool landscape);

void DrawForPrintingContinuity(
wxDC& dc,
wxSize pageSize,
CalChart::Configuration const& config,
CalChart::Sheet const& sheet,
bool landscape);

void DrawForPrintingElements(
wxDC& dc,
wxSize pageSize,
CalChart::Sheet const& sheet,
bool landscape);

void DrawForPrintingField(
wxDC& dc,
wxSize pageSize,
CalChart::Configuration const& config,
CalChart::ShowMode const& mode,
std::vector<std::string> const& labels,
CalChart::Sheet const& sheet,
int ref,
bool landscape);

}

namespace wxCalChart::Draw {
Expand Down
2 changes: 2 additions & 0 deletions src/CalChartPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "PreferencesGeneralSetup.h"
#include "PreferencesPSPrintingSetup.h"
#include "PreferencesPrintContinuitySetup.h"
#include "PreferencesPrintingSetup.hpp"
#include "PreferencesShowModeSetup.h"
#include "PreferencesUtils.h"
#include <wxUI/wxUI.hpp>
Expand Down Expand Up @@ -69,6 +70,7 @@ CalChartPreferences::CalChartPreferences(wxWindow* parent, CalChart::Configurati
mNotebook->AddPage(ContCellSetup::CreatePreference(mConfig, mNotebook), wxT("Continuity"));
mNotebook->AddPage(DrawingSetup::CreatePreference(mConfig, mNotebook), wxT("Drawing"));
mNotebook->AddPage(ShowModeSetup::CreatePreference(mConfig, mNotebook), wxT("Show Mode Setup"));
mNotebook->AddPage(PrintingSetup::CreatePreference(mConfig, mNotebook), wxT("Printing"));
mNotebook->AddPage(PrintContinuitySetup::CreatePreference(mConfig, mNotebook), wxT("Print Continuity Setup"));
mNotebook->AddPage(PSPrintingSetUp::CreatePreference(mConfig, mNotebook), wxT("PS Printing"));
return mNotebook;
Expand Down
Loading