fpvviewer: Much improves the zoom/position auto-adjustment of documents

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2796 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2013-09-20 13:33:07 +00:00
parent eb04addd7e
commit ef49aac4dc
3 changed files with 24 additions and 21 deletions

View File

@ -8,7 +8,7 @@ object frmFPVViewer: TfrmFPVViewer
ClientWidth = 485 ClientWidth = 485
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
LCLVersion = '1.1' LCLVersion = '1.3'
object notebook: TNotebook object notebook: TNotebook
Left = 0 Left = 0
Height = 424 Height = 424

View File

@ -333,24 +333,25 @@ 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
CanvasSize: TPoint; lSpaceForNegCoords: TPoint;
lCurPage: TvPage;
lZoom: Double;
lCanvasWidth: Integer;
begin begin
Render_PrepareFile(); Render_PrepareFile();
try try
// We need to be robust, because sometimes the document size won't be given lCurPage := FVec.GetPage(0);
// also give up drawing everything if we need more then 4MB of RAM for the image lCurPage.CalculateDocumentSize();
// and also give some space in the image to allow for negative coordinates
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 FVec.Height * spinScale.Value > FPVVIEWER_MAX_IMAGE_SIZE then CanvasSize.Y := FPVVIEWER_MAX_IMAGE_SIZE lCanvasWidth := Drawer.Width;
else if FVec.Height < FPVVIEWER_MIN_IMAGE_SIZE then CanvasSize.Y := Drawer.Height lZoom := (Drawer.Width / lCurPage.Width) * 0.8;
else CanvasSize.Y := Round(FVec.Height * spinScale.Value); spinScale.Value := lZoom;
if CanvasSize.Y < Drawer.Height then CanvasSize.Y := Drawer.Height; // Centralizes the image in the canvas
lSpaceForNegCoords.X := Round(lCurPage.MinX * -1 * lZoom + Drawer.Width * 0.1);
Render_DoRender(Drawer.Width, Drawer.Height, 4, 4, FVec.Width / Drawer.Width); lSpaceForNegCoords.Y := Round(lCurPage.MinY * lZoom - Drawer.Height * 0.1);
spinAdjustX.Value := lSpaceForNegCoords.X - FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS;
spinAdjustY.Value := lSpaceForNegCoords.Y + FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS;
Render_DoRender(Drawer.Width, Drawer.Height, lSpaceForNegCoords.X, lSpaceForNegCoords.Y, lZoom);
finally finally
Render_FreeFile(); Render_FreeFile();
end; end;
@ -559,10 +560,10 @@ begin
FVec.GetPageAsVectorial(0).DrawBackground(Drawer.Drawing.Canvas); FVec.GetPageAsVectorial(0).DrawBackground(Drawer.Drawing.Canvas);
FVec.GetPageAsVectorial(0).Render( FVec.GetPageAsVectorial(0).Render(
Drawer.Drawing.Canvas, Drawer.Drawing.Canvas,
FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS + ADrawerPosX, ADrawerPosX,
Drawer.Drawing.Height - FPVVIEWER_SPACE_FOR_NEGATIVE_COORDS + ADrawerPosY, Drawer.Drawing.Height + ADrawerPosY,
spinScale.Value, AScale,
-1 * spinScale.Value); -1 * AScale);
Drawer.Invalidate; Drawer.Invalidate;
end; end;

View File

@ -1,4 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="9"/> <Version Value="9"/>
@ -61,9 +61,11 @@
</CompilerMessages> </CompilerMessages>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
<LCLWidgetType Value="qt"/>
</CompilerOptions> </CompilerOptions>
</Item3> </Item3>
<SharedMatrixOptions Count="1">
<Item1 ID="669514139583" Modes="qt" Type="IDEMacro" MacroName="LCLWidgetType" Value="qt"/>
</SharedMatrixOptions>
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>