mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 20:07: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}.");
|
||||
}
|
||||
|
||||
string exportValue;
|
||||
if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out StringToken exportValueStringToken))
|
||||
{
|
||||
|
||||
exportValue = exportValueStringToken.Data;
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out HexToken exportValueHexToken))
|
||||
{
|
||||
|
||||
exportValue = exportValueHexToken.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
||||
name = nameStringToken.Data;
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out HexToken nameHexToken))
|
||||
{
|
||||
|
||||
name = nameHexToken.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -264,7 +266,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information);
|
||||
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information, options);
|
||||
result = field;
|
||||
}
|
||||
}
|
||||
|
@@ -114,11 +114,14 @@
|
||||
{
|
||||
public AcroChoiceFieldFlags Flags { get; }
|
||||
|
||||
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
||||
AcroFieldCommonInformation information) :
|
||||
public IReadOnlyList<AcroChoiceOption> Options { get; }
|
||||
|
||||
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
||||
AcroFieldCommonInformation information, IReadOnlyList<AcroChoiceOption> options) :
|
||||
base(dictionary, fieldType, (uint)fieldFlags, information)
|
||||
{
|
||||
Flags = fieldFlags;
|
||||
Options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// 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
|
||||
@@ -10,6 +11,7 @@
|
||||
/// </summary>
|
||||
public partial class NameToken : IDataToken<string>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// The string representation of the name.
|
||||
/// </summary>
|
||||
@@ -73,6 +75,27 @@
|
||||
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 />
|
||||
public override string ToString()
|
||||
{
|
||||
|
Reference in New Issue
Block a user