mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-06-28 15:30:17 +08:00
fix a bug with tokenization without spaces before string
This commit is contained in:
parent
10b0f87f09
commit
ba8d2f5b1d
@ -148,6 +148,29 @@ endobj";
|
|||||||
AssertCorrectToken<NumericToken, decimal>(array.Data[array.Data.Count - 2], 1.9m);
|
AssertCorrectToken<NumericToken, decimal>(array.Data[array.Data.Count - 2], 1.9m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ScansStringWithoutWhitespacePreceding()
|
||||||
|
{
|
||||||
|
const string s = @"T*() Tj
|
||||||
|
-91";
|
||||||
|
|
||||||
|
var tokens = new List<IToken>();
|
||||||
|
|
||||||
|
var scanner = scannerFactory(StringBytesTestConverter.Convert(s, false).Bytes);
|
||||||
|
|
||||||
|
while (scanner.MoveNext())
|
||||||
|
{
|
||||||
|
tokens.Add(scanner.CurrentToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(4, tokens.Count);
|
||||||
|
|
||||||
|
AssertCorrectToken<OperatorToken, string>(tokens[0], "T*");
|
||||||
|
AssertCorrectToken<StringToken, string>(tokens[1], "");
|
||||||
|
AssertCorrectToken<OperatorToken, string>(tokens[2], "Tj");
|
||||||
|
AssertCorrectToken<NumericToken, decimal>(tokens[3], -91);
|
||||||
|
}
|
||||||
|
|
||||||
private static void AssertCorrectToken<T, TData>(IToken token, TData expected) where T : IDataToken<TData>
|
private static void AssertCorrectToken<T, TData>(IToken token, TData expected) where T : IDataToken<TData>
|
||||||
{
|
{
|
||||||
var cast = Assert.IsType<T>(token);
|
var cast = Assert.IsType<T>(token);
|
||||||
|
@ -31,10 +31,11 @@
|
|||||||
|
|
||||||
public IFont Generate(PdfDictionary dictionary, IRandomAccessRead reader, bool isLenientParsing)
|
public IFont Generate(PdfDictionary dictionary, IRandomAccessRead reader, bool isLenientParsing)
|
||||||
{
|
{
|
||||||
var usingStandard14Only = !dictionary.ContainsKey(CosName.FIRST_CHAR);
|
var usingStandard14Only = !dictionary.ContainsKey(CosName.FIRST_CHAR) || !dictionary.ContainsKey(CosName.WIDTHS);
|
||||||
|
|
||||||
if (usingStandard14Only)
|
if (usingStandard14Only)
|
||||||
{
|
{
|
||||||
|
// TODO: some fonts combine standard 14 font with other metrics.
|
||||||
if (!dictionary.TryGetName(CosName.BASE_FONT, out var standard14Name))
|
if (!dictionary.TryGetName(CosName.BASE_FONT, out var standard14Name))
|
||||||
{
|
{
|
||||||
throw new InvalidFontFormatException($"The Type 1 font did not contain a first character entry but also did not reference a standard 14 font: {dictionary}");
|
throw new InvalidFontFormatException($"The Type 1 font did not contain a first character entry but also did not reference a standard 14 font: {dictionary}");
|
||||||
|
@ -5,8 +5,10 @@ namespace UglyToad.PdfPig.Graphics
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Cos;
|
using Cos;
|
||||||
|
using Exceptions;
|
||||||
using Operations;
|
using Operations;
|
||||||
using Operations.TextShowing;
|
using Operations.TextShowing;
|
||||||
|
using Operations.TextState;
|
||||||
using Tokenization.Tokens;
|
using Tokenization.Tokens;
|
||||||
|
|
||||||
internal class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
|
internal class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
|
||||||
@ -75,6 +77,14 @@ namespace UglyToad.PdfPig.Graphics
|
|||||||
var array = operands.ToArray();
|
var array = operands.ToArray();
|
||||||
|
|
||||||
return new ShowTextsWithPositioning(array);
|
return new ShowTextsWithPositioning(array);
|
||||||
|
case SetFontAndSize.Symbol:
|
||||||
|
if (operands.Count == 2 && operands[0] is NameToken name && operands[1] is NumericToken size)
|
||||||
|
{
|
||||||
|
return new SetFontAndSize(name.Data, size.Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
var information = string.Join(", ", operands.Select(x => x.ToString()));
|
||||||
|
throw new PdfDocumentFormatException($"Attempted to set font with wrong number of parameters: [{information}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!operations.TryGetValue(op.Data, out Type operationType))
|
if (!operations.TryGetValue(op.Data, out Type operationType))
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to document level information for this PDF document as well as access to the <see cref="T:UglyToad.PdfPig.Content.Page" />s contained in the document.
|
/// Provides access to document level information for this PDF document as well as access to the <see cref="T:UglyToad.PdfPig.Content.Page"/>s contained in the document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PdfDocument : IDisposable
|
public class PdfDocument : IDisposable
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
|
|
||||||
if (inputBytes.CurrentByte == '<' || inputBytes.CurrentByte == '['
|
if (inputBytes.CurrentByte == '<' || inputBytes.CurrentByte == '['
|
||||||
|| inputBytes.CurrentByte == '/' || inputBytes.CurrentByte == ']'
|
|| inputBytes.CurrentByte == '/' || inputBytes.CurrentByte == ']'
|
||||||
|| inputBytes.CurrentByte == '>')
|
|| inputBytes.CurrentByte == '>' || inputBytes.CurrentByte == '('
|
||||||
|
|| inputBytes.CurrentByte == ')')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
1
tools/build.cmd
Normal file
1
tools/build.cmd
Normal file
@ -0,0 +1 @@
|
|||||||
|
msbuild /t:pack "../src/UglyToad.PdfPig/UglyToad.PdfPig.csproj" /p:Configuration=Release /p:PackageOutputPath="../../releases"
|
Loading…
Reference in New Issue
Block a user