mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			234 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			234 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Matlab
		
	
| 
											11 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											11 years ago
										 | // | ||
|  | 
 | ||
|  | #import "UIFont+OWS.h" | ||
|  | 
 | ||
| 
											8 years ago
										 | NS_ASSUME_NONNULL_BEGIN | ||
|  | 
 | ||
| 
											11 years ago
										 | @implementation UIFont (OWS) | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_thinFontWithSize:(CGFloat)size | ||
|  | { | ||
| 
											8 years ago
										 |     return [UIFont systemFontOfSize:size weight:UIFontWeightThin]; | ||
| 
											11 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_lightFontWithSize:(CGFloat)size | ||
|  | { | ||
| 
											8 years ago
										 |     return [UIFont systemFontOfSize:size weight:UIFontWeightLight]; | ||
| 
											11 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_regularFontWithSize:(CGFloat)size | ||
|  | { | ||
| 
											8 years ago
										 |     return [UIFont systemFontOfSize:size weight:UIFontWeightRegular]; | ||
| 
											11 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_mediumFontWithSize:(CGFloat)size | ||
|  | { | ||
| 
											8 years ago
										 |     return [UIFont systemFontOfSize:size weight:UIFontWeightMedium]; | ||
| 
											11 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_boldFontWithSize:(CGFloat)size | ||
|  | { | ||
| 
											10 years ago
										 |     return [UIFont boldSystemFontOfSize:size]; | ||
| 
											11 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | + (UIFont *)ows_monospacedDigitFontWithSize:(CGFloat)size; | ||
|  | { | ||
|  |     return [self monospacedDigitSystemFontOfSize:size weight:UIFontWeightRegular]; | ||
|  | } | ||
|  | 
 | ||
| 
											9 years ago
										 | #pragma mark - Icon Fonts | ||
|  | 
 | ||
|  | + (UIFont *)ows_fontAwesomeFont:(CGFloat)size | ||
|  | { | ||
|  |     return [UIFont fontWithName:@"FontAwesome" size:size]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dripIconsFont:(CGFloat)size | ||
|  | { | ||
|  |     return [UIFont fontWithName:@"dripicons-v2" size:size]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_elegantIconsFont:(CGFloat)size | ||
|  | { | ||
|  |     return [UIFont fontWithName:@"ElegantIcons" size:size]; | ||
|  | } | ||
|  | 
 | ||
|  | #pragma mark - Dynamic Type | ||
| 
											10 years ago
										 | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_dynamicTypeTitle1Font | ||
| 
											8 years ago
										 | { | ||
| 
											8 years ago
										 |     return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle1]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeTitle2Font | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2]; | ||
| 
											10 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_dynamicTypeTitle3Font | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle3]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeHeadlineFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | + (UIFont *)ows_dynamicTypeBodyFont | ||
| 
											9 years ago
										 | { | ||
| 
											7 years ago
										 |     return [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; | ||
| 
											9 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | + (UIFont *)ows_dynamicTypeSubheadlineFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]; | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeFootnoteFont | ||
| 
											9 years ago
										 | { | ||
|  |     return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_dynamicTypeCaption1Font | ||
| 
											8 years ago
										 | { | ||
| 
											8 years ago
										 |     return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; | ||
| 
											9 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | + (UIFont *)ows_dynamicTypeCaption2Font | ||
| 
											8 years ago
										 | { | ||
| 
											8 years ago
										 |     return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | #pragma mark - Dynamic Type Clamped | ||
|  | 
 | ||
|  | + (UIFont *)preferredFontForTextStyleClamped:(UIFontTextStyle)fontTextStyle | ||
|  | { | ||
| 
											7 years ago
										 |     // We clamp the dynamic type sizes at the max size available | ||
|  |     // without "larger accessibility sizes" enabled. | ||
| 
											7 years ago
										 |     static NSDictionary<UIFontTextStyle, NSNumber *> *maxPointSizeMap = nil; | ||
|  |     static dispatch_once_t onceToken; | ||
|  |     dispatch_once(&onceToken, ^{ | ||
| 
											7 years ago
										 |         NSMutableDictionary<UIFontTextStyle, NSNumber *> *map = [@{ | ||
| 
											7 years ago
										 |             UIFontTextStyleTitle1 : @(34.0), | ||
|  |             UIFontTextStyleTitle2 : @(28.0), | ||
|  |             UIFontTextStyleTitle3 : @(26.0), | ||
|  |             UIFontTextStyleHeadline : @(23.0), | ||
|  |             UIFontTextStyleBody : @(23.0), | ||
|  |             UIFontTextStyleSubheadline : @(21.0), | ||
|  |             UIFontTextStyleFootnote : @(19.0), | ||
|  |             UIFontTextStyleCaption1 : @(18.0), | ||
|  |             UIFontTextStyleCaption2 : @(17.0), | ||
| 
											7 years ago
										 |         } mutableCopy]; | ||
| 
											5 years ago
										 |         map[UIFontTextStyleLargeTitle] = @(40.0); | ||
| 
											7 years ago
										 |         maxPointSizeMap = map; | ||
| 
											7 years ago
										 |     }); | ||
|  | 
 | ||
|  |     UIFont *font = [UIFont preferredFontForTextStyle:fontTextStyle]; | ||
|  |     NSNumber *_Nullable maxPointSize = maxPointSizeMap[fontTextStyle]; | ||
|  |     if (maxPointSize) { | ||
|  |         if (maxPointSize.floatValue < font.pointSize) { | ||
|  |             return [font fontWithSize:maxPointSize.floatValue]; | ||
|  |         } | ||
|  |     } else { | ||
|  |         OWSFailDebug(@"Missing max point size for style: %@", fontTextStyle); | ||
|  |     } | ||
|  | 
 | ||
|  |     return font; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | + (UIFont *)ows_dynamicTypeLargeTitle1ClampedFont | ||
|  | { | ||
| 
											5 years ago
										 |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleLargeTitle]; | ||
| 
											7 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | + (UIFont *)ows_dynamicTypeTitle1ClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleTitle1]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeTitle2ClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleTitle2]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeTitle3ClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleTitle3]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeHeadlineClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleHeadline]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeBodyClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleBody]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeSubheadlineClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleSubheadline]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeFootnoteClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleFootnote]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeCaption1ClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleCaption1]; | ||
|  | } | ||
|  | 
 | ||
|  | + (UIFont *)ows_dynamicTypeCaption2ClampedFont | ||
|  | { | ||
|  |     return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleCaption2]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | #pragma mark - Styles | ||
|  | 
 | ||
|  | - (UIFont *)ows_italic | ||
|  | { | ||
|  |     return [self styleWithSymbolicTraits:UIFontDescriptorTraitItalic]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | - (UIFont *)ows_bold | ||
|  | { | ||
|  |     return [self styleWithSymbolicTraits:UIFontDescriptorTraitBold]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | - (UIFont *)styleWithSymbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits | ||
|  | { | ||
|  |     UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits]; | ||
|  |     UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0]; | ||
| 
											7 years ago
										 |     OWSAssertDebug(font); | ||
| 
											8 years ago
										 |     return font ?: self; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | - (UIFont *)ows_mediumWeight | ||
| 
											8 years ago
										 | { | ||
|  |     // The recommended approach of deriving "medium" weight fonts for dynamic | ||
|  |     // type fonts is: | ||
|  |     // | ||
|  |     // [UIFontDescriptor fontDescriptorByAddingAttributes:...] | ||
|  |     // | ||
|  |     // But this doesn't seem to work in practice on iOS 11 using UIFontWeightMedium. | ||
|  | 
 | ||
|  |     UIFont *derivedFont = [UIFont systemFontOfSize:self.pointSize weight:UIFontWeightMedium]; | ||
| 
											8 years ago
										 |     return derivedFont; | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (UIFont *)ows_monospaced | ||
|  | { | ||
|  |     return [self.class ows_monospacedDigitFontWithSize:self.pointSize]; | ||
|  | } | ||
|  | 
 | ||
|  | 
 | ||
| 
											11 years ago
										 | @end | ||
| 
											8 years ago
										 | 
 | ||
|  | NS_ASSUME_NONNULL_END |