Saving numbered list as web archive causes indenting problem
Saving numbered list as web archive causes indenting problem
- Subject: Saving numbered list as web archive causes indenting problem
- From: Rob M <email@hidden>
- Date: Wed, 21 Jul 2010 12:59:30 -0600
This is kind of an obscure problem, but any help would be appreciated :)
GOAL
Given an attributed string that contains a numbered list (created using
NSTextView's List Panel), I want to programmatically scale the text larger,
then save the scaled string as a web archive.
PROBLEM
When the attributed string for a numbered list is scaled larger (by
adjusting the NSFont pointSize), then saved as a web archive, the numbers in
the list appear off the screen to the left when the web archive is opened in
a web view. A numbered list uses NSParagraphStyle's "headIndent" setting to
correctly indent the list text and it appears the indenting isn't working
correctly in the webarchive. This problem only occurs when the text is
programmatically scaled larger. So I'm not sure if it's a bug in Apple's
webarchive generating code or if I need to do something else when scaling
the text...
SAMPLE PROJECT
This simple project clearly demonstrates the problem:
http://files.me.com/robchronos/wz7oc5
SCREENSHOT
Here's a screenshot from the sample app showing what happens to the numbered
list when it's saved as a web archive:
http://files.me.com/robchronos/9asl08
CODE
Here's the code I use to scale the text and save it as a web archive:
// Get the text from the textView
NSMutableAttributedString *attributedString = [textView textStorage];
// Loop through all of the font runs in the text and increase the font size
by 4X
NSUInteger length = [attributedString length];
NSRange attributeRange = NSMakeRange( 0, 0);
while (attributeRange.location < length)
{
NSFont *font = [attributedString attribute:NSFontAttributeName
atIndex:attributeRange.location effectiveRange:&attributeRange];
if (font)
{
[attributedString removeAttribute:NSFontAttributeName range:attributeRange];
[attributedString addAttribute:NSFontAttributeName value:[NSFont
fontWithName:[font fontName] size:[font pointSize]*4.0]
range:attributeRange];
}
attributeRange.location += attributeRange.length;
}
// Retrieve the webarchive data
NSRange range = NSMakeRange(0, [attributedString length]);
NSDictionary *dict = [NSDictionary
dictionaryWithObject:NSWebArchiveTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
NSError *error = nil;
NSData *data = [attributedString dataFromRange:range documentAttributes:dict
error:&error];
// Write the webarchive data to a file
[data writeToFile:@"/NumberedList.webarchive" atomically:NO];
// Open the webarchive file in the webView
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:@"/NumberedList.webarchive"]]];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden