[vlc-commits] macosx: fix incorrect display of attributed strings in about panel and addon manager

Felix Paul Kühne git at videolan.org
Sun Sep 23 19:45:36 CEST 2018


vlc/vlc-3.0 | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue Sep  4 18:35:13 2018 +0200| [87ebe31a60c662b23a1df7aaa22c331e38ec0d72] | committer: Felix Paul Kühne

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

(cherry picked from commit f72c3a4e1568513d94ee79177f03f27e3fc335dc)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=87ebe31a60c662b23a1df7aaa22c331e38ec0d72
---

 modules/gui/macosx/VLCAboutWindowController.m  | 45 +++++++++++++++-----------
 modules/gui/macosx/VLCAddonsWindowController.m |  3 +-
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/modules/gui/macosx/VLCAboutWindowController.m b/modules/gui/macosx/VLCAboutWindowController.m
index 56ccfd236e..d9c10e81e8 100644
--- a/modules/gui/macosx/VLCAboutWindowController.m
+++ b/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 = (OSX_YOSEMITE_AND_HIGHER) ? @"Helvetica Neue" : @"Lucida Grande";
-    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];
 }
 
 /*****************************************************************************
diff --git a/modules/gui/macosx/VLCAddonsWindowController.m b/modules/gui/macosx/VLCAddonsWindowController.m
index 692faa9ccc..37a9a41d9f 100644
--- a/modules/gui/macosx/VLCAddonsWindowController.m
+++ b/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]];



More information about the vlc-commits mailing list