i am getting the NSAttributedString
from some applications with the help of NSPasteboard
(when someone copy). The font in the NSAttributedString
is always good but sometimes (depending on the application), when i convert to HTML, i get a different font and size. For example : Calibri goes to Helvetica. Here is my code :
//Get pasteboard nsattributedstring
NSArray *classes = [[NSArray alloc] initWithObjects:[NSAttributedString class], nil];
NSDictionary *options = [[NSDictionary alloc] init];
BOOL ok = [pasteboard canReadObjectForClasses:classes options:options];
if(ok){
NSArray *copiedItems = [pasteboard readObjectsForClasses:classes options:options];
if (copiedItems != nil) {
NSAttributedString *stringTest = [copiedItems lastObject];
NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [stringTest dataFromRange:NSMakeRange(0, stringTest.length) documentAttributes:documentAttributes error:NULL];
htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
}
}
I get my NSAttributedString
from the pasteboard which is fine, then i convert it to HTML. It is when i convert it to HTML the problem, it changes the font. For example, i use Calibri, MacOS doesn't have this font so it won't work.
**This is on MacOS