Skip to content

Commit

Permalink
Release v2.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed May 27, 2023
1 parent a03316b commit 87137e7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.3)

project(lunasvg VERSION 2.3.5 LANGUAGES CXX C)
project(lunasvg VERSION 2.3.8 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Releases](https://img.shields.io/badge/Version-2.3.5-orange.svg)](https://github.com/sammycage/lunasvg/releases)
[![Releases](https://img.shields.io/badge/Version-2.3.8-orange.svg)](https://github.com/sammycage/lunasvg/releases)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/sammycage/lunasvg/blob/master/LICENSE)
[![Build Status](https://github.com/sammycage/lunasvg/actions/workflows/ci.yml/badge.svg)](https://github.com/sammycage/lunasvg/actions)

Expand Down
3 changes: 2 additions & 1 deletion source/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ void Element::set(PropertyID id, const std::string& value, int specificity)
if(specificity >= property.specificity) {
property.specificity = specificity;
property.value = value;
return;
}

return;
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class Element : public Node {

template<typename T>
void transverse(T callback) {
if(callback(this))
if(!callback(this))
return;

for(auto& child : children) {
if(child->isText()) {
if(callback(child.get()))
if(!callback(child.get()))
return;
continue;
}
Expand Down
7 changes: 4 additions & 3 deletions source/layoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,16 @@ void MarkerData::add(const LayoutMarker* marker, const Point& origin, double ang

void MarkerData::render(RenderState& state) const
{
for(const auto& position : positions)
for(const auto& position : positions) {
position.marker->renderMarker(state, position.origin, position.angle, strokeWidth);
}
}

void MarkerData::inflate(Rect& box) const
{
for(const auto& position : positions)
for(const auto& position : positions) {
box.unite(position.marker->markerBoundingBox(position.origin, position.angle, strokeWidth));
}
}

LayoutShape::LayoutShape()
Expand Down Expand Up @@ -480,7 +482,6 @@ LayoutObject* LayoutContext::getResourcesById(const std::string& id) const
auto it = m_resourcesCache.find(id);
if(it == m_resourcesCache.end())
return nullptr;

return it->second;
}

Expand Down
81 changes: 43 additions & 38 deletions source/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ Path Parser::parsePath(const std::string& string)
break;

lastCommand = command;
if(IS_ALPHA(*ptr))
if(IS_ALPHA(*ptr)) {
command = *ptr++;
}
}

return path;
Expand All @@ -359,7 +360,6 @@ std::string Parser::parseHref(const std::string& string)
{
if(string.size() > 1 && string.front() == '#')
return string.substr(1);

return std::string{};
}

Expand Down Expand Up @@ -897,7 +897,8 @@ bool Parser::parseUrlFragment(const char*& ptr, const char* end, std::string& re
case '"': {
auto delim = *ptr;
++ptr; // delim
if(!Utils::skipWs(ptr, end) || *ptr != '#')
Utils::skipWs(ptr, end);
if(ptr >= end || *ptr != '#')
return false;
++ptr; // #
if(!Utils::readUntil(ptr, end, delim, ref))
Expand Down Expand Up @@ -976,7 +977,7 @@ bool Parser::parseTransform(const char*& ptr, const char* end, TransformType& ty
return true;
}

static inline ElementID elementId(const std::string& name)
static inline ElementID elementid(const std::string& name)
{
static const std::map<std::string, ElementID> elementmap = {
{"circle", ElementID::Circle},
Expand Down Expand Up @@ -1008,7 +1009,7 @@ static inline ElementID elementId(const std::string& name)
return it->second;
}

static inline PropertyID cssPropertyId(const std::string& name)
static inline PropertyID csspropertyid(const std::string& name)
{
static const std::map<std::string, PropertyID> csspropertymap = {
{"clip-path", PropertyID::Clip_Path},
Expand Down Expand Up @@ -1045,7 +1046,7 @@ static inline PropertyID cssPropertyId(const std::string& name)
return it->second;
}

static inline PropertyID propertyId(const std::string& name)
static inline PropertyID propertyid(const std::string& name)
{
static const std::map<std::string, PropertyID> propertymap = {
{"class", PropertyID::Class},
Expand Down Expand Up @@ -1093,7 +1094,7 @@ static inline PropertyID propertyId(const std::string& name)

auto it = propertymap.find(name);
if(it == propertymap.end())
return cssPropertyId(name);
return csspropertyid(name);
return it->second;
}

Expand Down Expand Up @@ -1386,14 +1387,14 @@ bool StyleSheet::parseSelectors(const char*& ptr, const char* end, SelectorList&
Selector selector;
if(!parseSelector(ptr, end, selector))
return false;
selectors.push_back(selector);
selectors.push_back(std::move(selector));

while(Utils::skipDesc(ptr, end, ',')) {
Utils::skipWs(ptr, end);
Selector selector;
if(!parseSelector(ptr, end, selector))
return false;
selectors.push_back(selector);
selectors.push_back(std::move(selector));
}

return true;
Expand All @@ -1419,7 +1420,7 @@ bool StyleSheet::parseDeclarations(const char*& ptr, const char* end, Declaratio

Declaration declaration;
declaration.specificity = 0x10;
declaration.id = cssPropertyId(name);
declaration.id = csspropertyid(name);
declaration.value.assign(start, Utils::rtrim(start, ptr));
if(Utils::skipDesc(ptr, end, '!')) {
if(!Utils::skipDesc(ptr, end, "important"))
Expand All @@ -1442,7 +1443,7 @@ bool StyleSheet::parseSelector(const char*& ptr, const char* end, Selector& sele
SimpleSelector simpleSelector;
if(!parseSimpleSelector(ptr, end, simpleSelector))
return false;
selector.push_back(simpleSelector);
selector.push_back(std::move(simpleSelector));
Utils::skipWs(ptr, end);
} while(ptr < end && IS_SELECTOR_STARTNAMECHAR(*ptr));

Expand All @@ -1455,7 +1456,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
if(Utils::skipDesc(ptr, end, '*'))
simpleSelector.id = ElementID::Star;
else if(readCSSIdentifier(ptr, end, name))
simpleSelector.id = elementId(name);
simpleSelector.id = elementid(name);

while(ptr < end) {
if(Utils::skipDesc(ptr, end, '#')) {
Expand All @@ -1464,7 +1465,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
a.matchType = AttributeSelector::MatchType::Equal;
if(!readCSSIdentifier(ptr, end, a.value))
return false;
simpleSelector.attributeSelectors.push_back(a);
simpleSelector.attributeSelectors.push_back(std::move(a));
continue;
}

Expand All @@ -1474,7 +1475,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
a.matchType = AttributeSelector::MatchType::Includes;
if(!readCSSIdentifier(ptr, end, a.value))
return false;
simpleSelector.attributeSelectors.push_back(a);
simpleSelector.attributeSelectors.push_back(std::move(a));
continue;
}

Expand All @@ -1483,7 +1484,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
if(!readCSSIdentifier(ptr, end, name))
return false;
AttributeSelector a;
a.id = propertyId(name);
a.id = propertyid(name);
if(Utils::skipDesc(ptr, end, '='))
a.matchType = AttributeSelector::MatchType::Equal;
else if(Utils::skipDesc(ptr, end, "~="))
Expand Down Expand Up @@ -1513,7 +1514,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
Utils::skipWs(ptr, end);
if(!Utils::skipDesc(ptr, end, ']'))
return false;
simpleSelector.attributeSelectors.push_back(a);
simpleSelector.attributeSelectors.push_back(std::move(a));
continue;
}

Expand Down Expand Up @@ -1553,7 +1554,7 @@ bool StyleSheet::parseSimpleSelector(const char*& ptr, const char* end, SimpleSe
}
}

simpleSelector.pseudoClassSelectors.push_back(selector);
simpleSelector.pseudoClassSelectors.push_back(std::move(selector));
continue;
}

Expand Down Expand Up @@ -1712,13 +1713,23 @@ static inline void parseStyle(const std::string& string, Element* element)
while(ptr < end && *ptr != ';')
++ptr;
value.assign(start, Utils::rtrim(start, ptr));
auto id = cssPropertyId(name);
auto id = csspropertyid(name);
if(id != PropertyID::Unknown)
element->set(id, value, 0x100);
Utils::skipWsDelimiter(ptr, end, ';');
}
}

static inline void removeComments(std::string& value)
{
auto start = value.find("/*");
while(start != std::string::npos) {
auto end = value.find("*/", start + 2);
value.erase(start, end - start + 2);
start = value.find("/*");
}
}

TreeBuilder::TreeBuilder() = default;

TreeBuilder::~TreeBuilder() = default;
Expand All @@ -1733,17 +1744,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
std::string name;
std::string value;
int ignoring = 0;

auto remove_comments = [](std::string& value) {
auto start = value.find("/*");
while(start != std::string::npos) {
auto end = value.find("*/", start + 2);
value.erase(start, end - start + 2);
start = value.find("/*");
}
};

auto handle_text = [&](const char* start, const char* end, bool in_cdata) {
auto handleText = [&](const char* start, const char* end, bool in_cdata) {
if(ignoring > 0 || current == nullptr || current->id != ElementID::Style)
return;

Expand All @@ -1752,7 +1753,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
else
decodeText(start, end, value);

remove_comments(value);
removeComments(value);
styleSheet.parse(value);
};

Expand All @@ -1761,7 +1762,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(!Utils::skipUntil(ptr, end, '<'))
break;

handle_text(start, ptr, false);
handleText(start, ptr, false);
ptr += 1;

if(ptr < end && *ptr == '/') {
Expand Down Expand Up @@ -1804,7 +1805,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(!Utils::skipUntil(ptr, end, "-->"))
return false;

handle_text(start, ptr, false);
handleText(start, ptr, false);
ptr += 3;
continue;
}
Expand All @@ -1814,7 +1815,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(!Utils::skipUntil(ptr, end, "]]>"))
return false;

handle_text(start, ptr, true);
handleText(start, ptr, true);
ptr += 3;
continue;
}
Expand Down Expand Up @@ -1847,7 +1848,9 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(!readIdentifier(ptr, end, name))
return false;

auto id = ignoring == 0 ? elementId(name) : ElementID::Unknown;
auto id = ElementID::Unknown;
if(ignoring == 0)
id = elementid(name);
if(id == ElementID::Unknown)
++ignoring;

Expand Down Expand Up @@ -1889,11 +1892,13 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(ptr >= end || *ptr != quote)
return false;

auto id = element ? propertyId(name) : PropertyID::Unknown;
auto id = PropertyID::Unknown;
if(element != nullptr)
id = propertyid(name);
if(id != PropertyID::Unknown) {
decodeText(start, Utils::rtrim(start, ptr), value);
if(id == PropertyID::Style) {
remove_comments(value);
removeComments(value);
parseStyle(value, element);
} else {
if(id == PropertyID::Id)
Expand Down Expand Up @@ -1935,7 +1940,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
if(!styleSheet.empty()) {
m_rootElement->transverse([&styleSheet](Node* node) {
if(node->isText())
return false;
return true;

auto element = static_cast<Element*>(node);
for(auto& rule : styleSheet.rules()) {
Expand All @@ -1946,7 +1951,7 @@ bool TreeBuilder::parse(const char* data, std::size_t size)
}
}

return false;
return true;
});
}

Expand Down

0 comments on commit 87137e7

Please sign in to comment.