Selaa lähdekoodia

Fixed the font size changing in Paragraph

master
vzhikserg 10 vuotta sitten
vanhempi
commit
cb1a1e1c51
2 muutettua tiedostoa jossa 32 lisäystä ja 11 poistoa
  1. 11
    11
      DocX/Paragraph.cs
  2. 21
    0
      UnitTests/DocXUnitTests.cs

+ 11
- 11
DocX/Paragraph.cs Näytä tiedosto

@@ -2710,16 +2710,16 @@ namespace Novacode
}
rPr.SetElementValue(textFormatPropName, value);
var last = rPr.Elements().Last();
if (content as System.Xml.Linq.XAttribute != null)//If content is an attribute
var last = rPr.Elements(textFormatPropName).Last();
if (content as XAttribute != null)//If content is an attribute
{
if (last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name) == null)
if (last.Attribute(((XAttribute)(content)).Name) == null)
{
last.Add(content); //Add this attribute if element doesn't have it
}
else
{
last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name).Value = ((System.Xml.Linq.XAttribute)(content)).Value; //Apply value only if element already has it
last.Attribute(((XAttribute)(content)).Name).Value = ((XAttribute)(content)).Value; //Apply value only if element already has it
}
}
return;
@@ -2745,33 +2745,33 @@ namespace Novacode
}
rPr.SetElementValue(textFormatPropName, value);
XElement last = rPr.Elements().Last();
XElement last = rPr.Elements(textFormatPropName).Last();
if (contentIsListOfFontProperties) //if content is a list of attributes, as in the case when specifying a font family
{
foreach (object property in fontProps)
{
if (last.Attribute(((System.Xml.Linq.XAttribute)(property)).Name) == null)
if (last.Attribute(((XAttribute)(property)).Name) == null)
{
last.Add(property); //Add this attribute if element doesn't have it
}
else
{
last.Attribute(((System.Xml.Linq.XAttribute)(property)).Name).Value =
((System.Xml.Linq.XAttribute)(property)).Value; //Apply value only if element already has it
last.Attribute(((XAttribute)(property)).Name).Value =
((XAttribute)(property)).Value; //Apply value only if element already has it
}
}
}
if (content as System.Xml.Linq.XAttribute != null)//If content is an attribute
if (content as XAttribute != null)//If content is an attribute
{
if (last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name) == null)
if (last.Attribute(((XAttribute)(content)).Name) == null)
{
last.Add(content); //Add this attribute if element doesn't have it
}
else
{
last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name).Value = ((System.Xml.Linq.XAttribute)(content)).Value; //Apply value only if element already has it
last.Attribute(((XAttribute)(content)).Name).Value = ((XAttribute)(content)).Value; //Apply value only if element already has it
}
}
else

+ 21
- 0
UnitTests/DocXUnitTests.cs Näytä tiedosto

@@ -2747,6 +2747,27 @@ namespace UnitTests
Assert.AreEqual(2000, table.GetColumnWidth(1));
}
}
[TestMethod]
public void UpdateParagraphFontSize_WhenSetFontSize_ReturnsExpected()
{
using (var document = DocX.Create("Update paragraph font size.docx"))
{
var paragraph = document.InsertParagraph().FontSize(9);
paragraph.FontSize(11);
string szValue = paragraph.Xml.Descendants(XName.Get("sz", DocX.w.NamespaceName))
.Attributes(XName.Get("val", DocX.w.NamespaceName)).First().Value;
string szCsValue = paragraph.Xml.Descendants(XName.Get("szCs", DocX.w.NamespaceName))
.Attributes(XName.Get("val", DocX.w.NamespaceName)).First().Value;
// the expected value is multiplied by 2
// and the last font size is 11*2 = 22
Assert.AreEqual("22", szValue);
Assert.AreEqual("22", szCsValue);
}
}
}
}

Loading…
Peruuta
Tallenna