mirror of
https://github.com/soukoku/ntwain.git
synced 2025-10-08 00:14:38 +08:00
Update language encoding after certain calls.
This commit is contained in:
@@ -41,6 +41,8 @@ namespace WinFormSample
|
||||
var caps = twain.GetAllCaps();
|
||||
foreach (var c in caps)
|
||||
listCaps.Items.Add(c);
|
||||
|
||||
var sts = twain.GetCapLabel(CAP.ICAP_XRESOLUTION, out string? test);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -776,9 +776,9 @@ namespace NTwain.Data
|
||||
/// The normal get...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Get()
|
||||
public string Get(Encoding? encoding = null)
|
||||
{
|
||||
return (GetValue(true));
|
||||
return (GetValue(true, encoding));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -786,16 +786,16 @@ namespace NTwain.Data
|
||||
/// that doesn't include the prefix byte...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetNoPrefix()
|
||||
public string GetNoPrefix(Encoding? encoding = null)
|
||||
{
|
||||
return (GetValue(false));
|
||||
return (GetValue(false, encoding));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get our value...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetValue(bool a_blMayHavePrefix)
|
||||
private string GetValue(bool a_blMayHavePrefix, Encoding? encoding = null)
|
||||
{
|
||||
// convert what we have into a byte array
|
||||
byte[] abyItem = new byte[256];
|
||||
@@ -879,7 +879,7 @@ namespace NTwain.Data
|
||||
}
|
||||
|
||||
// change encoding of byte array, then convert the bytes array to a string
|
||||
string sz = Encoding.Unicode.GetString(Encoding.Convert(Language.GetEncoding(), Encoding.Unicode, abyItem));
|
||||
string sz = Encoding.Unicode.GetString(Encoding.Convert(encoding ?? Language.GetEncoding(), Encoding.Unicode, abyItem));
|
||||
|
||||
// If the first character is a NUL, then return the empty string...
|
||||
if (sz[0] == '\0')
|
||||
@@ -2482,7 +2482,7 @@ namespace NTwain.Data
|
||||
/// Describes the status of a source.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
public struct TW_STATUS
|
||||
public partial struct TW_STATUS
|
||||
{
|
||||
public TWCC ConditionCode;
|
||||
public ushort Data;
|
||||
|
@@ -234,6 +234,14 @@ namespace NTwain.Data
|
||||
//}
|
||||
}
|
||||
|
||||
partial struct TW_STATUS
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return ConditionCode.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A more dotnet-friendly representation of <see cref="TW_ENUMERATION"/>.
|
||||
/// </summary>
|
||||
|
@@ -2,6 +2,8 @@
|
||||
using NTwain.Triplets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
@@ -81,6 +83,7 @@ namespace NTwain
|
||||
|
||||
/// <summary>
|
||||
/// Gets a CAP's help text (description).
|
||||
/// This is not implemented.
|
||||
/// </summary>
|
||||
/// <param name="cap"></param>
|
||||
/// <param name="help"></param>
|
||||
@@ -90,12 +93,18 @@ namespace NTwain
|
||||
help = null;
|
||||
var value = new TW_CAPABILITY(cap);
|
||||
var rc = DGControl.Capability.GetHelp(ref _appIdentity, ref _currentDS, ref value);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
// how to determine the length of this thing???
|
||||
var data = value.ReadOneValue<IntPtr>(this, false);
|
||||
}
|
||||
value.Free(this);
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a CAP's text name label.
|
||||
/// This is not implemented.
|
||||
/// </summary>
|
||||
/// <param name="cap"></param>
|
||||
/// <param name="label"></param>
|
||||
@@ -103,8 +112,13 @@ namespace NTwain
|
||||
public STS GetCapLabel(CAP cap, out string? label)
|
||||
{
|
||||
label = null;
|
||||
var value = new TW_CAPABILITY(cap);
|
||||
var value = new TW_CAPABILITY(cap) { ConType = TWON.ONEVALUE };
|
||||
var rc = DGControl.Capability.GetLabel(ref _appIdentity, ref _currentDS, ref value);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
// how to determine the length of this thing???
|
||||
var data = value.ReadOneValue<IntPtr>(this, false);
|
||||
}
|
||||
value.Free(this);
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
@@ -120,6 +134,11 @@ namespace NTwain
|
||||
labels = null;
|
||||
var value = new TW_CAPABILITY(cap);
|
||||
var rc = DGControl.Capability.GetLabelEnum(ref _appIdentity, ref _currentDS, ref value);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
// spec says they're utf8
|
||||
labels = value.ReadArray<TW_STR255>(this, false).Select(t => t.Get(Encoding.UTF8)).ToArray();
|
||||
}
|
||||
value.Free(this);
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
@@ -133,6 +152,12 @@ namespace NTwain
|
||||
{
|
||||
var rc = DGControl.Capability.Set(ref _appIdentity, ref _currentDS, ref value);
|
||||
value.Free(this);
|
||||
|
||||
if (value.Cap == CAP.CAP_LANGUAGE && rc == TWRC.SUCCESS)
|
||||
{
|
||||
RefreshCapLanguage();
|
||||
}
|
||||
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
|
||||
@@ -158,7 +183,14 @@ namespace NTwain
|
||||
public STS ResetCap(CAP cap, out TW_CAPABILITY value)
|
||||
{
|
||||
value = new TW_CAPABILITY(cap);
|
||||
return WrapInSTS(DGControl.Capability.Reset(ref _appIdentity, ref _currentDS, ref value));
|
||||
var rc = DGControl.Capability.Reset(ref _appIdentity, ref _currentDS, ref value);
|
||||
|
||||
if (value.Cap == CAP.CAP_LANGUAGE && rc == TWRC.SUCCESS)
|
||||
{
|
||||
RefreshCapLanguage();
|
||||
}
|
||||
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,7 +200,24 @@ namespace NTwain
|
||||
public STS ResetAllCaps()
|
||||
{
|
||||
var value = new TW_CAPABILITY(CAP.CAP_SUPPORTEDCAPS);
|
||||
return WrapInSTS(DGControl.Capability.ResetAll(ref _appIdentity, ref _currentDS, ref value));
|
||||
var rc = DGControl.Capability.ResetAll(ref _appIdentity, ref _currentDS, ref value);
|
||||
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
RefreshCapLanguage();
|
||||
}
|
||||
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
|
||||
private void RefreshCapLanguage()
|
||||
{
|
||||
var rc2 = GetCapCurrent(CAP.CAP_LANGUAGE, out TW_CAPABILITY curCap);
|
||||
if (rc2.RC == TWRC.SUCCESS)
|
||||
{
|
||||
var lang = curCap.ReadOneValue<TWLG>(this);
|
||||
Language.Set(lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,6 +49,7 @@ namespace NTwain
|
||||
{
|
||||
State = STATE.S4;
|
||||
RegisterCallback();
|
||||
Language.Set(source.Version.Language);
|
||||
CurrentSource = source;
|
||||
}
|
||||
return WrapInSTS(rc);
|
||||
|
Reference in New Issue
Block a user