{*******************************************************} { } { ProcessWatermark } { } { Copyright (C) 2025 kku } { } {*******************************************************} unit ProcessWM_KBIZ; interface uses Winapi.Windows, System.Classes, Vcl.Graphics; function ProcessWartermark_KBIZ(DC: HDC; bStartPage: Boolean = true): Boolean; implementation uses AppCtrlDefine, ApiHookPrint, BS1Hook, Tocsg.Safe, System.SysUtils, Condition, Tocsg.Graphic, Winapi.GDIPAPI; function ProcessWartermark_KBIZ(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; CtrlOpt: TAppCtrlOpt; oldColor: TColor; r: TRect; begin Result := true; if _PrtDC <> DC then exit; 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; // nX := GetDeviceCaps(DC, ASPECTX); // nY := GetDeviceCaps(DC, ASPECTY); Guard(MemCanvas, TCanvas.Create); // if bStartPage then // MemCanvas.Handle := CreateCompatibleDC(DC) // else MemCanvas.Handle := DC; //CreateCompatibleDC(DC); hbmp := CreateCompatibleBitmap(MemCanvas.Handle, nW, nH); // hbmp := CreateCompatibleBitmap(DC, nW, nH); hOldBmp := SelectObject(MemCanvas.Handle, hbmp); // gAppHook.Log(Format('ProcessWartermark() - DocSize X=%d, Y=%d, W=%d, H=%d, dc=%d', [nX, nY, nW, nH, DC])); // LogToReg('Step0', Format('ProcessWartermark() - DocSize X=%d, Y=%d, W=%d, H=%d, dc=%d', [nX, nY, nW, nH, DC])); // if bStartPage then // PatBlt(MemCanvas.Handle, 0, 0, nW, nH, WHITENESS); // pen := CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); // hOldBmp := SelectObject(MemCanvas.Handle, pen); nGapW := 0; nGapH := 0; // SetBkMode(MemCanvas.Handle, TRANSPARENT); // MemCanvas.Font.Orientation := 250; 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; nDefDivFont := 180; end else begin // KBIZ에서는 제외, 아래 짤리는 현상이 확인됨 24_0801 15:47:28 kku if gAppHook.Helper.bEndDocProc_ then begin if CompareText(gAppHook.ModuleName, 'winword.exe') = 0 then nGapH := 30; // 70; end; nDefDivFont := 190; end; // 기본 폰트 조절 if nW > nH then MemCanvas.Font.Size := nW div 180 else MemCanvas.Font.Size := nH div 180; oldColor := GetTextColor(DC); // 폰트색 지정... 프로그램에 따라 지정되는 설정이 다르다 MemCanvas.Font.Color := clGray; // 메모장등 SetTextColor(DC, clGray); // 엑셀등 try CtrlOpt := gAppHook.Helper.CtrlOpt; // sText := CtrlOpt.sPrintWaterTxt; 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)]); sText := Format('%s %s', [sEmpNo, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); end; SetBkMode(MemCanvas.Handle, TRANSPARENT); MemCanvas.Font.Color := clSilver; // MemCanvas.TextOut(nW - MemCanvas.TextWidth(sText) + nGapW, // nH - MemCanvas.TextHeight(sText) + nGapH, sText); // 오른쪽 하단 MemCanvas.TextOut(nGapW, nH - MemCanvas.TextHeight(sText) + nGapH, sText); // 왼쪽 하단 // sText := gAppHook.Helper.sCurDocName_; // MemCanvas.TextOut(nGapW, nH - MemCanvas.TextHeight(sText) + nGapH, sText); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if _bmpWater = nil then begin // var sImgPath: String := ExtractFilePath(gAppHook.Helper.DllPath) + 'KBIZ.dat'; // if FileExists(sImgPath) then begin try // var jpg: TJPEGImage; // Guard(jpg, TJPEGImage.Create); // jpg.LoadFromFile(sImgPath); // AppCtrlDefine.pas SetCtrlOpt()에 업체 등록해줘야 정상 동작함... 24_0731 15:01:57 kku // var bmpTemp: TBitmap; // Guard(bmpTemp, TBitmap.Create); // bmpTemp := TBitmap.Create; // bmpTemp.Assign(jpg); // bmpTemp.PixelFormat := pf4bit; sText := 'KBIZ'; _bmpWater := TBitmap.Create; // _bmpWater.PixelFormat := pf4bit; // 이거 켜면 흑백 출력시 안됨 24_0807 15:52:56 kku _bmpWater.Canvas.Font.Assign(MemCanvas.Font); if nW < nH then _bmpWater.Canvas.Font.Size := nW div (nDefDivFont div 5) // 가운데 폰트 크기 키우려면 숫자를 키우면 됨 else _bmpWater.Canvas.Font.Size := nH div (nDefDivFont div 5); _bmpWater.Canvas.Font.Style := MemCanvas.Font.Style + [fsBold]; _bmpWater.Canvas.Font.Color := clSilver; // if gAppHook.Helper.bSmallFont_ then // _bmpWater.SetSize(_bmpWater.Canvas.TextWidth(sText), _bmpWater.Canvas.TextHeight(sText)) // _bmpWater.SetSize(Round(_bmpWater.Canvas.TextWidth(sText) / 6.5), Round(_bmpWater.Canvas.TextHeight(sText) / 6.5)) // else _bmpWater.SetSize(_bmpWater.Canvas.TextWidth(sText), _bmpWater.Canvas.TextHeight(sText)); _bmpWater.Canvas.TextOut(0, 0, sText); // if gAppHook.Helper.bSmallFont_ then // _bmpWater.SetSize(Round(bmpTemp.Width / 6.5), Round(bmpTemp.Height / 6.5)) // else // _bmpWater.SetSize(bmpTemp.Width, bmpTemp.Height); // _bmpWater.Canvas.StretchDraw(TRect.Create(0, 0, _bmpWater.Width, _bmpWater.Height), bmpTemp); // var ii, jj: Integer; // for ii := 0 to _bmpWater.Width - 1 do // for jj := 0 to _bmpWater.Height - 1 do // if _bmpWater.Canvas.Pixels[ii, jj] <> clWhite then // _bmpWater.Canvas.Pixels[ii, jj] := clRed; // for ii := 0 to _bmpWaterP.Width - 1 do // for jj := 0 to _bmpWaterP.Height - 1 do // if _bmpWaterP.Canvas.Pixels[ii, jj] <> clWhite then // if ((ii + jj) mod 2) = 0 then // _bmpWaterP.Canvas.Pixels[ii, jj] := clWhite // else // _bmpWaterP.Canvas.Pixels[ii, jj] := clRed; // ScalePercentBmp(_bmpWater, 60); _bmpWater.TransparentColor := clWhite; _bmpWater.Transparent := true; // _bmpWater.SaveToFile('C:\Users\kku\Desktop\이전 바탕화면\출력 추출 데이터\1.bmp'); except // .. end; end; end; if _bmpWater <> nil then begin var cTrMatrix: TColorMatrix; ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // 회색 // cTrMatrix[0][0] := 0.299; // cTrMatrix[0][1] := 0.299; // cTrMatrix[0][2] := 0.299; // cTrMatrix[1][0] := 0.587; // cTrMatrix[1][1] := 0.587; // cTrMatrix[1][2] := 0.587; // cTrMatrix[2][0] := 0.114; // cTrMatrix[2][1] := 0.114; // cTrMatrix[2][2] := 0.114; // cTrMatrix[3][3] := 0.1; // 투명도 1.0 ~ 0.22 // cTrMatrix[4][4] := 1.0; // 위 처럼하면 컬러랑 흑백이 섞인 출력의 경우 흑백에 로고가 안찍히는 문제 확인됨 24_0805 16:02:28 kku // cTrMatrix[0][0] := 1; // cTrMatrix[1][1] := 1; // cTrMatrix[2][2] := 1; // cTrMatrix[3][3] := 1; // 투명도 1.0 ~ 0.22 // cTrMatrix[4][4] := 1; // 신도 복합기에서 회색 가까운 색으로 표현한다.. // cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.2); // 이게 더 회색에 가깝지만 투명도가 떨어짐 // cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.05); // 후지에서 가장 흐리게 // cTrMatrix := MakeColorMatrix(0.05, 0.05, 0.05, 0.05); // 0.05가 가장 흐리게, 신도에선 흑백출력시 안보임 if gAppHook.Helper.bSmallFont_ then cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.05) else cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.08); // cTrMatrix[0][0] := 0.3; // cTrMatrix[0][1] := 0.3; // cTrMatrix[0][2] := 0.3; // cTrMatrix[1][0] := 0.59; // cTrMatrix[1][1] := 0.59; // cTrMatrix[1][2] := 0.59; // cTrMatrix[2][0] := 0.11; // cTrMatrix[2][1] := 0.11; // cTrMatrix[2][2] := 0.11; // cTrMatrix[3][3] := 0.22; // 투명도 1.0 ~ 0.22 // cTrMatrix[4][4] := 1; 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.