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

View File

@@ -23,6 +23,7 @@ type
btnVisualize: TButton; btnVisualize: TButton;
Button1: TButton; Button1: TButton;
Button2: TButton; Button2: TButton;
buttonAutoFit: TButton;
buttonPrint: TButton; buttonPrint: TButton;
buttonAdjust: TButton; buttonAdjust: TButton;
buttonViewDebugInfo: TButton; buttonViewDebugInfo: TButton;
@@ -54,6 +55,7 @@ type
procedure Button1Click(Sender: TObject); procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject); procedure Button2Click(Sender: TObject);
procedure buttonAdjustClick(Sender: TObject); procedure buttonAdjustClick(Sender: TObject);
procedure buttonAutoFitClick(Sender: TObject);
procedure buttonPrintClick(Sender: TObject); procedure buttonPrintClick(Sender: TObject);
procedure buttonRenderingTestClick(Sender: TObject); procedure buttonRenderingTestClick(Sender: TObject);
procedure buttonViewDebugInfoClick(Sender: TObject); procedure buttonViewDebugInfoClick(Sender: TObject);
@@ -96,44 +98,24 @@ const
FPVVIEWER_MIN_IMAGE_SIZE = 100; FPVVIEWER_MIN_IMAGE_SIZE = 100;
FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100; FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100;
var var
Vec: TvVectorialDocument;
CanvasSize: TPoint; CanvasSize: TPoint;
lCurPage: TvVectorialPage; lCurPage: TvVectorialPage;
lPage: TvPage; lPage: TvPage;
YAxisMultiplier: Double = -1; YAxisMultiplier: Double = -1;
begin begin
// First check the in input Render_PrepareFile();
if editFileName.FileName = '' then Exit; // silent exit in this simple case
//if not CheckInput() then Exit;
notebook.PageIndex := 0;
Vec := TvVectorialDocument.Create;
try 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 // 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 // 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 // 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 if FVec.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 if FVec.Width < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.X := Drawer.Width
else CanvasSize.X := Round(Vec.Width * spinScale.Value); else CanvasSize.X := Round(FVec.Width * spinScale.Value);
if CanvasSize.X < Drawer.Width then CanvasSize.X := Drawer.Width; 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 if FVec.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 if FVec.Height < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.Y := Drawer.Height
else CanvasSize.Y := Round(Vec.Height * spinScale.Value); else CanvasSize.Y := Round(FVec.Height * spinScale.Value);
if CanvasSize.Y < Drawer.Height then CanvasSize.Y := Drawer.Height; if CanvasSize.Y < Drawer.Height then CanvasSize.Y := Drawer.Height;
Drawer.Drawing.Width := CanvasSize.X; Drawer.Drawing.Width := CanvasSize.X;
@@ -141,7 +123,7 @@ begin
Drawer.Drawing.Canvas.Brush.Color := clWhite; Drawer.Drawing.Canvas.Brush.Color := clWhite;
Drawer.Drawing.Canvas.Brush.Style := bsSolid; Drawer.Drawing.Canvas.Brush.Style := bsSolid;
Drawer.Drawing.Canvas.FillRect(0, 0, Drawer.Drawing.Width, Drawer.Drawing.Height); Drawer.Drawing.Canvas.FillRect(0, 0, Drawer.Drawing.Width, Drawer.Drawing.Height);
lPage := Vec.GetPage(0); lPage := FVec.GetPage(0);
if lPage = nil then if lPage = nil then
Exception.Create('The document has no pages'); Exception.Create('The document has no pages');
if lPage is TvTextPageSequence then YAxisMultiplier := 1.0; if lPage is TvTextPageSequence then YAxisMultiplier := 1.0;
@@ -165,9 +147,9 @@ begin
// Show debug tokens // Show debug tokens
TokensTreeView.Items.Clear; TokensTreeView.Items.Clear;
Vec.GenerateDebugTree(@FPVDebugAddItemProc); FVec.GenerateDebugTree(@FPVDebugAddItemProc);
finally finally
Vec.Free; Render_FreeFile();
end; end;
end; end;
@@ -388,6 +370,26 @@ begin
end; end;
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); procedure TfrmFPVViewer.buttonPrintClick(Sender: TObject);
var var
printDialog: TPrintDialog; printDialog: TPrintDialog;
@@ -579,6 +581,13 @@ begin
else FVec.ForcedEncodingOnRead := ''; else FVec.ForcedEncodingOnRead := '';
FVec.ReadFromFile(editFileName.FileName); 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; end;
procedure TfrmFPVViewer.Render_DoRender(ACanvasSizeX, ACanvasSizeY, procedure TfrmFPVViewer.Render_DoRender(ACanvasSizeX, ACanvasSizeY,
@@ -588,9 +597,6 @@ const
FPVVIEWER_MIN_IMAGE_SIZE = 100; FPVVIEWER_MIN_IMAGE_SIZE = 100;
FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100; FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS = 100;
begin begin
// Show document properties
labelFileEncoding.Caption := 'File encoding: ' + FVec.Encoding;
Drawer.Drawing.Width := ACanvasSizeX; Drawer.Drawing.Width := ACanvasSizeX;
Drawer.Drawing.Height := ACanvasSizeY; Drawer.Drawing.Height := ACanvasSizeY;
Drawer.Drawing.Canvas.Brush.Color := clWhite; Drawer.Drawing.Canvas.Brush.Color := clWhite;

View File

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