namespace UglyToad.PdfPig.Content
{
using System;
using System.Collections.Generic;
using Core;
using Filters;
using Graphics;
using Graphics.Operations;
using Tokenization.Scanner;
using XObjects;
///
/// Wraps content parsed from a page content stream for access.
///
///
/// This should contain a replayable stack of drawing instructions for page content
/// from a content stream in addition to lazily evaluated state such as text on the page or images.
///
internal class PageContent
{
private readonly IReadOnlyList> images;
private readonly IReadOnlyList markedContents;
private readonly IPdfTokenScanner pdfScanner;
private readonly IFilterProvider filterProvider;
private readonly IResourceStore resourceStore;
internal IReadOnlyList GraphicsStateOperations { get; }
public IReadOnlyList Letters { get; }
public IReadOnlyList Paths { get; }
internal PageContent(IReadOnlyList graphicsStateOperations, IReadOnlyList letters,
IReadOnlyList paths,
IReadOnlyList> images,
IReadOnlyList markedContents,
IPdfTokenScanner pdfScanner,
IFilterProvider filterProvider,
IResourceStore resourceStore)
{
GraphicsStateOperations = graphicsStateOperations;
Letters = letters;
Paths = paths;
this.images = images;
this.markedContents = markedContents;
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
this.resourceStore = resourceStore ?? throw new ArgumentNullException(nameof(resourceStore));
}
public IEnumerable GetImages()
{
foreach (var image in images)
{
var result = image.Match(x => XObjectFactory.ReadImage(x, pdfScanner, filterProvider, resourceStore),
x => x);
yield return result;
}
}
public IReadOnlyList GetMarkedContents() => markedContents;
}
}