Re: How do I use a NSTextBlock in an attributed string?

2017-03-10 Thread Daryle Walker

> On Mar 9, 2017, at 7:05 AM, Daryle Walker  wrote:
> 
>> 
>> On Mar 8, 2017, at 4:17 PM, Daryle Walker  wrote:
>> 
>> I tried:
>> 
>>>   // Set the paragraph formatting for the body...
>>>   let bodyAdvancement = bodyFont.maximumAdvancement
>>>   let bodyIndent = max(bodyAdvancement.width, 
>>> bodyAdvancement.height) / 2.0
>>>   let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
>>> as! NSMutableParagraphStyle
>>>   bodyParagraphStyle.headIndent = bodyIndent
>>>   bodyParagraphStyle.lineBreakMode = .byWordWrapping
>>> 
>>>   // ...and separator
>>>   let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
>>> as! NSMutableParagraphStyle
>>>   let separatorTextBlock = NSTextBlock()
>>>   separatorParagraphStyle.textBlocks.append(separatorTextBlock)
>>> 
>>>   // Set the body, but add a line for the initial separator
>>>   let richSeparator = NSMutableAttributedString(string: " \n", 
>>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>>> separatorParagraphStyle])
>>>   let richBody = NSMutableAttributedString(string: body, 
>>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>>> bodyParagraphStyle])
>>>   result.append(richSeparator)
>>>   result.append(richBody)
>> 
>> What I wanted: the separator line surrounded by a block.
>> What I got: the separator and the body all surrounded by a block.
>> 
>> I originally had the separator and body in a single string, and used a range 
>> to influence just the separator. This got the same result. I thought 
>> treating the separator and body in separate strings first wouldn’t infect 
>> the body with the text block, but it (illogically) does!
>> 
>> How do I end the influence of a block? Put -1 entries in the text-block 
>> array?
> 
> From tinkering around it seem like there is splatter dynamics when going 
> across ranges of text with different “textBlocks” settings, UNLESS the second 
> range uses no blocks. In just that case the second range copies the block 
> policy of the first range. This makes no sense.

I read the paragraph styles of my paragraphs, and their block settings are as 
expected. The separator has a single block, and the body has no blocks. This is 
a straight-up bug, but in Apple’s code (during rendering). That’s the problem 
with rarely-used/mentioned classes: not only does barely anyone knows how to 
use them, sometimes the creators didn’t do enough testing.

Since the bug is on Apple’s side (# 30968328), I can’t fix it and I’m stuck. 
The only idea in mind, besides giving up, is to create a 1x1 table. Now for 
more research….

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

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: How do I use a NSTextBlock in an attributed string?

2017-03-09 Thread Peter Hudson
Yes, you've got the page I thought may be helpful. I hadn't really suggested it 
as a considered solution to your problem. I just thought I'd mention it in case 
you hadn't come across it. 

Peter

> On 9 Mar 2017, at 23:43, Daryle Walker  wrote:
> 
> 
>> On Mar 9, 2017, at 11:59 AM, Peter Hudson  wrote:
>> 
>> Hi Daryle
>> 
>> I don’t know if you’ve come across this - but I found it quite useful.
>> 
>> 
>> Text Layout Programming Guide
>> 
>> Just Google it and its on Apples site.
>> 
> 
> Is there a particular chapter and verse you’re looking at? I’ve already gone 
> through the related guides. I’ve found only one applicable page 
> (),
>  and it’s really about NSTextBlock’s table-related subclasses. It does not 
> have enough information on NSTextBlock to help me. Importantly, is the 
> problem I talked about, block configurations changing correctly unless the 
> trailing paragraph is block-less, a problem with my understanding or a 
> straight-up bug?
> 
> I don’t know if the list will let this image through:
> 
> 
> 
> I got this picture from loading a file into my app, selecting my Export 
> command, choosing RTF, then using QuickLook on that file. The block outline 
> is supposed to be only between the “Sender” line and the “U2Vu…” line, but it 
> extents to the remainder of the file instead. For some reason, the fact that 
> the “U2Vu…” line has no blocks in its paragraph style means to copy the 
> previous paragraph’s block instead of being no-block-at-all.
> 
> — 
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 
___

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: How do I use a NSTextBlock in an attributed string?

2017-03-09 Thread Peter Hudson
Hi Daryle

I don’t know if you’ve come across this - but I found it quite useful.


Text Layout Programming Guide

Just Google it and its on Apples site.

Best 

Peter

___

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: How do I use a NSTextBlock in an attributed string?

2017-03-09 Thread Daryle Walker

> On Mar 8, 2017, at 4:17 PM, Daryle Walker  wrote:
> 
> I tried:
> 
>>// Set the paragraph formatting for the body...
>>let bodyAdvancement = bodyFont.maximumAdvancement
>>let bodyIndent = max(bodyAdvancement.width, 
>> bodyAdvancement.height) / 2.0
>>let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
>> as! NSMutableParagraphStyle
>>bodyParagraphStyle.headIndent = bodyIndent
>>bodyParagraphStyle.lineBreakMode = .byWordWrapping
>> 
>>// ...and separator
>>let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
>> as! NSMutableParagraphStyle
>>let separatorTextBlock = NSTextBlock()
>>separatorParagraphStyle.textBlocks.append(separatorTextBlock)
>> 
>>// Set the body, but add a line for the initial separator
>>let richSeparator = NSMutableAttributedString(string: " \n", 
>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>> separatorParagraphStyle])
>>let richBody = NSMutableAttributedString(string: body, 
>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>> bodyParagraphStyle])
>>result.append(richSeparator)
>>result.append(richBody)
> 
> What I wanted: the separator line surrounded by a block.
> What I got: the separator and the body all surrounded by a block.
> 
> I originally had the separator and body in a single string, and used a range 
> to influence just the separator. This got the same result. I thought treating 
> the separator and body in separate strings first wouldn’t infect the body 
> with the text block, but it (illogically) does!
> 
> How do I end the influence of a block? Put -1 entries in the text-block array?

From tinkering around it seem like there is splatter dynamics when going across 
ranges of text with different “textBlocks” settings, UNLESS the second range 
uses no blocks. In just that case the second range copies the block policy of 
the first range. This makes no sense.

NSTextBlock is a rarely used class, so it’s hard to find sample code on it. I 
got some on , but his/her 
handling code is spread over several files. But I don’t see how his/her code 
could work if the paragraph/block attribute doesn’t splatter upon range change. 
I don’t see that s/he is doing anything special to ensure a reset.

How is a paragraph defined in terms of applied paragraph styles? (Like if you 
fix an attributed-string’s paragraph styles, they are based on the setting of 
the “first” character.) Is it the first character after a line-break sequence 
to the end of the next line-break sequence?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


___

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

How do I use a NSTextBlock in an attributed string?

2017-03-08 Thread Daryle Walker
I tried:

> // Set the paragraph formatting for the body...
> let bodyAdvancement = bodyFont.maximumAdvancement
> let bodyIndent = max(bodyAdvancement.width, 
> bodyAdvancement.height) / 2.0
> let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
> as! NSMutableParagraphStyle
> bodyParagraphStyle.headIndent = bodyIndent
> bodyParagraphStyle.lineBreakMode = .byWordWrapping
> 
> // ...and separator
> let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
> as! NSMutableParagraphStyle
> let separatorTextBlock = NSTextBlock()
> separatorParagraphStyle.textBlocks.append(separatorTextBlock)
> 
> // Set the body, but add a line for the initial separator
> let richSeparator = NSMutableAttributedString(string: " \n", 
> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
> separatorParagraphStyle])
> let richBody = NSMutableAttributedString(string: body, 
> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
> bodyParagraphStyle])
> result.append(richSeparator)
> result.append(richBody)

What I wanted: the separator line surrounded by a block.
What I got: the separator and the body all surrounded by a block.

I originally had the separator and body in a single string, and used a range to 
influence just the separator. This got the same result. I thought treating the 
separator and body in separate strings first wouldn’t infect the body with the 
text block, but it (illogically) does!

How do I end the influence of a block? Put -1 entries in the text-block array?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

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