BSOne.SFC/eCrmHE/DLL_eCrmHeHelper/PrintWatermark/ProcessWM_Custom.pas

175 lines
6.2 KiB
Plaintext

{*******************************************************}
{ }
{ ProcessWatermark }
{ }
{ Copyright (C) 2025 kku }
{ }
{*******************************************************}
unit ProcessWM_Custom;
interface
uses
Winapi.Windows, System.Classes, Vcl.Graphics;
function ProcessWartermark_Custom(DC: HDC; bStartPage: Boolean = true): Boolean;
implementation
uses
AppCtrlDefine, ApiHookPrint, BS1Hook, Tocsg.Safe, System.SysUtils, Condition,
Tocsg.Graphic, Tocsg.Trace, GlobalDefine, Tocsg.Strings, Tocsg.WinInfo,
Tocsg.Network;
function ProcessWartermark_Custom(DC: HDC; bStartPage: Boolean = true): Boolean;
var
nW, nH, i, nX, nY,
nGapW, nGapH, nDefDivFont: Integer;
sText: String;
MemCanvas: TCanvas;
hbmp, hOldBmp: HBITMAP;
pen: HPEN;
oldColor: TColor;
CtrlOpt: TAppCtrlOpt;
r: TRect;
PWC: TPrtWaterCfg;
begin
Result := true;
if _PrtDC <> DC then
exit;
SaveDC(DC);
gAppHook.Helper.bIsWaterMaking_ := true;
try
// WriteLnFileEndUTF8('C:\ProgramData\HE\prt.log', 'Step-0');
try
if gAppHook.Helper.IsExcel then
begin
// 클리핑 제거 25_0605 14:51:11 kku
SelectClipRgn(DC, 0);
// 엑셀은 출력시트 설정에 따라 전체 영역으로 잡히는 않는 현상이 있다.. 24_0805 13:46:31 kku
nW := GetDeviceCaps(DC, HORZRES); // 세로모드 : 4961, 가로모드 : 7016, 크로미움 프린트 인쇄시 4760
nH := GetDeviceCaps(DC, VERTRES); // 세로모드 : 7016, 가로모드 : 4961, 크로미움 프린트 인쇄시 6814
end else begin
// if bStartPage then // 이럴리 없겠지만 안전장치
// exit;
ZeroMemory(@r, SizeOf(r));
GetClipBox(DC, r);
nW := r.Width;
nH := r.Height;
// LogToReg('Step-1', Format('W = %d, H = %d,', [nW, nH]));
// LogToReg('Step-2', Format('W = %d, H = %d,', [GetDeviceCaps(DC, HORZRES), GetDeviceCaps(DC, VERTRES)]));
if nW = 0 then
nW := GetDeviceCaps(DC, HORZRES); // 세로모드 : 4961, 가로모드 : 7016, 크로미움 프린트 인쇄시 4760
if nH = 0 then
nH := GetDeviceCaps(DC, VERTRES); // 세로모드 : 7016, 가로모드 : 4961, 크로미움 프린트 인쇄시 6814
end;
Guard(MemCanvas, TCanvas.Create);
MemCanvas.Handle := DC;
hbmp := CreateCompatibleBitmap(MemCanvas.Handle, nW, nH);
hOldBmp := SelectObject(MemCanvas.Handle, hbmp);
nGapW := 0;
nGapH := 0;
MemCanvas.Font.Name := 'Tahoma';
if gAppHook.Helper.bSmallFont_ then
begin
if Pos('PDF', UpperCase(_sPrtName)) = 0 then
begin
// 일반 프린터에서만 밀리는 현상이 있어서 갭을 준다.. 24_0627 10:52:33 kku
nGapW := 19;
nGapH := 17;
end;
end else begin
// if gAppHook.Helper.bEndDocProc_ then
// begin
// if CompareText(gAppHook.ModuleName, 'winword.exe') = 0 then
// nGapH := 70;
// end;
end;
// 기본 폰트 조절
// nDefDivFont을 10이라고 인식하기로함
if nW > nH then
nDefDivFont := nW div 130
else
nDefDivFont := nH div 130;
oldColor := GetTextColor(DC);
try
CtrlOpt := gAppHook.Helper.CtrlOpt;
PWC := CtrlOpt.PrtWaterCfg;
SetBkMode(MemCanvas.Handle, TRANSPARENT);
MemCanvas.Font.Color := clGray; // 메모장등
SetTextColor(DC, clGray); // 엑셀등
if (PWC.sTopText <> '') and (PWC.nTopSize > 0) then
begin
if gAppHook.Helper.bEndDocProc_ then
begin
if CompareText(gAppHook.ModuleName, 'winword.exe') = 0 then
nGapH := Round(70.0 * (Double(PWC.nTopSize) / 10));
end;
sText := StrsReplace(PWC.sTopText, ['{IpAddr}', '{HostName}', '{MacAddr}', '{EmpNo}', '{Dept}', '{UserName}', '{DateTime}'],
[CtrlOpt.sIpAddr, GetComName, GetMACAddr, CtrlOpt.sEmpNo, CtrlOpt.sDeptName, CtrlOpt.sUName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]);
MemCanvas.Font.Size := Round(Double(nDefDivFont) * (Double(PWC.nTopSize) / 10)); // 폰트 크기 줄임 24_0619 14:23:38 kku
case PWC.nTopPos of
1 : nX := nGapW; // 왼쪽
2 : nX := ((nW + nGapW) div 2) - (MemCanvas.TextWidth(sText) div 2); // 가운데
3 : nX := nW - MemCanvas.TextWidth(sText) + nGapW; // 오른쪽
end;
MemCanvas.TextOut(nX, nGapH, sText);
end;
if (PWC.sBotText <> '') and (PWC.nBotSize > 0) then
begin
if gAppHook.Helper.bEndDocProc_ then
begin
if CompareText(gAppHook.ModuleName, 'winword.exe') = 0 then
nGapH := Round(70.0 * (Double(PWC.nBotSize) / 10));
end;
sText := StrsReplace(PWC.sBotText, ['{IpAddr}', '{HostName}', '{MacAddr}', '{EmpNo}', '{Dept}', '{UserName}', '{DateTime}'],
[CtrlOpt.sIpAddr, GetComName, GetMACAddr, CtrlOpt.sEmpNo, CtrlOpt.sDeptName, CtrlOpt.sUName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]);
MemCanvas.Font.Size := Round(Double(nDefDivFont) * (Double(PWC.nBotSize) / 10)); // 폰트 크기 줄임 24_0619 14:23:38 kku
case PWC.nBotPos of
1 : nX := nGapW; // 왼쪽
2 : nX := ((nW + nGapW) div 2) - (MemCanvas.TextWidth(sText) div 2); // 가운데
3 : nX := nW - MemCanvas.TextWidth(sText) + nGapW; // 오른쪽
end;
MemCanvas.TextOut(nX, nH - MemCanvas.TextHeight(sText) + nGapH, sText);
end;
SelectObject(MemCanvas.Handle, hOldBmp);
DeleteObject(hbmp);
MemCanvas.Handle := 0;
finally
SetTextColor(DC, oldColor);
end;
gAppHook.Log(Format('ProcessWartermark() - Completed, LastError=%d', [GetLastError]));
except
// 실패하면 출력 안되게 해준다 22_0907 14:28:52 kku
Result := false;
DeleteDC(DC);
end;
finally
gAppHook.Helper.bIsWaterMaking_ := false;
RestoreDC(DC, -1);
end;
end;
end.