fix width and height order in jpeg parsing

height is before width, incorrect order caused adobe reader to draw image strangely.
This commit is contained in:
Eliot Jones
2020-03-15 18:02:46 +00:00
parent 7212b9e38c
commit 98bcc16e11
5 changed files with 18 additions and 4 deletions

View File

@@ -399,7 +399,7 @@
}
[Fact]
public void CanWriteSinglePageWithJpg()
public void CanWriteSinglePageWithJpeg()
{
var builder = new PdfDocumentBuilder();
var page = builder.AddPage(PageSize.A4);
@@ -417,7 +417,7 @@
page.AddJpeg(imageBytes, expectedBounds);
var bytes = builder.Build();
WriteFile(nameof(CanWriteSinglePageWithJpg), bytes);
WriteFile(nameof(CanWriteSinglePageWithJpeg), bytes);
using (var document = PdfDocument.Open(bytes))
{

View File

@@ -278,6 +278,9 @@
public static readonly NameToken If = new NameToken("IF");
public static readonly NameToken Im = new NameToken("IM");
public static readonly NameToken Image = new NameToken("Image");
public static readonly NameToken ImageB = new NameToken("ImageB");
public static readonly NameToken ImageC = new NameToken("ImageC");
public static readonly NameToken ImageI = new NameToken("ImageI");
public static readonly NameToken ImageMask = new NameToken("ImageMask");
public static readonly NameToken Index = new NameToken("Index");
public static readonly NameToken Indexed = new NameToken("Indexed");

View File

@@ -33,8 +33,8 @@
// ReSharper disable once UnusedVariable
var length = ReadShort(stream, shortBuffer);
var bpp = stream.ReadByte();
var width = ReadShort(stream, shortBuffer);
var height = ReadShort(stream, shortBuffer);
var width = ReadShort(stream, shortBuffer);
return new JpegInformation(width, height, bpp);
}

View File

@@ -142,6 +142,8 @@
var operations = pageContentParser.Parse(pageNumber, new ByteArrayInputBytes(contentBytes),
log);
var text = OtherEncodings.BytesAsLatin1String(contentBytes);
var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, rotation, pdfScanner,
pageContentParser,
filterProvider,

View File

@@ -247,9 +247,18 @@
context.WriteObject(memory, streamToken, image.Value.ObjectNumber);
}
var procSet = new List<NameToken>
{
NameToken.Create("PDF"),
NameToken.Text,
NameToken.ImageB,
NameToken.ImageC,
NameToken.ImageI
};
var resources = new Dictionary<NameToken, IToken>
{
{ NameToken.ProcSet, new ArrayToken(new []{ NameToken.Create("PDF"), NameToken.Create("Text") }) }
{ NameToken.ProcSet, new ArrayToken(procSet) }
};
if (fontsWritten.Count > 0)