Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion apple/Text/RNSVGGlyphContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ - (void)pushContext:(RNSVGText *)node
- (void)pushContext:(RNSVGGroup *)node font:(NSDictionary *)font;
@end

static NSString *RNSVGResolveGenericFontFamily(NSString *fontFamily)
{
if ([fontFamily length] == 0) {
return nil;
}

NSString *normalizedFontFamily = [fontFamily lowercaseString];

if ([normalizedFontFamily isEqualToString:@"serif"]) {
return @"Georgia";
}
if ([normalizedFontFamily isEqualToString:@"sans-serif"]) {
return @"System";
}
if ([normalizedFontFamily isEqualToString:@"monospace"]) {
return @"Menlo";
}
if ([normalizedFontFamily isEqualToString:@"cursive"]) {
return @"Snell Roundhand";
}
if ([normalizedFontFamily isEqualToString:@"fantasy"]) {
return @"Papyrus";
}

return fontFamily;
}

@implementation RNSVGGlyphContext

- (NSArray *)getFontContext
Expand All @@ -118,7 +145,7 @@ - (CTFontRef)getGlyphFont
NSString *fontStyle = RNSVGFontStyleStrings[topFont_->fontStyle];
NSString *fontWeight = RNSVGFontWeightStrings[topFont_->fontWeight];
UIFont *font = [RCTFont updateFont:nil
withFamily:[fontFamily isEqualToString:@""] ? nil : fontFamily
withFamily:RNSVGResolveGenericFontFamily(fontFamily)
size:@(isnan(size) ? 0 : size)
weight:fontWeight
style:fontStyle
Expand Down
18 changes: 18 additions & 0 deletions apps/common/test/Test2976.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import {View} from 'react-native';
import {Svg, Text} from 'react-native-svg';

export default function Test2976() {
return (
<View style={{flex: 1, justifyContent: 'center', paddingHorizontal: 24}}>
<Svg height="160" width="100%">
<Text y="45" fontSize={28}>
System font: The quick brown fox
</Text>
<Text y="105" fontFamily="serif" fontSize={28}>
Serif font: The quick brown fox
</Text>
</Svg>
</View>
);
}
1 change: 1 addition & 0 deletions apps/common/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Test2471 from './Test2471';
import Test2520 from './Test2520';
import Test2670 from './Test2670';
import Test2923 from './Test2923';
import Test2976 from './Test2976';

export default function App() {
return <ColorTest />;
Expand Down