@@ -25,6 +25,7 @@ You should have received a copy of the GNU Affero General Public License
25
25
using System . IO ;
26
26
using System . Text ;
27
27
using iText . IO . Font ;
28
+ using iText . IO . Font . Otf ;
28
29
using iText . IO . Util ;
29
30
using iText . Kernel . Font ;
30
31
using iText . Kernel . Geom ;
@@ -47,6 +48,9 @@ public class WordWrapUnitTest : ExtendedITextTest {
47
48
public static readonly String REGULAR_FONT = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
48
49
. CurrentContext . TestDirectory ) + "/resources/itext/layout/fonts/NotoSans-Regular.ttf" ;
49
50
51
+ public static readonly String KHMER_FONT = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
52
+ . CurrentContext . TestDirectory ) + "/resources/itext/layout/fonts/KhmerOS.ttf" ;
53
+
50
54
// หากอากาศดีในวันพรุ่งนี้เราจะไปปิกนิก - one sentence, multiple words.
51
55
public const String THAI_TEXT = "\u0E2B \u0E32 \u0E01 \u0E2D \u0E32 \u0E01 \u0E32 \u0E28 \u0E14 \u0E35 " + "\u0E43 \u0E19 \u0E27 \u0E31 \u0E19 \u0E1E \u0E23 \u0E38 \u0E48 \u0E07 \u0E19 \u0E35 \u0E49 "
52
56
+ "\u0E40 \u0E23 \u0E32 \u0E08 \u0E30 \u0E44 \u0E1B \u0E1B \u0E34 \u0E01 \u0E19 \u0E34 \u0E01 " ;
@@ -285,9 +289,7 @@ public virtual void OneThaiWordSplitAcrossMultipleRenderersGetIndexAndLayoutResu
285
289
NUnit . Framework . Assert . AreEqual ( 5 , lastFittingChildRendererData . childIndex ) ;
286
290
NUnit . Framework . Assert . AreEqual ( LayoutResult . NOTHING , lastFittingChildRendererData . childLayoutResult . GetStatus
287
291
( ) ) ;
288
- float occupiedAreaWidth = lastFittingChildRendererData . childLayoutResult . GetOccupiedArea ( ) . GetBBox ( ) . GetWidth
289
- ( ) ;
290
- NUnit . Framework . Assert . AreEqual ( 500 , occupiedAreaWidth , 0.0001 ) ;
292
+ NUnit . Framework . Assert . IsNull ( lastFittingChildRendererData . childLayoutResult . GetOccupiedArea ( ) ) ;
291
293
}
292
294
293
295
[ NUnit . Framework . Test ]
@@ -595,8 +597,8 @@ public virtual void UpdateSpecialScriptLayoutResultsTextRendererWithSpecialScrip
595
597
[ NUnit . Framework . Test ]
596
598
public virtual void CurWidthZeroDecrement ( ) {
597
599
int oldNewChildPos = 1 ;
598
- float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( oldNewChildPos , oldNewChildPos , new LayoutResult
599
- ( 0 , null , null , null ) , new Dictionary < int , LayoutResult > ( ) ) ;
600
+ float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( oldNewChildPos , oldNewChildPos , new Dictionary
601
+ < int , LayoutResult > ( ) ) ;
600
602
NUnit . Framework . Assert . AreEqual ( 0.0f , decrement , 0.0001 ) ;
601
603
}
602
604
@@ -605,35 +607,30 @@ public virtual void CurWidthLayoutResultNothing() {
605
607
float widthOfNewNothingResult = 500 ;
606
608
LayoutArea occupiedArea = new LayoutArea ( 1 , new Rectangle ( 0 , 0 , widthOfNewNothingResult , 0 ) ) ;
607
609
LayoutResult oldResult = new LayoutResult ( LayoutResult . FULL , occupiedArea , null , null ) ;
608
- LayoutResult newResult = new LayoutResult ( LayoutResult . NOTHING , occupiedArea , null , null ) ;
609
610
float simpleWidth = 200 ;
610
611
LayoutResult simpleDecrement = new LayoutResult ( LayoutResult . FULL , new LayoutArea ( 1 , new Rectangle ( 0 , 0 , simpleWidth
611
612
, 0 ) ) , null , null ) ;
612
613
IDictionary < int , LayoutResult > specialScriptLayoutResults = new Dictionary < int , LayoutResult > ( ) ;
613
614
specialScriptLayoutResults . Put ( 0 , oldResult ) ;
614
615
// leave specialScriptLayoutResults.get(1) null, as if childRenderers.get(1) is floating
615
616
specialScriptLayoutResults . Put ( 2 , simpleDecrement ) ;
616
- float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( 3 , 0 , newResult , specialScriptLayoutResults
617
- ) ;
618
- NUnit . Framework . Assert . AreEqual ( 2 * widthOfNewNothingResult + simpleWidth , decrement , 0.00001 ) ;
617
+ float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( 3 , 0 , specialScriptLayoutResults ) ;
618
+ NUnit . Framework . Assert . AreEqual ( widthOfNewNothingResult + simpleWidth , decrement , 0.00001 ) ;
619
619
}
620
620
621
621
[ NUnit . Framework . Test ]
622
622
public virtual void CurWidthLayoutResultPartial ( ) {
623
623
float widthOfNewPartialResult = 500 ;
624
624
LayoutArea oldOccupiedArea = new LayoutArea ( 1 , new Rectangle ( 0 , 0 , widthOfNewPartialResult , 0 ) ) ;
625
- LayoutArea newOccupiedArea = new LayoutArea ( 1 , new Rectangle ( 0 , 0 , widthOfNewPartialResult / 2 , 0 ) ) ;
626
625
LayoutResult oldResult = new LayoutResult ( LayoutResult . FULL , oldOccupiedArea , null , null ) ;
627
- LayoutResult newResult = new LayoutResult ( LayoutResult . PARTIAL , newOccupiedArea , null , null ) ;
628
626
float simpleWidth = 200 ;
629
627
LayoutResult simpleDecrement = new LayoutResult ( LayoutResult . FULL , new LayoutArea ( 1 , new Rectangle ( 0 , 0 , simpleWidth
630
628
, 0 ) ) , null , null ) ;
631
629
IDictionary < int , LayoutResult > specialScriptLayoutResults = new Dictionary < int , LayoutResult > ( ) ;
632
630
specialScriptLayoutResults . Put ( 0 , oldResult ) ;
633
631
// leave specialScriptLayoutResults.get(1) null, as if childRenderers.get(1) is floating
634
632
specialScriptLayoutResults . Put ( 2 , simpleDecrement ) ;
635
- float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( 3 , 0 , newResult , specialScriptLayoutResults
636
- ) ;
633
+ float decrement = LineRenderer . GetCurWidthSpecialScriptsDecrement ( 3 , 0 , specialScriptLayoutResults ) ;
637
634
NUnit . Framework . Assert . AreEqual ( widthOfNewPartialResult + simpleWidth , decrement , 0.00001 ) ;
638
635
}
639
636
@@ -659,5 +656,53 @@ public virtual void UpdateFloatsOverflowedToNextLine() {
659
656
NUnit . Framework . Assert . AreEqual ( 1 , floatsOverflowedToNextLineIRenderers . Count ) ;
660
657
NUnit . Framework . Assert . AreEqual ( onlyFloatToRemain , floatsOverflowedToNextLineIRenderers [ 0 ] ) ;
661
658
}
659
+
660
+ [ NUnit . Framework . Test ]
661
+ public virtual void PossibleBreakWithinActualText ( ) {
662
+ PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new MemoryStream ( ) ) ) ;
663
+ Document document = new Document ( pdfDocument ) ;
664
+ LineRenderer lineRenderer = new LineRenderer ( ) ;
665
+ lineRenderer . SetParent ( document . GetRenderer ( ) ) ;
666
+ TextRenderer textRenderer = new TextRenderer ( new iText . Layout . Element . Text ( "" ) ) ;
667
+ IList < Glyph > glyphs = new List < Glyph > ( ) ;
668
+ glyphs . Add ( new Glyph ( 629 , 378 , new char [ ] { '\u17c3 ' } ) ) ;
669
+ glyphs . Add ( new Glyph ( 578 , 756 , new char [ ] { '\u1790 ' } ) ) ;
670
+ glyphs . Add ( new Glyph ( 386 , 0 , new char [ ] { '\u17d2 ' , '\u1784 ' } ) ) ;
671
+ glyphs . Add ( new Glyph ( 627 , 378 , new char [ ] { '\u17c1 ' } ) ) ;
672
+ glyphs . Add ( new Glyph ( 581 , 756 , new char [ ] { '\u1793 ' } ) ) ;
673
+ glyphs . Add ( new Glyph ( 633 , 512 , new char [ ] { '\u17c7 ' } ) ) ;
674
+ GlyphLine glyphLine = new GlyphLine ( glyphs ) ;
675
+ glyphLine . SetActualText ( 0 , 3 , "\u1790 \u17d2 \u1784 \u17c3 " ) ;
676
+ glyphLine . SetActualText ( 3 , 6 , "\u1793 \u17c1 \u17c7 " ) ;
677
+ textRenderer . SetText ( glyphLine , PdfFontFactory . CreateFont ( KHMER_FONT , PdfEncodings . IDENTITY_H ) ) ;
678
+ lineRenderer . AddChild ( textRenderer ) ;
679
+ IList < int > possibleBreakPoints = new List < int > ( JavaUtil . ArraysAsList ( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ) ;
680
+ lineRenderer . DistributePossibleBreakPointsOverSequentialTextRenderers ( 0 , 1 , possibleBreakPoints , new List <
681
+ int > ( ) ) ;
682
+ IList < int > distributed = ( ( TextRenderer ) lineRenderer . GetChildRenderers ( ) [ 0 ] ) . GetSpecialScriptsWordBreakPoints
683
+ ( ) ;
684
+ NUnit . Framework . Assert . AreEqual ( new List < int > ( JavaUtil . ArraysAsList ( 3 , 6 ) ) , distributed ) ;
685
+ }
686
+
687
+ [ NUnit . Framework . Test ]
688
+ public virtual void TrimFirstOnePossibleBreak ( ) {
689
+ PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new MemoryStream ( ) ) ) ;
690
+ Document document = new Document ( pdfDocument ) ;
691
+ PdfFont pdfFont = PdfFontFactory . CreateFont ( THAI_FONT , PdfEncodings . IDENTITY_H ) ;
692
+ // " อากาศ"
693
+ String thai = "\u0020 " + THAI_WORD ;
694
+ TextRenderer textRenderer = new TextRenderer ( new iText . Layout . Element . Text ( "" ) ) ;
695
+ textRenderer . SetProperty ( Property . FONT , pdfFont ) ;
696
+ textRenderer . SetText ( thai ) ;
697
+ textRenderer . SetSpecialScriptsWordBreakPoints ( new List < int > ( JavaUtil . ArraysAsList ( 1 ) ) ) ;
698
+ LineRenderer lineRenderer = new LineRenderer ( ) ;
699
+ lineRenderer . SetParent ( document . GetRenderer ( ) ) ;
700
+ lineRenderer . AddChild ( textRenderer ) ;
701
+ lineRenderer . TrimFirst ( ) ;
702
+ TextRenderer childTextRenderer = ( TextRenderer ) lineRenderer . GetChildRenderers ( ) [ 0 ] ;
703
+ NUnit . Framework . Assert . IsNotNull ( childTextRenderer . GetSpecialScriptsWordBreakPoints ( ) ) ;
704
+ NUnit . Framework . Assert . AreEqual ( 1 , childTextRenderer . GetSpecialScriptsWordBreakPoints ( ) . Count ) ;
705
+ NUnit . Framework . Assert . AreEqual ( - 1 , ( int ) childTextRenderer . GetSpecialScriptsWordBreakPoints ( ) [ 0 ] ) ;
706
+ }
662
707
}
663
708
}
0 commit comments