Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created September 12, 2014 14:22
Show Gist options
  • Save sonsongithub/44768b95a6175c836886 to your computer and use it in GitHub Desktop.
Save sonsongithub/44768b95a6175c836886 to your computer and use it in GitHub Desktop.
debug NSAttriutedString and CoreText
if (self.attributedString != nil && [self.attributedString.string rangeOfString:@"これになる不思議"].location != NSNotFound) {
DNSLog(@"%@", self.attributedString);
UniChar *p = (UniChar*)malloc(sizeof(UniChar) * self.attributedString.string.length);
[self.attributedString.string getCharacters:p];
FILE *fp = fopen("/Users/sonson/bug_data.bin", "wb");
fwrite(p, sizeof(UniChar), self.attributedString.string.length, fp);
fclose(fp);
free(p);
CGFloat fontSize = 14;
NSString *temp = [self.attributedString.string stringByAppendingString:@"\n"];
NSParagraphStyle *paragraphStyle = [NSParagraphStyle defaultParagraphStyleWithFontSize:fontSize];
NSDictionary *attributes = @{NSParagraphStyleAttributeName:paragraphStyle, NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
_attributedString = [[NSAttributedString alloc] initWithString:temp attributes:attributes];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment