@@ -40,12 +40,16 @@ source product.
4040For more information, please contact iText Software Corp. at this
41414242*/
43+ using System ;
4344using iText . Kernel . Geom ;
4445using iText . Kernel . Pdf ;
4546using iText . Layout ;
4647using iText . Layout . Element ;
48+ using iText . Layout . Font ;
4749using iText . Layout . Layout ;
50+ using iText . Layout . Properties ;
4851using iText . Test ;
52+ using iText . Test . Attributes ;
4953
5054namespace iText . Layout . Renderer {
5155 public class TextRendererTest : ExtendedITextTest {
@@ -66,5 +70,42 @@ public virtual void NextRendererTest() {
6670 LayoutResult result2 = textRenderer2 . Layout ( layoutContext ) ;
6771 NUnit . Framework . Assert . AreEqual ( result1 . GetOccupiedArea ( ) , result2 . GetOccupiedArea ( ) ) ;
6872 }
73+
74+ [ NUnit . Framework . Test ]
75+ [ LogMessage ( iText . IO . LogMessageConstant . FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT ) ]
76+ public virtual void SetTextException ( ) {
77+ String val = "other text" ;
78+ String fontName = "Helvetica" ;
79+ TextRenderer rend = ( TextRenderer ) new Text ( "basic text" ) . GetRenderer ( ) ;
80+ FontProvider fp = new FontProvider ( ) ;
81+ fp . AddFont ( fontName ) ;
82+ rend . SetProperty ( Property . FONT_PROVIDER , fp ) ;
83+ rend . SetProperty ( Property . FONT , fontName ) ;
84+ rend . SetText ( val ) ;
85+ NUnit . Framework . Assert . AreEqual ( val , rend . GetText ( ) . ToString ( ) ) ;
86+ }
87+
88+ /// <summary>
89+ /// This test assumes that absolute positioning for
90+ /// <see cref="iText.Layout.Element.Text"/>
91+ /// elements is
92+ /// not supported. Adding this support is the subject of DEVSIX-1393.
93+ /// </summary>
94+ [ NUnit . Framework . Test ]
95+ [ LogMessage ( iText . IO . LogMessageConstant . FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT ) ]
96+ public virtual void SetFontAsText ( ) {
97+ PdfDocument pdfDoc = new PdfDocument ( new PdfWriter ( new ByteBufferOutputStream ( ) ) ) ;
98+ pdfDoc . AddNewPage ( ) ;
99+ Document doc = new Document ( pdfDoc ) ;
100+ Text txt = new Text ( "text" ) ;
101+ txt . SetProperty ( Property . POSITION , LayoutPosition . ABSOLUTE ) ;
102+ txt . SetProperty ( Property . TOP , 5f ) ;
103+ FontProvider fp = new FontProvider ( ) ;
104+ fp . AddFont ( "Helvetica" ) ;
105+ txt . SetProperty ( Property . FONT_PROVIDER , fp ) ;
106+ txt . SetFont ( "Helvetica" ) ;
107+ doc . Add ( new Paragraph ( ) . Add ( txt ) ) ;
108+ doc . Close ( ) ;
109+ }
69110 }
70111}
0 commit comments