1

We are using Windward to generate reports in Microsoft Word.

Due to some update, Unicode Characters are no longer displaying properly.

While the vendor is still looking for a fix, we're looking for a work around.

One Symptom that I've noticed is that the "Normal" style does not appear in the "Styles Gallery" on the Ribbon.

I can find it in the "styles.xml" part of the file. I noticed that the style does not have a RSID associated with it, the way a normal MS Word file would.

GOOD FILE "Normal" style appears in Gallery

<w:style w:type="paragraph" w:styleId="Normal" w:default="1">
    <w:name w:val="Normal" />
    <w:qFormat />
    <w:rsid w:val="003C4F1E" />
</w:style>

BAD FILE "Normal" style does NOT appear in Gallery

<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
    <w:name w:val="Normal"/>
</w:style>

Modifying the the Styles.xml file so that the "Normal" style would have rsid as well as qFormat xml tags fixed the issue of getting the "Normal" style to appear in the Gallery.

What I noticed was that once I had the "Normal" reappear and I clicked it without first having to select any text in the document, the Unicode Characters would display correctly.

When I checked document.xml I noticed that the following xml was added before the run:

    <w:rPr>
        <w:rFonts w:ascii="Mangal" w:hAnsi="Mangal" w:cs="Mangal"/>
    </w:rPr>

How did MS Word know to select those values for the runPoperty?

How can I use ooxml to detect Complex script and then make the appropriate font selection?

SAMPLE XML USING COMPLEX SCRIPT

<w:r>
    <w:rPr>
        <w:rFonts w:ascii="Mangal" w:hAnsi="Mangal" w:cs="Mangal"/>
    </w:rPr>
    <w:t>एनडीटीवी</w:t>
</w:r>

What I have so far.

static bool GetRunText()
{
    bool bStylesFound = false;

    using (WordprocessingDocument doc = WordprocessingDocument.Open(_path, false))
    {

        // Get a reference to the main document part.
        var docPart = doc.MainDocumentPart;

        // Get the first paragraph.  
        Paragraph p = docPart.Document.Body.Descendants<Paragraph>().ElementAtOrDefault(0);

        if (p == null)
        {
            Console.WriteLine("No paragraphs found.");

        }
        else
        {

            Run run = p.Descendants<Run>().ElementAtOrDefault(1);

            RunProperties rp = run.RunProperties;

            //Console.WriteLine(rp.RunFonts.);
            bStylesFound = true;
        }

        return bStylesFound;
    }

}
ezG
  • 391
  • 1
  • 17
  • Could you use the [edit] link to copy/paste an example of what you mean by "complex script" into the question, please? Then we can do some testing. Right off-hand, though, I'd say check the characters for a certain range of Unicode values... – Cindy Meister Sep 13 '19 at 18:08
  • @CindyMeister: I've updated my post with a sample. [Complex Script Definition](http://officeopenxml.com/WPtextFonts.php) – ezG Sep 13 '19 at 19:51
  • 1
    When I copy/paste the characters into Word this is the Word Open XML I get. Notice `w:bidi` for the language attributes of both the paragraph and the run formatting (pPr and rPr). I think if you check for the presence of `w:bidi` you should be able to pick these up. `एनडीटीवी` – Cindy Meister Sep 13 '19 at 20:05
  • 1
    you can check if the text in the run is in the specified unicode range. Seems like U+0900 to U+097F https://it.wikipedia.org/wiki/Devanagari_(Unicode) – Slai Sep 13 '19 at 20:07
  • @CindyMeister: It sounds like what I should be doing then is 1) Get the text programmatically, 2) test the range into which it falls; 3) Assign the appropiate font. When the characters are not displaying correctly there are no property tags (e.g. ) I can't check for the presence of w:bidi. It won't be there. It's a defect in the software we're using. – ezG Sep 13 '19 at 20:40
  • 1
    Also notice `w:hint="cs"` and `` - cs, I believe, stands for complex script (only just saw that). Although these may also not be present. In that case, if by "test the range into which it falls" means check the Unicode as Slai and I suggest, then, yes. – Cindy Meister Sep 13 '19 at 20:46

0 Answers0