Seite 1 von 1

FontRequester - Schrifteigenschaften

Verfasst: 05.01.2007 17:21
von sen-me
Wie kann ich Fett/Kursiv/Fett und Kursiv als standard auswählen?

Verfasst: 05.01.2007 21:05
von Fluid Byte
Mit PureBASIC gar nicht! Geht nur mit API:

Code: Alles auswählen

; Title:    ChooseFont API Dialog
; Author:   Fluid Byte
; Date:     January 05, 2007
; Compiler: PureBasic v4.02

hdcScreen = CreateDC_("DISPLAY",0,0,0)

lf.LOGFONT
lf\lfHeight = -MulDiv_(FontSize,GetDeviceCaps_(hdcScreen,#LOGPIXELSY),72)
lf\lfItalic = 0
lf\lfUnderline = 0
lf\lfStrikeOut = 0
lf\lfWeight = #FW_BOLD

PokeS(@lf\lfFaceName,"Arial")

DeleteDC_(hdcScreen)

lpcf.CHOOSEFONT
lpcf\lStructSize = SizeOf(CHOOSEFONT)
lpcf\lpLogFont = lf            
lpcf\Flags =  #CF_EFFECTS | #CF_INITTOLOGFONTSTRUCT | #CF_BOTH
lpcf\rgbColors = TextColor

If ChooseFont_(lpcf)
	Debug "FaceName = " + PeekS(@lf\lfFaceName)
	Debug "PointSize = " + Str(lpcf\iPointSize/10)
	Debug "Italic = " + Str(lf\lfItalic)
	Debug "Underline = " + Str(lf\lfUnderline)
	Debug "StrikeOut = " + Str(lf\lfStrikeOut)
	Debug "Weight = " + Str(lf\lfWeight)                        
EndIf

Verfasst: 07.06.2007 17:41
von teachco
Ja, das ist eine wirkliche Definitionslücke beim Fontrequester.
fett, kursiv, unterstrichen, durchgestrichen können nicht wie die anderen Einstellungen vorbelegt werden.

Okay. Nun habe ich einfach mal rumgespielt und o.a. Code modifiziert. Letztlich habe ich eine Procedure draus gemacht, um es besser zu verstehen. Vielleicht hilft es dem einen oder anderen. Es scheint zu funktionieren. Seiteneffekte habe ich nicht getestet.


Code: Alles auswählen

; Title:    ChooseFont API Dialog 
; Author:   Fluid Byte 
; Date:     January 05, 2007 
; Compiler: PureBasic v4.02 

; modified: by teachco
; Date:     June 07, 2007


Procedure FontRequester_workaround(fontname.s, underline.b, strikeout.b, italic.b , bold.b, FontSize.l , TextColor.l)
   hdcScreen = CreateDC_("DISPLAY",0,0,0) 

   lf.LOGFONT 
   lf\lfHeight = -MulDiv_(FontSize,GetDeviceCaps_(hdcScreen,#LOGPIXELSY),72) 
   lf\lfItalic = italic 
   lf\lfUnderline = underline 
   lf\lfStrikeOut = strikeout
   If bold  
      lf\lfWeight = #FW_BOLD
   Else
      lf\lfWeight = 0
   EndIf

   PokeS(@lf\lfFaceName,fontname) 

   DeleteDC_(hdcScreen) 

   lpcf.CHOOSEFONT 
   lpcf\lStructSize = SizeOf(CHOOSEFONT) 
   lpcf\lpLogFont = lf            
   lpcf\Flags =  #CF_EFFECTS | #CF_INITTOLOGFONTSTRUCT | #CF_BOTH 
   lpcf\rgbColors = TextColor 

   ChooseFont_(lpcf)

EndProcedure


; Vorbelegung Bsp.
fontname.s = "Verdana"
underline  = 1  ; 0: nicht gesetzt , 1: gesetzt
strikeout  = 1  ; 0: nicht gesetzt , 1: gesetzt
italic     = 1  ; 0: nicht gesetzt , 1: gesetzt
bold       = 1  ; 0: nicht gesetzt , 1: gesetzt
FontSize   = 20
TextColor  = RGB(255,0,0)


FontRequester_workaround(fontname, underline, strikeout, italic , bold, FontSize , TextColor)