MathgeomGLS
723 строки · 19.8 Кб
1unit fPrint;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11Vcl.Graphics,
12Vcl.Controls,
13Vcl.Forms,
14Vcl.Dialogs,
15Vcl.StdCtrls,
16Vcl.Buttons,
17Vcl.ExtCtrls,
18Vcl.Printers,
19
20uGlobal;
21
22type
23TPrintForm = class(TForm)
24Panel: TPanel;
25Label1: TLabel;
26Label2: TLabel;
27Label3: TLabel;
28Label4: TLabel;
29Label5: TLabel;
30EditScale: TEdit;
31EditLeft: TEdit;
32EditTop: TEdit;
33EditWidth: TEdit;
34EditHeight: TEdit;
35UnitRG: TRadioGroup;
36CloseBitBtn: TBitBtn;
37OKBitBtn: TBitBtn;
38Image: TImage;
39FitToPageButton: TSpeedButton;
40PageCentreButton: TSpeedButton;
41ColorDialog: TColorDialog;
42ColorButton: TSpeedButton;
43Label6: TLabel;
44EditBorder: TEdit;
45procedure FormCreate(Sender: TObject);
46procedure FormShow(Sender: TObject);
47procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
48procedure FloatKeyPress(Sender: TObject; var Key: Char);
49procedure ScaleKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
50procedure numKeyPress(Sender: TObject; var Key: Char);
51procedure LeftKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
52procedure TopKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
53procedure WidthKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
54procedure HeightKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
55procedure UnitRGClick(Sender: TObject);
56procedure FitToPageButtonClick(Sender: TObject);
57procedure PageCentreButtonClick(Sender: TObject);
58procedure ColorButtonClick(Sender: TObject);
59procedure CloseBitBtnClick(Sender: TObject);
60procedure EditBorderKeyPress(Sender: TObject; var Key: Char);
61procedure EditBorderKeyUp(Sender: TObject; var Key: Word;
62Shift: TShiftState);
63private
64bmpScale: double;
65bmpLeft: integer; { as pixels }
66bmpTop: integer; { as pixels }
67bmpWidth: integer; { as pixels }
68bmpHeight: integer; { as pixels }
69BorderWidth: integer;
70BorderColor: TColor;
71vubmp: TBitMap;
72procedure PaintImage;
73procedure ShowData(Sender: TObject);
74function PixelTomm(const v, t: integer): double;
75function PixelTocm(const v, t: integer): double;
76function PixelToInch(const v, t: integer): double;
77function mmToPixel(const v: double; const t: integer): integer;
78function cmToPixel(const v: double; const t: integer): integer;
79function InchToPixel(const v: double; const t: integer): integer;
80end;
81
82var
83PrintForm: TPrintForm;
84
85//========================================================================
86implementation
87//========================================================================
88
89uses
90fPlot1D;
91
92{$R *.dfm}
93
94procedure TPrintForm.FormCreate(Sender: TObject);
95begin
96with Layout do
97begin
98if bmpScale = 0 then
99begin
100Left := (Screen.Width - Width) div 2;
101Top := (Screen.Height - Height) div 2;
102UnitRG.ItemIndex := 0;
103bmpScale := 1;
104BorderColor := ClRed;
105BorderWidth := 10;
106end
107else
108begin
109Left := PrintLeft;
110Top := PrintTop;
111UnitRG.ItemIndex := PrintUnit;
112bmpScale := PrintScale;
113BorderColor := PrintBorderColor;
114BorderWidth := PrintBorderWidth;
115end;
116end;
117
118bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
119bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
120
121ShowData(Sender);
122vubmp := TBitMap.Create;
123vubmp.Width := Image.Width;
124vubmp.Height := Image.Height;
125end;
126
127procedure TPrintForm.FormShow(Sender: TObject);
128begin
129with MainForm.GLMemoryViewer do
130begin
131Width := vubmp.Width;
132Height := vubmp.Height;
133Buffer.BackgroundColor := GraphData.BackColor;
134Render;
135vubmp := Buffer.CreateSnapShotBitmap;
136end;
137UnitRG.SetFocus;
138UnitRG.ItemIndex := 0;
139UnitRGClick(Sender);
140EditScale.SetFocus;
141end;
142
143procedure TPrintForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
144var
145BorderRect: TRect;
146GraphRect: TRect;
147bmp: TBitmap;
148
149begin
150if ModalResult = mrOK then
151begin
152BorderRect := Rect(bmpLeft + BorderWidth div 2, bmpTop + BorderWidth div 2,
153bmpLeft + bmpWidth - BorderWidth div 2 + 1,
154bmpTop + bmpHeight - BorderWidth div 2 + 1);
155GraphRect := Rect(0, 0, bmpWidth - 2*BorderWidth,
156bmpHeight - 2*BorderWidth);
157
158Printer.Title := MainForm.Caption;
159Printer.BeginDoc;
160bmp := TBitmap.Create;
161try
162bmp.PixelFormat := pf32bit;
163{ bmp is a device-independent true-color 32 bits per pixel bitmap. }
164with GraphRect do
165begin
166bmp.Width := Right - Left;
167bmp.Height := Bottom - Top;
168end;
169
170with MainForm.GLMemoryViewer do
171begin
172Width := bmp.Width;
173Height := bmp.Height;
174Buffer.BackgroundColor := GraphData.BackColor;
175Render;
176bmp := Buffer.CreateSnapShotBitmap;
177end;
178
179Printer.Canvas.Pen.Color := BorderColor;
180Printer.Canvas.Pen.Width := BorderWidth;
181Printer.Canvas.Rectangle(BorderRect);
182Printer.Canvas.Draw(bmpLeft + BorderWidth, bmpTop + BorderWidth, bmp);
183finally
184Printer.EndDoc;
185bmp.Free;
186end;
187end;
188vubmp.Free;
189with Layout do
190begin
191PrintLeft := Left;
192PrintTop := Top;
193PrintUnit := UnitRG.ItemIndex;
194PrintScale := bmpScale;
195PrintBorderColor := BorderColor;
196PrintBorderWidth := BorderWidth;
197end;
198end;
199
200procedure TPrintForm.FloatKeyPress(Sender: TObject; var Key: Char);
201begin
202with Sender as TEdit do
203if not CharInSet(Key, ['0'..'9', '.', #8]) then Key := #0
204end;
205
206procedure TPrintForm.ScaleKeyUp(Sender: TObject; var Key: Word;
207Shift: TShiftState);
208begin
209try
210bmpScale := StrToFloat(EditScale.Text);
211except
212bmpScale := 1.0;
213end;
214
215bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
216if bmpWidth > PrinterInfo.xRes then
217begin
218bmpWidth := PrinterInfo.xRes;
219bmpScale := bmpWidth/MainForm.GLViewer.Width;
220bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
221ShowData(Sender);
222Exit;
223end;
224
225bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
226if bmpHeight > PrinterInfo.yRes then
227begin
228bmpHeight := PrinterInfo.yRes;
229bmpScale := bmpHeight/MainForm.GLViewer.Height;
230bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
231ShowData(Sender);
232Exit;
233end;
234ShowData(Sender);
235end;
236
237procedure TPrintForm.numKeyPress(Sender: TObject; var Key: Char);
238begin
239with Sender as TEdit do
240begin
241if UnitRG.ItemIndex = 0 then
242begin
243if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
244end
245else if not CharInSet(Key, ['0'..'9', '.', #8]) then Key := #0
246end;
247end;
248
249procedure TPrintForm.LeftKeyUp(Sender: TObject; var Key: Word;
250Shift: TShiftState);
251var
252v: double;
253
254begin
255try
256v := StrToFloat(EditLeft.Text);
257except
258v := 10;
259end;
260case UnitRG.ItemIndex of
2610:bmpLeft := round(v);
2621:bmpLeft := mmToPixel(v, 0);
2632:bmpLeft := cmToPixel(v, 0);
2643:bmpLeft := InchToPixel(v, 0);
265end;
266ShowData(Sender);
267end;
268
269procedure TPrintForm.TopKeyUp(Sender: TObject; var Key: Word;
270Shift: TShiftState);
271var
272v: double;
273
274begin
275try
276v := StrToFloat(EditTop.Text);
277except
278v := 10;
279end;
280case UnitRG.ItemIndex of
2810:bmpTop := round(v);
2821:bmpTop := mmToPixel(v, 0);
2832:bmpTop := cmToPixel(v, 0);
2843:bmpTop := InchToPixel(v, 0);
285end;
286ShowData(Sender);
287end;
288
289procedure TPrintForm.WidthKeyUp(Sender: TObject; var Key: Word;
290Shift: TShiftState);
291var
292v: double;
293
294begin
295try
296v := StrToFloat(EditWidth.Text);
297except
298v := bmpScale*MainForm.GLViewer.Width;
299end;
300case UnitRG.ItemIndex of
3010:bmpWidth := round(v);
3021:bmpWidth := mmToPixel(v, 0);
3032:bmpWidth := cmToPixel(v, 0);
3043:bmpWidth := InchToPixel(v, 0);
305end;
306if bmpWidth > PrinterInfo.xRes then
307begin
308bmpWidth := PrinterInfo.xRes;
309end;
310bmpScale := bmpWidth/MainForm.GLViewer.Width;
311bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
312ShowData(Sender);
313end; { TPrintForm.WidthKeyUp }
314
315procedure TPrintForm.HeightKeyUp(Sender: TObject; var Key: Word;
316Shift: TShiftState);
317var
318v: double;
319
320begin
321try
322v := StrToFloat(EditHeight.Text);
323except
324v := bmpScale*MainForm.GLViewer.Height;
325end;
326case UnitRG.ItemIndex of
3270:bmpHeight := round(v);
3281:bmpHeight := mmToPixel(v, 0);
3292:bmpHeight := cmToPixel(v, 0);
3303:bmpHeight := InchToPixel(v, 0);
331end;
332if bmpHeight > PrinterInfo.yRes then
333begin
334bmpHeight := PrinterInfo.yRes;
335end;
336bmpScale := bmpHeight/MainForm.GLViewer.Height;
337bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
338ShowData(Sender);
339end;
340
341procedure TPrintForm.UnitRGClick(Sender: TObject);
342begin
343ShowData(Sender);
344end;
345
346procedure TPrintForm.FitToPageButtonClick(Sender: TObject);
347var
348i: integer;
349
350begin
351UnitRG.SetFocus;
352i := UnitRG.ItemIndex;
353UnitRG.ItemIndex := 0;
354
355bmpScale := 1;
356bmpLeft := 0;
357bmpTop := 0;
358bmpHeight := MainForm.GLViewer.Height;
359bmpWidth := MainForm.GLViewer.Width;
360
361bmpWidth := Printer.PageWidth - 2*bmpLeft;
362bmpScale := bmpWidth/MainForm.GLViewer.Width;
363bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
364
365if bmpHeight > Printer.PageHeight - 2*bmpTop then
366begin
367bmpHeight := Printer.PageHeight - 2*bmpTop;
368bmpScale := bmpHeight/MainForm.GLViewer.Height;
369bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
370end;
371
372ShowData(Sender);
373UnitRG.SetFocus;
374UnitRG.ItemIndex := i
375end;
376
377procedure TPrintForm.PageCentreButtonClick(Sender: TObject);
378var
379i: integer;
380
381begin
382UnitRG.SetFocus;
383i := UnitRG.ItemIndex;
384UnitRG.ItemIndex := 0;
385if bmpLeft + bmpWidth > Printer.PageWidth then bmpLeft := 0;
386if bmpTop + bmpHeight > Printer.PageHeight then bmpTop := 0;
387if bmpWidth > Printer.PageWidth then
388begin
389bmpWidth := Printer.PageWidth;
390bmpScale := bmpWidth/MainForm.GLViewer.Width;
391bmpHeight := round(bmpScale*MainForm.GLViewer.Height);
392end;
393if bmpHeight > Printer.PageHeight then
394begin
395bmpHeight := Printer.PageHeight;
396bmpScale := bmpHeight/MainForm.GLViewer.Height;
397bmpWidth := round(bmpScale*MainForm.GLViewer.Width);
398end;
399bmpLeft := (Printer.PageWidth - bmpWidth) div 2;
400bmpTop := (Printer.PageHeight - bmpHeight) div 2;
401ShowData(Sender);
402UnitRG.SetFocus;
403UnitRG.ItemIndex := i
404end;
405
406procedure TPrintForm.ColorButtonClick(Sender: TObject);
407begin
408ColorDialog.Color := BorderColor;
409if ColorDialog.Execute then
410begin
411BorderColor := ColorDialog.Color;
412PaintImage;
413end;
414end;
415
416procedure TPrintForm.EditBorderKeyPress(Sender: TObject; var Key: Char);
417begin
418if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
419end;
420
421procedure TPrintForm.EditBorderKeyUp(Sender: TObject; var Key: Word;
422Shift: TShiftState);
423var
424v: integer;
425begin
426try
427v := StrToInt(EditBorder.Text);
428except
429v := 10;
430end;
431BorderWidth := v;
432ShowData(Sender);
433end;
434
435procedure TPrintForm.PaintImage;
436var
437PaperWidthPix: integer;
438PaperHeightPix: integer;
439PrintAreaWidthPix: integer;
440PrintAreaHeightPix: integer;
441dx, dy: integer;
442Scale: double;
443Shade: TRect;
444Paper: TRect;
445PrintArea: TRect;
446Graph: TRect;
447
448begin
449{ calculations }
450PaperWidthPix := PrinterInfo.xRes+2*PrinterInfo.xOffset;
451PaperHeightPix := PrinterInfo.yRes+2*PrinterInfo.yOffset;
452
453if PaperWidthPix > PaperHeightPix
454then Scale := 0.95*Image.Width/PaperWidthPix
455else Scale := 0.95*Image.Height/PaperHeightPix;
456
457PaperHeightPix := round(Scale*PaperHeightPix);
458PaperWidthPix := round(Scale*PaperWidthPix);
459
460PrintAreaWidthPix := round(Scale*PrinterInfo.xRes);
461PrintAreaHeightPix := round(Scale*PrinterInfo.yRes);
462
463Paper.Top := (Image.Height - PaperHeightPix) div 2 - 3;
464Paper.Left := (Image.Width - PaperWidthPix) div 2 - 3;
465Paper.Bottom := Paper.Top + PaperHeightPix;
466Paper.Right := Paper.Left + PaperWidthPix;
467
468dx := round(Scale*PrinterInfo.xOffset);
469dy := round(Scale*PrinterInfo.yOffset);
470
471PrintArea.Top := Paper.Top + dy;
472PrintArea.Left := Paper.Left + dx;
473PrintArea.Bottom := PrintArea.Top + PrintAreaHeightPix;
474PrintArea.Right := PrintArea.Left + PrintAreaWidthPix;
475
476Shade := Paper;
477Inc(Shade.Top, 6);
478Inc(Shade.Left, 6);
479Inc(Shade.Bottom, 6);
480Inc(Shade.Right, 6);
481
482if bmpWidth < 100 then bmpWidth := 100;
483if bmpHeight < 100 then bmpHeight := 100;
484
485Graph.Left := PrintArea.Left + round(Scale*bmpLeft);
486Graph.Top := PrintArea.Top + round(Scale*bmpTop);
487Graph.Right := Graph.Left + round(Scale*bmpWidth);
488Graph.Bottom := Graph.Top + round(Scale*bmpHeight);
489
490with Image.Canvas do
491begin
492with Brush do
493begin
494Style := bsSolid;
495Color := clCream;
496end;
497FillRect(Rect(0, 0, Image.Width, Image.Height));
498
499Brush.Color := clSilver;
500Pen.Color := clBlack;
501FillRect(Shade);
502
503Brush.Color := clWhite;
504FillRect(Paper);
505Rectangle(Paper);
506
507Pen.Color := clBlue;
508Rectangle(PrintArea);
509
510StretchDraw(Graph, vubmp);
511if BorderWidth > 0 then
512begin
513Brush.Color := BorderColor;
514FrameRect(Graph);
515end;
516end;
517end;
518
519procedure TPrintForm.ShowData(Sender: TObject);
520procedure TagIsZero;
521begin
522EditScale.Text := FloatToStrF(bmpScale, ffFixed, 6, 3);
523case UnitRg.ItemIndex of
5240:begin { pixels }
525EditLeft.Text := IntToStr(bmpLeft);
526EditTop.Text := IntToStr(bmpTop);
527EditWidth.Text := IntToStr(bmpWidth);
528EditHeight.Text := IntToStr(bmpHeight);
529end;
5301:begin { mm }
531EditLeft.Text :=
532FloatToStrF(PixelTomm(bmpLeft, 0), ffFixed, 6, 3);
533EditTop.Text :=
534FloatToStrF(PixelTomm(bmpTop, 0), ffFixed, 6, 3);
535EditWidth.Text :=
536FloatToStrF(PixelTomm(bmpWidth, 0), ffFixed, 6, 3);
537EditHeight.Text :=
538FloatToStrF(PixelTomm(bmpHeight, 0), ffFixed, 6, 3);
539end;
5402:begin { cm }
541EditLeft.Text :=
542FloatToStrF(PixelTocm(bmpLeft, 0), ffFixed, 6, 3);
543EditTop.Text :=
544FloatToStrF(PixelTocm(bmpTop, 0), ffFixed, 6, 3);
545EditWidth.Text :=
546FloatToStrF(PixelTocm(bmpWidth, 0), ffFixed, 6, 3);
547EditHeight.Text :=
548FloatToStrF(PixelTocm(bmpHeight, 0), ffFixed, 6, 3);
549end;
5503:begin { inch }
551EditLeft.Text :=
552FloatToStrF(PixelToInch(bmpLeft, 0), ffFixed, 6, 3);
553EditTop.Text :=
554FloatToStrF(PixelToInch(bmpTop, 0), ffFixed, 6, 3);
555EditWidth.Text :=
556FloatToStrF(PixelToInch(bmpWidth, 0), ffFixed, 6, 3);
557EditHeight.Text :=
558FloatToStrF(PixelToInch(bmpHeight, 0), ffFixed, 6, 3);
559end;
560end;
561end; { TagIsZero }
562
563begin
564if Sender is TEdit then
565begin
566with Sender as TEdit do
567case Tag of
5680:TagIsZero; { Factor etc. }
5691:begin { Scale }
570case UnitRg.ItemIndex of
5710:begin { pixels }
572EditLeft.Text := IntToStr(bmpLeft);
573EditTop.Text := IntToStr(bmpTop);
574EditWidth.Text := IntToStr(bmpWidth);
575EditHeight.Text := IntToStr(bmpHeight);
576end;
5771:begin { mm }
578EditLeft.Text :=
579FloatToStrF(PixelTomm(bmpLeft, Tag), ffFixed, 6, 3);
580EditTop.Text :=
581FloatToStrF(PixelTomm(bmpTop, Tag), ffFixed, 6, 3);
582EditWidth.Text :=
583FloatToStrF(PixelTomm(bmpWidth, Tag), ffFixed, 6, 3);
584EditHeight.Text :=
585FloatToStrF(PixelTomm(bmpHeight, Tag), ffFixed, 6, 3);
586end;
5872:begin { cm }
588EditLeft.Text :=
589FloatToStrF(PixelTocm(bmpLeft, Tag), ffFixed, 6, 3);
590EditTop.Text :=
591FloatToStrF(PixelTocm(bmpTop, Tag), ffFixed, 6, 3);
592EditWidth.Text :=
593FloatToStrF(PixelTocm(bmpWidth, Tag), ffFixed, 6, 3);
594EditHeight.Text :=
595FloatToStrF(PixelTocm(bmpHeight, Tag), ffFixed, 6, 3);
596end;
5973:begin { inch }
598EditLeft.Text :=
599FloatToStrF(PixelToInch(bmpLeft, Tag), ffFixed, 6, 3);
600EditTop.Text :=
601FloatToStrF(PixelToInch(bmpTop, Tag), ffFixed, 6, 3);
602EditWidth.Text :=
603FloatToStrF(PixelToInch(bmpWidth, Tag), ffFixed, 6, 3);
604EditHeight.Text :=
605FloatToStrF(PixelToInch(bmpHeight, Tag), ffFixed, 6, 3);
606end;
607end;
608end;
6094:begin { Width }
610EditScale.Text := FloatToStrF(bmpScale, ffFixed, 6, 3);
611case UnitRg.ItemIndex of
6120:EditHeight.Text := IntToStr(bmpHeight);
6131:begin { mm }
614EditLeft.Text :=
615FloatToStrF(PixelTomm(bmpLeft, Tag), ffFixed, 6, 3);
616EditTop.Text :=
617FloatToStrF(PixelTomm(bmpTop, Tag), ffFixed, 6, 3);
618EditHeight.Text :=
619FloatToStrF(PixelTomm(bmpHeight, Tag), ffFixed, 6, 3);
620end;
6212:begin { cm }
622EditLeft.Text :=
623FloatToStrF(PixelTocm(bmpLeft, Tag), ffFixed, 6, 3);
624EditTop.Text :=
625FloatToStrF(PixelTocm(bmpTop, Tag), ffFixed, 6, 3);
626EditHeight.Text :=
627FloatToStrF(PixelTocm(bmpHeight, Tag), ffFixed, 6, 3);
628end;
6293:begin { inch }
630EditLeft.Text :=
631FloatToStrF(PixelToInch(bmpLeft, Tag), ffFixed, 6, 3);
632EditTop.Text :=
633FloatToStrF(PixelToInch(bmpTop, Tag), ffFixed, 6, 3);
634EditHeight.Text :=
635FloatToStrF(PixelToInch(bmpHeight, Tag), ffFixed, 6, 3);
636end;
637end;
638end;
6395:begin { Height }
640EditScale.Text := FloatToStrF(bmpScale, ffFixed, 6, 3);
641case UnitRg.ItemIndex of
6420:EditWidth.Text := IntToStr(bmpWidth);
6431:begin { mm }
644EditLeft.Text :=
645FloatToStrF(PixelTomm(bmpLeft, Tag), ffFixed, 6, 3);
646EditTop.Text :=
647FloatToStrF(PixelTomm(bmpTop, Tag), ffFixed, 6, 3);
648EditWidth.Text :=
649FloatToStrF(PixelTomm(bmpWidth, Tag), ffFixed, 6, 3);
650end;
6512:begin { cm }
652EditLeft.Text :=
653FloatToStrF(PixelTocm(bmpLeft, Tag), ffFixed, 6, 3);
654EditTop.Text :=
655FloatToStrF(PixelTocm(bmpTop, Tag), ffFixed, 6, 3);
656EditWidth.Text :=
657FloatToStrF(PixelTocm(bmpWidth, Tag), ffFixed, 6, 3);
658end;
6593:begin { inch }
660EditLeft.Text :=
661FloatToStrF(PixelToInch(bmpLeft, Tag), ffFixed, 6, 3);
662EditTop.Text :=
663FloatToStrF(PixelToInch(bmpTop, Tag), ffFixed, 6, 3);
664EditWidth.Text :=
665FloatToStrF(PixelToInch(bmpWidth, Tag), ffFixed, 6, 3);
666end;
667end;
668end;
669end;
670end
671else TagIsZero; { UnitRG }
672EditBorder.Text := IntToStr(BorderWidth);
673PaintImage;
674end;
675
676function TPrintForm.PixelTomm(const v, t: integer): double;
677begin
678if odd(t)
679then Result := 25.4*v/PrinterInfo.yPixPerInch
680else Result := 25.4*v/PrinterInfo.xPixPerInch;
681end;
682
683function TPrintForm.PixelTocm(const v, t: integer): double;
684begin
685if odd(t)
686then Result := 2.54*v/PrinterInfo.yPixPerInch
687else Result := 2.54*v/PrinterInfo.xPixPerInch;
688end;
689
690function TPrintForm.PixelToInch(const v, t: integer): double;
691begin
692if odd(t)
693then Result := v/PrinterInfo.yPixPerInch
694else Result := v/PrinterInfo.xPixPerInch;
695end;
696
697function TPrintForm.mmToPixel(const v: double; const t: integer): integer;
698begin
699if odd(t)
700then Result := round(PrinterInfo.yPixPerInch*v/25.4)
701else Result := round(PrinterInfo.xPixPerInch*v/25.4);
702end;
703
704function TPrintForm.cmToPixel(const v: double; const t: integer): integer;
705begin
706if odd(t)
707then Result := round(PrinterInfo.yPixPerInch*v/2.54)
708else Result := round(PrinterInfo.xPixPerInch*v/2.54);
709end;
710
711function TPrintForm.InchToPixel(const v: double; const t: integer): integer;
712begin
713if odd(t)
714then Result := round(PrinterInfo.yPixPerInch*v)
715else Result := round(PrinterInfo.xPixPerInch*v);
716end;
717
718procedure TPrintForm.CloseBitBtnClick(Sender: TObject);
719begin
720Close;
721end;
722
723end.
724