StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string& _value) { switch (key) { case StyleParamKey::extrude: { return parseExtrudeString(_value); } case StyleParamKey::text_wrap: { int textWrap; if (_value == "false") { return std::numeric_limits<uint32_t>::max(); } if (_value == "true") { return 15; // DEFAULT } if (parseInt(_value, textWrap) > 0 && textWrap > 0) { return static_cast<uint32_t>(textWrap); } return std::numeric_limits<uint32_t>::max(); } case StyleParamKey::text_offset: case StyleParamKey::offset: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec) || std::isnan(vec.value.y)) { LOGW("Invalid offset parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::size: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec)) { LOGW("Invalid size parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::transition_hide_time: case StyleParamKey::transition_show_time: case StyleParamKey::transition_selected_time: case StyleParamKey::text_transition_hide_time: case StyleParamKey::text_transition_show_time: case StyleParamKey::text_transition_selected_time: { float time = 0.0f; if (!parseTime(_value, time)) { LOGW("Invalid time param '%s'", _value.c_str()); } return time; } case StyleParamKey::text_font_family: case StyleParamKey::text_font_weight: case StyleParamKey::text_font_style: { std::string normalized = _value; std::transform(normalized.begin(), normalized.end(), normalized.begin(), ::tolower); return normalized; } case StyleParamKey::text_align: case StyleParamKey::anchor: case StyleParamKey::text_anchor: case StyleParamKey::text_source: case StyleParamKey::text_transform: case StyleParamKey::sprite: case StyleParamKey::sprite_default: case StyleParamKey::style: case StyleParamKey::outline_style: case StyleParamKey::text_repeat_group: return _value; case StyleParamKey::text_font_size: { float fontSize = 0.f; if (!parseFontSize(_value, fontSize)) { LOGW("Invalid font-size '%s'.", _value.c_str()); } return fontSize; } case StyleParamKey::centroid: case StyleParamKey::interactive: case StyleParamKey::text_interactive: case StyleParamKey::tile_edges: case StyleParamKey::visible: case StyleParamKey::collide: case StyleParamKey::text_collide: if (_value == "true") { return true; } if (_value == "false") { return false; } LOGW("Bool value required for capitalized/visible. Using Default."); break; case StyleParamKey::order: case StyleParamKey::outline_order: case StyleParamKey::priority: case StyleParamKey::text_priority: { int num; if (parseInt(_value, num) > 0) { if (num >= 0) { return static_cast<uint32_t>(num); } } LOGW("Invalid '%s' value '%s'", keyName(key).c_str(), _value.c_str()); break; } case StyleParamKey::text_repeat_distance: { ValueUnitPair repeatDistance; repeatDistance.unit = Unit::pixel; int pos = parseValueUnitPair(_value, 0, repeatDistance); if (pos < 0) { LOGW("Invalid repeat distance value '%s'", _value.c_str()); repeatDistance.value = 256.0f; repeatDistance.unit = Unit::pixel; } else { if (repeatDistance.unit != Unit::pixel) { LOGW("Invalid unit provided for repeat distance"); } } return Width(repeatDistance); } case StyleParamKey::width: case StyleParamKey::outline_width: { ValueUnitPair width; width.unit = Unit::meter; int pos = parseValueUnitPair(_value, 0, width); if (pos < 0) { LOGW("Invalid width value '%s'", _value.c_str()); width.value = 2.0f; width.unit = Unit::pixel; } return Width(width); } case StyleParamKey::miter_limit: case StyleParamKey::outline_miter_limit: case StyleParamKey::text_font_stroke_width: { double num; if (parseFloat(_value, num) > 0) { return static_cast<float>(num); } break; } case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: return parseColor(_value); case StyleParamKey::cap: case StyleParamKey::outline_cap: return static_cast<uint32_t>(CapTypeFromString(_value)); case StyleParamKey::join: case StyleParamKey::outline_join: return static_cast<uint32_t>(JoinTypeFromString(_value)); default: break; } return none_type{}; }
StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string& _value) { switch (key) { case StyleParamKey::extrude: { return parseExtrudeString(_value); } case StyleParamKey::text_wrap: { int textWrap; if (_value == "false") { return std::numeric_limits<uint32_t>::max(); } if (_value == "true") { return uint32_t(15); // DEFAULT } if (parseInt(_value, textWrap) > 0 && textWrap > 0) { return static_cast<uint32_t>(textWrap); } return std::numeric_limits<uint32_t>::max(); } case StyleParamKey::text_offset: case StyleParamKey::offset: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec) || std::isnan(vec.value.y)) { LOGW("Invalid offset parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::size: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec)) { LOGW("Invalid size parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::transition_hide_time: case StyleParamKey::transition_show_time: case StyleParamKey::transition_selected_time: case StyleParamKey::text_transition_hide_time: case StyleParamKey::text_transition_show_time: case StyleParamKey::text_transition_selected_time: { float time = 0.0f; if (!parseTime(_value, time)) { LOGW("Invalid time param '%s'", _value.c_str()); } return time; } case StyleParamKey::text_font_family: case StyleParamKey::text_font_weight: case StyleParamKey::text_font_style: { std::string normalized = _value; std::transform(normalized.begin(), normalized.end(), normalized.begin(), ::tolower); return normalized; } case StyleParamKey::anchor: case StyleParamKey::text_anchor: { LabelProperty::Anchors anchors; for (auto& anchor : splitString(_value, ',')) { if (anchors.count == LabelProperty::max_anchors) { break; } LabelProperty::Anchor labelAnchor; if (LabelProperty::anchor(anchor, labelAnchor)) { anchors.anchor[anchors.count++] = labelAnchor; } else { LOG("Invalid anchor %s", anchor.c_str()); } } return anchors; } case StyleParamKey::placement: { LabelProperty::Placement placement = LabelProperty::Placement::vertex; if (!LabelProperty::placement(_value, placement)) { LOG("Invalid placement parameter, Setting vertex as default."); } return placement; } case StyleParamKey::text_align: case StyleParamKey::text_source: case StyleParamKey::text_transform: case StyleParamKey::sprite: case StyleParamKey::sprite_default: case StyleParamKey::style: case StyleParamKey::outline_style: case StyleParamKey::repeat_group: case StyleParamKey::text_repeat_group: return _value; case StyleParamKey::text_font_size: { float fontSize = 0.f; if (!parseFontSize(_value, fontSize)) { LOGW("Invalid font-size '%s'.", _value.c_str()); } return fontSize; } case StyleParamKey::flat: case StyleParamKey::interactive: case StyleParamKey::text_interactive: case StyleParamKey::tile_edges: case StyleParamKey::visible: case StyleParamKey::text_visible: case StyleParamKey::outline_visible: case StyleParamKey::collide: case StyleParamKey::text_optional: case StyleParamKey::text_collide: if (_value == "true") { return true; } if (_value == "false") { return false; } LOGW("Invalid boolean value %s for key %s", _value.c_str(), StyleParam::keyName(key).c_str()); break; case StyleParamKey::text_order: LOGW("text:order parameter is ignored."); break; case StyleParamKey::order: case StyleParamKey::outline_order: case StyleParamKey::priority: case StyleParamKey::text_priority: { int num; if (parseInt(_value, num) > 0) { if (num >= 0) { return static_cast<uint32_t>(num); } } LOGW("Invalid '%s' value '%s'", keyName(key).c_str(), _value.c_str()); break; } case StyleParamKey::placement_spacing: { ValueUnitPair placementSpacing; placementSpacing.unit = Unit::pixel; int pos = parseValueUnitPair(_value, 0, placementSpacing); if (pos < 0) { LOGW("Invalid placement spacing value '%s'", _value.c_str()); placementSpacing.value = 80.0f; placementSpacing.unit = Unit::pixel; } else { if (placementSpacing.unit != Unit::pixel) { LOGW("Invalid unit provided for placement spacing"); } } return Width(placementSpacing); } case StyleParamKey::repeat_distance: case StyleParamKey::text_repeat_distance: { ValueUnitPair repeatDistance; repeatDistance.unit = Unit::pixel; int pos = parseValueUnitPair(_value, 0, repeatDistance); if (pos < 0) { LOGW("Invalid repeat distance value '%s'", _value.c_str()); repeatDistance.value = 256.0f; repeatDistance.unit = Unit::pixel; } else { if (repeatDistance.unit != Unit::pixel) { LOGW("Invalid unit provided for repeat distance"); } } return Width(repeatDistance); } case StyleParamKey::width: case StyleParamKey::outline_width: { ValueUnitPair width; width.unit = Unit::meter; int pos = parseValueUnitPair(_value, 0, width); if (pos < 0) { LOGW("Invalid width value '%s'", _value.c_str()); width.value = 2.0f; width.unit = Unit::pixel; } return Width(width); } case StyleParamKey::angle: { double num; if (_value == "auto") { return std::nanf("1"); } else if (parseFloat(_value, num) > 0) { return static_cast<float>(num); } break; } case StyleParamKey::miter_limit: case StyleParamKey::outline_miter_limit: case StyleParamKey::placement_min_length_ratio: case StyleParamKey::text_font_stroke_width: { double num; if (parseFloat(_value, num) > 0) { return static_cast<float>(num); } break; } case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: return parseColor(_value); case StyleParamKey::cap: case StyleParamKey::outline_cap: return static_cast<uint32_t>(CapTypeFromString(_value)); case StyleParamKey::join: case StyleParamKey::outline_join: return static_cast<uint32_t>(JoinTypeFromString(_value)); default: break; } return none_type{}; }