Skip to content

Commit

Permalink
Remove spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jun 18, 2024
1 parent 4a33e8e commit 902cc31
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 81 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
libcurl4-openssl-dev \
libturbojpeg0-dev \
libwebp-dev \
libspdlog-dev \
ninja-build \
meson
Expand Down Expand Up @@ -63,7 +62,6 @@ jobs:
mingw-w64-x86_64-curl
mingw-w64-x86_64-libjpeg-turbo
mingw-w64-x86_64-libwebp
mingw-w64-x86_64-spdlog
mingw-w64-x86_64-ninja
mingw-w64-x86_64-meson
mingw-w64-x86_64-pkgconf
Expand Down
13 changes: 0 additions & 13 deletions include/plutobook.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,6 @@ typedef struct _plutobook_page_margins {
#define PLUTOBOOK_PAGE_MARGINS_MODERATE ((plutobook_page_margins_t){72, 54, 72, 54})
#define PLUTOBOOK_PAGE_MARGINS_WIDE ((plutobook_page_margins_t){72, 144, 72, 144})

typedef enum _plutobook_log_level {
PLUTOBOOK_LOG_LEVEL_TRACE = 0,
PLUTOBOOK_LOG_LEVEL_DEBUG = 1,
PLUTOBOOK_LOG_LEVEL_INFO = 2,
PLUTOBOOK_LOG_LEVEL_WARN = 3,
PLUTOBOOK_LOG_LEVEL_ERROR = 4,
PLUTOBOOK_LOG_LEVEL_CRITICAL = 5,
PLUTOBOOK_LOG_LEVEL_OFF = 6
} plutobook_log_level_t;

PLUTOBOOK_API plutobook_log_level_t plutobook_get_log_level(void);
PLUTOBOOK_API void plutobook_set_log_level(plutobook_log_level_t level);

typedef enum _plutobook_status {
PLUTOBOOK_STATUS_SUCCESS = 0,
PLUTOBOOK_STATUS_MEMORY_ERROR = 1,
Expand Down
6 changes: 0 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ project('plutobook', 'cpp',
default_options: ['cpp_std=c++20']
)

spdlog_dep = dependency('spdlog',
required: true,
fallback: ['spdlog', 'spdlog_dep']
)

expat_dep = dependency('expat',
required: true,
fallback: ['expat', 'expat_dep']
Expand Down Expand Up @@ -55,7 +50,6 @@ cairo_dep = dependency('cairo',
)

plutobook_deps = [
spdlog_dep,
expat_dep,
icu_dep,
freetype_dep,
Expand Down
18 changes: 4 additions & 14 deletions source/plutobook.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "plutobook.hpp"

#include <spdlog/spdlog.h>
#include <cairo-pdf.h>

#include <cstring>
#include <cstdlib>
#include <iostream>

int plutobook_version()
{
Expand All @@ -21,16 +21,6 @@ const char* plutobook_about()
return "PlutoBook " PLUTOBOOK_VERSION_STRING " (https://github.com/plutoprint)";
}

plutobook_log_level_t plutobook_get_log_level(void)
{
return static_cast<plutobook_log_level_t>(spdlog::get_level());
}

void plutobook_set_log_level(plutobook_log_level_t level)
{
spdlog::set_level(static_cast<spdlog::level::level_enum>(level));
}

struct _plutobook_canvas {
cairo_surface_t* surface;
cairo_t* context;
Expand All @@ -40,7 +30,7 @@ static plutobook_canvas_t* plutobook_canvas_create(cairo_surface_t* surface)
{
auto context = cairo_create(surface);
if(auto status = cairo_status(context)) {
spdlog::error("cairo error: {}", cairo_status_to_string(status));
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl;
cairo_surface_destroy(surface);
return nullptr;
}
Expand All @@ -64,13 +54,13 @@ void plutobook_canvas_destroy(plutobook_canvas_t* canvas)

#define CHECK_CANVAS_SURFACE_ERROR(canvas) do { \
if(auto status = cairo_surface_status(canvas->surface)) { \
spdlog::error("cairo error: {}", cairo_status_to_string(status)); \
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl; \
} \
} while(0)

#define CHECK_CANVAS_CONTEXT_ERROR(canvas) do { \
if(auto status = cairo_status(canvas->context)) { \
spdlog::error("cairo error: {}", cairo_status_to_string(status)); \
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl; \
} \
} while(0)

Expand Down
12 changes: 6 additions & 6 deletions source/plutobook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "replacedbox.h"
#include "graphicscontext.h"

#include <spdlog/spdlog.h>
#include <iostream>
#include <fstream>
#include <cmath>

Expand All @@ -28,7 +28,7 @@ FileOutputStream::FileOutputStream(const std::string& filename)
: m_stream(filename, std::ios::binary)
{
if(!m_stream.is_open()) {
spdlog::error("unable to open file: {}", filename);
std::cerr << "unable to open file: " << filename << std::endl;
}
}

Expand Down Expand Up @@ -373,7 +373,7 @@ bool Book::loadImage(const char* data, size_t length, const std::string_view& mi
{
auto image = ImageResource::decode(data, length, mimeType, textEncoding, m_customResourceFetcher, baseUrl);
if(image == nullptr) {
spdlog::error("unable to decode image data");
std::cerr << "unable to decode image data" << std::endl;
return false;
}

Expand All @@ -392,7 +392,7 @@ bool Book::loadImage(const char* data, size_t length, const std::string_view& mi

auto box = imageElement->box();
if(box == nullptr) {
spdlog::error("invalid img element");
std::cerr << "invalid img element" << std::endl;
return false;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ bool Book::writeToPdf(plutobook_stream_write_callback_t callback, void* closure,
fromPage = std::max(1u, std::min(fromPage, pageCount()));
toPage = std::max(1u, std::min(toPage, pageCount()));
if(pageStep == 0 || (pageStep > 0 && fromPage > toPage) || (pageStep < 0 && fromPage < toPage)) {
spdlog::error("invalid page rage: from={} to={} step={}", fromPage, toPage, pageStep);
std::cerr << "invalid page rage: from=" << fromPage << " to=" << toPage << " step=" << pageStep << std::endl;
return false;
}

Expand Down Expand Up @@ -558,7 +558,7 @@ bool Book::writeToPng(plutobook_stream_write_callback_t callback, void* closure,
int width = std::ceil(documentWidth());
int height = std::ceil(documentHeight());
if(width <= 0 || height <= 0) {
spdlog::error("invalid document size");
std::cerr << "invalid document size" << std::endl;
return false;
}

Expand Down
20 changes: 10 additions & 10 deletions source/resource/fontresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
#include <spdlog/spdlog.h>

#include <cairo-ft.h>
#include <hb-ft.h>

#include <iostream>
#include <numbers>
#include <cmath>

Expand All @@ -33,13 +33,13 @@ FTFontData* FTFontData::create(ResourceData resource)
static FT_Library ftLibrary;
if(ftLibrary == nullptr) {
if(auto error = FT_Init_FreeType(&ftLibrary)) {
spdlog::error("freetype error: {}", FT_Error_String(error));
std::cerr << "freetype error: " << FT_Error_String(error) << std::endl;
}
}

FT_Face ftFace = nullptr;
if(auto error = FT_New_Memory_Face(ftLibrary, (FT_Byte*)(resource.content()), resource.contentLength(), 0, &ftFace)) {
spdlog::error("freetype error: {}", FT_Error_String(error));
std::cerr << "freetype error: " << FT_Error_String(error) << std::endl;
return nullptr;
}

Expand All @@ -58,15 +58,15 @@ RefPtr<FontResource> FontResource::create(ResourceFetcher* fetcher, const Url& u
return nullptr;
auto fontData = FTFontData::create(std::move(resource));
if(fontData == nullptr) {
spdlog::error("unable to decode font: {}", url.value());
std::cerr << "unable to decode font: " << url << std::endl;
return nullptr;
}

static cairo_user_data_key_t key;
auto face = cairo_ft_font_face_create_for_ft_face(fontData->face(), FT_LOAD_DEFAULT);
cairo_font_face_set_user_data(face, &key, fontData, FTFontDataDestroy);
if(auto status = cairo_font_face_status(face)) {
spdlog::error("cairo error: {}", cairo_status_to_string(status));
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl;
FTFontDataDestroy(fontData);
return nullptr;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ RefPtr<SimpleFontData> SimpleFontData::create(cairo_scaled_font_t* font, FontFea
auto face = cairo_ft_scaled_font_lock_face(font);
if(face == nullptr) {
auto status = cairo_scaled_font_status(font);
spdlog::error("cairo error: {}", cairo_status_to_string(status));
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl;
cairo_scaled_font_destroy(font);
return nullptr;
}
Expand Down Expand Up @@ -615,8 +615,8 @@ RefPtr<SimpleFontData> FontDataCache::getFontData(const GlobalString& family, co
FcPatternDestroy(pattern);
if(matchResult == FcResultMatch)
return (fontData = createFontDataFromPattern(matchPattern, description));
spdlog::warn("unable to load font: family={} size={} weight={} width={} slope={}", familyName, description.size,
description.request.weight, description.request.width, description.request.slope);
std::cerr << "unable to load font: family=" << family << " size=" << description.size
<< " weight=" << description.request.weight << " width=" << description.request.width << " slope=" << description.request.slope << std::endl;
return nullptr;
}

Expand Down Expand Up @@ -656,8 +656,8 @@ RefPtr<SimpleFontData> FontDataCache::getFontData(uint32_t codepoint, const Font
if(matchResult == FcResultMatch)
return createFontDataFromPattern(matchPattern, description);
FcPatternDestroy(matchPattern);
spdlog::warn("unable to load font: codepoint={} size={} weight={} width={} slope={}", codepoint, description.size,
description.request.weight, description.request.width, description.request.slope);
std::cerr << "unable to load font: codepoint=" << codepoint << " size=" << description.size
<< " weight=" << description.request.weight << " width=" << description.request.width << " slope=" << description.request.slope << std::endl;
return nullptr;
}

Expand Down
18 changes: 9 additions & 9 deletions source/resource/imageresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include "graphicscontext.h"
#include "geometry.h"

#include <spdlog/spdlog.h>
#include <cairo.h>
#include <cstring>
#include <cmath>
#include <iostream>

#ifdef PLUTOBOOK_HAS_WEBP
#include <webp/decode.h>
Expand Down Expand Up @@ -37,7 +37,7 @@ RefPtr<ImageResource> ImageResource::create(ResourceFetcher* fetcher, const Url&
return nullptr;
auto image = decode(resource.content(), resource.contentLength(), resource.mimeType(), resource.textEncoding(), fetcher, url.base());
if(image == nullptr) {
spdlog::error("unable to decode image: {}", url.value());
std::cerr << "unable to decode image: " << url << std::endl;
return nullptr;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ RefPtr<BitmapImage> BitmapImage::create(const char* data, size_t size)
if(surface == nullptr)
return nullptr;
if(auto status = cairo_surface_status(surface)) {
spdlog::error("cairo error: {}", cairo_status_to_string(status));
std::cerr << "cairo error: " << cairo_status_to_string(status) << std::endl;
cairo_surface_destroy(surface);
return nullptr;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ cairo_surface_t* BitmapImage::decode(const char* data, size_t size)
int width, height;
auto tj = tjInitDecompress();
if(!tj || tjDecompressHeader(tj, (uint8_t*)(data), size, &width, &height) == -1) {
spdlog::error("turbojpeg error: {}", tjGetErrorStr());
std::cerr << "turbojpeg error: " << tjGetErrorStr2(tj) << std::endl;
tjDestroy(tj);
return nullptr;
}
Expand All @@ -214,12 +214,12 @@ cairo_surface_t* BitmapImage::decode(const char* data, size_t size)
if(size > 14 && std::memcmp(data, "RIFF", 4) == 0 && std::memcmp(data + 8, "WEBPVP", 6) == 0) {
WebPDecoderConfig config;
if(!WebPInitDecoderConfig(&config)) {
spdlog::error("webp error: WebPInitDecoderConfig failed");
std::cerr << "webp error: WebPInitDecoderConfig failed" << std::endl;
return nullptr;
}

if(WebPGetFeatures((const uint8_t*)(data), size, &config.input) != VP8_STATUS_OK) {
spdlog::error("webp error: WebPGetFeatures failed");
std::cerr << "webp error: WebPGetFeatures failed" << std::endl;
return nullptr;
}

Expand All @@ -237,7 +237,7 @@ cairo_surface_t* BitmapImage::decode(const char* data, size_t size)
config.output.height = surfaceHeight;
config.output.is_external_memory = 1;
if(WebPDecode((const uint8_t*)(data), size, &config) != VP8_STATUS_OK) {
spdlog::error("webp error: WebPDecode failed");
std::cerr << "webp error: WebPDecode failed" << std::endl;
return nullptr;
}

Expand All @@ -249,7 +249,7 @@ cairo_surface_t* BitmapImage::decode(const char* data, size_t size)
int width, height, channels;
auto imageData = stbi_load_from_memory((const stbi_uc*)(data), size, &width, &height, &channels, STBI_rgb_alpha);
if(imageData == nullptr) {
spdlog::error("stbi error: {}", stbi_failure_reason());
std::cerr << "stbi error: " << stbi_failure_reason() << std::endl;
return nullptr;
}

Expand Down Expand Up @@ -291,7 +291,7 @@ RefPtr<SVGImage> SVGImage::create(const std::string_view& content, ResourceFetch
if(!document->load(content))
return nullptr;
if(!document->rootElement()->isOfType(svgNs, svgTag)) {
spdlog::error("invalid svg root element");
std::cerr << "invalid svg root element" << std::endl;
return nullptr;
}

Expand Down
8 changes: 4 additions & 4 deletions source/resource/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "plutobook.hpp"
#include "url.h"

#include <spdlog/spdlog.h>
#include <filesystem>
#include <iostream>
#include <cstring>
#include <map>

Expand Down Expand Up @@ -270,7 +270,7 @@ ResourceData DefaultResourceFetcher::loadUrl(const std::string& url)
if(response == CURLE_OK)
return ResourceData::createWithoutCopy(content->data(), content->size(), mimeType, textEncoding, ByteArrayDestroy, content);
ByteArrayDestroy(content);
spdlog::error("curl error: {}", curl_easy_strerror(response));
std::cerr << "curl error: " << curl_easy_strerror(response) << std::endl;
return ResourceData();
}

Expand All @@ -290,7 +290,7 @@ ResourceData DefaultResourceFetcher::loadUrl(const std::string& url)
auto filename = percentDecode(input.substr(0, input.rfind('?')));
std::ifstream in(filename, std::ios::ate | std::ios::binary);
if(!in.is_open() || !in.good()) {
spdlog::error("unable to open file: {}", filename);
std::cerr << "unable to open file: " << filename << std::endl;
return ResourceData();
}

Expand All @@ -315,7 +315,7 @@ ResourceData ResourceLoader::loadUrl(const Url& url, ResourceFetcher* customFetc
auto fetcher = customFetcher ? customFetcher : defaultResourceFetcher();
auto resource = fetcher->loadUrl(url.value());
if(resource.isNull()) {
spdlog::error("unable to load url: {}", url.value());
std::cerr << "unable to load url: " << url << std::endl;
}

return resource;
Expand Down
4 changes: 2 additions & 2 deletions source/resource/textresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "stringutils.h"
#include "url.h"

#include <spdlog/spdlog.h>
#include <iostream>

namespace plutobook {

Expand All @@ -14,7 +14,7 @@ RefPtr<TextResource> TextResource::create(ResourceFetcher* fetcher, const Url& u
return nullptr;
auto text = decode(resource.content(), resource.contentLength(), resource.mimeType(), resource.textEncoding());
if(text.empty()) {
spdlog::error("unable to decode text: {}", url.value());
std::cerr << "unable to decode text: " << url << std::endl;
return nullptr;
}

Expand Down
5 changes: 3 additions & 2 deletions source/xmlparser.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "xmlparser.h"
#include "xmldocument.h"

#include <spdlog/spdlog.h>
#include <expat.h>
#include <iostream>

namespace plutobook {

Expand Down Expand Up @@ -48,7 +48,8 @@ bool XMLParser::parse(const std::string_view& content)
return true;
}

spdlog::error("expat error: {} on line {}, column {}", XML_ErrorString(error), XML_GetCurrentLineNumber(parser ), XML_GetCurrentColumnNumber(parser));
std::cerr << "expat error: " << XML_ErrorString(error) << "on line "
<< XML_GetCurrentLineNumber(parser) << " column " << XML_GetCurrentColumnNumber(parser) << std::endl;
XML_ParserFree(parser);
return false;
}
Expand Down
Loading

0 comments on commit 902cc31

Please sign in to comment.