Skip to content

Commit

Permalink
Release v2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jul 23, 2022
1 parent ef111f9 commit 7417baa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 88 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.1 LANGUAGES CXX C)
project(lunasvg VERSION 2.3.2 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)
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.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)

Expand Down
44 changes: 0 additions & 44 deletions source/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t*>(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);
Expand Down
2 changes: 0 additions & 2 deletions source/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
80 changes: 40 additions & 40 deletions source/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 7417baa

Please sign in to comment.