Changeset 241 for PrintPreview
- Timestamp:
- May 10, 2011, 6:51:04 AM (14 years ago)
- Location:
- PrintPreview
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
PrintPreview/PrintPreview.lpk
r239 r241 4 4 <PathDelim Value="\"/> 5 5 <Name Value="PrintPreview"/> 6 <Author Value="Chronos (robie@centrum.cz)"/> 6 7 <CompilerOptions> 7 8 <Version Value="9"/> 8 9 <PathDelim Value="\"/> 9 10 <SearchPaths> 10 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS) \"/>11 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 11 12 </SearchPaths> 12 13 <Other> … … 14 15 </Other> 15 16 </CompilerOptions> 17 <Description Value="Print preview component"/> 18 <License Value="GNU/GPL"/> 19 <Version Minor="1"/> 16 20 <Files Count="1"> 17 21 <Item1> … … 21 25 </Item1> 22 26 </Files> 27 <i18n> 28 <EnableI18N Value="True"/> 29 <OutDir Value="languages"/> 30 </i18n> 23 31 <Type Value="RunAndDesignTime"/> 24 32 <RequiredPkgs Count="3"> -
PrintPreview/UPrintPreview.lfm
r239 r241 1 1 object PrintPreviewForm: TPrintPreviewForm 2 Left = 2 882 Left = 244 3 3 Height = 459 4 Top = 1 714 Top = 124 5 5 Width = 664 6 6 Caption = 'Print preview' … … 114 114 Style = tbsSeparator 115 115 end 116 object Button5: TButton117 Left = 478118 Height = 22119 Top = 2120 Width = 75121 Caption = 'Button5'122 OnClick = Button5Click123 TabOrder = 5124 end125 116 end 126 117 object Image1: TImage … … 155 146 object ActionList1: TActionList 156 147 Images = ImageList1 157 left = 24 7148 left = 248 158 149 top = 67 159 150 object APrint: TAction -
PrintPreview/UPrintPreview.lrs
r239 r241 2 2 3 3 LazarusResources.Add('TPrintPreviewForm','FORMDATA',[ 4 'TPF0'#17'TPrintPreviewForm'#16'PrintPreviewForm'#4'Left'#3 ' '#1#6'Height'#35 +#203#1#3'Top'# 3#171#0#5'Width'#3#152#2#7'Caption'#6#13'Print preview'#12'Cli'6 +' entHeight'#3#203#1#11'ClientWidth'#3#152#2#8'OnCreate'#7#10'FormCreate'#9'O'7 +' nDestroy'#7#11'FormDestroy'#8'OnResize'#7#10'FormResize'#6'OnShow'#7#8'Form'8 +' Show'#10'LCLVersion'#6#6'0.9.30'#11'WindowState'#7#11'wsMaximized'#0#8'TToo'9 +' lBar'#8'ToolBar1'#4'Left'#2#0#6'Height'#2#26#3'Top'#2#0#5'Width'#3#152#2#710 +' Caption'#6#8'ToolBar1'#6'Images'#7#10'ImageList1'#14'ParentShowHint'#8#8'Sh'11 +' owHint'#9#8'TabOrder'#2#0#0#7'TButton'#7'Button1'#4'Left'#3#171#1#6'Height'12 +#2 #22#3'Top'#2#2#5'Width'#2'3'#6'Action'#7#6'AClose'#8'TabOrder'#2#0#0#0#7'T'13 +' Button'#7'Button2'#4'Left'#2#1#6'Height'#2#22#3'Top'#2#2#5'Width'#2'K'#6'Ac'14 +' tion'#7#6'APrint'#8'TabOrder'#2#1#0#0#7'TButton'#7'Button3'#4'Left'#2'L'#615 +' Height'#2#22#3'Top'#2#2#5'Width'#2'K'#6'Action'#7#10'APageSetup'#8'TabOrder'16 +#2# 2#0#0#7'TButton'#7'Button4'#4'Left'#3#151#0#6'Height'#2#22#3'Top'#2#2#5'W'17 +' idth'#2'K'#6'Action'#7#13'APrinterSetup'#8'TabOrder'#2#3#0#0#11'TToolButton'4 'TPF0'#17'TPrintPreviewForm'#16'PrintPreviewForm'#4'Left'#3#244#0#6'Height'#3 5 +#203#1#3'Top'#2'|'#5'Width'#3#152#2#7'Caption'#6#13'Print preview'#12'Client' 6 +'Height'#3#203#1#11'ClientWidth'#3#152#2#8'OnCreate'#7#10'FormCreate'#9'OnDe' 7 +'stroy'#7#11'FormDestroy'#8'OnResize'#7#10'FormResize'#6'OnShow'#7#8'FormSho' 8 +'w'#10'LCLVersion'#6#6'0.9.30'#11'WindowState'#7#11'wsMaximized'#0#8'TToolBa' 9 +'r'#8'ToolBar1'#4'Left'#2#0#6'Height'#2#26#3'Top'#2#0#5'Width'#3#152#2#7'Cap' 10 +'tion'#6#8'ToolBar1'#6'Images'#7#10'ImageList1'#14'ParentShowHint'#8#8'ShowH' 11 +'int'#9#8'TabOrder'#2#0#0#7'TButton'#7'Button1'#4'Left'#3#171#1#6'Height'#2 12 +#22#3'Top'#2#2#5'Width'#2'3'#6'Action'#7#6'AClose'#8'TabOrder'#2#0#0#0#7'TBu' 13 +'tton'#7'Button2'#4'Left'#2#1#6'Height'#2#22#3'Top'#2#2#5'Width'#2'K'#6'Acti' 14 +'on'#7#6'APrint'#8'TabOrder'#2#1#0#0#7'TButton'#7'Button3'#4'Left'#2'L'#6'He' 15 +'ight'#2#22#3'Top'#2#2#5'Width'#2'K'#6'Action'#7#10'APageSetup'#8'TabOrder'#2 16 +#2#0#0#7'TButton'#7'Button4'#4'Left'#3#151#0#6'Height'#2#22#3'Top'#2#2#5'Wid' 17 +'th'#2'K'#6'Action'#7#13'APrinterSetup'#8'TabOrder'#2#3#0#0#11'TToolButton' 18 18 +#11'ToolButton1'#4'Left'#3#24#1#3'Top'#2#2#5'Width'#2#8#7'Caption'#6#11'Tool' 19 19 +'Button1'#5'Style'#7#12'tbsSeparator'#0#0#11'TToolButton'#11'ToolButton2'#4 … … 29 29 +'n'#0#0#11'TToolButton'#11'ToolButton8'#4'Left'#3#1#1#3'Top'#2#2#6'Action'#7 30 30 +#8'AZoomOut'#0#0#11'TToolButton'#11'ToolButton9'#4'Left'#3#226#0#3'Top'#2#2#5 31 +'Width'#2#8#7'Caption'#6#11'ToolButton9'#5'Style'#7#12'tbsSeparator'#0#0#7'T' 32 +'Button'#7'Button5'#4'Left'#3#222#1#6'Height'#2#22#3'Top'#2#2#5'Width'#2'K'#7 33 +'Caption'#6#7'Button5'#7'OnClick'#7#12'Button5Click'#8'TabOrder'#2#5#0#0#0#6 31 +'Width'#2#8#7'Caption'#6#11'ToolButton9'#5'Style'#7#12'tbsSeparator'#0#0#0#6 34 32 +'TImage'#6'Image1'#4'Left'#2#0#6'Height'#3#157#1#3'Top'#2#26#5'Width'#3#133#2 35 33 +#5'Align'#7#8'alCustom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBott' … … 41 39 +#10'sbVertical'#8'PageSize'#2#0#8'TabOrder'#2#2#8'OnChange'#7#19'ScrollBarVe' 42 40 +'rtChange'#0#0#11'TActionList'#11'ActionList1'#6'Images'#7#10'ImageList1'#4 43 +'left'#3#24 7#0#3'top'#2'C'#0#7'TAction'#6'APrint'#7'Caption'#6#5'Print'#4'Hi'41 +'left'#3#248#0#3'top'#2'C'#0#7'TAction'#6'APrint'#7'Caption'#6#5'Print'#4'Hi' 44 42 +'nt'#6#5'Print'#9'OnExecute'#7#13'APrintExecute'#0#0#7'TAction'#10'APageSetu' 45 43 +'p'#7'Caption'#6#10'Page setup'#4'Hint'#6#10'Page setup'#9'OnExecute'#7#17'A' … … 66 64 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#177'gC'#255 67 65 +#194#129'O'#255#211#162'y'#255#210#160'v'#255#188'xJ'#255#176'fB'#255#0#0#0#0 68 ,#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#191#127'V'66 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#191#127'V' 69 67 +#255#234#201#158#255#244#223#195#255#246#226#201#255#246#226#201#255#244#223 70 +#196#255#227#189#144#255#187'xN'#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#068 ,#196#255#227#189#144#255#187'xN'#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 71 69 +#0#0#0#0#0#0#0#0#186'uI'#255#242#217#183#255#246#226#201#255#248#231#206#255 72 70 +#189#176#155#255#204#188#163#255#247#227#198#255#246#226#201#255#239#212#178 … … 130 128 +#246#226#201#255#244#222#192#255#231#197#158#255#155#140'h'#255'}nn'#255'Q' 131 129 +#174#211#255'0'#130#190#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 132 ,#0#0#0#0#0#0#0#176'f@'#255#181'mB'#255#180'lB'#255#176'f@'#255#0#0#0#0'&x'130 +#0#0#0#0#0#0#0#176'f@'#255#181'mB'#255#180'lB'#255#176'f@'#255#0#0#0#0'&x' 133 131 +#194#255'4'#138#197#255'B'#165#216#255'(h'#161#255#0#0#0#0#0#0#0#0#0#0#0#0#0 134 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0132 ,#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 135 133 +#0'$d'#162#255'6'#137#193#255'='#155#214#255'&_'#149#255#0#0#0#0#0#0#0#0#0#0 136 134 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 … … 194 192 +#28#255#0#0#0#0#0#0#0#0#173'z'#19#255#188#141'3'#255#173'z'#19#255#0#0#0#0#0 195 193 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#174'|'#29#255#175#127'$'#255#169'x'#29 196 ,#255#168'w'#28#255#0#0#0#0#0#0#0#0#0#0#0#0#169'u'#15#255#179#131'('#255#169194 +#255#168'w'#28#255#0#0#0#0#0#0#0#0#0#0#0#0#169'u'#15#255#179#131'('#255#169 197 195 +'u'#15#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#169'w'#26#255#164 198 +'s'#24#255#168'w'#28#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#164'q'#10#255#171'z'196 ,'s'#24#255#168'w'#28#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#164'q'#10#255#171'z' 199 197 +#31#255#164'q'#10#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#165's' 200 198 +#22#255#168'w'#28#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#159'l'#6#255 … … 258 256 +#0#0#194#142'*'#255#187#140'1'#255#185#137'/'#255#174'|'#29#255#0#0#0#0#0#0#0 259 257 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 260 ,#0#0#0#0#0#0#0#184#133'#'#255#172'|!'#255#169'w'#26#255#0#0#0#0#0#0#0#0#0#0#0261 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 262 +#0#0#0#0#0#0#0#174'{'#28#255#165's'#22#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0258 +#0#0#0#0#0#0#0#184#133'#'#255#172'|!'#255#169'w'#26#255#0#0#0#0#0#0#0#0#0#0#0 259 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 260 ,#0#0#0#0#0#0#0#174'{'#28#255#165's'#22#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 263 261 +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 264 262 +#0#0#0#0#0#162'p'#20#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0 -
PrintPreview/UPrintPreview.pas
r239 r241 28 28 TPrintPreview = class(TComponent) 29 29 private 30 FOnNewPage: TNotifyEvent; 30 31 FOnPrint: TNotifyEvent; 31 32 FOnPrintFooter: TNotifyEvent; … … 47 48 PageTitle: string; 48 49 Margins: TRect; 50 MarginsMM: TRect; 49 51 property XDPI: Integer read GetXDPI; 50 52 property YDPI: Integer read GetYDPI; 51 function MM(AValue: Double; VertRes: Boolean=True): Integer; 53 function MMToPixels(AValue: Double; VertRes: Boolean = True): Integer; 54 function PixelsToMM(AValue: Integer; VertRes: Boolean = True): Double; 52 55 procedure CreateNewPage; 53 56 constructor Create(AOwner: TComponent); override; … … 59 62 property PageNumber: Integer read GetPageNumber; 60 63 property Zoom: Double read GetZoom write SetZoom; 64 property OnNewPage: TNotifyEvent read FOnNewPage write FOnNewPage; 61 65 property OnPrint: TNotifyEvent read FOnPrint write FOnPrint; 62 66 property PageWidth: Integer read GetWidth; … … 83 87 Button3: TButton; 84 88 Button4: TButton; 85 Button5: TButton;86 89 EditPageNumber: TEdit; 87 90 Image1: TImage; … … 112 115 procedure AZoomInExecute(Sender: TObject); 113 116 procedure AZoomOutExecute(Sender: TObject); 114 procedure Button5Click(Sender: TObject);115 117 procedure EditPageNumberChange(Sender: TObject); 116 118 procedure FormCreate(Sender: TObject); … … 204 206 procedure TPrintPreview.UpdateMargins; 205 207 begin 206 Margins := Rect(MM(10), MM(10), MM(10), MM(10)); 207 end; 208 209 function TPrintPreview.MM(AValue: Double; VertRes: Boolean = True): Integer; 208 Margins := Rect(MMToPixels(MarginsMM.Left), MMToPixels(MarginsMM.Top), 209 MMToPixels(MarginsMM.Right), MMToPixels(MarginsMM.Bottom)); 210 end; 211 212 function TPrintPreview.MMToPixels(AValue: Double; VertRes: Boolean = True): Integer; 210 213 begin 211 214 if VertRes then … … 215 218 end; 216 219 220 function TPrintPreview.PixelsToMM(AValue: Integer; VertRes: Boolean): Double; 221 begin 222 if VertRes then 223 Result := AValue / YDPI * 25.4 224 else 225 Result := AValue / XDPI * 25.4; 226 end; 227 217 228 procedure TPrintPreview.CreateNewPage; 218 229 var … … 223 234 end else begin 224 235 NewPage := TPrintPage.Create; 236 Canvas := NewPage.Bitmap.Canvas; 237 if Pages.Count > 0 then 238 NewPage.Bitmap.Canvas.Font.Assign(TPrintPage(Pages.Last).Bitmap.Canvas.Font); 225 239 Pages.Add(NewPage); 226 Canvas := NewPage.Bitmap.Canvas;227 240 NewPage.Bitmap.SetSize(PageWidth, PageHeight); 228 241 with NewPage.Bitmap.Canvas do begin … … 241 254 end; 242 255 end; 256 if Assigned(FOnNewPage) then FOnNewPage(Self); 243 257 end; 244 258 … … 248 262 Zoom := 1; 249 263 Pages := TObjectList.Create; 264 MarginsMM := Rect(10, 10, 10, 10); 250 265 end; 251 266 … … 307 322 procedure TPrintPreviewForm.APrintExecute(Sender: TObject); 308 323 begin 324 (* with Printer.Canvas.Font do begin 325 Size := 10; 326 ShowMessage(IntToStr(Height) + ' ' + 327 IntToStr(PixelsPerInch)); 328 end; 329 with TPrintPage(PrintPreview.Pages.Last).Bitmap.Canvas.Font do begin 330 Size := 10; 331 ShowMessage(IntToStr(Height) + ' ' + IntToStr(PixelsPerInch)); 332 end; *) 333 309 334 PrintDialog1.MinPage := 1; 310 335 PrintDialog1.MaxPage := PrintPreview.PageCount; … … 317 342 procedure TPrintPreviewForm.AZoomInExecute(Sender: TObject); 318 343 begin 319 PrintPreview.Zoom := PrintPreview.Zoom * 2;344 PrintPreview.Zoom := PrintPreview.Zoom * 1.25; 320 345 Redraw; 321 346 end; … … 323 348 procedure TPrintPreviewForm.AZoomOutExecute(Sender: TObject); 324 349 begin 325 PrintPreview.Zoom := PrintPreview.Zoom / 2; 326 Redraw; 327 end; 328 329 procedure TPrintPreviewForm.Button5Click(Sender: TObject); 330 begin 331 ShowMessage('Printer page size: ' + IntToStr(Printer.PageWidth) + ', ' + IntToStr(Printer.PageHeight) + 332 ' DPI: ' + IntToStr(Printer.XDPI) + ', ' + IntToStr(Printer.YDPI) + 333 ' Page size: ' + IntToStr(TPrintPage(PrintPreview.Pages.Last).Bitmap.Width) + 334 ', ' + IntToStr(TPrintPage(PrintPreview.Pages.Last).Bitmap.Height) + ' '); 350 PrintPreview.Zoom := PrintPreview.Zoom / 1.25; 351 EditPageNumberChange(Self); 352 Redraw; 335 353 end; 336 354 … … 397 415 Page.Bitmap.Canvas.Width, 398 416 Page.Bitmap.Canvas.Height); 399 DestRect.Left := -Round(ScrollBarHoriz.Position / ScrollBarHoriz.Max * Width );400 DestRect.Top := -Round(ScrollBarVert.Position / ScrollBarVert.Max * Height );417 DestRect.Left := -Round(ScrollBarHoriz.Position / ScrollBarHoriz.Max * Width * PrintPreview.Zoom); 418 DestRect.Top := -Round(ScrollBarVert.Position / ScrollBarVert.Max * Height * PrintPreview.Zoom); 401 419 DestRect.Right := DestRect.Left + Round(Page.Bitmap.Canvas.Width * PrintPreview.Zoom); 402 420 DestRect.Bottom := DestRect.Top + Round(Page.Bitmap.Canvas.Height * PrintPreview.Zoom); … … 421 439 procedure TPrintPreviewForm.APageSetupExecute(Sender: TObject); 422 440 begin 423 PageSetupDialog1.Margins := PrintPreview.Margins; 424 PageSetupDialog1.Execute; 425 PrintPreview.Margins := PageSetupDialog1.Margins; 441 with PrintPreview do begin 442 PageSetupDialog1.Margins := Rect(MarginsMM.Left * 100, 443 MarginsMM.Top * 100, 444 MarginsMM.Right * 100, 445 MarginsMM.Bottom * 100); 446 if PageSetupDialog1.Execute then begin 447 MarginsMM := Rect(Round(PageSetupDialog1.Margins.Left / 100), 448 Round(PageSetupDialog1.Margins.Top / 100), 449 Round(PageSetupDialog1.Margins.Right / 100), 450 Round(PageSetupDialog1.Margins.Bottom / 100)); 451 UpdateMargins; 452 Redraw; 453 end; 454 end; 426 455 end; 427 456
Note:
See TracChangeset
for help on using the changeset viewer.