Merge branch 'previewer' into previewer

This commit is contained in:
Marcin Ziąbek
2022-03-24 00:04:28 +01:00
committed by GitHub
3 changed files with 21 additions and 26 deletions
+12 -12
View File
@@ -23,12 +23,14 @@ class InteractiveCanvas : ICustomDrawOperation
private const float MaxScale = 10f;
private const float PageSpacing = 25f;
private const float SafeZone = 50f;
private const float SafeZone = InnerGradientSize;
public float TotalHeight => Pages.Sum(x => x.Size.Height) + (Pages.Count - 1) * PageSpacing;
public float TotalPagesHeight => Pages.Sum(x => x.Size.Height) + (Pages.Count - 1) * PageSpacing;
public float TotalHeight => TotalPagesHeight + SafeZone * 2 / Scale;
public float MaxWidth => Pages.Any() ? Pages.Max(x => x.Size.Width) : 0;
public float MaxTranslateY => -(Height / 2 - SafeZone) / Scale;
public float MinTranslateY => (Height / 2 - SafeZone) / Scale - TotalHeight;
public float MinTranslateY => (Height / 2 + SafeZone) / Scale - TotalHeight;
public float ScrollPercentY
{
@@ -46,10 +48,8 @@ class InteractiveCanvas : ICustomDrawOperation
{
get
{
if (TotalHeight * Scale < Height)
return 1;
return Math.Clamp(Height / Scale / (MaxTranslateY - MinTranslateY), 0, 1);
var viewPortSize = Height / Scale / TotalHeight;
return Math.Clamp(viewPortSize, 0, 1);
}
}
@@ -63,14 +63,14 @@ class InteractiveCanvas : ICustomDrawOperation
private void LimitTranslate()
{
if (TotalHeight * Scale > Height)
if (TotalPagesHeight * Scale > Height)
{
TranslateY = Math.Min(TranslateY, MaxTranslateY);
TranslateY = Math.Max(TranslateY, MinTranslateY);
}
else
{
TranslateY = -TotalHeight / 2;
TranslateY = -TotalPagesHeight / 2;
}
if (Width / Scale < MaxWidth)
@@ -178,15 +178,15 @@ class InteractiveCanvas : ICustomDrawOperation
#region inner viewport gradient
private const float InnerGradientSize = 24f;
private const int InnerGradientSize = 24;
private static readonly SKColor InnerGradientColor = SKColor.Parse("#666");
private void DrawInnerGradient(SKCanvas canvas)
{
// gamma correction
var colors = Enumerable
.Range(0, 17)
.Select(x => 1f - x / 16f)
.Range(0, InnerGradientSize)
.Select(x => 1f - x / (float) InnerGradientSize)
.Select(x => Math.Pow(x, 2f))
.Select(x => (byte)(x * 255))
.Select(x => InnerGradientColor.WithAlpha(x))
+5 -6
View File
@@ -26,9 +26,9 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
VerticalAlignment="Center" HorizontalAlignment="Center"
TextAlignment="Center" Text="QuestPDF Document Preview" FontSize="14" Foreground="#DFFF" FontWeight="Regular" IsHitTestVisible="False" />
TextAlignment="Center" Text="QuestPDF Previewer" FontSize="14" Foreground="#DFFF" FontWeight="Regular" IsHitTestVisible="False" />
<previewer:PreviewerControl Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
@@ -36,13 +36,12 @@
CurrentScroll="{Binding #Window.CurrentScroll, Mode=TwoWay}"
ScrollViewportSize="{Binding #Window.ScrollViewportSize, Mode=OneWayToSource}"
Pages="{Binding #Window.DocumentRenderer.Pages, Mode=OneWay}" />
<ScrollBar Grid.Row="1" Grid.Column="1"
<ScrollBar Grid.Row="1" Grid.Column="1"
Orientation="Vertical"
AllowAutoHide="False"
Minimum="0" Maximum="1"
IsVisible="{Binding #Window.VerticalScrollbarVisible}"
IsVisible="{Binding #Window.VerticalScrollbarVisible, Mode=OneWay}"
Value="{Binding #Window.CurrentScroll, Mode=TwoWay}"
ViewportSize="{Binding #Window.ScrollViewportSize, Mode=OneWay}"></ScrollBar>
</Grid>
+4 -8
View File
@@ -24,8 +24,7 @@ namespace QuestPDF.Previewer
set => SetValue(DocumentProperty, value);
}
public static readonly StyledProperty<float> CurrentScrollProperty =
AvaloniaProperty.Register<PreviewerWindow, float>(nameof(CurrentScroll));
public static readonly StyledProperty<float> CurrentScrollProperty = AvaloniaProperty.Register<PreviewerWindow, float>(nameof(CurrentScroll));
public float CurrentScroll
{
@@ -33,8 +32,7 @@ namespace QuestPDF.Previewer
set => SetValue(CurrentScrollProperty, value);
}
public static readonly StyledProperty<float> ScrollViewportSizeProperty =
AvaloniaProperty.Register<PreviewerWindow, float>(nameof(ScrollViewportSize));
public static readonly StyledProperty<float> ScrollViewportSizeProperty = AvaloniaProperty.Register<PreviewerWindow, float>(nameof(ScrollViewportSize));
public float ScrollViewportSize
{
@@ -42,8 +40,7 @@ namespace QuestPDF.Previewer
set => SetValue(ScrollViewportSizeProperty, value);
}
public static readonly StyledProperty<bool> VerticalScrollbarVisibleProperty =
AvaloniaProperty.Register<PreviewerWindow, bool>(nameof(VerticalScrollbarVisible));
public static readonly StyledProperty<bool> VerticalScrollbarVisibleProperty = AvaloniaProperty.Register<PreviewerWindow, bool>(nameof(VerticalScrollbarVisible));
public bool VerticalScrollbarVisible
{
@@ -59,9 +56,8 @@ namespace QuestPDF.Previewer
.Subscribe(e => Dispatcher.UIThread.Post(() =>
{
VerticalScrollbarVisible = e.NewValue.Value < 1;
Debug.WriteLine($"Scrollbar visible: {VerticalScrollbarVisible}");
}));
// this.FindControl<Button>("GeneratePdf")
// .Click += (_, _) => _ = PreviewerUtils.SavePdfWithDialog(Document, this);