fpvviewer: Adds AutoFit button

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4486 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2016-02-05 09:31:50 +00:00
parent aad2fa0dc1
commit 7097939605
3 changed files with 79 additions and 40 deletions

View File

@ -8,7 +8,7 @@ object frmFPVViewer: TfrmFPVViewer
ClientWidth = 485
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '1.5'
LCLVersion = '1.7'
object notebook: TNotebook
Left = 0
Height = 424
@ -82,7 +82,7 @@ object frmFPVViewer: TfrmFPVViewer
TabOrder = 1
object editFileName: TFileNameEdit
Left = 8
Height = 23
Height = 22
Top = 8
Width = 304
DialogOptions = []
@ -270,10 +270,10 @@ object frmFPVViewer: TfrmFPVViewer
TabOrder = 11
end
object buttonViewDebugInfo: TButton
Left = 344
Left = 368
Height = 17
Top = 153
Width = 131
Width = 107
Caption = 'View Debug Info'
OnClick = buttonViewDebugInfoClick
TabOrder = 12
@ -297,12 +297,21 @@ object frmFPVViewer: TfrmFPVViewer
TabOrder = 14
end
object checkShowPage: TCheckBox
Left = 216
Left = 200
Height = 18
Top = 152
Width = 90
Caption = 'Show Page'
TabOrder = 15
end
object buttonAutoFit: TButton
Left = 296
Height = 17
Top = 153
Width = 64
Caption = 'Auto Fit'
OnClick = buttonAutoFitClick
TabOrder = 16
end
end
end

View File

@ -23,6 +23,7 @@ type
btnVisualize: TButton;
Button1: TButton;
Button2: TButton;
buttonAutoFit: TButton;
buttonPrint: TButton;
buttonAdjust: TButton;
buttonViewDebugInfo: TButton;
@ -54,6 +55,7 @@ type
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure buttonAdjustClick(Sender: TObject);
procedure buttonAutoFitClick(Sender: TObject);
procedure buttonPrintClick(Sender: TObject);
procedure buttonRenderingTestClick(Sender: TObject);
procedure buttonViewDebugInfoClick(Sender: TObject);
@ -96,44 +98,24 @@ const
FPVVIEWER_MIN_IMAGE_SIZE = 100;
FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100;
var
Vec: TvVectorialDocument;
CanvasSize: TPoint;
lCurPage: TvVectorialPage;
lPage: TvPage;
YAxisMultiplier: Double = -1;
begin
// First check the in input
if editFileName.FileName = '' then Exit; // silent exit in this simple case
//if not CheckInput() then Exit;
notebook.PageIndex := 0;
Vec := TvVectorialDocument.Create;
Render_PrepareFile();
try
// some formats like HTML need an input of control size to render themselves
Vec.Width := Drawer.Width;
Vec.Height := Drawer.Height;
// If we desire, force a encoding for the read operation
if comboEncoding.ItemIndex > 0 then
Vec.ForcedEncodingOnRead := comboEncoding.Text
else Vec.ForcedEncodingOnRead := '';
Vec.ReadFromFile(editFileName.FileName);
// Show document properties
labelFileEncoding.Caption := 'File encoding: ' + Vec.Encoding;
// We need to be robust, because sometimes the document size won't be given
// also give up drawing everything if we need more then 4MB of RAM for the image
// and also give some space in the image to allow for negative coordinates
if Vec.Width * spinScale.Value > FPVVIEWER_MAX_IMAGE_SIZE then CanvasSize.X := FPVVIEWER_MAX_IMAGE_SIZE
else if Vec.Width < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.X := Drawer.Width
else CanvasSize.X := Round(Vec.Width * spinScale.Value);
if FVec.Width * spinScale.Value > FPVVIEWER_MAX_IMAGE_SIZE then CanvasSize.X := FPVVIEWER_MAX_IMAGE_SIZE
else if FVec.Width < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.X := Drawer.Width
else CanvasSize.X := Round(FVec.Width * spinScale.Value);
if CanvasSize.X < Drawer.Width then CanvasSize.X := Drawer.Width;
if Vec.Height * spinScale.Value > FPVVIEWER_MAX_IMAGE_SIZE then CanvasSize.Y := FPVVIEWER_MAX_IMAGE_SIZE
else if Vec.Height < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.Y := Drawer.Height
else CanvasSize.Y := Round(Vec.Height * spinScale.Value);
if FVec.Height * spinScale.Value > FPVVIEWER_MAX_IMAGE_SIZE then CanvasSize.Y := FPVVIEWER_MAX_IMAGE_SIZE
else if FVec.Height < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.Y := Drawer.Height
else CanvasSize.Y := Round(FVec.Height * spinScale.Value);
if CanvasSize.Y < Drawer.Height then CanvasSize.Y := Drawer.Height;
Drawer.Drawing.Width := CanvasSize.X;
@ -141,7 +123,7 @@ begin
Drawer.Drawing.Canvas.Brush.Color := clWhite;
Drawer.Drawing.Canvas.Brush.Style := bsSolid;
Drawer.Drawing.Canvas.FillRect(0, 0, Drawer.Drawing.Width, Drawer.Drawing.Height);
lPage := Vec.GetPage(0);
lPage := FVec.GetPage(0);
if lPage = nil then
Exception.Create('The document has no pages');
if lPage is TvTextPageSequence then YAxisMultiplier := 1.0;
@ -165,9 +147,9 @@ begin
// Show debug tokens
TokensTreeView.Items.Clear;
Vec.GenerateDebugTree(@FPVDebugAddItemProc);
FVec.GenerateDebugTree(@FPVDebugAddItemProc);
finally
Vec.Free;
Render_FreeFile();
end;
end;
@ -388,6 +370,26 @@ begin
end;
end;
procedure TfrmFPVViewer.buttonAutoFitClick(Sender: TObject);
var
lPage: TvPage;
lDeltaX, lDeltaY: Integer;
lZoom: Double;
begin
Render_PrepareFile();
try
lPage := FVec.GetPage(0);
lPage.AutoFit(Drawer.Drawing.Canvas,
Drawer.Drawing.Width, Drawer.Drawing.Height,
lDeltaX, lDeltaY, lZoom);
spinAdjustX.Value := lDeltaX;
spinAdjustY.Value := lDeltaY;
spinScale.Value := lZoom;
finally
Render_FreeFile();
end;
end;
procedure TfrmFPVViewer.buttonPrintClick(Sender: TObject);
var
printDialog: TPrintDialog;
@ -579,6 +581,13 @@ begin
else FVec.ForcedEncodingOnRead := '';
FVec.ReadFromFile(editFileName.FileName);
// some formats like HTML need an input of control size to render themselves
FVec.Width := Drawer.Width;
FVec.Height := Drawer.Height;
// Show document properties
labelFileEncoding.Caption := 'File encoding: ' + FVec.Encoding;
end;
procedure TfrmFPVViewer.Render_DoRender(ACanvasSizeX, ACanvasSizeY,
@ -588,9 +597,6 @@ const
FPVVIEWER_MIN_IMAGE_SIZE = 100;
FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100;
begin
// Show document properties
labelFileEncoding.Caption := 'File encoding: ' + FVec.Encoding;
Drawer.Drawing.Width := ACanvasSizeX;
Drawer.Drawing.Height := ACanvasSizeY;
Drawer.Drawing.Canvas.Brush.Color := clWhite;

View File

@ -14,7 +14,7 @@
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="4">
<BuildModes Count="5">
<Item1 Name="default" Default="True"/>
<Item2 Name="win32-console">
<CompilerOptions>
@ -65,6 +65,9 @@
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
@ -73,6 +76,28 @@
</Linking>
</CompilerOptions>
</Item4>
<Item5 Name="carbon">
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="fpvviewer"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
</Item5>
<SharedMatrixOptions Count="2">
<Item1 ID="669514139583" Modes="qt" Type="IDEMacro" MacroName="LCLWidgetType" Value="qt"/>
<Item2 ID="166328276776" Modes="cocoa" Type="IDEMacro" MacroName="LCLWidgetType" Value="cocoa"/>
@ -114,7 +139,6 @@
<ComponentName Value="frmFPVViewer"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="fpvv_mainform"/>
</Unit1>
<Unit2>
<Filename Value="dxftokentotree.pas"/>