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

245 lines
9.5 KiB
Plaintext

{*******************************************************}
{ }
{ ProcessWatermark }
{ }
{ Copyright (C) 2025 kku }
{ }
{*******************************************************}
unit ProcessWM_SKEC;
interface
uses
Winapi.Windows, System.Classes, Vcl.Graphics;
function ProcessWartermark_SKEC(DC: HDC; bStartPage: Boolean = true): Boolean;
implementation
uses
AppCtrlDefine, ApiHookPrint, BS1Hook, Tocsg.Safe, System.SysUtils, Condition,
Tocsg.Graphic, Winapi.GDIPAPI, Tocsg.Strings, Vcl.Imaging.jpeg, Tocsg.Trace,
Tocsg.Convert;
function ProcessWartermark_SKEC(DC: HDC; bStartPage: Boolean = true): Boolean;
var
nW, nH, i, nX, nY, nSet,
nTextH1, nTextH2, nTextS1, nTextS2,
nGapW, nGapH, nFontSize: Integer;
sText: String;
MemCanvas: TCanvas;
hbmp, hOldBmp: HBITMAP;
pen: HPEN;
oldColor: TColor;
r: TRect;
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;
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 := '돋음';//'HY헤드라인M';//'Tahoma';
if (CompareText(gAppHook.ModuleName, 'winword.exe') = 0) or
(CompareText(gAppHook.ModuleName, 'notepad++.exe') = 0) then
nGapH := 45;
// 기본 폰트 조절
// if nW > nH then
// MemCanvas.Font.Size := nW div 195
// else
// MemCanvas.Font.Size := nH div 195;
MemCanvas.Font.Size := 10;
oldColor := GetTextColor(DC);
// 폰트색 지정... 프로그램에 따라 지정되는 설정이 다르다
MemCanvas.Font.Color := $00AEAEAE; // 메모장등
SetTextColor(DC, $00AEAEAE); // 엑셀등
try
SetBkMode(MemCanvas.Handle, TRANSPARENT);
if nW < nH then
nSet := nW
else
nSet := nH;
// 상단 문구 처리
sText := gAppHook.Helper.sPrintWaterTxt + ' 이 문서는 SK ecoplant 의 보안정책 및 관련 법령에 의해 보호를 받는 정보자산으로 승인 없는 열람, 복사, 수정, 배포를 금지합니다.';
nFontSize := MemCanvas.Font.Size;
nTextS1 := nFontSize;
while True do
begin
if MemCanvas.TextWidth(sText) >= nSet then
begin
nTextS1 := nFontSize - 1;
MemCanvas.Font.Size := nTextS1;
break;
end;
Inc(nFontSize);
MemCanvas.Font.Size := nFontSize;
end;
nTextH1 := MemCanvas.TextHeight(sText);
nY := nTextH1 + nGapH;
if nW < nH then
begin
MemCanvas.TextOut(nGapW, nY, gAppHook.Helper.sPrintWaterTxt);
sText := '이 문서는 SK ecoplant 의 보안정책 및 관련 법령에 의해 보호를 받는 정보자산으로 승인 없는 열람, 복사, 수정, 배포를 금지합니다.';
MemCanvas.TextOut(nW - nGapW - MemCanvas.TextWidth(sText), nY, sText);
end else begin
sText := gAppHook.Helper.sPrintWaterTxt + ' 이 문서는 SK ecoplant 의 보안정책 및 관련 법령에 의해 보호를 받는 정보자산으로 승인 없는 열람, 복사, 수정, 배포를 금지합니다.';
MemCanvas.TextOut(nGapW, nY, sText);
end;
// MemCanvas.TextOut(nGapW + (nW div 2) - (MemCanvas.TextWidth(sText) div 2), nY, sText);/
sText := 'This document is the informational asset protected by SK ecoplant security and law. Unauthorized access, copy, revision, distribution are strictly prohibited';
nFontSize := MemCanvas.Font.Size;
nTextS2 := nFontSize;
while True do
begin
if MemCanvas.TextWidth(sText) >= nSet then
begin
nTextS2 := nFontSize - 1;
MemCanvas.Font.Size := nTextS2;
break;
end;
Inc(nFontSize);
MemCanvas.Font.Size := nFontSize;
end;
nTextH2 := MemCanvas.TextHeight(sText);
// nY := MemCanvas.TextHeight(sText) + nGapH;
Inc(nY, nTextH2 + Round(nTextH2 / 2));
nFontSize := MemCanvas.Font.Size;
if nW < nH then
MemCanvas.TextOut(nGapW + (nW div 2) - (MemCanvas.TextWidth(sText) div 2), nY, sText)
else
MemCanvas.TextOut(nGapW, nY, sText);
// 하단 문구 처리
MemCanvas.Font.Size := nTextS1;
// nY := nH - (nTextH1 + nGapH) - (nTextH2 + Round(nTextH2 / 2));
nY := nH + nGapH - nTextH1 - (nTextH2 + Round(nTextH2 / 2));
if nW < nH then
begin
MemCanvas.TextOut(nGapW, nY, gAppHook.Helper.sPrintWaterTxt);
sText := '이 문서는 SK ecoplant 의 보안정책 및 관련 법령에 의해 보호를 받는 정보자산으로 승인 없는 열람, 복사, 수정, 배포를 금지합니다.';
MemCanvas.TextOut(nW - nGapW - MemCanvas.TextWidth(sText), nY, sText);
Inc(nY, nTextH2 + Round(nTextH2 / 2));
sText := 'This document is the informational asset protected by SK ecoplant security and law. Unauthorized access, copy, revision, distribution are strictly prohibited';
MemCanvas.TextOut(nGapW + (nW div 2) - (MemCanvas.TextWidth(sText) div 2), nY, sText);
end else begin
sText := gAppHook.Helper.sPrintWaterTxt + ' 이 문서는 SK ecoplant 의 보안정책 및 관련 법령에 의해 보호를 받는 정보자산으로 승인 없는 열람, 복사, 수정, 배포를 금지합니다.';
MemCanvas.TextOut(nGapW, nY, sText);
Inc(nY, nTextH2 + Round(nTextH2 / 2));
sText := 'This document is the informational asset protected by SK ecoplant security and law. Unauthorized access, copy, revision, distribution are strictly prohibited';
MemCanvas.TextOut(nGapW, nY, sText);
end;
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if _bmpWater = nil then
begin
var sImgPath: String := ExtractFilePath(gAppHook.Helper.DllPath) + 'CI.bmp';
if FileExists(sImgPath) then
begin
try
_bmpWater := TBitmap.Create;
_bmpWater.PixelFormat := pf4bit; // 이거 켜면 흑백 출력시 안됨 24_0807 15:52:56 kku
_bmpWater.LoadFromFile(sImgPath);
// if gAppHook.Helper.CurAppType = catWebb then
// ScalePercentBmp(_bmpWater, 40)
// else
// ScalePercentBmp(_bmpWater, 140);
ScalePercentBmp(_bmpWater, 60);
_bmpWater.TransparentColor := clWhite;
_bmpWater.Transparent := true;
except
// ..
end;
end;
end;
if _bmpWater <> nil then
begin
var cTrMatrix: TColorMatrix;
ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix));
if gAppHook.Helper.bSmallFont_ then
cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, BooleanToFloat(gAppHook.Helper.CtrlOpt.fWmTran <> 0.0, gAppHook.Helper.CtrlOpt.fWmTran, 0.23))
else
cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, BooleanToFloat(gAppHook.Helper.CtrlOpt.fWmTran <> 0.0, gAppHook.Helper.CtrlOpt.fWmTran, 0.25));
Dec(nW, nGapW);
Dec(nH, nGapH);
nX := (nW div 4) - (_bmpWater.Width div 2);
nY := (nH div 4) - (_bmpWater.Height div 2);
// MemCanvas.Draw(nX, nY, _bmpWater);
if not gAppHook.Helper.IsExcel or
( gAppHook.Helper.IsExcel and bStartPage and not _bDoStartProc) or
( gAppHook.Helper.IsExcel and not bStartPage ) then
begin
DrawBitmapWaterEx(MemCanvas.Handle, nX, nY, _bmpWater, @cTrMatrix);
end;
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.