mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:19:22 +02:00
printe4lazarus: raise exception, if tmp file cannot be created
git-svn-id: trunk@50173 -
This commit is contained in:
parent
7cdf5a2bb6
commit
a46caecea3
@ -1509,6 +1509,13 @@ begin
|
|||||||
cairo_ps_surface_dsc_begin_setup(sf);
|
cairo_ps_surface_dsc_begin_setup(sf);
|
||||||
cairo_ps_surface_dsc_comment(sf, PChar(s));
|
cairo_ps_surface_dsc_comment(sf, PChar(s));
|
||||||
|
|
||||||
|
if (fStream=nil) and not FileExists(FOutputFileName) then
|
||||||
|
begin
|
||||||
|
DebugLn('Error: unable to write cairo ps to "'+FOutputFileName+'"');
|
||||||
|
DestroyCairoHandle;
|
||||||
|
exit(0);
|
||||||
|
end;
|
||||||
|
|
||||||
//rotate and move
|
//rotate and move
|
||||||
case Orientation of
|
case Orientation of
|
||||||
poLandscape: begin
|
poLandscape: begin
|
||||||
|
@ -473,18 +473,20 @@ var
|
|||||||
aPrinterName : string;
|
aPrinterName : string;
|
||||||
begin
|
begin
|
||||||
Result:=-1;
|
Result:=-1;
|
||||||
|
if aFileName='' then
|
||||||
|
raise Exception.Create('TCUPSPrinter.PrintFile missing Filename');
|
||||||
if not CUPSLibInstalled then Exit;
|
if not CUPSLibInstalled then Exit;
|
||||||
aFileName:=ExpandFileNameUTF8(aFileName);
|
aFileName:=ExpandFileNameUTF8(aFileName);
|
||||||
|
|
||||||
if (Printers.Count>0) then
|
if (Printers.Count>0) then
|
||||||
begin
|
begin
|
||||||
if not Assigned(fcupsOptions) then
|
if not Assigned(fcupsOptions) then
|
||||||
SetOptionsOfPrinter;
|
SetOptionsOfPrinter;
|
||||||
|
|
||||||
if Assigned(fcupsPrinter) then
|
if Assigned(fcupsPrinter) then
|
||||||
aPrinterName:=fcupsPrinter^.Name
|
aPrinterName:=fcupsPrinter^.Name
|
||||||
else
|
else
|
||||||
aPrinterName:='';
|
aPrinterName:='';
|
||||||
|
|
||||||
{$IFDEF DebugCUPS}
|
{$IFDEF DebugCUPS}
|
||||||
DebugOptions;
|
DebugOptions;
|
||||||
@ -846,6 +848,7 @@ end;
|
|||||||
procedure TCUPSPrinter.DoBeginDoc;
|
procedure TCUPSPrinter.DoBeginDoc;
|
||||||
var
|
var
|
||||||
NewPath: String;
|
NewPath: String;
|
||||||
|
fs: TFileStream;
|
||||||
|
|
||||||
function TryTemporaryPath(const Path: string): Boolean;
|
function TryTemporaryPath(const Path: string): Boolean;
|
||||||
var
|
var
|
||||||
@ -872,13 +875,22 @@ begin
|
|||||||
|
|
||||||
FOutputFileName := AppendPathDelim(NewPath)+
|
FOutputFileName := AppendPathDelim(NewPath)+
|
||||||
'OutPrinter_'+FormatDateTime('yyyymmmddd-hhnnss',Now);
|
'OutPrinter_'+FormatDateTime('yyyymmmddd-hhnnss',Now);
|
||||||
|
|
||||||
if RawMode then
|
if RawMode then
|
||||||
FOutputFileName := FOutputFileName + '.raw'
|
FOutputFileName := FOutputFileName + '.raw'
|
||||||
else begin
|
else begin
|
||||||
FOutputFileName := FOutputFileName + '.ps';
|
FOutputFileName := FOutputFileName + '.ps';
|
||||||
TFilePrinterCanvas(Canvas).OutputFileName := FOutputFileName;
|
TFilePrinterCanvas(Canvas).OutputFileName := FOutputFileName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// test writing, on error this raises exception showing the user the filename
|
||||||
|
fs:=TFileStream.Create(FOutputFilename,fmCreate);
|
||||||
|
try
|
||||||
|
fs.Write(FOutputFilename[1],1);
|
||||||
|
finally
|
||||||
|
fs.free;
|
||||||
|
end;
|
||||||
|
DeleteFileUTF8(FOutputFilename);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//If not aborted, send PostScript file to printer.
|
//If not aborted, send PostScript file to printer.
|
||||||
@ -902,9 +914,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
end else
|
end else
|
||||||
TFilePrinterCanvas(Canvas).OutPutFileName:='';
|
TFilePrinterCanvas(Canvas).OutputFileName:='';
|
||||||
|
|
||||||
if not aAborted and FileExistsUTF8(FOutputFileName) then begin
|
if not aAborted then begin
|
||||||
|
if not FileExistsUTF8(FOutputFileName) then
|
||||||
|
raise Exception.Create('Unable to write to "'+FOutputFileName+'"');
|
||||||
{$IFDEF LogPrintoutFile}
|
{$IFDEF LogPrintoutFile}
|
||||||
CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
|
CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -916,7 +930,6 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
DeleteFileUTF8(FOutputFilename);
|
DeleteFileUTF8(FOutputFilename);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCUPSPrinter.DoResetPrintersList;
|
procedure TCUPSPrinter.DoResetPrintersList;
|
||||||
|
Loading…
Reference in New Issue
Block a user