mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 19:05:01 +08:00
#21 add a test for accented characters and fill in more writing methods for content stream operators
the output is currently incorrect for accented characters
This commit is contained in:
@@ -207,6 +207,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanWriteSinglePageWithAccentedCharacters()
|
||||
{
|
||||
var builder = new PdfDocumentBuilder();
|
||||
var page = builder.AddPage(PageSize.A4);
|
||||
|
||||
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Fonts", "TrueType");
|
||||
var file = Path.Combine(path, "Roboto-Regular.ttf");
|
||||
|
||||
var font = builder.AddTrueTypeFont(File.ReadAllBytes(file));
|
||||
|
||||
page.AddText("é (lower case, upper case É).", 9,
|
||||
new PdfPoint(30, page.PageSize.Height - 50), font);
|
||||
|
||||
WriteFile(nameof(CanWriteSinglePageWithAccentedCharacters), builder.Build());
|
||||
}
|
||||
|
||||
private static void WriteFile(string name, byte[] bytes)
|
||||
{
|
||||
try
|
||||
|
@@ -77,7 +77,7 @@
|
||||
{
|
||||
using (var memoryStream = new MemoryStream(input))
|
||||
{
|
||||
// The first 2 bytes are the header which DelfateStream does not support.
|
||||
// The first 2 bytes are the header which DeflateStream does not support.
|
||||
memoryStream.ReadByte();
|
||||
memoryStream.ReadByte();
|
||||
|
||||
|
@@ -5,6 +5,9 @@
|
||||
using Content;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Modify the current transformation matrix by concatenating the specified matrix.
|
||||
/// </summary>
|
||||
internal class ModifyCurrentTransformationMatrix : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "cm";
|
||||
|
@@ -4,9 +4,13 @@
|
||||
using System.IO;
|
||||
using Content;
|
||||
|
||||
/// <summary>
|
||||
/// Restore the graphics state by removing the most recently saved state from the stack and making it the current state.
|
||||
/// </summary>
|
||||
internal class Pop : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "Q";
|
||||
|
||||
public static readonly Pop Value = new Pop();
|
||||
|
||||
public string Operator => Symbol;
|
||||
@@ -30,7 +34,8 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -3,6 +3,9 @@
|
||||
using System.IO;
|
||||
using Content;
|
||||
|
||||
/// <summary>
|
||||
/// Save the current graphics state on the graphics state stack.
|
||||
/// </summary>
|
||||
internal class Push : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "q";
|
||||
@@ -14,11 +17,6 @@
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Symbol;
|
||||
}
|
||||
|
||||
public void Run(IOperationContext context, IResourceStore resourceStore)
|
||||
{
|
||||
context.PushState();
|
||||
@@ -26,7 +24,13 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Symbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,9 @@
|
||||
using Content;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Begin a text object, initializing the text matrix and the text line matrix to the identity matrix. Text objects cannot be nested.
|
||||
/// </summary>
|
||||
internal class BeginText : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "BT";
|
||||
|
@@ -4,6 +4,9 @@
|
||||
using Content;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <summary>
|
||||
/// End a text object, discarding the text matrix.
|
||||
/// </summary>
|
||||
internal class EndText : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "ET";
|
||||
|
@@ -30,7 +30,8 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -4,6 +4,10 @@
|
||||
using Content;
|
||||
using TextState;
|
||||
|
||||
/// <summary>
|
||||
/// Move to the start of the next line, offset from the start of the current line by (tx, ty).
|
||||
/// This operator also sets the leading parameter in the text state.
|
||||
/// </summary>
|
||||
internal class MoveToNextLineWithOffsetSetLeading : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "TD";
|
||||
@@ -33,7 +37,12 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
stream.WriteDecimal(Tx);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Ty);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -5,6 +5,9 @@
|
||||
using Content;
|
||||
using PdfPig.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Set the text matrix and the text line matrix.
|
||||
/// </summary>
|
||||
internal class SetTextMatrix : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "Tm";
|
||||
@@ -33,7 +36,20 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
stream.WriteDecimal(Value[0]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Value[1]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Value[2]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Value[3]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Value[4]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteDecimal(Value[5]);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -3,6 +3,10 @@
|
||||
using System.IO;
|
||||
using Content;
|
||||
|
||||
/// <summary>
|
||||
/// Set the character spacing to a number expressed in unscaled text space units.
|
||||
/// Initial value: 0.
|
||||
/// </summary>
|
||||
internal class SetCharacterSpacing : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "Tc";
|
||||
@@ -25,7 +29,10 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
stream.WriteDecimal(Spacing);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -165,7 +165,7 @@
|
||||
|
||||
if (!font.TryGetBoundingAdvancedWidth(characterCode, out var width))
|
||||
{
|
||||
throw new InvalidFontFormatException($"Could not find advanced with for character named '{pair.Value}' with character code: {characterCode}.");
|
||||
width = font.TableRegister.HorizontalMetricsTable.AdvancedWidths[0];
|
||||
}
|
||||
|
||||
widths[pair.Key - firstCharacter] = new NumericToken(width * scaling);
|
||||
|
Reference in New Issue
Block a user