mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 03:34:52 +08:00
favour pdf level widths over advance widths for truetype. fix image sizes for visual verification tests
This commit is contained in:
@@ -54,5 +54,10 @@
|
||||
Assert.Equal(Height, letter.GlyphRectangle.Height, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{X} {Y} {Width} {Text} {FontSize} {FontName} {Height}";
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 238 KiB |
Binary file not shown.
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 209 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,74 @@
|
||||
namespace UglyToad.PdfPig.Tests.Integration
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
public class SinglePageInkscapeTests
|
||||
{
|
||||
private static string GetFilename()
|
||||
{
|
||||
var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents"));
|
||||
|
||||
return Path.Combine(documentFolder, "Single Page Simple - from inkscape.pdf");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LettersHaveCorrectPositionsPdfBox()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename()))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
var letters = page.Letters;
|
||||
var positions = GetPdfBoxData();
|
||||
|
||||
for (int i = 0; i < letters.Count; i++)
|
||||
{
|
||||
var letter = letters[i];
|
||||
var position = positions[i];
|
||||
position.AssertWithinTolerance(letter, page, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AssertablePositionData> GetPdfBoxData()
|
||||
{
|
||||
const string data = @"100.57143 687.4286 31.616001 W 32.0 KTICVV+DejaVuSans 47.776
|
||||
130.74742 687.4286 13.152 r 32.0 KTICVV+DejaVuSans 36.704002
|
||||
143.89941 687.4286 8.864 i 32.0 KTICVV+DejaVuSans 49.792004
|
||||
152.76341 687.4286 12.544001 t 32.0 KTICVV+DejaVuSans 46.016003
|
||||
165.30742 687.4286 19.68 e 32.0 KTICVV+DejaVuSans 37.632
|
||||
184.98743 687.4286 10.144 32.0 KTICVV+DejaVuSans 0.0
|
||||
195.13142 687.4286 16.640001 s 32.0 KTICVV+DejaVuSans 37.632
|
||||
211.77142 687.4286 19.552 o 32.0 KTICVV+DejaVuSans 37.632
|
||||
231.32343 687.4286 31.168001 m 32.0 KTICVV+DejaVuSans 36.704002
|
||||
262.49142 687.4286 19.68 e 32.0 KTICVV+DejaVuSans 37.632
|
||||
282.17142 687.4286 12.544001 t 32.0 KTICVV+DejaVuSans 46.016003
|
||||
294.71542 687.4286 20.256 h 32.0 KTICVV+DejaVuSans 49.792004
|
||||
315.06744 687.4286 8.864 i 32.0 KTICVV+DejaVuSans 49.792004
|
||||
323.93146 687.4286 20.256 n 32.0 KTICVV+DejaVuSans 36.704002
|
||||
344.18747 687.4286 20.288 g 32.0 KTICVV+DejaVuSans 50.336002
|
||||
364.47546 687.4286 10.144 32.0 KTICVV+DejaVuSans 0.0
|
||||
374.61948 687.4286 8.864 i 32.0 KTICVV+DejaVuSans 49.792004
|
||||
383.4835 687.4286 20.256 n 32.0 KTICVV+DejaVuSans 36.704002
|
||||
100.57143 647.4286 9.408 I 32.0 KTICVV+DejaVuSans 47.776
|
||||
109.97942 647.4286 20.256 n 32.0 KTICVV+DejaVuSans 36.704002
|
||||
130.23543 647.4286 18.528002 k 32.0 KTICVV+DejaVuSans 49.792004
|
||||
148.76343 647.4286 16.640001 s 32.0 KTICVV+DejaVuSans 37.632
|
||||
165.40343 647.4286 17.568 c 32.0 KTICVV+DejaVuSans 37.632
|
||||
183.06743 647.4286 19.584002 a 32.0 KTICVV+DejaVuSans 37.632
|
||||
202.65143 647.4286 20.288 p 32.0 KTICVV+DejaVuSans 50.336002
|
||||
222.93942 647.4286 19.68 e 32.0 KTICVV+DejaVuSans 37.632
|
||||
";
|
||||
|
||||
var result = data.Split(new[] { "\r", "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(AssertablePositionData.Parse)
|
||||
.ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,7 +35,7 @@
|
||||
[Fact]
|
||||
public void SinglePageSimpleFromInkscape()
|
||||
{
|
||||
Run(SingleInkscapePage);
|
||||
Run(SingleInkscapePage, 841);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,7 +65,7 @@
|
||||
[Fact]
|
||||
public void PigProductionCompactFontFormat()
|
||||
{
|
||||
Run(PigProduction);
|
||||
Run(PigProduction, 680);
|
||||
}
|
||||
|
||||
private static void Run(string file, int imageHeight = 792)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Fonts.Simple
|
||||
{
|
||||
using System;
|
||||
using Cmap;
|
||||
using Composite;
|
||||
using Core;
|
||||
@@ -107,18 +108,24 @@
|
||||
}
|
||||
|
||||
decimal width;
|
||||
if (font == null)
|
||||
|
||||
var index = characterCode - firstCharacter;
|
||||
if (widths != null && index >= 0 && index < widths.Length)
|
||||
{
|
||||
fromFont = false;
|
||||
width = widths[characterCode - firstCharacter];
|
||||
width = widths[index];
|
||||
}
|
||||
else
|
||||
else if (font != null)
|
||||
{
|
||||
if (!font.TryGetBoundingAdvancedWidth(characterCode, out width))
|
||||
{
|
||||
width = boundingBoxPreTransform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"Could not retrieve width for character code: {characterCode} in font {Name}.");
|
||||
}
|
||||
|
||||
if (fromFont)
|
||||
{
|
||||
|
Reference in New Issue
Block a user