Turbopower_ipro: Improved print preview form.

git-svn-id: trunk@52057 -
This commit is contained in:
wp 2016-03-25 17:48:05 +00:00
parent 7ea0992229
commit 03648e9dcf
11 changed files with 518 additions and 216 deletions

View File

@ -99,6 +99,10 @@ const
FONTSIZESVALUSARRAY : array[0..6] of integer = (8,10,12,14,18,24,36);
MAXWORDS = 65536;
ZOOM_TO_FIT = 0;
ZOOM_TO_FIT_WIDTH = -1;
ZOOM_TO_FIT_HEIGHT = -2;
type
{$IFDEF IP_LAZARUS}
TIpEnumItemsMethod = TLCLEnumItemsMethod;
@ -2235,7 +2239,7 @@ type
PrintWidth, PrintHeight: Integer;
PrintTopLeft: TPoint;
PageCount: Integer;
function AntiAliasingMode: TAntiAliasingMode;
function PreviewAntiAliasingMode: TAntiAliasingMode;
{$ENDIF}
procedure InvalidateSize;
property Hyper : TIpHtml read FHyper write SetHtml;
@ -2395,21 +2399,58 @@ type
TIpHtmlControlEvent2 = procedure(Sender: TIpHtmlCustomPanel;
Frame: TIpHtmlFrame; Html: TIpHtml; Node: TIpHtmlNodeControl; var cancel: boolean) of object;
TIpHtmlPrintSettings = class(TPersistent)
TIpHtmlPreviewSettings = class(TPersistent)
private
FAntiAliasingMode: TAntiAliasingMode;
FPosition: TPosition;
FMaximized: Boolean;
FLeft: Integer;
FTop: Integer;
FWidth: Integer;
FHeight: Integer;
FZoom: Integer;
private
function IsLeftStored: Boolean;
function IsHeightStored: Boolean;
function IsTopStored: Boolean;
function IsWidthStored: Boolean;
public
constructor Create;
published
property AntiAliasingMode: TAntiAliasingMode
read FAntiAliasingMode write FAntiAliasingMode default amDontCare;
property Position: TPosition
read FPosition write FPosition default poScreenCenter;
property Maximized: Boolean
read FMaximized write FMaximized default false;
property Left: Integer
read FLeft write FLeft stored IsLeftStored;
property Top: Integer
read FTop write FTop stored IsTopStored;
property Width: Integer
read FWidth write FWidth stored IsWidthStored;
property Height: Integer
read FHeight write FHeight stored IsHeightStored;
property Zoom: integer
read FZoom write FZoom default 100;
end;
TIpHtmlPrintSettings = class(TPersistent)
private
FPreview: TIpHtmlPreviewSettings;
FMarginTop: Double;
FMarginLeft: Double;
FMarginBottom: Double;
FMarginRight: Double;
public
constructor Create;
destructor Destroy; override;
published
property AntiAliasingMode: TAntiAliasingMode read FAntiAliasingMode write FAntiAliasingMode;
property MarginLeft: Double read FMarginLeft write FMarginLeft;
property MarginTop: Double read FMarginTop write FMarginTop;
property MarginRight: Double read FMarginRight write FMarginRight;
property MarginBottom: Double read FMarginBottom write FMarginBottom;
property Preview: TIpHtmlPreviewSettings read FPreview write FPreview;
end;
{ TIpHtmlCustomPanel }
@ -13324,9 +13365,9 @@ begin
end;
{$IFDEF Html_Print}
function TIpHtmlInternalPanel.AntiAliasingMode: TAntiAliasingMode;
function TIpHtmlInternalPanel.PreviewAntiAliasingMode: TAntiAliasingMode;
begin
Result := HTMLPanel.PrintSettings.AntiAliasingMode;
Result := HTMLPanel.PrintSettings.Preview.AntiAliasingMode;
end;
procedure TIpHtmlInternalPanel.BeginPrint;
@ -13447,20 +13488,46 @@ begin
end;
procedure TIpHtmlInternalPanel.PrintPreview;
var
preview: TIpHtmlPreview;
p: TPosition;
begin
if (Hyper <> nil) then begin
BeginPrint;
try
with TIpHTMLPreview.Create(Application) do
preview := TIpHTMLPreview.Create(Application);
with preview do
try
p := HTMLPanel.PrintSettings.Preview.Position;
if (p = poDesigned) or (p = poDefaultSizeOnly) then begin
Left := HTMLPanel.PrintSettings.Preview.Left;
Top := HTMLPanel.PrintSettings.Preview.Top;
end;
if (p <> poDefault) and (p <> poDefaultSizeOnly) then begin
Width := HTMLPanel.PrintSettings.Preview.Width;
Height := HTMLPanel.PrintSettings.Preview.Height;
end;
Position := p;
if HTMLPanel.PrintSettings.Preview.Maximized then
WindowState := wsMaximized else
WindowState := wsNormal;
lblMaxPage.Caption := IntToStr(PageCount);
FCurPage := 1;
HTML := Hyper;
ScaleFonts := True;
try
OwnerPanel := Self;
Zoom := HTMLPanel.PrintSettings.Preview.Zoom;
ShowModal;
HTMLPanel.PrintSettings.Preview.Maximized := (WindowState = wsMaximized);
if (WindowState = wsNormal) and (p <> poDefault) and (p <> poDefaultSizeOnly)
then begin
HTMLPanel.PrintSettings.Preview.Left := Left;
HTMLPanel.PrintSettings.Preview.Top := Top;
HTMLPanel.PrintSettings.Preview.Width := Width;
HTMLPanel.PrintSettings.Preview.Height := Height;
end;
finally
ScaleFonts := False;
end;
@ -15851,17 +15918,61 @@ begin
Result := nil;
end;
{ TIpHtmlPreviewSettings }
constructor TIpHtmlPreviewSettings.Create;
begin
inherited;
FPosition := poScreenCenter;
FZoom := 100;
FWidth := Screen.Width * 3 div 4;
FHeight := Screen.Height * 3 div 4;
FLeft := Screen.Width div 4;
FTop := Screen.Height div 4;
end;
function TIpHtmlPreviewSettings.IsLeftStored: Boolean;
begin
Result := ((FPosition = poDesigned) or (FPosition = poDefaultSizeOnly)) and
(FLeft <> Screen.Width div 4);
end;
function TIpHtmlPreviewSettings.IsHeightStored: Boolean;
begin
Result := ((FPosition = poDesigned) or (FPosition = poDefaultPosOnly)) and
(FHeight <> Screen.Height * 3 div 4)
end;
function TIpHtmlPreviewSettings.IsTopStored: Boolean;
begin
Result := ((FPosition = poDesigned) or (FPosition = poDefaultSizeOnly)) and
(FTop <> Screen.Height div 4);
end;
function TIpHtmlPreviewSettings.IsWidthStored: Boolean;
begin
Result := ((FPosition = poDesigned) or (FPosition = poDefaultPosOnly)) and
(FWidth <> Screen.Width * 3 div 4)
end;
{ TIpHtmlPrintSettings }
constructor TIpHtmlPrintSettings.Create;
begin
inherited;
FPreview := TIpHtmlPreviewSettings.Create;
FMarginLeft := DEFAULT_PRINTMARGIN;
FMarginTop := DEFAULT_PRINTMARGIN;
FMarginRight := DEFAULT_PRINTMARGIN;
FMarginBottom := DEFAULT_PRINTMARGIN;
end;
destructor TIpHtmlPrintSettings.Destroy;
begin
FPreview.Free;
inherited;
end;
{ TIpHtmlNodeTH }
constructor TIpHtmlNodeTH.Create(ParentNode: TIpHtmlNode);

View File

@ -1,34 +1,34 @@
object IpHTMLPreview: TIpHTMLPreview
Left = 274
Height = 372
Height = 498
Top = 141
Width = 645
Width = 868
Caption = 'Print preview'
ClientHeight = 372
ClientWidth = 645
ClientHeight = 498
ClientWidth = 868
OnCreate = FormCreate
OnDestroy = FormDestroy
OnResize = FormResize
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.7'
object Panel1: TPanel
object ToolbarPanel: TPanel
Left = 0
Height = 36
Top = 0
Width = 645
Width = 868
Align = alTop
AutoSize = True
BevelOuter = bvNone
ClientHeight = 36
ClientWidth = 645
ClientWidth = 868
TabOrder = 0
object Label1: TLabel
AnchorSideLeft.Control = btnPrev
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 422
Left = 551
Height = 15
Top = 11
Width = 29
@ -39,9 +39,9 @@ object IpHTMLPreview: TIpHTMLPreview
object Label2: TLabel
AnchorSideLeft.Control = edtPage
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 493
Left = 622
Height = 15
Top = 11
Width = 11
@ -52,9 +52,9 @@ object IpHTMLPreview: TIpHTMLPreview
object lblMaxPage: TLabel
AnchorSideLeft.Control = Label2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 509
Left = 638
Height = 1
Top = 18
Width = 1
@ -64,7 +64,7 @@ object IpHTMLPreview: TIpHTMLPreview
object Label3: TLabel
AnchorSideLeft.Control = btnSelectPrinter
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 170
Height = 15
@ -75,7 +75,7 @@ object IpHTMLPreview: TIpHTMLPreview
ParentColor = False
end
object btnPrint: TButton
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 5
Height = 25
@ -89,11 +89,11 @@ object IpHTMLPreview: TIpHTMLPreview
TabOrder = 0
end
object btnFirst: TButton
AnchorSideLeft.Control = btnClose
AnchorSideLeft.Control = btnFit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 336
Left = 465
Height = 25
Top = 6
Width = 42
@ -101,14 +101,14 @@ object IpHTMLPreview: TIpHTMLPreview
BorderSpacing.Around = 5
Caption = '<<'
OnClick = btnFirstClick
TabOrder = 1
TabOrder = 6
end
object btnPrev: TButton
AnchorSideLeft.Control = btnFirst
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 383
Left = 512
Height = 25
Top = 6
Width = 34
@ -116,14 +116,14 @@ object IpHTMLPreview: TIpHTMLPreview
BorderSpacing.Around = 5
Caption = '<'
OnClick = btnPrevClick
TabOrder = 2
TabOrder = 7
end
object btnNext: TButton
AnchorSideLeft.Control = lblMaxPage
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 515
Left = 644
Height = 25
Top = 6
Width = 34
@ -131,14 +131,14 @@ object IpHTMLPreview: TIpHTMLPreview
BorderSpacing.Around = 5
Caption = '>'
OnClick = btnNextClick
TabOrder = 4
TabOrder = 9
end
object btnLast: TButton
AnchorSideLeft.Control = btnNext
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 554
Left = 683
Height = 25
Top = 6
Width = 42
@ -146,68 +146,43 @@ object IpHTMLPreview: TIpHTMLPreview
BorderSpacing.Around = 5
Caption = '>>'
OnClick = btnLastClick
TabOrder = 5
TabOrder = 10
end
object btnClose: TButton
AnchorSideLeft.Control = ZoomCombo
AnchorSideLeft.Control = btnLast
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 276
Left = 746
Height = 25
Top = 6
Width = 55
AutoSize = True
BorderSpacing.Left = 16
BorderSpacing.Around = 5
Cancel = True
Caption = 'Close'
ModalResult = 2
TabOrder = 6
TabOrder = 11
end
object edtPage: TEdit
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 456
Left = 585
Height = 23
Top = 7
Width = 32
Alignment = taRightJustify
BorderSpacing.Around = 5
OnChange = edtPageChange
TabOrder = 3
TabOrder = 8
Text = '1'
end
object ZoomCombo: TComboBox
AnchorSideLeft.Control = Label3
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
Left = 210
Height = 23
Top = 7
Width = 61
BorderSpacing.Around = 5
ItemHeight = 15
Items.Strings = (
'10%'
'25%'
'50%'
'75%'
'100%'
'150%'
'200%'
'300%'
'400%'
)
OnChange = ZoomComboChange
Style = csDropDownList
TabOrder = 7
end
object btnSelectPrinter: TButton
AnchorSideLeft.Control = btnPrint
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 61
Height = 25
@ -217,21 +192,83 @@ object IpHTMLPreview: TIpHTMLPreview
BorderSpacing.Around = 5
Caption = 'Select printer...'
OnClick = btnSelectPrinterClick
TabOrder = 8
TabOrder = 1
end
object edtZoom: TSpinEdit
AnchorSideLeft.Control = Label3
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 210
Height = 23
Top = 7
Width = 61
Alignment = taRightJustify
BorderSpacing.Around = 5
MaxValue = 1000
MinValue = 1
OnChange = edtZoomChange
TabOrder = 2
Value = 100
end
object btnFitHeight: TButton
AnchorSideLeft.Control = edtZoom
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 276
Height = 25
Top = 6
Width = 62
AutoSize = True
BorderSpacing.Around = 5
Caption = 'Height'
OnClick = btnFitHeightClick
TabOrder = 3
end
object btnFitWidth: TButton
AnchorSideLeft.Control = btnFitHeight
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 343
Height = 25
Top = 6
Width = 58
AutoSize = True
BorderSpacing.Around = 5
Caption = 'Width'
OnClick = btnFitWidthClick
TabOrder = 4
end
object btnFit: TButton
AnchorSideLeft.Control = btnFitWidth
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ToolbarPanel
AnchorSideTop.Side = asrCenter
Left = 406
Height = 25
Top = 6
Width = 54
AutoSize = True
BorderSpacing.Around = 5
Caption = 'Fit all'
OnClick = btnFitClick
TabOrder = 5
end
end
object ScrollBox1: TScrollBox
Left = 0
Height = 336
Height = 462
Top = 36
Width = 645
Width = 868
HorzScrollBar.Page = 158
HorzScrollBar.Tracking = True
VertScrollBar.Page = 125
VertScrollBar.Tracking = True
Align = alClient
ClientHeight = 332
ClientWidth = 641
ClientHeight = 458
ClientWidth = 864
Color = clBtnFace
ParentColor = False
TabOrder = 1
@ -241,8 +278,9 @@ object IpHTMLPreview: TIpHTMLPreview
Top = 0
Width = 158
BevelOuter = bvNone
ClientHeight = 125
ClientWidth = 158
BorderStyle = bsSingle
ClientHeight = 121
ClientWidth = 154
Color = clWhite
ParentColor = False
TabOrder = 0

View File

@ -48,13 +48,16 @@ uses
Windows,
{$ENDIF}
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, IpHtml;
StdCtrls, ExtCtrls, Spin, IpHtml;
resourcestring
rsIpHTMLPreviewPrintPreview = 'Print preview';
rsIpHTMLPreviewPrint = 'Print';
rsIpHTMLPreviewZoom = 'Zoom:';
rsIpHTMLPreviewClose = 'Close';
rsIpHTMLPreviewFitAll = 'Fit all';
rsIpHTMLPreviewFitWidth = 'Width';
rsIpHTMLPreviewFitHeight = 'Height';
rsIpHTMLPreviewPage = 'Page:';
rsIpHTMLPreviewOf = 'of';
rsIpHTMLPreviewSelectPrinter = 'Select printer ...';
@ -64,23 +67,15 @@ type
{ TIpHTMLPreview }
TIpHTMLPreview = class(TForm)
btnFitHeight: TButton;
btnFitWidth: TButton;
btnFit: TButton;
btnSelectPrinter: TButton;
Label3: TLabel;
ZoomCombo: TComboBox;
PaperPanel: TPanel;
PaintBox1: TPaintBox;
procedure btnNextClick(Sender: TObject);
procedure btnLastClick(Sender: TObject);
procedure btnSelectPrinterClick(Sender: TObject);
procedure edtPageChange(Sender: TObject);
procedure btnPrintClick(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ZoomComboChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
published
Panel1: TPanel;
edtZoom: TSpinEdit;
ToolbarPanel: TPanel;
btnPrint: TButton;
btnFirst: TButton;
btnPrev: TButton;
@ -92,32 +87,50 @@ type
Label2: TLabel;
lblMaxPage: TLabel;
ScrollBox1: TScrollBox;
procedure FormShow(Sender: TObject);
procedure btnFirstClick(Sender: TObject);
procedure btnFitClick(Sender: TObject);
procedure btnFitHeightClick(Sender: TObject);
procedure btnFitWidthClick(Sender: TObject);
procedure btnLastClick(Sender: TObject);
procedure btnNextClick(Sender: TObject);
procedure btnPrevClick(Sender: TObject);
procedure SetCurPage(const Value: Integer);
protected
procedure btnPrintClick(Sender: TObject);
procedure btnSelectPrinterClick(Sender: TObject);
procedure edtPageChange(Sender: TObject);
procedure edtZoomChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
private
FClipRect, SourceRect: TRect;
Scratch: TBitmap;
FScale: double;
FZoom: Integer;
FZoomToFit: Integer;
FLockZoomUpdate: Integer;
procedure SetCurPage(const Value: Integer);
procedure SetZoom(const Value: Integer);
procedure ResizeCanvas;
procedure ScaleSourceRect;
protected
procedure AlignPaintBox;
procedure Render;
procedure ResizeCanvas;
procedure ScaleSourceRect;
procedure UpdateBtnStates;
public
FCurPage: Integer;
HTML : TIpHtml;
PageRect: TRect;
OwnerPanel: TIpHtmlInternalPanel;
procedure RenderPage(PageNo: Integer);
property ClipRect: TRect read FClipRect write FClipRect;
property CurPage: Integer read FCurPage write SetCurPage;
procedure RenderPage(PageNo: Integer);
property Zoom: Integer read FZoom write SetZoom;
property Scale: double read FScale;
property Zoom: Integer read FZoom write SetZoom;
end;
implementation
uses
@ -132,22 +145,23 @@ uses
const
SCRATCH_WIDTH = 800; //640;
SCRATCH_HEIGHT = 600; //480;
ZOOM_FACTOR = 1.1;
procedure TIpHTMLPreview.FormShow(Sender: TObject);
begin
Zoom := 100;
RenderPage(CurPage);
end;
procedure TIpHTMLPreview.RenderPage(PageNo: Integer);
procedure TIpHTMLPreview.AlignPaintBox;
var
CR : TRect;
sb: Integer;
begin
CR := Rect(0, 0, OwnerPanel.PrintWidth, 0);
CR.Top := (PageNo - 1) * OwnerPanel.PrintHeight;
CR.Bottom := Cr.Top + OwnerPanel.PrintHeight;
PageRect := CR;
PaintBox1.Invalidate;
sb := GetSystemMetrics(SM_CXVSCROLL);
if PaperPanel.Width < ClientWidth - sb then
PaperPanel.Left := (ClientWidth - sb - PaperPanel.Width) div 2
else
PaperPanel.Left := 0;
sb := GetSystemMetrics(SM_CXHSCROLL);
if PaperPanel.Height < ClientHeight - sb - ToolbarPanel.Height then
PaperPanel.Top := (ClientHeight - sb - ToolbarPanel.Height - PaperPanel.Height) div 2
else
PaperPanel.Top := 0;
end;
procedure TIpHTMLPreview.btnFirstClick(Sender: TObject);
@ -155,25 +169,19 @@ begin
CurPage := 1;
end;
procedure TIpHTMLPreview.btnPrevClick(Sender: TObject);
procedure TIpHTMLPreview.btnFitClick(Sender: TObject);
begin
CurPage := CurPage - 1;
SetZoom(ZOOM_TO_FIT);
end;
procedure TIpHTMLPreview.SetCurPage(const Value: Integer);
procedure TIpHTMLPreview.btnFitHeightClick(Sender: TObject);
begin
if (Value <> FCurPage)
and (Value >= 1)
and (Value <= OwnerPanel.PageCount) then begin
FCurPage := Value;
RenderPage(Value);
edtPage.Text := IntToStr(CurPage);
end;
SetZoom(ZOOM_TO_FIT_HEIGHT);
end;
procedure TIpHTMLPreview.btnNextClick(Sender: TObject);
procedure TIpHTMLPreview.btnFitWidthClick(Sender: TObject);
begin
CurPage := CurPage + 1;
SetZoom(ZOOM_TO_FIT_WIDTH);
end;
procedure TIpHTMLPreview.btnLastClick(Sender: TObject);
@ -181,6 +189,16 @@ begin
CurPage := OwnerPanel.PageCount;
end;
procedure TIpHTMLPreview.btnNextClick(Sender: TObject);
begin
CurPage := CurPage + 1;
end;
procedure TIpHTMLPreview.btnPrevClick(Sender: TObject);
begin
CurPage := CurPage - 1;
end;
procedure TIpHTMLPreview.btnSelectPrinterClick(Sender: TObject);
begin
if OwnerPanel <> nil then
@ -188,11 +206,6 @@ begin
SetZoom(Zoom); {force recalc of preview sizes}
end;
procedure TIpHTMLPreview.edtPageChange(Sender: TObject);
begin
CurPage := StrToInt(edtPage.Text);
end;
procedure TIpHTMLPreview.btnPrintClick(Sender: TObject);
begin
Screen.Cursor := crHourglass;
@ -206,12 +219,68 @@ begin
end;
end;
procedure TIpHTMLPreview.ScaleSourceRect;
procedure TIpHTMLPreview.edtPageChange(Sender: TObject);
begin
SourceRect.Left := round(SourceRect.Left / Scale);
SourceRect.Top := round(SourceRect.Top / Scale);
SourceRect.Right := round(SourceRect.Right / Scale);
SourceRect.Bottom := round(SourceRect.Bottom / Scale);
CurPage := StrToInt(edtPage.Text);
end;
procedure TIpHTMLPreview.edtZoomChange(Sender: TObject);
var
newZoom: Double;
begin
if (FLockZoomUpdate = 0) and TryStrToFloat(edtZoom.Text, newZoom) then
SetZoom(Round(newZoom));
end;
procedure TIpHTMLPreview.FormCreate(Sender: TObject);
begin
FZoom := 100;
FZoomToFit := ZOOM_TO_FIT;
Scratch := TBitmap.Create;
Scratch.Width := SCRATCH_WIDTH;
Scratch.Height := SCRATCH_HEIGHT;
// localization
Self.Caption := rsIpHTMLPreviewPrintPreview;
btnPrint.Caption := rsIpHTMLPreviewPrint;
Label3.Caption := rsIpHTMLPreviewZoom;
btnClose.Caption := rsIpHTMLPreviewClose;
Label1.Caption := rsIpHTMLPreviewPage;
Label2.Caption := rsIpHTMLPreviewOf;
btnSelectPrinter.Caption := rsIpHTMLPreviewSelectPrinter;
btnFit.Caption := rsIpHTMLPreviewFitAll;
btnFitWidth.Caption := rsIpHTMLPreviewFitWidth;
btnFitHeight.Caption := rsIpHTMLPreviewFitHeight;
end;
procedure TIpHTMLPreview.FormDestroy(Sender: TObject);
begin
Scratch.Free;
end;
procedure TIpHTMLPreview.FormResize(Sender: TObject);
begin
if (FZoomToFit <= 0) and (OwnerPanel <> nil) then
SetZoom(FZoomToFit) {force recalc of preview sizes}
else
AlignPaintbox;
end;
procedure TIpHTMLPreview.FormShow(Sender: TObject);
begin
UpdateBtnStates;
// SetZoom(FZoom);
RenderPage(CurPage);
end;
procedure TIpHTMLPreview.PaintBox1Paint(Sender: TObject);
begin
SourceRect := PaintBox1.Canvas.ClipRect;
ScaleSourceRect;
ClipRect := SourceRect;
OffsetRect(SourceRect, 0, PageRect.Top);
Render;
end;
procedure TIpHTMLPreview.Render;
@ -246,7 +315,7 @@ begin
R.Right := R.Left + round(SCRATCH_WIDTH * Scale) + 1;
R.Bottom := R.Top + round(SCRATCH_HEIGHT * Scale) + 1;
PaintBox1.Canvas.AntialiasingMode := OwnerPanel.AntiAliasingMode;
PaintBox1.Canvas.AntialiasingMode := OwnerPanel.PreviewAntiAliasingMode;
PaintBox1.Canvas.StretchDraw(R, Scratch);
inc(WindowLeft, SCRATCH_WIDTH);
@ -260,77 +329,15 @@ begin
end;
end;
procedure TIpHTMLPreview.PaintBox1Paint(Sender: TObject);
begin
SourceRect := PaintBox1.Canvas.ClipRect;
ScaleSourceRect;
ClipRect := SourceRect;
OffsetRect(SourceRect, 0, PageRect.Top);
Render;
end;
procedure TIpHTMLPreview.FormDestroy(Sender: TObject);
begin
Scratch.Free;
end;
procedure TIpHTMLPreview.ZoomComboChange(Sender: TObject);
procedure TIpHTMLPreview.RenderPage(PageNo: Integer);
var
S: string;
CR : TRect;
begin
with ZoomCombo do
S := Items[ItemIndex];
Zoom := StrToInt(copy(S, 1, length(S) - 1));
end;
procedure TIpHTMLPreview.FormCreate(Sender: TObject);
begin
ZoomCombo.ItemIndex := 4;
FZoom := 100;
Scratch := TBitmap.Create;
Scratch.Width := SCRATCH_WIDTH;
Scratch.Height := SCRATCH_HEIGHT;
// localization
Self.Caption := rsIpHTMLPreviewPrintPreview;
btnPrint.Caption := rsIpHTMLPreviewPrint;
Label3.Caption := rsIpHTMLPreviewZoom;
btnClose.Caption := rsIpHTMLPreviewClose;
Label1.Caption := rsIpHTMLPreviewPage;
Label2.Caption := rsIpHTMLPreviewOf;
btnSelectPrinter.Caption := rsIpHTMLPreviewSelectPrinter
end;
procedure TIpHTMLPreview.SetZoom(const Value: Integer);
var
Scale1, Scale2, Scale0: double;
{$IFDEF IP_LAZARUS}
ClientHeightDbl, ClientWidthDbl: double;
{$ENDIF}
begin
FZoom := Value;
{$IFDEF IP_LAZARUS}
ClientHeightDbl := ClientHeight;
ClientWidthDbl := ClientWidth;
if Printer.PageHeight>0 then
Scale1 := ClientHeightDbl/Printer.PageHeight
else
Scale1 := ClientHeightDbl/500;
if Printer.PageWidth>0 then
Scale2 := ClientWidthDbl/ Printer.PageWidth
else
Scale2 := ClientWidthDbl/ 500;
{$ELSE}
Scale1 := ClientHeight/ Printer.PageHeight; //JMN
Scale2 := ClientWidth/ Printer.PageWidth; //JMN
{$ENDIF}
if Scale1 < Scale2 then
Scale0 := Scale1
else
Scale0 := Scale2;
FScale := Scale0 * FZoom / 100;
ResizeCanvas;
AlignPaintBox;
CR := Rect(0, 0, OwnerPanel.PrintWidth, 0);
CR.Top := (PageNo - 1) * OwnerPanel.PrintHeight;
CR.Bottom := Cr.Top + OwnerPanel.PrintHeight;
PageRect := CR;
PaintBox1.Invalidate;
end;
procedure TIpHTMLPreview.ResizeCanvas;
@ -357,22 +364,72 @@ begin
AlignPaintBox;
end;
procedure TIpHTMLPreview.AlignPaintBox;
procedure TIpHTMLPreview.ScaleSourceRect;
begin
if PaperPanel.Width < ClientWidth then
PaperPanel.Left := ClientWidth div 2 - (PaperPanel.Width div 2)
else
PaperPanel.Left := 0;
if PaperPanel.Height < ClientHeight then
PaperPanel.Top := ClientHeight div 2 - (PaperPanel.Height div 2)
else
PaperPanel.Top := 0;
SourceRect.Left := round(SourceRect.Left / Scale);
SourceRect.Top := round(SourceRect.Top / Scale);
SourceRect.Right := round(SourceRect.Right / Scale);
SourceRect.Bottom := round(SourceRect.Bottom / Scale);
end;
procedure TIpHTMLPreview.FormResize(Sender: TObject);
procedure TIpHTMLPreview.SetCurPage(const Value: Integer);
begin
if OwnerPanel<>nil then
SetZoom(Zoom); {force recalc of preview sizes}
if (Value <> FCurPage)
and (Value >= 1)
and (Value <= OwnerPanel.PageCount) then begin
FCurPage := Value;
RenderPage(Value);
edtPage.Text := IntToStr(CurPage);
UpdateBtnStates;
end;
end;
procedure TIpHTMLPreview.SetZoom(const Value: Integer);
var
ClientHeightDbl, ClientWidthDbl: Double;
PrnPgHeight, PrnPgWidth: Double;
scaleW, scaleH: Integer;
sb: Integer;
begin
FZoomToFit := Value;
// Available client area in inches, without scrollbars
sb := GetSystemMetrics(SM_CXHSCROLL);
ClientHeightDbl := (ClientHeight - sb - ToolbarPanel.Height) / ScreenInfo.PixelsPerInchY;
sb := GetSystemMetrics(SM_CXVSCROLL);
ClientWidthDbl := (ClientWidth - sb)/ ScreenInfo.PixelsPerInchX;
// Printer page size in inches
PrnPgHeight := Printer.PageHeight / Printer.YDpi;
PrnPgWidth := Printer.PageWidth / Printer.XDpi;
case Value of
ZOOM_TO_FIT:
begin
scaleW := round(ClientWidthDbl / PrnPgWidth * 100);
scaleH := round(ClientHeightDbl / PrnPgHeight * 100);
if scaleW < scaleH then FZoom := scaleW else FZoom := scaleH;
end;
ZOOM_TO_FIT_WIDTH:
FZoom := round(ClientWidthDbl / PrnPgWidth * 100);
ZOOM_TO_FIT_HEIGHT:
FZoom := round(ClientHeightDbl / PrnPgHeight * 100);
else
FZoom := Value;
end;
inc(FLockZoomUpdate);
edtZoom.Value := FZoom;
dec(FLockZoomUpdate);
FScale := ScreenInfo.PixelsPerInchX / Printer.XDpi * FZoom * 0.01;
ResizeCanvas;
end;
procedure TIpHtmlPreview.UpdateBtnStates;
begin
btnFirst.Enabled := (FCurPage > 1);
btnPrev.Enabled := (FCurPage > 1);
btnNext.Enabled := (FCurPage < OwnerPanel.PageCount);
btnLast.Enabled := (FCurPage < OwnerPanel.PageCount);
end;
end.

View File

@ -15,6 +15,18 @@ msgstr ""
msgid "Close"
msgstr "Fermer"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "de"
@ -38,3 +50,4 @@ msgstr "Choisir une imprimante..."
#: iphtmlpv.rsiphtmlpreviewzoom
msgid "Zoom:"
msgstr "Zoom :"

View File

@ -15,6 +15,18 @@ msgstr ""
msgid "Close"
msgstr "Bezárás"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "/"
@ -38,3 +50,4 @@ msgstr "Nyomtató választása..."
#: iphtmlpv.rsiphtmlpreviewzoom
msgid "Zoom:"
msgstr "Nagyítás:"

View File

@ -16,6 +16,18 @@ msgstr ""
msgid "Close"
msgstr "Chiudi"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "di"

View File

@ -1,4 +1,3 @@
Valdas Jankunas <zmuogs@gmail.com>, 2012.
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
@ -16,6 +15,18 @@ msgstr ""
msgid "Close"
msgstr "Užverti"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "iš"

View File

@ -5,6 +5,18 @@ msgstr "Content-Type: text/plain; charset=UTF-8"
msgid "Close"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr ""

View File

@ -13,6 +13,18 @@ msgstr ""
msgid "Close"
msgstr "Fechar"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "de"

View File

@ -13,6 +13,18 @@ msgstr ""
msgid "Close"
msgstr "Закрыть"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "из"

View File

@ -1,4 +1,3 @@
Igor Paliychuk <mansonigor@gmail.com>, 2012.
msgid ""
msgstr ""
"Project-Id-Version: \n"
@ -17,6 +16,18 @@ msgstr ""
msgid "Close"
msgstr "Закрити"
#: iphtmlpv.rsiphtmlpreviewfitall
msgid "Fit all"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitheight
msgid "Height"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewfitwidth
msgid "Width"
msgstr ""
#: iphtmlpv.rsiphtmlpreviewof
msgid "of"
msgstr "з"