Skip to content

Commit f3f6e3a

Browse files
Merge pull request livecode#6335 from livecodeali/bugfix-20814
[[ Bug 20814 ]] Fix print to pdf
2 parents 19e90fb + 55f65ff commit f3f6e3a

8 files changed

Lines changed: 70 additions & 12 deletions

File tree

docs/notes/bugfix-20814.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix printing to pdf

engine/src/customprinter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ class MCDebugPrintingDevice: public MCCustomPrintingDevice
20962096

20972097
typedef MCCustomPrintingDevice *(*MCCustomPrinterCreateProc)(void);
20982098

2099-
Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer)
2099+
bool MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer)
21002100
{
21012101
MCCustomPrintingDevice *t_device;
21022102
t_device = nil;
@@ -2134,10 +2134,9 @@ Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filenam
21342134
#endif
21352135

21362136
if (t_device == nil)
2137-
{
2138-
MCeerror -> add(EE_PRINT_UNKNOWNDST, 0, 0);
2139-
return ES_ERROR;
2140-
}
2137+
{
2138+
return false;
2139+
}
21412140

21422141
MCAutoStringRef t_native_path;
21432142
if (p_filename != nil)
@@ -2163,5 +2162,5 @@ Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filenam
21632162

21642163
r_printer = t_printer;
21652164

2166-
return ES_NORMAL;
2165+
return true;
21672166
}

engine/src/exec-printing.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,13 @@ void MCPrintingExecPrintCardIntoRect(MCExecContext& ctxt, MCCard *p_card, MCRect
633633

634634
void MCPrintingExecOpenPrintingToDestination(MCExecContext& ctxt, MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options)
635635
{
636-
if (MCCustomPrinterCreate(p_destination, p_filename, p_options, (MCCustomPrinter*&)MCprinter) == ES_NORMAL)
636+
if (MCCustomPrinterCreate(p_destination, p_filename, p_options, (MCCustomPrinter*&)MCprinter))
637+
{
637638
MCPrintingExecOpenPrinting(ctxt);
639+
return;
640+
}
641+
642+
ctxt . LegacyThrow(EE_PRINT_UNKNOWNDST);
638643
}
639644

640645
void MCPrintingExecOpenPrinting(MCExecContext& ctxt)

engine/src/lnxpsprinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ MCPrinterResult MCPSPrinter::DoBeginPrint(MCStringRef p_document, MCPrinterDevic
254254
// Now attempt to create a PDF printer - creation of the custom printer
255255
// copies all the existing printer state into itself, so we basically get
256256
// a custom printer configured just like we are.
257-
if (MCCustomPrinterCreate(MCSTR("pdf"), *t_path, kMCEmptyArray, m_pdf_printer) != ES_NORMAL)
257+
if (!MCCustomPrinterCreate(MCSTR("pdf"), *t_path, kMCEmptyArray, m_pdf_printer))
258258
return PRINTER_RESULT_ERROR;
259259

260260
// Now all we need to do is get the PDF printer to begin!

engine/src/printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ class MCCustomPrinter: public MCPrinter
613613
MCArrayRef m_device_options;
614614
};
615615

616-
Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer);
616+
bool MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer);
617617

618618
////////////////////////////////////////////////////////////////////////////////
619619

engine/src/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3193,7 +3193,9 @@ __MCU_library_map_path(MCStringRef p_path,
31933193
!MCdispatcher->fetchlibrarymapping(*t_base_path,
31943194
&t_mapped_path))
31953195
{
3196-
t_mapped_path = *t_base_path;
3196+
// If there is no mapping, restore the original path including ./
3197+
// if it was there.
3198+
t_mapped_path = p_path;
31973199
}
31983200

31993201
// If the mapped path does not begin with './', then we just resolve.

tests/_testlib.livecodescript

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ on TestLoadAuxiliaryExtension pName, pResourceFolder
487487
end if
488488
end TestLoadAuxiliaryExtension
489489

490-
constant kBytecodePathPrefix = "_tests/_build/"
490+
constant kTestsBuildPath = "_tests/_build/"
491491
function TestGetBuiltBytecodeFile pName
492492
local tBasePath, tExtraPath
493493
set the itemDelimiter to slash
@@ -501,11 +501,15 @@ function TestGetBuiltBytecodeFile pName
501501
put item 1 to tTestsOffset - 1 of tBasePath into tBasePath
502502

503503
local tModuleFile
504-
put tBasePath & "/" & kBytecodePathPrefix & tExtraPath & slash & \
504+
put tBasePath & "/" & kTestsBuildPath & tExtraPath & slash & \
505505
pName & ".lcm" into tModuleFile
506506
return tModuleFile
507507
end TestGetBuiltBytecodeFile
508508

509+
function TestGetTestBuildFolder
510+
return TestGetEngineRepositoryPath() & slash & kTestsBuildPath
511+
end TestGetTestBuildFolder
512+
509513
on TestLoadAllExtensions
510514
local tExtFolder
511515
put _TestGetBuiltExtensionsFolder() into tExtFolder
@@ -680,6 +684,11 @@ private function __MeetsRequirements pRequirement, pOptions
680684
if TestIsInStandalone() then
681685
return false
682686
end if
687+
688+
if "revpdfprinter" is among the items of pOptions \
689+
and the environment is "server" then
690+
return false
691+
end if
683692
return the platform is not "HTML5"
684693
case "database"
685694
if not __MeetsRequirements("external", "revdb") then
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
script "CorePrinting"
2+
/*
3+
Copyright (C) 2018 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on TestPDFPrinter
20+
TestSkipIfNot "external", "revpdfprinter"
21+
22+
local tFile, tStack
23+
put TestGetTestBuildFolder() & slash & "test.pdf" into tFile
24+
create stack
25+
put it into tStack
26+
open printing to pdf tFile
27+
print card 1 of tStack
28+
close printing
29+
TestAssert "print stack to pdf", there is a file tFile
30+
end TestPDFPrinter
31+
32+
command _TestOpenPrintingBadDest
33+
local tFile
34+
put TestGetTestBuildFolder() & slash & "test" into tFile
35+
open printing to baddest tFile
36+
end _TestOpenPrintingBadDest
37+
38+
on TestOpenPrintingBadDest
39+
TestAssertThrow "open printing to bad dest throws", \
40+
_TestOpenPrintingBadDest, the long id of me, \
41+
EE_PRINT_UNKNOWNDST
42+
end TestOpenPrintingBadDest

0 commit comments

Comments
 (0)