307 lines
11 KiB
Plaintext
307 lines
11 KiB
Plaintext
{*******************************************************}
|
|
{ }
|
|
{ ProcessWatermark }
|
|
{ }
|
|
{ Copyright (C) 2025 kku }
|
|
{ }
|
|
{*******************************************************}
|
|
|
|
unit ProcessWM_DEMO;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, System.Classes, Vcl.Graphics;
|
|
|
|
type
|
|
PRGBQuadArray = ^TRGBQuadArray;
|
|
TRGBQuadArray = array[0..0] of TRGBQuad;
|
|
|
|
function ProcessWartermark_DEMO(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, EM.DelphiZXIngQRCode, Tocsg.WinInfo, Tocsg.Network, Winapi.GDIPOBJ, Winapi.GDIPUTIL, System.Math;
|
|
|
|
procedure DrawRotatedText(Canvas: TCanvas; X, Y, Angle: Integer; const Text: string);
|
|
var
|
|
LogFont: TLogFont;
|
|
OldFont, RotatedFont: HFONT;
|
|
begin
|
|
// 기존 폰트를 기반으로 로그폰트 가져오기
|
|
GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont);
|
|
|
|
// 회전 각도 설정 (0.1도 단위, 즉 450 = 45도)
|
|
LogFont.lfEscapement := Angle * 10;
|
|
LogFont.lfOrientation := Angle * 10;
|
|
|
|
// 안티앨리어싱 등 품질 향상 옵션
|
|
LogFont.lfQuality := ANTIALIASED_QUALITY;
|
|
|
|
// 회전 폰트 생성
|
|
RotatedFont := CreateFontIndirect(LogFont);
|
|
OldFont := SelectObject(Canvas.Handle, RotatedFont);
|
|
|
|
// 텍스트 출력
|
|
TextOut(Canvas.Handle, X, Y, PChar(Text), Length(Text));
|
|
|
|
// 자원 정리
|
|
SelectObject(Canvas.Handle, OldFont);
|
|
DeleteObject(RotatedFont);
|
|
end;
|
|
|
|
function ProcessWartermark_DEMO(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;
|
|
rc: 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(@rc, SizeOf(rc));
|
|
GetClipBox(DC, rc);
|
|
nW := rc.Width;
|
|
nH := rc.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; //CreateCompatibleDC(DC);
|
|
hbmp := CreateCompatibleBitmap(MemCanvas.Handle, nW, nH);
|
|
hOldBmp := SelectObject(MemCanvas.Handle, hbmp);
|
|
|
|
nGapW := 0;
|
|
nGapH := 0;
|
|
|
|
MemCanvas.Font.Name := '돋움'; //'Segoe UI';//'Tahoma'; // '굴림';
|
|
if (CompareText(gAppHook.ModuleName, 'winword.exe') = 0) or
|
|
(CompareText(gAppHook.ModuleName, 'notepad++.exe') = 0) then
|
|
nGapH := 60;
|
|
|
|
// 기본 폰트 조절
|
|
if nW > nH then
|
|
MemCanvas.Font.Size := nW div 160
|
|
else
|
|
MemCanvas.Font.Size := nH div 160;
|
|
oldColor := GetTextColor(DC);
|
|
|
|
try
|
|
SetBkMode(MemCanvas.Handle, TRANSPARENT);
|
|
MemCanvas.Font.Color := clGray;
|
|
SetTextColor(DC, clGray);
|
|
sText := gAppHook.Helper.sPrintWaterTxt;
|
|
|
|
// QR 코드 추가 25_1106 20:17:25 kku
|
|
var QRCode: TDelphiZXingQRCode;
|
|
Guard(QRCode, TDelphiZXingQRCode.Create);
|
|
QRCode.Data := '"' + sText + '"';
|
|
QRCode.QuietZone := 4;
|
|
var QrBmp: TBitmap;
|
|
Guard(QrBmp, TBitmap.Create);
|
|
QrBmp.SetSize(QRCode.Rows, QRCode.Columns);
|
|
var R, C, nQrSize: Integer;
|
|
for R := 0 to QRCode.Rows - 1 do
|
|
begin
|
|
for C := 0 to QRCode.Columns - 1 do
|
|
begin
|
|
if (QRCode.IsBlack[R, C]) then
|
|
begin
|
|
QrBmp.Canvas.Pixels[C, R] := clBlack;
|
|
end else
|
|
begin
|
|
QrBmp.Canvas.Pixels[C, R] := clWhite;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
ZeroMemory(@rc, SizeOf(rc));
|
|
if nW < nH then
|
|
nQrSize := nW div 20
|
|
else
|
|
nQrSize := nH div 20;
|
|
|
|
rc.Left := nW - nQrSize;
|
|
rc.Right := nW;
|
|
rc.Top := nH - nQrSize;
|
|
rc.Bottom := nH;
|
|
|
|
MemCanvas.StretchDraw(rc, QrBmp);
|
|
|
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
// 사선 텍스트
|
|
if _bmpWaterP = nil then
|
|
begin
|
|
// sText := CtrlOpt.sPrintWaterTxt;
|
|
sText := Format('%s / %s / %s', [GetComName, GetHostIP, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]);
|
|
sText := Format('%s / %s', [GetComName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]);
|
|
sText := sText + ' ' + sText + ' ' + sText + ' ' + sText + ' ' + sText;
|
|
try
|
|
// _bmpWaterP := CreateWatermarkBitmap_Final(sText, 50, 0.35, -45, 1500);
|
|
// _bmpWaterP.SaveToFile('C:\ProgramData\HE\test1.bmp');
|
|
|
|
_bmpWaterP := TBitmap.Create;
|
|
_bmpWaterP.PixelFormat := pf32bit;
|
|
_bmpWaterP.Canvas.Font.Assign(MemCanvas.Font);
|
|
_bmpWaterP.Canvas.Font.Color := clGray;
|
|
_bmpWaterP.Canvas.Font.Size := 15;
|
|
_bmpWaterP.Canvas.Font.Style := _bmpWaterP.Canvas.Font.Style - [fsBold];
|
|
_bmpWaterP.TransparentColor := clWhite;
|
|
_bmpWaterP.Transparent := true;
|
|
|
|
var nTW: Integer := _bmpWaterP.Canvas.TextWidth(sText);
|
|
_bmpWaterP.SetSize(nTW, _bmpWaterP.Canvas.TextHeight(sText));
|
|
_bmpWaterP.Canvas.TextOut(0, 0, sText);
|
|
|
|
// _bmpWaterP.SetSize(nW, nH);
|
|
// var nGap: Integer := _bmpWaterP.Canvas.TextHeight(sText) * 18;
|
|
// DrawRotatedText(_bmpWaterP.Canvas, nGap * -1, 0, -45, sText);
|
|
// DrawRotatedText(_bmpWaterP.Canvas, 0, 0, -45, sText);
|
|
// DrawRotatedText(_bmpWaterP.Canvas, nGap, 0, -45, sText);
|
|
|
|
except
|
|
// ..
|
|
end;
|
|
end;
|
|
|
|
if _bmpWaterP <> 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.13))
|
|
else
|
|
cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, BooleanToFloat(gAppHook.Helper.CtrlOpt.fWmTran <> 0.0, gAppHook.Helper.CtrlOpt.fWmTran, 0.15));
|
|
|
|
if not gAppHook.Helper.IsExcel or
|
|
( gAppHook.Helper.IsExcel and bStartPage and not _bDoStartProc) or
|
|
( gAppHook.Helper.IsExcel and not bStartPage ) then
|
|
begin
|
|
var nGap: Integer := _bmpWaterP.Canvas.TextHeight(sText) * 22;
|
|
DrawBitmapWaterEx2(MemCanvas.Handle, nGap * -1, 0, _bmpWaterP, @cTrMatrix, 0, 0, 45);
|
|
DrawBitmapWaterEx2(MemCanvas.Handle, 0, 0, _bmpWaterP, @cTrMatrix, 0, 0, 45);
|
|
DrawBitmapWaterEx2(MemCanvas.Handle, nGap, 0, _bmpWaterP, @cTrMatrix, 0, 0, 45);
|
|
|
|
// DrawBitmapWaterEx2(MemCanvas.Handle, 0, 0, _bmpWaterP, @cTrMatrix);
|
|
end;
|
|
end;
|
|
|
|
// CI 이미지 출력
|
|
{
|
|
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.TransparentColor := clWhite;
|
|
_bmpWater.Transparent := true;
|
|
|
|
var bmp: TBitmap;
|
|
Guard(bmp, TBitmap.Create);
|
|
bmp.LoadFromFile(sImgPath);
|
|
_bmpWater.SetSize(bmp.Width * 4, bmp.Height * 4);
|
|
_bmpWater.Canvas.Draw((_bmpWater.Width div 2) - (bmp.Width div 2),
|
|
(_bmpWater.Height div 2) - (bmp.Height div 2), bmp);
|
|
|
|
// LogToReg('BW-01', BooleanToStr(gAppHook.Helper.CurAppType = catWebb, 'YES', 'NO'));
|
|
if gAppHook.Helper.CurAppType = catWebb then
|
|
ScalePercentBmp(_bmpWater, 40)
|
|
else
|
|
ScalePercentBmp(_bmpWater, 150);
|
|
// _bmpWater.SaveToFile('C:\Users\kku\Desktop\이전 바탕화면\출력 추출 데이터\1.bmp');
|
|
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.04))
|
|
else
|
|
// cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.0099);
|
|
cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, BooleanToFloat(gAppHook.Helper.CtrlOpt.fWmTran <> 0.0, gAppHook.Helper.CtrlOpt.fWmTran, 0.05));
|
|
|
|
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;
|
|
}
|
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
|
// if bStartPage then
|
|
// BitBlt(DC, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, SRCCOPY);
|
|
|
|
SelectObject(MemCanvas.Handle, hOldBmp);
|
|
|
|
// DeleteObject(pen);
|
|
DeleteObject(hbmp);
|
|
// if bStartPage then
|
|
// DeleteDC(MemCanvas.Handle);
|
|
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.
|