mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-21 04:17:57 +08:00
#24 add options to list box
This commit is contained in:
@@ -220,33 +220,35 @@
|
|||||||
throw new PdfDocumentFormatException($"An option array containing array elements should contain 2 strings, instead got: {optionArrayToken}.");
|
throw new PdfDocumentFormatException($"An option array containing array elements should contain 2 strings, instead got: {optionArrayToken}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string exportValue;
|
||||||
if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out StringToken exportValueStringToken))
|
if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out StringToken exportValueStringToken))
|
||||||
{
|
{
|
||||||
|
exportValue = exportValueStringToken.Data;
|
||||||
}
|
}
|
||||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out HexToken exportValueHexToken))
|
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out HexToken exportValueHexToken))
|
||||||
{
|
{
|
||||||
|
exportValue = exportValueHexToken.Data;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new PdfDocumentFormatException($"An option array array element's first value should be the export value string, instead got: {optionArrayToken.Data[0]}.");
|
throw new PdfDocumentFormatException($"An option array array element's first value should be the export value string, instead got: {optionArrayToken.Data[0]}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string name;
|
||||||
if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out StringToken nameStringToken))
|
if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out StringToken nameStringToken))
|
||||||
{
|
{
|
||||||
|
name = nameStringToken.Data;
|
||||||
}
|
}
|
||||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out HexToken nameHexToken))
|
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out HexToken nameHexToken))
|
||||||
{
|
{
|
||||||
|
name = nameHexToken.Data;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new PdfDocumentFormatException($"An option array array element's second value should be the option name string, instead got: {optionArrayToken.Data[1]}.");
|
throw new PdfDocumentFormatException($"An option array array element's second value should be the option name string, instead got: {optionArrayToken.Data[1]}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.Add(new AcroChoiceOption(i, name, exportValue));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -264,7 +266,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information);
|
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information, options);
|
||||||
result = field;
|
result = field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -114,11 +114,14 @@
|
|||||||
{
|
{
|
||||||
public AcroChoiceFieldFlags Flags { get; }
|
public AcroChoiceFieldFlags Flags { get; }
|
||||||
|
|
||||||
|
public IReadOnlyList<AcroChoiceOption> Options { get; }
|
||||||
|
|
||||||
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
||||||
AcroFieldCommonInformation information) :
|
AcroFieldCommonInformation information, IReadOnlyList<AcroChoiceOption> options) :
|
||||||
base(dictionary, fieldType, (uint)fieldFlags, information)
|
base(dictionary, fieldType, (uint)fieldFlags, information)
|
||||||
{
|
{
|
||||||
Flags = fieldFlags;
|
Flags = fieldFlags;
|
||||||
|
Options = options ?? throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Util.JetBrains.Annotations;
|
using Util.JetBrains.Annotations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A name object is an atomic symbol uniquely defined by a sequence of characters.
|
/// A name object is an atomic symbol uniquely defined by a sequence of characters.
|
||||||
/// Each name is considered identical if it has the same sequence of characters. Names are used in
|
/// Each name is considered identical if it has the same sequence of characters. Names are used in
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class NameToken : IDataToken<string>
|
public partial class NameToken : IDataToken<string>
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The string representation of the name.
|
/// The string representation of the name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -73,6 +75,27 @@
|
|||||||
return name?.Data;
|
return name?.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if two names are equal.
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator ==(NameToken name1, NameToken name2)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(name1, name2))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name1?.Equals(name2) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks two names for lack of equality.
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator !=(NameToken name1, NameToken name2)
|
||||||
|
{
|
||||||
|
return !(name1 == name2);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user