[futurebasic] Re: [FB] Character with stroke

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2017 : Group Archive : Group : All Groups

From: Eugen Rosu <eugen.rosu@...>
Date: Mon, 24 Apr 2017 16:27:40 +0300
Thanks, Ken
Your example works perfect.

I used this (bellow) in my app, but in vain. Nothing happens. The text remains unchanged.

‘———————————————————
LOCAL
     DIM AS HIRect          bounds
     DIM AS RGBColor        fontRGB
     DIM AS WindowRef       wOverlay
     DIM AS RECT            r
     DIM AS WindowGroupRef  group
     DIM AS CGColorRef      white
     DIM AS CGContextRef    ctx
LOCAL FN MyTextViewInAnOverlayWindow
'~'1
SetRect( @r, 1, 44, _wndWidth, _wndHeight - 545 )
APPEARANCE WINDOW -_wOverlay,, @r, _kOverlayWindowClass, _kWindowCompositingAttribute
bounds.origin.x = 25
bounds.origin.y = 40
bounds.size.width = _wndWidth - 53
bounds.size.height = _wndHeight - 545
FN HITextViewCreate( #bounds, 0, 0, @gTextView4 )
FN HIViewAddSubview( FN HIViewGetRoot( WINDOW( _wndRef ) ), gTextView4 )
FN HIViewSetVisible( gTextView4, _True )
FN HIViewSetEnabled( gTextView4, _True )
FN TxtViewSetAlpha( gTextView4, 0 )

GET WINDOW _wOverlay, @wOverlay

FN QDBeginCGContext( FN GetWindowPort( wOverlay ), @ctx )
white = FN CGColorCreateGenericRGB( 1.0, 1.0, 1.0, 0.0 )
CGContextSetFillColorWithColor( ctx, white )
CGContextSetStrokeColorWithColor( ctx, white )
CGColorRelease( white )
CGContextSetTextDrawingMode (ctx, _kCGTextFillStroke )
FN AttributedText( ctx ) //It's the same you use in your example "Character with stroke.bas"
CGContextRelease( ctx )
// This doesn't change the text at all
group = FN GetWindowGroupOfClass( _kFloatingWindowClass )
FN SetWindowGroup( wOverlay, group )
END FN
'~'5

‘———————————————————
Eugen


On Apr 24, 2017, at 1:03, Ken Shmidheiser <kshmidheiser@...> wrote:

> Eugen,
> 
> Here is some food for thought.
> 
> Ken
> 
> 
> include "Tlbx CFAttributedString.incl"
> include "Tlbx CoreText.incl"
> 
> system CFStringRef kCTStrokeWidthAttributeName
> system CFStringRef kCTStrokeColorAttributeName
> 
> local fn AttributedText( ctx as CGContextRef )
> '~'1
> dim as CFIndex       strLen
> dim as CTLineRef     lineRef
> dim as CGColorRef    white, black
> dim as CTFontRef     font
> dim as double        strokeWidth
> dim as CFNumberRef   strokeValue
> dim as CFMutableAttributedStringRef  attrStr
> 
> // Create string
> attrStr = fn CFAttributedStringCreateMutable( _kCFAllocatorDefault, 0 )
> CFAttributedStringReplaceString( attrStr, fn CFRangeMake( 0, 0 ), @"Stroked & Shadowed" )
> 
> // Set font face and size
> font = fn CTFontCreateWithName( @"Helvetica Bold", 60.0, 0 ) 
> strLen = fn CFAttributedStringGetLength( attrStr )
> CFAttributedStringSetAttribute( attrStr, fn CFRangeMake( 0, strLen ), kCTFontAttributeName, font )
> 
> // Set color of text
> white = fn CGColorGetConstantColor( kCGColorWhite )
> CFAttributedStringSetAttribute( attrStr, fn CFRangeMake( 0, strLen ), kCTForegroundColorAttributeName, white )
> 
> // Set width of stroke
> strokeWidth = 4.0
> strokeValue = fn CFNumberCreate( _kCFAllocatorDefault, _kCFNumberDoubleType, @strokeWidth )
> CFAttributedStringSetAttribute( attrStr, fn CFRangeMake( 0, 7 ), kCTStrokeWidthAttributeName, strokeValue )
> CFRelease( strokeValue )
> 
> // Set color of stroke
> black = fn CGColorCreateGenericRGB( 0.0, 0.0, 0.0, 0.8 ) 
> CFAttributedStringSetAttribute( attrStr, fn CFRangeMake( 0, 7 ), kCTStrokeColorAttributeName, black )
> CGColorRelease( black )
> 
> // Create Core Text line and set text in context
> lineRef = fn CTLineCreateWithAttributedString( attrStr )
> CGContextSetTextPosition( ctx, 40.0, 40.0 )
> CTLineDraw( lineRef, ctx )
> CFRelease( lineRef )
> CFRelease( attrStr )
> end fn
> 
> void local fn DoDialog
> '~'1
> select ( dialog(0) )
> case _wndClose : end
> end select
> end fn
> 
> dim as Rect          r
> dim as CGContextRef  ctx
> dim as CGColorRef    white
> dim as CGSize        shadowOffset
> dim as CGFloat       shadowBlurRadius
> 
> shadowOffset.width  = 0.0
> shadowOffset.height = 0.0
> shadowBlurRadius    =  10.0
> 
> fn NewWindowPositionMethod( _kWindowAlertPositionOnMainScreen )
> SetRect( r, 0, 0, 680, 120 )
> appearance window 1, @"Atrributed String Test", @r, _kDocumentWindowClass, _kWindowCloseBoxAttribute
> 
> fn QDBeginCGContext( window( _wndPort ), @ctx )
> 
> // Set fill color
> white = fn CGColorCreateGenericRGB( 1.0, 1.0, 1.0, 0.0 )
> CGContextSetFillColorWithColor( ctx, white )
> CGContextSetStrokeColorWithColor( ctx, white ) 
> CGColorRelease( white )
> 
> // kCGTextFillStroke - does fill and stroke at the same time
> CGContextSetTextDrawingMode (ctx, _kCGTextFillStroke ) 
> 
> // Set shadow color, offset and blur radius
> CGContextSetShadow( ctx, shadowOffset, shadowBlurRadius )
> 
> // Set attributed text
> fn AttributedText( ctx )
> 
> fn QDEndCGContext(  window( _wndPort ), @ctx )
> CGContextRelease( ctx )
> 
> on dialog fn DoDialog
> 
> do
> HandleEvents
> until gFBQuit
> 
>