Skip to content

Commit

Permalink
Fix #1232
Browse files Browse the repository at this point in the history
  • Loading branch information
daichenjie committed Jun 6, 2024
1 parent 7110660 commit 6ecd959
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ooxml/XWPF/Usermodel/XWPFSharedRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,26 @@ public String GetFontFamily(FontCharRange fcr)
}
}

public double FontSize { get; set; }
public double FontSize
{
get
{
OpenXmlFormats.Wordprocessing.CT_RPr pr = run.rPr1;
return (pr != null && pr.IsSetSz()) ? pr.sz.val / 2.0 : -1;
}
set
{
OpenXmlFormats.Wordprocessing.CT_RPr pr = run.IsSetRPr1() ? run.rPr1 : run.AddNewRPr1();
if(value < 1)
{
// fix for TestBug58922() in NPOI
pr.sz = null; // unset
return;
}
OpenXmlFormats.Wordprocessing.CT_HpsMeasure ctSize = pr.IsSetSz() ? pr.sz : pr.AddNewSz();
ctSize.val = (ulong) (value * 2);
}
}

public string Text
{
Expand Down
38 changes: 38 additions & 0 deletions testcases/ooxml/XWPF/UserModel/TestXWPFSharedRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using NPOI.OpenXmlFormats.Shared;
using NPOI.XWPF.Usermodel;
using NPOI.XWPF.UserModel;
using NUnit.Framework;

namespace TestCases.XWPF.UserModel
{
public class TestXWPFSharedRun
{
private CT_R ctRun;
public IRunBody p;

[SetUp]
public void SetUp()
{
XWPFDocument doc = new XWPFDocument();
p = doc.CreateParagraph();

this.ctRun = new CT_R();
}

[Test]
public void TestSetGetFontSize()
{
NPOI.OpenXmlFormats.Wordprocessing.CT_RPr rpr = ctRun.AddNewRPr1();
rpr.AddNewSz().val = 14;

XWPFSharedRun run = new XWPFSharedRun(ctRun, p);
Assert.AreEqual(7.0, run.FontSize);

run.FontSize = 24;
Assert.AreEqual(48, (int) rpr.sz.val);

run.FontSize = 24.5;
Assert.AreEqual(24.5, run.FontSize);
}
}
}

0 comments on commit 6ecd959

Please sign in to comment.