Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
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 docs/notes/bugfix-20814.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Fix printing to pdf
11 changes: 5 additions & 6 deletions engine/src/customprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ class MCDebugPrintingDevice: public MCCustomPrintingDevice

typedef MCCustomPrintingDevice *(*MCCustomPrinterCreateProc)(void);

Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer)
bool MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options, MCCustomPrinter*& r_printer)
{
MCCustomPrintingDevice *t_device;
t_device = nil;
Expand Down Expand Up @@ -2134,10 +2134,9 @@ Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filenam
#endif

if (t_device == nil)
{
MCeerror -> add(EE_PRINT_UNKNOWNDST, 0, 0);
return ES_ERROR;
}
{
return false;
}

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

r_printer = t_printer;

return ES_NORMAL;
return true;
}
7 changes: 6 additions & 1 deletion engine/src/exec-printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,13 @@ void MCPrintingExecPrintCardIntoRect(MCExecContext& ctxt, MCCard *p_card, MCRect

void MCPrintingExecOpenPrintingToDestination(MCExecContext& ctxt, MCStringRef p_destination, MCStringRef p_filename, MCArrayRef p_options)
{
if (MCCustomPrinterCreate(p_destination, p_filename, p_options, (MCCustomPrinter*&)MCprinter) == ES_NORMAL)
if (MCCustomPrinterCreate(p_destination, p_filename, p_options, (MCCustomPrinter*&)MCprinter))
{
MCPrintingExecOpenPrinting(ctxt);
return;
}

ctxt . LegacyThrow(EE_PRINT_UNKNOWNDST);
}

void MCPrintingExecOpenPrinting(MCExecContext& ctxt)
Expand Down
2 changes: 1 addition & 1 deletion engine/src/lnxpsprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ MCPrinterResult MCPSPrinter::DoBeginPrint(MCStringRef p_document, MCPrinterDevic
// Now attempt to create a PDF printer - creation of the custom printer
// copies all the existing printer state into itself, so we basically get
// a custom printer configured just like we are.
if (MCCustomPrinterCreate(MCSTR("pdf"), *t_path, kMCEmptyArray, m_pdf_printer) != ES_NORMAL)
if (!MCCustomPrinterCreate(MCSTR("pdf"), *t_path, kMCEmptyArray, m_pdf_printer))
return PRINTER_RESULT_ERROR;

// Now all we need to do is get the PDF printer to begin!
Expand Down
2 changes: 1 addition & 1 deletion engine/src/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class MCCustomPrinter: public MCPrinter
MCArrayRef m_device_options;
};

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

////////////////////////////////////////////////////////////////////////////////

Expand Down
4 changes: 3 additions & 1 deletion engine/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,9 @@ __MCU_library_map_path(MCStringRef p_path,
!MCdispatcher->fetchlibrarymapping(*t_base_path,
&t_mapped_path))
{
t_mapped_path = *t_base_path;
// If there is no mapping, restore the original path including ./
// if it was there.
t_mapped_path = p_path;
}

// If the mapped path does not begin with './', then we just resolve.
Expand Down
13 changes: 11 additions & 2 deletions tests/_testlib.livecodescript
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ on TestLoadAuxiliaryExtension pName, pResourceFolder
end if
end TestLoadAuxiliaryExtension

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

local tModuleFile
put tBasePath & "/" & kBytecodePathPrefix & tExtraPath & slash & \
put tBasePath & "/" & kTestsBuildPath & tExtraPath & slash & \
pName & ".lcm" into tModuleFile
return tModuleFile
end TestGetBuiltBytecodeFile

function TestGetTestBuildFolder
return TestGetEngineRepositoryPath() & slash & kTestsBuildPath
end TestGetTestBuildFolder

on TestLoadAllExtensions
local tExtFolder
put _TestGetBuiltExtensionsFolder() into tExtFolder
Expand Down Expand Up @@ -677,6 +681,11 @@ private function __MeetsRequirements pRequirement, pOptions
if TestIsInStandalone() then
return false
end if

if "revpdfprinter" is among the items of pOptions \
and the environment is "server" then
return false
end if
return the platform is not "HTML5"
case "database"
if not __MeetsRequirements("external", "revdb") then
Expand Down
42 changes: 42 additions & 0 deletions tests/lcs/core/printing/printing.livecodescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
script "CorePrinting"
/*
Copyright (C) 2018 LiveCode Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */

on TestPDFPrinter
TestSkipIfNot "external", "revpdfprinter"

local tFile, tStack
put TestGetTestBuildFolder() & slash & "test.pdf" into tFile
create stack
put it into tStack
open printing to pdf tFile
print card 1 of tStack
close printing
TestAssert "print stack to pdf", there is a file tFile
end TestPDFPrinter

command _TestOpenPrintingBadDest
local tFile
put TestGetTestBuildFolder() & slash & "test" into tFile
open printing to baddest tFile
end _TestOpenPrintingBadDest

on TestOpenPrintingBadDest
TestAssertThrow "open printing to bad dest throws", \
_TestOpenPrintingBadDest, the long id of me, \
EE_PRINT_UNKNOWNDST
end TestOpenPrintingBadDest