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-transform", MapCSSProperty::TextTransform, MapCSSDeclaration::NoFlag },
75 {
"width", MapCSSProperty::Width, MapCSSDeclaration::LineProperty },
76 {
"z-index", MapCSSProperty::ZIndex, MapCSSDeclaration::NoFlag },
82}
static constexpr const capstyle_map[] = {
91}
static constexpr const joinstyle_map[] = {
100}
static constexpr const capitalizationstyle_map[] = {
111 MapCSSDeclaration::Unit unit;
112}
static constexpr const unit_map[] = {
113 {
"m", MapCSSDeclaration::Meters },
114 {
"pt", MapCSSDeclaration::Point },
115 {
"px", MapCSSDeclaration::Pixels },
120 MapCSSDeclaration::Position position;
121}
static constexpr const position_map[] = {
122 {
"center", MapCSSDeclaration::Position::Center },
123 {
"line", MapCSSDeclaration::Position::Line },
126MapCSSDeclaration::MapCSSDeclaration(Type type)
131MapCSSDeclaration::~MapCSSDeclaration() =
default;
133bool MapCSSDeclaration::isValid()
const
136 case PropertyDeclaration:
137 return property() != MapCSSProperty::Unknown;
139 return !m_identValue.isEmpty();
140 case ClassDeclaration:
141 return !m_class.isNull();
148MapCSSDeclaration::Type MapCSSDeclaration::type()
const
158int MapCSSDeclaration::propertyFlags()
const
163int MapCSSDeclaration::intValue()
const
165 return m_doubleValue;
168double MapCSSDeclaration::doubleValue()
const
170 return m_doubleValue;
173bool MapCSSDeclaration::boolValue()
const
178QString MapCSSDeclaration::stringValue()
const
180 return m_stringValue;
183QColor MapCSSDeclaration::colorValue()
const
185 if (!m_colorValue.isValid() && !m_stringValue.isEmpty()) {
186 return QColor(m_stringValue);
206void MapCSSDeclaration::setDoubleValue(
double val)
211void MapCSSDeclaration::setBoolValue(
bool val)
216bool MapCSSDeclaration::hasExpression()
const
218 return m_evalExpression.isValid();
221MapCSSValue MapCSSDeclaration::evaluateExpression(
const MapCSSExpressionContext &context)
const
223 return m_evalExpression.evaluate(context);
226MapCSSProperty MapCSSDeclaration::propertyFromName(
const char *name, std::size_t len)
228 const auto it = std::lower_bound(std::begin(property_types), std::end(property_types), name, [len](
const auto &lhs,
const char *rhs) {
229 const auto lhsLen = std::strlen(lhs.name);
230 const auto cmp = std::strncmp(lhs.name, rhs, std::min(lhsLen, len));
231 return cmp < 0 || (cmp == 0 && lhsLen < len);
233 if (it == std::end(property_types) || std::strncmp((*it).name, name, std::max(len, std::strlen((*it).name))) != 0) {
234 return MapCSSProperty::Unknown;
236 return (*it).property;
239void MapCSSDeclaration::setPropertyName(
const char *name, std::size_t len)
241 const auto it = std::lower_bound(std::begin(property_types), std::end(property_types), name, [len](
const auto &lhs,
const char *rhs) {
242 const auto lhsLen = std::strlen(lhs.name);
243 const auto cmp = std::strncmp(lhs.name, rhs, std::min(lhsLen, len));
244 return cmp < 0 || (cmp == 0 && lhsLen < len);
246 if (it == std::end(property_types) || std::strncmp((*it).name, name, std::max(len, std::strlen((*it).name))) != 0) {
248 m_property = MapCSSProperty::Unknown;
251 m_property = (*it).property;
252 m_flags = (*it).flags;
255void MapCSSDeclaration::setIdentifierValue(
const char *val,
int len)
260void MapCSSDeclaration::setStringValue(
char *str)
266void MapCSSDeclaration::setColorRgba(uint32_t argb)
274 m_dashValue = dashes;
279 for (
const auto &c : capstyle_map) {
280 if (std::strcmp(c.name, m_identValue.constData()) == 0) {
284 qDebug() <<
"unknown line cap style:" << m_identValue;
290 for (
const auto &j : joinstyle_map) {
291 if (std::strcmp(j.name, m_identValue.constData()) == 0) {
300 for (
const auto &c : capitalizationstyle_map) {
301 if (std::strcmp(c.name, m_identValue.constData()) == 0) {
302 return c.capitalizationStyle;
308bool MapCSSDeclaration::isBoldStyle()
const
310 return m_identValue ==
"bold";
313bool MapCSSDeclaration::isItalicStyle()
const
315 return m_identValue ==
"italic";
318bool MapCSSDeclaration::isUnderlineStyle()
const
320 return m_identValue ==
"underline";
323MapCSSDeclaration::Position MapCSSDeclaration::textPosition()
const
325 for (
const auto &p : position_map) {
326 if (std::strcmp(p.name, m_identValue.constData()) == 0) {
330 return Position::NoPostion;
333MapCSSDeclaration::Unit MapCSSDeclaration::unit()
const
338void MapCSSDeclaration::setUnit(
const char *val,
int len)
340 for (
const auto &u : unit_map) {
341 if (std::strncmp(u.name, val, std::max<std::size_t>(std::strlen(u.name), len)) == 0) {
350ClassSelectorKey MapCSSDeclaration::classSelectorKey()
const
355void MapCSSDeclaration::setClassSelectorKey(ClassSelectorKey key)
363 if (m_type == TagDeclaration) {
364 m_tagKey = dataSet.
makeTagKey(m_identValue.constData());
367 if (m_evalExpression.isValid()) {
368 m_evalExpression.compile(dataSet);
375 for (
const auto c : str) {
393void MapCSSDeclaration::write(
QIODevice *out)
const
398 case PropertyDeclaration:
399 for (
const auto &p : property_types) {
400 if (p.property == m_property) {
407 if (!std::isnan(m_doubleValue)) {
409 }
else if (m_colorValue.isValid()) {
411 }
else if (!m_dashValue.isEmpty()) {
412 for (
const auto &d : m_dashValue) {
416 }
else if (!m_stringValue.isNull()) {
417 writeQuotedString(out, m_stringValue.toUtf8());
418 }
else if (!m_identValue.isEmpty()) {
419 out->
write(m_identValue);
420 }
else if (m_evalExpression.isValid()) {
422 m_evalExpression.write(out);
425 out->
write(m_boolValue ?
"true" :
"false");
428 for (
const auto &u : unit_map) {
429 if (u.unit == m_unit) {
437 out->
write(m_identValue);
438 if (!std::isnan(m_doubleValue)) {
441 }
else if (!m_stringValue.isEmpty()) {
443 writeQuotedString(out, m_stringValue.toUtf8());
444 }
else if (m_evalExpression.isValid()) {
445 out->
write(
" = eval(");
446 m_evalExpression.write(out);
450 case ClassDeclaration:
452 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)