diff --git a/NAPS2.Sdk/Scan/BitDepthCaps.cs b/NAPS2.Sdk/Scan/BitDepthCaps.cs index 7d7499fd37..b26d1bbcee 100644 --- a/NAPS2.Sdk/Scan/BitDepthCaps.cs +++ b/NAPS2.Sdk/Scan/BitDepthCaps.cs @@ -1,12 +1,14 @@ namespace NAPS2.Scan; -public record BitDepthCaps( - bool SupportsColor, - bool SupportsGrayscale, - bool SupportsBlackAndWhite -) +public class BitDepthCaps { - private BitDepthCaps() : this(false, false, false) + internal BitDepthCaps() { } + + public bool SupportsColor { get; init; } + + public bool SupportsGrayscale { get; init; } + + public bool SupportsBlackAndWhite { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/DpiCaps.cs b/NAPS2.Sdk/Scan/DpiCaps.cs index bfd49cd4d2..142de30af7 100644 --- a/NAPS2.Sdk/Scan/DpiCaps.cs +++ b/NAPS2.Sdk/Scan/DpiCaps.cs @@ -2,14 +2,17 @@ namespace NAPS2.Scan; -public record DpiCaps( - ImmutableList? Values, - int Min, - int Max, - int Step -) +public class DpiCaps { - private DpiCaps() : this(null, 0, 0, 0) + internal DpiCaps() { } + + public ImmutableList? Values { get; init; } + + public int Min { get; init; } + + public int Max { get; init; } + + public int Step { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/Internal/Twain/LocalTwainController.cs b/NAPS2.Sdk/Scan/Internal/Twain/LocalTwainController.cs index 43e81d65aa..ecc4b8566a 100644 --- a/NAPS2.Sdk/Scan/Internal/Twain/LocalTwainController.cs +++ b/NAPS2.Sdk/Scan/Internal/Twain/LocalTwainController.cs @@ -142,19 +142,27 @@ private List InternalGetDeviceList(ScanOptions options) bool supportsDuplex = supportsFeeder && ds.Capabilities.CapDuplex.GetCurrent() != Duplex.None; - return new ScanCaps( - new MetadataCaps( - Manufacturer: ds.Manufacturer, - Model: ds.Name, - SerialNumber: ds.Capabilities.CapSerialNumber.GetCurrent() - ), - new PaperSourceCaps(supportsFlatbed, supportsFeeder, supportsDuplex, - ds.Capabilities.CapAutomaticSenseMedium.IsSupported || - ds.Capabilities.CapFeederLoaded.IsSupported), - flatbedCaps, - feederCaps, - supportsDuplex ? feederCaps : null - ); + return new ScanCaps + { + MetadataCaps = new MetadataCaps + { + Manufacturer = ds.Manufacturer, + Model = ds.Name, + SerialNumber = ds.Capabilities.CapSerialNumber.GetCurrent() + }, + PaperSourceCaps = new PaperSourceCaps + { + SupportsFlatbed = supportsFlatbed, + SupportsFeeder = supportsFeeder, + SupportsDuplex = supportsDuplex, + CanCheckIfFeederHasPaper = + ds.Capabilities.CapAutomaticSenseMedium.IsSupported || + ds.Capabilities.CapFeederLoaded.IsSupported + }, + FlatbedCaps = flatbedCaps, + FeederCaps = feederCaps, + DuplexCaps = supportsDuplex ? feederCaps : null + }; } finally { @@ -184,20 +192,27 @@ private PerSourceCaps GetPerSourceCaps(DataSource ds) { var xRes = ds.Capabilities.ICapXResolution.GetValues().Select(x => (int) x.Whole); var yRes = ds.Capabilities.ICapYResolution.GetValues().Select(x => (int) x.Whole); - var dpiCaps = new DpiCaps(xRes.Intersect(yRes).ToImmutableList(), 0, 0, 0); + var dpiCaps = new DpiCaps { Values = xRes.Intersect(yRes).ToImmutableList() }; var pixelTypes = ds.Capabilities.ICapPixelType.GetValues().ToList(); - var bitDepthCaps = new BitDepthCaps( - pixelTypes.Contains(PixelType.RGB), - pixelTypes.Contains(PixelType.Gray), - pixelTypes.Contains(PixelType.BlackWhite)); + var bitDepthCaps = new BitDepthCaps + { + SupportsColor = pixelTypes.Contains(PixelType.RGB), + SupportsGrayscale = pixelTypes.Contains(PixelType.Gray), + SupportsBlackAndWhite = pixelTypes.Contains(PixelType.BlackWhite) + }; var w = ds.Capabilities.ICapPhysicalWidth.GetCurrent(); var h = ds.Capabilities.ICapPhysicalHeight.GetCurrent(); - var scanAreaSize = new PageSize( + var scanArea = new PageSize( decimal.Round(w.Whole + w.Fraction / 65536m, 4), decimal.Round(h.Whole + h.Fraction / 65536m, 4), PageSizeUnit.Inch); - var pageSizeCaps = new PageSizeCaps(scanAreaSize); - return new PerSourceCaps(dpiCaps, bitDepthCaps, pageSizeCaps); + var pageSizeCaps = new PageSizeCaps { ScanArea = scanArea }; + return new PerSourceCaps + { + DpiCaps = dpiCaps, + BitDepthCaps = bitDepthCaps, + PageSizeCaps = pageSizeCaps + }; } public async Task StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken) diff --git a/NAPS2.Sdk/Scan/Internal/Wia/WiaScanDriver.cs b/NAPS2.Sdk/Scan/Internal/Wia/WiaScanDriver.cs index e0e2a9b006..d16a275165 100644 --- a/NAPS2.Sdk/Scan/Internal/Wia/WiaScanDriver.cs +++ b/NAPS2.Sdk/Scan/Internal/Wia/WiaScanDriver.cs @@ -46,17 +46,24 @@ public Task GetDevices(ScanOptions options, CancellationToken cancelToken, Actio var feeder = items.FirstOrDefault(x => x.Name() == "Feeder"); var flatbedCaps = flatbed != null ? GetItemCaps(device, flatbed, true) : null; var feederCaps = feeder != null ? GetItemCaps(device, feeder, false) : null; - return (ScanCaps?) new ScanCaps( - new MetadataCaps( - Manufacturer: device.Properties.GetOrNull(WiaPropertyId.DIP_VEND_DESC)?.Value as string, - Model: device.Properties.GetOrNull(WiaPropertyId.DIP_DEV_DESC)?.Value as string - ), - new PaperSourceCaps(device.SupportsFlatbed(), device.SupportsFeeder(), device.SupportsDuplex(), - true), - device.SupportsFlatbed() ? flatbedCaps : null, - device.SupportsFeeder() ? feederCaps : null, - device.SupportsDuplex() ? feederCaps : null - ); + return (ScanCaps?) new ScanCaps + { + MetadataCaps = new MetadataCaps + { + Manufacturer = device.Properties.GetOrNull(WiaPropertyId.DIP_VEND_DESC)?.Value as string, + Model = device.Properties.GetOrNull(WiaPropertyId.DIP_DEV_DESC)?.Value as string + }, + PaperSourceCaps = new PaperSourceCaps + { + SupportsFlatbed = device.SupportsFlatbed(), + SupportsFeeder = device.SupportsFeeder(), + SupportsDuplex = device.SupportsDuplex(), + CanCheckIfFeederHasPaper = true + }, + FlatbedCaps = device.SupportsFlatbed() ? flatbedCaps : null, + FeederCaps = device.SupportsFeeder() ? feederCaps : null, + DuplexCaps = device.SupportsDuplex() ? feederCaps : null + }; } catch (WiaException e) { @@ -70,27 +77,32 @@ private PerSourceCaps GetItemCaps(WiaDevice device, WiaItem item, bool flatbed) { var xRes = item.Properties.GetOrNull(WiaPropertyId.IPS_XRES); var dpiCaps = xRes != null - ? new DpiCaps( - xRes.Attributes.Values?.Cast().ToImmutableList(), - xRes.Attributes.Min, - xRes.Attributes.Max, - xRes.Attributes.Step) + ? new DpiCaps + { + Values = xRes.Attributes.Values?.Cast().ToImmutableList(), + Min = xRes.Attributes.Min, + Max = xRes.Attributes.Max, + Step = xRes.Attributes.Step + } : null; var dataType = item.Properties.GetOrNull(WiaPropertyId.IPA_DATATYPE); var validDataTypes = dataType?.Attributes.Values; var bitDepthCaps = validDataTypes != null - ? new BitDepthCaps( - validDataTypes.Contains(3), - validDataTypes.Contains(2), - validDataTypes.Contains(0)) + ? new BitDepthCaps + { + SupportsColor = validDataTypes.Contains(3), + SupportsGrayscale = validDataTypes.Contains(2), + SupportsBlackAndWhite = validDataTypes.Contains(0) + } : null; var (horizontalSize, verticalSize) = GetScanArea(device, item, flatbed); - var scanAreaSize = new PageSize(horizontalSize / 1000m, verticalSize / 1000m, PageSizeUnit.Inch); - return new PerSourceCaps( - dpiCaps, - bitDepthCaps, - new PageSizeCaps(scanAreaSize) - ); + var scanArea = new PageSize(horizontalSize / 1000m, verticalSize / 1000m, PageSizeUnit.Inch); + return new PerSourceCaps + { + DpiCaps = dpiCaps, + BitDepthCaps = bitDepthCaps, + PageSizeCaps = new PageSizeCaps { ScanArea = scanArea } + }; } public Task Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, diff --git a/NAPS2.Sdk/Scan/MetadataCaps.cs b/NAPS2.Sdk/Scan/MetadataCaps.cs index 75d67e0c58..70b7bb4e7f 100644 --- a/NAPS2.Sdk/Scan/MetadataCaps.cs +++ b/NAPS2.Sdk/Scan/MetadataCaps.cs @@ -1,15 +1,20 @@ namespace NAPS2.Scan; -public record MetadataCaps( - string? DriverSubtype = null, - string? Manufacturer = null, - string? Model = null, - string? SerialNumber = null, - string? Location = null, - string? IconUri = null -) +public class MetadataCaps { - private MetadataCaps() : this(null, null, null, null, null, null) + internal MetadataCaps() { } + + public string? DriverSubtype { get; init; } + + public string? Manufacturer { get; init; } + + public string? Model { get; init; } + + public string? SerialNumber { get; init; } + + public string? Location { get; init; } + + public string? IconUri { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/PageSizeCaps.cs b/NAPS2.Sdk/Scan/PageSizeCaps.cs index 010b914c2a..6904f65cff 100644 --- a/NAPS2.Sdk/Scan/PageSizeCaps.cs +++ b/NAPS2.Sdk/Scan/PageSizeCaps.cs @@ -1,10 +1,10 @@ namespace NAPS2.Scan; -public record PageSizeCaps( - PageSize ScanAreaSize -) +public class PageSizeCaps { - private PageSizeCaps() : this(new PageSize(0, 0, PageSizeUnit.Inch)) + internal PageSizeCaps() { } + + public PageSize? ScanArea { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/PaperSourceCaps.cs b/NAPS2.Sdk/Scan/PaperSourceCaps.cs index feb4b1881d..23fd62d5e4 100644 --- a/NAPS2.Sdk/Scan/PaperSourceCaps.cs +++ b/NAPS2.Sdk/Scan/PaperSourceCaps.cs @@ -1,13 +1,16 @@ namespace NAPS2.Scan; -public record PaperSourceCaps( - bool SupportsFlatbed, - bool SupportsFeeder, - bool SupportsDuplex, - bool CanCheckIfFeederHasPaper -) +public class PaperSourceCaps { - private PaperSourceCaps() : this(false, false, false, false) + internal PaperSourceCaps() { } + + public bool SupportsFlatbed { get; init; } + + public bool SupportsFeeder { get; init; } + + public bool SupportsDuplex { get; init; } + + public bool CanCheckIfFeederHasPaper { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/PerSourceCaps.cs b/NAPS2.Sdk/Scan/PerSourceCaps.cs index d67bfcec83..0fa6aa88e0 100644 --- a/NAPS2.Sdk/Scan/PerSourceCaps.cs +++ b/NAPS2.Sdk/Scan/PerSourceCaps.cs @@ -1,12 +1,14 @@ namespace NAPS2.Scan; -public record PerSourceCaps( - DpiCaps? DpiCaps, - BitDepthCaps? BitDepthCaps, - PageSizeCaps? PageSizeCaps -) +public class PerSourceCaps { - private PerSourceCaps() : this(null, null, null) + internal PerSourceCaps() { } + + public DpiCaps? DpiCaps { get; init; } + + public BitDepthCaps? BitDepthCaps { get; init; } + + public PageSizeCaps? PageSizeCaps { get; init; } } \ No newline at end of file diff --git a/NAPS2.Sdk/Scan/ScanCaps.cs b/NAPS2.Sdk/Scan/ScanCaps.cs index a81231b47d..4ec0304cfa 100644 --- a/NAPS2.Sdk/Scan/ScanCaps.cs +++ b/NAPS2.Sdk/Scan/ScanCaps.cs @@ -1,14 +1,18 @@ namespace NAPS2.Scan; -public record ScanCaps( - MetadataCaps? MetadataCaps, - PaperSourceCaps? PaperSourceCaps, - PerSourceCaps? FlatbedCaps, - PerSourceCaps? FeederCaps, - PerSourceCaps? DuplexCaps -) +public class ScanCaps { - private ScanCaps() : this(null, null, null, null, null) + internal ScanCaps() { } + + public MetadataCaps? MetadataCaps { get; init; } + + public PaperSourceCaps? PaperSourceCaps { get; init; } + + public PerSourceCaps? FlatbedCaps { get; init; } + + public PerSourceCaps? FeederCaps { get; init; } + + public PerSourceCaps? DuplexCaps { get; init; } } \ No newline at end of file