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 7, 2024
2 parents e722be3 + 051c0c3 commit 4ab5adb
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 4 deletions.
20 changes: 20 additions & 0 deletions itext.tests/itext.io.tests/itext/io/font/TrueTypeFontTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,25 @@ public virtual void NotoSansScMapGlyphsCidsToGidsTest() {
NUnit.Framework.Assert.AreEqual(1, actualResult.Count);
NUnit.Framework.Assert.IsTrue(actualResult.Contains(charGidInFont));
}

[NUnit.Framework.Test]
public virtual void CmapPlatform0PlatEnc3Format4Test() {
FontProgram fontProgram = FontProgramFactory.CreateFont(SOURCE_FOLDER + "glyphs.ttf");
CheckCmapTableEntry(fontProgram, 'f', 2);
CheckCmapTableEntry(fontProgram, 'i', 3);
}

[NUnit.Framework.Test]
public virtual void CmapPlatform0PlatEnc3Format6Test() {
FontProgram fontProgram = FontProgramFactory.CreateFont(SOURCE_FOLDER + "glyphs-fmt-6.ttf");
CheckCmapTableEntry(fontProgram, 'f', 2);
CheckCmapTableEntry(fontProgram, 'i', 3);
}

private void CheckCmapTableEntry(FontProgram fontProgram, char uniChar, int expectedGlyphId) {
Glyph glyph = fontProgram.GetGlyph(uniChar);
NUnit.Framework.Assert.AreEqual(expectedGlyphId, glyph.GetCode());
NUnit.Framework.Assert.AreEqual(new char[] { uniChar }, glyph.GetUnicodeChars());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ This software uses the following test resources under the following licenses:
| NotoSansTC-Regular.otf | OFL-1.1 | OFL.txt | Based on commit 165c01b46ea533872e002e0785ff17e44f6d97d8 (30.04.2021) from repository: "https://github.com/googlefonts/noto-cjk"
| NotoSansSC-Regular.otf | OFL-1.1 | OFL.txt | Based on commit 165c01b46ea533872e002e0785ff17e44f6d97d8 (30.04.2021) from repository: "https://github.com/googlefonts/noto-cjk"
| NotoSansCJKjp-Bold.otf | OFL-1.1 | OFL.txt | Based on commit 165c01b46ea533872e002e0785ff17e44f6d97d8 (30.04.2021) from repository: "https://github.com/googlefonts/noto-cjk"
| Puritan2 | OFL-1.1 | OFL.txt |
| Puritan2 | OFL-1.1 | OFL.txt |
| glyphs.ttf, glyphs-fmt-6.ttf | MIT | Derived from https://github.com/RazrFalcon/ttf-parser/tree/337e7d1c08b06478a84c4345f4f289fc2cb9210c/tests/fonts-src |
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,41 @@ public virtual void NotoSansTcFontTest() {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpFilename, DESTINATION_FOLDER
));
}

[NUnit.Framework.Test]
public virtual void CmapPlatform0PlatEnc3Format4FontTest() {
String filename = DESTINATION_FOLDER + "cmapPlatform0PlatEnc3Format4FontTest.pdf";
String cmpFilename = SOURCE_FOLDER + "cmp_cmapPlatform0PlatEnc3Format4FontTest.pdf";
PdfWriter writer = CompareTool.CreateTestPdfWriter(filename);
writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
PdfDocument pdfDoc = new PdfDocument(writer);
PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "glyphs.ttf");
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
canvas.SaveState().BeginText().SetFontAndSize(font, 20).MoveText(36, 700).ShowText("===fff===iii===fi").EndText
().RestoreState();
canvas.Rectangle(100, 500, 100, 100).Fill();
canvas.Release();
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpFilename, DESTINATION_FOLDER
));
}

[NUnit.Framework.Test]
public virtual void CmapPlatform0PlatEnc3Format6FontTest() {
String filename = DESTINATION_FOLDER + "cmapPlatform0PlatEnc3Format6FontTest.pdf";
String cmpFilename = SOURCE_FOLDER + "cmp_cmapPlatform0PlatEnc3Format6FontTest.pdf";
PdfWriter writer = CompareTool.CreateTestPdfWriter(filename);
writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
PdfDocument pdfDoc = new PdfDocument(writer);
PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "glyphs-fmt-6.ttf");
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
canvas.SaveState().BeginText().SetFontAndSize(font, 20).MoveText(36, 700).ShowText("===fff===iii===").EndText
().RestoreState();
canvas.Rectangle(100, 500, 100, 100).Fill();
canvas.Release();
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpFilename, DESTINATION_FOLDER
));
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ This software uses the following test resources under the following licenses:
| cmr10.pfb | SIL OFL-1.1 | LICENSE-SIL-1.1.txt | https://www.ams.org/arc/resources/amsfonts-about.html (13.09.2023)
| cmr10.pfm | SIL OFL-1.1 | LICENSE-SIL-1.1.txt | https://www.ams.org/arc/resources/amsfonts-about.html (13.09.2023)
| SourceHanSansHW-Regular.otf | LICENCE-SIL-1.1.txt | https://github.com/adobe-fonts/source-han-sans/releases/tag/2.004R (File: Static Language Specific OTFs, path in zip folder:OTF/japanesHW) (07.09.2023)
| glyphs.ttf, glyphs-fmt-6.ttf | MIT | Derived from https://github.com/RazrFalcon/ttf-parser/tree/337e7d1c08b06478a84c4345f4f289fc2cb9210c/tests/fonts-src
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions itext/itext.io/itext/io/font/OpenTypeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ private void ReadCmapTable() {
int map31 = 0;
int map30 = 0;
int mapExt = 0;
int map03 = 0;
cmaps = new OpenTypeParser.CmapTable();
for (int k = 0; k < num_tables; ++k) {
int platId = raf.ReadUnsignedShort();
Expand All @@ -1025,6 +1026,11 @@ private void ReadCmapTable() {
if (platId == 1 && platSpecId == 0) {
map10 = offset;
}
else {
if (platId == 0 && platSpecId == 3) {
map03 = offset;
}
}
}
}
}
Expand All @@ -1049,6 +1055,26 @@ private void ReadCmapTable() {
}
}
}
if (map03 > 0) {
// Unicode platform, Unicode >2.0 semantics, expect format 4 or 6 subtable
raf.Seek(table_location[0] + map03);
int format = raf.ReadUnsignedShort();
// We treat this table as equivalent to (platformId = 3, encodingId = 1)
// for downstream processing, since both are intended to address the Unicode BMP.
// Note that only one of these encoding subtables is used at a time. If multiple encoding subtables
// are found, the ‘cmap’ parsing software determines which one to use.
switch (format) {
case 4: {
cmaps.cmap31 = ReadFormat4(false);
break;
}

case 6: {
cmaps.cmap31 = ReadFormat6();
break;
}
}
}
if (map31 > 0) {
raf.Seek(table_location[0] + map31);
int format = raf.ReadUnsignedShort();
Expand Down
Loading

0 comments on commit 4ab5adb

Please sign in to comment.