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

Commit

Permalink
remove text-max-size and icon-max-size
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored and jfirebaugh committed Aug 20, 2015
1 parent d1a0d7a commit 60e9712
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/mbgl/map/tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ std::unique_ptr<Bucket> TileWorker::createSymbolBucket(const GeometryTileLayer&
applyLayoutProperty(PropertyKey::IconIgnorePlacement, bucket_desc.layout, layout.icon.ignore_placement, z);
applyLayoutProperty(PropertyKey::IconOptional, bucket_desc.layout, layout.icon.optional, z);
applyLayoutProperty(PropertyKey::IconRotationAlignment, bucket_desc.layout, layout.icon.rotation_alignment, z);
applyLayoutProperty(PropertyKey::IconMaxSize, bucket_desc.layout, layout.icon.max_size, z);
applyLayoutProperty(PropertyKey::IconImage, bucket_desc.layout, layout.icon.image, z);
applyLayoutProperty(PropertyKey::IconPadding, bucket_desc.layout, layout.icon.padding, z);
applyLayoutProperty(PropertyKey::IconRotate, bucket_desc.layout, layout.icon.rotate, z);
Expand All @@ -251,7 +250,6 @@ std::unique_ptr<Bucket> TileWorker::createSymbolBucket(const GeometryTileLayer&
applyLayoutProperty(PropertyKey::TextRotationAlignment, bucket_desc.layout, layout.text.rotation_alignment, z);
applyLayoutProperty(PropertyKey::TextField, bucket_desc.layout, layout.text.field, z);
applyLayoutProperty(PropertyKey::TextFont, bucket_desc.layout, layout.text.font, z);
applyLayoutProperty(PropertyKey::TextMaxSize, bucket_desc.layout, layout.text.max_size, z);
applyLayoutProperty(PropertyKey::TextMaxWidth, bucket_desc.layout, layout.text.max_width, z);
applyLayoutProperty(PropertyKey::TextLineHeight, bucket_desc.layout, layout.text.line_height, z);
applyLayoutProperty(PropertyKey::TextLetterSpacing, bucket_desc.layout, layout.text.letter_spacing, z);
Expand All @@ -267,6 +265,11 @@ std::unique_ptr<Bucket> TileWorker::createSymbolBucket(const GeometryTileLayer&
applyLayoutProperty(PropertyKey::TextOffset, bucket_desc.layout, layout.text.offset, z);
applyLayoutProperty(PropertyKey::TextAllowOverlap, bucket_desc.layout, layout.text.allow_overlap, z);

applyLayoutProperty(PropertyKey::IconSize, bucket_desc.layout, layout.icon.size, z + 1);
applyLayoutProperty(PropertyKey::IconSize, bucket_desc.layout, layout.icon.max_size, 18);
applyLayoutProperty(PropertyKey::TextSize, bucket_desc.layout, layout.text.size, z + 1);
applyLayoutProperty(PropertyKey::TextSize, bucket_desc.layout, layout.text.max_size, 18);

if (bucket->needsDependencies(layer, bucket_desc.filter, *style.glyphStore, *style.sprite)) {
partialParse = true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
sdfShader.u_texsize = texsize;

// adjust min/max zooms for variable font sies
float zoomAdjust = std::log(fontSize / bucketProperties.max_size) / std::log(2);
float zoomAdjust = std::log(fontSize / bucketProperties.size) / std::log(2);

sdfShader.u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level

Expand Down Expand Up @@ -157,8 +157,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
? state.getAngle()
: 0;

// If layerStyle.size > bucket.info.fontSize then labels may collide
const float fontSize = properties.icon.size != 0 ? properties.icon.size : layout.icon.max_size;
const float fontSize = properties.icon.size;
const float fontScale = fontSize / 1.0f;

spriteAtlas->bind(state.isChanging() || layout.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf);
Expand Down Expand Up @@ -191,7 +190,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
iconShader->u_texsize = {{ float(spriteAtlas->getWidth()) / 4.0f, float(spriteAtlas->getHeight()) / 4.0f }};

// adjust min/max zooms for variable font sies
float zoomAdjust = std::log(fontSize / layout.icon.max_size) / std::log(2);
float zoomAdjust = std::log(fontSize / layout.icon.size) / std::log(2);

iconShader->u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level
iconShader->u_fadedist = 0 * 10;
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/renderer/symbol_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ void SymbolBucket::addFeature(const std::vector<std::vector<Coordinate>> &lines,
const float minScale = 0.5f;
const float glyphSize = 24.0f;

const float fontScale = layout.text.max_size / glyphSize;
const float fontScale = layout.text.size / glyphSize;
const float textBoxScale = collision.tilePixelRatio * fontScale;
const float iconBoxScale = collision.tilePixelRatio * layout.icon.max_size;
const float textMaxBoxScale = collision.tilePixelRatio * layout.text.max_size / glyphSize;
const float iconBoxScale = collision.tilePixelRatio * layout.icon.size;
const float symbolSpacing = collision.tilePixelRatio * layout.spacing;
const bool avoidEdges = layout.avoid_edges && layout.placement != PlacementType::Line;
const float textPadding = layout.text.padding * collision.tilePixelRatio;
Expand All @@ -302,7 +303,7 @@ void SymbolBucket::addFeature(const std::vector<std::vector<Coordinate>> &lines,

// Calculate the anchor points around which you want to place labels
Anchors anchors = isLine ?
getAnchors(line, symbolSpacing, textMaxAngle, shapedText.left, shapedText.right, shapedIcon.left, shapedIcon.right, glyphSize, textBoxScale, overscaling) :
getAnchors(line, symbolSpacing, textMaxAngle, shapedText.left, shapedText.right, shapedIcon.left, shapedIcon.right, glyphSize, textMaxBoxScale, overscaling) :
Anchors({ Anchor(float(line[0].x), float(line[0].y), 0, minScale) });

// For each potential label, create the placement features used to check for collisions, and the quads use for rendering.
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/style/property_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::IconIgnorePlacement, defaultStyleLayout<StyleLayoutSymbol>().icon.ignore_placement },
{ PropertyKey::IconOptional, defaultStyleLayout<StyleLayoutSymbol>().icon.optional },
{ PropertyKey::IconRotationAlignment, defaultStyleLayout<StyleLayoutSymbol>().icon.rotation_alignment },
{ PropertyKey::IconMaxSize, defaultStyleLayout<StyleLayoutSymbol>().icon.max_size },
{ PropertyKey::IconImage, defaultStyleLayout<StyleLayoutSymbol>().icon.image },
{ PropertyKey::IconRotate, defaultStyleLayout<StyleLayoutSymbol>().icon.rotate },
{ PropertyKey::IconPadding, defaultStyleLayout<StyleLayoutSymbol>().icon.padding },
Expand All @@ -80,7 +79,6 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::TextRotationAlignment, defaultStyleLayout<StyleLayoutSymbol>().text.rotation_alignment },
{ PropertyKey::TextField, defaultStyleLayout<StyleLayoutSymbol>().text.field },
{ PropertyKey::TextFont, defaultStyleLayout<StyleLayoutSymbol>().text.font },
{ PropertyKey::TextMaxSize, defaultStyleLayout<StyleLayoutSymbol>().text.max_size },
{ PropertyKey::TextMaxWidth, defaultStyleLayout<StyleLayoutSymbol>().text.max_width },
{ PropertyKey::TextLineHeight, defaultStyleLayout<StyleLayoutSymbol>().text.line_height },
{ PropertyKey::TextLetterSpacing, defaultStyleLayout<StyleLayoutSymbol>().text.letter_spacing },
Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/style/property_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ enum class PropertyKey {
IconIgnorePlacement,
IconOptional,
IconRotationAlignment,
IconMaxSize,
IconImage,
IconOffset,
IconPadding,
IconRotate,
IconKeepUpright,

TextOpacity,
TextSize,
TextColor,
TextHaloColor,
TextHaloWidth,
Expand All @@ -70,7 +68,7 @@ enum class PropertyKey {
TextRotationAlignment,
TextField,
TextFont,
TextMaxSize,
TextSize,
TextMaxWidth,
TextLineHeight,
TextLetterSpacing,
Expand Down
14 changes: 12 additions & 2 deletions src/mbgl/style/style_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const Tim
properties.set<SymbolProperties>();
SymbolProperties &symbol = properties.get<SymbolProperties>();
applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::IconSize, symbol.icon.size, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::IconColor, symbol.icon.color, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::IconHaloColor, symbol.icon.halo_color, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::IconHaloWidth, symbol.icon.halo_width, z, now, zoomHistory);
Expand All @@ -232,13 +231,24 @@ void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const Tim
applyStyleProperty(PropertyKey::IconTranslateAnchor, symbol.icon.translate_anchor, z, now, zoomHistory);

applyTransitionedStyleProperty(PropertyKey::TextOpacity, symbol.text.opacity, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextSize, symbol.text.size, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextColor, symbol.text.color, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextHaloColor, symbol.text.halo_color, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextHaloWidth, symbol.text.halo_width, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextHaloBlur, symbol.text.halo_blur, z, now, zoomHistory);
applyTransitionedStyleProperty(PropertyKey::TextTranslate, symbol.text.translate, z, now, zoomHistory);
applyStyleProperty(PropertyKey::TextTranslateAnchor, symbol.text.translate_anchor, z, now, zoomHistory);

// text-size and icon-size are layout properties but they also need to be evaluated as paint properties:
auto it = bucket->layout.properties.find(PropertyKey::IconSize);
if (it != bucket->layout.properties.end()) {
const PropertyEvaluator<float> evaluator(z, zoomHistory);
symbol.icon.size = mapbox::util::apply_visitor(evaluator, it->second);
}
it = bucket->layout.properties.find(PropertyKey::TextSize);
if (it != bucket->layout.properties.end()) {
const PropertyEvaluator<float> evaluator(z, zoomHistory);
symbol.text.size = mapbox::util::apply_visitor(evaluator, it->second);
}
}

template <>
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/style/style_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class StyleLayoutSymbol {
bool ignore_placement = false;
bool optional = false;
RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport;
float size = 1.0f;
float max_size = 1.0f;
std::string image;
float rotate = 0.0f;
Expand All @@ -62,6 +63,7 @@ class StyleLayoutSymbol {
RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport;
std::string field;
std::string font = "Open Sans Regular, Arial Unicode MS Regular";
float size = 16.0f;
float max_size = 16.0f;
float max_width = 15.0f /* em */;
float line_height = 1.2f /* em */;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/style/style_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void StyleParser::parseLayout(JSVal value, util::ptr<StyleBucket> &bucket) {
parseOptionalProperty<Function<bool>>("icon-ignore-placement", Key::IconIgnorePlacement, bucket->layout, value);
parseOptionalProperty<Function<bool>>("icon-optional", Key::IconOptional, bucket->layout, value);
parseOptionalProperty<Function<RotationAlignmentType>>("icon-rotation-alignment", Key::IconRotationAlignment, bucket->layout, value);
parseOptionalProperty<Function<float>>("icon-max-size", Key::IconMaxSize, bucket->layout, value);
parseOptionalProperty<Function<float>>("icon-size", Key::IconSize, bucket->layout, value);
parseOptionalProperty<Function<std::string>>("icon-image", Key::IconImage, bucket->layout, value);
parseOptionalProperty<Function<float>>("icon-rotate", Key::IconRotate, bucket->layout, value);
parseOptionalProperty<Function<float>>("icon-padding", Key::IconPadding, bucket->layout, value);
Expand All @@ -884,7 +884,7 @@ void StyleParser::parseLayout(JSVal value, util::ptr<StyleBucket> &bucket) {
parseOptionalProperty<Function<RotationAlignmentType>>("text-rotation-alignment", Key::TextRotationAlignment, bucket->layout, value);
parseOptionalProperty<Function<std::string>>("text-field", Key::TextField, bucket->layout, value);
parseOptionalProperty<Function<std::string>>("text-font", Key::TextFont, bucket->layout, value);
parseOptionalProperty<Function<float>>("text-max-size", Key::TextMaxSize, bucket->layout, value);
parseOptionalProperty<Function<float>>("text-size", Key::TextSize, bucket->layout, value);
parseOptionalProperty<Function<float>>("text-max-width", Key::TextMaxWidth, bucket->layout, value);
parseOptionalProperty<Function<float>>("text-line-height", Key::TextLineHeight, bucket->layout, value);
parseOptionalProperty<Function<float>>("text-letter-spacing", Key::TextLetterSpacing, bucket->layout, value);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/util/geojsonvt

0 comments on commit 60e9712

Please sign in to comment.