Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "components/cpp-misc"]
path = components/cpp-misc
url = [email protected]:sindarin-inc/cpp-misc.git
[submodule "components/tiny-epub"]
path = components/tiny-epub
url = [email protected]:sindarin-inc/tiny-epub.git
14 changes: 14 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@
"cStandard": "c17",
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/components/esp_lcd_seeya103/test_apps/build-esp32p4/compile_commands.json"
},
{
"name": "sim",
"includePath": [
"${default}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/lib/Simulator/build/compile_commands.json"
}
],
"version": 4
Expand Down
2 changes: 1 addition & 1 deletion components/cpp-misc
1 change: 1 addition & 0 deletions components/tiny-epub
Submodule tiny-epub added at 3cea0c
44 changes: 40 additions & 4 deletions lib/Simulator/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,36 @@ add_subdirectory(${REPO_ROOT_DIR}/components/miniz ${CMAKE_CURRENT_BINARY_DIR}/m

add_subdirectory(${REPO_ROOT_DIR}/components/Adafruit-GFX-Library ${CMAKE_CURRENT_BINARY_DIR}/Adafruit-GFX-Library)

# Compile configs to have libraries use our esp-idf stubs
add_library(stubs_config INTERFACE)
target_compile_definitions(stubs_config INTERFACE
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=1
CONFIG_LOG_MAXIMUM_LEVEL=4
ESP_PLATFORM=1
)
target_include_directories(stubs_config INTERFACE ${REPO_ROOT_DIR}/lib/Simulator/stubs/esp-idf)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/defer" ${CMAKE_CURRENT_BINARY_DIR}/defer)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/spiram-cpp" ${CMAKE_CURRENT_BINARY_DIR}/spiram-cpp)
# Have spiram-cpp use our esp-idf stubs
target_include_directories(spiram-cpp PUBLIC ${REPO_ROOT_DIR}/lib/Simulator/stubs/esp-idf)
target_compile_definitions(spiram-cpp PUBLIC ESP_PLATFORM=1)
target_link_libraries(spiram-cpp PUBLIC stubs_config)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/stringutil" ${CMAKE_CURRENT_BINARY_DIR}/stringutil)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/bmpimage" ${CMAKE_CURRENT_BINARY_DIR}/bmpimage)
target_link_libraries(bmpimage PUBLIC stubs_config)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/unzipper" ${CMAKE_CURRENT_BINARY_DIR}/unzipper)
target_link_libraries(unzipper PUBLIC stubs_config)

add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/idflog" ${CMAKE_CURRENT_BINARY_DIR}/idflog)

add_subdirectory(${REPO_ROOT_DIR}/components/tiny-font ${CMAKE_CURRENT_BINARY_DIR}/tiny-font)

add_subdirectory(${REPO_ROOT_DIR}/components/tiny-epub/epubfile ${CMAKE_CURRENT_BINARY_DIR}/epubfile)

add_subdirectory(${REPO_ROOT_DIR}/components/tiny-epub/renderer ${CMAKE_CURRENT_BINARY_DIR}/renderer)

# Conditionally link freetype if we're using 8-bit or 16-bit display
if(DISPLAY_TYPE STREQUAL "DISPLAY_SIM_24BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_SIM_16BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_SIM_8BIT")
# Set FreeType options before adding the subdirectory
Expand All @@ -67,11 +86,19 @@ if(DISPLAY_TYPE STREQUAL "DISPLAY_SIM_24BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_S
CONFIG_TINYFONT_IBMF=0
CONFIG_TINYFONT_DISPLAY_DPI=${TTF_SCREEN_RES_PER_INCH}
)
target_compile_definitions(renderer PRIVATE
CONFIG_EPUB_RENDERER_REPLACE_SUPERSUBSCRIPT_CHARACTERS=0
CONFIG_EPUB_RENDERER_NATIVE_SUPERSUBSCRIPT_CHARACTERS=1
)
else()
target_compile_definitions(tiny-font PUBLIC
CONFIG_TINYFONT_TTF=0
CONFIG_TINYFONT_IBMF=1
)
target_compile_definitions(renderer PRIVATE
CONFIG_EPUB_RENDERER_REPLACE_SUPERSUBSCRIPT_CHARACTERS=1
CONFIG_EPUB_RENDERER_NATIVE_SUPERSUBSCRIPT_CHARACTERS=0
)
endif()

add_subdirectory(${REPO_ROOT_DIR}/lib/esp_ringbuf ${CMAKE_CURRENT_BINARY_DIR}/esp_ringbuf)
Expand All @@ -90,7 +117,16 @@ endif()

add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HTTP_CLIENT_SOURCE})

target_link_libraries(${PROJECT_NAME} PUBLIC pugixml ArduinoJson miniz astubs esp-idf-stubs nvs_flash Adafruit-GFX-Library tiny-font mbedtls mbedx509 mbedcrypto esp_ringbuf defer spiram-cpp stringutil)
target_link_libraries(${PROJECT_NAME} PUBLIC ArduinoJson miniz astubs esp-idf-stubs nvs_flash Adafruit-GFX-Library tiny-font mbedtls mbedx509 mbedcrypto esp_ringbuf defer spiram-cpp stringutil epubfile renderer)

target_compile_definitions(renderer PUBLIC
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_PARAGRAPH=5003
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_DISPLAY_PAGE=2400
CONFIG_EPUB_RENDERER_CSTR_POOL_SIZE=2000
CONFIG_EPUB_RENDERER_TOKENS_SIZE=500
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_LINE=200
CONFIG_EPUB_RENDERER_LINES_SIZE=36
)

target_include_directories(${PROJECT_NAME} PUBLIC
"${REPO_ROOT_DIR}/src"
Expand Down
2 changes: 2 additions & 0 deletions lib/Simulator/stubs/esp-idf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project(esp-idf-stubs)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Path to the root of the repo
set(REPO_ROOT_DIR "${PROJECT_SOURCE_DIR}/../../../..")

Expand Down
18 changes: 18 additions & 0 deletions lib/Simulator/stubs/esp-idf/esp_log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#include "esp_log.h"

#include <stdio.h>
#include <time.h>

void esp_log_level_set(const char *tag, esp_log_level_t level) { return; }

esp_log_level_t esp_log_level_get(const char *tag) { return ESP_LOG_DEBUG; }

uint32_t esp_log_timestamp(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}

void esp_log_write(esp_log_level_t level, const char *tag, const char *format, ...) {
va_list args;
va_start(args, format);
char buffer[512];
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
fprintf(stdout, "%s", buffer);
}
20 changes: 13 additions & 7 deletions scripts/epub-render/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#include <stb_image.h>
#pragma clang diagnostic pop

#include <EPubFile/EPubFile.hpp>
#include <Renderer/Renderer.hpp>
#include <Unzipper/UnzipperFileStream.hpp>

#include "DisplayUtil.hpp"
#include "EPub/EPubFile.hpp"
#include "Renderers/Renderer.hpp"
#include "Storage/SFileUnzipperStream.hpp"
#include "UI/Fonts.hpp"

int main(int argc, char **argv) {
Expand Down Expand Up @@ -121,11 +124,14 @@ int main(int argc, char **argv) {
readable->readableType = readableType;

PreferencesStore prefs;
SolDrm solDrm(prefs);
auto epubFile = std::make_shared<EPubFile>(file, readable, solDrm);

Renderer renderer(*display, boundingBoxRect, font);
renderer.setStream(epubFile);
auto solDrm = std::make_shared<SolDrm>(prefs);
auto unzipperStream = std::make_shared<SFileUnzipperStream>(file);
auto epubFile = std::make_shared<EPubFile>(unzipperStream, solDrm);
epubFile->setIsAnArticle(readable->readableType == "article");
auto epubStream = std::make_shared<EPubFileRendererStream>(epubFile);

Renderer renderer(*display, boundingBoxRect, FontHandle{font});
renderer.setStream(epubStream);
renderer.renderPage(place);
renderer.setLineSpacing(lineSpacing);

Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(components
miniz
ulp
astubs
pugixml
improv
ArduinoJson
Adafruit-GFX-Library
Expand Down
2 changes: 1 addition & 1 deletion src/Communications/HtmlCleaner.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <Renderer/RendererStream.hpp>
#include <Spiram/String.hpp>
#include <iostream>
#include <sstream>
#include <string>

#include "Renderers/RendererStream.hpp"
#include "Storage/SFile.hpp"

enum StripHtmlState {
Expand Down
97 changes: 86 additions & 11 deletions src/Displays/DisplaySystem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <Adafruit_GFX.h>
#include <Renderer/RendererDisplay.hpp>
#include <StringUtil/StringUtil.hpp>
#include <array>
#include <freertos/FreeRTOS.h>
Expand Down Expand Up @@ -65,13 +66,19 @@ struct DisplayRect {
[[nodiscard]] auto inset(uint16_t xAmount, uint16_t yAmount) const -> DisplayRect {
return inset(xAmount, xAmount, yAmount, yAmount);
}

// Implicit conversion to tiny-epub RendererDisplayRect
operator RendererDisplayRect() const {
return {static_cast<int16_t>(x), static_cast<int16_t>(y), static_cast<int16_t>(width),
static_cast<int16_t>(height)};
}
};

class DisplaySystem {
class DisplaySystem : public RendererDisplay {
public:
DisplaySystem();
DisplaySystem(DisplaySystem const &) = delete;
virtual ~DisplaySystem() = default;
~DisplaySystem() override = default;

// Constant text-box inset defaults during reading. These should be overridden to sane values in
// subclasses.
Expand Down Expand Up @@ -124,14 +131,14 @@ class DisplaySystem {
// Use these methods for normal drawing as they'll take into account the offsets and focus area
// automatically. Any methods we need from Adafruit_GFX that need to respect the focus area
// should be copied in here.
[[nodiscard]] auto width() const -> int16_t {
[[nodiscard]] inline auto width() const -> int16_t override {
return nativeWidth() - displayInsets().left - displayInsets().right;
};
[[nodiscard]] auto height() const -> int16_t {
[[nodiscard]] inline auto height() const -> int16_t override {
return nativeHeight() - displayInsets().top - displayInsets().bottom;
};

void fillScreen(uint16_t color) { gfxClass_->fillScreen(color); }
void fillScreen(uint16_t color) override { gfxClass_->fillScreen(color); }
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2,
uint16_t color) {
gfxClass_->fillTriangle(xOffset(x0), yOffset(y0), xOffset(x1), yOffset(y1), xOffset(x2),
Expand All @@ -141,7 +148,7 @@ class DisplaySystem {
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
gfxClass_->fillRect(xOffset(x), yOffset(y), w, h, color);
}
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) override {
gfxClass_->drawLine(xOffset(x0), yOffset(y0), xOffset(x1), yOffset(y1), color);
}
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
Expand Down Expand Up @@ -205,12 +212,11 @@ class DisplaySystem {
-> int;
auto getTextWidth(const std::string &buffer, Font *font = static_cast<Font *>(&fontFace0))
-> int;
inline auto getTextWidthQuick(const char *buffer, Font *font = static_cast<Font *>(&fontFace0))
-> int {
if (font == nullptr) {
inline auto getTextWidthQuick(const char *cstr, FontHandle font) -> uint16_t override {
if (font.ptr == nullptr) {
return -1;
} else {
return font->getTextWidthQuick(buffer);
return reinterpret_cast<Font *>(font.ptr)->getTextWidthQuick(cstr);
}
}

Expand All @@ -227,7 +233,76 @@ class DisplaySystem {

// Draw a bitmap
void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h,
uint16_t color);
uint16_t color) override;

inline auto lineHeight(FontHandle font) -> uint16_t override {
return font.ptr ? reinterpret_cast<Font *>(font.ptr)->lineHeight() : 0;
}

inline auto getTextWidth(const char *cstr, FontHandle font) -> uint16_t override {
if (!font.ptr || cstr == nullptr) {
return 0;
}
return reinterpret_cast<Font *>(font.ptr)->getTextWidth(cstr);
}

inline void getTextSize(const char *cstr, uint16_t *outWidth, uint16_t *outHeight,
FontHandle font) override {
if (!outWidth || !outHeight) {
return;
}
if (!font.ptr || !cstr) {
*outWidth = 0;
*outHeight = 0;
return;
}
Dim dim = reinterpret_cast<Font *>(font.ptr)->getTextSize(std::string(cstr));
*outWidth = dim.width;
*outHeight = dim.height;
}

[[nodiscard]] auto getSuperscriptCharacter(const char inputChar, FontHandle font) const -> const
char * override {
#if CONFIG_TINYFONT_IBMF
return reinterpret_cast<Font *>(font.ptr)->getSuperscriptCharacter(inputChar);
#elif CONFIG_TINYFONT_TTF
return nullptr;
#else
#error "No font system selected"
#endif
};

[[nodiscard]] auto getSubscriptCharacter(const char inputChar, FontHandle font) const -> const
char * override {
#if CONFIG_TINYFONT_IBMF
return reinterpret_cast<Font *>(font.ptr)->getSubscriptCharacter(inputChar);
#elif CONFIG_TINYFONT_TTF
return nullptr;
#else
#error "No font system selected"
#endif
};

inline void setSupSubFontSize(FontHandle font) override {
#if CONFIG_TINYFONT_TTF
reinterpret_cast<Font *>(font.ptr)->setSupSubFontSize();
#endif
}

inline void setNormalFontSize(FontHandle font) override {
#if CONFIG_TINYFONT_TTF
reinterpret_cast<Font *>(font.ptr)->setNormalFontSize();
#endif
}

inline auto drawSingleLineOfText(const char *cstr, int16_t x, int16_t y, bool invert,
FontHandle font) -> int16_t override {
if (!font.ptr || !cstr) {
return x;
}
return static_cast<int16_t>(this->drawSingleLineOfText(std::string(cstr), x, y, invert,
reinterpret_cast<Font *>(font.ptr)));
}

// Draw a bitmap scaled by a multiplier
void drawScaledXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h,
Expand Down
19 changes: 0 additions & 19 deletions src/EPub/EPubDefs.hpp

This file was deleted.

Loading
Loading