Re: boundingRectWithSize gives wrong size

2019-08-28 Thread Jens Alfke via Cocoa-dev


> On Aug 28, 2019, at 12:33 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
>   NSRect string_rect = CGRectIntegral( [mesg_string boundingRectWithSize: 
> drawRect_.size

What is drawRect_ set to when this is called?

It's been a while since I used this, but IIRC the output width will be the same 
as the input, with the height increased to account for the number of lines the 
string is broken into.

With NSStringDrawingUsesLineFragmentOrigin, if the text is broken into lines, 
it's not going to tell you the exact pixel width of the widest line.

In single-line mode (without NSStringDrawingUsesLineFragmentOrigin) I believe 
you do get the exact dimensions of the single line of text.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Cocoa-dev Digest, Vol 16, Issue 72

2019-08-28 Thread Jens Alfke via Cocoa-dev


> On Aug 27, 2019, at 7:21 PM, Turtle Creek Software  
> wrote:
> 
> What I can't find is where the __bridge cast should go. The compiler 
> complains at all locations.
> The app runs the same, but will ARC be OK without it?

You shouldn't need to use __bridge at all, since you're no longer casting back 
and forth between Obj-C references and void*.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: boundingRectWithSize gives wrong size

2019-08-28 Thread Richard Charles via Cocoa-dev


> On Aug 28, 2019, at 1:33 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> I am trying to determine the size of a piece of text using 
> boundingRectWithSize.
> 
> The problem is that this method does not return the correct width. (The 
> height seems to be about right.) Sometimes, the width is only a little bit 
> too wide, sometimes it is much too wide.

I have had good results with CTLineGetTypographicBounds().

--Richard Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


boundingRectWithSize gives wrong size

2019-08-28 Thread Gabriel Zachmann via Cocoa-dev
I am trying to determine the size of a piece of text using boundingRectWithSize.

The problem is that this method does not return the correct width.
(The height seems to be about right.)
Sometimes, the width is only a little bit too wide, sometimes it is much too 
wide.
And I could not find a pattern, it is not just a linear factor.

Below is the code snippet that I use.

I already did considerable googling but could not find a solution for my 
problem.
(Most posts say that I needed to use the correct options, so I included them, 
to no avail.)

I would appreciate very much all kinds of pointers or suggestions.

Best regards, Gabriel



   NSMutableString * mesg = NULL;
...
   textLayer_.string = mesg;
   textLayer_.fontSize = fontSize_;

   NSStringDrawingContext * ctxt = [NSStringDrawingContext new];
   ctxt.minimumScaleFactor = 1.0;
   NSFont * font = [NSFont fontWithName: @"Andale Mono" size: 
textLayer_.fontSize ];
   NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] 
init];

   paragraphStyle.lineBreakMode = NSLineBreakByClipping;
   NSDictionary * attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
 font, NSFontAttributeName,
 paragraphStyle, 
NSParagraphStyleAttributeName, nil];
   NSAttributedString * mesg_string = [[NSAttributedString alloc] 
initWithString: mesg
  
attributes: attrsDictionary];

   NSRect string_rect = CGRectIntegral( [mesg_string boundingRectWithSize: 
drawRect_.size
   options: 
NSStringDrawingUsesLineFragmentOrigin |
 // 
NSStringDrawingUsesDeviceMetrics |   // tried with and w/o  
 

NSStringDrawingUsesFontLeading
   context: ctxt ] );

   string_rect.size.height += 0.2 * textLayer_.fontSize;// for the shadow
   if ( string_rect.size.width < drawRect_.size.width )
   string_rect.size.width *= 0.9;//  

   textLayer_.bounds = string_rect;

   // set drop shadow
   textLayer_.shadowPath = CGPathCreateWithRect( string_rect, NULL );

   [textLayer_ setNeedsDisplay];




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Recommendations for cross platform library/framework

2019-08-28 Thread Pier Bover via Cocoa-dev
Another option I've found is using Kotlin Native.

https://kotlinlang.org/docs/reference/native-overview.html

It compiles Kotlin code directly to Apple frameworks for perfect
interoperability without the need of a JVM.

On Mon, Aug 26, 2019 at 6:41 PM Pier Bover  wrote:

> Hi all
>
> In a couple of months I'll be starting a macOS Swift 5 project and if
> possible I'd like to separate as the business networking logic so that it
> can be reused in a Windows app in the future.
>
> Ideally I'd want to statically link the library but I've also considered
> using dynamic libraries, or even include binaries in my app and execute
> them via Process().
>
> I've considered a multitude of corssplatform options (JVM, QT, Xamarin,
> etc) but quite frankly I'd rather maintain one codebase per platform than
> use one of those which could introduce more problems than they solve.
>
> I'd prefer avoiding C++ if possible. My first choice would have been using
> Go which can compile to .so shared objects but Xcode cannot use those
> without some bridge written in C. I've read Rust can compile to a dylib for
> Xcode.
>
> Has anyone any recommendations or tips to share?
>
> Thanks in advance.
>
> Pier
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com