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

[ios] Add glyphs rasterization options #517

Merged
merged 7 commits into from
Oct 26, 2020

Conversation

lloydsheng
Copy link
Contributor

Add MGLGlyphsRasterizationMode indicates how the map view load glyphs.

@lloydsheng lloydsheng requested a review from 1ec5 as a code owner October 22, 2020 12:24
@lloydsheng lloydsheng requested review from a team and julianrex October 22, 2020 12:24
@julianrex julianrex requested review from alexshalamov and jmkiley and removed request for a team and 1ec5 October 22, 2020 15:43
Copy link
Contributor

@julianrex julianrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! thank you

@@ -726,9 +726,23 @@ - (void)configureWithOptions:(MGLMapSnapshotOptions *)options {

// Create the snapshotter
mbgl::optional<std::string> localFontFamilyName = config.localFontFamilyName ? mbgl::optional<std::string>(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt;
mbgl::GlyphsRasterizationOptions glyphsRasterizationOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If MGLIdeographicFontFamilyName is provided and it is set to NO, and MGLGlyphsRasterizationMode is set to something other than MGLNoGlyphsRasterizedLocally, maybe we should print error and fallback to NoGlyphsRasterizedLocally option.

Maybe worth adding test for that combination?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely.

@@ -726,9 +726,23 @@ - (void)configureWithOptions:(MGLMapSnapshotOptions *)options {

// Create the snapshotter
mbgl::optional<std::string> localFontFamilyName = config.localFontFamilyName ? mbgl::optional<std::string>(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt;
mbgl::GlyphsRasterizationOptions glyphsRasterizationOptions;
glyphsRasterizationOptions.fontFamily = localFontFamilyName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if localFontFamilyName is nullopt, we should fallback to MGLNoGlyphsRasterizedLocally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


- (MGLGlyphsRasterizationMode)glyphsRasterizationModeWithInfoDictionaryObject:(id)infoDictionaryObject {
if (!infoDictionaryObject || ![infoDictionaryObject isKindOfClass:[NSString class]]) {
return MGLNoGlyphsRasterizedLocally;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should return something that represents 'unset' value, nil cc/ @julianrex?

With this PR, if user don't set MGLIdeographicFontFamilyName and MGLGlyphsRasterizationMode, glyphsRasterizationModeWithInfoDictionaryObject would return MGLNoGlyphsRasterizedLocally, thus, we will not render CJK characters locally. That will be a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. Rather than nil (which would make this return type a bit weird), what if we add MGLGlyphsRasterizationModeNone?

Comment on lines 559 to 572
mbgl::optional<std::string> localFontFamilyName = config.localFontFamilyName ? mbgl::optional<std::string>(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt;
auto renderer = std::make_unique<mbgl::Renderer>(_mbglView->getRendererBackend(), config.scaleFactor, localFontFamilyName);
mbgl::GlyphsRasterizationOptions glyphsRasterizationOptions;
glyphsRasterizationOptions.fontFamily = localFontFamilyName;
switch (config.glyphsRasterizationMode) {
case MGLNoGlyphsRasterizedLocally:
glyphsRasterizationOptions.rasterizationMode = mbgl::GlyphsRasterizationMode::NoGlyphsRasterizedLocally;
break;
case MGLIdeographsRasterizedLocally:
glyphsRasterizationOptions.rasterizationMode = mbgl::GlyphsRasterizationMode::IdeographsRasterizedLocally;
break;
case MGLAllGlyphsRasterizedLocally:
glyphsRasterizationOptions.rasterizationMode = mbgl::GlyphsRasterizationMode::AllGlyphsRasterizedLocally;
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block could be shared between snapshotter and mapview

@@ -726,9 +726,23 @@ - (void)configureWithOptions:(MGLMapSnapshotOptions *)options {

// Create the snapshotter
mbgl::optional<std::string> localFontFamilyName = config.localFontFamilyName ? mbgl::optional<std::string>(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt;
mbgl::GlyphsRasterizationOptions glyphsRasterizationOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely.

@@ -726,9 +726,23 @@ - (void)configureWithOptions:(MGLMapSnapshotOptions *)options {

// Create the snapshotter
mbgl::optional<std::string> localFontFamilyName = config.localFontFamilyName ? mbgl::optional<std::string>(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt;
mbgl::GlyphsRasterizationOptions glyphsRasterizationOptions;
glyphsRasterizationOptions.fontFamily = localFontFamilyName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


- (MGLGlyphsRasterizationMode)glyphsRasterizationModeWithInfoDictionaryObject:(id)infoDictionaryObject {
if (!infoDictionaryObject || ![infoDictionaryObject isKindOfClass:[NSString class]]) {
return MGLNoGlyphsRasterizedLocally;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. Rather than nil (which would make this return type a bit weird), what if we add MGLGlyphsRasterizationModeNone?

Comment on lines 7 to 13
typedef NS_ENUM(NSUInteger, MGLGlyphsRasterizationMode) {
/// No glyphs are rasterized locally. All glyphs are loaded from the server.
MGLNoGlyphsRasterizedLocally = 0,
/// Ideographs are rasterized locally, and they are not loaded from the server.
MGLIdeographsRasterizedLocally,
/// All glyphs are rasterized locally. No glyphs are loaded from the server.
MGLAllGlyphsRasterizedLocally
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These enums should have the same prefix, e.g. for Swift consumption. Although it's a mouthful, how about:

MGLGlyphsRasterizationModeNone
MGLGlyphsRasterizationModeIdeographsRasterizedLocally
MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally
MGLGlyphsRasterizationModeAllGlyphsRasterizedLocally

@lloydsheng
Copy link
Contributor Author

lloydsheng commented Oct 23, 2020

@alexshalamov @julianrex Thanks for your review 🙇 .

@"MGLIdeographsRasterizedLocally":@(MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally),
@"MGLAllGlyphsRasterizedLocally":@(MGLGlyphsRasterizationModeAllGlyphsRasterizedLocally)};

return (MGLGlyphsRasterizationMode)[nameOptionMap[infoDictionaryObject] integerValue];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other readers: this should result in MGLGlyphsRasterizationModeNone if infoDictionaryObject is not expected.

See: https://github.com/mapbox/mapbox-gl-native-ios/pull/517/files#diff-944ba4f88de8974791fb7cf7e890a87157c51513eb6e31179983619a8312c6a6R176

Comment on lines 10 to 13
/// No glyphs are rasterized locally. All glyphs are loaded from the server.
MGLGlyphsRasterizationModeIdeographsRasterizedLocally,
/// Ideographs are rasterized locally, and they are not loaded from the server.
MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments for these two enum values are incorrectly mixed.

Comment on lines 77 to 78
NSDictionary *nameOptionMap = @{@"MGLNoGlyphsRasterizedLocally":@(MGLGlyphsRasterizationModeIdeographsRasterizedLocally),
@"MGLIdeographsRasterizedLocally":@(MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mode values are wrongly matched. I am wondering why the tests are passed 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

mbgl::GlyphsRasterizationOptions options;
if (fontFamilyName == nil) {
if (rasterizationMode != MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally) {
MGLLogError(@"The `MGLIdeographicFontFamilyName` is set to `NO`, this will make `MGLGlyphsRasterizationMode` always be `MGLNoGlyphsRasterizedLocally`.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MGLIdeographicFontFamilyName can not fully reflect the font family names anymore, as it will also be used for mbgl::GlyphsRasterizationMode::AllGlyphsRasterizedLocally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll ticket this out and address after beta has landed.

rasterizationMode:(MGLGlyphsRasterizationMode)rasterizationMode {
mbgl::GlyphsRasterizationOptions options;
if (fontFamilyName == nil) {
if (rasterizationMode != MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that rasterizationMode == MGLGlyphsRasterizationModeNone?

options.rasterizationMode = mbgl::GlyphsRasterizationMode::AllGlyphsRasterizedLocally;
break;
default:
options.rasterizationMode = mbgl::GlyphsRasterizationMode::NoGlyphsRasterizedLocally;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about mode MGLGlyphsRasterizationModeNone?
And should we print an error log in case that the mode fallback to default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should always fallback to default. If fontFamilyName is not nil and user sets MGLNoGlyphsRasterizedLocally or MGLGlyphsRasterizationModeNone, I think we should warn and fallback to MGLIdeographsRasterizedLocally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to revisit and test the behavior here once beta is released.

return options;
}

options.fontFamily = mbgl::optional<std::string>(std::string(fontFamilyName.UTF8String));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: options.fontFamily = std::string(fontFamilyName.UTF8String); should be enough

@jmkiley jmkiley merged commit 5b239aa into main Oct 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants