mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
update RecursiveXYCut code with RecursiveXYCutOptions
@@ -136,23 +136,33 @@ The method can be tailored by providing a __minimum block width__, and __horizon
|
||||
|
||||
- Minimum block width is set to 1/3 of page width:
|
||||
```csharp
|
||||
var blocks = RecursiveXYCut.Instance.GetBlocks(words, page.Width / 3.0);
|
||||
var blocks = RecursiveXYCut.Instance.GetBlocks(words,
|
||||
new RecursiveXYCut.RecursiveXYCutOptions()
|
||||
{
|
||||
MinimumWidth = page.Width / 3.0
|
||||
});
|
||||
```
|
||||
- Average of the page letters' height and width is used as gap size (the values won’t change), and minimum block width is set to 1/3 of page width:
|
||||
```csharp
|
||||
var blocks = RecursiveXYCut.Instance.GetBlocks(words,
|
||||
page.Width / 3m,
|
||||
page.Letters.Average(l => l.GlyphRectangle.Width),
|
||||
page.Letters.Average(l => l.GlyphRectangle.Height));
|
||||
new RecursiveXYCut.RecursiveXYCutOptions()
|
||||
{
|
||||
MinimumWidth = page.Width / 3.0,
|
||||
DominantFontWidthFunc = _ => page.Letters.Average(l => l.GlyphRectangle.Width),
|
||||
DominantFontHeightFunc = _ => page.Letters.Average(l => l.GlyphRectangle.Height)
|
||||
});
|
||||
```
|
||||
|
||||
- A function that will be applied to each block letters’ height and width can also be provided. Here we use the average and minimum block width is set to 1/3 of page width:
|
||||
|
||||
```csharp
|
||||
var blocks = RecursiveXYCut.Instance.GetBlocks(words,
|
||||
page.Width / 3m,
|
||||
width => width.Average(),
|
||||
height => height.Average());
|
||||
new RecursiveXYCut.RecursiveXYCutOptions()
|
||||
{
|
||||
MinimumWidth = page.Width / 3.0,
|
||||
DominantFontWidthFunc = letters => letters.Select(l => l.GlyphRectangle.Width).Average(),
|
||||
DominantFontHeightFunc = letters => letters.Select(l => l.GlyphRectangle.Height).Average()
|
||||
});
|
||||
```
|
||||
|
||||
### Results
|
||||
|
||||
Reference in New Issue
Block a user