Skip to content

Commit 6a55211

Browse files
Benoit Lagaeitext-teamcity
authored andcommitted
Merge branch 'hotfix/fontstring' into develop
Autoported commit. Original commit hash: [09282149a]
2 parents 600a2ca + c602e81 commit 6a55211

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

itext.tests/itext.layout.tests/itext/layout/renderer/TextRendererTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ source product.
4040
For more information, please contact iText Software Corp. at this
4141
4242
*/
43+
using System;
4344
using iText.Kernel.Geom;
4445
using iText.Kernel.Pdf;
4546
using iText.Layout;
4647
using iText.Layout.Element;
48+
using iText.Layout.Font;
4749
using iText.Layout.Layout;
50+
using iText.Layout.Properties;
4851
using iText.Test;
52+
using iText.Test.Attributes;
4953

5054
namespace 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
}

itext/itext.io/itext/io/LogMessageConstant.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public sealed class LogMessageConstant {
8686

8787
public const String FORBID_RELEASE_IS_SET = "ForbidRelease flag is set and release is called. Releasing will not be performed.";
8888

89+
public const String FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT = "The Font Property must be a PdfFont object";
90+
8991
public const String FORM_FIELD_WAS_FLUSHED = "A form field was flushed. There's no way to create this field in the AcroForm dictionary.";
9092

9193
public const String IMAGE_HAS_AMBIGUOUS_SCALE = "The image cannot be auto scaled and scaled by a certain parameter simultaneously";

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,14 @@ private bool IsGlyphPartOfWordForHyphenation(Glyph g) {
12381238

12391239
private void UpdateFontAndText() {
12401240
if (strToBeConverted != null) {
1241-
font = GetPropertyAsFont(Property.FONT);
1241+
try {
1242+
font = GetPropertyAsFont(Property.FONT);
1243+
}
1244+
catch (InvalidCastException) {
1245+
font = ResolveFirstPdfFont();
1246+
ILogger logger = LoggerFactory.GetLogger(typeof(iText.Layout.Renderer.TextRenderer));
1247+
logger.Error(iText.IO.LogMessageConstant.FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT);
1248+
}
12421249
text = ConvertToGlyphLine(strToBeConverted);
12431250
otfFeaturesApplied = false;
12441251
strToBeConverted = null;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c544ffc7af6136ff5fa27b49f79e64335e7b6020
1+
09282149a2b61964c6b1b0fa6d08498c955ef8e0

0 commit comments

Comments
 (0)