Changeset 241 for PrintPreview


Ignore:
Timestamp:
May 10, 2011, 6:51:04 AM (13 years ago)
Author:
george
Message:
  • Modified: Page count estimation.
Location:
PrintPreview
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • PrintPreview/PrintPreview.lpk

    r239 r241  
    44    <PathDelim Value="\"/>
    55    <Name Value="PrintPreview"/>
     6    <Author Value="Chronos (robie@centrum.cz)"/>
    67    <CompilerOptions>
    78      <Version Value="9"/>
    89      <PathDelim Value="\"/>
    910      <SearchPaths>
    10         <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)\"/>
     11        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    1112      </SearchPaths>
    1213      <Other>
     
    1415      </Other>
    1516    </CompilerOptions>
     17    <Description Value="Print preview component"/>
     18    <License Value="GNU/GPL"/>
     19    <Version Minor="1"/>
    1620    <Files Count="1">
    1721      <Item1>
     
    2125      </Item1>
    2226    </Files>
     27    <i18n>
     28      <EnableI18N Value="True"/>
     29      <OutDir Value="languages"/>
     30    </i18n>
    2331    <Type Value="RunAndDesignTime"/>
    2432    <RequiredPkgs Count="3">
  • PrintPreview/UPrintPreview.lfm

    r239 r241  
    11object PrintPreviewForm: TPrintPreviewForm
    2   Left = 288
     2  Left = 244
    33  Height = 459
    4   Top = 171
     4  Top = 124
    55  Width = 664
    66  Caption = 'Print preview'
     
    114114      Style = tbsSeparator
    115115    end
    116     object Button5: TButton
    117       Left = 478
    118       Height = 22
    119       Top = 2
    120       Width = 75
    121       Caption = 'Button5'
    122       OnClick = Button5Click
    123       TabOrder = 5
    124     end
    125116  end
    126117  object Image1: TImage
     
    155146  object ActionList1: TActionList
    156147    Images = ImageList1
    157     left = 247
     148    left = 248
    158149    top = 67
    159150    object APrint: TAction
  • PrintPreview/UPrintPreview.lrs

    r239 r241  
    22
    33LazarusResources.Add('TPrintPreviewForm','FORMDATA',[
    4   'TPF0'#17'TPrintPreviewForm'#16'PrintPreviewForm'#4'Left'#3' '#1#6'Height'#3
    5   +#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#7
    10   +'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'#6
    15   +'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'
    1818  +#11'ToolButton1'#4'Left'#3#24#1#3'Top'#2#2#5'Width'#2#8#7'Caption'#6#11'Tool'
    1919  +'Button1'#5'Style'#7#12'tbsSeparator'#0#0#11'TToolButton'#11'ToolButton2'#4
     
    2929  +'n'#0#0#11'TToolButton'#11'ToolButton8'#4'Left'#3#1#1#3'Top'#2#2#6'Action'#7
    3030  +#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
    3432  +'TImage'#6'Image1'#4'Left'#2#0#6'Height'#3#157#1#3'Top'#2#26#5'Width'#3#133#2
    3533  +#5'Align'#7#8'alCustom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBott'
     
    4139  +#10'sbVertical'#8'PageSize'#2#0#8'TabOrder'#2#2#8'OnChange'#7#19'ScrollBarVe'
    4240  +'rtChange'#0#0#11'TActionList'#11'ActionList1'#6'Images'#7#10'ImageList1'#4
    43   +'left'#3#247#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'
    4442  +'nt'#6#5'Print'#9'OnExecute'#7#13'APrintExecute'#0#0#7'TAction'#10'APageSetu'
    4543  +'p'#7'Caption'#6#10'Page setup'#4'Hint'#6#10'Page setup'#9'OnExecute'#7#17'A'
     
    6664  +#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
    6765  +#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'
    6967  +#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#0
     68  ,#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
    7169  +#0#0#0#0#0#0#0#0#186'uI'#255#242#217#183#255#246#226#201#255#248#231#206#255
    7270  +#189#176#155#255#204#188#163#255#247#227#198#255#246#226#201#255#239#212#178
     
    130128  +#246#226#201#255#244#222#192#255#231#197#158#255#155#140'h'#255'}nn'#255'Q'
    131129  +#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'
    133131  +#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#0
     132  ,#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
    135133  +#0'$d'#162#255'6'#137#193#255'='#155#214#255'&_'#149#255#0#0#0#0#0#0#0#0#0#0
    136134  +#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
     
    194192  +#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
    195193  +#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#169
     194  +#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
    197195  +'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'
    199197  +#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'
    200198  +#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
     
    258256  +#0#0#194#142'*'#255#187#140'1'#255#185#137'/'#255#174'|'#29#255#0#0#0#0#0#0#0
    259257  +#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#0
    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
    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#0
     258  +#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
    263261  +#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
    264262  +#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  
    2828  TPrintPreview = class(TComponent)
    2929  private
     30    FOnNewPage: TNotifyEvent;
    3031    FOnPrint: TNotifyEvent;
    3132    FOnPrintFooter: TNotifyEvent;
     
    4748    PageTitle: string;
    4849    Margins: TRect;
     50    MarginsMM: TRect;
    4951    property XDPI: Integer read GetXDPI;
    5052    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;
    5255    procedure CreateNewPage;
    5356    constructor Create(AOwner: TComponent); override;
     
    5962    property PageNumber: Integer read GetPageNumber;
    6063    property Zoom: Double read GetZoom write SetZoom;
     64    property OnNewPage: TNotifyEvent read FOnNewPage write FOnNewPage;
    6165    property OnPrint: TNotifyEvent read FOnPrint write FOnPrint;
    6266    property PageWidth: Integer read GetWidth;
     
    8387    Button3: TButton;
    8488    Button4: TButton;
    85     Button5: TButton;
    8689    EditPageNumber: TEdit;
    8790    Image1: TImage;
     
    112115    procedure AZoomInExecute(Sender: TObject);
    113116    procedure AZoomOutExecute(Sender: TObject);
    114     procedure Button5Click(Sender: TObject);
    115117    procedure EditPageNumberChange(Sender: TObject);
    116118    procedure FormCreate(Sender: TObject);
     
    204206procedure TPrintPreview.UpdateMargins;
    205207begin
    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));
     210end;
     211
     212function TPrintPreview.MMToPixels(AValue: Double; VertRes: Boolean = True): Integer;
    210213begin
    211214  if VertRes then
     
    215218end;
    216219
     220function TPrintPreview.PixelsToMM(AValue: Integer; VertRes: Boolean): Double;
     221begin
     222  if VertRes then
     223    Result := AValue / YDPI * 25.4
     224  else
     225    Result := AValue / XDPI * 25.4;
     226end;
     227
    217228procedure TPrintPreview.CreateNewPage;
    218229var
     
    223234  end else begin
    224235      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);
    225239      Pages.Add(NewPage);
    226       Canvas := NewPage.Bitmap.Canvas;
    227240      NewPage.Bitmap.SetSize(PageWidth, PageHeight);
    228241      with NewPage.Bitmap.Canvas do begin
     
    241254      end;
    242255    end;
     256  if Assigned(FOnNewPage) then FOnNewPage(Self);
    243257end;
    244258
     
    248262  Zoom := 1;
    249263  Pages := TObjectList.Create;
     264  MarginsMM := Rect(10, 10, 10, 10);
    250265end;
    251266
     
    307322procedure TPrintPreviewForm.APrintExecute(Sender: TObject);
    308323begin
     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
    309334  PrintDialog1.MinPage := 1;
    310335  PrintDialog1.MaxPage := PrintPreview.PageCount;
     
    317342procedure TPrintPreviewForm.AZoomInExecute(Sender: TObject);
    318343begin
    319   PrintPreview.Zoom := PrintPreview.Zoom * 2;
     344  PrintPreview.Zoom := PrintPreview.Zoom * 1.25;
    320345  Redraw;
    321346end;
     
    323348procedure TPrintPreviewForm.AZoomOutExecute(Sender: TObject);
    324349begin
    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;
    335353end;
    336354
     
    397415    Page.Bitmap.Canvas.Width,
    398416    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);
    401419  DestRect.Right := DestRect.Left + Round(Page.Bitmap.Canvas.Width * PrintPreview.Zoom);
    402420  DestRect.Bottom := DestRect.Top + Round(Page.Bitmap.Canvas.Height * PrintPreview.Zoom);
     
    421439procedure TPrintPreviewForm.APageSetupExecute(Sender: TObject);
    422440begin
    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;
    426455end;
    427456
Note: See TracChangeset for help on using the changeset viewer.