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 Jan 10, 2024
2 parents b0e0781 + 05d1d9c commit 66fe498
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,24 @@ public virtual void ShortOctalDataAsTextTest() {
NUnit.Framework.Assert.AreEqual("EC", PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1)));
}
}

[NUnit.Framework.Test]
public virtual void NotDefaultCodespacesCyrillicTest() {
String inFile = sourceFolder + "notDefaultCodespacesCyrillic.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFile))) {
String extractedText = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1));
NUnit.Framework.Assert.IsTrue(extractedText.Contains("бронирование"));
NUnit.Framework.Assert.IsTrue(extractedText.Contains("From"));
}
}

[NUnit.Framework.Test]
public virtual void NotDefaultCodespacesChineseTest() {
String inFile = sourceFolder + "notDefaultCodespacesChinese.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFile))) {
String extractedText = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(1));
NUnit.Framework.Assert.IsTrue(extractedText.Contains("L3B 廠: 新竹科學工業園區新竹市東區力行二路 1 號"));
}
}
}
}
Binary file not shown.
Binary file not shown.
24 changes: 14 additions & 10 deletions itext/itext.kernel/itext/kernel/font/PdfType0Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,27 +742,31 @@ private static String GetOrdering(PdfDictionary cidFont) {
}

private static bool ContainsCodeInCodeSpaceRange(IList<byte[]> codeSpaceRanges, int code, int length) {
long unsignedCode = code & unchecked((int)(0xffffffff));
for (int i = 0; i < codeSpaceRanges.Count; i += 2) {
if (length == codeSpaceRanges[i].Length) {
int mask = 0xff;
int totalShift = 0;
byte[] low = codeSpaceRanges[i];
byte[] high = codeSpaceRanges[i + 1];
bool fitsIntoRange = true;
for (int ind = length - 1; ind >= 0; ind--, totalShift += 8, mask <<= 8) {
int actualByteValue = (code & mask) >> totalShift;
if (!(actualByteValue >= (0xff & low[ind]) && actualByteValue <= (0xff & high[ind]))) {
fitsIntoRange = false;
}
}
if (fitsIntoRange) {
long lowValue = BytesToLong(low);
long highValue = BytesToLong(high);
if (unsignedCode >= lowValue && unsignedCode <= highValue) {
return true;
}
}
}
return false;
}

private static long BytesToLong(byte[] bytes) {
long res = 0;
int shift = 0;
for (int i = bytes.Length - 1; i >= 0; --i) {
res += (bytes[i] & 0xff) << shift;
shift += 8;
}
return res;
}

private void FlushFontData() {
if (cidFontType == CID_FONT_TYPE_0) {
GetPdfObject().Put(PdfName.Type, PdfName.Font);
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bc6666faacd4ec5f4ac133a8d23fee1ee5e4884a
1c6199fc40db8637ee9e95bbe09585289e71182f

0 comments on commit 66fe498

Please sign in to comment.