session-ios/SignalMessaging/categories/UIFont+OWS.m

235 lines
6.1 KiB
Mathematica
Raw Normal View History

2014-11-24 21:51:43 +01:00
//
2019-02-14 22:20:29 +01:00
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
2014-11-24 21:51:43 +01:00
//
#import "UIFont+OWS.h"
2019-02-21 00:07:08 +01:00
#import <SignalCoreKit/iOSVersions.h>
2014-11-24 21:51:43 +01:00
2018-01-25 19:53:39 +01:00
NS_ASSUME_NONNULL_BEGIN
2014-11-24 21:51:43 +01:00
@implementation UIFont (OWS)
+ (UIFont *)ows_thinFontWithSize:(CGFloat)size
{
return [UIFont systemFontOfSize:size weight:UIFontWeightThin];
2014-11-24 21:51:43 +01:00
}
+ (UIFont *)ows_lightFontWithSize:(CGFloat)size
{
return [UIFont systemFontOfSize:size weight:UIFontWeightLight];
2014-11-24 21:51:43 +01:00
}
+ (UIFont *)ows_regularFontWithSize:(CGFloat)size
{
return [UIFont systemFontOfSize:size weight:UIFontWeightRegular];
2014-11-24 21:51:43 +01:00
}
+ (UIFont *)ows_mediumFontWithSize:(CGFloat)size
{
return [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
}
+ (UIFont *)ows_boldFontWithSize:(CGFloat)size
{
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
return [UIFont boldSystemFontOfSize:size];
2014-11-24 21:51:43 +01:00
}
2019-03-08 06:05:58 +01:00
+ (UIFont *)ows_monospacedDigitFontWithSize:(CGFloat)size;
{
return [self monospacedDigitSystemFontOfSize:size weight:UIFontWeightRegular];
}
#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
+ (UIFont *)ows_dynamicTypeTitle1Font
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle1];
}
+ (UIFont *)ows_dynamicTypeTitle2Font
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2];
}
+ (UIFont *)ows_dynamicTypeTitle3Font
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleTitle3];
}
+ (UIFont *)ows_dynamicTypeHeadlineFont
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
}
+ (UIFont *)ows_dynamicTypeBodyFont
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}
+ (UIFont *)ows_dynamicTypeSubheadlineFont
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
}
+ (UIFont *)ows_dynamicTypeFootnoteFont
2017-04-17 21:13:15 +02:00
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
}
+ (UIFont *)ows_dynamicTypeCaption1Font
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
}
+ (UIFont *)ows_dynamicTypeCaption2Font
{
return [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2];
}
2019-02-14 22:20:29 +01:00
#pragma mark - Dynamic Type Clamped
+ (UIFont *)preferredFontForTextStyleClamped:(UIFontTextStyle)fontTextStyle
{
2019-02-14 22:22:51 +01:00
// We clamp the dynamic type sizes at the max size available
// without "larger accessibility sizes" enabled.
2019-02-14 22:20:29 +01:00
static NSDictionary<UIFontTextStyle, NSNumber *> *maxPointSizeMap = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
2019-02-21 00:07:08 +01:00
NSMutableDictionary<UIFontTextStyle, NSNumber *> *map = [@{
2019-02-14 22:20:29 +01:00
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),
2019-02-21 00:07:08 +01:00
} mutableCopy];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) {
map[UIFontTextStyleLargeTitle] = @(40.0);
}
maxPointSizeMap = map;
2019-02-14 22:20:29 +01:00
});
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;
}
+ (UIFont *)ows_dynamicTypeLargeTitle1ClampedFont
{
2019-02-21 00:07:08 +01:00
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) {
return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleLargeTitle];
} else {
return [UIFont preferredFontForTextStyleClamped:UIFontTextStyleTitle1];
}
}
2019-02-14 22:20:29 +01:00
+ (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];
}
#pragma mark - Styles
- (UIFont *)ows_italic
{
return [self styleWithSymbolicTraits:UIFontDescriptorTraitItalic];
}
2018-04-10 19:02:33 +02:00
- (UIFont *)ows_bold
{
return [self styleWithSymbolicTraits:UIFontDescriptorTraitBold];
}
- (UIFont *)styleWithSymbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits
{
UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0];
OWSAssertDebug(font);
return font ?: self;
}
2018-04-16 18:39:11 +02:00
- (UIFont *)ows_mediumWeight
{
// 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];
2018-04-09 22:27:05 +02:00
return derivedFont;
}
2014-11-24 21:51:43 +01:00
@end
2018-01-25 19:53:39 +01:00
NS_ASSUME_NONNULL_END