From 79fde3fbeb30eb77b4761e1fb55203b71e05eef7 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Mon, 28 Mar 2011 22:38:26 -0400 Subject: [PATCH] Factored out font substitution code, added special case for radio buttons --- Tools/nib2cib/Converter+Mac.j | 99 +++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/Tools/nib2cib/Converter+Mac.j b/Tools/nib2cib/Converter+Mac.j index 15250f455..008ff73db 100644 --- a/Tools/nib2cib/Converter+Mac.j +++ b/Tools/nib2cib/Converter+Mac.j @@ -42,40 +42,7 @@ { var object = objects[count]; - if ([object respondsToSelector:@selector(font)] && - [object respondsToSelector:@selector(setFont:)] && - [object font] != nil) - { - var nibFont = [object font], - cibFont = nil; - - if ([object respondsToSelector:@selector(cibFontForNibFont)]) - cibFont = [object cibFontForNibFont]; - else - cibFont = [NSFont cibFontForNibFont:[object font]]; - - if (!cibFont || ![cibFont isEqual:nibFont]) - { - var source = ""; - - if (!cibFont) - { - cibFont = [theme valueForAttributeWithName:@"font" inState:[object themeState] forClass:[object class]]; - - if ([cibFont familyName] === "Arial, sans-serif") - { - var size = [cibFont size]; - - cibFont = [cibFont isBold] ? [CPFont boldSystemFontOfSize:size] : [CPFont systemFontOfSize:size]; - source = " (from theme)" - } - } - - [object setFont:cibFont]; - - CPLog.debug("%s: substituted <%s>%s for <%fpx %s>", [object className], cibFont ? [cibFont cssString] : "theme default", source, [nibFont size], [nibFont familyName]); - } - } + [self replaceFontForObject:object]; if (![object isKindOfClass:[CPView class]]) continue; @@ -127,4 +94,68 @@ return object; } +- (void)replaceFontForObject:(id)object +{ + if ([object respondsToSelector:@selector(font)] && + [object respondsToSelector:@selector(setFont:)]) + { + var nibFont = [object font]; + + if (nibFont) + [self replaceFont:nibFont forObject:object]; + } + else if ([object isKindOfClass:[CPView class]]) + { + /* + Determine if a view is actually a container for radio buttons. + They have to be manually iterated over because they are not + part of the top level object data. + */ + var subviews = [object subviews], + count = [subviews count]; + + if (count && [subviews[0] isKindOfClass:[CPRadio class]]) + { + while (count--) + { + var radio = subviews[count]; + + [self replaceFont:[radio font] forObject:radio]; + } + } + } +} + +- (void)replaceFont:(CPFont)nibFont forObject:(id)object +{ + var cibFont = nil; + + if ([object respondsToSelector:@selector(cibFontForNibFont)]) + cibFont = [object cibFontForNibFont]; + else + cibFont = [NSFont cibFontForNibFont:[object font]]; + + if (!cibFont || ![cibFont isEqual:nibFont]) + { + var source = ""; + + if (!cibFont) + { + cibFont = [theme valueForAttributeWithName:@"font" inState:[object themeState] forClass:[object class]]; + + if ([cibFont familyName] === "Arial, sans-serif") + { + var size = [cibFont size]; + + cibFont = [cibFont isBold] ? [CPFont boldSystemFontOfSize:size] : [CPFont systemFontOfSize:size]; + source = " (from theme)" + } + } + + [object setFont:cibFont]; + + CPLog.debug("%s: substituted <%s>%s for <%fpx %s>", [object className], cibFont ? [cibFont cssString] : "theme default", source, [nibFont size], [nibFont familyName]); + } +} + @end