mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-19 03:37:38 +03:00
parent
72aa8f4397
commit
ac80f4ee8b
@ -21,7 +21,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions
|
||||
{
|
||||
@ -39,7 +39,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Feeder };
|
||||
|
||||
@ -54,7 +54,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF Duplex", "ADF" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF Duplex", "ADF"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Feeder };
|
||||
|
||||
@ -69,7 +69,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Duplex };
|
||||
|
||||
@ -84,7 +84,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Auto };
|
||||
|
||||
@ -99,7 +99,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Auto };
|
||||
|
||||
@ -115,7 +115,7 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE,
|
||||
new[] { "Feeder(left aligned)", "Feeder(left aligned,Duplex)" })
|
||||
["Feeder(left aligned)", "Feeder(left aligned,Duplex)"])
|
||||
});
|
||||
var options = new ScanOptions { PaperSource = PaperSource.Duplex };
|
||||
|
||||
@ -130,8 +130,8 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" }),
|
||||
SaneOption.CreateForTesting(2, SaneOptionNames.SOURCE, new[] { "Flatbed", "ADF", "Duplex" })
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"]),
|
||||
SaneOption.CreateForTesting(2, SaneOptionNames.SOURCE, ["Flatbed", "ADF", "Duplex"])
|
||||
});
|
||||
var options = new ScanOptions
|
||||
{
|
||||
@ -144,6 +144,23 @@ public class SaneScanDriverOptionTests : ContextualTests
|
||||
Assert.Equal("Flatbed", device.GetValue(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetOptions_NoGrayErrorDiffusion()
|
||||
{
|
||||
var device = new DeviceOptionsMock(new[]
|
||||
{
|
||||
SaneOption.CreateForTesting(1, SaneOptionNames.MODE, ["Gray[Error Diffusion]", "True Gray"])
|
||||
});
|
||||
var options = new ScanOptions
|
||||
{
|
||||
BitDepth = BitDepth.Grayscale
|
||||
};
|
||||
|
||||
var optionData = _driver.SetOptions(device, options);
|
||||
|
||||
Assert.Equal("True Gray", optionData.Mode);
|
||||
}
|
||||
|
||||
private class DeviceOptionsMock : ISaneDevice
|
||||
{
|
||||
private readonly IEnumerable<SaneOption> _options;
|
||||
|
@ -55,8 +55,14 @@ internal class SaneOptionController
|
||||
}
|
||||
|
||||
public bool TrySet(string name, SaneOptionMatcher matcher)
|
||||
{
|
||||
return TrySet(name, matcher, out _);
|
||||
}
|
||||
|
||||
public bool TrySet(string name, SaneOptionMatcher matcher, out string? matchedValue)
|
||||
{
|
||||
_logger.LogDebug($"Maybe setting {name}");
|
||||
matchedValue = null;
|
||||
if (!_options.ContainsKey(name))
|
||||
return false;
|
||||
var opt = _options[name];
|
||||
@ -68,6 +74,7 @@ internal class SaneOptionController
|
||||
{
|
||||
if (matcher.Matches(value))
|
||||
{
|
||||
matchedValue = value;
|
||||
_logger.LogDebug($"Setting {name} to {value}");
|
||||
_device.SetOption(opt, value, out var info);
|
||||
if (info.HasFlag(SaneOptionSetInfo.ReloadOptions))
|
||||
|
@ -34,10 +34,12 @@ internal static class SaneOptionMatchers
|
||||
|
||||
public static readonly SaneOptionMatcher BlackAndWhite =
|
||||
new SaneOptionMatcher(SaneOptionTranslations.Lineart, "black and white", "black & white", "black/white");
|
||||
|
||||
|
||||
public static readonly SaneOptionMatcher Grayscale =
|
||||
new SaneOptionMatcher(SaneOptionTranslations.Gray, "gray", "grey");
|
||||
|
||||
new SaneOptionMatcher(SaneOptionTranslations.Gray, "gray", "grey")
|
||||
// Error diffusion isn't "real" grayscale
|
||||
.Exclude(new SaneOptionMatcher([], "Error Diffusion"));
|
||||
|
||||
public static readonly SaneOptionMatcher Color =
|
||||
new SaneOptionMatcher(SaneOptionTranslations.Color, "color", "colour");
|
||||
}
|
@ -397,7 +397,7 @@ internal class SaneScanDriver : IScanDriver
|
||||
BitDepth.Grayscale => SaneOptionMatchers.Grayscale,
|
||||
_ => SaneOptionMatchers.Color
|
||||
};
|
||||
controller.TrySet(SaneOptionNames.MODE, mode);
|
||||
controller.TrySet(SaneOptionNames.MODE, mode, out optionData.Mode);
|
||||
|
||||
SetResolution(options, controller, optionData);
|
||||
|
||||
@ -580,9 +580,10 @@ internal class SaneScanDriver : IScanDriver
|
||||
|
||||
internal class OptionData
|
||||
{
|
||||
public bool IsFeeder { get; set; }
|
||||
public double XRes { get; set; }
|
||||
public double YRes { get; set; }
|
||||
public bool IsFeeder;
|
||||
public double XRes;
|
||||
public double YRes;
|
||||
public string? Mode;
|
||||
}
|
||||
|
||||
// if (options.BitDepth == BitDepth.Color)
|
||||
|
Loading…
Reference in New Issue
Block a user