BSOne.SFC/EM.Lib/ImageEn_SRC/Source/ieprnform1.pas

551 lines
18 KiB
Plaintext

(* ImageEn Build 7.0.0.06.2637 @ 7-4-17 14:58:42.679 *)
(*
Copyright (c) 1998-2017 by Carlotta Calandra. All rights reserved.
Copyright (c) 2011-2017 by Xequte Software.
This software comes without express or implied warranty.
In no case shall the author be liable for any damage or unwanted behavior of any
computer hardware and/or software.
Author grants you the right to include the component
in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE.
ImageEn, IEvolution and ImageEn ActiveX may not be included in any
commercial, shareware or freeware libraries or components.
www.ImageEn.com
*)
(*
File version 1007
*)
unit ieprnform1;
{$R-}
{$Q-}
{$I ie.inc}
{$IFDEF IEINCLUDEPRINTDIALOGS}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ImageEnView, ImageEnIO,
ComCtrls, ExtCtrls, Menus, ieview, hyiedefs, imageenproc, ievect, ImgList, hyieutils, iexBitmaps, iesettings, iexLayers,
iexRulers;
type
TfiePrnForm1 = class(TForm)
PrinterSetupDialog1: TPrinterSetupDialog;
ImageEnView1: TImageEnView;
Panel1: TPanel;
imlPositions: TImageList;
grpSize: TGroupBox;
grpMargins: TGroupBox;
grpOther: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
UpDown1: TUpDown;
UpDown2: TUpDown;
UpDown3: TUpDown;
UpDown4: TUpDown;
lblPosition: TLabel;
cmbPosition: TComboBox;
edtGamma: TEdit;
updGamma: TUpDown;
lblGamma: TLabel;
lblSize: TLabel;
cmbPrintSize: TComboBox;
edtWidth: TEdit;
updWidth: TUpDown;
edtHeight: TEdit;
updHeight: TUpDown;
lblByX: TLabel;
btnPrint: TBitBtn;
btnSetup: TBitBtn;
btnCancel: TBitBtn;
lblPagesByX: TLabel;
edtPagesWide: TEdit;
updPagesWide: TUpDown;
edtPagesHigh: TEdit;
updPagesHigh: TUpDown;
procedure FormCreate(Sender: TObject);
procedure btnSetupClick(Sender: TObject);
procedure cmbPositionDrawItem(Control: TWinControl; Index: Integer; Rect:
TRect; State: TOwnerDrawState);
procedure PrintPreview(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure cmbPrintSizeChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SpeedButton12Click(Sender: TObject);
procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);
procedure UpDown3Click(Sender: TObject; Button: TUDBtnType);
procedure UpDown4Click(Sender: TObject; Button: TUDBtnType);
procedure updGammaClick(Sender: TObject; Button: TUDBtnType);
procedure updWidthClick(Sender: TObject; Button: TUDBtnType);
procedure updHeightClick(Sender: TObject; Button: TUDBtnType);
procedure FormResize(Sender: TObject);
procedure updPagesHighClick(Sender: TObject; Button: TUDBtnType);
procedure updPagesWideClick(Sender: TObject; Button: TUDBtnType);
private
{ Private declarations }
fHaveActivated: Boolean;
procedure IncDecMargins(text: TEdit; Button: TUDBtnType);
procedure IncDecValue(text: TEdit; Button: TUDBtnType);
function UnitMult: double;
procedure UpdatePrintSizeControls();
public
{ Public declarations }
fDialogsMeasureUnit: TIEDialogsMeasureUnit;
io: TImageEnIO;
fTaskName: string;
fPrintPreviewParams: TIOPrintPreviewParams;
PrintAnnotations: boolean;
activating: boolean;
procedure UpdateLanguage();
procedure LoadParameters;
procedure SaveParameters;
{$IFDEF UNIT_TESTING}
procedure SetNextLanguage;
{$ENDIF}
end;
implementation
uses
printers;
{$R *.DFM}
const
// Items of cmbPrintSize - MUST ALIGN WITH TIESize
_cmbPrintSize_Normal = 0;
_cmbPrintSize_FitToPage = 1;
_cmbPrintSize_StretchToPage = 2;
_cmbPrintSize_FillPage = 3;
_cmbPrintSize_SpecifiedSize = 4;
_cmbPrintSize_MultiplePages = 5;
{$IFDEF UNIT_TESTING}
procedure tfiePrnForm1.SetNextLanguage;
begin
Self.Tag := Self.Tag + 1;
if Self.tag >= ord( msUser ) then
Self.Tag := 0;
IEGlobalSettings().MsgLanguage := TMsgLanguage(Self.Tag);
UpdateLanguage();
end;
{$ENDIF}
function tfiePrnForm1.UnitMult: double;
begin
if (fDialogsMeasureUnit = ieduCm) or (fDialogsMeasureUnit = ieduSelectableDefCm) then
Result := CM_per_Inch
else
Result := 1;
end;
procedure TfiePrnForm1.FormCreate(Sender: TObject);
begin
fHaveActivated := False;
IEInitializeComboBox( cmbPosition );
// Move controls to display positions
edtPagesWide .Top := edtWidth .Top;
updPagesWide .Top := updWidth .Top;
edtPagesHigh .Top := edtHeight .Top;
updPagesHigh .Top := updHeight .Top;
lblPagesByX .Top := lblByX .Top;
end;
procedure TfiePrnForm1.btnSetupClick(Sender: TObject);
begin
PrinterSetupDialog1.Execute;
PrintPreview(self);
end;
procedure tfiePrnForm1.LoadParameters;
begin
// get parameters from fPrintPreviewParams
Edit1.Text := FloatToStrF(fPrintPreviewParams.MarginTop, ffGeneral, 4, 4);
Edit2.Text := FloatToStrF(fPrintPreviewParams.MarginLeft, ffGeneral, 4, 4);
Edit3.Text := FloatToStrF(fPrintPreviewParams.MarginRight, ffGeneral, 4, 4);
Edit4.Text := FloatToStrF(fPrintPreviewParams.MarginBottom, ffGeneral, 4, 4);
cmbPosition.ItemIndex := ord(fPrintPreviewParams.Position);
cmbPrintSize.ItemIndex := integer(fPrintPreviewParams.Size);
UpdatePrintSizeControls();
if ( fPrintPreviewParams.Width > 0 ) and ( fPrintPreviewParams.Size <> psMultiplePages ) then
edtWidth.Text := FloatToStrF(fPrintPreviewParams.Width, ffGeneral, 4, 4)
else
edtWidth.Text := FloatToStrF( (io.fPrintBitmap.Width / io.Params.DpiX) * UnitMult , ffGeneral, 4, 4);
if ( fPrintPreviewParams.Height > 0 ) and ( fPrintPreviewParams.Size <> psMultiplePages ) then
edtHeight.Text := FloatToStrF(fPrintPreviewParams.Height, ffGeneral, 4, 4)
else
edtHeight.Text := FloatToStrF( (io.fPrintBitmap.Height / io.Params.DpiY) * UnitMult, ffGeneral, 4, 4);
if ( fPrintPreviewParams.Width > 0 ) and ( fPrintPreviewParams.Size = psMultiplePages ) then
edtPagesWide.Text := IntToStr( Trunc( fPrintPreviewParams.Width ));
if ( fPrintPreviewParams.Height > 0 ) and ( fPrintPreviewParams.Size = psMultiplePages ) then
edtPagesHigh.Text := IntToStr( Trunc( fPrintPreviewParams.Height ));
edtGamma.Text := FloatToStrF(fPrintPreviewParams.Gamma, ffGeneral, 4, 4);
end;
procedure tfiePrnForm1.SaveParameters;
begin
// put parameters to fPrintPreviewParams
fPrintPreviewParams.MarginTop := IEStrToFloatDefS(Edit1.Text, 1);
fPrintPreviewParams.MarginLeft := IEStrToFloatDefS(Edit2.Text, 1);
fPrintPreviewParams.MarginRight := IEStrToFloatDefS(Edit3.Text, 1);
fPrintPreviewParams.MarginBottom := IEStrToFloatDefS(Edit4.Text, 1);
fPrintPreviewParams.Position := TIOPrintPreviewPosition(cmbPosition.ItemIndex);
fPrintPreviewParams.Size := TIOPrintPreviewSize(cmbPrintSize.ItemIndex);
if fPrintPreviewParams.Size = psSpecifiedSize then
begin
fPrintPreviewParams.Width := IEStrToFloatDefS( edtWidth.Text, 6 );
fPrintPreviewParams.Height := IEStrToFloatDefS( edtHeight.Text, 4 );
end
else
if fPrintPreviewParams.Size = psMultiplePages then
begin
fPrintPreviewParams.Width := StrToIntDef( edtPagesWide.Text, 6 );
fPrintPreviewParams.Height := StrToIntDef( edtPagesHigh.Text, 4 );
end
else
begin
fPrintPreviewParams.Width := -1;
fPrintPreviewParams.Height := -1;
end;
fPrintPreviewParams.Gamma := IEStrToFloatDefS(edtGamma.Text, 1);
end;
procedure tfiePrnForm1.FormActivate(Sender: TObject);
begin
// Prevent double calls to FormActivate
if fHaveActivated then
exit;
fHaveActivated := True;
Application.ProcessMessages; // first draws all controls (to avoid "Swiss Cheese")
activating := True;
if IEGlobalSettings().UseButtonGlyphsInDialogs = False then
begin
btnPrint.Glyph := nil;
btnSetup.Glyph := nil;
btnCancel.Glyph := nil;
cmbPosition.Style := csDropDownList;
end;
LoadParameters;
if cmbPrintSize.ItemIndex < 0 then
cmbPrintSize.ItemIndex := 1;
activating := false;
PrintPreview(Sender);
end;
procedure TfiePrnForm1.cmbPositionDrawItem(Control: TWinControl; Index:
Integer; Rect: TRect; State: TOwnerDrawState);
var
iGlyph : Integer;
sText : string;
begin
iGlyph := Index;
sText := cmbPosition.Items[Index];
IEDrawComboListBoxItem( TCombobox(Control).Canvas, Rect, Control.Enabled, sText, imlPositions, iGlyph);
end;
// Preview or print
procedure tfiePrnForm1.PrintPreview(Sender: TObject);
var
VerticalPos: TIEVerticalPos;
HorizontalPos: TIEHorizontalPos;
Size: TIESize;
MarginLeft, MarginTop, MarginRight, MarginBottom, SpecWidth, SpecHeight, GammaCorrection: double;
lc: TCursor;
begin
if activating then
exit;
if (Width < 100) or (Height < 100) then
exit; // to disallow AV
VerticalPos := ievpCenter;
HorizontalPos := iehpCenter;
if TIOPrintPreviewPosition(cmbPosition.ItemIndex) in [ppTopLeft, ppTop, ppTopRight] then
VerticalPos := ievpTop;
if TIOPrintPreviewPosition(cmbPosition.ItemIndex) in [ppBottomLeft, ppBottom, ppBottomRight] then
VerticalPos := ievpBottom;
if TIOPrintPreviewPosition(cmbPosition.ItemIndex) in [ppTopLeft, ppLeft, ppBottomLeft] then
HorizontalPos := iehpLeft;
if TIOPrintPreviewPosition(cmbPosition.ItemIndex) in [ppTopRight, ppRight, ppBottomRight] then
HorizontalPos := iehpRight;
Size := iesFitToPage;
case cmbPrintSize.ItemIndex of
_cmbPrintSize_Normal : Size := iesNormal;
_cmbPrintSize_FitToPage : Size := iesFitToPage;
_cmbPrintSize_StretchToPage : Size := iesFitToPageStretch;
_cmbPrintSize_FillPage : Size := iesFillPage;
_cmbPrintSize_SpecifiedSize : Size := iesSpecifiedSize;
_cmbPrintSize_MultiplePages : Size := iesMultiplePages;
end;
MarginLeft := IEStrToFloatDefS(Edit2.Text, 0) / UnitMult;
MarginTop := IEStrToFloatDefS(Edit1.Text, 0) / UnitMult;
MarginRight := IEStrToFloatDefS(Edit3.Text, 0) / UnitMult;
MarginBottom := IEStrToFloatDefS(Edit4.text, 0) / UnitMult;
if Size = iesMultiplePages then
begin
SpecWidth := IEStrToFloatDefS( edtPagesWide.Text, 1 );
SpecHeight := IEStrToFloatDefS( edtPagesHigh.Text, 1 );
end
else
begin
SpecWidth := IEStrToFloatDefS(edtWidth.Text, 1) / UnitMult;
if SpecWidth = 0 then SpecWidth := 0.001;
SpecHeight := IEStrToFloatDefS(edtHeight.Text, 1) / UnitMult;
if SpecHeight = 0 then SpecHeight := 0.001;
end;
GammaCorrection := IEStrToFloatDefS(edtGamma.Text, 1);
lc := Screen.Cursor;
Screen.Cursor := crHourGlass;
if Sender = btnPrint then
begin
// PRINT IMAGE
Printer.Title := fTaskName;
Printer.BeginDoc;
io.PrintImageEx( io.fPrintBitmap,
Printer.Canvas, -1, -1, -1, -1, MarginLeft, MarginTop, MarginRight, MarginBottom, VerticalPos, HorizontalPos,
Size, SpecWidth, SpecHeight, GammaCorrection);
Printer.EndDoc;
end
else
begin
// PREVIEW IMAGE ONLY
io.PreviewPrintImageEx( io.fPrintBitmap,
ImageEnView1.Bitmap, ImageEnView1.IdealImageWidth, ImageEnView1.IdealImageHeight, Printer, MarginLeft, MarginTop, MarginRight, MarginBottom, VerticalPos, HorizontalPos,
Size, SpecWidth, SpecHeight, GammaCorrection);
ImageEnView1.Update;
ImageEnView1.Fit;
end;
Screen.Cursor := lc;
if Sender = btnPrint then
ModalResult := mrOK;
end;
procedure tfiePrnForm1.cmbPrintSizeChange(Sender: TObject);
begin
UpdatePrintSizeControls;
PrintPreview(Sender);
end;
procedure tfiePrnForm1.UpdatePrintSizeControls();
var
bSpecifiedSize : Boolean;
bMultiplePages : Boolean;
begin
bSpecifiedSize := cmbPrintSize.ItemIndex = _cmbPrintSize_SpecifiedSize;
edtWidth .Enabled := bSpecifiedSize;
updWidth .Enabled := bSpecifiedSize;
lblByX .Enabled := bSpecifiedSize;
edtHeight .Enabled := bSpecifiedSize;
updHeight .Enabled := bSpecifiedSize;
bMultiplePages := cmbPrintSize.ItemIndex = _cmbPrintSize_MultiplePages;
edtPagesWide .Visible := bMultiplePages;
edtPagesHigh .Visible := bMultiplePages;
updPagesWide .Visible := bMultiplePages;
updPagesHigh .Visible := bMultiplePages;
lblPagesByX .Visible := bMultiplePages;
edtWidth .Visible := not bMultiplePages;
updWidth .Visible := not bMultiplePages;
lblByX .Visible := not bMultiplePages;
edtHeight .Visible := not bMultiplePages;
updHeight .Visible := not bMultiplePages;
end;
procedure TfiePrnForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Save parameters if they print or close, but do not cancel
If ModalResult <> mrCancel then
SaveParameters;
end;
procedure tfiePrnForm1.SpeedButton12Click(Sender: TObject);
begin
modalresult := mrCancel;
end;
procedure tfiePrnForm1.UpdateLanguage();
var
bEnglish : Boolean;
begin
bEnglish := (IEGlobalSettings().MsgLanguage = msEnglish) or
((IEGlobalSettings().MsgLanguage = msSystem) and (syslocale.PriLangID = LANG_ENGLISH));
Caption := iemsg(IEMSG_PRINT);
btnPrint .Caption := iemsg(IEMSG_PRINT);
btnSetup .Caption := iemsg(IEMSG_PRINTSETUP) + '...';
btnCancel.Caption := iemsg(IEMSG_CANCEL);
Edit1.Hint := iemsg(IEMSG_TOPMARGIN);
Edit2.Hint := iemsg(IEMSG_LEFTMARGIN);
Edit3.Hint := iemsg(IEMSG_RIGHTMARGIN);
Edit4.hint := iemsg(IEMSG_BOTTOMMARGIN);
Label1.Caption := iemsg(IEMSG_TOP) + ':';
Label2.Caption := iemsg(IEMSG_LEFT) + ':';
Label3.Caption := iemsg(IEMSG_RIGHT) + ':';
Label4.Caption := iemsg(IEMSG_BOTTOM) + ':';
cmbPrintSize.Hint := iemsg(IEMSG_LOCATIONSIZE);
edtGamma.hint := iemsg(IEMSG_GAMMACORRECTION);
edtPagesWide.Hint := iemsg(IEMsg_PagesAcross);
edtPagesHigh.Hint := iemsg(IEMsg_PagesDown);
cmbPosition.Clear;
cmbPosition.Items.Add(iemsg(IEMSG_TOPLEFT));
cmbPosition.Items.Add(iemsg(IEMSG_TOPCENTER));
cmbPosition.Items.Add(iemsg(IEMSG_TOPRIGHT));
cmbPosition.Items.Add(iemsg(IEMSG_CENTERLEFT));
cmbPosition.Items.Add(iemsg(IEMSG_CENTER));
cmbPosition.Items.Add(iemsg(IEMSG_CENTERRIGHT));
cmbPosition.Items.Add(iemsg(IEMSG_BOTTOMLEFT));
cmbPosition.Items.Add(iemsg(IEMSG_BOTTOMCENTER));
cmbPosition.Items.Add(iemsg(IEMSG_BOTTOMRIGHT));
if not bEnglish then
begin
cmbPrintSize.Items[ _cmbPrintSize_Normal ] := iemsg( IEMSG_NORMAL );
cmbPrintSize.Items[ _cmbPrintSize_FitToPage ] := iemsg( IEMSG_FITTOPAGE );
cmbPrintSize.Items[ _cmbPrintSize_StretchToPage ] := iemsg( IEMSG_STRETCHTOPAGE );
cmbPrintSize.Items[ _cmbPrintSize_FillPage ] := iemsg( IEMSG_FILLPAGE );
cmbPrintSize.Items[ _cmbPrintSize_SpecifiedSize ] := iemsg( IEMSG_SPECIFIEDSIZE );
cmbPrintSize.Items[ _cmbPrintSize_MultiplePages ] := iemsg( IEMSG_MULTIPLEPAGES );
end;
grpSize .Caption := ' ' + iemsg(IEMSG_SIZE) + ' ';
grpOther .Caption := ' ' + iemsg(IEMSG_OTHER) + ' ';
if (fDialogsMeasureUnit = ieduInches) or (fDialogsMeasureUnit = ieduSelectableDefInches) then
begin
// inches
grpMargins.Caption := ' ' + iemsg(IEMSG_MARGINS) + ' (' + iemsg(IEMSG_INCHES) + ') ';
edtWidth.Hint := iemsg(IEMSG_WIDTH) + ' (' + iemsg(IEMSG_INCHES) + ')';
edtHeight.Hint := iemsg(IEMSG_HEIGHT) + ' (' + iemsg(IEMSG_INCHES) + ')';
end
else
begin
// centimeters (Cm)
grpMargins.Caption := ' ' + iemsg(IEMSG_MARGINS) + ' (' + IEGlobalSettings().MeasureUnits[ieuCENTIMETERS] + ') ';
edtWidth.Hint := iemsg(IEMSG_WIDTH) + ' (' + IEGlobalSettings().MeasureUnits[ieuCENTIMETERS] + ')';
edtHeight.Hint := iemsg(IEMSG_HEIGHT) + ' (' + IEGlobalSettings().MeasureUnits[ieuCENTIMETERS] + ')';
end;
lblGamma.Caption := iemsg(IEMSG_GAMMACORRECTION) + ':';
lblPosition .Caption := iemsg(IEMSG_POSITION) + ':';
if bEnglish then
lblSize.Caption := 'Print Size:' // English text too short
else
lblSize.Caption := iemsg(IEMSG_SIZE) + ':';
end;
procedure TfiePrnForm1.IncDecMargins(text: TEdit; Button: TUDBtnType);
begin
case Button of
btNext: text.Text := FloatToStrF(dmax(IEStrToFloatDefS(text.Text, 0) + IEGlobalSettings().PrintDialogMarginsIncrement, IEGlobalSettings().PrintDialogMarginsMinValue), ffGeneral, 4, 4);
btPrev: text.Text := FloatToStrF(dmax(IEStrToFloatDefS(text.Text, 0) - IEGlobalSettings().PrintDialogMarginsIncrement, IEGlobalSettings().PrintDialogMarginsMinValue), ffGeneral, 4,4);
end;
end;
procedure TfiePrnForm1.IncDecValue(text: TEdit; Button: TUDBtnType);
begin
case Button of
btNext: text.Text := IntToStr( StrToIntDef(text.Text, 0) + 1 );
btPrev: text.Text := IntToStr( imax(1, StrToIntDef(text.Text, 0) - 1 ));
end;
end;
procedure TfiePrnForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(Edit1, Button);
end;
procedure TfiePrnForm1.UpDown2Click(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(Edit2, Button);
end;
procedure TfiePrnForm1.UpDown3Click(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(Edit3, Button);
end;
procedure TfiePrnForm1.UpDown4Click(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(Edit4, Button);
end;
procedure TfiePrnForm1.updGammaClick(Sender: TObject; Button: TUDBtnType);
begin
case button of
btNext: edtGamma.Text := FloatToStrF(dmax(IEStrToFloatDefS(edtGamma.Text, 0) + 0.1, 0), ffGeneral, 4, 4);
btPrev: edtGamma.Text := FloatToStrF(dmax(IEStrToFloatDefS(edtGamma.Text, 0) - 0.1, 0), ffGeneral, 4, 4);
end;
end;
procedure TfiePrnForm1.updWidthClick(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(edtWidth, Button);
end;
procedure TfiePrnForm1.updHeightClick(Sender: TObject; Button: TUDBtnType);
begin
IncDecMargins(edtHeight, Button);
end;
procedure TfiePrnForm1.FormResize(Sender: TObject);
begin
PrintPreview(self);
end;
procedure TfiePrnForm1.updPagesHighClick(Sender: TObject; Button: TUDBtnType);
begin
IncDecValue(edtPagesHigh, Button);
end;
procedure TfiePrnForm1.updPagesWideClick(Sender: TObject; Button: TUDBtnType);
begin
IncDecValue(edtPagesWide, Button);
end;
{$ELSE} // {$ifdef IEINCLUDEPRINTDIALOGS}
interface
implementation
{$ENDIF}
end.