PureBasic Forum
http://forums.purebasic.com/english/

Read Font
http://forums.purebasic.com/english/viewtopic.php?f=13&t=15669
Page 1 of 1

Author:  Konne [ Tue Jun 21, 2005 7:08 pm ]
Post subject:  Read Font

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

Author:  Dude [ Sat Dec 08, 2018 7:25 am ]
Post subject:  Re: Read Font

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:
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

Author:  Fangbeast [ Sat Dec 08, 2018 8:39 am ]
Post subject:  Re: Read Font

Quote:
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.

Author:  RASHAD [ Sat Dec 08, 2018 9:39 am ]
Post subject:  Re: Read Font

Hi Fang
Hi Dude

Code:
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

Author:  Dude [ Sat Dec 08, 2018 9:59 am ]
Post subject:  Re: Read Font

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

Code:
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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/