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

Convert colors to sRGB for mbgl; fix title case unit tests #11391

Merged
merged 3 commits into from
Mar 8, 2018
Merged
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
7 changes: 6 additions & 1 deletion platform/darwin/src/MGLAttributionInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ @implementation MGLAttributionInfo
CGFloat blue;
CGFloat alpha;
#if !TARGET_OS_IPHONE
linkColor = [linkColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
// CSS uses the sRGB color space.
if ([NSColor redColor].colorSpaceName == NSCalibratedRGBColorSpace) {
linkColor = [linkColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
} else {
linkColor = [linkColor colorUsingColorSpace:[NSColorSpace sRGBColorSpace]];
}
#endif
[linkColor getRed:&red green:&green blue:&blue alpha:&alpha];
[css appendFormat:
Expand Down
6 changes: 5 additions & 1 deletion platform/darwin/src/NSString+MGLAdditions.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#import "NSString+MGLAdditions.h"

#if TARGET_OS_OSX
#import <Availability.h>
#endif

@implementation NSString (MGLAdditions)

- (NSRange)mgl_wholeRange {
Expand All @@ -13,7 +17,7 @@ - (nullable NSString *)mgl_stringOrNilIfEmpty {
- (NSString *)mgl_titleCasedStringWithLocale:(NSLocale *)locale {
NSMutableString *string = self.mutableCopy;
NSOrthography *orthography;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if ([NSOrthography respondsToSelector:@selector(defaultOrthographyForLanguage:)]) {
Expand Down
17 changes: 11 additions & 6 deletions platform/darwin/test/MGLSDKTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extension MGLSDKTestHelpers {
class func protocolMethodDescriptions(_ p: Protocol) -> Set<String> {
var methods = Set<String>()
var methodCount = UInt32()
let methodDescriptionList: UnsafeMutablePointer<objc_method_description>! = protocol_copyMethodDescriptionList(p, false, true, &methodCount)
let methodDescriptionList = protocol_copyMethodDescriptionList(p, false, true, &methodCount)
for i in 0..<Int(methodCount) {
let description: objc_method_description = methodDescriptionList[i]
let description = methodDescriptionList![i]
XCTAssertNotNil(description.name?.description)
methods.insert(description.name!.description)
}
Expand All @@ -36,11 +36,16 @@ extension MGLSDKTestHelpers {
class func classMethodDescriptions(_ cls: Swift.AnyClass) -> Set<String> {
var methods = Set<String>()
var methodCount = UInt32()
let methodList: UnsafeMutablePointer<Method?>! = class_copyMethodList(cls, &methodCount)
let methodList = class_copyMethodList(cls, &methodCount)
for i in 0..<Int(methodCount) {
let method = methodList[i]
let selector : Selector = method_getName(method)
methods.insert(selector.description)
let method = methodList![i]
let selector = method_getName(method)
#if os(macOS)
methods.insert(selector.description)
#else
XCTAssertNotNil(selector)
methods.insert(selector!.description)
#endif
}
free(methodList)
return methods
Expand Down
12 changes: 10 additions & 2 deletions platform/darwin/test/MGLTileSetTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ - (void)testTileSetFromTileURLTemplates {
// when the tile set has attribution infos
MGLAttributionInfo *mapboxInfo = [[MGLAttributionInfo alloc] initWithTitle:[[NSAttributedString alloc] initWithString:@"Mapbox"]
URL:[NSURL URLWithString:@"https://www.mapbox.com/"]];
#if TARGET_OS_IPHONE
UIColor *redColor = [UIColor redColor];
#else
// CSS uses the sRGB color space. In macOS 10.12 Sierra and below,
// -[NSColor redColor] is in the calibrated RGB space and has a slightly
// different sRGB value than on iOS and macOS 10.13 High Sierra.
NSColor *redColor = [NSColor colorWithSRGBRed:1 green:0 blue:0 alpha:1];
#endif
NSAttributedString *gl = [[NSAttributedString alloc] initWithString:@"GL" attributes:@{
NSBackgroundColorAttributeName: [MGLColor redColor],
NSBackgroundColorAttributeName: redColor,
}];
MGLAttributionInfo *glInfo = [[MGLAttributionInfo alloc] initWithTitle:gl URL:nil];
tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
Expand All @@ -82,7 +90,7 @@ - (void)testTileSetFromTileURLTemplates {
#else
NSString *html = (@"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica\">"
@"<a href=\"https://www.mapbox.com/\">Mapbox</a> </font>"
@"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica; background-color: #ff2600\">GL</font>\n");
@"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica; background-color: #ff0000\">GL</font>\n");
#endif
XCTAssertEqualObjects(@(tileSet.attribution.c_str()), html);

Expand Down
3 changes: 2 additions & 1 deletion platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## 0.7.0

### Styles and rendering
### Styles

* Added support for a new layer type: `MGLHeatmapStyleLayer`, a powerful way to visualize point data distributions using heatmaps, fully customizable through runtime styling. [#11046](https://github.com/mapbox/mapbox-gl-native/pull/11046)
* The layout and paint properties on subclasses of `MGLStyleLayer` are now of type `NSExpression` instead of `MGLStyleValue`. A new “Predicates and Expressions” guide provides an overview of the supported operators. ([#10726](https://github.com/mapbox/mapbox-gl-native/pull/10726))
* Added an `MGLComputedShapeSource` class that allows applications to supply vector data to a style layer on a per-tile basis. ([#9983](https://github.com/mapbox/mapbox-gl-native/pull/9983))
* A style can now display smooth hillshading and customize its appearance at runtime using the `MGLHillshadeStyleLayer` class. Hillshading is based on a rasterized digital elevation model supplied by the `MGLRasterDEMSource` class. ([#10642](https://github.com/mapbox/mapbox-gl-native/pull/10642))
* Fixed incorrect color calibration on macOS 10.13 High Sierra when using color-related methods of `MGLStyleLayer` subclasses, as well as when displaying an `MGLAttributionInfo`. It is no longer necessary to explicitly convert an `NSColor` to the sRGB color space before using these classes on High Sierra. ([#11391](https://github.com/mapbox/mapbox-gl-native/pull/11391))
* The `MGLSymbolStyleLayer.textFontNames` property can now depend on a feature’s attributes. ([#10850](https://github.com/mapbox/mapbox-gl-native/pull/10850))
* Properties such as `MGLSymbolStyleLayer.iconAllowsOverlap` and `MGLSymbolStyleLayer.iconIgnoresPlacement` now account for symbols in other sources. ([#10436](https://github.com/mapbox/mapbox-gl-native/pull/10436))

Expand Down
12 changes: 6 additions & 6 deletions platform/macos/macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@
TargetAttributes = {
DA839E911CC2E3400062CAFB = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0830;
LastSwiftMigration = 0920;
};
DAAA17961CE13BAE00731EFE = {
CreatedOnToolsVersion = 7.3.1;
Expand All @@ -1388,7 +1388,7 @@
};
DAE6C3301CC30DB200DB3429 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
};
};
};
Expand Down Expand Up @@ -1885,7 +1885,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
PRODUCT_NAME = "Mapbox GL";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1900,7 +1900,7 @@
OTHER_CFLAGS = "-fvisibility=hidden";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
PRODUCT_NAME = "Mapbox GL";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down Expand Up @@ -2026,7 +2026,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -2053,7 +2053,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion platform/macos/src/NSColor+MGLAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@interface NSColor (MGLAdditions)

/**
Converts the color into an mbgl::Color in calibrated RGB space.
Converts the color into an mbgl::Color in sRGB space.
*/
- (mbgl::Color)mgl_color;

Expand Down
26 changes: 18 additions & 8 deletions platform/macos/src/NSColor+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@

@implementation NSColor (MGLAdditions)

- (mbgl::Color)mgl_color
{
- (mbgl::Color)mgl_color {
CGFloat r, g, b, a;

[[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
// The Mapbox Style Specification does not specify a color space, but it is
// assumed to be sRGB for consistency with CSS.
NSColor *srgbColor = self;
if ([NSColor redColor].colorSpaceName == NSCalibratedRGBColorSpace) {
srgbColor = [srgbColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
} else {
srgbColor = [srgbColor colorUsingColorSpace:[NSColorSpace sRGBColorSpace]];
}
[srgbColor getRed:&r green:&g blue:&b alpha:&a];

return { (float)r, (float)g, (float)b, (float)a };
}

+ (NSColor *)mgl_colorWithColor:(mbgl::Color)color
{
return [NSColor colorWithCalibratedRed:color.r green:color.g blue:color.b alpha:color.a];
+ (NSColor *)mgl_colorWithColor:(mbgl::Color)color {
// macOS 10.12 Sierra and below uses calibrated RGB by default.
if ([NSColor redColor].colorSpaceName == NSCalibratedRGBColorSpace) {
return [NSColor colorWithCalibratedRed:color.r green:color.g blue:color.b alpha:color.a];
} else {
return [NSColor colorWithRed:color.r green:color.g blue:color.b alpha:color.a];
}
}

- (mbgl::style::PropertyValue<mbgl::Color>)mgl_colorPropertyValue
{
- (mbgl::style::PropertyValue<mbgl::Color>)mgl_colorPropertyValue {
mbgl::Color color = self.mgl_color;
return {{ color.r, color.g, color.b, color.a }};
}
Expand Down