RTF output help

Want to talk about something that isn't covered by another category?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Posts: 3
Joined: Sun Jan 05, 2020 5:32 am

RTF output help

Post by rfarnold47 » Fri Jan 17, 2020 5:09 am

I am creating an app that will convert input files to rtf. I am trying to figure out how to define a font table in such a way that if a font is NOT selected by the user of my app the RTF document will open in whatever application's default font. In other words, if a font is not defined, and the RTF is opened in Word (for example) the document will appear in whatever Word's default "normal" font is. In my case, my default Normal font in Word is Calibri. However, no matter what I do to try NOT to set a font in the RTF document, it opens with Times New Roman font.

Does anyone have any idea how to code RTF so that it defers to the app that opens the RTF file to set the default font?

Thanks (I don't know where else to go for an answer).

VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8474
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: RTF output help

Post by FourthWorld » Fri Jan 17, 2020 9:10 am

I just did a quick test, and it seems that LC's RTF output will include font assignment for each effective font of text runs and the field itself.

However, in a quick test I found that I could delete the font assignments in the beginning of the RTF file, and when opening in a word processor it uses the app's default font.

In my example file, the first lines of the RTF is:

Code: Select all

{\rtf1\ansi {\fonttbl{\f0\fnil \fcharset0 dejavu serif;}}
Given a font name of "dejavu serif", removing that gives us:

Code: Select all

{\rtf1\ansi {\fonttbl{\f0\fnil \fcharset0;}}
With that, the style run "f0" no longer has a font specifier, so runs using that style make no font assignment.

So if you know your font names you should be able to replace those with empty in the opening style def portion of the file to remove them.
Richard Gaskin
LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Off-Topic”