Test integrating twaincs 2.5.

This commit is contained in:
Eugene Wang 2022-04-24 18:08:43 -04:00
parent 88cf5bd49f
commit 7abf933d4a
25 changed files with 16697 additions and 12753 deletions

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_common", "_common", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
ProjectSection(SolutionItems) = preProject
@ -21,10 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTwain.Win", "src\NTwain.Wi
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_twain-doc", "_twain-doc", "{0C94E5AD-E226-4A30-92B4-C28FE5B7FC23}"
ProjectSection(SolutionItems) = preProject
twain-doc\TWAIN-2.4-Features.pdf = twain-doc\TWAIN-2.4-Features.pdf
twain-doc\TWAIN-2.4-Specification.pdf = twain-doc\TWAIN-2.4-Specification.pdf
twain-doc\twain2.4.h = twain-doc\twain2.4.h
twain-doc\TWAIN_Errata_for_Version_2.4.pdf = twain-doc\TWAIN_Errata_for_Version_2.4.pdf
twain-doc\TWAIN-2.5-Features.pdf = twain-doc\TWAIN-2.5-Features.pdf
twain-doc\TWAIN-2.5-Specification.pdf = twain-doc\TWAIN-2.5-Specification.pdf
twain-doc\twain2.5.h = twain-doc\twain2.5.h
EndProjectSection
EndProject
Global

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Threading;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace Net5Console
{
@ -39,7 +40,7 @@ namespace Net5Console
hold.Set();
};
if (session.Open() == TWAINWorkingGroup.STS.SUCCESS)
if (session.Open() == STS.SUCCESS)
{
Console.WriteLine("Opened DSM");
Console.WriteLine();

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{
@ -41,7 +42,7 @@ namespace NTwain
{
return ValueReader.ReadOneValueContainer<TWQC>(_twain, ref twCap);
}
return TWQC.Uknown;
return TWQC.Unknown;
}
/// <summary>

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

View File

@ -10,6 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.Security.Permissions" Version="6.0.0" />
</ItemGroup>
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

View File

@ -6,6 +6,7 @@ using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static TWAINWorkingGroup.TWAIN;
namespace TWAINWorkingGroup
{
@ -146,313 +147,316 @@ namespace TWAINWorkingGroup
}
}
partial struct TW_FIX32 : IEquatable<TW_FIX32>, IConvertible
partial class TWAIN
{
// the conversion logic is found in the spec.
partial struct TW_FIX32 : IEquatable<TW_FIX32>, IConvertible
{
// the conversion logic is found in the spec.
float ToFloat()
{
return Whole + Frac / 65536f;
}
double ToDouble()
{
return Whole + Frac / 65536.0;
}
public TW_FIX32(double value)
{
Whole = (short)value;
Frac = (ushort)((value - Whole) * 65536.0);
}
public TW_FIX32(float value)
{
//int temp = (int)(value * 65536.0 + 0.5);
//Whole = (short)(temp >> 16);
//Fraction = (ushort)(temp & 0x0000ffff);
// different version from twain faq
bool sign = value < 0;
int temp = (int)(value * 65536.0 + (sign ? (-0.5) : 0.5));
Whole = (short)(temp >> 16);
Frac = (ushort)(temp & 0x0000ffff);
}
public override string ToString()
{
return ToFloat().ToString();
}
public bool Equals(TW_FIX32 other)
{
return Whole == other.Whole && Frac == other.Frac;
}
public override bool Equals(object obj)
{
if (obj is TW_FIX32 other)
float ToFloat()
{
return Equals(other);
return Whole + Frac / 65536f;
}
return false;
}
public override int GetHashCode()
{
return Whole ^ Frac;
}
#region IConvertable
TypeCode IConvertible.GetTypeCode()
{
return TypeCode.Single;
}
bool IConvertible.ToBoolean(IFormatProvider provider)
{
return this != 0;
}
byte IConvertible.ToByte(IFormatProvider provider)
{
return Convert.ToByte((float)this);
}
char IConvertible.ToChar(IFormatProvider provider)
{
return Convert.ToChar((float)this);
}
DateTime IConvertible.ToDateTime(IFormatProvider provider)
{
return Convert.ToDateTime((float)this);
}
decimal IConvertible.ToDecimal(IFormatProvider provider)
{
return Convert.ToDecimal((float)this);
}
double IConvertible.ToDouble(IFormatProvider provider)
{
return Convert.ToDouble((float)this);
}
short IConvertible.ToInt16(IFormatProvider provider)
{
return Convert.ToInt16((float)this);
}
int IConvertible.ToInt32(IFormatProvider provider)
{
return Convert.ToInt32((float)this);
}
long IConvertible.ToInt64(IFormatProvider provider)
{
return Convert.ToInt64((float)this);
}
sbyte IConvertible.ToSByte(IFormatProvider provider)
{
return Convert.ToSByte((float)this);
}
float IConvertible.ToSingle(IFormatProvider provider)
{
return Convert.ToSingle((float)this);
}
string IConvertible.ToString(IFormatProvider provider)
{
return this.ToString();
}
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
{
return Convert.ChangeType((float)this, conversionType, CultureInfo.InvariantCulture);
}
ushort IConvertible.ToUInt16(IFormatProvider provider)
{
return Convert.ToUInt16((float)this);
}
uint IConvertible.ToUInt32(IFormatProvider provider)
{
return Convert.ToUInt32((float)this);
}
ulong IConvertible.ToUInt64(IFormatProvider provider)
{
return Convert.ToUInt64((float)this);
}
#endregion
public static implicit operator float(TW_FIX32 value) => value.ToFloat();
public static implicit operator TW_FIX32(float value) => new TW_FIX32(value);
public static implicit operator double(TW_FIX32 value) => value.ToDouble();
public static implicit operator TW_FIX32(double value) => new TW_FIX32((float)value);
public static bool operator ==(TW_FIX32 value1, TW_FIX32 value2) => value1.Equals(value2);
public static bool operator !=(TW_FIX32 value1, TW_FIX32 value2) => !value1.Equals(value2);
}
partial struct TW_FRAME : IEquatable<TW_FRAME>
{
/// <summary>
/// Creates <see cref="TW_FRAME"/> from a string representation of it.
/// </summary>
/// <param name="value"></param>
public TW_FRAME(string value) : this()
{
var parts = value.Split(',');
if (parts.Length == 4)
double ToDouble()
{
Left = float.Parse(parts[0]);
Top = float.Parse(parts[1]);
Right = float.Parse(parts[2]);
Bottom = float.Parse(parts[3]);
return Whole + Frac / 65536.0;
}
else
public TW_FIX32(double value)
{
throw new ArgumentException($"Cannot create frame from \"{value}\".");
Whole = (short)value;
Frac = (ushort)((value - Whole) * 65536.0);
}
public TW_FIX32(float value)
{
//int temp = (int)(value * 65536.0 + 0.5);
//Whole = (short)(temp >> 16);
//Fraction = (ushort)(temp & 0x0000ffff);
// different version from twain faq
bool sign = value < 0;
int temp = (int)(value * 65536.0 + (sign ? (-0.5) : 0.5));
Whole = (short)(temp >> 16);
Frac = (ushort)(temp & 0x0000ffff);
}
public override string ToString()
{
return ToFloat().ToString();
}
public bool Equals(TW_FIX32 other)
{
return Whole == other.Whole && Frac == other.Frac;
}
public override bool Equals(object obj)
{
if (obj is TW_FIX32 other)
{
return Equals(other);
}
return false;
}
public override int GetHashCode()
{
return Whole ^ Frac;
}
#region IConvertable
TypeCode IConvertible.GetTypeCode()
{
return TypeCode.Single;
}
bool IConvertible.ToBoolean(IFormatProvider provider)
{
return this != 0;
}
byte IConvertible.ToByte(IFormatProvider provider)
{
return Convert.ToByte((float)this);
}
char IConvertible.ToChar(IFormatProvider provider)
{
return Convert.ToChar((float)this);
}
DateTime IConvertible.ToDateTime(IFormatProvider provider)
{
return Convert.ToDateTime((float)this);
}
decimal IConvertible.ToDecimal(IFormatProvider provider)
{
return Convert.ToDecimal((float)this);
}
double IConvertible.ToDouble(IFormatProvider provider)
{
return Convert.ToDouble((float)this);
}
short IConvertible.ToInt16(IFormatProvider provider)
{
return Convert.ToInt16((float)this);
}
int IConvertible.ToInt32(IFormatProvider provider)
{
return Convert.ToInt32((float)this);
}
long IConvertible.ToInt64(IFormatProvider provider)
{
return Convert.ToInt64((float)this);
}
sbyte IConvertible.ToSByte(IFormatProvider provider)
{
return Convert.ToSByte((float)this);
}
float IConvertible.ToSingle(IFormatProvider provider)
{
return Convert.ToSingle((float)this);
}
string IConvertible.ToString(IFormatProvider provider)
{
return this.ToString();
}
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
{
return Convert.ChangeType((float)this, conversionType, CultureInfo.InvariantCulture);
}
ushort IConvertible.ToUInt16(IFormatProvider provider)
{
return Convert.ToUInt16((float)this);
}
uint IConvertible.ToUInt32(IFormatProvider provider)
{
return Convert.ToUInt32((float)this);
}
ulong IConvertible.ToUInt64(IFormatProvider provider)
{
return Convert.ToUInt64((float)this);
}
#endregion
public static implicit operator float(TW_FIX32 value) => value.ToFloat();
public static implicit operator TW_FIX32(float value) => new TW_FIX32(value);
public static implicit operator double(TW_FIX32 value) => value.ToDouble();
public static implicit operator TW_FIX32(double value) => new TW_FIX32((float)value);
public static bool operator ==(TW_FIX32 value1, TW_FIX32 value2) => value1.Equals(value2);
public static bool operator !=(TW_FIX32 value1, TW_FIX32 value2) => !value1.Equals(value2);
}
partial struct TW_FRAME : IEquatable<TW_FRAME>
{
/// <summary>
/// Creates <see cref="TW_FRAME"/> from a string representation of it.
/// </summary>
/// <param name="value"></param>
public TW_FRAME(string value) : this()
{
var parts = value.Split(',');
if (parts.Length == 4)
{
Left = float.Parse(parts[0]);
Top = float.Parse(parts[1]);
Right = float.Parse(parts[2]);
Bottom = float.Parse(parts[3]);
}
else
{
throw new ArgumentException($"Cannot create frame from \"{value}\".");
}
}
/// <summary>
/// String representation of Left,Top,Right,Bottom.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"{Left},{Top},{Right},{Bottom}";
}
public bool Equals(TW_FRAME other)
{
return Left == other.Left && Top == other.Top &&
Right == other.Right && Bottom == other.Bottom;
}
public override bool Equals(object obj)
{
if (obj is TW_FRAME other)
{
return Equals(other);
}
return false;
}
public override int GetHashCode()
{
return Left.GetHashCode() ^ Top.GetHashCode() ^
Right.GetHashCode() ^ Bottom.GetHashCode();
}
public static bool operator ==(TW_FRAME value1, TW_FRAME value2)
{
return value1.Equals(value2);
}
public static bool operator !=(TW_FRAME value1, TW_FRAME value2)
{
return !value1.Equals(value2);
}
}
/// <summary>
/// String representation of Left,Top,Right,Bottom.
/// </summary>
/// <returns></returns>
public override string ToString()
partial struct TW_STR32
{
return $"{Left},{Top},{Right},{Bottom}";
}
public const int Size = 34;
public bool Equals(TW_FRAME other)
{
return Left == other.Left && Top == other.Top &&
Right == other.Right && Bottom == other.Bottom;
}
public override bool Equals(object obj)
{
if (obj is TW_FRAME other)
public TW_STR32(string value) : this()
{
return Equals(other);
Set(value);
}
return false;
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR32 value) => value.ToString();
public static explicit operator TW_STR32(string value) => new TW_STR32(value);
}
public override int GetHashCode()
partial struct TW_STR64
{
return Left.GetHashCode() ^ Top.GetHashCode() ^
Right.GetHashCode() ^ Bottom.GetHashCode();
public const int Size = 66;
public TW_STR64(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR64 value) => value.ToString();
public static explicit operator TW_STR64(string value) => new TW_STR64(value);
}
public static bool operator ==(TW_FRAME value1, TW_FRAME value2)
partial struct TW_STR128
{
return value1.Equals(value2);
public const int Size = 130;
public TW_STR128(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR128 value) => value.ToString();
public static explicit operator TW_STR128(string value) => new TW_STR128(value);
}
public static bool operator !=(TW_FRAME value1, TW_FRAME value2)
partial struct TW_STR255
{
return !value1.Equals(value2);
public const int Size = 256;
public TW_STR255(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR255 value) => value.ToString();
public static explicit operator TW_STR255(string value) => new TW_STR255(value);
}
}
partial struct TW_STR32
{
public const int Size = 34;
public TW_STR32(string value) : this()
partial struct TW_IDENTITY
{
Set(value);
public override string ToString()
{
return $"{Manufacturer} - {ProductName} {Version} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
}
}
public override string ToString()
partial struct TW_VERSION
{
return Get();
public override string ToString()
{
return $"{MajorNum}.{MinorNum}";
}
}
public static implicit operator string(TW_STR32 value) => value.ToString();
public static explicit operator TW_STR32(string value) => new TW_STR32(value);
}
partial struct TW_STR64
{
public const int Size = 66;
public TW_STR64(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR64 value) => value.ToString();
public static explicit operator TW_STR64(string value) => new TW_STR64(value);
}
partial struct TW_STR128
{
public const int Size = 130;
public TW_STR128(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR128 value) => value.ToString();
public static explicit operator TW_STR128(string value) => new TW_STR128(value);
}
partial struct TW_STR255
{
public const int Size = 256;
public TW_STR255(string value) : this()
{
Set(value);
}
public override string ToString()
{
return Get();
}
public static implicit operator string(TW_STR255 value) => value.ToString();
public static explicit operator TW_STR255(string value) => new TW_STR255(value);
}
partial struct TW_IDENTITY
{
public override string ToString()
{
return $"{Manufacturer} - {ProductName} {Version} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
}
}
partial struct TW_VERSION
{
public override string ToString()
{
return $"{MajorNum}.{MinorNum}";
}
}
partial struct TW_DEVICEEVENT
{
public TWDE Event { get { return (TWDE)_event; } }
public TWFL FlashUsed2 { get { return (TWFL)_flashUsed2; } }
//partial struct TW_DEVICEEVENT
//{
// public TWDE Event { get { return (TWDE)_event; } }
// public TWFL FlashUsed2 { get { return (TWFL)_flashUsed2; } }
//}
}
}

View File

@ -1,217 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////////
//
// TwainWorkingGroup.TWAIN
//
// This is a wrapper class for basic TWAIN functionality. It establishes
// behavior that every application should adhere to. It also hides OS
// specific details, so that toolkits or applications can use one unified
// interface to TWAIN.
//
///////////////////////////////////////////////////////////////////////////////////////
// Author Date TWAIN Comment
// M.McLaughlin 13-Mar-2019 2.4.0.3 Add language code page support for strings
// M.McLaughlin 13-Nov-2015 2.4.0.0 Updated to latest spec
// M.McLaughlin 13-Sep-2015 2.3.1.2 DsmMem bug fixes
// M.McLaughlin 26-Aug-2015 2.3.1.1 Log fix and sync with TWAIN Direct
// M.McLaughlin 13-Mar-2015 2.3.1.0 Numerous fixes
// M.McLaughlin 13-Oct-2014 2.3.0.4 Added logging
// M.McLaughlin 24-Jun-2014 2.3.0.3 Stability fixes
// M.McLaughlin 21-May-2014 2.3.0.2 64-Bit Linux
// M.McLaughlin 27-Feb-2014 2.3.0.1 AnyCPU support
// M.McLaughlin 21-Oct-2013 2.3.0.0 Initial Release
///////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Kodak Alaris Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////
using System;
namespace TWAINWorkingGroup
{
/// <summary>
/// A quick and dirty CSV reader/writer...
/// </summary>
public class CSV
{
///////////////////////////////////////////////////////////////////////////////
// Public Functions...
///////////////////////////////////////////////////////////////////////////////
#region Public Functions...
/// <summary>
/// Start with an empty string...
/// </summary>
public CSV()
{
m_szCsv = "";
}
/// <summary>
/// Add an item to a CSV string...
/// </summary>
/// <param name="a_szItem">Something to add to the CSV string</param>
public void Add(string a_szItem)
{
// If the item has commas, we need to do work...
if (a_szItem.Contains(","))
{
// If the item has quotes, replace them with paired quotes, then
// quote it and add it...
if (a_szItem.Contains("\""))
{
m_szCsv += ((m_szCsv != "") ? "," : "") + "\"" + a_szItem.Replace("\"", "\"\"") + "\"";
}
// Otherwise, just quote it and add it...
else
{
m_szCsv += ((m_szCsv != "") ? "," : "") + "\"" + a_szItem + "\"";
}
}
// If the item has quotes, replace them with escaped quotes, then
// quote it and add it...
else if (a_szItem.Contains("\""))
{
m_szCsv += ((m_szCsv != "") ? "," : "") + "\"" + a_szItem.Replace("\"", "\"\"") + "\"";
}
// Otherwise, just add it...
else
{
m_szCsv += ((m_szCsv != "") ? "," : "") + a_szItem;
}
}
/// <summary>
/// Clear the record...
/// </summary>
public void Clear()
{
m_szCsv = "";
}
/// <summary>
/// Get the current CSV string...
/// </summary>
/// <returns>The current value of the CSV string</returns>
public string Get()
{
return (m_szCsv);
}
/// <summary>
/// Parse a CSV string...
/// </summary>
/// <param name="a_szCsv">A CSV string to parse</param>
/// <returns>An array if items (some can be CSV themselves)</returns>
public static string[] Parse(string a_szCsv)
{
int ii;
bool blEnd;
string[] aszCsv;
string[] aszLeft;
string[] aszRight;
// Validate...
if ((a_szCsv == null) || (a_szCsv == ""))
{
return (new string[] { "" });
}
// If there are no quotes, then parse it fast...
if (!a_szCsv.Contains("\""))
{
return (a_szCsv.Split(new char[] { ',' }));
}
// There's no opening quote, so split and recurse...
if (a_szCsv[0] != '"')
{
aszLeft = new string[] { a_szCsv.Substring(0, a_szCsv.IndexOf(',')) };
aszRight = Parse(a_szCsv.Remove(0, a_szCsv.IndexOf(',') + 1));
aszCsv = new string[aszLeft.Length + aszRight.Length];
aszLeft.CopyTo(aszCsv, 0);
aszRight.CopyTo(aszCsv, aszLeft.Length);
return (aszCsv);
}
// Handle the quoted string...
else
{
// Find the terminating quote...
blEnd = true;
for (ii = 0; ii < a_szCsv.Length; ii++)
{
if (a_szCsv[ii] == '"')
{
blEnd = !blEnd;
}
else if (blEnd && (a_szCsv[ii] == ','))
{
break;
}
}
ii -= 1;
// We have a problem...
if (!blEnd)
{
throw new Exception("Error in CSV string...");
}
// This is the last item, remove any escaped quotes and return it...
if (((ii + 1) >= a_szCsv.Length))
{
return (new string[] { a_szCsv.Substring(1, a_szCsv.Length - 2).Replace("\"\"", "\"") });
}
// We have more data...
if (a_szCsv[ii + 1] == ',')
{
aszLeft = new string[] { a_szCsv.Substring(1, ii - 1).Replace("\"\"", "\"") };
aszRight = Parse(a_szCsv.Remove(0, ii + 2));
aszCsv = new string[aszLeft.Length + aszRight.Length];
aszLeft.CopyTo(aszCsv, 0);
aszRight.CopyTo(aszCsv, aszLeft.Length);
return (aszCsv);
}
// We have a problem...
throw new Exception("Error in CSV string...");
}
}
#endregion
///////////////////////////////////////////////////////////////////////////////
// Private Attributes...
///////////////////////////////////////////////////////////////////////////////
#region Private Attributes...
/// <summary>
/// Our working string for creating or parsing...
/// </summary>
private string m_szCsv;
#endregion
}
}

View File

@ -1,61 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////////
//
// TwainWorkingGroup.TWAIN
//
// These are the definitions for TWAIN. They're essentially the C/C++
// TWAIN.H file contents translated to C#, with modifications that
// recognize the differences between Windows, Linux and Mac OS X.
//
///////////////////////////////////////////////////////////////////////////////////////
// Author Date TWAIN Comment
// M.McLaughlin 13-Mar-2019 2.4.0.3 Add language code page support for strings
// M.McLaughlin 13-Nov-2015 2.4.0.0 Updated to latest spec
// M.McLaughlin 13-Sep-2015 2.3.1.2 DsmMem bug fixes
// M.McLaughlin 26-Aug-2015 2.3.1.1 Log fix and sync with TWAIN Direct
// M.McLaughlin 13-Mar-2015 2.3.1.0 Numerous fixes
// M.McLaughlin 13-Oct-2014 2.3.0.4 Added logging
// M.McLaughlin 24-Jun-2014 2.3.0.3 Stability fixes
// M.McLaughlin 21-May-2014 2.3.0.2 64-Bit Linux
// M.McLaughlin 27-Feb-2014 2.3.0.1 AnyCPU support
// M.McLaughlin 21-Oct-2013 2.3.0.0 Initial Release
///////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Kodak Alaris Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////
namespace TWAINWorkingGroup
{
public static class Consts
{
/// <summary>
/// Don't care values...
/// </summary>
public const byte TWON_DONTCARE8 = 0xff;
public const ushort TWON_DONTCARE16 = 0xff;
public const uint TWON_DONTCARE32 = 0xffffffff;
/// <summary>
/// We're departing from a strict translation of TWAIN.H so that
/// we can achieve a unified status return type.
/// </summary>
public const int STSCC = 0x10000; // get us past the custom space
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,424 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////////
//
// TwainWorkingGroup.TWAIN
//
// This is a wrapper class for basic TWAIN functionality. It establishes
// behavior that every application should adhere to. It also hides OS
// specific details, so that toolkits or applications can use one unified
// interface to TWAIN.
//
///////////////////////////////////////////////////////////////////////////////////////
// Author Date TWAIN Comment
// M.McLaughlin 13-Mar-2019 2.4.0.3 Add language code page support for strings
// M.McLaughlin 13-Nov-2015 2.4.0.0 Updated to latest spec
// M.McLaughlin 13-Sep-2015 2.3.1.2 DsmMem bug fixes
// M.McLaughlin 26-Aug-2015 2.3.1.1 Log fix and sync with TWAIN Direct
// M.McLaughlin 13-Mar-2015 2.3.1.0 Numerous fixes
// M.McLaughlin 13-Oct-2014 2.3.0.4 Added logging
// M.McLaughlin 24-Jun-2014 2.3.0.3 Stability fixes
// M.McLaughlin 21-May-2014 2.3.0.2 64-Bit Linux
// M.McLaughlin 27-Feb-2014 2.3.0.1 AnyCPU support
// M.McLaughlin 21-Oct-2013 2.3.0.0 Initial Release
///////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Kodak Alaris Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace TWAINWorkingGroup
{
/// <summary>
/// The header for a Bitmap file.
/// Needed for supporting DAT.IMAGENATIVEXFER...
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct BITMAPFILEHEADER
{
public ushort bfType;
public uint bfSize;
public ushort bfReserved1;
public ushort bfReserved2;
public uint bfOffBits;
}
/// <summary>
/// The header for a Device Independent Bitmap (DIB).
/// Needed for supporting DAT.IMAGENATIVEXFER...
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
public void Init()
{
biSize = (uint)Marshal.SizeOf(this);
}
}
/// <summary>
/// The TIFF file header.
/// Needed for supporting DAT.IMAGENATIVEXFER...
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TIFFHEADER
{
public ushort u8ByteOrder;
public ushort u16Version;
public uint u32OffsetFirstIFD;
public ushort u16u16IFD;
}
/// <summary>
/// An individual TIFF Tag.
/// Needed for supporting DAT.IMAGENATIVEXFER...
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TIFFTAG
{
public ushort u16Tag;
public ushort u16Type;
public uint u32Count;
public uint u32Value;
}
///////////////////////////////////////////////////////////////////////////////
// Private Definitions (TIFF): this stuff should have been here all along to
// make it easier to share. It's only needed when writing out files from
// DAT_IMAGEMEMXFER data.
///////////////////////////////////////////////////////////////////////////////
// A TIFF header is composed of tags...
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TiffTag
{
public TiffTag(ushort a_u16Tag, ushort a_u16Type, uint a_u32Count, uint a_u32Value)
{
u16Tag = a_u16Tag;
u16Type = a_u16Type;
u32Count = a_u32Count;
u32Value = a_u32Value;
}
public ushort u16Tag;
public ushort u16Type;
public uint u32Count;
public uint u32Value;
}
// TIFF header for Uncompressed BITONAL images...
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TiffBitonalUncompressed
{
// Constructor...
public TiffBitonalUncompressed(uint a_u32Width, uint a_u32Height, uint a_u32Resolution, uint a_u32Size)
{
// Header...
u16ByteOrder = 0x4949;
u16Version = 42;
u32OffsetFirstIFD = 8;
// First IFD...
u16IFD = 16;
// Tags...
tifftagNewSubFileType = new TiffTag(254, 4, 1, 0);
tifftagSubFileType = new TiffTag(255, 3, 1, 1);
tifftagImageWidth = new TiffTag(256, 4, 1, a_u32Width);
tifftagImageLength = new TiffTag(257, 4, 1, a_u32Height);
tifftagBitsPerSample = new TiffTag(258, 3, 1, 1);
tifftagCompression = new TiffTag(259, 3, 1, 1);
tifftagPhotometricInterpretation = new TiffTag(262, 3, 1, 1);
tifftagFillOrder = new TiffTag(266, 3, 1, 1);
tifftagStripOffsets = new TiffTag(273, 4, 1, 222);
tifftagSamplesPerPixel = new TiffTag(277, 3, 1, 1);
tifftagRowsPerStrip = new TiffTag(278, 4, 1, a_u32Height);
tifftagStripByteCounts = new TiffTag(279, 4, 1, a_u32Size);
tifftagXResolution = new TiffTag(282, 5, 1, 206);
tifftagYResolution = new TiffTag(283, 5, 1, 214);
tifftagT4T6Options = new TiffTag(292, 4, 1, 0);
tifftagResolutionUnit = new TiffTag(296, 3, 1, 2);
// Footer...
u32NextIFD = 0;
u64XResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
u64YResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
}
// Header...
public ushort u16ByteOrder;
public ushort u16Version;
public uint u32OffsetFirstIFD;
// First IFD...
public ushort u16IFD;
// Tags...
public TiffTag tifftagNewSubFileType;
public TiffTag tifftagSubFileType;
public TiffTag tifftagImageWidth;
public TiffTag tifftagImageLength;
public TiffTag tifftagBitsPerSample;
public TiffTag tifftagCompression;
public TiffTag tifftagPhotometricInterpretation;
public TiffTag tifftagFillOrder;
public TiffTag tifftagStripOffsets;
public TiffTag tifftagSamplesPerPixel;
public TiffTag tifftagRowsPerStrip;
public TiffTag tifftagStripByteCounts;
public TiffTag tifftagXResolution;
public TiffTag tifftagYResolution;
public TiffTag tifftagT4T6Options;
public TiffTag tifftagResolutionUnit;
// Footer...
public uint u32NextIFD;
public ulong u64XResolution;
public ulong u64YResolution;
}
// TIFF header for Group4 BITONAL images...
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TiffBitonalG4
{
// Constructor...
public TiffBitonalG4(uint a_u32Width, uint a_u32Height, uint a_u32Resolution, uint a_u32Size)
{
// Header...
u16ByteOrder = 0x4949;
u16Version = 42;
u32OffsetFirstIFD = 8;
// First IFD...
u16IFD = 16;
// Tags...
tifftagNewSubFileType = new TiffTag(254, 4, 1, 0);
tifftagSubFileType = new TiffTag(255, 3, 1, 1);
tifftagImageWidth = new TiffTag(256, 4, 1, a_u32Width);
tifftagImageLength = new TiffTag(257, 4, 1, a_u32Height);
tifftagBitsPerSample = new TiffTag(258, 3, 1, 1);
tifftagCompression = new TiffTag(259, 3, 1, 4);
tifftagPhotometricInterpretation = new TiffTag(262, 3, 1, 0);
tifftagFillOrder = new TiffTag(266, 3, 1, 1);
tifftagStripOffsets = new TiffTag(273, 4, 1, 222);
tifftagSamplesPerPixel = new TiffTag(277, 3, 1, 1);
tifftagRowsPerStrip = new TiffTag(278, 4, 1, a_u32Height);
tifftagStripByteCounts = new TiffTag(279, 4, 1, a_u32Size);
tifftagXResolution = new TiffTag(282, 5, 1, 206);
tifftagYResolution = new TiffTag(283, 5, 1, 214);
tifftagT4T6Options = new TiffTag(293, 4, 1, 0);
tifftagResolutionUnit = new TiffTag(296, 3, 1, 2);
// Footer...
u32NextIFD = 0;
u64XResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
u64YResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
}
// Header...
public ushort u16ByteOrder;
public ushort u16Version;
public uint u32OffsetFirstIFD;
// First IFD...
public ushort u16IFD;
// Tags...
public TiffTag tifftagNewSubFileType;
public TiffTag tifftagSubFileType;
public TiffTag tifftagImageWidth;
public TiffTag tifftagImageLength;
public TiffTag tifftagBitsPerSample;
public TiffTag tifftagCompression;
public TiffTag tifftagPhotometricInterpretation;
public TiffTag tifftagFillOrder;
public TiffTag tifftagStripOffsets;
public TiffTag tifftagSamplesPerPixel;
public TiffTag tifftagRowsPerStrip;
public TiffTag tifftagStripByteCounts;
public TiffTag tifftagXResolution;
public TiffTag tifftagYResolution;
public TiffTag tifftagT4T6Options;
public TiffTag tifftagResolutionUnit;
// Footer...
public uint u32NextIFD;
public ulong u64XResolution;
public ulong u64YResolution;
}
// TIFF header for Uncompressed GRAYSCALE images...
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TiffGrayscaleUncompressed
{
// Constructor...
public TiffGrayscaleUncompressed(uint a_u32Width, uint a_u32Height, uint a_u32Resolution, uint a_u32Size)
{
// Header...
u16ByteOrder = 0x4949;
u16Version = 42;
u32OffsetFirstIFD = 8;
// First IFD...
u16IFD = 14;
// Tags...
tifftagNewSubFileType = new TiffTag(254, 4, 1, 0);
tifftagSubFileType = new TiffTag(255, 3, 1, 1);
tifftagImageWidth = new TiffTag(256, 4, 1, a_u32Width);
tifftagImageLength = new TiffTag(257, 4, 1, a_u32Height);
tifftagBitsPerSample = new TiffTag(258, 3, 1, 8);
tifftagCompression = new TiffTag(259, 3, 1, 1);
tifftagPhotometricInterpretation = new TiffTag(262, 3, 1, 1);
tifftagStripOffsets = new TiffTag(273, 4, 1, 198);
tifftagSamplesPerPixel = new TiffTag(277, 3, 1, 1);
tifftagRowsPerStrip = new TiffTag(278, 4, 1, a_u32Height);
tifftagStripByteCounts = new TiffTag(279, 4, 1, a_u32Size);
tifftagXResolution = new TiffTag(282, 5, 1, 182);
tifftagYResolution = new TiffTag(283, 5, 1, 190);
tifftagResolutionUnit = new TiffTag(296, 3, 1, 2);
// Footer...
u32NextIFD = 0;
u64XResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
u64YResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
}
// Header...
public ushort u16ByteOrder;
public ushort u16Version;
public uint u32OffsetFirstIFD;
// First IFD...
public ushort u16IFD;
// Tags...
public TiffTag tifftagNewSubFileType;
public TiffTag tifftagSubFileType;
public TiffTag tifftagImageWidth;
public TiffTag tifftagImageLength;
public TiffTag tifftagBitsPerSample;
public TiffTag tifftagCompression;
public TiffTag tifftagPhotometricInterpretation;
public TiffTag tifftagStripOffsets;
public TiffTag tifftagSamplesPerPixel;
public TiffTag tifftagRowsPerStrip;
public TiffTag tifftagStripByteCounts;
public TiffTag tifftagXResolution;
public TiffTag tifftagYResolution;
public TiffTag tifftagResolutionUnit;
// Footer...
public uint u32NextIFD;
public ulong u64XResolution;
public ulong u64YResolution;
}
// TIFF header for Uncompressed COLOR images...
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TiffColorUncompressed
{
// Constructor...
public TiffColorUncompressed(uint a_u32Width, uint a_u32Height, uint a_u32Resolution, uint a_u32Size)
{
// Header...
u16ByteOrder = 0x4949;
u16Version = 42;
u32OffsetFirstIFD = 8;
// First IFD...
u16IFD = 14;
// Tags...
tifftagNewSubFileType = new TiffTag(254, 4, 1, 0);
tifftagSubFileType = new TiffTag(255, 3, 1, 1);
tifftagImageWidth = new TiffTag(256, 4, 1, a_u32Width);
tifftagImageLength = new TiffTag(257, 4, 1, a_u32Height);
tifftagBitsPerSample = new TiffTag(258, 3, 3, 182);
tifftagCompression = new TiffTag(259, 3, 1, 1);
tifftagPhotometricInterpretation = new TiffTag(262, 3, 1, 2);
tifftagStripOffsets = new TiffTag(273, 4, 1, 204);
tifftagSamplesPerPixel = new TiffTag(277, 3, 1, 3);
tifftagRowsPerStrip = new TiffTag(278, 4, 1, a_u32Height);
tifftagStripByteCounts = new TiffTag(279, 4, 1, a_u32Size);
tifftagXResolution = new TiffTag(282, 5, 1, 188);
tifftagYResolution = new TiffTag(283, 5, 1, 196);
tifftagResolutionUnit = new TiffTag(296, 3, 1, 2);
// Footer...
u32NextIFD = 0;
u16XBitsPerSample1 = 8;
u16XBitsPerSample2 = 8;
u16XBitsPerSample3 = 8;
u64XResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
u64YResolution = (ulong)0x100000000 + (ulong)a_u32Resolution;
}
// Header...
public ushort u16ByteOrder;
public ushort u16Version;
public uint u32OffsetFirstIFD;
// First IFD...
public ushort u16IFD;
// Tags...
public TiffTag tifftagNewSubFileType;
public TiffTag tifftagSubFileType;
public TiffTag tifftagImageWidth;
public TiffTag tifftagImageLength;
public TiffTag tifftagBitsPerSample;
public TiffTag tifftagCompression;
public TiffTag tifftagPhotometricInterpretation;
public TiffTag tifftagStripOffsets;
public TiffTag tifftagSamplesPerPixel;
public TiffTag tifftagRowsPerStrip;
public TiffTag tifftagStripByteCounts;
public TiffTag tifftagXResolution;
public TiffTag tifftagYResolution;
public TiffTag tifftagResolutionUnit;
// Footer...
public uint u32NextIFD;
public ushort u16XBitsPerSample1;
public ushort u16XBitsPerSample2;
public ushort u16XBitsPerSample3;
public ulong u64XResolution;
public ulong u64YResolution;
}
}

View File

@ -1,255 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////////
//
// TwainWorkingGroup.TWAIN
//
// These are the definitions for TWAIN. They're essentially the C/C++
// TWAIN.H file contents translated to C#, with modifications that
// recognize the differences between Windows, Linux and Mac OS X.
//
///////////////////////////////////////////////////////////////////////////////////////
// Author Date TWAIN Comment
// M.McLaughlin 13-Mar-2019 2.4.0.3 Add language code page support for strings
// M.McLaughlin 13-Nov-2015 2.4.0.0 Updated to latest spec
// M.McLaughlin 13-Sep-2015 2.3.1.2 DsmMem bug fixes
// M.McLaughlin 26-Aug-2015 2.3.1.1 Log fix and sync with TWAIN Direct
// M.McLaughlin 13-Mar-2015 2.3.1.0 Numerous fixes
// M.McLaughlin 13-Oct-2014 2.3.0.4 Added logging
// M.McLaughlin 24-Jun-2014 2.3.0.3 Stability fixes
// M.McLaughlin 21-May-2014 2.3.0.2 64-Bit Linux
// M.McLaughlin 27-Feb-2014 2.3.0.1 AnyCPU support
// M.McLaughlin 21-Oct-2013 2.3.0.0 Initial Release
///////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Kodak Alaris Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Text;
namespace TWAINWorkingGroup
{
/// <summary>
/// Handle encoding between C# and what the DS is currently set to.
/// NOTE: this is static for users of this object do not have to track
/// the encoding (i.e. let TWAIN.cs deal with all of this). This
/// means there is one language for all open DSes, so the last one wins.
/// </summary>
static class Language
{
/// <summary>
/// The encoding to use for strings to/from the DS
/// </summary>
/// <returns></returns>
public static Encoding GetEncoding()
{
return (m_encoding);
}
/// <summary>
/// The current language of the DS
/// </summary>
/// <returns></returns>
public static void Set(TWLG a_twlg)
{
switch (a_twlg)
{
default:
// NOTE: can only get here if a TWLG was added, but it wasn't added here
m_encoding = Encoding.GetEncoding(1252);
break;
case TWLG.USERLOCALE:
// NOTE: this should never come back from the DS. only here for completeness
m_encoding = Encoding.GetEncoding(1252);
break;
case TWLG.THAI:
m_encoding = Encoding.GetEncoding(874);
break;
case TWLG.JAPANESE:
m_encoding = Encoding.GetEncoding(932);
break;
case TWLG.CHINESE:
case TWLG.CHINESE_PRC:
case TWLG.CHINESE_SINGAPORE:
case TWLG.CHINESE_SIMPLIFIED:
m_encoding = Encoding.GetEncoding(936);
break;
case TWLG.KOREAN:
case TWLG.KOREAN_JOHAB:
m_encoding = Encoding.GetEncoding(949);
break;
case TWLG.CHINESE_HONGKONG:
case TWLG.CHINESE_TAIWAN:
case TWLG.CHINESE_TRADITIONAL:
m_encoding = Encoding.GetEncoding(950);
break;
case TWLG.ALBANIA:
case TWLG.CROATIA:
case TWLG.CZECH:
case TWLG.HUNGARIAN:
case TWLG.POLISH:
case TWLG.ROMANIAN:
case TWLG.SERBIAN_LATIN:
case TWLG.SLOVAK:
case TWLG.SLOVENIAN:
m_encoding = Encoding.GetEncoding(1250);
break;
case TWLG.BYELORUSSIAN:
case TWLG.BULGARIAN:
case TWLG.RUSSIAN:
case TWLG.SERBIAN_CYRILLIC:
case TWLG.UKRANIAN:
m_encoding = Encoding.GetEncoding(1251);
break;
case TWLG.AFRIKAANS:
case TWLG.BASQUE:
case TWLG.CATALAN:
case TWLG.DAN: // DANISH
case TWLG.DUT: // DUTCH
case TWLG.DUTCH_BELGIAN:
case TWLG.ENG: // ENGLISH
case TWLG.ENGLISH_AUSTRALIAN:
case TWLG.ENGLISH_CANADIAN:
case TWLG.ENGLISH_IRELAND:
case TWLG.ENGLISH_NEWZEALAND:
case TWLG.ENGLISH_SOUTHAFRICA:
case TWLG.ENGLISH_UK:
case TWLG.USA:
case TWLG.FAEROESE:
case TWLG.FIN: // FINNISH
case TWLG.FRN: // FRENCH
case TWLG.FRENCH_BELGIAN:
case TWLG.FCF: // FRENCH_CANADIAN
case TWLG.FRENCH_LUXEMBOURG:
case TWLG.FRENCH_SWISS:
case TWLG.GER: // GERMAN
case TWLG.GERMAN_AUSTRIAN:
case TWLG.GERMAN_LIECHTENSTEIN:
case TWLG.GERMAN_LUXEMBOURG:
case TWLG.GERMAN_SWISS:
case TWLG.ICE: // ICELANDIC
case TWLG.INDONESIAN:
case TWLG.ITN: // ITALIAN
case TWLG.ITALIAN_SWISS:
case TWLG.NOR: // NORWEGIAN
case TWLG.NORWEGIAN_BOKMAL:
case TWLG.NORWEGIAN_NYNORSK:
case TWLG.POR: // PORTUGUESE
case TWLG.PORTUGUESE_BRAZIL:
case TWLG.SPA: // SPANISH
case TWLG.SPANISH_MEXICAN:
case TWLG.SPANISH_MODERN:
case TWLG.SWE: // SWEDISH
case TWLG.SWEDISH_FINLAND:
m_encoding = Encoding.GetEncoding(1252);
break;
case TWLG.GREEK:
m_encoding = Encoding.GetEncoding(1253);
break;
case TWLG.TURKISH:
m_encoding = Encoding.GetEncoding(1254);
break;
case TWLG.HEBREW:
m_encoding = Encoding.GetEncoding(1255);
break;
case TWLG.ARABIC:
case TWLG.ARABIC_ALGERIA:
case TWLG.ARABIC_BAHRAIN:
case TWLG.ARABIC_EGYPT:
case TWLG.ARABIC_IRAQ:
case TWLG.ARABIC_JORDAN:
case TWLG.ARABIC_KUWAIT:
case TWLG.ARABIC_LEBANON:
case TWLG.ARABIC_LIBYA:
case TWLG.ARABIC_MOROCCO:
case TWLG.ARABIC_OMAN:
case TWLG.ARABIC_QATAR:
case TWLG.ARABIC_SAUDIARABIA:
case TWLG.ARABIC_SYRIA:
case TWLG.ARABIC_TUNISIA:
case TWLG.ARABIC_UAE:
case TWLG.ARABIC_YEMEN:
case TWLG.FARSI:
case TWLG.URDU:
m_encoding = Encoding.GetEncoding(1256);
break;
case TWLG.ESTONIAN:
case TWLG.LATVIAN:
case TWLG.LITHUANIAN:
m_encoding = Encoding.GetEncoding(1257);
break;
case TWLG.VIETNAMESE:
m_encoding = Encoding.GetEncoding(1258);
break;
case TWLG.ASSAMESE:
case TWLG.BENGALI:
case TWLG.BIHARI:
case TWLG.BODO:
case TWLG.DOGRI:
case TWLG.GUJARATI:
case TWLG.HARYANVI:
case TWLG.HINDI:
case TWLG.KANNADA:
case TWLG.KASHMIRI:
case TWLG.MALAYALAM:
case TWLG.MARATHI:
case TWLG.MARWARI:
case TWLG.MEGHALAYAN:
case TWLG.MIZO:
case TWLG.NAGA:
case TWLG.ORISSI:
case TWLG.PUNJABI:
case TWLG.PUSHTU:
case TWLG.SIKKIMI:
case TWLG.TAMIL:
case TWLG.TELUGU:
case TWLG.TRIPURI:
// NOTE: there are no known code pages for these, so we will use English
m_encoding = Encoding.GetEncoding(1252);
break;
}
}
private static Encoding m_encoding = MakeDefault();
private static Encoding MakeDefault()
{
#if !NETFRAMEWORK
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
return Encoding.GetEncoding(1252);
}
}
}

View File

@ -1,544 +0,0 @@
///////////////////////////////////////////////////////////////////////////////////////
//
// TwainWorkingGroup.TWAIN
//
// These are the definitions for TWAIN. They're essentially the C/C++
// TWAIN.H file contents translated to C#, with modifications that
// recognize the differences between Windows, Linux and Mac OS X.
//
///////////////////////////////////////////////////////////////////////////////////////
// Author Date TWAIN Comment
// M.McLaughlin 13-Mar-2019 2.4.0.3 Add language code page support for strings
// M.McLaughlin 13-Nov-2015 2.4.0.0 Updated to latest spec
// M.McLaughlin 13-Sep-2015 2.3.1.2 DsmMem bug fixes
// M.McLaughlin 26-Aug-2015 2.3.1.1 Log fix and sync with TWAIN Direct
// M.McLaughlin 13-Mar-2015 2.3.1.0 Numerous fixes
// M.McLaughlin 13-Oct-2014 2.3.0.4 Added logging
// M.McLaughlin 24-Jun-2014 2.3.0.3 Stability fixes
// M.McLaughlin 21-May-2014 2.3.0.2 64-Bit Linux
// M.McLaughlin 27-Feb-2014 2.3.0.1 AnyCPU support
// M.McLaughlin 21-Oct-2013 2.3.0.0 Initial Release
///////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Kodak Alaris Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace TWAINWorkingGroup
{
/// <summary>
/// Our logger. If we bump up to 4.5 (and if mono supports it at compile
/// time), then we'll be able to add the following to our traces, which
/// seems like it should be more than enough to locate log messages. For
/// now we'll leave the log messages undecorated:
/// [CallerFilePath] string file = "",
/// [CallerMemberName] string member = "",
/// [CallerLineNumber] int line = 0
/// </summary>
public static class Log
{
// Public Methods...
#region Public Methods...
/// <summary>
/// Initialize our delegates...
/// </summary>
static Log()
{
Close = CloseLocal;
GetLevel = GetLevelLocal;
Open = OpenLocal;
RegisterTwain = RegisterTwainLocal;
SetFlush = SetFlushLocal;
SetLevel = SetLevelLocal;
WriteEntry = WriteEntryLocal;
}
/// <summary>
/// Let the caller override our delegates with their own functions...
/// </summary>
/// <param name="a_closedelegate">use this to close the logging session</param>
/// <param name="a_getleveldelegate">get the current log level</param>
/// <param name="a_opendelegate">open the logging session</param>
/// <param name="a_registertwaindelegate">not needed at this time</param>
/// <param name="a_setflushdelegate">turn flushing on and off</param>
/// <param name="a_setleveldelegate">set the new log level</param>
/// <param name="a_writeentrydelegate">the function that actually writes to the log</param>
/// <param name="a_getstatedelegate">returns a way to get the current TWAIN state</param>
public static void Override
(
CloseDelegate a_closedelegate,
GetLevelDelegate a_getleveldelegate,
OpenDelegate a_opendelegate,
RegisterTwainDelegate a_registertwaindelegate,
SetFlushDelegate a_setflushdelegate,
SetLevelDelegate a_setleveldelegate,
WriteEntryDelegate a_writeentrydelegate,
out GetStateDelegate a_getstatedelegate
)
{
Close = (a_closedelegate != null) ? a_closedelegate : CloseLocal;
GetLevel = (a_getleveldelegate != null) ? a_getleveldelegate : GetLevelLocal;
Open = (a_opendelegate != null) ? a_opendelegate : OpenLocal;
RegisterTwain = (a_registertwaindelegate != null) ? a_registertwaindelegate : RegisterTwainLocal;
SetFlush = (a_setflushdelegate != null) ? a_setflushdelegate : SetFlushLocal;
SetLevel = (a_setleveldelegate != null) ? a_setleveldelegate : SetLevelLocal;
WriteEntry = (a_writeentrydelegate != null) ? a_writeentrydelegate : WriteEntryLocal;
a_getstatedelegate = GetStateLocal;
}
/// <summary>
/// Write an assert message, but only throw with a debug build...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void Assert(string a_szMessage)
{
WriteEntry("A", a_szMessage, true);
#if DEBUG
throw new Exception(a_szMessage);
#endif
}
/// <summary>
/// Write an error message...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void Error(string a_szMessage)
{
WriteEntry("E", a_szMessage, true);
}
/// <summary>
/// Write an informational message...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void Info(string a_szMessage)
{
WriteEntry(".", a_szMessage, ms_blFlush);
}
/// <summary>
/// Log after sending to the TWAIN driver...
/// </summary>
/// <param name="a_sts">status</param>
/// <param name="a_szMemref">data</param>
public static void LogSendAfter(STS a_sts, string a_szMemref)
{
// The data argument type (DAT) stuff...
if ((a_szMemref != null) && (a_szMemref != "") && (a_szMemref[0] != '('))
{
Log.Info("twn> " + a_szMemref);
}
// TWRC...
if ((int)a_sts < Consts.STSCC)
{
Log.Info("twn> " + a_sts);
}
// TWCC...
else
{
Log.Info("twn> FAILURE/" + a_sts);
}
}
/// <summary>
/// Log before sending to the TWAIN driver...
/// </summary>
/// <param name="a_szDg">data group</param>
/// <param name="a_szDat">data argument type</param>
/// <param name="a_szMsg">message</param>
/// <param name="a_szMemref">data</param>
public static void LogSendBefore(string a_szDg, string a_szDat, string a_szMsg, string a_szMemref)
{
Log.Info("");
Log.Info("twn> DG_" + a_szDg + "/DAT_" + a_szDat + "/MSG_" + a_szMsg);
if ((a_szMemref != null) && (a_szMemref != "") && (a_szMemref[0] != '('))
{
Log.Info("twn> " + a_szMemref);
}
}
/// <summary>
/// Write a verbose message, this is extra info that isn't normally
/// needed to diagnose problems, but may provide insight into what
/// the code is doing...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void Verbose(string a_szMessage)
{
WriteEntry("V", a_szMessage, ms_blFlush);
}
/// <summary>
/// Write a verbose data message, this is extra info, specifically
/// data transfers, that isn't normally needed to diagnose problems.
/// Turning this one can really bloat the logs...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void VerboseData(string a_szMessage)
{
WriteEntry("D", a_szMessage, ms_blFlush);
}
/// <summary>
/// Write an warning message...
/// </summary>
/// <param name="a_szMessage">message to log</param>
public static void Warn(string a_szMessage)
{
WriteEntry("W", a_szMessage, ms_blFlush);
}
#endregion
// Public Definitions...
#region Public Definitions...
// The public methods that need attributes, here offered
// as delegates, so that a caller will be able to override
// them...
public delegate void CloseDelegate();
public delegate int GetLevelDelegate();
public delegate string GetStateDelegate();
public delegate void OpenDelegate(string a_szName, string a_szPath, int a_iLevel);
public delegate void RegisterTwainDelegate(TWAIN a_twain);
public delegate void SetFlushDelegate(bool a_blFlush);
public delegate void SetLevelDelegate(int a_iLevel);
public delegate void WriteEntryDelegate(string a_szSeverity, string a_szMessage, bool a_blFlush);
#endregion
// Public Attributes...
#region Public Attributes...
// The public methods that need attributes, here offered
// as delegates, so that a caller will be able to override
// them...
public static CloseDelegate Close;
public static GetLevelDelegate GetLevel;
public static OpenDelegate Open;
public static RegisterTwainDelegate RegisterTwain;
public static SetFlushDelegate SetFlush;
public static SetLevelDelegate SetLevel;
public static WriteEntryDelegate WriteEntry;
#endregion
// Private Methods...
#region Private Methods...
/// <summary>
/// Close tracing...
/// </summary>
private static void CloseLocal()
{
if (!ms_blFirstPass)
{
Trace.Close();
ms_filestream.Close();
ms_filestream = null;
}
ms_blFirstPass = true;
ms_blOpened = false;
ms_blFlush = false;
ms_iMessageNumber = 0;
}
/// <summary>
/// Get the debugging level...
/// </summary>
/// <returns>the level</returns>
private static int GetLevelLocal()
{
return (ms_iLevel);
}
/// <summary>
/// Get the state...
/// </summary>
/// <returns>the level</returns>
private static string GetStateLocal()
{
return ((ms_twain == null) ? "S1" : ms_twain.GetState().ToString());
}
/// <summary>
/// Turn on the listener for our log file...
/// </summary>
/// <param name="a_szName">the name of our log</param>
/// <param name="a_szPath">the path where we want our log to go</param>
/// <param name="a_iLevel">debug level</param>
private static void OpenLocal(string a_szName, string a_szPath, int a_iLevel)
{
string szLogFile;
// Init stuff...
ms_blFirstPass = true;
ms_blOpened = true;
ms_blFlush = false;
ms_iMessageNumber = 0;
ms_iLevel = a_iLevel;
// Ask for a TWAINDSM log...
if (a_iLevel > 0)
{
Environment.SetEnvironmentVariable("TWAINDSM_LOG", Path.Combine(a_szPath, "twaindsm.log"));
Environment.SetEnvironmentVariable("TWAINDSM_MODE", "w");
}
// Backup old stuff...
szLogFile = Path.Combine(a_szPath, a_szName);
try
{
if (File.Exists(szLogFile + "_backup_2.log"))
{
File.Delete(szLogFile + "_backup_2.log");
}
if (File.Exists(szLogFile + "_backup_1.log"))
{
File.Move(szLogFile + "_backup_1.log", szLogFile + "_backup_2.log");
}
if (File.Exists(szLogFile + ".log"))
{
File.Move(szLogFile + ".log", szLogFile + "_backup_1.log");
}
}
catch
{
// Don't care, keep going...
}
// Turn on the listener...
ms_filestream = File.Open(szLogFile + ".log", FileMode.Append, FileAccess.Write, FileShare.Read);
Trace.Listeners.Add(new TextWriterTraceListener(ms_filestream, a_szName + "Listener"));
}
/// <summary>
/// Register the TWAIN object so we can get some extra info...
/// </summary>
/// <param name="a_twain">twain object or null</param>
private static void RegisterTwainLocal(TWAIN a_twain)
{
ms_twain = a_twain;
}
/// <summary>
/// Flush data to the file...
/// </summary>
private static void SetFlushLocal(bool a_blFlush)
{
ms_blFlush = a_blFlush;
if (a_blFlush)
{
Trace.Flush();
}
}
/// <summary>
/// Set the debugging level
/// </summary>
/// <param name="a_iLevel"></param>
private static void SetLevelLocal(int a_iLevel)
{
// Squirrel this value away...
ms_iLevel = a_iLevel;
// One has to opt out of flushing, since the consequence
// of turning it off often involves losing log data...
if ((a_iLevel & c_iDebugNoFlush) == c_iDebugNoFlush)
{
SetFlush(false);
}
else
{
SetFlush(true);
}
}
/// <summary>
/// Do this for all of them...
/// </summary>
/// <param name="a_szMessage">The message</param>
/// <param name="a_szSeverity">Message severity</param>
/// <param name="a_blFlush">Flush it to disk</param>
private static void WriteEntryLocal(string a_szSeverity, string a_szMessage, bool a_blFlush)
{
long lThreadId;
// Filter...
switch (a_szSeverity)
{
// Always log these, and always flush them to disk...
case "A":
case "E":
case "W":
a_blFlush = true;
break;
// Log informationals when bit-0 is set...
case ".":
if ((ms_iLevel & c_iDebugInfo) != 0)
{
break;
}
return;
// Log verbose when bit-1 is set...
case "V":
if ((ms_iLevel & c_iDebugVerbose) != 0)
{
a_szSeverity = ".";
break;
}
return;
// Log verbose data when bit-1 is set...
case "D":
if ((ms_iLevel & c_iDebugVerboseData) != 0)
{
a_szSeverity = ".";
break;
}
return;
}
// Get our thread id...
if (ms_blIsWindows)
{
lThreadId = NativeMethods.GetCurrentThreadId();
}
else
{
lThreadId = Thread.CurrentThread.ManagedThreadId;
}
// First pass...
if (ms_blFirstPass)
{
string szPlatform;
// We're Windows...
if (Environment.OSVersion.ToString().Contains("Microsoft Windows"))
{
szPlatform = "windows";
}
// We're Mac OS X (this has to come before LINUX!!!)...
else if (Directory.Exists("/Library/Application Support"))
{
szPlatform = "macosx";
}
// We're Linux...
else if (Environment.OSVersion.ToString().Contains("Unix"))
{
szPlatform = "linux";
}
// We have a problem, Log will throw for us...
else
{
szPlatform = "unknown";
}
if (!ms_blOpened)
{
// We'll assume they want logging, since they didn't tell us...
Open("Twain", ".", 1);
}
Trace.UseGlobalLock = true;
ms_blFirstPass = false;
Trace.WriteLine
(
string.Format
(
"{0:D6} {1} {2} T{3:D8} V{4} ts:{5} os:{6}",
ms_iMessageNumber++,
DateTime.Now.ToString("HHmmssffffff"),
(ms_twain != null) ? ms_twain.GetState().ToString() : "S1",
lThreadId,
a_szSeverity.ToString(),
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ffffff"),
szPlatform
)
);
}
// And log it...
Trace.WriteLine
(
string.Format
(
"{0:D6} {1} {2} T{3:D8} V{4} {5}",
ms_iMessageNumber++,
DateTime.Now.ToString("HHmmssffffff"),
(ms_twain != null) ? ms_twain.GetState().ToString() : "S1",
lThreadId,
a_szSeverity.ToString(),
a_szMessage
)
);
// Flush it...
if (a_blFlush)
{
Trace.Flush();
}
}
#endregion
// Private Definitions...
#region Private Definitions
/// <summary>
/// LogLevel bitmask...
/// </summary>
private const int c_iDebugInfo = 0x0001;
private const int c_iDebugVerbose = 0x0002;
private const int c_iDebugVerboseData = 0x0004;
private const int c_iDebugNoFlush = 0x0008;
#endregion
// Private Attributes...
#region Private Attributes
private static bool ms_blFirstPass = true;
private static bool ms_blOpened = false;
private static bool ms_blFlush = false;
private static int ms_iMessageNumber = 0;
private static int ms_iLevel = 0;
private static TWAIN ms_twain = null;
private static bool ms_blIsWindows = false;
private static FileStream ms_filestream;
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
This namespace contains types and utilities from the [twaincs project](https://github.com/twain/twain-cs)
that are modified/regrouped for use in this lib so it's not 2 giant files (TWAIN.cs and TWAINH.cs).
This namespace contains types and utilities from the [twaincs project](https://github.com/twain/twain-cs)
that's been modified with partials.
Version initially used is 2.4.11.0 (commit 0699e1f4845c80707bb00b9198dd7f29bf853a64 on Jul 9, 2020).
Version initially used is 2.5.0.0.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
using System;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

View File

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

View File

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
using static TWAINWorkingGroup.TWAIN;
namespace NTwain
{

Binary file not shown.

Binary file not shown.

2302
twain-doc/twain2.5.h Normal file

File diff suppressed because it is too large Load Diff