From 7417baa0aff477f361e44e2aa793fdb0c7aae352 Mon Sep 17 00:00:00 2001 From: sammycage Date: Sat, 23 Jul 2022 10:16:47 +0100 Subject: [PATCH] Release v2.3.2 --- CMakeLists.txt | 2 +- README.md | 2 +- source/canvas.cpp | 44 -------------------------- source/canvas.h | 2 -- source/parser.cpp | 80 +++++++++++++++++++++++------------------------ source/parser.h | 1 + 6 files changed, 43 insertions(+), 88 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9916c67..b9bf46a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.3) -project(lunasvg VERSION 2.3.1 LANGUAGES CXX C) +project(lunasvg VERSION 2.3.2 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 14) set(CMAKE_C_STANDARD 11) diff --git a/README.md b/README.md index 75d8808..54ae043 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Releases](https://img.shields.io/badge/Version-2.3.1-orange.svg)](https://github.com/sammycage/lunasvg/releases) +[![Releases](https://img.shields.io/badge/Version-2.3.2-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) diff --git a/source/canvas.cpp b/source/canvas.cpp index c414d0c..6311ffc 100644 --- a/source/canvas.cpp +++ b/source/canvas.cpp @@ -153,50 +153,6 @@ void Canvas::mask(const Rect& clip, const Transform& transform) plutovg_fill(pluto); } -void Canvas::clear(unsigned int value) -{ - auto r = (value >> 24) & 0xFF; - auto g = (value >> 16) & 0xFF; - auto b = (value >> 8) & 0xFF; - auto a = (value >> 0) & 0xFF; - - plutovg_set_source_rgba(pluto, r / 255.0, g / 255.0, b / 255.0, a / 255.0); - plutovg_set_opacity(pluto, 1.0); - plutovg_set_operator(pluto, plutovg_operator_src); - plutovg_paint(pluto); -} - -void Canvas::rgba() -{ - auto width = plutovg_surface_get_width(surface); - auto height = plutovg_surface_get_height(surface); - auto stride = plutovg_surface_get_stride(surface); - auto data = plutovg_surface_get_data(surface); - for(int y = 0;y < height;y++) - { - auto pixels = reinterpret_cast(data + stride * y); - for(int x = 0;x < width;x++) - { - auto pixel = pixels[x]; - auto a = (pixel >> 24) & 0xFF; - if(a == 0) - continue; - - auto r = (pixel >> 16) & 0xFF; - auto g = (pixel >> 8) & 0xFF; - auto b = (pixel >> 0) & 0xFF; - if(a != 255) - { - r = (r * 255) / a; - g = (g * 255) / a; - b = (b * 255) / a; - } - - pixels[x] = (a << 24) | (b << 16) | (g << 8) | r; - } - } -} - void Canvas::luminance() { auto width = plutovg_surface_get_width(surface); diff --git a/source/canvas.h b/source/canvas.h index bfd8890..a7d7433 100644 --- a/source/canvas.h +++ b/source/canvas.h @@ -52,8 +52,6 @@ class Canvas void blend(const Canvas* source, BlendMode mode, double opacity); void mask(const Rect& clip, const Transform& transform); - void clear(unsigned int value); - void rgba(); void luminance(); unsigned int width() const; diff --git a/source/parser.cpp b/source/parser.cpp index 21ad9e5..cda095a 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -373,22 +373,8 @@ std::string Parser::parseUrl(const std::string& string) auto ptr = string.data(); auto end = ptr + string.size(); - if(!Utils::skipDesc(ptr, end, "url(") - || !Utils::skipWs(ptr, end)) { - return std::string{}; - } - - char delim = ')'; - if(*ptr == '\'' || *ptr == '"') { - delim = *ptr; - ++ptr; - } - - if(!Utils::skipDesc(ptr, end, '#')) - return std::string{}; - std::string value; - Utils::readUntil(ptr, end, delim, value); + parseUrlFragment(ptr, end, value); return value; } @@ -753,32 +739,9 @@ Paint Parser::parsePaint(const std::string& string, const StyledElement* element auto ptr = string.data(); auto end = ptr + string.size(); - if(!Utils::skipDesc(ptr, end, "url(")) - return parseColor(string, element, defaultValue); - - if(!Utils::skipWs(ptr, end)) - return defaultValue; - - char delim = ')'; - if(*ptr == '\'' || *ptr == '"') { - delim = *ptr; - ++ptr; - } - std::string ref; - if(!Utils::skipDesc(ptr, end, '#') - || !Utils::readUntil(ptr, end, delim, ref)) { - return defaultValue; - } - - if(*ptr == '\'' || *ptr == '"') - ++ptr; - - if(ptr >= end || *ptr != ')') - return defaultValue; - - ++ptr; - Utils::skipWs(ptr, end); + if(!parseUrlFragment(ptr, end, ref)) + return parseColor(string, element, defaultValue); std::string fallback{ptr, end}; if(fallback.empty()) @@ -956,6 +919,43 @@ bool Parser::parseColorComponent(const char*& ptr, const char* end, double& valu return true; } +bool Parser::parseUrlFragment(const char*& ptr, const char* end, std::string& ref) +{ + if(!Utils::skipDesc(ptr, end, "url(") + || !Utils::skipWs(ptr, end)) { + return false; + } + + switch(*ptr) { + case '\'': + case '"': { + auto delim = *ptr; + ++ptr; // delim + if(!Utils::skipWs(ptr, end) || *ptr != '#') + return false; + ++ptr; // # + if(!Utils::readUntil(ptr, end, delim, ref)) + return false; + ++ptr; // delim + break; + } + + case '#': + ++ptr; // # + Utils::readUntil(ptr, end, ')', ref); + break; + default: + return false; + } + + if(ptr >= end || *ptr != ')') + return false; + + ++ptr; // ) + Utils::skipWs(ptr, end); + return true; +} + bool Parser::parseTransform(const char*& ptr, const char* end, TransformType& type, double* values, int& count) { int required = 0; diff --git a/source/parser.h b/source/parser.h index 61b6a51..6ced83e 100644 --- a/source/parser.h +++ b/source/parser.h @@ -59,6 +59,7 @@ class Parser static bool parseNumberList(const char*& ptr, const char* end, double* values, int count); static bool parseArcFlag(const char*& ptr, const char* end, bool& flag); static bool parseColorComponent(const char*& ptr, const char* end, double& value); + static bool parseUrlFragment(const char*& ptr, const char* end, std::string& ref); static bool parseTransform(const char*& ptr, const char* end, TransformType& type, double* values, int& count); };