From d2434d07517619d390e2e1f4b7952f6cf2c9e4ff Mon Sep 17 00:00:00 2001 From: m-stephen Date: Tue, 16 Jul 2019 11:39:34 +0800 Subject: [ios , macos] Exclude CJK resources from offline download by default (#14952) * [iOS, macOS] exclude CJK glyphs resources download by default. * [iOS, macOS] update iosapp * [iOS, macOS] update macOS * [iOS, macOS] update iOS change log * [iOS, macOS] update macOS change log * [iOS, macOS] update comment & add test cases * Update platform/darwin/test/MGLOfflineRegionTests.m Co-Authored-By: Jason Wray * Update platform/darwin/test/MGLOfflineRegionTests.m Co-Authored-By: Jason Wray * Update platform/darwin/test/MGLOfflineRegionTests.m Co-Authored-By: Jason Wray * Update platform/ios/CHANGELOG.md Co-Authored-By: Jason Wray * Update platform/macos/CHANGELOG.md Co-Authored-By: Jason Wray * Update platform/darwin/test/MGLOfflineRegionTests.m Co-Authored-By: Jason Wray --- platform/darwin/src/MGLOfflineRegion.h | 2 +- platform/darwin/src/MGLShapeOfflineRegion.mm | 2 +- platform/darwin/src/MGLTilePyramidOfflineRegion.mm | 2 +- platform/darwin/test/MGLOfflineRegionTests.m | 24 ++++++++++++++++++++-- platform/ios/CHANGELOG.md | 3 +++ .../ios/app/MBXOfflinePacksTableViewController.m | 6 ++++-- platform/macos/CHANGELOG.md | 2 +- platform/macos/app/MapDocument.m | 4 ++-- 8 files changed, 35 insertions(+), 10 deletions(-) diff --git a/platform/darwin/src/MGLOfflineRegion.h b/platform/darwin/src/MGLOfflineRegion.h index 6a9bdbc399..c668e3bf22 100644 --- a/platform/darwin/src/MGLOfflineRegion.h +++ b/platform/darwin/src/MGLOfflineRegion.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN See `MGLIdeographicFontFamilyName` setting. Also, for regions outside of China, Japan, and Korea, these glyphs will rarely appear for non-CJK users. - By default, this property is set to `YES`, so that the offline pack will + By default, this property is set to `NO`, so that the offline pack will include ideographic glyphs. */ @property (nonatomic) BOOL includesIdeographicGlyphs; diff --git a/platform/darwin/src/MGLShapeOfflineRegion.mm b/platform/darwin/src/MGLShapeOfflineRegion.mm index 25b6b8e166..b4f4b5e92a 100644 --- a/platform/darwin/src/MGLShapeOfflineRegion.mm +++ b/platform/darwin/src/MGLShapeOfflineRegion.mm @@ -72,7 +72,7 @@ _shape = shape; _minimumZoomLevel = minimumZoomLevel; _maximumZoomLevel = maximumZoomLevel; - _includesIdeographicGlyphs = YES; + _includesIdeographicGlyphs = NO; } return self; } diff --git a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm index a398d6baa4..73fcaa91d8 100644 --- a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm +++ b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm @@ -68,7 +68,7 @@ _bounds = bounds; _minimumZoomLevel = minimumZoomLevel; _maximumZoomLevel = maximumZoomLevel; - _includesIdeographicGlyphs = YES; + _includesIdeographicGlyphs = NO; } return self; } diff --git a/platform/darwin/test/MGLOfflineRegionTests.m b/platform/darwin/test/MGLOfflineRegionTests.m index 4d5767a8d2..0af9ebb5fa 100644 --- a/platform/darwin/test/MGLOfflineRegionTests.m +++ b/platform/darwin/test/MGLOfflineRegionTests.m @@ -12,7 +12,7 @@ MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid); MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:nil bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX]; XCTAssertEqualObjects(region.styleURL, [MGLStyle streetsStyleURLWithVersion:MGLStyleDefaultVersion], @"Streets isn’t the default style."); - + NSURL *localURL = [NSURL URLWithString:@"beautiful.style"]; XCTAssertThrowsSpecificNamed([[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:localURL bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX], NSException, MGLInvalidStyleURLException, @"No exception raised when initializing region with a local file URL as the style URL."); } @@ -22,7 +22,7 @@ MGLTilePyramidOfflineRegion *original = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURLWithVersion:MGLStyleDefaultVersion] bounds:bounds fromZoomLevel:5 toZoomLevel:10]; MGLTilePyramidOfflineRegion *copy = [original copy]; XCTAssertEqualObjects(original, copy, @"Tile pyramid region should be equal to its copy."); - + XCTAssertEqualObjects(original.styleURL, copy.styleURL, @"Style URL has changed."); XCTAssert(MGLCoordinateBoundsEqualToCoordinateBounds(original.bounds, copy.bounds), @"Bounds have changed."); XCTAssertEqual(original.minimumZoomLevel, copy.minimumZoomLevel, @"Minimum zoom level has changed."); @@ -48,4 +48,24 @@ XCTAssertEqual(original.includesIdeographicGlyphs, copy.includesIdeographicGlyphs, @"Include ideographs has changed."); } +- (void)testIncludesIdeographicGlyphsByDefault { + + // Tile pyramid offline region + { + MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid); + MGLTilePyramidOfflineRegion *tilePyramidOfflineRegion = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURLWithVersion:MGLStyleDefaultVersion] bounds:bounds fromZoomLevel:5 toZoomLevel:10]; + XCTAssertFalse(tilePyramidOfflineRegion.includesIdeographicGlyphs, @"tile pyramid offline region should not include ideographic glyphs"); + } + + // Shape offline region + { + NSString *geojson = @"{\"type\": \"Point\", \"coordinates\": [-3.8671874999999996, 52.482780222078226] }"; + NSError *error; + MGLShape *shape = [MGLShape shapeWithData: [geojson dataUsingEncoding:NSUTF8StringEncoding] encoding: NSUTF8StringEncoding error:&error]; + XCTAssertNil(error); + MGLShapeOfflineRegion *shapeOfflineRegion = [[MGLShapeOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURLWithVersion:MGLStyleDefaultVersion] shape:shape fromZoomLevel:5 toZoomLevel:10]; + XCTAssertFalse(shapeOfflineRegion.includesIdeographicGlyphs, @"tile pyramid offline region should not include ideographic glyphs"); + } +} + @end diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b187db42a3..61b0fbd9e5 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -8,6 +8,9 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed a custom geometry source bug caused by using the outdated tiles after style update [#15112](https://github.com/mapbox/mapbox-gl-native/pull/15112) +### Other changes +* Ideographic glyphs from Chinese, Japanese, and Korean are no longer downloaded by default as part of offline packs; they are instead rendered on-device, saving bandwidth and storage while improving performance. ([#14176](https://github.com/mapbox/mapbox-gl-native/pull/14176)) + ## 5.2.0 ### Offline maps diff --git a/platform/ios/app/MBXOfflinePacksTableViewController.m b/platform/ios/app/MBXOfflinePacksTableViewController.m index e237df4019..4459711b58 100644 --- a/platform/ios/app/MBXOfflinePacksTableViewController.m +++ b/platform/ios/app/MBXOfflinePacksTableViewController.m @@ -103,8 +103,10 @@ static NSString * const MBXOfflinePacksTableViewActiveCellReuseIdentifier = @"Ac } MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:mapView.styleURL bounds:mapView.visibleCoordinateBounds fromZoomLevel:mapView.zoomLevel toZoomLevel:mapView.maximumZoomLevel]; - BOOL hasIdeographicFontFamilyName = !![[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; - region.includesIdeographicGlyphs = hasIdeographicFontFamilyName; + id ideographicFontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; + if([ideographicFontFamilyName isKindOfClass:[NSNumber class]] && ![ideographicFontFamilyName boolValue]){ + region.includesIdeographicGlyphs = YES; + } NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{ MBXOfflinePackContextNameKey: name, }]; diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 8ca6391ff3..49dd5ff53a 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -4,11 +4,11 @@ * 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)) +* Ideographic glyphs from Chinese, Japanese, and Korean are no longer downloaded by default as part of offline packs; they are instead rendered on-device, saving bandwidth and storage while improving performance. ([#14176](https://github.com/mapbox/mapbox-gl-native/pull/14176)) * The `MGLIdeographicFontFamilyName` Info.plist key now also accepts an array of font family names, to customize 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)) * Performance improvements for queryRenderedFeatures API and optimization that allocates containers based on a number of rendered layers. ([#14930](https://github.com/mapbox/mapbox-gl-native/pull/14930)) * Fixed rendering layers after fill-extrusion regression caused by optimization of fill-extrusion rendering. ([#15065](https://github.com/mapbox/mapbox-gl-native/pull/15065)) - ### Styles and rendering * Setting `MGLMapView.contentInset` now moves the map’s focal point to the center of the content frame after insetting. ([#14664](https://github.com/mapbox/mapbox-gl-native/pull/14664)) diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 213aa33107..1ab8b690b9 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -932,8 +932,8 @@ NSArray> *MBXFlattenedShapes(NSArray> *sha self.minimumOfflinePackZoomLevelFormatter.maximum = @(ceil(self.mapView.maximumZoomLevel)); self.maximumOfflinePackZoomLevelFormatter.maximum = @(ceil(self.mapView.maximumZoomLevel)); - NSString *fontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; - self.includesIdeographicGlyphsBox.state = fontFamilyName ? NSOffState : NSOnState; + id ideographicFontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; + self.includesIdeographicGlyphsBox.state = ([ideographicFontFamilyName isKindOfClass:[NSNumber class]] && ![ideographicFontFamilyName boolValue]) ? NSOffState : NSOnState; [self.addOfflinePackWindow makeFirstResponder:self.offlinePackNameField]; __weak __typeof__(self) weakSelf = self; -- cgit v1.2.1