7#include "mapcssdeclaration_p.h"
10#include "mapcssproperty.h"
11#include "mapcssvalue_p.h"
25}
static constexpr const property_types[] = {
28 {
"casing-color", MapCSSProperty::CasingColor, MapCSSDeclaration::NoFlag },
29 {
"casing-dashes", MapCSSProperty::CasingDashes, MapCSSDeclaration::NoFlag },
30 {
"casing-linecap", MapCSSProperty::CasingLineCap, MapCSSDeclaration::NoFlag },
31 {
"casing-linejoin", MapCSSProperty::CasingLineJoin, MapCSSDeclaration::NoFlag },
32 {
"casing-opacity", MapCSSProperty::CasingOpacity, MapCSSDeclaration::NoFlag },
33 {
"casing-width", MapCSSProperty::CasingWidth, MapCSSDeclaration::NoFlag },
34 {
"color", MapCSSProperty::Color, MapCSSDeclaration::LineProperty },
35 {
"dashes", MapCSSProperty::Dashes, MapCSSDeclaration::NoFlag },
36 {
"extrude", MapCSSProperty::Extrude, MapCSSDeclaration::ExtrudeProperty },
37 {
"fill-color", MapCSSProperty::FillColor, MapCSSDeclaration::AreaProperty | MapCSSDeclaration::CanvasProperty },
38 {
"fill-image", MapCSSProperty::FillImage, MapCSSDeclaration::AreaProperty | MapCSSDeclaration::CanvasProperty },
39 {
"fill-opacity", MapCSSProperty::FillOpacity, MapCSSDeclaration::AreaProperty },
40 {
"font-family", MapCSSProperty::FontFamily, MapCSSDeclaration::NoFlag },
41 {
"font-size", MapCSSProperty::FontSize, MapCSSDeclaration::NoFlag },
42 {
"font-style", MapCSSProperty::FontStyle, MapCSSDeclaration::NoFlag },
43 {
"font-variant", MapCSSProperty::FontVariant, MapCSSDeclaration::NoFlag },
44 {
"font-weight", MapCSSProperty::FontWeight, MapCSSDeclaration::NoFlag },
45 {
"icon-allow-icon-overlap", MapCSSProperty::IconAllowIconOverlap, MapCSSDeclaration::NoFlag },
46 {
"icon-allow-text-overlap", MapCSSProperty::IconAllowTextOverlap, MapCSSDeclaration::NoFlag },
47 {
"icon-color", MapCSSProperty::IconColor, MapCSSDeclaration::NoFlag },
48 {
"icon-height", MapCSSProperty::IconHeight, MapCSSDeclaration::NoFlag },
49 {
"icon-image", MapCSSProperty::IconImage, MapCSSDeclaration::LabelProperty },
50 {
"icon-opacity", MapCSSProperty::IconOpacity, MapCSSDeclaration::NoFlag },
51 {
"icon-width", MapCSSProperty::IconWidth, MapCSSDeclaration::NoFlag },
52 {
"image", MapCSSProperty::Image, MapCSSDeclaration::LineProperty },
53 {
"linecap", MapCSSProperty::LineCap, MapCSSDeclaration::NoFlag },
54 {
"linejoin", MapCSSProperty::LineJoin, MapCSSDeclaration::NoFlag },
55 {
"max-width", MapCSSProperty::MaxWidth, MapCSSDeclaration::NoFlag },
56 {
"opacity", MapCSSProperty::Opacity, MapCSSDeclaration::NoFlag },
57 {
"shield-casing-color", MapCSSProperty::ShieldCasingColor, MapCSSDeclaration::LabelProperty },
58 {
"shield-casing-width", MapCSSProperty::ShieldCasingWidth, MapCSSDeclaration::NoFlag },
59 {
"shield-color", MapCSSProperty::ShieldColor, MapCSSDeclaration::LabelProperty },
60 {
"shield-frame-color", MapCSSProperty::ShieldFrameColor, MapCSSDeclaration::LabelProperty },
61 {
"shield-frame-width", MapCSSProperty::ShieldFrameWidth, MapCSSDeclaration::NoFlag },
62 {
"shield-image", MapCSSProperty::ShieldImage, MapCSSDeclaration::LabelProperty },
63 {
"shield-opacity", MapCSSProperty::ShieldOpacity, MapCSSDeclaration::NoFlag },
64 {
"shield-shape", MapCSSProperty::ShieldShape, MapCSSDeclaration::NoFlag },
65 {
"shield-text", MapCSSProperty::ShieldText, MapCSSDeclaration::LabelProperty },
66 {
"text", MapCSSProperty::Text, MapCSSDeclaration::LabelProperty },
67 {
"text-color", MapCSSProperty::TextColor, MapCSSDeclaration::CanvasProperty },
68 {
"text-decoration", MapCSSProperty::TextDecoration, MapCSSDeclaration::NoFlag },
69 {
"text-halo-color", MapCSSProperty::TextHaloColor, MapCSSDeclaration::NoFlag },
70 {
"text-halo-radius", MapCSSProperty::TextHaloRadius, MapCSSDeclaration::NoFlag },
71 {
"text-offset", MapCSSProperty::TextOffset, MapCSSDeclaration::NoFlag },
72 {
"text-opacity", MapCSSProperty::TextOpacity, MapCSSDeclaration::NoFlag },
73 {
"text-position", MapCSSProperty::TextPosition, MapCSSDeclaration::NoFlag },
74 {
"text-require-fit", MapCSSProperty::TextRequireFit, MapCSSDeclaration::NoFlag },
75 {
"text-transform", MapCSSProperty::TextTransform, MapCSSDeclaration::NoFlag },
76 {
"width", MapCSSProperty::Width, MapCSSDeclaration::LineProperty },
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.
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)