Seite 1 von 1

Standard Font

Verfasst: 10.10.2013 22:56
von delikanli_19_82
Hallo Leute,

ich suche schon seit längerem in Google und bin nicht fündig geworden. Vielleicht kann mir jemand einen Tipp geben.

Ich würde gerne unter Windows, Linux und Mac in Erfahrung bringen, wie ich

a) die installierten Fonts auslesen kann

b) (das ist VIEL WICHTIGER) den Standard-Font, der gerade von allen GUI-Programmen systemweit genutzt wird, herausfinden kann. Font + Size.

In beiden Fällen gehe ich davon aus, das man die jeweilige OS-API nutzen muss. Allerdings ist mir nicht klar, wie ich das anstellen soll. Wäre für Tipps dankbar.

MFG

Kurt

Re: Standard Font

Verfasst: 11.10.2013 00:47
von STARGÅTE
Für a) und Windows kann ich volgenden Code anbieten:

Code: Alles auswählen

Enumeration
	#SystemFont_Sort_Default
	#SystemFont_Sort_Name
	#SystemFont_Sort_Type
EndEnumeration

Enumeration
	#SystemFont_Type_Raster = 1
	#SystemFont_Type_Device = 2
	#SystemFont_Type_TrueType = 4
EndEnumeration

Structure SystemFont
	Name$
	Type.i
EndStructure

Global NewList SystemFont.SystemFont()

Procedure ExamineSystemFontsCallback(*EnumLogFont.ENUMLOGFONT, *NewTextMetric.NEWTEXTMETRIC, FontType.l, lParam) 
	If AddElement(SystemFont())
		With SystemFont()
			\Name$ = PeekS(@*EnumLogFont\elfLogFont\lfFaceName[0]) 
			\Type  = FontType
		EndWith
		ProcedureReturn #True 
	EndIf
EndProcedure 

Procedure ExamineSystemFonts(Sort=#SystemFont_Sort_Default)
	ClearList(SystemFont())
	Protected DesktopWindow.i = GetDesktopWindow_() 
	If Not DesktopWindow : ProcedureReturn #False : EndIf
	Protected DC.i = GetDC_(DesktopWindow)
	If Not DC : ProcedureReturn #False : EndIf
	If EnumFontFamilies_(DC, #Null, @ExamineSystemFontsCallback(), 0) 
		ReleaseDC_ (DesktopWindow, DC) 
		Select Sort
			Case #SystemFont_Sort_Name
				SortStructuredList(SystemFont(), #PB_Sort_NoCase, OffsetOf(SystemFont\Name$), #PB_String)
			Case #SystemFont_Sort_Type
				SortStructuredList(SystemFont(), #PB_Sort_NoCase, OffsetOf(SystemFont\Type), #PB_Integer)
		EndSelect
		ResetList(SystemFont())
		ProcedureReturn #True
	Else
		ProcedureReturn #False
	EndIf
EndProcedure

Macro NextSystemFont()
	NextElement(SystemFont())
EndMacro

Macro SystemFontName()
	SystemFont()\Name$
EndMacro

Macro SystemFontType()
	SystemFont()\Type
EndMacro



CompilerIf #PB_Compiler_IsMainFile
	
	Enumeration
		#Window
		#Gadget
	EndEnumeration
	
	OpenWindow(#Window, 0, 0, 800, 600, "Fenster", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
	ListIconGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "Name", 300)
	AddGadgetColumn(#Gadget, 1, "Typ", 100)
	
	ExamineSystemFonts(#SystemFont_Sort_Name)
	While NextSystemFont()
		Type$ = ""
		If SystemFontType() & #SystemFont_Type_Raster : Type$ + "Raster" : EndIf
		If SystemFontType() & #SystemFont_Type_Device : Type$ + "Device" : EndIf
		If SystemFontType() & #SystemFont_Type_TrueType : Type$ + "TrueType" : EndIf
		AddGadgetItem(#Gadget, -1, SystemFont()\Name$+#LF$+Type$)
	Wend
	
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
	
CompilerEndIf

Re: Standard Font

Verfasst: 12.10.2013 06:55
von delikanli_19_82
Danke Stargate.