none
Character font loses the font after opening in Word RRS feed

  • Question

  • I create programmatically a paragraph with some text.  The paragraph has the style with style name sFamilyRow1 applied.  There is one character in this paragraph where I apply a font change to Wingdings (the envelope symbol).  I am creating a phone book with more than 300 entries, so there are more than 300 instances of this paragraph.

    When I first open the document in Word, everything looks ok.  But after I made some edits in Word, not anywhere near the Wingding character, all the characters with the Wingding font changes to the font of sFamilyRow1, which is Calibri.

    The code to generate the document is as follows:

    Run chEnvelope = new Run(new Text("+")); //the envelope char
    RunProperties rPr = new RunProperties();
    RunFonts fWingding = new RunFonts();  
    fWingding.Ascii = "Wingdings";
    rPr.PrependChild(fWingding);
    chEnvelope.PrependChild(rPr);
    Paragraph p2 = new Paragraph(chEnvelope);
    p2.AppendChild(new Run(new TabChar()));
    p2.AppendChild(new Run(new Text(Address1)));
    ParagraphProperties pPr2 = new ParagraphProperties();
    pPr2.ParagraphStyleId = new ParagraphStyleId() { Val = sFamilyRow1 };
    p2.PrependChild(pPr2);

    The Xml data is like follows:

    <w:p>
     <w:pPr>
       <w:pStyle w:val="FamilyRow1" />
     </w:pPr>
     <w:r>
       <w:rPr>
         <w:rFonts w:ascii="Wingdings" />
       </w:rPr>
       <w:t>+</w:t>
     </w:r>
     <w:r><w:tab /></w:r>
     <w:r>
       <w:t>1178 Evergreen Terrace</w:t>
     </w:r>
    </w:p>

    What could I be doing wrong here?  It is now very frustrating as I can't do more than hitting the Enter key a few times before the Wingding font disappears.

    Thanks.

    Thursday, March 22, 2012 6:39 AM

Answers

  • I overcome the problem by using a SymbolChar instead, for a + (0x2B) I have to use F02B:

    SymbolChar chEnvelope = new SymbolChar();
    chEnvelope.Char = HexBinaryValue.FromString("F02B");
    chEnvelope.Font = "Wingdings";
    Paragraph p2 = new Paragraph(chEnvelope);

    and it is serialized as:

    <w:sym w:char="F02B" w:font="Wingdings"/>

    It seems a character applied the font of Wingdings will not work as intended.

    • Marked as answer by Bruce Song Monday, March 26, 2012 2:27 AM
    Sunday, March 25, 2012 12:58 PM

All replies

  • More info.

    I saved the Word document after it loses the font, and the said paragraph has been changed to as follows:

    <w:p w:rsidR="00E70909" w:rsidRDefault="00E8768B">
      <w:pPr>
        <w:pStyle w:val="FamilyRow1"/>
      </w:pPr>
      <w:r>
        <w:rPr><w:rFonts w:ascii="Wingdings"/></w:rPr>
        <w:t></w:t>
      </w:r>
      <w:r>
        <w:tab/>
        <w:t>1178 Evergreen Terrace</w:t>
      </w:r>
    </w:p>
    

    The non-displayable character, in UTF-8 is EF 80 AB.  Note that the '+' character is 0x2B.  So somehow Word has transformed the character to a Unicode character of the same base value.

    Is it due to AutoCorrect?  If so, what can I switch off in AutoCorrect to prevent this?

    Even though the Xml shows that the character is still Wingdings, in Word if I select the character, the font window shows that it is Cailbri.

    Hope some Word expert can help me on this.  Thanks.

    Thursday, March 22, 2012 12:55 PM
  • I overcome the problem by using a SymbolChar instead, for a + (0x2B) I have to use F02B:

    SymbolChar chEnvelope = new SymbolChar();
    chEnvelope.Char = HexBinaryValue.FromString("F02B");
    chEnvelope.Font = "Wingdings";
    Paragraph p2 = new Paragraph(chEnvelope);

    and it is serialized as:

    <w:sym w:char="F02B" w:font="Wingdings"/>

    It seems a character applied the font of Wingdings will not work as intended.

    • Marked as answer by Bruce Song Monday, March 26, 2012 2:27 AM
    Sunday, March 25, 2012 12:58 PM
  • Hi K.Kong,

    Glad to hear that you have figured out the problem and share it with us. Thank you very much.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 2:27 AM