-
Notifications
You must be signed in to change notification settings - Fork 122
[ios] Add glyphs rasterization options #517
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
platform/ios/src/MGLMapView.mm
Outdated
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; | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
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 |
There was a problem hiding this comment.
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
@alexshalamov @julianrex Thanks for your review 🙇 . |
@"MGLIdeographsRasterizedLocally":@(MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally), | ||
@"MGLAllGlyphsRasterizedLocally":@(MGLGlyphsRasterizationModeAllGlyphsRasterizedLocally)}; | ||
|
||
return (MGLGlyphsRasterizationMode)[nameOptionMap[infoDictionaryObject] integerValue]; |
There was a problem hiding this comment.
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.
/// 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, |
There was a problem hiding this comment.
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.
NSDictionary *nameOptionMap = @{@"MGLNoGlyphsRasterizedLocally":@(MGLGlyphsRasterizationModeIdeographsRasterizedLocally), | ||
@"MGLIdeographsRasterizedLocally":@(MGLGlyphsRasterizationModeNoGlyphsRasterizedLocally), |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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`."); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
2505280
to
cca743c
Compare
Add
MGLGlyphsRasterizationMode
indicates how the map view load glyphs.