namespace UglyToad.PdfPig.Content
{
using System.Collections.Generic;
using UglyToad.PdfPig.Core;
using UglyToad.PdfPig.Graphics;
using UglyToad.PdfPig.Tokens;
using UglyToad.PdfPig.Util;
///
///
///
public class PdfMarkedContent
{
private readonly List images = new List();
private readonly List pdfPaths = new List();
private readonly List letters = new List();
private readonly List xObjectContentRecords = new List();
internal PdfMarkedContent(int id, NameToken tag, DictionaryToken properties)
{
this.Id = id;
this.Tag = tag;
this.Properties = properties;
this.ChildContents = new List();
}
///
/// Is the marked content an artifact.
///
public bool IsArtifact { get; internal set; }
///
/// Internal Id for top marked content. Child marked contents will share the same Id as the parent.
///
public int Id { get; }
///
/// Marked-content identifier.
///
public int MCID
{
get
{
if (Properties == null) return -1;
if (Properties.ContainsKey(NameToken.Mcid))
{
return Properties.GetInt(NameToken.Mcid);
}
return -1;
}
}
///
///
///
public string Tag { get; }
///
/// Properties.
///
public DictionaryToken Properties { get; }
///
/// Child contents.
///
public List ChildContents { get; }
///
/// The natural language specification.
///
public string Language
{
get
{
if (Properties == null) return null;
if (Properties.TryGet(NameToken.Lang, out IDataToken langToken))
{
return langToken.Data;
}
return null;
}
}
///
/// The replacement text.
///
public string ActualText
{
get
{
if (Properties == null) return null;
if (Properties.TryGet(NameToken.ActualText, out IDataToken textToken))
{
return textToken.Data;
}
return null;
}
}
///
/// The alternate description.
///
public string AlternateDescription
{
get
{
if (Properties == null) return null;
if (Properties.TryGet(NameToken.Alternate, out IDataToken textToken))
{
return textToken.Data;
}
return null;
}
}
///
/// The abbreviation expansion text.
///
public string ExpandedForm
{
get
{
if (Properties == null) return null;
if (Properties.TryGet(NameToken.E, out IDataToken textToken))
{
return textToken.Data;
}
return null;
}
}
///
/// The marked content's images.
///
public IReadOnlyList Images => images;
///
/// The marked content's paths.
///
public IReadOnlyList PdfPaths => pdfPaths;
///
/// The marked content's letters.
///
public IReadOnlyList Letters => letters;
internal void Add(IPdfImage pdfImage)
{
images.Add(pdfImage);
}
internal void Add(PdfPath pdfPath)
{
pdfPaths.Add(pdfPath);
}
internal void Add(Letter letter)
{
letters.Add(letter);
}
internal void Add(XObjectContentRecord xObjectContentRecord)
{
xObjectContentRecords.Add(xObjectContentRecord);
}
internal void Add(PdfMarkedContent markedContent)
{
ChildContents.Add(markedContent);
}
internal static PdfMarkedContent Create(int id, NameToken name, DictionaryToken properties)
{
if (name.Equals(NameToken.Artifact))
{
return new PdfArtifactMarkedContent(id, properties);
}
else
{
return new PdfMarkedContent(id, name, properties);
}
}
///
public override string ToString()
{
return "Id=" + Id + ", Tag=" + this.Tag + ", Properties=" + this.Properties + ", Contents=" + this.ChildContents.Count;
}
}
}