none
Embedding fonts to RTF RRS feed

  • Question

  • RTF supports fonts embedding. But I've not found any example how to embed fonts to rtf file. MS Word generates fileds and data like this.

    {\f230\fbidi \fdecor\fcharset0\fprq2{\*\panose 04020705040a02060702}
    {\*\fontemb\ftruetype 
    5ba1000099a00000020002000400000004020705040a02060702000090
    0065007200730069006f006e00200031002e0035003600000010004100
    030142480060da0065690045aa14cde98ccfd21159a3440a4dde19f1ebe
    6f7300e819b086bbfdc03c2c01fda246e9d15878691a9dd6172df21b8fdfa
    aeaba8ffaf6b6c1bbc443da013441c80e6fe154dfd6690f00ee63e101adb1
    b3332e49b341de932d1660ce44a857d66fcd30a0a397dae88140298954

    .....

    65c1b474e4557a922ce3c0cb7c599e2cbc0}Emb_Font;}

    I tried to open font-file (.ttf) in my app and convert it's content to hex string. It worked with images in rtf, but didn't give me any result with fonts. Are there any examples how to use font embedding with rtf files ?

    Tuesday, June 24, 2014 9:38 AM

Answers

  • Hi, Caillen. Thank you for help. I've solved this problem by using TTEmbedFontFunction from WinAPI to generate font data.
    Thursday, June 26, 2014 12:15 PM

All replies

  • Hi Alexey,

    Thanks for your post in MSDN forums.

    Your question has little to do with Office Development, so I think this might not the right forum. It's more like a question about the RTF syntax. RTF Specification may help you on this(it is an earlier version, but could help you understand the basic syntax):

    Rich Text Format (RTF) Specification, version 1.6

    For information about Font Table and Font Embedding, please check this part:

    Font Table & Font Embedding

    Here's an example which demonstrates how to use Font Table to apply some fonts(color/font size/back color...) to some plain text, you can save it in an .rtf file, open it with WordPad or Word to see the result:

    {\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}{\f1 ProFontWindows;}}
     {\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red255\green255\blue0;}
     This line is font 0 which is courier\line
     \f1
     This line is font 1\line
     \f0
     This line is font 0 again\line
     This line has a \cf2 red \cf1 word\line
     \highlight3 while this line has a \cf2 red \cf1 word and is highlighted in yellow\highlight0\line
     Finally, back to the default color.\line
     }

    If you use Word document and save it as an RTF document, open it with notepad, you could find the source rtf content.

    To embed a ttf file, check this part in the above document:

    RTF supports TrueType® and other embedded fonts. The type of the embedded font is described by the following control words.

    Control
      Word

    Embedded font type

    \ftnil

    Unknown or default font type (the   default)

    \fttruetype

    TrueType font


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, June 25, 2014 3:07 AM
    Moderator
  • Hi, Caillen. Thank you for reply. May be, the question was raised not correctly. I know how to use RTF syntax, font table, etc. I try to understand what kind of data MS Word processor needs to receive in {\*\fontemb } group. If save RTF document with embedded fonts by MS Word, it generates some hexadecimal data. But I didn't find what is this data neither in specification, nor in different web resources. In specification, in this section {\* \fontemb <fonttype> <fontfname>? <data>? }, specified that <data>-part is "font data". What does it mean ? Is it a content of file, that stores font (.ttf, etc.) or some data structures (like LOGFONT, PANOSE, etc.), generated by Windows API ?
    Wednesday, June 25, 2014 7:35 AM
  • Hi Alexey,

    After checking this document:

    Word 2007: Rich Text Format (RTF) Specification, version 1.9.1

    I found similar description:

    RTF supports embedded fonts with the \fontemb group located inside a font definition. An embedded font   can be specified by a file name, or the actual font data may be located   inside the group. If a file name is specified, it is contained in the \fontfile group. The \cpgN control word can be used   to specify the character set for the file name.

    RTF supports TrueTypeÒ and other embedded fonts. The type of   the embedded font is described by the following control words.

                                                    
        

    Control word

        
        

    Embedded font type

        
       

    \ftnil

       
       

    Unknown     or default font type (the default)

       
       

    \fttruetype

       
       

    TrueType     font

       

    This clearly suggests that you can embed font file into the rtf \fontemb section.

    But please check another KB file here:

    Embedded fonts are not displayed as expected in the documents that are saved as RTF in Word

    According to this document, seems that if you don't convert the .rtf file back to .doc or .docx file, the Word application will not recogonize the embeded font files.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 26, 2014 2:39 AM
    Moderator
  • Hi, Caillen. Thank you for help. I've solved this problem by using TTEmbedFontFunction from WinAPI to generate font data.
    Thursday, June 26, 2014 12:15 PM