add doc comments, make point size internal until I can learn matrices, add test case for ascii 85 filter, add test case for document text

This commit is contained in:
Eliot Jones
2017-12-30 18:02:59 +00:00
parent 88c86971d8
commit cf41614cc2
4 changed files with 52 additions and 5 deletions

View File

@@ -41,7 +41,7 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
Assert.Equal("Man \0\0\0\0is d", text); Assert.Equal("Man \0\0\0\0is d", text);
} }
[Fact] [Fact]
public void ZInMiddleOf5CharacterSequenceThrows() public void ZInMiddleOf5CharacterSequenceThrows()
{ {
@@ -52,6 +52,16 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
Assert.Throws<InvalidOperationException>(action); Assert.Throws<InvalidOperationException>(action);
} }
[Fact]
public void SingleCharacterLastThrows()
{
var bytes = Encoding.ASCII.GetBytes("9jqo^B");
Action action = () => filter.Decode(bytes, new PdfDictionary(), 1);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
private const string PdfContent = @"1 0 obj private const string PdfContent = @"1 0 obj
<< /Length 568 >> << /Length 568 >>
stream stream

View File

@@ -2,6 +2,7 @@
{ {
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using Xunit; using Xunit;
public class FontSizeTestFromGoogleChromeTests public class FontSizeTestFromGoogleChromeTests
@@ -35,5 +36,18 @@
Assert.Equal(842, page.Height); Assert.Equal(842, page.Height);
} }
} }
[Fact]
public void GetsCorrectPageTextIgnoringHiddenCharacters()
{
using (var document = PdfDocument.Open(GetFilename()))
{
var page = document.GetPage(1);
var text = string.Join(string.Empty, page.Letters.Select(x => x.Value));
Assert.Equal("Hello, this is 16ptHello, this is 16px", text);
}
}
} }
} }

View File

@@ -9,6 +9,9 @@
/// </summary> /// </summary>
public string Value { get; } public string Value { get; }
/// <summary>
/// The lower-left position of the letter. Letters with descenders will extend below this point.
/// </summary>
public PdfPoint Location { get; } public PdfPoint Location { get; }
/// <summary> /// <summary>
@@ -17,9 +20,9 @@
public decimal Width { get; } public decimal Width { get; }
/// <summary> /// <summary>
/// Size defined by the Tj operator prior to our possibly incorrect transformation. /// Size as defined in the PDF file. This is not equivalent to font size in points but is relative to other font sizes on the page.
/// </summary> /// </summary>
internal decimal FontSize { get; } public decimal FontSize { get; }
/// <summary> /// <summary>
/// The name of the font. /// The name of the font.
@@ -27,10 +30,13 @@
public string FontName { get; } public string FontName { get; }
/// <summary> /// <summary>
/// The size of the font in points. /// The size of the font in points. This is not ready for public consumption as the calculation is incorrect.
/// </summary> /// </summary>
public decimal PointSize { get; } internal decimal PointSize { get; }
/// <summary>
/// Create a new letter to represent some text drawn by the Tj operator.
/// </summary>
internal Letter(string value, PdfPoint location, decimal width, decimal fontSize, string fontName, decimal pointSize) internal Letter(string value, PdfPoint location, decimal width, decimal fontSize, string fontName, decimal pointSize)
{ {
Value = value; Value = value;

View File

@@ -1,11 +1,28 @@
namespace UglyToad.Pdf.Geometry namespace UglyToad.Pdf.Geometry
{ {
/// <summary>
/// A point in a PDF file.
/// </summary>
/// <remarks>
/// PDF coordinates are defined with the origin at the lower left (0, 0).
/// The Y-axis extends vertically upwards and the X-axis horizontally to the right.
/// Unless otherwise specified on a per-page basis, units in PDF space are equivalent to a typographic point (1/72 inch).
/// </remarks>
public struct PdfPoint public struct PdfPoint
{ {
/// <summary>
/// The origin of the coordinates system.
/// </summary>
public static PdfPoint Origin = new PdfPoint(0m, 0m); public static PdfPoint Origin = new PdfPoint(0m, 0m);
/// <summary>
/// The X coordinate for this point. (Horizontal axis).
/// </summary>
public decimal X { get; } public decimal X { get; }
/// <summary>
/// The Y coordinate of this point. (Vertical axis).
/// </summary>
public decimal Y { get; } public decimal Y { get; }
public PdfPoint(decimal x, decimal y) public PdfPoint(decimal x, decimal y)