• Welcome to Theos PowerBasic Museum 2017.

Font Changes

Started by Scott Slater, March 18, 2010, 01:41:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Scott Slater

Can you change font sizes on labels and buttons in WinLIFT?  I can't seem to figure out how to do it.  I've tried sending the standard %WM_SETFONT message as well as the DDT Control Set Font statement, and both seem to get ignored.  I have a need for some larger fonts on parts of the screen than the default.  How would I go about doing this?

-Scott

Patrice Terrier

#1
Scott,

There are several issues with the "standard" GDI fonts when you want to use advanced features on VISTA/SEVEN

1 - They look good only if you draw on DirectDraw surface with a dark background (because of the missing alpha channel)
2 - The antialias is terrible on a DirectDraw surface.
3 - GDI fonts are valid only within a GDI DC, they have no effect on a GDIPLUS or DirectDraw surface.
4 - When using a theme, it is important to know the correct size of the font because it is heavily used in internal computation to adapt the size of the skinned control.

Currently, if you want to use GDI font on labels and buttons then use this API:
Quote' Disable skinning of a specific control
  DECLARE FUNCTION skSkinDisable LIB "WinLIFT.dll" ALIAS "skSkinDisable" (BYVAL hWnd AS LONG) AS LONG
then they will be drawn the usual way without skinning.

The problem i have with the WM_SETFONT message, is how to figure from a GDI font handle only, the size and the name of the font being used?
With GetTextExtentPoint32 i could have an idea of the font size, but i don't know how to retrieve the font name.

The only viable solution would be to create a new API like skSetCtrlFont(hCtrlHandle, "Use this TTF", WithThisPixelSize).

If you have a better idea then let me know.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Here is the function i wrote to retrieve the size of the font assigned to a GDI32 DC handle.

FUNCTION skGetCtrlFontSize(BYVAL hCtrl AS LONG) AS LONG
    LOCAL siz AS SIZEL, hIC, hFont, nSize AS LONG
   
    hIC = skDisplayDC()
    hFont = SendMessage(hCtrl, %WM_GETFONT, 0, 0)
    IF hFont THEN
       CALL GetTextExtentPoint32(hIC, "W", 1, siz)
       nSize = ((siz.cy / GetDeviceCaps(hIC, %LOGPIXELSY)) * 72): IF nSize > 1 THEN nSize -= 1
       FUNCTION = nSize
    END IF
    CALL DeleteDC(hIC)

END FUNCTION


Note: i have to remove 1 to nSize, because there is no exact correlation between GDI and GDIPLUS font (used internaly by WinLIFT).

So far it seems to work fine with the size.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Dominic Mitchell

Quote
The problem i have with the WM_SETFONT message, is how to figure from a GDI font handle only,
the size and the name of the font being used?

Check the lfFaceName member after using the following code:

  LOCAL tlf     AS LOGFONT
     
  GetObject hFont, SIZEOF(tlf), BYVAL VARPTR(tlf)

 
Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Patrice Terrier

#4
Dominic

I didn't think of GetObject, that works very well to retrieve the font name, however unfortunatly GDI and GDIPLUS do not use the same FaceName, that would have been too easy (GDI use TrueType and GDIPLUS OpenType)  ::)

Anyway thank you very much for the suggestion.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Scott Slater

Quote from: Patrice Terrier on March 18, 2010, 08:20:06 AM
The only viable solution would be to create a new API like skSetCtrlFont(hCtrlHandle, "Use this TTF", WithThisPixelSize).

That would work great in my situation.  I just want to create some banner-type labels for the top part of my screen, so setting a different font (size mainly) would be helpful.  Setting the color would also be helpful but isn't as big of an issue for me at this point.

My particular application may run in 800x600 or 1280x1024 or who knows... It automatically re-sizes to fit the screen and the controls are drawn on the fly so that the controls look the same whether in 800x600 or otherwise.  I calculate the font size based on the current users resolution settings, so I need  to have some control over label fonts.

Thanks,

-Scott

Patrice Terrier

#6
Scott,

Since WinLIFT version 4.80, there is an API: skSetLabelFont, that should do what you want.

'// 4.80 Create a full ARGB color (with alpha channel).
  DECLARE FUNCTION skARGB LIB "WinLIFT.dll" ALIAS "skARGB" ( _
  BYVAL A AS BYTE, _                 ' Alpha channel in the range 0-255 (0 full transparency, 255 full opaque mode).
  BYVAL R AS BYTE, _                 ' Red channel in the range 0-255.
  BYVAL G AS BYTE, _                 ' Green channel in the range 0-255.
  BYVAL B AS BYTE _                  ' Blue channel in the range 0-255.
  ) AS LONG

  %FontStyleRegular = 0
  %FontStyleBold = 1
  %FontStyleItalic = 2
  %FontStyleBoldItalic = 3
  %FontStyleUnderline = 4
  %FontStyleStrikeout = 8
'// 4.80 This API is to be used only with STATIC and BUTTON controls exclusively!
  DECLARE SUB skSetLabelFont LIB "WinLIFT.dll" ALIAS "skSetLabelFont" ( _
  BYVAL hCtrl AS LONG, _             ' The control handle.
  zFontName AS ASCIIZ, _             ' The GDI+ compatible font name to use.
  BYVAL nFontSize AS WORD, _         ' The font size in pixel.
  BYVAL ARGBcolor AS LONG, _         ' The ARGB color (use the skARGB() function above, or NULL to apply the skin theme color).
  BYVAL nFontStyle AS WORD _         ' One of the FontStyle constant above.       
  )


It must be used AFTER the initial call to skInitEngine and skSkinWindow, and you must provide the handle of the Label (STATIC control) you want to customize.


Screen shot of the FF3 WinLIFT Fonts project:



...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Scott Slater

That works and would be suitable for my needs.  Especially if the fonts on the other controls can be set that way as well.

Thanks!

Patrice Terrier

Scott,

Thank you for the feedback.

I don't think that would be possible for all controls, but it should work also with buttons, as for your initial request. ;)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Mark Strickland

Hummmm

I tried this but the font does not change.  It is after the SkInitEngine function call in the form create using FireFly.


    skSetLabelFont(HWND_FORM1_LABEL7,"MS Sans Serif",50,%Null,%FontStyleBold)


Thoughts?

Patrice Terrier

#10
Mark,

QuotezFontName AS ASCIIZ, _             ' The GDI+ compatible font name to use.

The font name in GDI and GDIPLUS do not match the same, try with "Microsoft Sans Serif" instead.

You can see a complete list of the GDIPLUS font available on your system if you download "PhotoComposer" from my web site.
Then, to popup the font selector, click on the small "Add annotation" icon located at the bottom of the window (below the "Select background" icon).

Also there is built-in GDIPLUS font selector in GDImage, the declaration for the API is:
'****************************************************************************
' Version 3.50
' Display the GDImage dialog True Type Font Text editor.
  DECLARE FUNCTION ZI_FontBox LIB "GDIMAGE.DLL" ALIAS "ZI_FontBox" ( _
  BYVAL hParent AS LONG, _  ' The parent window handle.
  zCaption AS ASCIIZ, _     ' The font box caption.
  zUseText AS ASCIIZ, _     ' The string to edit.
  zUseFont AS ASCIIZ, _     ' The font to use.
  BYREF UseSize AS LONG, _  ' The pixel size to use.
  BYREF ColrARGB AS LONG, _ ' The ARGB color to use
  BYREF Use3D AS LONG _     ' The shadow 3D offset.
  ) AS LONG
' Return:
' Return = 2 when the user clic the "Ok" button to validate the input, any other value must be ignored.
'****************************************************************************


Note: I would recommend you to use "Trebuchet MS", because it is available on all computers, and it looks very close to GDI "MS Sans Serif".

I have attached to this post a screen shot of the GDImage font selector.

Remember, on VISTA and SEVEN, GDI font do not work with DWM when using the transparent composited mode, this is the reason why WinLIFT and GDImage are using GDIPLUS font. 


Here is an example of callback function, to get a list of available GDIPLUS fonts installed on your system:
FUNCTION EnumFontName(lf AS LOGFONT, tm AS TEXTMETRIC, BYVAL FontType AS LONG, hWnd AS LONG) AS LONG
    CALL GdipCreateFontFamilyFromName(UCODE$(lf.lfFaceName), 0, FontBoxFam&)
    IF FontBoxFam& THEN
       IF (FontType AND %TRUETYPE_FONTTYPE) THEN ' True type fonts
          CALL GdipCreateFont(FontBoxFam&, 8, %FontStyleRegular, %UnitPixel, curFont&)
          IF CurFont& THEN
             SendMessage(hWnd, %CB_ADDSTRING, 0, VARPTR(lf.lfFaceName))
             CALL GdipDeleteFont(curFont&)       ' Delete the font object
          END IF
       END IF
       CALL GdipDeleteFontFamily(FontBoxFam&)       ' Delete the font family object
    END IF
    FUNCTION = 1
END FUNCTION


...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Mark Strickland

OK --- I must be "graphically challenged" also (as Paul Squires said).

I tried both of the selected fonts and nothing changed.  I also verified that both are installed.

I am running on XP and this is a FireFly 3.07 project.  The skSetLabelFont call is at the end of the form create function in FF and after the skSkinWindow function and all other WinLift function calls.

I am using skSetAnchorCtrl on the same label and other controls and all work correctly.

Ideas accepted.

Patrice Terrier

#12
Mark

I have posted the "Fonts.zip" project on the FireFly forum, to show you how to use custom fonts with WinLIFT.

And there is also a copy of the FF3 project attached to this post.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Herman Kieskamp

Why will this not work on editboxes ? :o

Herman.

Patrice Terrier

Changing the Font Used by an Edit Control

An application can change the font that an edit control uses by sending the WM_SETFONT message. Most applications do this while processing the WM_INITDIALOG message. Changing the font does not change the size of the edit control; applications that send the WM_SETFONT message may have to retrieve the font metrics for the text and recalculate the size of the edit control. For more information about fonts and font metrics, see Fonts and Text.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb775460(v=vs.85).aspx
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com