Browse Source

macosx: fix incorrect display of attributed strings in about panel and addon manager

Due to a low-level AppKit implementation detail, all attributed strings will be Helvetica sans-neue and black unless you request otherwise
pull/71/head
Felix Paul Kühne 8 years ago
parent
commit
f72c3a4e15
  1. 45
      modules/gui/macosx/VLCAboutWindowController.m
  2. 3
      modules/gui/macosx/VLCAddonsWindowController.m

45
modules/gui/macosx/VLCAboutWindowController.m

@ -42,7 +42,7 @@
@interface VLCAboutWindowController ()
{
NSString *o_authors;
NSString *_authorsString;
}
@end
@ -52,14 +52,12 @@
{
self = [super initWithWindowNibName:@"About"];
if (self) {
[self setWindowFrameAutosaveName:@"about"];
}
return self;
}
- (void) dealloc
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
}
@ -89,15 +87,14 @@
[[self window] setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
/* Get the localized info dictionary (InfoPlist.strings) */
NSDictionary *o_local_dict;
o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
NSDictionary *localizedInfoDict = [[NSBundle mainBundle] localizedInfoDictionary];
/* Setup the copyright field */
[o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
[o_copyright_field setStringValue: [localizedInfoDict objectForKey:@"NSHumanReadableCopyright"]];
/* l10n */
[[self window] setTitle: _NS("About VLC media player")];
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSColor colorWithCalibratedRed:0. green:0.3411 blue:0.6824 alpha:1.], NSForegroundColorAttributeName, [NSFont systemFontOfSize:13], NSFontAttributeName, nil];
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSColor secondaryLabelColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize:13], NSFontAttributeName, nil];
NSAttributedString *attrStr;
attrStr = [[NSAttributedString alloc] initWithString:_NS("Credits") attributes:stringAttributes];
[o_credits_btn setAttributedTitle:attrStr];
@ -105,7 +102,6 @@
[o_gpl_btn setAttributedTitle:attrStr];
attrStr = [[NSAttributedString alloc] initWithString:_NS("Authors") attributes:stringAttributes];
[o_authors_btn setAttributedTitle:attrStr];
attrStr = nil;
[o_trademarks_txt setStringValue:_NS("VLC media player and VideoLAN are trademarks of the VideoLAN Association.")];
/* setup the creator / revision field */
@ -128,7 +124,7 @@
[tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
[tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
}
o_authors = [tmpArray componentsJoinedByString:@"\n\n"];
_authorsString = [tmpArray componentsJoinedByString:@"\n\n"];
/* setup join us! */
NSString *joinus = toNSStr(_(""
@ -141,10 +137,13 @@
"\"https://www.videolan.org/contribute/\"><span style=\" text-decoration: "
"underline; color:#0057ae;\">Help and join us!</span></a>"));
NSString *fontfamily = @"Helvetica Neue";
NSString *joinUsWithStyle = [NSString stringWithFormat:@"<div style=\"text-align:left;font-family: -apple-system, %@;\">%@</div>",
fontfamily, joinus];
NSAttributedString *joinus_readytorender = [[NSAttributedString alloc] initWithHTML:[joinUsWithStyle dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUTF8StringEncoding] forKey:NSCharacterEncodingDocumentOption] documentAttributes:NULL];
NSString *joinUsWithStyle = [NSString stringWithFormat:@"<div style=\"text-align:left;font-family: -apple-system, Helvetica Neue;\">%@</div>", joinus];
NSMutableAttributedString *joinus_readytorender = [[NSMutableAttributedString alloc] initWithHTML:[joinUsWithStyle dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]
options:@{NSCharacterEncodingDocumentOption : [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:NULL];
[joinus_readytorender setAttributes:@{NSForegroundColorAttributeName : [NSColor secondaryLabelColor],
NSFontAttributeName : [NSFont systemFontOfSize:12.]}
range:NSMakeRange(0, joinus_readytorender.length)];
[o_joinus_txt setAllowsEditingTextAttributes: YES];
[o_joinus_txt setSelectable: YES];
[o_joinus_txt setAttributedStringValue:joinus_readytorender];
@ -190,15 +189,23 @@
[o_revision_field setHidden:YES];
[o_name_version_field setHidden:YES];
NSString *stringToDisplay;
if (sender == o_authors_btn)
[o_credits_textview setString:o_authors];
stringToDisplay = _authorsString;
else if (sender == o_credits_btn)
[o_credits_textview setString:[toNSStr(psz_thanks) stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]];
stringToDisplay = [toNSStr(psz_thanks) stringByReplacingOccurrencesOfString:@"\n" withString:@" "
options:0 range:NSRangeFromString(@"680 2")];
else
[o_credits_textview setString:toNSStr(psz_license)];
stringToDisplay = toNSStr(psz_license);
[(VLCScrollingClipView *)[o_credits_scrollview contentView] resetScrolling];
[(VLCScrollingClipView *)[o_credits_scrollview contentView] startScrolling];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:stringToDisplay
attributes:@{NSForegroundColorAttributeName : [NSColor secondaryLabelColor],
NSFontAttributeName : [NSFont systemFontOfSize:12.]}];
[[o_credits_textview textStorage] setAttributedString:attributedString];
VLCScrollingClipView *scrollView = (VLCScrollingClipView *)[o_credits_scrollview contentView];
[scrollView resetScrolling];
[scrollView startScrolling];
}
/*****************************************************************************

3
modules/gui/macosx/VLCAddonsWindowController.m

@ -226,8 +226,9 @@ static void addonChangedCallback( addons_manager_t *manager,
// Parse HTML description properly
NSMutableString *htmlDescription = [NSMutableString stringWithFormat:@"<style>body{ font-family: -apple-system-body, -apple-system, HelveticaNeue, Arial, sans-serif; }</style>%@", [currentItem description]];
[htmlDescription replaceOccurrencesOfString:@"\n" withString:@"<br />" options:NSLiteralSearch range:NSMakeRange(0, [htmlDescription length])];
NSAttributedString *attributedDescription = [[NSAttributedString alloc] initWithHTML:[htmlDescription dataUsingEncoding:NSUTF8StringEncoding]
NSMutableAttributedString *attributedDescription = [[NSMutableAttributedString alloc] initWithHTML:[htmlDescription dataUsingEncoding:NSUTF8StringEncoding]
documentAttributes:NULL];
[attributedDescription setAttributes:@{NSForegroundColorAttributeName : [NSColor secondaryLabelColor], NSFontAttributeName : [NSFont systemFontOfSize:11.]} range:NSMakeRange(0, attributedDescription.length)];
[[_description textStorage] setAttributedString:attributedDescription];
[self updateInstallButton:[currentItem isInstalled]];

Loading…
Cancel
Save