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 Sep 14, 2023
2 parents 3da10f3 + 2501a75 commit 2618ff1
Show file tree
Hide file tree
Showing 40 changed files with 713 additions and 248 deletions.
1 change: 1 addition & 0 deletions itext.tests/itext.io.tests/itext.io.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ItemGroup>
<ProjectReference Include="..\..\itext\itext.io\itext.io.csproj" />
<ProjectReference Include="..\..\itext\itext.pdftest\itext.pdftest.csproj" />
<ProjectReference Include="..\..\itext\itext.font-asian\itext.font-asian.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.NET.Test.Sdk">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using iText.IO.Font.Cmap;
using iText.Test;

namespace iText.IO.Font {
[NUnit.Framework.Category("UnitTest")]
public class CjkResourceLoaderNoFontAsianTest : ExtendedITextTest {
// Android-Conversion-Skip-File (TODO DEVSIX-7376 investigate why CjkResourceLoaderNoFontAsianTest is skipped on Android)
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
// Here we mimic the absence of font asian
CjkResourceLoader.SetCmapLocation(new CjkResourceLoaderNoFontAsianTest.DummyCMapLocationResource());
}

[NUnit.Framework.OneTimeTearDown]
public static void AfterClass() {
CjkResourceLoader.SetCmapLocation(new CMapLocationResource());
}

[NUnit.Framework.Test]
public virtual void GetCompatibleCidFontNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return null.
NUnit.Framework.Assert.IsNull(CjkResourceLoader.GetCompatibleCidFont("78-RKSJ-V"));
}

[NUnit.Framework.Test]
public virtual void IsPredefinedCidFontNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return false.
NUnit.Framework.Assert.IsFalse(CjkResourceLoader.IsPredefinedCidFont("KozMinPro-Regular"));
}

[NUnit.Framework.Test]
public virtual void GetCompatibleCmapsNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return null.
NUnit.Framework.Assert.IsNull(CjkResourceLoader.GetCompatibleCmaps("HeiseiKakuGo-W5"));
}

[NUnit.Framework.Test]
public virtual void GetRegistryNamesNoFontAsian() {
// Without font-asian module in the class path
// registry names collection is expected to be empty.
NUnit.Framework.Assert.IsTrue(CjkResourceLoader.GetRegistryNames().IsEmpty());
}

[NUnit.Framework.Test]
public virtual void GetCid2UniCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => CjkResourceLoader.GetCid2UniCmap
("UniJIS-UTF16-H"));
}

[NUnit.Framework.Test]
public virtual void GetUni2CidCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => CjkResourceLoader.GetUni2CidCmap
("UniJIS-UTF16-H"));
}

[NUnit.Framework.Test]
public virtual void GetByte2CidCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => CjkResourceLoader.GetByte2CidCmap
("78ms-RKSJ-H"));
}

[NUnit.Framework.Test]
public virtual void GetCid2ByteCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => CjkResourceLoader.GetCidToCodepointCmap
("78ms-RKSJ-H"));
}

private class DummyCMapLocationResource : CMapLocationResource {
public override String GetLocationPath() {
return base.GetLocationPath() + "dummy/path/";
}
}
}
}
86 changes: 86 additions & 0 deletions itext.tests/itext.io.tests/itext/io/font/CjkResourceLoaderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using iText.IO.Font.Cmap;
using iText.Test;

namespace iText.IO.Font {
[NUnit.Framework.Category("IntegrationTest")]
public class CjkResourceLoaderTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void GetCompatibleCidFont() {
String expected = "HeiseiMin-W3";
String compatibleCidFont = CjkResourceLoader.GetCompatibleCidFont("78-RKSJ-V");
NUnit.Framework.Assert.AreEqual(expected, compatibleCidFont);
}

[NUnit.Framework.Test]
public virtual void GetCompatibleCmaps() {
ICollection<String> compatibleCmaps = CjkResourceLoader.GetCompatibleCmaps("HeiseiKakuGo-W5");
NUnit.Framework.Assert.AreEqual(66, compatibleCmaps.Count);
NUnit.Framework.Assert.IsTrue(compatibleCmaps.Contains("78-RKSJ-V"));
}

[NUnit.Framework.Test]
public virtual void GetRegistryNames() {
IDictionary<String, ICollection<String>> registryNames = CjkResourceLoader.GetRegistryNames();
NUnit.Framework.Assert.AreEqual(9, registryNames.Count);
NUnit.Framework.Assert.IsTrue(registryNames.ContainsKey("Adobe_Japan1"));
NUnit.Framework.Assert.IsTrue(registryNames.Get("Adobe_Japan1").Contains("78-RKSJ-V"));
}

[NUnit.Framework.Test]
public virtual void GetCid2UniCMap() {
CMapCidUni cid2UniCmap = CjkResourceLoader.GetCid2UniCmap("UniJIS-UTF16-H");
NUnit.Framework.Assert.AreEqual(0x00b5, cid2UniCmap.Lookup(159));
}

[NUnit.Framework.Test]
public virtual void GetUni2CidCMap() {
CMapCodepointToCid uni2CidCmap = CjkResourceLoader.GetCodepointToCidCmap("UniJIS-UTF16-H");
NUnit.Framework.Assert.AreEqual(159, uni2CidCmap.Lookup(0x00b5));
}

[NUnit.Framework.Test]
public virtual void GetByte2CidCMap() {
CMapByteCid byte2CidCmap = CjkResourceLoader.GetByte2CidCmap("78ms-RKSJ-H");
int byteCode = 0x94e0;
char cid = (char)7779;
byte[] byteCodeBytes = new byte[] { (byte)((byteCode & 0xFF00) >> 8), (byte)(byteCode & 0xFF) };
String actual = byte2CidCmap.DecodeSequence(byteCodeBytes, 0, 2);
String expected = new String(new char[] { cid });
NUnit.Framework.Assert.AreEqual(expected, actual);
}

[NUnit.Framework.Test]
public virtual void GetCid2ByteCMap() {
CMapCidToCodepoint cid2Byte = CjkResourceLoader.GetCidToCodepointCmap("78ms-RKSJ-H");
int byteCode = 0x94e0;
int cid = 7779;
byte[] actual = cid2Byte.Lookup(cid);
byte[] expected = new byte[] { (byte)((byteCode & 0xFF00) >> 8), (byte)(byteCode & 0xFF) };
NUnit.Framework.Assert.AreEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ You should have received a copy of the GNU Affero General Public License

namespace iText.IO.Font {
[NUnit.Framework.Category("UnitTest")]
public class FontCacheNoFontAsianTest : ExtendedITextTest {
// Android-Conversion-Skip-File (TODO DEVSIX-7376 investigate why FontCacheNoFontAsianTest is skipped on Android)
public class FontCacheTest : ExtendedITextTest {
[NUnit.Framework.SetUp]
public virtual void Before() {
FontCache.ClearSavedFonts();
Expand All @@ -37,7 +36,7 @@ public virtual void Before() {
public virtual void ClearFontCacheTest() {
String fontName = "FreeSans.ttf";
NUnit.Framework.Assert.IsNull(FontCache.GetFont(fontName));
FontProgram fontProgram = new FontCacheNoFontAsianTest.FontProgramMock();
FontProgram fontProgram = new FontCacheTest.FontProgramMock();
FontCache.SaveFont(fontProgram, fontName);
NUnit.Framework.Assert.AreEqual(fontProgram, FontCache.GetFont(fontName));
FontCache.ClearSavedFonts();
Expand All @@ -51,7 +50,7 @@ public virtual void FontStringTtcCacheKeyTest() {
FontCacheKey ttc1 = FontCacheKey.Create(fontName, 1);
NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc1));
FontProgram fontProgram = new FontCacheNoFontAsianTest.FontProgramMock();
FontProgram fontProgram = new FontCacheTest.FontProgramMock();
FontCache.SaveFont(fontProgram, ttc1);
NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
NUnit.Framework.Assert.AreEqual(fontProgram, FontCache.GetFont(ttc1));
Expand All @@ -68,75 +67,15 @@ public virtual void FontBytesTtcCacheKeyTest() {
NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
NUnit.Framework.Assert.IsNull(FontCache.GetFont(otherTtc0));
NUnit.Framework.Assert.IsNull(FontCache.GetFont(normal));
FontProgram otherTtc0MockFontProgram = new FontCacheNoFontAsianTest.FontProgramMock();
FontProgram normalMockFontProgram = new FontCacheNoFontAsianTest.FontProgramMock();
FontProgram otherTtc0MockFontProgram = new FontCacheTest.FontProgramMock();
FontProgram normalMockFontProgram = new FontCacheTest.FontProgramMock();
FontCache.SaveFont(otherTtc0MockFontProgram, otherTtc0);
FontCache.SaveFont(normalMockFontProgram, normal);
NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
NUnit.Framework.Assert.AreEqual(otherTtc0MockFontProgram, FontCache.GetFont(otherTtc0));
NUnit.Framework.Assert.AreEqual(normalMockFontProgram, FontCache.GetFont(normal));
}

[NUnit.Framework.Test]
public virtual void GetCompatibleCidFontNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return null.
NUnit.Framework.Assert.IsNull(FontCache.GetCompatibleCidFont("78-RKSJ-V"));
}

[NUnit.Framework.Test]
public virtual void IsPredefinedCidFontNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return false.
NUnit.Framework.Assert.IsFalse(FontCache.IsPredefinedCidFont("78-RKSJ-V"));
}

[NUnit.Framework.Test]
public virtual void GetCompatibleCmapsNoFontAsian() {
// Without font-asian module in the class path
// any value passed into a method is expected to return null.
NUnit.Framework.Assert.IsNull(FontCache.GetCompatibleCmaps("HeiseiKakuGo-W5"));
}

[NUnit.Framework.Test]
public virtual void GetRegistryNamesNoFontAsian() {
// Without font-asian module in the class path
// registry names collection is expected to be empty.
NUnit.Framework.Assert.IsTrue(FontCache.GetRegistryNames().IsEmpty());
}

[NUnit.Framework.Test]
public virtual void GetCid2UniCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => FontCache.GetCid2UniCmap("UniJIS-UTF16-H"
));
}

[NUnit.Framework.Test]
public virtual void GetUni2CidCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => FontCache.GetUni2CidCmap("UniJIS-UTF16-H"
));
}

[NUnit.Framework.Test]
public virtual void GetByte2CidCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => FontCache.GetByte2CidCmap("78ms-RKSJ-H"
));
}

[NUnit.Framework.Test]
public virtual void GetCid2ByteCMapNoFontAsian() {
// Without font-asian module in the class path
// no CMap can be found.
NUnit.Framework.Assert.Catch(typeof(iText.IO.Exceptions.IOException), () => FontCache.GetCidToCodepointCmap
("78ms-RKSJ-H"));
}

private class FontProgramMock : FontProgram {
public override int GetPdfFontFlags() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using iText.Test;

namespace iText.IO.Font {
[NUnit.Framework.Category("UnitTest")]
public class FontProgramDescriptorFactoryTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void KozminNamesTest() {
FontProgramDescriptor descriptor = FontProgramDescriptorFactory.FetchDescriptor("KozMinPro-Regular");
NUnit.Framework.Assert.AreEqual("KozMinPro-Regular", descriptor.GetFontName());
NUnit.Framework.Assert.AreEqual("KozMinPro-Regular".ToLowerInvariant(), descriptor.GetFullNameLowerCase());
NUnit.Framework.Assert.AreEqual(400, descriptor.GetFontWeight());
}

[NUnit.Framework.Test]
public virtual void HelveticaNamesTest() {
FontProgramDescriptor descriptor = FontProgramDescriptorFactory.FetchDescriptor("Helvetica");
NUnit.Framework.Assert.AreEqual("Helvetica", descriptor.GetFontName());
NUnit.Framework.Assert.AreEqual("helvetica", descriptor.GetFullNameLowerCase());
NUnit.Framework.Assert.AreEqual("helvetica", descriptor.GetFullNameLowerCase());
NUnit.Framework.Assert.AreEqual(500, descriptor.GetFontWeight());
}
}
}
18 changes: 18 additions & 0 deletions itext.tests/itext.io.tests/itext/io/font/FontProgramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Utils;
using iText.IO.Exceptions;
using iText.IO.Font.Constants;
using iText.IO.Font.Otf;
using iText.Test;

namespace iText.IO.Font {
Expand Down Expand Up @@ -70,5 +71,22 @@ public virtual void RegisterDirectoryType1Test() {
NUnit.Framework.Assert.IsNotNull(computerModern);
NUnit.Framework.Assert.IsNotNull(cmr10);
}

[NUnit.Framework.Test]
public virtual void CidFontWithCmapTest() {
char space = ' ';
FontProgram fp = FontProgramFactory.CreateFont("KozMinPro-Regular", "UniJIS-UCS2-HW-H", true);
Glyph glyph = fp.GetGlyph(space);
NUnit.Framework.Assert.AreEqual(new char[] { space }, glyph.GetUnicodeChars());
NUnit.Framework.Assert.AreEqual(32, glyph.GetUnicode());
NUnit.Framework.Assert.AreEqual(231, glyph.GetCode());
NUnit.Framework.Assert.AreEqual(500, glyph.GetWidth());
fp = FontProgramFactory.CreateFont("KozMinPro-Regular", null, true);
glyph = fp.GetGlyph(space);
NUnit.Framework.Assert.AreEqual(new char[] { space }, glyph.GetUnicodeChars());
NUnit.Framework.Assert.AreEqual(32, glyph.GetUnicode());
NUnit.Framework.Assert.AreEqual(1, glyph.GetCode());
NUnit.Framework.Assert.AreEqual(278, glyph.GetWidth());
}
}
}
Loading

0 comments on commit 2618ff1

Please sign in to comment.