Skip to content

Commit cbcb9ab

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 32b257e + 4d88123 commit cbcb9ab

File tree

13 files changed

+51
-22
lines changed

13 files changed

+51
-22
lines changed

itext.tests/itext.layout.tests/itext/layout/HyphenateLayoutTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,20 @@ public virtual void HyphenSymbolTest01() {
244244
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
245245
, "diff"));
246246
}
247+
248+
[NUnit.Framework.Test]
249+
public virtual void WordsBreakingWordSoftHyphenTest() {
250+
String outFileName = destinationFolder + "wordsBreakingWordSoftHyphenTest.pdf";
251+
String cmpFileName = sourceFolder + "cmp_wordsBreakingWordSoftHyphenTest.pdf";
252+
String SOFT_HYPHEN = "\u00AD";
253+
String text = "Soft hyphen at the mid" + SOFT_HYPHEN + "dle,\nhyphen at the end: abcdef" + SOFT_HYPHEN + "ghijklmnopqrst\n"
254+
+ SOFT_HYPHEN + "hyphen at the beginning.";
255+
using (Document document = new Document(new PdfDocument(new PdfWriter(outFileName)))) {
256+
document.Add(new Paragraph(text).SetWidth(150).SetBorder(new SolidBorder(1)).SetHyphenation(new HyphenationConfig
257+
(1, 1)));
258+
}
259+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
260+
));
261+
}
247262
}
248263
}

itext.tests/itext.layout.tests/itext/layout/font/selectorstrategy/BestMatchFontSelectorStrategyTest.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public virtual void TwoDiacriticsInRowTest() {
3636
IList<Tuple2<GlyphLine, PdfFont>> result = strategy.GetGlyphLines("L with accent: \u004f\u0301\u0302 abc");
3737
NUnit.Framework.Assert.AreEqual(3, result.Count);
3838
NUnit.Framework.Assert.AreEqual("L with accent: ", result[0].GetFirst().ToString());
39-
NUnit.Framework.Assert.AreEqual("\u004f\u0301\u0302", result[1].GetFirst().ToString());
40-
NUnit.Framework.Assert.AreEqual(" abc", result[2].GetFirst().ToString());
39+
NUnit.Framework.Assert.AreEqual("\u004f\u0301\u0302 ", result[1].GetFirst().ToString());
40+
NUnit.Framework.Assert.AreEqual("abc", result[2].GetFirst().ToString());
4141
// Diacritics and symbol were separated, but the font is the same
4242
NUnit.Framework.Assert.AreEqual(result[0].GetSecond(), result[2].GetSecond());
4343
}
@@ -49,8 +49,8 @@ public virtual void OneDiacriticTest() {
4949
IList<Tuple2<GlyphLine, PdfFont>> result = strategy.GetGlyphLines("L with accent: \u004f\u0302 abc");
5050
NUnit.Framework.Assert.AreEqual(3, result.Count);
5151
NUnit.Framework.Assert.AreEqual("L with accent: ", result[0].GetFirst().ToString());
52-
NUnit.Framework.Assert.AreEqual("\u004f\u0302", result[1].GetFirst().ToString());
53-
NUnit.Framework.Assert.AreEqual(" abc", result[2].GetFirst().ToString());
52+
NUnit.Framework.Assert.AreEqual("\u004f\u0302 ", result[1].GetFirst().ToString());
53+
NUnit.Framework.Assert.AreEqual("abc", result[2].GetFirst().ToString());
5454
NUnit.Framework.Assert.AreNotEqual(result[0].GetSecond(), result[1].GetSecond());
5555
}
5656

@@ -75,8 +75,8 @@ public virtual void DiacriticFontDoesnotContainPreviousSymbolTest() {
7575
NUnit.Framework.Assert.AreEqual(6, result.Count);
7676
NUnit.Framework.Assert.AreEqual("Ми", result[0].GetFirst().ToString());
7777
NUnit.Framework.Assert.AreEqual("\u0301", result[1].GetFirst().ToString());
78-
NUnit.Framework.Assert.AreEqual("ръ", result[2].GetFirst().ToString());
79-
NUnit.Framework.Assert.AreEqual(" (mír", result[3].GetFirst().ToString());
78+
NUnit.Framework.Assert.AreEqual("ръ (", result[2].GetFirst().ToString());
79+
NUnit.Framework.Assert.AreEqual("mír", result[3].GetFirst().ToString());
8080
NUnit.Framework.Assert.AreEqual("ə", result[4].GetFirst().ToString());
8181
NUnit.Framework.Assert.AreEqual(")", result[5].GetFirst().ToString());
8282
NUnit.Framework.Assert.AreEqual(result[0].GetSecond(), result[2].GetSecond());
@@ -100,8 +100,8 @@ public virtual void SurrogatePairsTest() {
100100
IList<Tuple2<GlyphLine, PdfFont>> result = strategy.GetGlyphLines("text \uD800\uDF10\uD800\uDF00\uD800\uDF11 text"
101101
);
102102
NUnit.Framework.Assert.AreEqual(3, result.Count);
103-
NUnit.Framework.Assert.AreEqual("text", result[0].GetFirst().ToString());
104-
NUnit.Framework.Assert.AreEqual(" \uD800\uDF10\uD800\uDF00\uD800\uDF11 ", result[1].GetFirst().ToString());
103+
NUnit.Framework.Assert.AreEqual("text ", result[0].GetFirst().ToString());
104+
NUnit.Framework.Assert.AreEqual("\uD800\uDF10\uD800\uDF00\uD800\uDF11 ", result[1].GetFirst().ToString());
105105
NUnit.Framework.Assert.AreEqual("text", result[2].GetFirst().ToString());
106106
NUnit.Framework.Assert.AreEqual(result[0].GetSecond(), result[2].GetSecond());
107107
}
@@ -122,13 +122,21 @@ public virtual void ThreeFontWithSpacesTest() {
122122
IFontSelectorStrategy strategy = FontSelectorTestsUtil.CreateStrategyWithLimitedThreeFonts(new BestMatchFontSelectorStrategy.BestMatchFontSelectorStrategyFactory
123123
());
124124
IList<Tuple2<GlyphLine, PdfFont>> result = strategy.GetGlyphLines(" axadefa ");
125-
NUnit.Framework.Assert.AreEqual(6, result.Count);
125+
NUnit.Framework.Assert.AreEqual(5, result.Count);
126126
NUnit.Framework.Assert.AreEqual(" a", result[0].GetFirst().ToString());
127127
NUnit.Framework.Assert.AreEqual("x", result[1].GetFirst().ToString());
128128
NUnit.Framework.Assert.AreEqual("a", result[2].GetFirst().ToString());
129129
NUnit.Framework.Assert.AreEqual("def", result[3].GetFirst().ToString());
130-
NUnit.Framework.Assert.AreEqual("a", result[4].GetFirst().ToString());
131-
NUnit.Framework.Assert.AreEqual(" ", result[5].GetFirst().ToString());
130+
NUnit.Framework.Assert.AreEqual("a ", result[4].GetFirst().ToString());
131+
}
132+
133+
[NUnit.Framework.Test]
134+
public virtual void WindowsLineEndingsTest() {
135+
IFontSelectorStrategy strategy = FontSelectorTestsUtil.CreateStrategyWithFreeSans(new BestMatchFontSelectorStrategy.BestMatchFontSelectorStrategyFactory
136+
());
137+
IList<Tuple2<GlyphLine, PdfFont>> result = strategy.GetGlyphLines("Hello\r\n World!\r\n ");
138+
NUnit.Framework.Assert.AreEqual(1, result.Count);
139+
NUnit.Framework.Assert.AreEqual("Hello\r\n World!\r\n ", result[0].GetFirst().ToString());
132140
}
133141
}
134142
}

itext/itext.layout/itext/layout/font/selectorstrategy/AbstractFontSelectorStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public virtual IList<Tuple2<GlyphLine, PdfFont>> GetGlyphLines(String text) {
109109
if (codePoint > 0xFFFF) {
110110
i++;
111111
}
112-
if (IsCurrentFontCheckRequired() && (i != indexDiacritic - 1)) {
112+
if (IsCurrentFontCheckRequired() && (i != indexDiacritic - 1) && !iText.IO.Util.TextUtil.IsWhitespaceOrNonPrintable
113+
(codePoint)) {
113114
if (currentFont != MatchFont(codePoint, fontSelector, fontProvider, additionalFonts)) {
114115
breakRequested = true;
115116
}
@@ -191,8 +192,7 @@ protected internal virtual PdfFont MatchFont(int codePoint, FontSelector fontSel
191192
foreach (FontInfo fontInfo in fontSelector.GetFonts()) {
192193
if (fontInfo.GetFontUnicodeRange().Contains(codePoint)) {
193194
PdfFont temptFont = GetPdfFont(fontInfo, fontProvider, additionalFonts);
194-
Glyph glyph = temptFont.GetGlyph(codePoint);
195-
if (null != glyph && 0 != glyph.GetCode()) {
195+
if (temptFont.ContainsGlyph(codePoint)) {
196196
matchedFont = temptFont;
197197
break;
198198
}

itext/itext.layout/itext/layout/renderer/TextRenderer.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,20 +466,26 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
466466
for (int i = hyph.Length() - 1; i >= 0; i--) {
467467
String pre = hyph.GetPreHyphenText(i);
468468
String pos = hyph.GetPostHyphenText(i);
469-
float currentHyphenationChoicePreTextWidth = GetGlyphLineWidth(ConvertToGlyphLine(text.ToUnicodeString(currentTextPos
470-
, wordBounds[0]) + pre + hyphenationConfig.GetHyphenSymbol()), fontSize.GetValue(), hScale, characterSpacing
471-
, wordSpacing);
469+
char hyphen = hyphenationConfig.GetHyphenSymbol();
470+
String glyphLine = text.ToUnicodeString(currentTextPos, wordBounds[0]) + pre;
471+
if (font.ContainsGlyph(hyphen)) {
472+
glyphLine += hyphen;
473+
}
474+
float currentHyphenationChoicePreTextWidth = GetGlyphLineWidth(ConvertToGlyphLine(glyphLine), fontSize.GetValue
475+
(), hScale, characterSpacing, wordSpacing);
472476
if (currentLineWidth + currentHyphenationChoicePreTextWidth + italicSkewAddition + boldSimulationAddition
473477
<= layoutBox.GetWidth()) {
474478
hyphenationApplied = true;
475479
if (line.GetStart() == -1) {
476480
line.SetStart(currentTextPos);
477481
}
478482
line.SetEnd(Math.Max(line.GetEnd(), wordBounds[0] + pre.Length));
479-
GlyphLine lineCopy = line.Copy(line.GetStart(), line.GetEnd());
480-
lineCopy.Add(font.GetGlyph(hyphenationConfig.GetHyphenSymbol()));
481-
lineCopy.SetEnd(lineCopy.GetEnd() + 1);
482-
line = lineCopy;
483+
if (font.ContainsGlyph(hyphen)) {
484+
GlyphLine lineCopy = line.Copy(line.GetStart(), line.GetEnd());
485+
lineCopy.Add(font.GetGlyph(hyphen));
486+
lineCopy.SetEnd(lineCopy.GetEnd() + 1);
487+
line = lineCopy;
488+
}
483489
// TODO DEVSIX-7010 recalculate line properties in case of word hyphenation.
484490
// These values are based on whole word. Recalculate properly based on hyphenated part.
485491
currentLineAscender = Math.Max(currentLineAscender, nonBreakablePartMaxAscender);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
238107cd5532d937fc246b97f60c8f1599786f9d
1+
d7b7288459c53470547f639cf5386cb2636c2eca

0 commit comments

Comments
 (0)