[macos] Assume sRGB for mbgl expressions, CSS in attribution

Assume mbgl needs colors in the sRGB color space rather than the calibrated RGB color space. Fixed link colors when creating attribution from HTML.
This commit is contained in:
Minh Nguyễn
2018-03-06 00:32:12 -08:00
committed by Minh Nguyễn
parent 12664cd4c4
commit 6c0599b536
5 changed files with 37 additions and 13 deletions

View File

@@ -49,7 +49,12 @@
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:

View File

@@ -66,8 +66,16 @@
// 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, @{
@@ -82,7 +90,7 @@
#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);

View File

@@ -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))

View File

@@ -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;

View File

@@ -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 }};
}