Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Aug 13, 2024
2 parents 3606f48 + 5898a03 commit 6447d51
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public virtual void InlineImagesTest03() {

[NUnit.Framework.Test]
public virtual void InlineImagesPngTest() {
//TODO update cmp-files after DEVSIX-3564 will be fixed
String filename = "inlineImagePng.pdf";
PdfDocument document = new PdfDocument(CompareTool.CreateTestPdfWriter(destinationFolder + filename));
PdfPage page = document.AddNewPage();
Expand All @@ -159,7 +158,6 @@ public virtual void InlineImagesPngTest() {

[NUnit.Framework.Test]
public virtual void InlineImagesPngErrorWhileOpenTest() {
//TODO update cmp-files after DEVSIX-3564 will be fixed
String filename = "inlineImagePngErrorWhileOpen.pdf";
PdfDocument document = new PdfDocument(CompareTool.CreateTestPdfWriter(destinationFolder + filename));
PdfPage page = document.AddNewPage();
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@ protected internal virtual void AddInlineImage(PdfImageXObject imageXObject, flo
PdfOutputStream os = contentStream.GetOutputStream();
os.WriteBytes(BI);
byte[] imageBytes = imageXObject.GetPdfObject().GetBytes(false);
SaveColorSpaceToPageResourcesIfNeeded(imageXObject.GetPdfObject());
foreach (KeyValuePair<PdfName, PdfObject> entry in imageXObject.GetPdfObject().EntrySet()) {
PdfName key = entry.Key;
if (!PdfName.Type.Equals(key) && !PdfName.Subtype.Equals(key) && !PdfName.Length.Equals(key)) {
Expand All @@ -2141,6 +2142,22 @@ protected internal virtual void AddInlineImage(PdfImageXObject imageXObject, flo
RestoreState();
}

private void SaveColorSpaceToPageResourcesIfNeeded(PdfStream image) {
PdfObject colorSpace = image.Get(PdfName.ColorSpace);
//The colour space specified by the ColorSpace (or CS) entry shall be one of the standard device colour spaces
//(DeviceGray, DeviceRGB, or DeviceCMYK).
if (colorSpace == null || colorSpace.Equals(PdfName.DeviceGray) || colorSpace.Equals(PdfName.DeviceRGB) ||
colorSpace.Equals(PdfName.DeviceCMYK)) {
return;
}
//PDF 1.2: the value of the ColorSpace entry may also be the name of a colour space in the ColorSpace
//subdictionary of the current resource dictionary. In this case, the name may designate any colour space
//that can be used with an image XObject.
PdfName name = resources.AddColorSpace(colorSpace);
image.Remove(PdfName.ColorSpace);
image.Put(PdfName.ColorSpace, name);
}

/// <summary>
/// Adds
/// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/>
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fdf0981cf57bd8f4e1b26df8abe030126ca2a0ac
e441c12a214f5ed043403b9377dc71061e7a0d78

0 comments on commit 6447d51

Please sign in to comment.