Fonts in the EditorGadget

Just starting out? Need help? Post your questions and find answers here.
albert_redditt
User
User
Posts: 14
Joined: Mon Jul 20, 2009 9:29 pm
Location: Santa Barbara California US

Fonts in the EditorGadget

Post by albert_redditt »

How do you make the font bold type??????

I don't see anyway of manipulating the font in any of the gadgets.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I'm sorry I have little time tonight for a complete solution, otherwise I'd post an example. However, if you dig into MSDN for EM_SETCHARFORMAT I believe you'll find what you need. (for Windows, of course. Dunno for other OS's.)
BERESHEIT
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

Eh Try,

SetGadgetFont(#Gadget, FontID)

Search for SetGadgetFont in the PB help, they have an example as well.
Don't forget you need to load the font first.

:)
"What you are is what you have been. What you’ll be is what you do now.” -Buddha
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I assumed something more involved of course, as setting font, size, etc. for selected range. But SetGadgetFont may be all you need, I really can't tell from your question which you are looking for.
BERESHEIT
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re:

Post by mestnyi »

netmaestro wrote:I assumed something more involved of course, as setting font, size, etc. for selected range.
Here it is necessary for me, how to do this? :)
http://www.purebasic.fr/english/viewtop ... 50#p522021
If there are examples of better offer.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Fonts in the EditorGadget

Post by mk-soft »

You can use rtf (Rich Text Format). Wiki: https://en.wikipedia.org/wiki/Rich_Text_Format

Windows Only

Code: Select all

;-TOP

; *****************************************************************************
; AddTextRTF by mk-soft, v1.05, 27.03.2018

CompilerIf #PB_Compiler_Version < 550
  Procedure UTF8(Text.s)
    Protected *mem = AllocateMemory(StringByteLength(Text, #PB_UTF8) + 1)
    If *mem
      PokeS(*mem, Text, -1, #PB_UTF8)
    EndIf
    ProcedureReturn *mem
  EndProcedure
CompilerEndIf

Procedure AddTextRTF(Gadget, Text.s , NewLine=#False)
  If Left(Text, 5) <> "{\rtf"
    Text = "{\rtf " + Text + "}"
  EndIf
  If NewLine
    Text = Left(Text, Len(text) - 1) + "\line}" 
  EndIf
  CompilerIf #PB_Compiler_Unicode
    Protected hEdit = GadgetID(Gadget)
    Protected ndx = GetWindowTextLength_(hEdit)
    Protected *szBuffer = UTF8(Text)
    SendMessage_(hEdit, #EM_SETSEL, ndx, ndx)
    SendMessage_(hEdit, #EM_REPLACESEL, 0, *szBuffer)
    FreeMemory(*szBuffer)
  CompilerElse
    AddGadgetItem(Gadget, -1 , Text)
  CompilerEndIf
EndProcedure

; *****************************************************************************

;-


Define.s rtf1, rtf2 
;rtf1 = "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par}"
rtf1 = "This is some {\b bold} text."

rtf2 = "{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}"
rtf2 + "{\colortbl;\red0\green0\blue255;\red255\green0\blue;}"
rtf2 + "This line is the Default color\line"
rtf2 + "\cf2"
rtf2 + "\tab This line is red And has a tab before it\line"
rtf2 + "\cf1"
rtf2 + "\b This line is the blue color And bold"
rtf2 + "}"

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  AddTextRTF(0, rtf1, 1)
  AddTextRTF(0, rtf2, 1)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Update... :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: Fonts in the EditorGadget

Post by eJan »

You can try with these, thanks to: Srod & netmaestro.

Code: Select all

; Srod: http://www.purebasic.fr/english/viewtopic.php?p=164184#164184

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 270, 160, "TextGadget", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  TextGadget(0, 10, 10, 250, 20, "TextGadget Standard (Left)")

  font = SendMessage_(GadgetID(0), #WM_GETFONT, 0, 0)
  GetObject_(font, SizeOf(LOGFONT), lg.LOGFONT)
  lg\lfWeight = #FW_BOLD
  font = CreateFontIndirect_(lg)
  SendMessage_(GadgetID(0), #WM_SETFONT, font, 1)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

DeleteObject_(font)

Code: Select all

; netmaestro: http://www.purebasic.fr/english/viewtopic.php?p=164013#164013

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(0, 10, 10, 250, 20, "TextGadget Standard (Left) [BOLD]")
  TextGadget(1, 10, 70, 250, 20, "TextGadget Center", #PB_Text_Center)
  TextGadget(2, 10, 40, 250, 20, "TextGadget Right", #PB_Text_Right)
  TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
  TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)

  SetGadgetFont(0, GetStockObject_(#BOLD_FONTTYPE))

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Image
Post Reply