Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Default to local rendering of CJK characters, using system font #14862

Merged
merged 51 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
84ae427
Change default CJK font from "PingFang" to "Helvetica"
m-stephen Jun 6, 2019
11579ef
Add CHANGELOG.
m-stephen Jun 6, 2019
9c56d2c
Update CHANGELOG.
m-stephen Jun 6, 2019
45fa35e
[ios] Enable client-side rendering and use `Helvetica` by default. Se…
m-stephen Jun 10, 2019
c5ba207
[ios] Update change log
m-stephen Jun 10, 2019
d7d5f00
[ios] Change default CJK configuration in `iosapp` project
m-stephen Jun 10, 2019
3f11ba4
[ios] Update comment
m-stephen Jun 10, 2019
b5c4157
[ios] return local font name using default system font.
m-stephen Jun 12, 2019
a228b63
[ios] Update changelog
m-stephen Jun 12, 2019
1da72a7
[ios] update changelogs & comments
m-stephen Jun 12, 2019
a71fe6b
[iOS, macOS]Support mac os
m-stephen Jun 12, 2019
e6e933e
[iOS, macOS] fix bug
m-stephen Jun 12, 2019
d486c24
[iOS, macOS] update change log
m-stephen Jun 12, 2019
514f570
[iOS, macOS] fix nit.
m-stephen Jun 13, 2019
2819f9e
[iOS, macOS] Ability to specify an array of fonts for fallbacks for `…
m-stephen Jun 13, 2019
61335ba
[iOS, macOS] Update comments
m-stephen Jun 13, 2019
2c607dc
[iOS, macOS] Update change log
m-stephen Jun 13, 2019
5750022
[iOS, macOS] update for mac OS font family names
m-stephen Jun 13, 2019
15752ef
Merge branch 'master' into Stephen-CJK
m-stephen Jun 13, 2019
41b582f
Fix nit.
m-stephen Jun 13, 2019
6b3d599
Update platform/ios/CHANGELOG.md
m-stephen Jun 14, 2019
30fff23
[iOS, macOS] Set `MGLIdeographicFontFamilyName` to a Boolean value `N…
m-stephen Jun 14, 2019
cc8620b
[iOS, macOS] remove `MGLIdeographicFontFamilyName` from info.plist & …
m-stephen Jun 14, 2019
1a33224
[iOS, macOS] remove `MGLIdeographicFontFamilyName` from macOS demo ap…
m-stephen Jun 14, 2019
92c07a9
[iOS, macOS] update macOS changelog
m-stephen Jun 14, 2019
77c8b19
Merge branch 'master' into Stephen-CJK
m-stephen Jun 14, 2019
02118db
[iOS, macOS] Change docs
m-stephen Jul 4, 2019
2e5b1c6
Update Change log
m-stephen Jul 4, 2019
225f3e4
Merge branch 'master' into Stephen-CJK
m-stephen Jul 4, 2019
4b9a218
[iOS, macOS] Test case
m-stephen Jul 4, 2019
ab9ff7f
Update platform/macos/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
6af745c
Update platform/macos/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
5b0b7f1
Update platform/ios/CHANGELOG.md
m-stephen Jul 9, 2019
4fc272b
Update platform/darwin/src/MGLRendererConfiguration.mm
m-stephen Jul 9, 2019
613e6bf
Update platform/darwin/test/MGLRendererConfigurationTests.mm
m-stephen Jul 9, 2019
c15205c
Update platform/macos/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
5369630
Update platform/macos/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
f095d05
Update platform/macos/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
473c548
[iOS, macOS] update comments
m-stephen Jul 9, 2019
2c4c172
[iOS, macOS] add plist value test && filter for invalid string
m-stephen Jul 9, 2019
b1f7fbe
Merge branch 'master' into Stephen-CJK
m-stephen Jul 9, 2019
8d94c1c
[iOS, macOS] fix nit
m-stephen Jul 9, 2019
bbb1ad7
Update platform/ios/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
b37b31f
Update platform/ios/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
7b627e9
Update platform/ios/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
48ae2a5
Update platform/macos/CHANGELOG.md
m-stephen Jul 9, 2019
0868c3e
Update platform/ios/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
bd979ae
Update platform/ios/docs/guides/Info.plist Keys.md
m-stephen Jul 9, 2019
7e4b86b
[iOS, macOS] add invalid value type test
m-stephen Jul 9, 2019
6a494d3
Merge branch 'master' into Stephen-CJK
m-stephen Jul 9, 2019
155e2e8
Apply own suggestions from code review
friedbunny Jul 9, 2019
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
19 changes: 14 additions & 5 deletions platform/darwin/src/MGLRendererConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ MGL_EXPORT
/** The name of the font family to use for client-side text rendering.

Currently only used for CJK glyphs. Changing this at run time is not currently
supported. Enable client-side rendering of CJK glyphs by setting
`MGLIdeographicFontFamilyName` in your containing app's Info.plist to a value
which will be available at run time. Default font for local ideograph font family
is "PingFang". */
@property (nonatomic, readonly) std::string localFontFamilyName;
supported. By default, client-side rendering is enabled for CJK glyphs using Apple
system default font.

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a string
m-stephen marked this conversation as resolved.
Show resolved Hide resolved
m-stephen marked this conversation as resolved.
Show resolved Hide resolved
value for using your specific local font which will be available at run time,
e.g. "PingFang TC".

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a array of
font family names. Once the front ones are unavaiable, it will fallback to others until
using default system font.

Set `MGLIdeographicFontFamilyName` to a Boolean value `NO` for using your custom remote font.
*/
@property (nonatomic, readonly) mbgl::optional<std::string> localFontFamilyName;

/**
A Boolean value indicating whether symbol layers may enable per-source symbol
Expand Down
36 changes: 33 additions & 3 deletions platform/darwin/src/MGLRendererConfiguration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,40 @@ - (const float)scaleFactor {
return mbgl::optional<std::string>();
}

- (std::string)localFontFamilyName {
NSString *fontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"];
- (mbgl::optional<std::string>)localFontFamilyName {

std::string systemFontFamilyName;
#if TARGET_OS_IPHONE
systemFontFamilyName = std::string([[UIFont systemFontOfSize:0 weight:UIFontWeightRegular].familyName UTF8String]);
#else
systemFontFamilyName = std::string([[NSFont systemFontOfSize:0 weight:NSFontWeightRegular].familyName UTF8String]);
#endif

return fontFamilyName ? std::string([fontFamilyName UTF8String]) : std::string("PingFang");
id fontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"];

if([fontFamilyName isKindOfClass:[NSNumber class]] && ![fontFamilyName boolValue])
{
return mbgl::optional<std::string>();
}
else if([fontFamilyName isKindOfClass:[NSString class]])
{
return fontFamilyName ? std::string([fontFamilyName UTF8String]) : systemFontFamilyName;
}
//Ability to specify an array of fonts for fallbacks for `localIdeographicFontFamily`
m-stephen marked this conversation as resolved.
Show resolved Hide resolved
else if ([fontFamilyName isKindOfClass:[NSArray class]]){
for(NSString *name in fontFamilyName){
#if TARGET_OS_IPHONE
if([[UIFont familyNames] containsObject:name]){
return std::string([name UTF8String]);
}
#else
if([[[NSFontManager sharedFontManager] availableFontFamilies] containsObject:name]){
return std::string([name UTF8String]);
}
#endif
}
}
return systemFontFamilyName;
}

@end
6 changes: 6 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.

## master

* Fixed a crash caused by incorrect `MGLMapViewImpl` renderable size. ([#14810](https://github.com/mapbox/mapbox-gl-native/pull/14810))
* The `MGLIdeographicFontFamilyName` Info.plist key can now be set to an array of font family names to ensure correct font fallback behavior. It can also be set to a Boolean value of `NO` to force the SDK to typeset CJK characters in a remote font specified by `MGLSymbolStyleLayer.textFontNames`. ([#14862](https://github.com/mapbox/mapbox-gl-native/pull/14862))
* Fixed queryRenderedFeatues bug caused by incorrect sort feature index calculation. ([#14884](https://github.com/mapbox/mapbox-gl-native/pull/14884))

## 5.1.0

### Styles and rendering
Expand Down
2 changes: 0 additions & 2 deletions platform/ios/app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<string>7877</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MGLIdeographicFontFamilyName</key>
<string>PingFang TC</string>
<key>NSHumanReadableCopyright</key>
<string>© 2014–2019 Mapbox</string>
<key>NSLocationAlwaysUsageDescription</key>
Expand Down
21 changes: 19 additions & 2 deletions platform/ios/docs/guides/Info.plist Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@ If you have implemented custom opt-out of Mapbox Telemetry within the user inter

## MGLIdeographicFontFamilyName

The name of the font family to use for client-side text rendering of CJK ideographs. Set this to the name of a font family which will be available at run time, e.g. `PingFang TC` (iOS 9+), `Heiti TC` (iOS 8+), another appropriate built-in font, or a font provided by your application. Note that if a non-existent font is specified, iOS will fall back to using Helvetica which is likely not to include support for the glyphs needed to render maps in your application.
The name of the font family to use for client-side text rendering of CJK ideographs.

Currently only used for CJK glyphs. Changing this at run time is not currently
supported. By default, client-side rendering is enabled for CJK glyphs using Apple
system default font.

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a string
m-stephen marked this conversation as resolved.
Show resolved Hide resolved
value for using your specific local font which will be available at run time,
e.g. "PingFang TC", another appropriate built-in font, or a font provided by your application.
Note that if a non-existent font is specified, iOS will fall back to using Helvetica which is likely not to include support for the glyphs needed to render maps in your application.

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a array of
font family names. Once the front ones are unavaiable, it will fallback to others until
using default system font.

Set `MGLIdeographicFontFamilyName` to a Boolean value `NO` for using your custom remote font.

## MGLCollisionBehaviorPre4_0

If this key is set to YES (`true`), collision detection is performed only between symbol style layers based on the same source, as in versions 2.0–3.7 of the Mapbox Maps SDK for iOS. In other words, symbols in an `MGLSymbolStyleLayer` based on one source (for example, an `MGLShapeSource`) may overlap with symbols in another layer that is based on a different source (such as the Mapbox Streets source). This is the case regardless of the `MGLSymbolStyleLayer.iconAllowsOverlap`, `MGLSymbolStyleLayer.iconIgnoresPlacement`, `MGLSymbolStyleLayer.textAllowsOverlap`, and `MGLSymbolStyleLayer.textIgnoresPlacement` properties.

Beginning in version 4.0, the SDK also performs collision detection between style layers based on different sources by default. For the default behavior, omit the `MGLCollisionBehaviorPre4_0` key or set it to NO (`false`).

This property may also be set using `[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"MGLCollisionBehaviorPre4_0"]`; it will override any value specified in the `Info.plist`.
This property may also be set using `[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"MGLCollisionBehaviorPre4_0"]`; it will override any value specified in the `Info.plist`.


m-stephen marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Added an `MGLMapView.prefetchesTiles` property to configure lower-resolution tile prefetching behavior. ([#14816](https://github.com/mapbox/mapbox-gl-native/pull/14816))
* Fixed queryRenderedFeatues bug caused by incorrect sort feature index calculation. ([#14884](https://github.com/mapbox/mapbox-gl-native/pull/14884))
* The `MGLIdeographicFontFamilyName` Info.plist key can now be set to an array of font family names to ensure correct font fallback behavior. It can also be set to a Boolean value of `NO` to force the SDK to typeset CJK characters in a remote font specified by `MGLSymbolStyleLayer.textFontNames`. ([#14862](https://github.com/mapbox/mapbox-gl-native/pull/14862))
m-stephen marked this conversation as resolved.
Show resolved Hide resolved

### Styles and rendering

Expand Down
2 changes: 0 additions & 2 deletions platform/macos/app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MGLIdeographicFontFamilyName</key>
<string>PingFang TC</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
Expand Down
21 changes: 18 additions & 3 deletions platform/macos/docs/guides/Info.plist Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@ Use this key if you need to customize the API base URL used throughout the SDK.

The default value is `https://api.mapbox.com`.

## MGLIdeographicFontFamilyName
## MGLIdeographicFontFamilyName
m-stephen marked this conversation as resolved.
Show resolved Hide resolved

The name of the font family to use for client-side text rendering of CJK ideographs. Set this to the name of a font family which will be available at run time, e.g. `PingFang TC` (iOS 9+), `Heiti TC` (iOS 8+), another appropriate built-in font, or a font provided by your application. Note that if a non-existent font is specified, iOS will fall back to using Helvetica which is likely not to include support for the glyphs needed to render maps in your application.
The name of the font family to use for client-side text rendering of CJK ideographs.

Currently only used for CJK glyphs. Changing this at run time is not currently
supported. By default, client-side rendering is enabled for CJK glyphs using Apple
system default font.

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a string
m-stephen marked this conversation as resolved.
Show resolved Hide resolved
value for using your specific local font which will be available at run time,
e.g. "PingFang TC", another appropriate built-in font, or a font provided by your application.
Note that if a non-existent font is specified, iOS will fall back to using Helvetica which is likely not to include support for the glyphs needed to render maps in your application.

Set `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a array of
font family names. Once the front ones are unavaiable, it will fallback to others until
using default system font.

Set `MGLIdeographicFontFamilyName` to a Boolean value `NO` for using your custom remote font.

## MGLCollisionBehaviorPre4_0

If this key is set to YES (`true`), collision detection is performed only between symbol style layers based on the same source, as in versions 0.1–0.7 of the Mapbox Maps SDK for iOS. In other words, symbols in an `MGLSymbolStyleLayer` based on one source (for example, an `MGLShapeSource`) may overlap with symbols in another layer that is based on a different source (such as the Mapbox Streets source). This is the case regardless of the `MGLSymbolStyleLayer.iconAllowsOverlap`, `MGLSymbolStyleLayer.iconIgnoresPlacement`, `MGLSymbolStyleLayer.textAllowsOverlap`, and `MGLSymbolStyleLayer.textIgnoresPlacement` properties.

Beginning in version 0.7, the SDK also performs collision detection between style layers based on different sources by default. For the default behavior, omit the `MGLCollisionBehaviorPre4_0` key or set it to NO (`false`). This property is so named because version 0.7 of the Mapbox Maps SDK for macOS corresponds to version 4.0 of the Mapbox Maps SDK for iOS.
Beginning in version 0.7, the SDK also performs collision detection between style layers based on different sources by default. For the default behavior, omit the `MGLCollisionBehaviorPre4_0` key or set it to NO (`false`). This property is so named because version 0.7 of the Mapbox Maps SDK for macOS corresponds to version 4.0 of the Mapbox Maps SDK for iOS.