177 lines
5.5 KiB
Plaintext
177 lines
5.5 KiB
Plaintext
{*******************************************************}
|
|
{ }
|
|
{ ProcessWatermark }
|
|
{ }
|
|
{ Copyright (C) 2025 kku }
|
|
{ }
|
|
{*******************************************************}
|
|
|
|
unit ProcessWM_KOCES;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, System.Classes, Vcl.Graphics;
|
|
|
|
function ProcessWartermark_KOCES(DC: HDC; bStartPage: Boolean = true): Boolean;
|
|
|
|
implementation
|
|
|
|
uses
|
|
AppCtrlDefine, ApiHookPrint, BS1Hook, Tocsg.Safe, System.SysUtils, Condition,
|
|
Tocsg.Graphic;
|
|
|
|
function ProcessWartermark_KOCES(DC: HDC; bStartPage: Boolean = true): Boolean;
|
|
var
|
|
nW, nH, i, nX, nY, nDPI,
|
|
nGapW, nGapH, nBtLimitW: Integer;
|
|
sText, sBottomText: String;
|
|
MemCanvas: TCanvas;
|
|
hbmp, hOldBmp: HBITMAP;
|
|
pen: HPEN;
|
|
CtrlOpt: TAppCtrlOpt;
|
|
oldColor: TColor;
|
|
r: TRect;
|
|
begin
|
|
Result := true;
|
|
|
|
if _PrtDC <> DC then
|
|
exit;
|
|
|
|
// LogToReg('KOCES-01', '');
|
|
SaveDC(DC);
|
|
gAppHook.Helper.bIsWaterMaking_ := true;
|
|
try
|
|
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;
|
|
|
|
// LogToReg('KOCES-02', Format('W=%d, H=%d', [nW, nH]));
|
|
|
|
Guard(MemCanvas, TCanvas.Create);
|
|
MemCanvas.Handle := DC; //CreateCompatibleDC(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
|
|
if nH > nW then
|
|
begin
|
|
nGapW := 19;
|
|
nGapH := 17;
|
|
end else begin
|
|
nGapW := 29;
|
|
nGapH := 23;
|
|
end;
|
|
end;
|
|
end else begin
|
|
if gAppHook.Helper.bEndDocProc_ then
|
|
begin
|
|
if CompareText(gAppHook.ModuleName, 'winword.exe') = 0 then
|
|
nGapH := 70;
|
|
end;
|
|
end;
|
|
|
|
if nW > nH then
|
|
nBtLimitW := Round(nW * 0.45)
|
|
else
|
|
nBtLimitW := Round(nW * 0.55);
|
|
sBottomText := '이 문서는 KOCES에서 출력한 문서입니다. 본 문서는 허가없이 외부로 반출 할 수 없습니다.';
|
|
if _nFontSize = 0 then
|
|
begin
|
|
_nFontSize := 1;
|
|
while True do
|
|
begin
|
|
MemCanvas.Font.Size := _nFontSize;
|
|
// if _nFontSize > 500 then
|
|
// break;
|
|
|
|
if MemCanvas.TextWidth(sBottomText) >= nBtLimitW then
|
|
break;
|
|
Inc(_nFontSize);
|
|
end;
|
|
end;
|
|
|
|
MemCanvas.Font.Size := _nFontSize;
|
|
|
|
// LogToReg('KOCES-03', '');
|
|
|
|
|
|
|
|
oldColor := GetTextColor(DC);
|
|
// 폰트색 지정... 프로그램에 따라 지정되는 설정이 다르다
|
|
MemCanvas.Font.Color := clGray; // 메모장등
|
|
SetTextColor(DC, clGray); // 엑셀등
|
|
SetBkMode(MemCanvas.Handle, TRANSPARENT);
|
|
|
|
try
|
|
CtrlOpt := gAppHook.Helper.CtrlOpt;
|
|
with CtrlOpt do
|
|
begin
|
|
if CtrlOpt.sUName <> '' then
|
|
sText := Format('%s / %s / %s / %s', [sUName, sDeptName, sEmpNo, DateTimeToStr(Now)])
|
|
else if sDeptName <> '' then
|
|
sText := Format('%s / %s / %s', [sDeptName, sEmpNo, DateTimeToStr(Now)])
|
|
else
|
|
sText := Format('%s / %s', [sEmpNo, DateTimeToStr(Now)]);
|
|
end;
|
|
// sText := Format('%d-%d:%d-%d + ',[nW, nH, now, noh]) + sText;
|
|
MemCanvas.TextOut(nGapW, nGapH, sText);
|
|
// LogToReg('KOCES-04', sText);
|
|
|
|
MemCanvas.Font.Style := MemCanvas.Font.Style + [fsBold];
|
|
MemCanvas.TextOut(nW - MemCanvas.TextWidth(sBottomText) + nGapW,
|
|
nH - MemCanvas.TextHeight(sBottomText) + nGapH, sBottomText);
|
|
|
|
// LogToReg('KOCES-05', sText);
|
|
|
|
SelectObject(MemCanvas.Handle, hOldBmp);
|
|
DeleteObject(hbmp);
|
|
MemCanvas.Handle := 0;
|
|
finally
|
|
SetTextColor(DC, oldColor);
|
|
end;
|
|
|
|
gAppHook.Log(Format('ProcessWartermark_KOCES() - 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.
|