Hi
Hi Rasmus,
Thanks for your inquiry.
Please note that formatting is
applied on a few different levels. For example, let’s consider
formatting of simple text. Text in documents is represented by Run
element and a Run can only be a child of a Paragraph. You can apply
formatting 1) to Run nodes by using Character Styles e.g. a Glyph Style, 2) to the parent of those Run nodes i.e. a Paragraph node (possibly via paragraph Styles) and 3) you can also apply direct formatting to Run nodes by using Run attributes (Font). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.
A useful thing to note about the Aspose.Words’ API is
that querying direct formatting (Run.Font, Paragraph.ParagraphFormat) will normally return the “calculated”
formatting value based on all direct formatting, styles and document
defaults etc. Therefore, using the direct formatting properties are the
best way to find the visible formatting of the content.
Please use the Run.Font property to get the direct formatting (font formatting) of Run nodes inside content control.
Hope this answers your query. Please let us know if you have any more queries.
Hi Tahir
Hi Anders,
Thanks for your inquiry.
licenselogimatic:
The problem in my case is that the object I am querying, namely a Sdt controls ContentsFont should reeturn the explicitly set values - not inherited. And I need to know if nothing is set explicitliy.
StructuredDocumentTag.ContentsFont property returns font formatting that will be applied to text entered into SDT. If you want to get the explicitly set values, please use Run.Font property.
licenselogimatic:
So what I need is the exact value from the Run properties under the Sdt Control
So my query to you was if there are any way in Aspose to get the explicit Font information - not the calculated ones.
To get the explicit Font information, please use Run.Font property. Please insert some text inside the contents control and check the font size using following code example.
Document doc = new Document(MyDir + "SdtTagFontSize.docx");
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
foreach (Run run in sdt.GetChildNodes(NodeType.Run, true))
{
MessageBox.Show(run.Text + " " + run.Font.Size.ToString());
}
}
Hope this answers your query. Please let us know if you have any more queries.
Hi, I have updated the attached document - it seemed like the placeholder text wasn’t showing for FirstSdt.
Hi Anders,
Thanks for your inquiry.
licenselogimatic:
FirstSdt:
firstRun.Font.Size = 11 pt (This is the placeholder text’s size)
sdt.ContentsFont.Size = 8 pt (This is the one I should end up with)
sdt.ContentsFont.Style.Font.Size = 28 pt (The size of the Title style)
SecondSdt:
firstRun.Font.Size = 11 pt (This is the placeholders text’s size)
sdt.ContentsFont.Size = 10 pt ( inherit from I don’t know where)
sdt.ContentsFont.Style.Font.Size = 28 pt (this is the one I should end up with )
I have tested the scenario and have found the ContentsFont.Size return incorrect font size for second content control. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10164. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.
licenselogimatic:
What I lack is something in Aspose that can help me determine which one is correct to use. There is nowhere in Aspose (i have found) that can tell me whether I should use the ContentFont.Size or ContentsFont.Style.Size.
If direct formatting is not applied to content control, you can use ContentsFont.Style.Size. Please compare the Run.Font.Size and ContentsFont.Style.Size to check either direct formatting is applied to content control or not. If direct formatting is applied to content control, please use Run.Font.Size.
licenselogimatic:
But in both cases the Run.Font is wrong - since this will take the font property of the placeholder text.
The Run.Font.Size is correct. Please check the Font of text ‘Click here to enter text’. It is ‘Placeholder Text’ which is based on ‘Default Paragraph font’ and its font size is 11.
Please open your document and move the cursor to the end of document. Clear the formatting and insert new content control. The font size of new content control is 11. Please check the attached image for detail.
Hi Tahir
Hi Anders,
Thanks for your inquiry.
licenselogimatic:
If just the ContentsFont.Size in the second example would return “nothing” I would be happy. Then I could programmatically distinct the two scenarios. Whether “nothing” is 0 or null doesn’t really matter to me. Or take it from the applied Style’s Font size.
The StructuredDocumentTag.ContentsFont property return the font formatting that will be applied to text entered into SDT. This property would not return “nothing” or “null” value.
licenselogimatic:
When i wrote “In both cases the Run.Font is wrong” - I meant “In both cases using the Run.Font is wrong” - because that is the font and style of the placeholder text - which in Word is ignored when you start entering text.
When you write the text inside content control, you can insert the text using 1) Run node, 2) DocumentBuilder.write method. In both cases you need to set the font size. In your case, the ContentsFont.Size return incorrect value which is a bug. You can use ContentsFont.Size value to set Run.Font.Size value or DocumentBuilder.Font.Size value. After the fix of this bug, you can insert the text inside content control according to font size of content control using ContentsFont.Size.
licenselogimatic:
I will wait for an answer to the issue until we do further - and for now my users must just suffice with the generated documents being different to what Word does. At least we have a workaround by fixing the source document so the three different Fonts in play are identical.
Unfortunately, there is no workaround available for this issue. we will update you via this forum thread once this issue is resolved.
We apologize for your inconvenience.