It is currently Sat Mar 25, 2017 6:53 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Italic Underline Bold in EditorGadget
PostPosted: Mon Mar 20, 2017 4:14 am 
Offline
New User
New User

Joined: Mon Jan 25, 2016 9:49 am
Posts: 5
How to change the text italic or underline in Editorgadget?

I know to make text bold:

Code:
CocoaMessage(@Range.NSRange, GadgetID(0), "selectedRange")
TextStorage.i = CocoaMessage(0, GadgetID(0), "textStorage")
FontSize.CGFloat = 12.0
BoldSystemFont.i = CocoaMessage(0, 0, "NSFont boldSystemFontOfSize:@", @FontSize)
CocoaMessage(0, TextStorage, "addAttribute:$", @"NSFont", "value:", BoldSystemFont, "range:@", @Range)


Top
 Profile  
Reply with quote  
 Post subject: Re: Italic Underline Bold in EditorGadget
PostPosted: Mon Mar 20, 2017 6:49 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 2800
Location: Netherlands
I haven't verified it but it looks like you need to use fontWithDescriptor to create the font.

Something like
Code:
#NSFontItalicTrait = 1

FontSize.CGFloat = 12.0
BoldSystemFont = CocoaMessage(0, 0, "NSFont boldSystemFontOfSize:@", @FontSize)

FontDescriptor = CocoaMessage(0, BoldSystemFont, "fontDescriptor")
SymbolicTraits = CocoaMessage(0, FontDescriptor, "symbolicTraits") | #NSFontItalicTrait
FontDescriptor = CocoaMessage(0, FontDescriptor, "fontDescriptorWithSymbolicTraits:", SymbolicTraits)
BoldItalicFont = CocoaMessage(0, 0, "NSFont fontWithDescriptor:", FontDescriptor, "size:@", @FontSize)

_________________
MacOS 10.12, PB 5.51 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Italic Underline Bold in EditorGadget
PostPosted: Mon Mar 20, 2017 4:51 pm 
Offline
New User
New User

Joined: Mon Jan 25, 2016 9:49 am
Posts: 5
Thank you
This method give me bold + italic
but not italic only

Code:
          #NSFontItalicTrait = 1
 CocoaMessage(@Range.NSRange, GadgetID(#Editor_0), "selectedRange")
TextStorage.i = CocoaMessage(0, GadgetID(#Editor_0), "textStorage")
;FontSize.CGFloat = 12.0
BoldSystemFont.i = CocoaMessage(0, 0, "NSFont boldSystemFontOfSize:@", @FontSize)
FontDescriptor = CocoaMessage(0, BoldSystemFont, "fontDescriptor")
SymbolicTraits = CocoaMessage(0, FontDescriptor, "symbolicTraits") | #NSFontItalicTrait
FontDescriptor = CocoaMessage(0, FontDescriptor, "fontDescriptorWithSymbolicTraits:", SymbolicTraits)
BoldItalicFont.i = CocoaMessage(0, 0, "NSFont fontWithDescriptor:", FontDescriptor, "size:@", @FontSize)
CocoaMessage(0, TextStorage, "addAttribute:$", @"NSFont", "value:", BoldItalicFont, "range:@", @Range)


Regards


Top
 Profile  
Reply with quote  
 Post subject: Re: Italic Underline Bold in EditorGadget
PostPosted: Mon Mar 20, 2017 9:35 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 253
try
Code:
CocoaMessage(0, 0, "NSFont systemFontOfSize:@", @FontSize)
instead of
Code:
CocoaMessage(0, 0, "NSFont boldSystemFontOfSize:@", @FontSize)


Top
 Profile  
Reply with quote  
 Post subject: Re: Italic Underline Bold in EditorGadget
PostPosted: Fri Mar 24, 2017 2:45 am 
Offline
New User
New User

Joined: Mon Jan 25, 2016 9:49 am
Posts: 5
Thank you but it's always the same.
I change the value of ' #NSFontItalicTrait': 1, 2 or 3
Not possible to have only italic or only underline.
Have you another idea?


Top
 Profile  
Reply with quote  
 Post subject: Re: Italic Underline Bold in EditorGadget
PostPosted: Fri Mar 24, 2017 11:43 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 2800
Location: Netherlands
Code:
#NSItalicFontMask = 1
#NSBoldFontMask   = 2

#NSUnderlineStyleNone = 0
#NSUnderlineStyleSingle = 1
#NSUnderlineStyleThick = 2
#NSUnderlineStyleDouble = 9
#NSUnderlinePatternSolid = 0
#NSUnderlinePatternDot = $100
#NSUnderlinePatternDash = $200
#NSUnderlinePatternDashDot = $300
#NSUnderlinePatternDashDotDot = $400
#NSUnderlineByWord = $8000


FontManager = CocoaMessage(0, 0, "NSFontManager sharedFontManager")
FontSize.CGFloat = 12

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  SetGadgetText(0, "This is a test")
 
  TextStorage = CocoaMessage(0, GadgetID(0), "textStorage")
 
 
  Range.NSRange\location = 0
  Range\length = 4
  BoldFont = CocoaMessage(0, FontManager, "fontWithFamily:$", @"Helvetica",
                          "traits:", #NSBoldFontMask,
                          "weight:", 0, "size:@", @FontSize)
  CocoaMessage(0, TextStorage, "addAttribute:$", @"NSFont", "value:", BoldFont, "range:@", @Range)
 
 
  ItalicFont = CocoaMessage(0, FontManager, "fontWithFamily:$", @"Helvetica",
                            "traits:", #NSItalicFontMask,
                            "weight:", 0, "size:@", @FontSize)
  Range\location = 10
  Range\length = 4
  CocoaMessage(0, TextStorage, "addAttribute:$", @"NSFont", "value:", ItalicFont, "range:@", @Range)
 
 
  UnderlineStyle = CocoaMessage(0, 0, "NSNumber numberWithInt:",
                                #NSUnderlineStyleSingle | #NSUnderlineByWord)
  Range\location = 0
  Range\length = 9
  CocoaMessage(0, TextStorage, "addAttribute:$", @"NSUnderline", "value:", UnderlineStyle, "range:@", @Range)
 
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
MacOS 10.12, PB 5.51 x64


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye