BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to save and restore a font's settings to one's own file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Randall Parker
Guest





PostPosted: Fri Jan 23, 2004 11:17 pm    Post subject: How to save and restore a font's settings to one's own file Reply with quote



I want to be able to add to my application's file format the ability for a user to
save out the font settings the user chose for some graphs the user specific
information about. What I'm kinda confused about is just what are the essential
attributes of a font.

TFont has Size and I can see why one would want to save Size. But it also has Height.
Isn't Height implied by Size?

The properties of TFont are:

Charset
Color
FontAdapter
Handle
Height
Name
Pitch
PixelsPerInch
Size
Style

Realistically speaking which of those should or should not be saved? Should they all
be saved? They are all writable.

I do not think that Handle should be saved and restored. Wouldn't it be set when the
TFont object was created?

Also, are enums always int size? So if I save them in 4 byte int fields that would be
a good sized field to save them in in a binary file?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 24, 2004 12:37 am    Post subject: Re: How to save and restore a font's settings to one's own f Reply with quote



"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:4011ab52$1 (AT) newsgroups (DOT) borland.com...

Quote:
TFont has Size and I can see why one would want to save Size. But it also
has Height.
Isn't Height implied by Size?

Yes, and vice versa. Setting the Size also assigns the Height, and setting
the Height also assigns the Size. You only need to store one of them, not
both.

Quote:
Realistically speaking which of those should or should not
be saved? Should they all be saved? They are all writable.

Whichever ones you are actually interested in preserving - the ones you
allow the user to actually change. Anything else can probably be left at
its default setting.

Quote:
I do not think that Handle should be saved and restored.
Wouldn't it be set when the TFont object was created?

Correct.

Quote:
Also, are enums always int size?

Not always. In the case of properties that are actually an enum, such as
Pitch, you can store the value as a simple integer, ie:

int value = Font->Pitch;
// store value as needed...

int value = 0;
// read value as needed...
if( (value >= fpDefault) && (value <= fpFixed) )
Font->Pitch = static_cast<TFontPitch>(value);

But for things that are not simple enums but are Sets instead, such as the
Style property, you will have to retreive and assign the values manually.
You could store the values into your own int that is a bitmask of the values
in the Set, ie.

TFontStyles styles = Font->Style;
int value = 0;
if( styles.Contains(fsBold) ) value |= 0x00000001;
if( styles.Contains(fsItalic) ) value |= 0x00000002;
if( styles.Contains(fsUnderline) ) value |= 0x00000004;
if( styles.Contains(fsStrikeOut) ) value |= 0x00000008;
// store value as needed...

TFontStyles styles;
int value = 0;
// read value as needed....
if( value & 0x00000001 ) styles << fsBold;
if( value & 0x00000002 ) styles << fsItalic;
if( value & 0x00000004 ) styles << fsUnderline;
if( value & 0x00000008 ) styles << fsStrikeOut;
Font->Style = styles;


Gambit



Back to top
Dennis Jones
Guest





PostPosted: Sat Jan 24, 2004 2:10 am    Post subject: Re: How to save and restore a font's settings to one's own f Reply with quote




"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:4011ab52$1 (AT) newsgroups (DOT) borland.com...
Quote:
I want to be able to add to my application's file format the ability for a
user to
save out the font settings the user chose for some graphs the user
specific
information about. What I'm kinda confused about is just what are the
essential
attributes of a font.

Of the TFont properties, I believe these are the critical ones:

Charset
Color
Name
Pitch
PixelsPerInch
Size (or Height)
Style

I have an old application in which I save and restore fonts by reading and
writing a LOGFONT structure combined with a color identifier. I have a
structure like:

typedef struct
{
TColor Color;
TLogFont logfont;
} FontRec_t;

Here, I get the LOGFONT information for the font in question, write it to a
file (or registry, or wherever), from which it can be restored later. Below
is a scaled-down version of the functions I use. Error checking has been
removed for brevity. You will need to decide what you want to do if the
calls to GetObject or CreateFontIndirect fail.

void WriteFontStream(TStream *s, TFont *pFont)
{
FontRec_t fRec;

GetObject( pFont->Handle, sizeof(fRec.logfont), &fRec.logfont );
fRec.Color = pFont->Color;
s->Write( &fRec, sizeof(fRec) );
}

void ReadFontStream(TStream *s, TFont *pFont)
{
FontRec_t fRec;

s->Read( &fRec, sizeof(fRec) );
pFont->Handle = CreateFontIndirect( &fRec.logfont );
pFont->Color = fRec.Color;
}

- Dennis



Back to top
Randall Parker
Guest





PostPosted: Sun Jan 25, 2004 1:18 am    Post subject: Re: How to save and restore a font's settings to one's own f Reply with quote

Dennis,

Borland's doc on the TFont constructor says that PixelsPerInch is initialized by the
TFont constructor based on the screen resolution. Given that a person might save out
on one one machine at one resolution and then read in and recreate on a different
machine at a different resolution that suggests that one should avoid saving and
restoring that field oneself.

Agree? Disagree?

Dennis Jones wrote:
Quote:
Of the TFont properties, I believe these are the critical ones:

Charset
Color
Name
Pitch
PixelsPerInch
Size (or Height)
Style



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.