Setting TFlxFont from TFont

Hi, just wondering if there is a helper function in any of the FlexCel code to set the properties of a TFlxFont from a TFont?

If not, I can write my own, and can see how to set most of the properties, but I have the following questions:

1) How does TFont.Size or TFont.Height convert to TFlxFont.Size20?

2) Do I need to bother with CharSet, Family and Scheme. or can I just set them to 0,0 and none?


Sadly there is no method for this. The reason is that FlexCel tries to not depend in platform classes like TFont (which is different from TFont in Firemonkey for example).

But writing a helper method should not be very complex. About the questions:
1)Size20 is the size of the font * 20. So if you have a 10 point font, size20 must be 200.

Size20 is in points (and 1 point is 1/72 of an inch). So you need to use "Size" not "Height" as Height is the size in pixels, not points.

The size in pixels depends in the screen resolution, so a 192 dpi screen will have double the font "height" than a 96 dpi screen, but the TFont.Size (and TFlxFont.Size20) would be the same. since the fonts have the same size in inches on the screen. (the 192 dpi screen just need the double of pixels to get to the same size, since pixels are half the size).

The other thing to consider is that Font.Size (and Height) might be negative.
A formula to convert could be:
FlxFont.Size20 := Round(20 * Abs(Font.Size));

2)You don't really need to bother with CharSet and Family, just set them to 0,0. But Scheme is a little trickier.

You know, Excel (since Excel 2007) has 2 "theme" fonts: Major and Minor. They show as "Body" and "Headings" in Excel respectively.
So, if you set a font to have an Scheme (that is don't select "None") the font will be the one provided by the theme. If you for example set a font as major font and Times New Roman, the font will be Calibri anyway, since Calibri is the major font in the "Office" theme.

So it really boils down to if you care about themes or not. Most people isn't even aware that themes exist, as they were introduced in Excel 2007 and they look like the old Excel 2003 fonts and colors, but under the hood what you are doing is completely different. If you don't care about themes, just set the scheme to none. If not, remember that major and minor fonts are given by the theme, not by you.

If you care to learn more about "color" themes (which have a similar structure) I wrote about them a (very) long time ago here:

But well, since I haven't written anything about fonts, I took the time to create a little gif that shows how the major and minor fonts change when you change the theme below. I hope it clarifies a little more instead of making it murkier :)

Thanks, Adrian. Very comprehensive reply as always.