Read Font

Just starting out? Need help? Post your questions and find answers here.
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Read Font

Post by Konne »

Hello,
I've got a very big problem.
How can I read the Font or Size or Color from a text in an editorgadget?
Is it possible to mark a letter and read the informations?

Please help me.
thx

sencerlly your Konne
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Read Font

Post by Dude »

I've got a similar problem today.

I have an EditorGadget, and if I hold Ctrl and scroll the mouse wheel, the font size changes. How can I get the font size of the EditorGadget, but while the user is changing its size with Ctrl+MouseWheel, so when my app restarts it can show the font in the same size again?

Thanks to Fangbeast, I found some code to get the EditorGadget font size from here:

viewtopic.php?p=456182#p456182

But when I try to work it into my mousewheel action, it doesn't update with the scrolling:

Code: Select all

Procedure GetEditorFontSize(gad)
  format.CHARFORMAT2\cbSize=SizeOf(CHARFORMAT2)
  SendMessage_(GadgetID(gad),#EM_GETCHARFORMAT,#SCF_ALL,@format)
  fs=Round(format\yHeight/20,#PB_Round_Nearest)
  ProcedureReturn fs
EndProcedure

randomsize=Random(25,10)

OpenWindow(0,200,200,600,200,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,580,150)
SetGadgetText(0,"Use Ctrl+MouseWheel here to change font size")
SetGadgetFont(0,LoadFont(0,"Arial",randomsize))

TextGadget(1,10,170,580,20,"Initial font size: "+Str(GetEditorFontSize(0)))

SetActiveGadget(0)

Repeat
  
  ev=WaitWindowEvent(1)
  
  If ev=#WM_MOUSEWHEEL
    SetGadgetText(1,"Font size: "+Str(GetEditorFontSize(0))) ; Doesn't show new size?
  EndIf
  
Until ev=#PB_Event_CloseWindow
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Read Font

Post by Fangbeast »

I have an EditorGadget, and if I hold Ctrl and scroll the mouse wheel, the font size changes. How can I get the font size of the EditorGadget, but while the user is changing its size with Ctrl+MouseWheel, so when my app restarts it can show the font in the same size again?

Thanks to Fangbeast, I found some code to get the EditorGadget font size from here:

viewtopic.php?p=456182#p456182

But when I try to work it into my mousewheel action, it doesn't update with the scrolling:
It's not my code. And I seem to remember that I had to do a SendMessage_ to tell the editorgadget to send messages back to the user as events were occurring. Will see if I can remember where I put it but I suspect I used it in my NotePiddle project.

I will take a look unless someone finds it first.
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Read Font

Post by RASHAD »

Hi Fang
Hi Dude

Code: Select all

OpenWindow(0,200,200,600,200,"test",#PB_Window_SystemMenu)

eg=EditorGadget(0,10,10,580,150)
SetGadgetText(0,"Use Ctrl+MouseWheel here to change font size")

TextGadget(1,10,170,580,20,"")

SetActiveGadget(0)
format.CHARFORMAT2\cbSize=SizeOf(CHARFORMAT2)
SendMessage_(eg,#EM_GETCHARFORMAT,#SCF_ALL,@format)
fs.f=Round(format\yHeight/20,#PB_Round_Nearest)
SetGadgetText(1,"Font size: "+Str(fs))
Repeat

  ev=WaitWindowEvent()
 
  If ev=#WM_MOUSEWHEEL         
    SendMessage_(eg, #EM_GETZOOM, @Numerator, @Denominator)
    If Numerator > 0
      SetGadgetText(1,"Font size: "+Str(Round(fs*Numerator/100,#PB_Round_Nearest)))
    EndIf
 
  EndIf
Until ev=#PB_Event_CloseWindow
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Read Font

Post by Dude »

Thank you, Rashad. :) I made my own standalone procedures from your code:

Code: Select all

Procedure EditorFontSize(gad)
  format.CHARFORMAT2\cbSize=SizeOf(CHARFORMAT2)
  SendMessage_(GadgetID(gad),#EM_GETCHARFORMAT,#SCF_ALL,@format)
  ProcedureReturn Round(format\yHeight/20,#PB_Round_Nearest)
EndProcedure

Procedure EditorFontSizeAfterZoom(gad)
  SendMessage_(GadgetID(gad),#EM_GETZOOM,@num,@den)
  ProcedureReturn Round(EditorFontSize(gad)*num/100,#PB_Round_Nearest)
EndProcedure

OpenWindow(0,200,200,600,200,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,580,150)
SetGadgetText(0,"Use Ctrl+MouseWheel here to change font size")

TextGadget(1,10,170,580,20,"Initial font size: "+Str(EditorFontSize(0)))

SetActiveGadget(0)

Repeat
  
  ev=WaitWindowEvent()
  
  If ev=#WM_MOUSEWHEEL         
    SetGadgetText(1,"New font size: "+Str(EditorFontSizeAfterZoom(0)))
  EndIf
  
Until ev=#PB_Event_CloseWindow
Post Reply