📄 apfaxcnv.dpr
字号:
WaitForSingleObject(Semaphore,GetTimeout);
LogEvent('Client signaled');
end;
end
else
begin
LogEvent('!!! Client app. didn''t start');
end;
finally
CloseHandle(Semaphore);
end
else
LogEvent('Unable to create semaphore');
end;
end;
end;
New(FaxConvData);
if DumpLogging then begin {!!.06}
FaxConvData^.FileHandle := CreateFile(DumpLog {'C:\FAXCONV.DMP'}, {!!.06}
GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN,
0 );
if FaxConvData^.FileHandle <> INVALID_HANDLE_VALUE then
SetEndOfFile(FaxConvData^.FileHandle);
end; {!!.06}
with FaxConvData^ do begin
BytesInBuffer := 0;
ReadPtr := 0;
acInitFaxConverter(apfConverter, nil, nil, nil, nil, '');
acSetResolutionMode(apfConverter, True); // High
if ShellHandle <> INVALID_HANDLE_VALUE then begin
ClientAppName := GetShellName; //re-using ClientAppName
StrPCopy(apfConverter^.OutFileName, ClientAppName);
end else begin
StrPCopy(apfConverter^.OutFileName, GetDefaultFileName); {!!.06}
PipeWriteBuffer.Event := eStartDoc;
PipeWriteBuffer.Data := WideCharToString(DocName);
Res := CallNamedPipe(ApdPipeName,
@PipeWriteBuffer, sizeof(PipeWriteBuffer),
@PipeReadBuffer, sizeof(PipeReadBuffer),
BytesReadFromPipe, NMPWAIT_USE_DEFAULT_WAIT);
if Res then
begin
LogEvent(format('Wrote %d bytes to pipe.',[sizeof(PipeWriteBuffer)]));
LogEvent(format('Read %d bytes from pipe.',[BytesReadFromPipe]));
if BytesReadFromPipe > 0 then begin
LogEvent(format('Read code %d from pipe.',[PipeReadBuffer.Event]));
StrPCopy(apfConverter^.OutFilename,PipeReadBuffer.Data);
LogEvent('File name supplied:'+apfConverter^.OutFilename);
end;
end
else
begin
LogEvent('CallNamedPipe failed. Reason:'+IntToStr(GetLastError));
end;
end;
LogEvent('Output file: ' + apfConverter^.OutFilename);
cvtLastError := acCreateOutputFile(apfConverter);
if cvtLastError <> ecOk then begin
LogEvent('acCreateOutputFile failure'+IntToStr(cvtLastError));
exit;
end;
end;
FaxConvData.apfConverter.StatusWnd := ShellHandle; {!!.01}
except
ShowException(ExceptObject,ExceptAddr);
end;
end;
{Codes defined by the printer mini-driver}
const
BEGINDOC = $41;
BEGINPAGE = $42;
ENDDOC = $43;
ENDPAGE = $44;
ABORT = $45;
PORTRAIT = $46;
LANDSCAPE = $47;
MULTCOP = $48;
XM_ABS = $58;
YM_ABS = $59;
SENDBLOCK = $4D;
ENDBLOCK = $4E;
HIRES = $52;
LORES = $53;
procedure Advance(Handle : THandle);
{- Move buffer read pointer one byte forward}
var
FaxConvData : PFaxConvData absolute Handle;
begin
with FaxConvData^ do begin
inc(ReadPtr);
dec(BytesInBuffer);
end;
end;
procedure AdvanceN(Handle : THandle;N : DWord);
{- Move buffer read pointer N bytes forward}
var
FaxConvData : PFaxConvData absolute Handle;
begin
with FaxConvData^ do begin
inc(ReadPtr,N);
dec(BytesInBuffer,N);
end;
end;
procedure ProcessBuffer(Handle : THandle);
{- Process next escape sequence in buffer, then advance the pointer.}
var
FaxConvData : PFaxConvData absolute Handle;
S : string;
N,i : integer;
BytesWritten : DWord;
begin
with FaxConvData^ do
case Buffer[ReadPtr] of
$1B :
begin
Advance(Handle);
case Buffer[ReadPtr] of
BEGINDOC :
begin
LogEvent('BEGINDOC');
LogEvent('Driver Version: ' + Version);
LogEvent('APRO Version: ' + ApVersionStr);
Advance(Handle);
HaveData := False;
end;
BEGINPAGE :
begin
LogEvent('BEGINPAGE');
Advance(Handle);
inc(apfConverter^.CurrPage);
end;
ENDDOC :
begin
LogEvent('ENDDOC');
Advance(Handle);
end;
ENDPAGE :
begin
if apfConverter.StatusWnd <> INVALID_HANDLE_VALUE then {!!.01}
PostMessage(apfConverter.StatusWnd, apw_EndPage, 0, 0); {!!.01}
LogEvent('ENDPAGE');
with apfConverter^ do begin
FillChar(TmpBuffer^, MaxData, 0);
if HaveData then
begin
N := ByteOfs;
HaveData := False;
end
else
N := 0;
cvtLastError := acOutToFileCallBack(apfConverter, DataLine^, N, True, True);
end;
Advance(Handle);
end;
ABORT :
begin
LogEvent('ABORT');
Advance(Handle);
end;
PORTRAIT :
begin
LogEvent('PORTRAIT');
IsLandscape := False;
Advance(Handle);
end;
LANDSCAPE :
begin
LogEvent('LANDSCAPE');
IsLandscape := True;
Advance(Handle);
end;
MULTCOP :
begin
LogEvent('MULTCOP');
Advance(Handle);
end;
XM_ABS :
begin
LogEvent('XM_ABS');
Advance(Handle);
S := '';
while char(Buffer[ReadPtr]) <> 'X' do begin
S := S + char(Buffer[ReadPtr]);
Advance(Handle);
end;
Advance(Handle);
LogEvent(S);
end;
YM_ABS :
begin
LogEvent('YM_ABS');
Advance(Handle);
S := '';
while char(Buffer[ReadPtr]) <> 'Y' do begin
S := S + char(Buffer[ReadPtr]);
Advance(Handle);
end;
Advance(Handle);
LogEvent(S);
N := StrToInt(S);
{ in Standard Res, RASDD is giving us YMove twice as big as they }
{ should be, we're dividing the increment in half here }
if not apfConverter^.UseHighRes then
N := N div 2;
if HaveData then begin
with ApfConverter^ do
cvtLastError := acOutToFileCallBack(apfConverter, DataLine^, ByteOfs, False, True);
HaveData := False;
end;
with ApfConverter^ do begin
FillChar(TmpBuffer^, MaxData, 0);
acCompressRasterLine(apfConverter, TmpBuffer^);
end;
for i := 1 to pred(N) do
with ApfConverter^ do
cvtLastError := acOutToFileCallBack(apfConverter, DataLine^, ByteOfs, False, True);
end;
SENDBLOCK :
begin
if HaveData then begin
with ApfConverter^ do
cvtLastError := acOutToFileCallBack(apfConverter, DataLine^, ByteOfs, False, True);
HaveData := False;
end;
LogEvent('SENDBLOCK');
Advance(Handle);
S := '';
while char(Buffer[ReadPtr]) <> 'M' do begin
S := S + char(Buffer[ReadPtr]);
Advance(Handle);
end;
Advance(Handle);
LogEvent(S);
N := StrToInt(S);
if DumpLogging then {!!.06}
WriteFile(FileHandle,Buffer[ReadPtr],N,BytesWritten,nil);
with ApfConverter^ do begin
FillChar(TmpBuffer^, MaxData, 0);
Move(Buffer[ReadPtr], TmpBuffer^, N);
acCompressRasterLine(apfConverter, TmpBuffer^);
FillChar(TmpBuffer^, MaxData, 0);
HaveData := True;
end;
AdvanceN(Handle,N);
end;
ENDBLOCK :
begin
LogEvent('ENDBLOCK');
Advance(Handle);
end;
HIRES :
begin
LogEvent('HIRES');
Advance(Handle);
acSetResolutionMode(apfConverter, True);
end;
LORES :
begin
LogEvent('LORES');
Advance(Handle);
acSetResolutionMode(apfConverter, False);
end;
else begin {!!.06}
HandleError(format('Unexpected subcode in stream:%x', {!!.06}
[Buffer[ReadPtr]])); {!!.06}
Advance(Handle); {!!.06}
end; {!!.06}
end
end
else begin {!!.06}
HandleError(format('Unexpected code in stream:%x', {!!.06}
[Buffer[ReadPtr]])); {!!.06}
Advance(Handle); {!!.06}
end; {!!.06}
end;
end;
procedure TrimBuffer(Handle : THandle);
{- Remove data already processed from the buffer.}
var
FaxConvData : PFaxConvData absolute Handle;
begin
with FaxConvData^ do begin
move(Buffer[ReadPtr],Buffer,BytesInBuffer);
ReadPtr := 0;
end;
end;
procedure AddToBuffer(Handle : THandle;var InBuffer;InBufSize : DWord);
{- Append data to buffer - process and trim as necessary to make it fit.}
var
FaxConvData : PFaxConvData absolute Handle;
begin
with FaxConvData^ do begin
while BytesInBuffer + InBufSize > BufferSize do
ProcessBuffer(Handle);
TrimBuffer(Handle);
move(InBuffer,Buffer[BytesInBuffer],InBufSize);
inc(BytesInBuffer,InBufSize);
end;
end;
procedure FaxConvEndDoc(Handle : THandle); cdecl;
{- Called by driver when no more data is pending.}
{- Process any remaining data in buffer and close output file(s).}
var
FaxConvData : PFaxConvData absolute Handle;
PipeWriteBuffer : TPipeEvent;
BytesReadFromPipe : DWord;
ShellHandle : THandle;
begin
try
LogEvent('FaxConvEndDoc');
with FaxConvData^ do begin
while BytesInBuffer > 0 do
ProcessBuffer(Handle);
if DumpLogging then {!!.06}
CloseHandle(FaxConvData.FileHandle);
{ insert HeadFiller and HeadPadding from registry }
GetHeaderMods(apfConverter.MainHeader); {!!.06}
if apfConverter <> nil then begin
with apfConverter^ do
cvtLastError := acCloseOutputFile(apfConverter);
LogEvent('Closing output file: ' + apfConverter^.OutFilename);
if cvtLastError <> ecOk then
LogEvent('acCloseOutputFile failure'+IntToStr(cvtLastError));
acDoneFaxConverter(apfConverter);
ShellHandle := GetShellHandle;
if ShellHandle <> INVALID_HANDLE_VALUE then begin
LogEvent('Posting message to fax converter (' + IntToStr(ShellHandle) + ')');
PostMessage(ShellHandle, apw_EndDoc, 0, 0);
RemoveShellRegKeys;
end else begin
PipeWriteBuffer.Event := eEndDoc;
CallNamedPipe(ApdPipeName,
@PipeWriteBuffer, sizeof(PipeWriteBuffer),
nil,0,
BytesReadFromPipe, NMPWAIT_NOWAIT);
end;
end;
end;
Dispose(FaxConvData);
except
ShowException(ExceptObject,ExceptAddr);
end;
end;
procedure FaxConvConvert(Handle : THandle;var InBuffer; InBufSize : DWord); cdecl;
{- Called by driver for each block of data sent by Windows.}
{- Put data block in buffer.}
var
FaxConvData : PFaxConvData absolute Handle;
begin
try
LogEvent('FaxConvConvert');
AddToBuffer(Handle,InBuffer,InBufSize);
except
ShowException(ExceptObject,ExceptAddr);
end;
end;
exports
FaxConvInit,
FaxConvStartDoc,
FaxConvEndDoc,
FaxConvConvert;
begin
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -