mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-19 10:47:56 +08:00
update DefaultPageSegmenter to use DlaOptions
This commit is contained in:
@@ -2,9 +2,11 @@
|
|||||||
{
|
{
|
||||||
using Content;
|
using Content;
|
||||||
using Core;
|
using Core;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default Page Segmenter. All words are included in one block.
|
/// Default Page Segmenter. All words are included in one block.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -15,15 +17,43 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static DefaultPageSegmenter Instance { get; } = new DefaultPageSegmenter();
|
public static DefaultPageSegmenter Instance { get; } = new DefaultPageSegmenter();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the blocks.
|
/// Get the blocks using default options values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pageWords">The words in the page.</param>
|
/// <param name="words">The page's words to generate text blocks for.</param>
|
||||||
public IReadOnlyList<TextBlock> GetBlocks(IEnumerable<Word> pageWords)
|
public IReadOnlyList<TextBlock> GetBlocks(IEnumerable<Word> words)
|
||||||
{
|
{
|
||||||
if (pageWords.Count() == 0) return EmptyArray<TextBlock>.Instance;
|
return GetBlocks(words, new DefaultPageSegmenterOptions());
|
||||||
|
}
|
||||||
|
|
||||||
return new List<TextBlock>() { new TextBlock(new XYLeaf(pageWords).GetLines()) };
|
/// <summary>
|
||||||
|
/// Get the text blocks using options.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="words">The page's words to generate text blocks for.</param>
|
||||||
|
/// <param name="options">The <see cref="DefaultPageSegmenterOptions"/> to use.</param>
|
||||||
|
/// <returns>The <see cref="TextBlock"/>s generated by the default method.</returns>
|
||||||
|
public IReadOnlyList<TextBlock> GetBlocks(IEnumerable<Word> words, DlaOptions options)
|
||||||
|
{
|
||||||
|
if (options is DefaultPageSegmenterOptions dOptions)
|
||||||
|
{
|
||||||
|
if (words?.Any() != true)
|
||||||
|
{
|
||||||
|
return EmptyArray<TextBlock>.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new List<TextBlock>() { new TextBlock(new XYLeaf(words).GetLines(dOptions.WordSeparator), dOptions.LineSeparator) };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Options provided must be of type " + nameof(DefaultPageSegmenterOptions) + ".", nameof(options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default page segmenter options.
|
||||||
|
/// </summary>
|
||||||
|
public class DefaultPageSegmenterOptions : PageSegmenterOptions
|
||||||
|
{ }
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user