[20 Mar 2008] How to get info on the current font?

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[20 Mar 2008] How to get info on the current font?

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 20 Mar 2008 19:10:20 -0000

Hi

I have been working a bit on some input routines and is looking for a way to establish information about the font currently in use. This is mainly to reestablish it as the current font if I have to modify a font locally in an input field. Of course hardcoding a default font for the program is possible, but I kind of like the approach of not messing with the default font unless I have to.

Anyway - To do this I have to find a way of asking for a 'current font' and a 'current font size'. As for the font size I think I have it in place using the bit of code included below. But does anyone have suggestions on how to extract information about the current font (like in "times.font"). Pleeeeeze....

regards Jesper

Code: Select all

Function p_GetCurrentFontSize()

/* This stuff in the first part is just to find a 'free' value to use 
when creating */
/* a new temporary TextObject. You don't want to accidentally 
overwrite an existing */
/* object. It establishes an index (i) not already used for 
TextObjects */
/* If you have lots of TextObjects starting at index 1 you may of 
course initilize */
/* the local value to.. say 500. Odds are the value 501 will be 
free :-) */

	local i=0
	local code = 0
	ExitOnError(False)
	while code = 0
		i=i+1
		local attr = GetAttribute(#TEXTOBJECT,i,#ATTRHEIGHT)
		code = GetLastError()
	wend
	ExitOnError(True)

/* This is the part that actually checks for the current font size */
/* by looking at a newly created TextObject and returning its height 
*/
		
	CreateTextObject(i,"X")
	local fontsize=(GetAttribute(#TEXTOBJECT,i,#ATTRHEIGHT))
	FreeTextObject(i)
	Return(fontsize)
endfunction
PEB
Posts: 576
Joined: Sun Feb 21, 2010 1:28 am

[20 Mar 2008] Re: How to get info on the current font?

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 20 Mar 2008 12:37:07 -0700 (PDT)

I know this doesn't answer your question, but if you make a function, such as p_DefaultFont(), you can wrap up into that function the font name, size, and whatever other text attributes you want to use so that all you have to do is call that function, and everything will be set for you when you want to use that default font. (Of course, other preset font styles can also be managed in the same way.)
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[21 Mar 2008] Re: How to get info on the current font?

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 21 Mar 2008 07:56:50 -0000

Yes. However the thing is that I am trying to code an InputBox or rather a list of InputBoxes, that depends as little as possible on global stuff in other parts of the program. Once done I can wrap it up in an include file like - InputBoxes_include.hws, and use it in any program without regard to what else is in that program. One approach is to store all properties of each box in a list of tables like this...

Code: Select all

InputBoxes = {}

InputBoxes.DefaultFont = "times.font"
InputBoxes.DefaultFontSize = 15
InputBoxes.DefaultWidth = 200
InputBoxes.DefaultHeight = 18
etc.
...
...
Then I have a function like p_InitInputBox(index), that looks like this...

Code: Select all

function p_InitInputBox(index)

InputBoxes[index].text= <some default text - probably "">
InputBoxes[index].width = <InputBoxes.DefaultWidth>
InputBoxes[index].height = < InputBoxes.DefaultHeight>
InputBoxes[index].font = InputBoxes.DefaultFont
InputBoxes[index].fontsize = InputBoxes.DefaultFontSize
etc.
...
...

endfunction
Finally I have supporting functions like p_SetInputBoxFont (index,fontname$,fontsize) to allow me to change the default vlaues of any initialized InputBox.

There are also properties for each InputBox that links it to a 'previous' and 'next' InputBox. This may then be used to traverse a chain of InputBoxes. With this I have the building block for making a kind of grid control as well by just adding a property for the number of 'cells' per grid line and setting the border width of each cell to a sensible value.

Anyway the problem with fonts is that it is a global setting. So each time I change the font it affects all future uses of it with print/nprint/textout. To avoid any surprises I therefore have to store the old font setting, then change the font for my current use, and then restore the old font for use. The most flexible solution would be for me to be able to just ask ... oldfont$,oldfontsize=p_GetCurrentFont() and then later do a... p_SetCurrentFont(oldfont$,oldfontsize). For now I make do with a global variable for the default font/fontsize. But that as I see it is only a 90% solution - though of course it works :-)

rgds Jesper
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[21 Mar 2008] Re: Re: How to get info on the current font?

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 21 Mar 2008 11:26:05 +0100
Anyway the problem with fonts is that it is a global setting. So each time I change the font it affects all future uses of it with print/nprint/textout. To avoid any surprises I therefore have to store the old font setting, then change the font for my current use, and then restore the old font for use. The most flexible solution would be for me to be able to just ask ... oldfont$,oldfontsize=p_GetCurrentFont() and then later do a... p_SetCurrentFont(oldfont$,oldfontsize). For now I make do with a global variable for the default font/fontsize. But that as I see it is only a 90% solution - though of course it works :-)
Well, I can implement that. It's not really a problem. You'll then be able to do a GetAttribute() to retrieve the current font settings.
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[21 Mar 2008] Re: How to get info on the current font?

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 21 Mar 2008 20:23:07 -0000

Ahh - having it implemented as a parameter for the GetAttribute() function would be convenient and save me the indirect approach used to provide the font size with the TextObject too. Please do.....

regards Jesper
Locked