1312 lines
42 KiB
Plaintext
1312 lines
42 KiB
Plaintext
unit DPtrMonMain;
|
||
|
||
interface
|
||
|
||
uses
|
||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
||
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
|
||
Vcl.StdCtrls, Tocsg.Printer, ThdWatchPrintSpool, Vcl.ExtCtrls, VirtualTrees,
|
||
Vcl.Buttons, System.Generics.Collections, ThdExecuteEndNoti, DWaitProcPrt,
|
||
Tocsg.Trace, Vcl.Menus, Tocsg.Controls;
|
||
|
||
type
|
||
PPtrJobEnt = ^TPtrJobEnt;
|
||
|
||
TPtrJobEnt = record
|
||
sPName: string;
|
||
dt: TDateTime;
|
||
bBlock: Boolean;
|
||
Info: TPrtJobDevInfo;
|
||
end;
|
||
|
||
PPrtWaterEnt = ^TPrtWaterEnt;
|
||
|
||
TPrtWaterEnt = record
|
||
sPtrName, sImgPath,
|
||
sDocName, sPdfPath: string;
|
||
dwPageSizeT, dwTotalPage: DWORD;
|
||
|
||
DevMode: TDeviceMode;
|
||
end;
|
||
|
||
TDlgPtrMonMain = class(TForm)
|
||
pnTop: TPanel;
|
||
Label1: TLabel;
|
||
Label2: TLabel;
|
||
chPreventPtr: TCheckBox;
|
||
mmAllowPtr: TMemo;
|
||
mmAllowFile: TMemo;
|
||
pnClient: TPanel;
|
||
vtList: TVirtualStringTree;
|
||
chPrintCol: TCheckBox;
|
||
Label3: TLabel;
|
||
edColDir: TEdit;
|
||
btnSelColDir: TSpeedButton;
|
||
Label4: TLabel;
|
||
cbColFmt: TComboBox;
|
||
Label5: TLabel;
|
||
cbQuality: TComboBox;
|
||
Label6: TLabel;
|
||
FileOpenDialog: TFileOpenDialog;
|
||
CheckBox1: TCheckBox;
|
||
CheckBox2: TCheckBox;
|
||
Edit1: TEdit;
|
||
Edit2: TEdit;
|
||
CheckBox3: TCheckBox;
|
||
Edit3: TEdit;
|
||
CheckBox4: TCheckBox;
|
||
chWatermark: TCheckBox;
|
||
Label7: TLabel;
|
||
edWaterImg: TEdit;
|
||
btnSelImg: TSpeedButton;
|
||
Label8: TLabel;
|
||
edWaterImgAlpha: TEdit;
|
||
Label9: TLabel;
|
||
edTopText: TEdit;
|
||
Label10: TLabel;
|
||
Label11: TLabel;
|
||
edTopTextSize: TEdit;
|
||
cbTopTextPos: TComboBox;
|
||
Label12: TLabel;
|
||
edBottomText: TEdit;
|
||
Label13: TLabel;
|
||
edBottomTextSize: TEdit;
|
||
cbBottomTextPos: TComboBox;
|
||
tWater: TTimer;
|
||
MainMenu: TMainMenu;
|
||
miPrinterControl: TMenuItem;
|
||
miWatchOn: TMenuItem;
|
||
miWatchOff: TMenuItem;
|
||
N4: TMenuItem;
|
||
miExit: TMenuItem;
|
||
procedure btnSelColDirClick(Sender: TObject);
|
||
procedure vtListGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
|
||
procedure vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
||
procedure vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
||
procedure vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
||
procedure tWaterTimer(Sender: TObject);
|
||
procedure btnSelImgClick(Sender: TObject);
|
||
procedure miExitClick(Sender: TObject);
|
||
procedure miWatchOnClick(Sender: TObject);
|
||
procedure miPrinterControlClick(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
Trace_: TTgTrace;
|
||
MgCtrls_: TManagerInputControlsData;
|
||
ThdPrinter_: TTgPrtSpoolWatch;
|
||
AllowPtrList_, AllowFNameList_: TStringList;
|
||
qWaterEnts_: TQueue<PPrtWaterEnt>;
|
||
dlgProg_: TDlgWaitExtrProcPrt;
|
||
procedure OnPtrJobNotify(Sender: TThdPrtSpoolWatch; Job: TPrtJobInfo);
|
||
procedure OnWaterEntNotify(Sender: TObject; const Item: PPrtWaterEnt; Action: TCollectionNotification);
|
||
public
|
||
{ Public declarations }
|
||
constructor Create(aOwner: TComponent); override;
|
||
destructor Destroy; override;
|
||
|
||
procedure process_WM_NOTIEXECUTE_END(var msg: TMessage); message WM_NOTIEXECUTE_END;
|
||
procedure process_WM_SYSCOMMAND(var msg: TWMSyscommand); message WM_SYSCOMMAND;
|
||
end;
|
||
|
||
var
|
||
DlgPtrMonMain: TDlgPtrMonMain;
|
||
|
||
implementation
|
||
|
||
uses
|
||
superobject, GlobalDefine, DNotice, Winapi.WinSpool, Tocsg.Path, Tocsg.Strings,
|
||
Tocsg.Safe, Tocsg.Files, Tocsg.Process, Tocsg.VTUtil, Tocsg.Convert,
|
||
Vcl.Printers, Vcl.Imaging.pngimage, SynPdf, Tocsg.Exception, Tocsg.Network,
|
||
Tocsg.WinInfo, imageen, hyiedefs, hyieutils, PdfDoc, Tocsg.DateTime;
|
||
|
||
{$R *.dfm}
|
||
|
||
constructor TDlgPtrMonMain.Create(aOwner: TComponent);
|
||
begin
|
||
inherited Create(aOwner);
|
||
|
||
Trace_ := TTgTrace.Create(GetRunExePathDir, CutFileExt(ExtractFileName(GetRunExePath)) + '.log');
|
||
Trace_.Level := 99;
|
||
|
||
ThdPrinter_ := nil;
|
||
AllowPtrList_ := TStringList.Create;
|
||
AllowFNameList_ := TStringList.Create;
|
||
MgCtrls_ := TManagerInputControlsData.Create(CutFileExt(GetRunExePath) + '.ini');
|
||
MgCtrls_.RegInputCtrl(chPreventPtr);
|
||
MgCtrls_.RegInputCtrl(mmAllowPtr);
|
||
MgCtrls_.RegInputCtrl(mmAllowFile);
|
||
MgCtrls_.RegInputCtrl(chPrintCol);
|
||
MgCtrls_.RegInputCtrl(edColDir);
|
||
MgCtrls_.RegInputCtrl(cbColFmt);
|
||
MgCtrls_.RegInputCtrl(cbQuality);
|
||
MgCtrls_.RegInputCtrl(chWatermark);
|
||
MgCtrls_.RegInputCtrl(edWaterImg);
|
||
MgCtrls_.RegInputCtrl(edTopText);
|
||
MgCtrls_.RegInputCtrl(edTopTextSize);
|
||
MgCtrls_.RegInputCtrl(cbTopTextPos);
|
||
MgCtrls_.RegInputCtrl(edBottomText);
|
||
MgCtrls_.RegInputCtrl(edBottomTextSize);
|
||
MgCtrls_.RegInputCtrl(cbBottomTextPos);
|
||
MgCtrls_.Load;
|
||
|
||
dlgProg_ := nil;
|
||
qWaterEnts_ := TQueue<PPrtWaterEnt>.Create;
|
||
|
||
FileOpenDialog.DefaultFolder := GetDesktopDir;
|
||
end;
|
||
|
||
destructor TDlgPtrMonMain.Destroy;
|
||
begin
|
||
tWater.Enabled := false;
|
||
if dlgProg_ <> nil then
|
||
FreeAndNil(dlgProg_);
|
||
if ThdPrinter_ <> nil then
|
||
FreeAndNil(ThdPrinter_);
|
||
qWaterEnts_.OnNotify := OnWaterEntNotify;
|
||
FreeAndNil(qWaterEnts_);
|
||
FreeAndNil(AllowFNameList_);
|
||
FreeAndNil(AllowPtrList_);
|
||
FreeAndNil(MgCtrls_);
|
||
inherited;
|
||
FreeAndNil(Trace_);
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.miExitClick(Sender: TObject);
|
||
begin
|
||
if MessageBox(0, PChar('<27><><EFBFBD><EFBFBD><EFBFBD>Ͻðڽ<C3B0><DABD>ϱ<EFBFBD>?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then
|
||
exit;
|
||
|
||
Close;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.miPrinterControlClick(Sender: TObject);
|
||
begin
|
||
miWatchOn.Checked := ThdPrinter_ <> nil;
|
||
miWatchOn.Enabled := not miWatchOn.Checked;
|
||
miWatchOff.Enabled := not miWatchOn.Enabled;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.miWatchOnClick(Sender: TObject);
|
||
begin
|
||
if ThdPrinter_ = nil then
|
||
begin
|
||
mmAllowPtr.Text := Trim(mmAllowPtr.Text);
|
||
mmAllowFile.Text := Trim(mmAllowFile.Text);
|
||
SplitString(UpperCase(mmAllowPtr.Text), ';', AllowPtrList_);
|
||
SplitString(UpperCase(mmAllowFile.Text), ';', AllowFNameList_);
|
||
|
||
edColDir.Text := Trim(edColDir.Text);
|
||
if chPrintCol.Checked and (edColDir.Text = '') then
|
||
begin
|
||
MessageBox(Handle, PChar('<27><><EFBFBD>¹<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20>Է<EFBFBD><D4B7><EFBFBD> <20>ֽʽÿ<CABD>.'), PChar(Caption), MB_ICONWARNING or MB_OK);
|
||
edColDir.SetFocus;
|
||
exit;
|
||
end;
|
||
|
||
if chPrintCol.Checked and not DirectoryExists(edColDir.Text) then
|
||
begin
|
||
MessageBox(Handle, PChar('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.'), PChar(Caption), MB_ICONWARNING or MB_OK);
|
||
edColDir.SetFocus;
|
||
exit;
|
||
end;
|
||
|
||
ThdPrinter_ := TTgPrtSpoolWatch.Create(true, PRINTER_CHANGE_ADD_JOB);
|
||
ThdPrinter_.OnPrtNotificationEvent := OnPtrJobNotify;
|
||
ThdPrinter_.StartWatch;
|
||
|
||
if chWatermark.Checked then
|
||
tWater.Enabled := true;
|
||
|
||
MgCtrls_.Save;
|
||
end
|
||
else
|
||
begin
|
||
if MessageBox(Handle, PChar('<27><><EFBFBD><EFBFBD><EFBFBD>Ͻðڽ<C3B0><DABD>ϱ<EFBFBD>?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then
|
||
exit;
|
||
|
||
tWater.Enabled := false;
|
||
try
|
||
qWaterEnts_.OnNotify := OnWaterEntNotify;
|
||
qWaterEnts_.Clear;
|
||
finally
|
||
qWaterEnts_.OnNotify := nil;
|
||
end;
|
||
FreeAndNil(ThdPrinter_);
|
||
end;
|
||
|
||
SetChildControlEnable(pnTop, ThdPrinter_ = nil);
|
||
// chPreventPtr.Enabled := ThdPrinter_ = nil;
|
||
// Label1.Enabled := chPreventPtr.Enabled;
|
||
// mmAllowPtr.Enabled := chPreventPtr.Enabled;
|
||
// Label2.Enabled := chPreventPtr.Enabled;
|
||
// mmAllowFile.Enabled := chPreventPtr.Enabled;
|
||
//
|
||
// chPrintCol.Enabled := ThdPrinter_ = nil;
|
||
// Label3.Enabled := chPrintCol.Enabled;
|
||
// edColDir.Enabled := chPrintCol.Enabled;
|
||
// btnSelColDir.Enabled := chPrintCol.Enabled;
|
||
// Label4.Enabled := chPrintCol.Enabled;
|
||
// cbColFmt.Enabled := chPrintCol.Enabled;
|
||
// Label5.Enabled := chPrintCol.Enabled;
|
||
// cbQuality.Enabled := chPrintCol.Enabled;
|
||
// Label6.Enabled := chPrintCol.Enabled;
|
||
|
||
Application.ProcessMessages;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.OnWaterEntNotify(Sender: TObject; const Item: PPrtWaterEnt; Action: TCollectionNotification);
|
||
begin
|
||
if Action = cnRemoved then
|
||
begin
|
||
if FileExists(Item.sImgPath) then
|
||
DeleteDir(ExtractFilePath(Item.sImgPath));
|
||
Dispose(Item);
|
||
end;
|
||
end;
|
||
|
||
|
||
//procedure MergePNGLayer(Layer1, Layer2: TPNGObject; Const aLeft, aTop: Integer);
|
||
//var
|
||
// x, y: Integer;
|
||
// SL1, SL2, SLBlended: pRGBLine;
|
||
// aSL1, aSL2, aSLBlended: PByteArray;
|
||
// blendCoeff: single;
|
||
// blendedPNG, Lay2buff: TPNGObject;
|
||
//begin
|
||
// blendedPNG := TPNGObject.Create;
|
||
// blendedPNG.Assign(Layer1);
|
||
// Lay2buff:=TPNGObject.Create;
|
||
// Lay2buff.Assign(Layer2);
|
||
// Layer2.SetSize(Layer1.Width, Layer1.Height);
|
||
//// SetPNGCanvasSize(Layer2, Layer1.Width, Layer1.Height, aLeft, aTop);
|
||
// for y := 0 to Layer1.Height - 1 do
|
||
// begin
|
||
// SL1 := Layer1.Scanline[y];
|
||
// SL2 := Layer2.Scanline[y];
|
||
// aSL1 := Layer1.AlphaScanline[y];
|
||
// aSL2 := Layer2.AlphaScanline[y];
|
||
// SLBlended := blendedPNG.Scanline[y];
|
||
// aSLBlended := blendedPNG.AlphaScanline[y];
|
||
// for x := 0 to Layer1.Width - 1 do
|
||
// begin
|
||
// blendCoeff:=aSL1[x] * 100/255/100;
|
||
// aSLBlended[x] := round(aSL2[x] + (aSL1[x]-aSL2[x]) * blendCoeff);
|
||
// SLBlended[x].rgbtRed := round(SL2[x].rgbtRed + (SL1[x].rgbtRed-SL2[x].rgbtRed) * blendCoeff);
|
||
// SLBlended[x].rgbtGreen := round(SL2[x].rgbtGreen + (SL1[x].rgbtGreen-SL2[x].rgbtGreen) * blendCoeff);
|
||
// SLBlended[x].rgbtBlue := round(SL2[x].rgbtBlue + (SL1[x].rgbtBlue-SL2[x].rgbtBlue) * blendCoeff);
|
||
// end;
|
||
// end;
|
||
// Layer1.Assign(blendedPNG);
|
||
// Layer2.Assign(Lay2buff);
|
||
// blendedPNG.Free;
|
||
// Lay2buff.Free;
|
||
//end;
|
||
|
||
procedure TDlgPtrMonMain.tWaterTimer(Sender: TObject);
|
||
|
||
procedure ExtrPrintImgFiles(sImgPath: string; aList: TStrings);
|
||
var
|
||
sFName: string;
|
||
i: Integer;
|
||
begin
|
||
aList.Clear;
|
||
sFName := CutFileExt(sImgPath);
|
||
if not FileExists(sImgPath) and not FileExists(Format('%s_%.4d.png', [sFName, 1])) then
|
||
exit;
|
||
|
||
if FileExists(sImgPath) then
|
||
aList.Add(sImgPath);
|
||
|
||
i := 1;
|
||
while True do
|
||
begin
|
||
sImgPath := Format('%s_%.4d.png', [sFName, i]);
|
||
if FileExists(sImgPath) then
|
||
aList.Add(sImgPath)
|
||
else
|
||
exit;
|
||
Inc(i);
|
||
end;
|
||
|
||
// <20><><EFBFBD><EFBFBD> TIF<49><46><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
// DeleteFile(sImgPath);
|
||
//
|
||
// sFName := CutFileExt(sImgPath);
|
||
// i := 1;
|
||
// while True do
|
||
// begin
|
||
// sImgPath := Format('%s-%.3d.png', [sFName, i]);
|
||
// if FileExists(sImgPath) then
|
||
// aList.Add(sImgPath)
|
||
// else
|
||
// exit;
|
||
// Inc(i);
|
||
// end;
|
||
end;
|
||
|
||
{ Returns grayscale version of a color. }
|
||
function RgbToGray(C: TColor): TColor;
|
||
begin
|
||
C := Round(C and $FF * 0.3 + C and $00FF00 shr 8 * 0.59 + C shr 16 * 0.11);
|
||
Result := RGB(C, C, C);
|
||
end;
|
||
|
||
{ Converts whole PNG image to grayscale. }
|
||
procedure ToGrayscale(PNG: TPNGObject);
|
||
var
|
||
X, Y: Integer;
|
||
begin
|
||
for X := 0 to PNG.Width - 1 do
|
||
for Y := 0 to PNG.Height - 1 do
|
||
PNG.Pixels[X, Y] := RgbToGray(PNG.Pixels[X, Y]);
|
||
end;
|
||
|
||
var
|
||
pInfo: PPrtWaterEnt;
|
||
WInfo: TPrtWaterEnt;
|
||
pi, i, c, nLeft, nTop, nW, nH: Integer;
|
||
ImgList: TStringList;
|
||
bProcGrayW, bIsWatchPtr: Boolean;
|
||
png, pngW: TPngImage;
|
||
// bmp: TBitmap;
|
||
bf: BLENDFUNCTION;
|
||
pngRect: TRect;
|
||
sTopText, sBottomText: string;
|
||
arrDevice, arrDriver, arrPort: array[0..255] of Char;
|
||
hDev: THandle;
|
||
DevMode: PDeviceMode;
|
||
pdf: TPdfDocumentGDI;
|
||
pdfPage: TPdfPage;
|
||
begin
|
||
try
|
||
if FindWindow('TDlgWaitExtrProcPrt', nil) <> 0 then
|
||
exit;
|
||
|
||
if Printer.Printing then
|
||
exit;
|
||
|
||
if qWaterEnts_.Count = 0 then
|
||
exit;
|
||
|
||
pInfo := qWaterEnts_.Dequeue;
|
||
if pInfo = nil then
|
||
exit;
|
||
|
||
WInfo := pInfo^;
|
||
Dispose(pInfo);
|
||
|
||
// if dlgProg_ <> nil then
|
||
// FreeAndNil(dlgProg_);
|
||
|
||
dlgProg_ := TDlgWaitExtrProcPrt.Create(Self, WInfo.dwTotalPage);
|
||
dlgProg_.Show;
|
||
bIsWatchPtr := (ThdPrinter_ <> nil) and ThdPrinter_.IsWatch;
|
||
if bIsWatchPtr then
|
||
ThdPrinter_.StopWatch;
|
||
|
||
png := nil;
|
||
try
|
||
Guard(ImgList, TStringList.Create);
|
||
ExtrPrintImgFiles(WInfo.sImgPath, ImgList);
|
||
if ImgList.Count = 0 then
|
||
exit;
|
||
|
||
Guard(pngW, TPngImage.Create);
|
||
try
|
||
if FileExists(edWaterImg.Text) then
|
||
pngW.LoadFromFile(edWaterImg.Text);
|
||
except
|
||
// ..
|
||
end;
|
||
|
||
png := TPngImage.Create;
|
||
png.LoadFromFile(ImgList[0]);
|
||
|
||
sTopText := Trim(edTopText.Text);
|
||
sBottomText := Trim(edBottomText.Text);
|
||
|
||
ZeroMemory(@bf, SizeOf(bf));
|
||
bf.AlphaFormat := 0; // <20>Ϲ<EFBFBD> <20><>Ʈ<EFBFBD><C6AE> 0, 32<33><32>Ʈ <20><>Ʈ<EFBFBD><C6AE> AC_SRC_ALPHA
|
||
bf.BlendFlags := 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0
|
||
bf.BlendOp := AC_SRC_OVER; // AC_SRC_OVER
|
||
bf.SourceConstantAlpha := 125; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD> 0 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 255)
|
||
|
||
bProcGrayW := false;
|
||
|
||
// Guard(bmp, TBitmap.Create);
|
||
|
||
{$IF true}
|
||
if WInfo.sPdfPath <> '' then
|
||
begin
|
||
Guard(pdf, TPdfDocumentGDI.Create);
|
||
|
||
// pdf.UseUniscribe := true;
|
||
// pdf.StandardFontsReplace := true;
|
||
// pdf.UseFontFallBack := false;
|
||
// pdf.FontFallBackName := 'Tahoma';
|
||
pdf.ScreenLogPixels := 600;
|
||
|
||
case WInfo.dwPageSizeT of
|
||
DMPAPER_LETTERSMALL:
|
||
begin
|
||
pdf.DefaultPaperSize := psUserDefined;
|
||
pdf.DefaultPageWidth := 216 * 72;
|
||
pdf.DefaultPageHeight := 280 * 72;
|
||
end;
|
||
DMPAPER_LETTER:
|
||
pdf.DefaultPaperSize := psLetter;
|
||
DMPAPER_LEGAL:
|
||
pdf.DefaultPaperSize := psLegal;
|
||
DMPAPER_A3:
|
||
pdf.DefaultPaperSize := psA3;
|
||
DMPAPER_A4:
|
||
pdf.DefaultPaperSize := psA4;
|
||
DMPAPER_A4SMALL:
|
||
begin
|
||
pdf.DefaultPaperSize := psUserDefined;
|
||
pdf.DefaultPageWidth := 210 * 72;
|
||
pdf.DefaultPageHeight := 297 * 72;
|
||
end;
|
||
DMPAPER_A5:
|
||
pdf.DefaultPaperSize := psA5;
|
||
DMPAPER_B4:
|
||
begin
|
||
pdf.DefaultPaperSize := psUserDefined;
|
||
pdf.DefaultPageWidth := 250 * 72;
|
||
pdf.DefaultPageHeight := 354 * 72;
|
||
end;
|
||
DMPAPER_B5:
|
||
begin
|
||
pdf.DefaultPaperSize := psUserDefined;
|
||
pdf.DefaultPageWidth := 182 * 72;
|
||
pdf.DefaultPageHeight := 257 * 72;
|
||
end;
|
||
end;
|
||
|
||
if png.Width > png.Height then
|
||
begin
|
||
var nSizeTemp: Integer := pdf.DefaultPageHeight;
|
||
pdf.DefaultPageHeight := pdf.DefaultPageWidth;
|
||
pdf.DefaultPageWidth := nSizeTemp;
|
||
end;
|
||
|
||
pdfPage := pdf.AddPage;
|
||
pdf.VCLCanvas.Brush.Style := bsClear;
|
||
pdf.VCLCanvas.Font.Name := 'Tahoma';
|
||
|
||
var F: TFont;
|
||
Guard(F, TFont.Create);
|
||
F.Size := 400;
|
||
// F.Size := 150;
|
||
F.Orientation := 300;
|
||
F.Color := clSilver; // $F1F1F1; // clSilver; // clGray;
|
||
F.Style := png.Canvas.Font.Style + [fsBold];
|
||
var ImgEn: TImageEn;
|
||
Guard(ImgEn, TImageEn.Create(nil));
|
||
|
||
for i := 0 to ImgList.Count - 1 do
|
||
begin
|
||
try
|
||
if i <> 0 then
|
||
begin
|
||
try
|
||
if png <> nil then
|
||
FreeAndNil(png);
|
||
// i = 0<><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD> <20>ҷ<EFBFBD><D2B7><EFBFBD>
|
||
png := TPngImage.Create;
|
||
png.LoadFromFile(ImgList[i]);
|
||
except
|
||
break;
|
||
end;
|
||
pdfPage := pdf.AddPage;
|
||
end;
|
||
|
||
// bmp.Assign(png);
|
||
|
||
dlgProg_.SetPagePos(i + 1);
|
||
|
||
if pngW.Width > 0 then
|
||
begin
|
||
// if (png.Header.ColorType = COLOR_GRAYSCALE) then
|
||
// begin
|
||
// Guard(bmp, Vcl.Graphics.TBitmap.Create);
|
||
// bmp.Assign(png);
|
||
// bmp.PixelFormat := pf24bit;
|
||
// png.Assign(bmp);
|
||
|
||
// if not bProcGrayW then
|
||
// begin
|
||
// ToGrayscale(pngW);
|
||
// bProcGrayW := true;
|
||
// end;
|
||
// end;
|
||
|
||
pngRect.Right := pngW.Width * 3;
|
||
pngRect.Bottom := pngW.Height * 3;
|
||
pngRect.Left := (png.Width div 2) - (pngRect.Right div 2);
|
||
pngRect.Top := (png.Height div 2) - (pngRect.Bottom div 2);
|
||
|
||
Winapi.Windows.AlphaBlend(png.Canvas.Handle, pngRect.Left, pngRect.Top, pngRect.Right, pngRect.Bottom, pngW.Canvas.Handle, 0, 0, pngW.Width, pngW.Height, bf);
|
||
end;
|
||
|
||
if sTopText <> '' then
|
||
begin
|
||
png.Canvas.Font.Size := 10 * 7;
|
||
nLeft := 0;
|
||
nTop := 0;
|
||
if cbTopTextPos.ItemIndex <> 0 then
|
||
nLeft := png.Width - png.Canvas.TextWidth(sTopText);
|
||
|
||
png.Canvas.TextOut(nLeft, nTop, sTopText);
|
||
end;
|
||
|
||
if sBottomText <> '' then
|
||
begin
|
||
png.Canvas.Font.Size := 10 * 7;
|
||
nLeft := 0;
|
||
nTop := png.Height - png.Canvas.TextHeight(sBottomText);
|
||
if cbBottomTextPos.ItemIndex <> 0 then
|
||
nLeft := png.Width - png.Canvas.TextWidth(sBottomText);
|
||
|
||
png.Canvas.TextOut(nLeft, nTop, sBottomText);
|
||
end;
|
||
|
||
// var png2: TPngImage;
|
||
// Guard(png2, TPngImage.CreateBlank(png.Header.ColorType, png.Header.BitDepth, png.Width, png.Height));
|
||
//// Guard(png2, TPngImage.CreateBlank(COLOR_RGBALPHA, 16, png.Width, png.Height));
|
||
//
|
||
//// SetBkMode(png2.Canvas.Handle, TRANSPARENT);
|
||
//// png2.Canvas.FloodFill(0, 0, clWhite, fsBorder);
|
||
//// PatBlt(png2.Canvas.Handle, 0, 0, png2.Width, png2.Height, WHITENESS);
|
||
// png2.Canvas.Font.Size := 200;
|
||
// png2.Canvas.Font.Orientation := 300;
|
||
// png2.Canvas.Font.Color := clRed; // $F1F1F1; // clSilver; // clGray;
|
||
// png2.Canvas.Font.Style := png.Canvas.Font.Style + [fsBold];
|
||
//
|
||
// png2.Canvas.Brush.Style := bsClear;
|
||
// png2.Canvas.TextOut(0, png2.Height div 2, Format('%s %s', [GetHostIp, GetComName]));
|
||
// png2.SaveToFile('c:\png_test.png');
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD> <20>ÿ<EFBFBD><C3BF><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ũ <20>߰<EFBFBD> 23_0826 15:13:33 kku
|
||
// var F: TFont;
|
||
// Guard(F, TFont.Create);
|
||
// F.Size := 300;
|
||
// F.Orientation := 300;
|
||
// F.Color := clSilver; // $F1F1F1; // clSilver; // clGray;
|
||
// F.Style := png.Canvas.Font.Style + [fsBold];
|
||
// var ImgEn: TImageEn;
|
||
// Guard(ImgEn, TImageEn.Create(nil));
|
||
// png.SaveToStream(ms);
|
||
// ms.Position := 0;
|
||
ImgEn.IO.Bitmap.Assign(png);
|
||
{
|
||
var nLIdx := ImgEn.LayersAdd;
|
||
ImgEn.Proc.Fill(TColor2TRGB(clWhite));
|
||
ImgEn.Proc.SetTransparentColors(TColor2TRGB(clWhite), TColor2TRGB(clWhite), 0);
|
||
ImgEn.Proc.TextOut(0, png.Height - (png.Height div 3) - 200,
|
||
// ImgEn.Proc.TextOut(400, png.Height - (png.Height div 3) - 800,
|
||
Format('%s %s' + #13#10 + 'ToCSG - Fujifilm', [GetHostIp, GetComName]), F, 40);
|
||
// Format('%s/%s/' + 'ToCSG - <20>Ƹ<EFBFBD><C6B8><EFBFBD><EFBFBD>۽<EFBFBD><DBBD><EFBFBD>', [GetHostIp, GetComName]), F, 40);
|
||
// ImgEn.Proc.TextOut(500, png.Height - (png.Height div 3) - 700, Format('%s %s' + #13#10 + 'ToCSG - Fujifilm', [GetHostIp, GetComName]), F, 25);
|
||
// ImgEn.Proc.TextOut(500, png.Height - ((png.Height div 3) * 2) - 700, Format('%s %s' + #13#10 + 'ToCSG - Fujifilm', [GetHostIp, GetComName]), F, 25);
|
||
// ImgEn.Proc.TextOut(500, png.Height - 700, Format('%s %s' + #13#10 + 'ToCSG - Fujifilm', [GetHostIp, GetComName]), F, 25);
|
||
ImgEn.Layers[nLIdx].Transparency := 150;
|
||
ImgEn.LayersMerge(0, 1);
|
||
}
|
||
// ImgEn.Update;
|
||
// ms.Clear;
|
||
// ImgEn.IO.SaveToStreamPNG(ms);
|
||
// ms.Position := 0;
|
||
// png.LoadFromStream(ms);
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD> <20>ÿ<EFBFBD><C3BF><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ũ <20>߰<EFBFBD> - <20><>
|
||
|
||
ZeroMemory(@pngRect, SizeOf(pngRect));
|
||
pngRect.Right := png.Width;
|
||
pngRect.Bottom := png.Height;
|
||
pdf.VCLCanvas.StretchDraw(pngRect, ImgEn.IO.Bitmap); // png);
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. PrintPDF .. 1');
|
||
end;
|
||
end;
|
||
|
||
try
|
||
pdf.SaveToFile(WInfo.sPdfPath);
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. PrintPDF .. 2');
|
||
end;
|
||
end
|
||
else
|
||
{$IFEND}
|
||
begin
|
||
pi := -1;
|
||
for i := 0 to Printer.Printers.Count - 1 do
|
||
begin
|
||
if Printer.Printers[i] = WInfo.sPtrName then
|
||
pi := i;
|
||
end;
|
||
|
||
if pi = -1 then
|
||
begin
|
||
TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<><C3A3> <20><><EFBFBD><EFBFBD> .. Name=%s', [WInfo.sPtrName]);
|
||
exit;
|
||
end;
|
||
|
||
Printer.PrinterIndex := pi;
|
||
|
||
Printer.Title := 'BSOne* ' + WInfo.sDocName;
|
||
|
||
hDev := 0;
|
||
Printer.GetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
if hDev = 0 then
|
||
exit;
|
||
|
||
DevMode := GlobalLock(hDev);
|
||
try
|
||
DevMode.dmPaperSize := WInfo.dwPageSizeT;
|
||
// DevMode.dmColor := DMCOLOR_MONOCHROME;
|
||
DevMode^ := WInfo.DevMode;
|
||
Printer.SetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
finally
|
||
GlobalUnlock(hDev);
|
||
end;
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Printer.BeginDoc <20><><EFBFBD><EFBFBD> <20>ؾ<EFBFBD><D8BE>Ѵ<EFBFBD>..
|
||
// <20>Ϻ<EFBFBD> <20><><EFBFBD>α<CEB1><D7B7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 23_0623 08:45:27 kku
|
||
try
|
||
if png.Width > png.Height then
|
||
Printer.Orientation := poLandscape
|
||
else
|
||
Printer.Orientation := poPortrait;
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. Set Printer.Orientation');
|
||
end;
|
||
|
||
// Guard(bmpW, Vcl.Graphics.TBitmap.Create);
|
||
// if pngW.Width > 0 then
|
||
// begin
|
||
// bmpW.Assign(pngW);
|
||
//// bmpW.Transparent := true;
|
||
//// bmpW.TransparentMode := tmFixed;
|
||
//// bmpW.TransparentColor := clWhite;
|
||
// end;
|
||
|
||
nW := 0;
|
||
nH := 0;
|
||
|
||
Printer.BeginDoc;
|
||
try
|
||
for i := 0 to ImgList.Count - 1 do
|
||
begin
|
||
if not Printer.Printing or Printer.Aborted then
|
||
break;
|
||
|
||
if nW = 0 then
|
||
begin
|
||
nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES);
|
||
nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES);
|
||
end;
|
||
|
||
try
|
||
if i <> 0 then
|
||
begin
|
||
try
|
||
if png <> nil then
|
||
FreeAndNil(png);
|
||
// i = 0<><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD> <20>ҷ<EFBFBD><D2B7><EFBFBD>
|
||
png := TPngImage.Create;
|
||
png.LoadFromFile(ImgList[i]);
|
||
except
|
||
break;
|
||
end;
|
||
Printer.NewPage;
|
||
end;
|
||
|
||
dlgProg_.SetPagePos(i + 1);
|
||
|
||
// <20><>Ǯ<EFBFBD><C7AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> png<6E><67> <20>״<EFBFBD><D7B4><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̻<EFBFBD><CCBB>ϰ<EFBFBD> ó<><C3B3><EFBFBD>ȴ<EFBFBD>..
|
||
// <20><EFBFBD><D7B7><EFBFBD> <20>Ʒ<EFBFBD>ó<EFBFBD><C3B3> bmp<6D><70> <20>ѹ<EFBFBD> <20><>ȯ <20><> ó<><C3B3>
|
||
// bmp.Assign(png);
|
||
|
||
if pngW.Width > 0 then
|
||
begin
|
||
// if (png.Header.ColorType = COLOR_GRAYSCALE) then
|
||
// begin
|
||
// // <20><><EFBFBD><EFBFBD> <20><><EFBFBD>Ͻ<EFBFBD> <20><><EFBFBD>ձ<D5B1><E2BFA1> <20>Ʒ<EFBFBD>ó<EFBFBD><C3B3> ó<><C3B3><EFBFBD>ϸ<EFBFBD>
|
||
// // <20><><EFBFBD><EFBFBD> <20>κ<EFBFBD><CEBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD> <20><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD> <20><><EFBFBD>µȴ<C2B5>. (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>尡<EFBFBD><E5B0A1>)
|
||
// // <20><EFBFBD><D7B7><EFBFBD> <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD><CCB9><EFBFBD> <20><><EFBFBD><EFBFBD>ũ<EFBFBD><C5A9> <20><><EFBFBD>°ɷ<C2B0>... 23_0824 15:01:26 kku
|
||
// // todo : <20><><EFBFBD><EFBFBD> <20>ʿ<EFBFBD>
|
||
// Guard(bmp, Vcl.Graphics.TBitmap.Create);
|
||
// bmp.Assign(png);
|
||
// bmp.PixelFormat := pf24bit;
|
||
// png.Assign(bmp);
|
||
//
|
||
// if not bProcGrayW then
|
||
// begin
|
||
// ToGrayscale(pngW);
|
||
// bProcGrayW := true;
|
||
// end;
|
||
// end;
|
||
|
||
pngRect.Right := pngW.Width * 3;
|
||
pngRect.Bottom := pngW.Height * 3;
|
||
pngRect.Left := (png.Width div 2) - (pngRect.Right div 2);
|
||
pngRect.Top := (png.Height div 2) - (pngRect.Bottom div 2);
|
||
|
||
Winapi.Windows.AlphaBlend(png.Canvas.Handle, pngRect.Left, pngRect.Top, pngRect.Right, pngRect.Bottom, pngW.Canvas.Handle, 0, 0, pngW.Width, pngW.Height, bf);
|
||
end;
|
||
//
|
||
// if bmpW.Width > 0 then
|
||
// begin
|
||
// pngRect.Right := bmpW.Width * 3;
|
||
// pngRect.Bottom := bmpW.Height * 3;
|
||
// pngRect.Left := (bmp.Width div 2) - (pngRect.Right div 2);
|
||
// pngRect.Top := (bmp.Height div 2) - (pngRect.Bottom div 2);
|
||
//
|
||
// Winapi.Windows.AlphaBlend(bmp.Canvas.Handle, pngRect.Left,
|
||
// pngRect.Top, pngRect.Right, pngRect.Bottom,
|
||
// bmpW.Canvas.Handle, 0, 0, bmpW.Width, bmpW.Height, bf);
|
||
// end;
|
||
|
||
png.Canvas.Brush.Style := bsClear;
|
||
if sTopText <> '' then
|
||
begin
|
||
// bmp.Canvas.Font.Size := 10 * 7;
|
||
png.Canvas.Font.Size := 10 * 7;
|
||
nLeft := 0;
|
||
nTop := 0;
|
||
if cbTopTextPos.ItemIndex <> 0 then
|
||
nLeft := png.Width - png.Canvas.TextWidth(sTopText);
|
||
|
||
// bmp.Canvas.TextOut(nLeft, nTop, sTopText);
|
||
png.Canvas.TextOut(nLeft, nTop, sTopText);
|
||
end;
|
||
|
||
if sBottomText <> '' then
|
||
begin
|
||
png.Canvas.Font.Size := 10 * 7;
|
||
nLeft := 0;
|
||
nTop := png.Height - png.Canvas.TextHeight(sBottomText);
|
||
if cbBottomTextPos.ItemIndex <> 0 then
|
||
nLeft := png.Width - png.Canvas.TextWidth(sBottomText);
|
||
png.Canvas.TextOut(nLeft, nTop, sBottomText);
|
||
end;
|
||
|
||
// bmp.SaveToFile('C:\Users\kku\Desktop\<5C><> <20><><EFBFBD><EFBFBD>\test.bmp');
|
||
// png.SaveToFile('C:\Users\kku\Desktop\<5C><> <20><><EFBFBD><EFBFBD>\test.png');
|
||
// pngW.SaveToFile('C:\Users\kku\Desktop\<5C><> <20><><EFBFBD><EFBFBD>\test2.png');
|
||
|
||
// ZeroMemory(@pngRect, SizeOf(pngRect));
|
||
// pngRect.Right := png.Width; // nW;
|
||
// pngRect.Bottom := png.Height; // nH;
|
||
// Printer.Canvas.StretchDraw(pngRect, bmp);
|
||
|
||
// BitBlt(Printer.Canvas.Handle, 0, 0, nW, nH, png.Canvas.Handle, 0, 0, SRCCOPY);
|
||
|
||
StretchBlt(Printer.Canvas.Handle, 0, 0, nW, nH, png.Canvas.Handle, 0, 0, png.Width, png.Height, SRCCOPY);
|
||
|
||
// ZeroMemory(@pngRect, SizeOf(pngRect));
|
||
// pngRect.Right := png.Width;
|
||
// pngRect.Bottom := png.Height;
|
||
// Printer.Canvas.StretchDraw(pngRect, png);
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. DoPrint ..');
|
||
end;
|
||
end;
|
||
finally
|
||
if Printer.Printing then
|
||
Printer.EndDoc;
|
||
end;
|
||
end;
|
||
|
||
// SendEventLog(URI_USER_ACTION, LOGCODE_EVENT_PRINTER,
|
||
// Format('Ptrinter : %s, Document : %s', [WInfo.sPtrName, WInfo.sDocName]));
|
||
// PopupMessage(TYPE_MSG_EVENT_PRINTWATER, WInfo.sPtrName + '|' + WInfo.sDocName);
|
||
finally
|
||
if png <> nil then
|
||
FreeAndNil(png);
|
||
|
||
DeleteDir(ExtractFilePath(WInfo.sImgPath));
|
||
|
||
if dlgProg_ <> nil then
|
||
FreeAndNil(dlgProg_);
|
||
|
||
if bIsWatchPtr and (ThdPrinter_ <> nil) then
|
||
ThdPrinter_.StartWatch;
|
||
end;
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. ProcessPrintWaterEnt()');
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.btnSelColDirClick(Sender: TObject);
|
||
begin
|
||
FileOpenDialog.FileName := '';
|
||
FileOpenDialog.FileTypeIndex := 0;
|
||
FileOpenDialog.Options := FileOpenDialog.Options + [fdoPickFolders];
|
||
if FileOpenDialog.Execute then
|
||
edColDir.Text := FileOpenDialog.FileName;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.btnSelImgClick(Sender: TObject);
|
||
begin
|
||
FileOpenDialog.FileName := '';
|
||
FileOpenDialog.FileTypeIndex := 1;
|
||
FileOpenDialog.Options := FileOpenDialog.Options - [fdoPickFolders];
|
||
if FileOpenDialog.Execute then
|
||
edWaterImg.Text := FileOpenDialog.FileName;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.OnPtrJobNotify(Sender: TThdPrtSpoolWatch; Job: TPrtJobInfo);
|
||
var
|
||
sTaskDir: string;
|
||
|
||
function GetSpoolCopyPath: string;
|
||
var
|
||
sRecentSool, sSpoolWorkDir: string;
|
||
i: Integer;
|
||
begin
|
||
Result := '';
|
||
try
|
||
sSpoolWorkDir := sTaskDir + Format('%s-%s\', [FormatDateTime('hhnnss', Now), GetValidFileName(Job.PrinterName, '#')]);
|
||
DeleteDir(sSpoolWorkDir);
|
||
|
||
if ForceDirectories(sSpoolWorkDir) then
|
||
begin
|
||
TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> .. Spool <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. Printer=%s, Doc=%s', [Job.PrinterName, Job.Document], 2);
|
||
while Job.IsSpooling2 do
|
||
begin
|
||
if i = 1000 then // 100<30>ʰ<EFBFBD> <20><><EFBFBD>ٷ<EFBFBD><D9B7>ش<EFBFBD> 23_0525 08:03:11 kku
|
||
break;
|
||
|
||
Inc(i);
|
||
Sleep(100);
|
||
end;
|
||
|
||
sRecentSool := GetLastSpoolPath(GetSystemDir + 'spool\PRINTERS\');
|
||
if FileExists(sRecentSool) then
|
||
begin
|
||
Result := sSpoolWorkDir + ExtractFileName(sRecentSool);
|
||
CopyFile(PChar(sRecentSool), PChar(Result), false);
|
||
Sleep(500);
|
||
|
||
if not FileExists(Result) then
|
||
begin
|
||
Result := '';
|
||
TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> .. Spool <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. Printer=%s, Doc=%s', [Job.PrinterName, Job.Document], 2);
|
||
end else begin
|
||
TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> .. Spool <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. Printer=%s, Doc=%s, Size=%d', [Job.PrinterName, Job.Document, GetFileSize_path(Result)], 2);
|
||
end;
|
||
end
|
||
else
|
||
TTgTrace.T('Not found spool file..');
|
||
end;
|
||
except
|
||
on E: Exception do
|
||
ETgException.TraceException(Self, E, 'Fail .. GetSpoolCopyPath()');
|
||
end;
|
||
end;
|
||
|
||
label
|
||
LB_OpenSpool;
|
||
var
|
||
O: ISuperObject;
|
||
sData, sChk, sExt, sFName, sPName, sQuality, sSpoolPath, sExportPath: string;
|
||
i: Integer;
|
||
dt: TDateTime;
|
||
bBlock: Boolean;
|
||
PrtInfo: TPrtJobDevInfo;
|
||
arrDevice, arrDriver, arrPort: array[0..255] of Char;
|
||
DevMode: PDeviceMode;
|
||
begin
|
||
if Job.WorkEnd then
|
||
exit;
|
||
|
||
if not Job.IsCustomPause and Job.IsSpooling then
|
||
begin
|
||
if (Job.Document <> '') and Job.Document.StartsWith('BSOne*') then
|
||
begin
|
||
if FindWindow('TDlgWaitExtrProcPrt', nil) <> 0 then
|
||
begin
|
||
Job.SetPrtJob(JOB_CONTROL_CANCEL);
|
||
Job.SetPrtJob(JOB_CONTROL_DELETE);
|
||
Job.WorkEnd := true;
|
||
exit;
|
||
end;
|
||
|
||
Job.PausePrtJob;
|
||
end;
|
||
exit;
|
||
end;
|
||
|
||
if Job.IsCustomPause then
|
||
begin
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>õ<EFBFBD>... <20>ȵ<EFBFBD> 23_0720 08:14:41 kku
|
||
// begin
|
||
// var pi: Integer := -1;
|
||
// for i := 0 to Printer.Printers.Count - 1 do
|
||
// begin
|
||
// if Printer.Printers[i] = Job.PrinterName then
|
||
// pi := i;
|
||
// end;
|
||
//
|
||
// if pi = -1 then
|
||
// begin
|
||
// TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<><C3A3> <20><><EFBFBD><EFBFBD> .. Name=%s', [Job.PrinterName]);
|
||
// exit;
|
||
// end;
|
||
//
|
||
// Printer.PrinterIndex := pi;
|
||
//
|
||
// Printer.Title := '*BSOne*';
|
||
//
|
||
// var hDev: THandle := 0;
|
||
// Printer.GetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
// if hDev = 0 then
|
||
// exit;
|
||
//
|
||
// DevMode := GlobalLock(hDev);
|
||
// try
|
||
//// DevMode.dmPaperSize := WInfo.dwPageSizeT;
|
||
// // DevMode^ := WInfo.DevMode;
|
||
// DevMode.dmColor := DMCOLOR_MONOCHROME;
|
||
// Printer.SetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
// finally
|
||
// GlobalUnlock(hDev);
|
||
// end;
|
||
// end;
|
||
|
||
|
||
dt := Now;
|
||
sTaskDir := GetRunExePathDir + 'Task\';
|
||
ASSERT(ForceDirectories(sTaskDir));
|
||
sPName := GetProcessNameFromWndHandle(GetForegroundWindow);
|
||
|
||
if not Job.GetJobDevInfo(PrtInfo) then
|
||
begin
|
||
ZeroMemory(@PrtInfo, SizeOf(PrtInfo));
|
||
{$IFDEF DEBUG}
|
||
ASSERT(false);
|
||
{$ENDIF}
|
||
end;
|
||
|
||
if dlgProg_ <> nil then
|
||
FreeAndNil(dlgProg_);
|
||
|
||
sSpoolPath := '';
|
||
try
|
||
if chPrintCol.Checked and DirectoryExists(edColDir.Text) then
|
||
begin
|
||
sSpoolPath := GetSpoolCopyPath;
|
||
|
||
if FileExists(sSpoolPath) then
|
||
begin
|
||
if cbColFmt.ItemIndex = 0 then
|
||
sExt := '.pdf'
|
||
else
|
||
sExt := '.tif';
|
||
|
||
case cbQuality.ItemIndex of
|
||
0:
|
||
sQuality := '-imgbitcount 1 ';
|
||
1:
|
||
sQuality := '-imgbitcount 8 ';
|
||
else
|
||
sQuality := '';
|
||
end;
|
||
|
||
var sConv: string := GetRunExePathDir + 'Bs1psf.dat';
|
||
if FileExists(sConv) then
|
||
begin
|
||
sFName := GetValidFileName(ExtractFileName(Job.Document), '#');
|
||
sExportPath := IncludeTrailingBackslash(edColDir.Text) + sFName + sExt;
|
||
ExecuteAppWaitUntilTerminate(sConv, Format('-$ 65XSD4234455S4PLET58 -unicode %s"%s" "%s"', [sQuality, sSpoolPath, sExportPath]), SW_HIDE);
|
||
|
||
if not FileExists(sExportPath) then
|
||
begin
|
||
// Ư<><C6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EEB0A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> spl2pdf<64><66><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> 23_0525 15:52:14 kku
|
||
if sPName = '' then
|
||
sFName := FormatDateTime('yyyymmddhhnnkss', Now)
|
||
else
|
||
sFName := sPName + '_' + FormatDateTime('yyyymmddhhnnkss', Now);
|
||
|
||
sExportPath := IncludeTrailingBackslash(edColDir.Text) + sFName + sExt;
|
||
ExecuteAppWaitUntilTerminate(sConv, Format('-$ 65XSD4234455S4PLET58 -unicode %s"%s" "%s"', [sQuality, sSpoolPath, sExportPath]), SW_HIDE);
|
||
end;
|
||
|
||
if FileExists(sExportPath) then
|
||
begin
|
||
case cbColFmt.ItemIndex of
|
||
0:
|
||
;
|
||
// 1 : ;
|
||
2:
|
||
begin
|
||
if ExtractJpgFromTiff(sExportPath) > 0 then
|
||
DeleteFile(sExportPath);
|
||
end;
|
||
3:
|
||
; //sExt := '.tif';
|
||
else
|
||
begin
|
||
if ExtractpngFromTiff(sExportPath) > 0 then
|
||
DeleteFile(sExportPath);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
if chWatermark.Checked then
|
||
begin
|
||
var sWorkDir: string := sTaskDir + Format('%s-%s\', [FormatDateTime('hhnnss', Now), GetValidFileName(Job.PrinterName, '#')]);
|
||
|
||
if ForceDirectories(sWorkDir) then
|
||
begin
|
||
if sSpoolPath = '' then
|
||
sSpoolPath := GetSpoolCopyPath;
|
||
|
||
if FileExists(sSpoolPath) then
|
||
begin
|
||
Finalize(PrtInfo);
|
||
Job.GetJobDevInfo(PrtInfo);
|
||
|
||
Job.SetPrtJob(JOB_CONTROL_CANCEL);
|
||
Job.SetPrtJob(JOB_CONTROL_DELETE);
|
||
Job.WorkEnd := true;
|
||
TTgTrace.T('[W] Stop Job', [sSpoolPath]);
|
||
|
||
var pi: Integer := -1;
|
||
for i := 0 to Printer.Printers.Count - 1 do
|
||
begin
|
||
if Printer.Printers[i] = Job.PrinterName then
|
||
pi := i;
|
||
end;
|
||
|
||
if pi = -1 then
|
||
begin
|
||
TTgTrace.T('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<><C3A3> <20><><EFBFBD><EFBFBD> .. Name=%s', [Job.PrinterName]);
|
||
exit;
|
||
end;
|
||
|
||
Printer.PrinterIndex := pi;
|
||
|
||
var hDev: THandle := 0;
|
||
Printer.GetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
if hDev = 0 then
|
||
exit;
|
||
|
||
DevMode := GlobalLock(hDev);
|
||
try
|
||
PrtInfo.DevMode := DevMode^;
|
||
Printer.SetPrinter(arrDevice, arrDriver, arrPort, hDev);
|
||
finally
|
||
GlobalUnlock(hDev);
|
||
end;
|
||
|
||
TTgTrace.T('[W] Copy SpoolPath="%s"', [sSpoolPath]);
|
||
|
||
var sConv: string := GetRunExePathDir + 'Bs1psf.dat';
|
||
if FileExists(sConv) then
|
||
begin
|
||
sFName := GetValidFileName(ExtractFileName(Job.Document), '#');
|
||
// tif<69><66> -imgbitcount 8<><38> <20>÷<EFBFBD><C3B7>ν<EFBFBD><CEBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>Ѵ<EFBFBD> 24<32><34> <20>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20>ʹ<EFBFBD> Ŀ<><C4BF>
|
||
// <20><EFBFBD><D7B7><EFBFBD> png<6E><67> <20><><EFBFBD><EFBFBD> 24_0207 13:03:10 kku
|
||
sExportPath := sWorkDir + sFName + '.png'; // '.tif';
|
||
// ExecuteAppWaitUntilTerminate(sConv, Format('-$ 65XSD4234455S4PLET58 -unicode -imgxres 600 -imgyres 600 "%s" "%s"',
|
||
// [sSpoolPath, sExportPath]), SW_HIDE);
|
||
|
||
TTgTrace.T('[W] DocName="%s"', [PrtInfo.sDocName]);
|
||
TTgTrace.T('[W] PtrName="%s"', [PrtInfo.sPtrName]);
|
||
TTgTrace.T('[W] PaperInfo="%s"', [PrtInfo.sPaperInfo]);
|
||
TTgTrace.T('[W] TotalPage="%d"', [PrtInfo.dwTotalPage]);
|
||
|
||
if PrtInfo.sPtrName = '' then
|
||
begin
|
||
PrtInfo.sPtrName := Job.PrinterName;
|
||
TTgTrace.T('[W] Force PtrName="%s"', [PrtInfo.sPtrName]);
|
||
end;
|
||
|
||
dlgProg_ := TDlgWaitExtrProcPrt.Create(Self, PrtInfo.dwTotalPage, sWorkDir, sFName);
|
||
dlgProg_.Show;
|
||
|
||
//Constructor TThdExecuteEndNoti.Create(hRcvWnd: HWND; OLog: ISuperObject; bUseWM: Boolean; sExePath, sParam, sSrcPath, sDestPath: String; pAssoc: Pointer; tif: TWICImage);
|
||
//Constructor TThdExecuteEndNoti.Create(hRcvWnd: HWND; OLog: ISuperObject; bUseWM: Boolean; aPrtInfo: TPrtJobDevInfo; sPortInfo, sExePath, sParam, sSrcPath, sDestPath: String; pAssoc: Pointer; tif: TWICImage);
|
||
// -imgbitcount 8 <20>߰<EFBFBD> <20>⺻<EFBFBD><E2BABB> 1, <20>⺻<EFBFBD><E2BABB><EFBFBD><EFBFBD> <20>ϸ<EFBFBD> <20>÷<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ȵǴ<C8B5> <20><><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD> <20>ִ<EFBFBD>
|
||
// depth<74><68> 1, 8, 24 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> 24_0207 09:35:07 kku
|
||
// TThdExecuteEndNoti.Create(Handle, PrtInfo, Job.Port, sConv,
|
||
//// '-$ 65XSD4234455S4PLET58 -unicode -imgxres 600 -imgyres 600 "%s" "%s"',
|
||
// '-$ 65XSD4234455S4PLET58 -unicode -imgbitcount 24 -imgxres 600 -imgyres 600 "%s" "%s"',
|
||
// sSpoolPath, sExportPath, Job, TWICImage.Create).StartThread;
|
||
|
||
TThdExecuteEndNoti.Create(Handle, nil, chWatermark.Checked, PrtInfo, Job.Port, sConv,
|
||
// '-$ 65XSD4234455S4PLET58 -unicode -imgxres 600 -imgyres 600 "%s" "%s"',
|
||
'-$ 65XSD4234455S4PLET58 -unicode -imgbitcount 24 -imgxres 600 -imgyres 600 "%s" "%s"',
|
||
sSpoolPath, sExportPath, nil, TWICImage.Create).StartThread;
|
||
|
||
var pData: PPtrJobEnt := VT_AddChildData(vtList);
|
||
ZeroMemory(pData, SizeOf(TPtrJobEnt));
|
||
pData.dt := dt;
|
||
pData.bBlock := bBlock;
|
||
pData.sPName := sPName;
|
||
pData.Info := PrtInfo;
|
||
|
||
exit;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
finally
|
||
if (dlgProg_ = nil) and FileExists(sSpoolPath) then
|
||
DeleteFile(sSpoolPath);
|
||
end;
|
||
|
||
bBlock := false;
|
||
try
|
||
sChk := Job.PrinterName.ToUpper;
|
||
for i := 0 to AllowPtrList_.Count - 1 do
|
||
if Pos(AllowPtrList_[i], sChk) > 0 then
|
||
begin
|
||
Job.ResumePrtJob;
|
||
exit;
|
||
end;
|
||
|
||
sChk := Job.Document.ToUpper;
|
||
for i := 0 to AllowFNameList_.Count - 1 do
|
||
if Pos(AllowFNameList_[i], sChk) > 0 then
|
||
begin
|
||
Job.ResumePrtJob;
|
||
exit;
|
||
end;
|
||
|
||
O := SO;
|
||
O.I['T'] := TYPE_MSG_PREVENT_PRINTER;
|
||
sData := Job.PrinterName + '|' + Job.Document;
|
||
|
||
bBlock := chPreventPtr.Checked;
|
||
finally
|
||
var pData: PPtrJobEnt := VT_AddChildData(vtList);
|
||
ZeroMemory(pData, SizeOf(TPtrJobEnt));
|
||
pData.dt := dt;
|
||
pData.bBlock := bBlock;
|
||
pData.sPName := sPName;
|
||
pData.Info := PrtInfo;
|
||
// Job.GetJobDevInfo(pData.Info);
|
||
end;
|
||
|
||
if bBlock then
|
||
begin
|
||
Job.SetPrtJob(JOB_CONTROL_CANCEL);
|
||
Job.SetPrtJob(JOB_CONTROL_DELETE);
|
||
sData := sData + '|PV';
|
||
end
|
||
else
|
||
Job.ResumePrtJob;
|
||
|
||
O.S['D'] := sData;
|
||
TDlgNotice.Create(Self).PopupMessage(O.AsString);
|
||
|
||
Job.WorkEnd := true;
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
||
var
|
||
pData: PPtrJobEnt;
|
||
begin
|
||
pData := Sender.GetNodeData(Node);
|
||
Finalize(pData^);
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
||
begin
|
||
HintText := vtList.Text[Node, Column];
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.vtListGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
|
||
begin
|
||
NodeDataSize := SizeOf(TPtrJobEnt);
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
||
var
|
||
pData: PPtrJobEnt;
|
||
begin
|
||
pData := Sender.GetNodeData(Node);
|
||
|
||
case Column of
|
||
0:
|
||
CellText := IntToStr(Node.Index + 1);
|
||
1:
|
||
CellText := DateTimeToStr(pData.dt);
|
||
2:
|
||
CellText := BooleanToStr(pData.bBlock, '<27><><EFBFBD>ܵ<EFBFBD>', '<27><><EFBFBD>µ<EFBFBD>');
|
||
3:
|
||
CellText := pData.Info.sDocName;
|
||
4:
|
||
CellText := pData.Info.sPtrName;
|
||
5:
|
||
CellText := IntToStr(pData.Info.dwTotalPage);
|
||
6:
|
||
CellText := IntToStr(pData.Info.dwCopyCount);
|
||
7:
|
||
CellText := BooleanToStr(pData.Info.bColor, '<27>÷<EFBFBD>', '<27><><EFBFBD><EFBFBD>');
|
||
8:
|
||
CellText := pData.Info.sPaperInfo;
|
||
9:
|
||
CellText := BooleanToStr(pData.Info.bPaperV, '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>');
|
||
10:
|
||
CellText := Format('%d%%', [pData.Info.dwScale]);
|
||
11:
|
||
CellText := pData.Info.sDataType;
|
||
12:
|
||
CellText := pData.Info.sPrintProcessor;
|
||
13:
|
||
CellText := pData.sPName;
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.process_WM_NOTIEXECUTE_END(var msg: TMessage);
|
||
var
|
||
Thd: TThdExecuteEndNoti;
|
||
begin
|
||
if dlgProg_ <> nil then
|
||
FreeAndNil(dlgProg_);
|
||
|
||
Thd := TThdExecuteEndNoti(msg.LParam);
|
||
|
||
if FileExists(Thd.DestPath) or
|
||
FileExists(Format('%s_%.4d.png', [CutFileExt(Thd.DestPath), 1])) then
|
||
begin
|
||
var pWEnt: PPrtWaterEnt;
|
||
New(pWEnt);
|
||
pWEnt.sPtrName := Thd.PrtInfo.sPtrName;
|
||
pWEnt.sDocName := Thd.PrtInfo.sDocName;
|
||
pWEnt.sImgPath := Thd.DestPath;
|
||
pWEnt.dwPageSizeT := Thd.PrtInfo.dwPaperSizeT;
|
||
pWEnt.dwTotalPage := Thd.PrtInfo.dwTotalPage;
|
||
pWEnt.DevMode := Thd.PrtInfo.DevMode;
|
||
if (Thd.PortInfo <> '') and FileExists(Thd.PortInfo) and (GetFileExt(Thd.PortInfo).ToUpper = 'PDF') then
|
||
pWEnt.sPdfPath := Thd.PortInfo;
|
||
qWaterEnts_.Enqueue(pWEnt);
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgPtrMonMain.process_WM_SYSCOMMAND(var msg: TWMSyscommand);
|
||
begin
|
||
if msg.CmdType = SC_CLOSE then
|
||
begin
|
||
miExit.Click;
|
||
exit;
|
||
end;
|
||
inherited;
|
||
end;
|
||
|
||
end.
|
||
|