Space between the last 2 lines of a paragraph is larger? - ios

I draw the text using CTFramesetter, I have set kCTParagraphStyleSpecifierParagraphSpacing, kCTParagraphStyleSpecifierLineSpacing, kCTParagraphStyleSpecifierParagraphSpacingBefore all to 0.0.
As you can see in the image, the space between the last 2 lines of a paragraph is much larger than others'.
There're in total 15 lines in this image, I pasted their ascent, descent, leading, origin.y in the following, we can see that the ascent and descent on the 5th and 10th line are larger than others', I couldn't find any specifier to set to avoid this weird layout.
Any ideas?
1 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 399.000000
2 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 374.000000
3 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 349.000000
4 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 324.000000
5 ascent=25.722656, desecent=13.699219, leading=0.720000, origin.y: 294.000000
6 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 258.000000
7 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 233.000000
8 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 208.000000
9 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 183.000000
10 ascent=25.722656, descent=13.699219, leading=0.720000, origin.y: 153.000000
11 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 117.000000
12 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 92.000000
13 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 67.000000
14 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 42.000000
15 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 17.000000

If you use NSMutableAttributeString for text layout, you can set a CTRunDelegate attribute to set the \n metrics to 0. For me this worked:
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateVersion1;
callbacks.getAscent = lineBreakCallback;
callbacks.getDescent = lineBreakCallback;
callbacks.getWidth = lineBreakCallback;
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)#"System", 1.0f, NULL);
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, NULL); //3
NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:
//set the delegate
(__bridge id)delegate, (NSString*)kCTRunDelegateAttributeName,
(__bridge id)fontRef, kCTFontAttributeName,
nil];
stringLength++;
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:#"\n" attributes:attrDictionaryDelegate]];
CFRelease(delegate);
CFRelease(fontRef);
and
static CGFloat lineBreakCallback( void* ref )
{
return 0;
}
EDIT:
following comments I fixed memory management part (I hope that correctly)
I added a font attribute with font of size 1. This is because when the font size of a run (default font size is about 16) is bigger than the rest of line, it changes the line metrics even if the run metrics are smaller (which is quite annoying if you really want to set a bigger font size to a part of a line without for example changing the line's descent - I haven't found a solution for this problem yet).

Damit, it's a bug. DTCoreText works around this by repositioning the baseline origins of those affected lines.
see http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/

Related

Multiplying character-separated numbers in a cell with another cell (Distributive Property)

I have numbers in one cell that are separated by "-" and I want to multiply them by another number in another cell.
Example:
A: 12 - 6 - 8
B: 83
Doing MULTIPLY(SUM(SPLIT(A,"-")),B) is not mathematically correct. How can I do 12 * 83 + 8 * 83 + 8 * 83?
Thanks a lot.
Here's what you can try:
=INDEX(LAMBDA(ζ,JOIN("-",ζ*SEQUENCE(1,COLUMNS(ζ))))(SPLIT(A1,"-")))
Update
=PRODUCT(SPLIT(A1,"-"))
Update 2
Let's say you have 83 in B1 and 12 - 6 - 8 in A1. Here's what you can try:
=LAMBDA(ζ,SUMPRODUCT(ζ,IF(ζ,B1)))(SPLIT(A1,"-"))

Separate string with format into array

I am trying to separate the values of a formatted string into an array. I have the string specifying format but cannot find a way to get the values of a formatted string given the format.
Here is the format string:
fmt=['%2i %2i %4i %2i %2i %2i %1i %11.7f %11.7f %12.5f %12.5f ' ...
'%5.2f %11.5f %5.2f %6.2f %2i %1i %9.5f %9.5f %3i\n'];
And here is an example of a formatted string that I'd like to separate:
5 27 2015 2 21 17 0 32.3788833 -64.6799500 6.16800 -0.12000 5.53 0.36000 5.40 6.03 4 4 -99.99999 -99.99999 999
Is there any way of doing this? If not, in objective-c can I replace consecutive spaces with one space and then separate with one space?
Hope this helps,
NSString *yourStr = #"5 27 2015 2 21 17 0 32.3788833 -64.6799500 6.16800 -0.12000 5.53 0.36000 5.40 6.03 4 4 -99.99999 -99.99999 999 ";
NSPredicate *nonEmptyValue = [NSPredicate predicateWithFormat:#"SELF != ''"];
NSArray *parts = [yourStr componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *finalArr = [parts filteredArrayUsingPredicate:nonEmptyValue];
You can use NSString's componentsSeparatedByString: to convert your string into an NSArray.
Example:
NSString *string = #"5 27 2015 2 21 17 0 32.3788833 -64.6799500 6.16800 -0.12000 5.53 0.36000 5.40 6.03 4 4 -99.99999 -99.99999 999";
NSArray *array = [string componentsSeparatedByString:#" "];
P.S. Make sure you clean your string from leading/trailing spaces and convert multiple consecutive spaces into one single space character.

how do i loop numbers around a calendar in c++?

I have been working on this program for hours and cannot find out how to make the numbers loop around after they hit saturday. They either go way passed it to the right or if i add and endl; they go up and down.
// This is how my output looks like (except they curve around they just go forever to the right:
Number of days: 31
Offset: 0
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
This what you mean?
#include <iostream>
using namespace std;
int main()
{
int i;
for (i=1; i<=31; i++) {
cout << ((i<10) ? " " : "") << i << " ";
if (i%7==0) cout << endl;
}
return 0;
}
Outputs:
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
The % sign is the modulus operator. It gives the remainder of division. So every 7th day divided by 7 is going to have a remainder of zero. That's how you check where to put the line breaks.

SpeechKit SDK (Dragon Mobile) - Crash on Initialization

We have a repeating crash when initilizing Speechkit.
It only happens sometimes on both iOS7 & iOS8 and we could not identify a specific scenario.
We were using ver. 1.0.3 and upgraded to 1.4.12. This issue happens in both versions.
The trace looks like:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000
Thread : Crashed: com.apple.main-thread
0 CoreFoundation 0x25521ca4 CFArrayGetCount + 23
1 24me 0x00548de1 -[TAGPValue(Hash) hash]
2 24me 0x00548de1 -[TAGPValue(Hash) hash]
3 24me 0x00548bf3 -[TAGPValue(Hash) hash]
4 24me 0x00548513 -[TAGPValue(Hash) hash]
5 24me 0x0054b6a9 -[TAGPValue(Hash) hash]
6 24me 0x0038ab17 -[ViewController setupTextToSpeechInterface] (ViewController.m:1370)
7 24me 0x0037a481 -[ViewController viewDidLoad] (ViewController.m:196)
//this is the method we use to initialise
-(void)setupTextToSpeechInterface{
if (![SpeechKit sessionID]) {
[SpeechKit setupWithID:#"XXXXXXXXXXXX"
host:#"ti.nmdp.nuancemobility.net"
port:443
useSSL:NO
delegate:nil];
}
}

EXC_CRASH (SIGBART) Crash Report

Hello everyone I deployed an update for my app and few users have complained/bad reviews etc of app shutting down on them.
One user sent me a crash report and I have re-symbolicated it and it has shown the method where it is crashing and the line number.
I have tried many possible solutions but for the life of me I cannot reproduce it on my device.
Could anyone please be kind and let me know what could be the problem in the following code that is crashing the app:
The line no it is crashing is m:555 i.e
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
I am not sure what the issue is, I have tried passing #"" empty as content still it doesn't crashes.
-(CGFloat)getCellHeightForContent:(NSString*)content
{
NSString *text = content;
CGFloat width = self.tableview.frame.size.width - 15 - 30 - 15; //tableView width - left border width - accessory indicator - right border width
UIFont *font = [UIFont systemFontOfSize:17];
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX}
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize size = rect.size;
size.height = ceilf(size.height);
size.width = ceilf(size.width);
if ((size.height )+ 5 < 70) {
return 70;
}
return size.height + 15;
}
here is the crash report
Incident Identifier: CAB2B27B-F65F-4F8A-82C6-C1AECD791335
CrashReporter Key: 759ffd08fa781ee7b8ae9515835758c563110d7f
Hardware Model: iPhone5,1
Process: xxxx [9226]
Path: /var/mobile/Applications/AA5E7A52-ED1E-421F-B377-CF32D55E71EA/xxxx.app/xxxx
Identifier: com.xxxx.xxxx
Version: 7.0.1 (7.0.1)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2014-06-18 22:09:44.336 -0400
OS Version: iOS 7.1.1 (11D201)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x2e33bf06 0x2e267000 + 872198
1 libobjc.A.dylib 0x38ad2ce2 0x38acf000 + 15586
2 CoreFoundation 0x2e33be48 0x2e267000 + 872008
3 Foundation 0x2ec72bd0 0x2ec57000 + 113616
4 Foundation 0x2ec72aac 0x2ec57000 + 113324
5 xxxx 0x00073850 -[DetailVC getCellHeightForContent:] (DetailVC.m:555)
6 xxxx 0x000725b4 -[DetailVC tableView:heightForRowAtIndexPath:] (DetailVC.m:382)
7 UIKit 0x30c7b1ae 0x30b60000 + 1159598
8 UIKit 0x30c3fd92 0x30b60000 + 916882
9 UIKit 0x30c41b6c 0x30b60000 + 924524
10 UIKit 0x30c41ac0 0x30b60000 + 924352
11 UIKit 0x30c416ba 0x30b60000 + 923322
12 xxxx 0x00070c4c -[DetailVC viewDidLoad] (DetailVC.m:157)
13 UIKit 0x30b6fa4e 0x30b60000 + 64078
14 UIKit 0x30b6f80c 0x30b60000 + 63500
15 UIKit 0x30cfbc0e 0x30b60000 + 1686542
16 UIKit 0x30c1948a 0x30b60000 + 758922
......
Thank you in advance for your help!!
Since the crash report is not fully symbolicated and the exception reason is not shown in the report, the following is only an assumption:
You are saying line 555 references this code:
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
This causing an exception could be because text is nil.
You should really try to get a fully symbolicated crash report. This requires your Mac to have the iOS symbols of iOS 7.1.1 of armv7s or armv7. You get those symbols by connecting an iPhone 5 or iPad 3 with iOS 7.1.1 running to your Mac. If you can't do that, provide the full crash report somewhere and I'll symbolicate it for you this one time.
Even better if you get a crash report that also shows the exception reason, but usually Apple reports do not contain that, so it might be helpful to integrate a 3rd party crash reporting functionality into your app. (Don't ask for recommendations since I am biased and most answers will also be biased, rather test them yourself and choose wisely).

Resources