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

Disallow expressions for text-font, or require fontstacks to be listed up front #9939

Closed
jfirebaugh opened this issue Sep 8, 2017 · 5 comments · Fixed by #10850
Closed
Labels
Core The cross-platform C++ core, aka mbgl

Comments

@jfirebaugh
Copy link
Contributor

One of the components of an offline region download is the complete set of glyph range PBFs for all the font stacks used by that region's style. We currently determine the set of font stacks via this method:

std::vector<FontStack> Parser::fontStacks() const {
std::set<FontStack> optional;
for (const auto& layer : layers) {
if (layer->is<SymbolLayer>()) {
PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont();
if (textFont.isUndefined()) {
optional.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
} else if (textFont.isConstant()) {
optional.insert(textFont.asConstant());
} else if (textFont.isCameraFunction()) {
textFont.asCameraFunction().stops.match(
[&] (const auto& stops) {
for (const auto& stop : stops.stops) {
optional.insert(stop.second);
}
}
);
}
}
}
return std::vector<FontStack>(optional.begin(), optional.end());
}

This will fail for text-font properties that use an expression. We need to either disallows the use of expressions for text-font, or introduce a new top-level style spec property that explicitly declares all the font stacks that the style uses (or at least the font stacks that should be available offline).

cc @anandthakker

@anandthakker
Copy link
Contributor

@jfirebaugh as an in-between compromise, we could allow expressions of some tightly constrained form for text-font, such that we could implement the equivalent of the above code to collect the possible values from literals in the expression.

@nickidlugash
Copy link
Contributor

nickidlugash commented Sep 9, 2017

we could allow expressions of some tightly constrained form for text-font

Could expressions that only include literal values be allowed? I think the most common use cases for expressions for text-font would mainly just involve literal values (e.g. in match expressions and/or zoom curves).

@kkaefer kkaefer added the Core The cross-platform C++ core, aka mbgl label Sep 11, 2017
@anandthakker
Copy link
Contributor

anandthakker commented Sep 11, 2017

Yeah, along the lines of @nickidlugash's point, one way to formulate this restriction that seems pretty reasonable both to implement and communicate:

text-font expressions must have a finite number of output values. I.e., varying expressions like [zoom], [get, property_name], [id] may not be used to construct the output value for a text-font expression.

So [ "concat", "Wingdings", ["match", ["get", "font-weight"], "regular", "", "bold", " Bold"]] would fail validation with the above error message, but [ "match", ["get", "font-weight"], "regular", "Wingdings", "bold", "Wingdings Bold"] would pass.

update: Hmm, actually the stated restriction doesn't quite capture it, since it technically would describe both of the examples above.

@jfirebaugh
Copy link
Contributor Author

That also sounds more restrictive than what @nickidlugash wants. E.g., it disallows things like ["curve", ["step"], ["zoom"], "Stack A", 4, "Stack B"].

@jfirebaugh
Copy link
Contributor Author

So long as text-font allows only feature-constant expressions, static analysis can determine the bounded set of possible output values. If we allow text-font to have feature-varying expressions, then some expressions will be ok (e.g. ["match", ["get", "foo"], "a", "Stack A", "Stack B"]), while others will not (["get", "stack"]). Still, static analysis should be able to tell when the set of possible output values is unbounded, and we can disallow those cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants