Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Release NAPS2

on:
push:
tags:
- 'v*' # Triggers the workflow when you push a tag starting with 'v' (e.g., v1.0.0-custom)

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Build Windows (exe, zip)
if: matrix.os == 'windows-latest'
run: |
dotnet run --project NAPS2.Tools -- pkg exe
dotnet run --project NAPS2.Tools -- pkg zip

- name: Build Linux (deb, rpm)
if: matrix.os == 'ubuntu-latest'
run: |
dotnet run --project NAPS2.Tools -- pkg deb -p linux
dotnet run --project NAPS2.Tools -- pkg rpm -p linux

- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
**/*.exe
**/*.zip
**/*.deb
**/*.rpm
**/*.pkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<CheckEolWorkloads>false</CheckEolWorkloads>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions NAPS2.Lib.Tests/Automation/CommandLineIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,31 @@ await _automationHelper.RunCommand(
AssertRecoveryCleanedUp();
}

[Fact]
public async Task ScanPdfSettings_OcrFromPdfSettings()
{
SetUpFakeOcr(new()
{
{ LoadImage(ImageResources.ocr_test), "ADVERTISEMENT." }
});
var path = $"{FolderPath}/test.pdf";
await _automationHelper.WithContainer(container =>
{
var config = container.Resolve<Naps2Config>();
config.User.Set(c => c.OcrLanguageCode, "eng");
config.User.Set(c => c.PdfSettings.Ocr, true);
config.User.Set(c => c.EnableOcr, false);
}).RunCommand(
new AutomatedScanningOptions
{
OutputPath = path,
Verbose = true
},
ImageResources.ocr_test);
PdfAsserts.AssertContainsTextOnce("ADVERTISEMENT.", path);
AssertRecoveryCleanedUp();
}

[Fact]
public async Task ScanPdfSettings_DefaultMetadata()
{
Expand Down
74 changes: 74 additions & 0 deletions NAPS2.Lib.Tests/Images/SaveImagesOperationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using NAPS2.Images;
using NAPS2.ImportExport;
using NAPS2.ImportExport.Images;
using NAPS2.Sdk.Tests;
using NAPS2.Util;
using NSubstitute;
using Xunit;

namespace NAPS2.Lib.Tests.Images;

public class SaveImagesOperationTests : ContextualTests
{
[Fact]
public async Task SaveWithResolutionScale50Percent()
{
var overwritePrompt = Substitute.For<IOverwritePrompt>();
var operation = new SaveImagesOperation(overwritePrompt, ImageContext);

var original = CreateScannedImage();
var originalImage = original.Render();
int originalWidth = originalImage.Width;
int originalHeight = originalImage.Height;
originalImage.Dispose();

var tempFile = Path.Combine(FolderPath, "scaled.jpg");
var imageSettings = new ImageSettings
{
ResolutionScale = 50,
JpegQuality = 75
};

var started = operation.Start(tempFile, Placeholders.None, new[] { original }, imageSettings);
Assert.True(started);

bool success = await operation.Success;
Assert.True(success);
Assert.True(File.Exists(tempFile));

using var savedImage = ImageContext.Load(tempFile);
Assert.Equal((int)Math.Round(originalWidth * 0.5), savedImage.Width);
Assert.Equal((int)Math.Round(originalHeight * 0.5), savedImage.Height);
}

[Fact]
public async Task SaveWithResolutionScale100Percent()
{
var overwritePrompt = Substitute.For<IOverwritePrompt>();
var operation = new SaveImagesOperation(overwritePrompt, ImageContext);

var original = CreateScannedImage();
var originalImage = original.Render();
int originalWidth = originalImage.Width;
int originalHeight = originalImage.Height;
originalImage.Dispose();

var tempFile = Path.Combine(FolderPath, "unscaled.jpg");
var imageSettings = new ImageSettings
{
ResolutionScale = 100,
JpegQuality = 75
};

var started = operation.Start(tempFile, Placeholders.None, new[] { original }, imageSettings);
Assert.True(started);

bool success = await operation.Success;
Assert.True(success);
Assert.True(File.Exists(tempFile));

using var savedImage = ImageContext.Load(tempFile);
Assert.Equal(originalWidth, savedImage.Width);
Assert.Equal(originalHeight, savedImage.Height);
}
}
7 changes: 5 additions & 2 deletions NAPS2.Lib/Automation/AutomatedScanning.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading;
using System.Threading;
using NAPS2.Dependencies;
using NAPS2.EtoForms;
using NAPS2.ImportExport;
Expand Down Expand Up @@ -191,6 +191,7 @@ private void ConfigureOcr()
{
// Don't use OCR-enabled settings from the GUI if --noprofile is set
_config.Run.Set(c => c.EnableOcr, false);
_config.Run.Set(c => c.PdfSettings.Ocr, false);
}
bool canUseOcr = IsPdfFile(_options.OutputPath) || IsPdfFile(_options.EmailFileName);
if (!canUseOcr)
Expand All @@ -200,16 +201,18 @@ private void ConfigureOcr()
if (_options.DisableOcr)
{
_config.Run.Set(c => c.EnableOcr, false);
_config.Run.Set(c => c.PdfSettings.Ocr, false);
}
else if (_options.EnableOcr || !string.IsNullOrEmpty(_options.OcrLang))
{
_config.Run.Set(c => c.EnableOcr, true);
_config.Run.Set(c => c.PdfSettings.Ocr, true);
}
if (!string.IsNullOrEmpty(_options.OcrLang))
{
_config.Run.Set(c => c.OcrLanguageCode, _options.OcrLang);
}
_ocrParams = _config.DefaultOcrParams();
_ocrParams = _config.DefaultOcrParams(_config.Get(c => c.PdfSettings));
}

private async Task InstallComponents()
Expand Down
8 changes: 5 additions & 3 deletions NAPS2.Lib/Config/ConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using NAPS2.Ocr;
using NAPS2.Ocr;
using NAPS2.Pdf;
using NAPS2.Scan;

namespace NAPS2.Config;

public static class ConfigExtensions
{
public static OcrParams DefaultOcrParams(this Naps2Config config)
public static OcrParams DefaultOcrParams(this Naps2Config config, PdfSettings? pdfSettings = null)
{
if (!config.Get(c => c.EnableOcr))
bool enableOcr = pdfSettings?.Ocr ?? config.Get(c => c.EnableOcr);
if (!enableOcr)
{
return OcrParams.Empty;
}
Expand Down
7 changes: 5 additions & 2 deletions NAPS2.Lib/Config/InternalDefaults.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Immutable;
using System.Collections.Immutable;
using NAPS2.ImportExport;
using NAPS2.ImportExport.Email;
using NAPS2.ImportExport.Email.Oauth;
Expand Down Expand Up @@ -93,14 +93,17 @@ public static CommonConfig GetCommonConfig() =>
Compat = PdfCompat.Default,
DefaultFileName = "",
SkipSavePrompt = false,
SinglePagePdfs = false
SinglePagePdfs = false,
JpegQuality = 75,
ResolutionScale = 100
},
RememberPdfSettings = false,
ImageSettings = new ImageSettings
{
DefaultFileName = "",
SkipSavePrompt = false,
JpegQuality = 75,
ResolutionScale = 100,
SinglePageTiff = false,
TiffCompression = TiffCompression.Auto
},
Expand Down
6 changes: 6 additions & 0 deletions NAPS2.Lib/EtoForms/Layout/EtoLayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ public static LayoutControl NaturalHeight(this LayoutControl control, int height
public static LayoutControl Scale(this LayoutControl control) =>
new LayoutControl(control, scale: true);

public static LayoutElement Scale(this LayoutElement element)
{
element.Scale = true;
return element;
}

public static LayoutControl SpacingAfter(this LayoutControl control, int spacingAfter) =>
new LayoutControl(control, spacingAfter: spacingAfter);

Expand Down
Loading