A Wingding font character gets changed to an invalid UTF-8 character

Answered A Wingding font character gets changed to an invalid UTF-8 character

  • Friday, March 23, 2012 1:11 AM
     
      Has Code

    I have a Word document created programmatically using OpenXmlDoc.  The section of interest is as 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>742 Evergreen Terrace</w:t>
     </w:r>
    </w:p>

    The '+' character is the envelope symbol in the Wingding typeface.  There are about 300 instances of this paragraph as I was trying to generate a phone directory from a database.

    When I open the document in Word for the first time, it looks great.  If I select the envelope character, the font window says Wingdings.

    However, after some edits, which was nothing but inserting some extra new lines to paginate the document better, all the envelope symbols in the document became a square with a question mark inside.  Now if I select the character, the font windows says Calibri, which is the typeface for the rest of the paragraph.

    I saved this corrupted document and the data is now:

    <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>742 Evergreen Terrace</w:t>
      </w:r>
    </w:p>

    The character that cannot be displayed is EF 80 AB in the saved file.  This is UTF-8 for U+002B.  This is supposed to be invalid, as it is an overlong encoding.  2B can be sufficiently encoded in one byte, but instead three bytes were used.

    My urgent question is how do I prevent the Wingdings character from being corrupted in this manner?

    Is there a better way of inserting a Wingdings character into an OpenXmlDoc document?

    Thanks.

All Replies

  • Sunday, March 25, 2012 11:47 AM
     
     Answered Has Code

    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.


    • Edited by K.Kong Sunday, March 25, 2012 12:56 PM
    • Marked As Answer by K.Kong Monday, March 26, 2012 10:19 AM
    •  
  • Monday, March 26, 2012 4:22 AM
    Moderator
     
     Answered Has Code

    Hi K.Kong,

    Thanks for posting in the MSDN Forum.

    As far as I know, when wu use Wingdings we will format run properties like this:

    RunFonts runFonts = new RunFonts(){ Ascii = "Wingdings", HighAnsi = "Wingdings" };
    

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked As Answer by K.Kong Monday, March 26, 2012 10:19 AM
    •  
  • Monday, March 26, 2012 10:18 AM
     
     

    Thanks.  Seems like they cannot be treated as normal Ascii characters applied with the typeface Wingdings.

    The SymbolChar method requires less code and it generates less Xml.