7#include "mapcssdeclaration_p.h"
10#include "mapcssproperty.h"
11#include "mapcssvalue_p.h"
25}
static constexpr const property_types[] = {
77 {
"z-index", MapCSSProperty::ZIndex, MapCSSDeclaration::NoFlag },
83}
static constexpr const capstyle_map[] = {
92}
static constexpr const joinstyle_map[] = {
101}
static constexpr const capitalizationstyle_map[] = {
112 MapCSSDeclaration::Unit unit;
113}
static constexpr const unit_map[] = {
114 {
"m", MapCSSDeclaration::Meters },
115 {
"pt", MapCSSDeclaration::Point },
116 {
"px", MapCSSDeclaration::Pixels },
121 MapCSSDeclaration::Position position;
122}
static constexpr const position_map[] = {
123 {
"center", MapCSSDeclaration::Position::Center },
124 {
"line", MapCSSDeclaration::Position::Line },
127MapCSSDeclaration::MapCSSDeclaration(Type type)
132MapCSSDeclaration::~MapCSSDeclaration() =
default;
134bool MapCSSDeclaration::isValid()
const
137 case PropertyDeclaration:
138 return property() != MapCSSProperty::Unknown;
140 return !m_identValue.isEmpty();
141 case ClassDeclaration:
142 return !m_class.isNull();
149MapCSSDeclaration::Type MapCSSDeclaration::type()
const
159int MapCSSDeclaration::propertyFlags()
const
164int MapCSSDeclaration::intValue()
const
166 return m_doubleValue;
169double MapCSSDeclaration::doubleValue()
const
171 return m_doubleValue;
174bool MapCSSDeclaration::boolValue()
const
179QString MapCSSDeclaration::stringValue()
const
181 return m_stringValue;
184QColor MapCSSDeclaration::colorValue()
const
186 if (!m_colorValue.isValid() && !m_stringValue.isEmpty()) {
187 return QColor(m_stringValue);
207void MapCSSDeclaration::setDoubleValue(
double val)
212void MapCSSDeclaration::setBoolValue(
bool val)
217bool MapCSSDeclaration::hasExpression()
const
219 return m_evalExpression.isValid();
222MapCSSValue MapCSSDeclaration::evaluateExpression(
const MapCSSExpressionContext &context)
const
224 return m_evalExpression.evaluate(context);
227MapCSSProperty MapCSSDeclaration::propertyFromName(
const char *name, std::size_t len)
229 const auto it = std::lower_bound(std::begin(property_types), std::end(property_types), name, [len](
const auto &lhs,
const char *rhs) {
230 const auto lhsLen = std::strlen(lhs.name);
231 const auto cmp = std::strncmp(lhs.name, rhs, std::min(lhsLen, len));
232 return cmp < 0 || (cmp == 0 && lhsLen < len);
234 if (it == std::end(property_types) || std::strncmp((*it).name, name, std::max(len, std::strlen((*it).name))) != 0) {
235 return MapCSSProperty::Unknown;
237 return (*it).property;
240void MapCSSDeclaration::setPropertyName(
const char *name, std::size_t len)
242 const auto it = std::lower_bound(std::begin(property_types), std::end(property_types), name, [len](
const auto &lhs,
const char *rhs) {
243 const auto lhsLen = std::strlen(lhs.name);
244 const auto cmp = std::strncmp(lhs.name, rhs, std::min(lhsLen, len));
245 return cmp < 0 || (cmp == 0 && lhsLen < len);
247 if (it == std::end(property_types) || std::strncmp((*it).name, name, std::max(len, std::strlen((*it).name))) != 0) {
249 m_property = MapCSSProperty::Unknown;
252 m_property = (*it).property;
253 m_flags = (*it).flags;
256void MapCSSDeclaration::setIdentifierValue(
const char *val,
int len)
261void MapCSSDeclaration::setStringValue(
char *str)
267void MapCSSDeclaration::setColorRgba(uint32_t argb)
275 m_dashValue = dashes;
280 for (
const auto &c : capstyle_map) {
281 if (std::strcmp(c.name, m_identValue.constData()) == 0) {
285 qDebug() <<
"unknown line cap style:" << m_identValue;
291 for (
const auto &j : joinstyle_map) {
292 if (std::strcmp(j.name, m_identValue.constData()) == 0) {
301 for (
const auto &c : capitalizationstyle_map) {
302 if (std::strcmp(c.name, m_identValue.constData()) == 0) {
303 return c.capitalizationStyle;
309bool MapCSSDeclaration::isBoldStyle()
const
311 return m_identValue ==
"bold";
314bool MapCSSDeclaration::isItalicStyle()
const
316 return m_identValue ==
"italic";
319bool MapCSSDeclaration::isUnderlineStyle()
const
321 return m_identValue ==
"underline";
324MapCSSDeclaration::Position MapCSSDeclaration::textPosition()
const
326 for (
const auto &p : position_map) {
327 if (std::strcmp(p.name, m_identValue.constData()) == 0) {
331 return Position::NoPostion;
334MapCSSDeclaration::Unit MapCSSDeclaration::unit()
const
339void MapCSSDeclaration::setUnit(
const char *val,
int len)
341 for (
const auto &u : unit_map) {
342 if (std::strncmp(u.name, val, std::max<std::size_t>(std::strlen(u.name), len)) == 0) {
351ClassSelectorKey MapCSSDeclaration::classSelectorKey()
const
356void MapCSSDeclaration::setClassSelectorKey(ClassSelectorKey key)
364 if (m_type == TagDeclaration) {
365 m_tagKey = dataSet.
makeTagKey(m_identValue.constData());
368 if (m_evalExpression.isValid()) {
369 m_evalExpression.compile(dataSet);
376 for (
const auto c : str) {
394void MapCSSDeclaration::write(
QIODevice *out)
const
399 case PropertyDeclaration:
400 for (
const auto &p : property_types) {
401 if (p.property == m_property) {
408 if (!std::isnan(m_doubleValue)) {
410 }
else if (m_colorValue.isValid()) {
412 }
else if (!m_dashValue.isEmpty()) {
413 for (
const auto &d : m_dashValue) {
417 }
else if (!m_stringValue.isNull()) {
418 writeQuotedString(out, m_stringValue.toUtf8());
419 }
else if (!m_identValue.isEmpty()) {
420 out->
write(m_identValue);
421 }
else if (m_evalExpression.isValid()) {
423 m_evalExpression.write(out);
426 out->
write(m_boolValue ?
"true" :
"false");
429 for (
const auto &u : unit_map) {
430 if (u.unit == m_unit) {
438 out->
write(m_identValue);
439 if (!std::isnan(m_doubleValue)) {
442 }
else if (!m_stringValue.isEmpty()) {
444 writeQuotedString(out, m_stringValue.toUtf8());
445 }
else if (m_evalExpression.isValid()) {
446 out->
write(
" = eval(");
447 m_evalExpression.write(out);
451 case ClassDeclaration:
453 out->
write(m_class.name());
A set of nodes, ways and relations.
TagKey makeTagKey(const char *keyName, StringMemory keyMemOpt=StringMemory::Transient)
Create a tag key for the given tag name.
OSM-based multi-floor indoor maps for buildings.
MapCSSProperty
Known properties in MapCSS declarations.
@ LineJoin
line end cap style: none (default), round, square
@ CasingDashes
line casing opacity
@ IconWidth
URL to the icon image.
@ FontStyle
font weight: bold or normal (default)
@ ShieldText
shield casing width
@ CasingOpacity
line casing color
@ ShieldFrameWidth
shield frame color
@ TextOpacity
text color used for the label
@ CasingColor
line casing width
@ TextRequireFit
text halo radius
@ FillImage
area fill opacity
@ FillColor
line casing join style
@ ShieldFrameColor
shield opacity
@ LineCap
fill image for the line
@ CasingLineCap
line casing dash pattern
@ TextHaloColor
label content
@ IconAllowIconOverlap
the equivalent to CartoCSS's allow-overlap, non-standard extension
@ ShieldOpacity
shield color
@ FontVariant
italic or normal (default)
@ CasingLineJoin
line casing end cap
@ ShieldCasingWidth
shield casing color
@ Text
maximum width before wrapping
@ TextTransform
none (default) or underline
@ TextColor
none (default), uppercase, lowercase or capitalize
@ ShieldImage
text to render on the shield
@ IconAllowTextOverlap
for colorized SVGs, non-standard extension
@ ShieldShape
background image of the shield
@ ShieldColor
text has to fit into its associated geometry (custom extension)
@ TextHaloRadius
text halo color
@ ShieldCasingColor
shield frame width (0 to disable)
@ CasingWidth
line join style: round (default), miter, bevel
@ TextDecoration
small-caps or normal (default)
@ IconImage
image to fill the area with
@ TextPosition
text opacity
@ TextOffset
line or center
@ MaxWidth
vertical offset from the center of the way or point
@ FontFamily
the equivalent to CartoCSS's ignore-placement, non-standard extension
@ FillOpacity
area fill color
@ Extrude
rounded or rectangular
QByteArray fromRawData(const char *data, qsizetype size)
QByteArray number(double n, char format, int precision)
QColor fromRgba(QRgb rgba)
qint64 write(const QByteArray &data)
QString fromUtf8(QByteArrayView str)