Hello,
Is it possible to check what fonts are available on a system. I want to put all fonts in an array, so the user can choose which font to use for printing some data.
I am looking for some function like "aFonts := ReadFonts()"
René Koot
Hello,
Is it possible to check what fonts are available on a system. I want to put all fonts in an array, so the user can choose which font to use for printing some data.
I am looking for some function like "aFonts := ReadFonts()"
Ops, sorry. Wrong forum.
EMG
#include "FiveMac.ch"
function Main()
MsgInfo( ChooseFont() )
return nil
#pragma BEGINDUMP
#include <fivemac.h>
HB_FUNC( CHOOSEFONT )
{
NSFontManager * fontManager = [ NSFontManager sharedFontManager ];
NSFontPanel * fontPanel = [ fontManager fontPanel:YES ];
[ fontPanel makeKeyAndOrderFront: fontPanel ];
// [ NSApp runModalForWindow: fontPanel ];
}
#pragma ENDDUMP#include "FiveMac.ch"
function Main()
MsgInfo( ChooseFont() )
return nil
#pragma BEGINDUMP
#include <fivemac.h>
@interface FontPanelController : NSWindowController <NSWindowDelegate>
{
}
-( void ) changeFont: ( id ) sender;
-( void ) windowWillClose: ( id ) sender;
@end
@implementation FontPanelController
-( void ) changeFont: ( id ) sender
{
NSBeep();
}
- ( void ) windowWillClose: ( id ) sender
{
NSBeep();
[ NSApp abortModal ];
// hb_retc( [ [ sender font ].fontName cStringUsingEncoding : NSWindowsCP125$sCP1252StringEncoding ] );
hb_retc( "font name" );
}
@end
HB_FUNC( CHOOSEFONT )
{
NSFontManager * fontManager = [ NSFontManager sharedFontManager ];
NSFontPanel * fontPanel = [ fontManager fontPanel:YES ];
[ fontPanel setDelegate: [ [ FontPanelController alloc ] init ] ];
[ fontPanel makeKeyAndOrderFront: fontPanel ];
[ NSApp runModalForWindow: fontPanel ];
}
#pragma ENDDUMP#include "FiveMac.ch"
function Main()
MsgInfo( ChooseFont() )
return nil
#pragma BEGINDUMP
#include <fivemac.h>
@interface FontPanelController : NSWindowController <NSWindowDelegate>
{
@public NSFont * font;
@public NSFont * newFont;
}
-( void ) changeFont: ( id ) sender;
-( void ) windowWillClose: ( id ) sender;
@end
@implementation FontPanelController
-( void ) changeFont: ( id ) sender
{
newFont = [ sender convertFont: font ];
}
- ( void ) windowWillClose: ( id ) sender
{
[ NSApp abortModal ];
hb_retc( [ [ ( newFont ? newFont: font ) displayName ] cStringUsingEncoding : NSWindowsCP1252StringEncoding ] );
}
@end
HB_FUNC( CHOOSEFONT )
{
NSFontManager * fontManager = [ NSFontManager sharedFontManager ];
NSFontPanel * fontPanel = [ fontManager fontPanel:YES ];
FontPanelController * fontPanelController = [ [ FontPanelController alloc ] init ];
[ fontPanel setDelegate: fontPanelController ];
fontPanelController->font = [ NSFont systemFontOfSize : 10 ];
[ fontPanel makeKeyAndOrderFront: fontPanel ];
[ NSApp runModalForWindow: fontPanel ];
}
#pragma ENDDUMP#include "FiveMac.ch"
function Main()
MsgInfo( ChooseFont() )
return nilSo my suggestion was right, after all.
EMG
Dear Enrico,
Always ![]()
Hello Antonio,
Thank you very much for this implementation, it looks very nice and easy to use.
But what I mean is a function that only puts the names of the fonts in an array. Than I can use that array in a COMBOBOX and use the name of the font in a print routine. Simular as in Word where the user can choose the font from a combobox and than the fontsize from another combobox.
Always thankful for all the help you give. If you need some financial support, please let me know.
HB_FUNC( FM_AVAILABLEFONTS )
{
NSArray * aFonts = [ [ NSFontManager sharedFontManager ] availableFonts ];
int i;
hb_reta( [ aFonts count ] );
for( i = 0; i < [ aFonts count ]; i++ )
hb_storvc( [ ( NSString * ) [ aFonts objectAtIndex: i ] cStringUsingEncoding : NSWindowsCP1252StringEncoding ], -1, i + 1 );
}#include "FiveMac.ch"
function Main()
local oDlg, cVar
local aFonts := FM_availableFonts()
DEFINE DIALOG oDlg TITLE "Available fonts" SIZE 300, 300
@ 200, 50 COMBOBOX cVar ITEMS aFonts SIZE 200, 20 OF oDlg
ACTIVATE DIALOG oDlg CENTERED
return nil

Hello Antonio,
Sorry for the late response, I had a small vacation (needed it)
Thank you very much, this is just what I was looking for.