I miss a TextHeight()

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Simular to TextLength() to get the hight of a Font. I know that i can select a FontHeight with loadfont() but this FontHeightPixelHight.

So, does somebody know a Api-Call to do this?

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by GPI

So, does somebody know a Api-Call to do this?
I think PB posted a tip about determining whether the user has big fonts. You can use the code in there to get the pixel height.


--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Thanks, found a solution:

Code: Select all

;see the example, how to get the hdc
Procedure GetTextHeight(hdc)
  tm.textmetric
  PrevMapMode=SetMapMode_(hdc,#mm_text)
  gettextmetrics_(hdc,tm)
  If prevmapmode
    setmapmode_(hdc,prevmapmode)
  EndIf
  ProcedureReturn tm\tmHeight
EndProcedure



LoadFont(0,"TeXplus EX",10)

CreateImage(0,100,100)

hdc=StartDrawing(ImageOutput()) ; start drawing and get the HDC

DrawingFont(UseFont(0)) ; Use the own font

Height=GetTextHeight(hdc) ; how big it is

;draw a text with a pixel-line between the text
Locate(1,1)
DrawText("XYZ")
Locate(1,1+Height+1)
DrawText("abc")

StopDrawing()

CloseFont(0)


;display it

OpenWindow(0,0,0,100,100,#pb_window_screencentered,"TEST")
CreateGadgetList(WindowID())
ImageGadget(0,0,0,100,100,ImageID())
Repeat
Until WaitWindowEvent()=#pb_event_closewindow

End
PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
Post Reply