Skip to content

Commit 887e211

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 7802f9a + c8e6369 commit 887e211

File tree

8 files changed

+82
-47
lines changed

8 files changed

+82
-47
lines changed

itext.tests/itext.layout.tests/itext/layout/DestinationTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
2323
using System;
24+
using System.Collections.Generic;
2425
using iText.Commons.Utils;
2526
using iText.Kernel.Pdf;
2627
using iText.Kernel.Utils;
@@ -48,7 +49,9 @@ public virtual void DestinationTest01() {
4849
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
4950
Document doc = new Document(pdfDoc);
5051
Text text = new Text(MessageFormatUtil.Format("Page {0}", 10));
51-
text.SetProperty(Property.DESTINATION, "p10");
52+
ICollection<Object> destinations = new HashSet<Object>();
53+
destinations.Add("p10");
54+
text.SetProperty(Property.DESTINATION, destinations);
5255
doc.Add(new Paragraph(text).SetFixedPosition(1, 549, 742, 40).SetMargin(0));
5356
doc.Close();
5457
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder

itext.tests/itext.layout.tests/itext/layout/LinkTest.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
2323
using System;
24+
using System.Collections.Generic;
2425
using iText.Commons.Datastructures;
2526
using iText.Commons.Utils;
2627
using iText.Kernel.Colors;
@@ -334,8 +335,9 @@ public virtual void IntraForwardLinkTest() {
334335
pdfDoc.GetPage(1).Flush();
335336
doc.Add(text);
336337
Paragraph customText = new Paragraph("Custom text");
337-
customText.SetProperty(Property.DESTINATION, new Tuple2<String, PdfDictionary>("custom", linkAnnotation.GetAction
338-
()));
338+
ICollection<Object> destinations = new HashSet<Object>();
339+
destinations.Add(new Tuple2<String, PdfDictionary>("custom", linkAnnotation.GetAction()));
340+
customText.SetProperty(Property.DESTINATION, destinations);
339341
doc.Add(customText);
340342
doc.Close();
341343
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
@@ -353,8 +355,9 @@ public virtual void IntraBackwardLinkTest() {
353355
PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).SetAction(PdfAction.CreateGoTo
354356
("custom"));
355357
Paragraph customText = new Paragraph("Custom text");
356-
customText.SetProperty(Property.DESTINATION, new Tuple2<String, PdfDictionary>("custom", linkAnnotation.GetAction
357-
()));
358+
ICollection<Object> destinations = new HashSet<Object>();
359+
destinations.Add(new Tuple2<String, PdfDictionary>("custom", linkAnnotation.GetAction()));
360+
customText.SetProperty(Property.DESTINATION, destinations);
358361
doc.Add(customText);
359362
doc.Add(new AreaBreak());
360363
pdfDoc.GetPage(1).Flush();
@@ -369,6 +372,22 @@ public virtual void IntraBackwardLinkTest() {
369372
, "diff"));
370373
}
371374

375+
[NUnit.Framework.Test]
376+
public virtual void LinkWithSetDestinationTest() {
377+
String outFileName = destinationFolder + "linkWithSetDestination.pdf";
378+
String cmpFileName = sourceFolder + "cmp_linkWithSetDestination.pdf";
379+
using (Document document = new Document(new PdfDocument(new PdfWriter(outFileName)))) {
380+
Link link = new Link("link", PdfAction.CreateGoTo("destination"));
381+
document.Add(new Paragraph().Add(link));
382+
document.Add(new AreaBreak());
383+
Paragraph target = new Paragraph("target");
384+
target.SetDestination("destination");
385+
document.Add(target);
386+
}
387+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
388+
, "diff"));
389+
}
390+
372391
[NUnit.Framework.Test]
373392
public virtual void DestinationToFlushedPageTest() {
374393
String outFileName = destinationFolder + "destinationToFlushedPage.pdf";

itext.tests/itext.layout.tests/itext/layout/PdfUA2Test.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
2323
using System;
24+
using System.Collections.Generic;
2425
using System.IO;
2526
using iText.Commons.Datastructures;
2627
using iText.Commons.Utils;
@@ -878,11 +879,13 @@ public virtual void CheckOutlinesAsStructureDestinationsTest() {
878879
PdfAction action11 = PdfAction.CreateGoTo("header1.1");
879880
header11Outline.AddAction(action11);
880881
Paragraph header1 = new Paragraph("header1 text");
881-
header1.SetProperty(Property.DESTINATION, new Tuple2<String, PdfDictionary>("header1", action1.GetPdfObject
882-
()));
882+
ICollection<Object> destinations1 = new HashSet<Object>();
883+
destinations1.Add(new Tuple2<String, PdfDictionary>("header1", action1.GetPdfObject()));
884+
header1.SetProperty(Property.DESTINATION, destinations1);
883885
Paragraph header11 = new Paragraph("header1.1 text");
884-
header11.SetProperty(Property.DESTINATION, new Tuple2<String, PdfDictionary>("header1.1", action11.GetPdfObject
885-
()));
886+
ICollection<Object> destinations2 = new HashSet<Object>();
887+
destinations2.Add(new Tuple2<String, PdfDictionary>("header1.1", action11.GetPdfObject()));
888+
header11.SetProperty(Property.DESTINATION, destinations2);
886889
document.Add(header1);
887890
document.Add(header11);
888891
}
Binary file not shown.
Binary file not shown.

itext/itext.layout/itext/layout/ElementPropertyContainer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,12 @@ public virtual T SetFontScript(UnicodeScript? script) {
939939
/// <param name="destination">the destination name to be created</param>
940940
/// <returns>this Element.</returns>
941941
public virtual T SetDestination(String destination) {
942-
SetProperty(Property.DESTINATION, destination);
942+
ICollection<Object> existingDestinations = this.GetProperty<ICollection<Object>>(Property.DESTINATION);
943+
if (existingDestinations == null) {
944+
existingDestinations = new HashSet<Object>();
945+
}
946+
existingDestinations.Add(destination);
947+
SetProperty(Property.DESTINATION, existingDestinations);
943948
return (T)(Object)this;
944949
}
945950

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,46 +1931,51 @@ protected internal virtual void ApplyRelativePositioningTranslation(bool reverse
19311931
}
19321932

19331933
protected internal virtual void ApplyDestination(PdfDocument document) {
1934-
Object destination = this.GetProperty<Object>(Property.DESTINATION);
1935-
if (destination == null) {
1934+
ICollection<Object> destinations = this.GetProperty<ICollection<Object>>(Property.DESTINATION);
1935+
if (destinations == null) {
19361936
return;
19371937
}
1938-
String destinationName = null;
1939-
PdfDictionary linkActionDict = null;
1940-
if (destination is String) {
1941-
destinationName = (String)destination;
1942-
}
1943-
else {
1944-
if (CHECK_TUPLE2_TYPE.GetType().Equals(destination.GetType())) {
1945-
// 'If' above is the only autoportable way it seems
1946-
Tuple2<String, PdfDictionary> destTuple = (Tuple2<String, PdfDictionary>)destination;
1947-
destinationName = destTuple.GetFirst();
1948-
linkActionDict = destTuple.GetSecond();
1938+
foreach (Object destination in destinations) {
1939+
String destinationName = null;
1940+
PdfDictionary linkActionDict = null;
1941+
if (destination == null) {
1942+
continue;
19491943
}
1950-
}
1951-
if (destinationName != null) {
1952-
int pageNumber = occupiedArea.GetPageNumber();
1953-
if (pageNumber < 1 || pageNumber > document.GetNumberOfPages()) {
1954-
ILogger logger = ITextLogManager.GetLogger(typeof(iText.Layout.Renderer.AbstractRenderer));
1955-
String logMessageArg = "Property.DESTINATION, which specifies this element location as destination, see ElementPropertyContainer.setDestination.";
1956-
logger.LogWarning(MessageFormatUtil.Format(iText.IO.Logs.IoLogMessageConstant.UNABLE_TO_APPLY_PAGE_DEPENDENT_PROP_UNKNOWN_PAGE_ON_WHICH_ELEMENT_IS_DRAWN
1957-
, logMessageArg));
1958-
return;
1944+
if (destination is String) {
1945+
destinationName = (String)destination;
1946+
}
1947+
else {
1948+
if (CHECK_TUPLE2_TYPE.GetType().Equals(destination.GetType())) {
1949+
// 'If' above is the only autoportable way it seems
1950+
Tuple2<String, PdfDictionary> destTuple = (Tuple2<String, PdfDictionary>)destination;
1951+
destinationName = destTuple.GetFirst();
1952+
linkActionDict = destTuple.GetSecond();
1953+
}
1954+
}
1955+
if (destinationName != null) {
1956+
int pageNumber = occupiedArea.GetPageNumber();
1957+
if (pageNumber < 1 || pageNumber > document.GetNumberOfPages()) {
1958+
ILogger logger = ITextLogManager.GetLogger(typeof(iText.Layout.Renderer.AbstractRenderer));
1959+
String logMessageArg = "Property.DESTINATION, which specifies this element location as destination, " + "see ElementPropertyContainer.setDestination.";
1960+
logger.LogWarning(MessageFormatUtil.Format(iText.IO.Logs.IoLogMessageConstant.UNABLE_TO_APPLY_PAGE_DEPENDENT_PROP_UNKNOWN_PAGE_ON_WHICH_ELEMENT_IS_DRAWN
1961+
, logMessageArg));
1962+
return;
1963+
}
1964+
PdfArray array = new PdfArray();
1965+
array.Add(document.GetPage(pageNumber).GetPdfObject());
1966+
array.Add(PdfName.XYZ);
1967+
array.Add(new PdfNumber(occupiedArea.GetBBox().GetX()));
1968+
array.Add(new PdfNumber(occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight()));
1969+
array.Add(new PdfNumber(0));
1970+
document.AddNamedDestination(destinationName, array.MakeIndirect(document));
1971+
}
1972+
bool isPdf20 = document.GetPdfVersion().CompareTo(PdfVersion.PDF_2_0) >= 0;
1973+
if (linkActionDict != null && isPdf20 && document.IsTagged()) {
1974+
// Add structure destination for the action for tagged pdf 2.0
1975+
PdfStructElem structElem = GetCurrentStructElem(document);
1976+
PdfStructureDestination dest = PdfStructureDestination.CreateFit(structElem);
1977+
linkActionDict.Put(PdfName.SD, dest.GetPdfObject());
19591978
}
1960-
PdfArray array = new PdfArray();
1961-
array.Add(document.GetPage(pageNumber).GetPdfObject());
1962-
array.Add(PdfName.XYZ);
1963-
array.Add(new PdfNumber(occupiedArea.GetBBox().GetX()));
1964-
array.Add(new PdfNumber(occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight()));
1965-
array.Add(new PdfNumber(0));
1966-
document.AddNamedDestination(destinationName, array.MakeIndirect(document));
1967-
}
1968-
bool isPdf20 = document.GetPdfVersion().CompareTo(PdfVersion.PDF_2_0) >= 0;
1969-
if (linkActionDict != null && isPdf20 && document.IsTagged()) {
1970-
// Add structure destination for the action for tagged pdf 2.0
1971-
PdfStructElem structElem = GetCurrentStructElem(document);
1972-
PdfStructureDestination dest = PdfStructureDestination.CreateFit(structElem);
1973-
linkActionDict.Put(PdfName.SD, dest.GetPdfObject());
19741979
}
19751980
DeleteProperty(Property.DESTINATION);
19761981
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c6ce1c78908ccf7588c16c0bf87d9b7870c0728a
1+
06f230eeee87c891d640d95c0ffc6656d378ce32

0 commit comments

Comments
 (0)