Skip to content

Commit 2365172

Browse files
authored
Split out epub+renderer code into sindarin-inc/tiny-epub (#1154)
1 parent 59ad579 commit 2365172

File tree

136 files changed

+738
-8153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+738
-8153
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
[submodule "components/cpp-misc"]
2626
path = components/cpp-misc
2727
url = [email protected]:sindarin-inc/cpp-misc.git
28+
[submodule "components/tiny-epub"]
29+
path = components/tiny-epub
30+
url = [email protected]:sindarin-inc/tiny-epub.git

.vscode/c_cpp_properties.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@
7373
"cStandard": "c17",
7474
"cppStandard": "c++17",
7575
"compileCommands": "${workspaceFolder}/components/esp_lcd_seeya103/test_apps/build-esp32p4/compile_commands.json"
76+
},
77+
{
78+
"name": "sim",
79+
"includePath": [
80+
"${default}"
81+
],
82+
"defines": [
83+
"_DEBUG",
84+
"UNICODE",
85+
"_UNICODE"
86+
],
87+
"cStandard": "c17",
88+
"cppStandard": "c++17",
89+
"compileCommands": "${workspaceFolder}/lib/Simulator/build/compile_commands.json"
7690
}
7791
],
7892
"version": 4

components/tiny-epub

Submodule tiny-epub added at 3cea0c8

lib/Simulator/Common/CMakeLists.txt

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,36 @@ add_subdirectory(${REPO_ROOT_DIR}/components/miniz ${CMAKE_CURRENT_BINARY_DIR}/m
4343

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

46+
# Compile configs to have libraries use our esp-idf stubs
47+
add_library(stubs_config INTERFACE)
48+
target_compile_definitions(stubs_config INTERFACE
49+
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=1
50+
CONFIG_LOG_MAXIMUM_LEVEL=4
51+
ESP_PLATFORM=1
52+
)
53+
target_include_directories(stubs_config INTERFACE ${REPO_ROOT_DIR}/lib/Simulator/stubs/esp-idf)
54+
4655
add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/defer" ${CMAKE_CURRENT_BINARY_DIR}/defer)
4756

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

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

62+
add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/bmpimage" ${CMAKE_CURRENT_BINARY_DIR}/bmpimage)
63+
target_link_libraries(bmpimage PUBLIC stubs_config)
64+
65+
add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/unzipper" ${CMAKE_CURRENT_BINARY_DIR}/unzipper)
66+
target_link_libraries(unzipper PUBLIC stubs_config)
67+
68+
add_subdirectory("${REPO_ROOT_DIR}/components/cpp-misc/idflog" ${CMAKE_CURRENT_BINARY_DIR}/idflog)
69+
5570
add_subdirectory(${REPO_ROOT_DIR}/components/tiny-font ${CMAKE_CURRENT_BINARY_DIR}/tiny-font)
5671

72+
add_subdirectory(${REPO_ROOT_DIR}/components/tiny-epub/epubfile ${CMAKE_CURRENT_BINARY_DIR}/epubfile)
73+
74+
add_subdirectory(${REPO_ROOT_DIR}/components/tiny-epub/renderer ${CMAKE_CURRENT_BINARY_DIR}/renderer)
75+
5776
# Conditionally link freetype if we're using 8-bit or 16-bit display
5877
if(DISPLAY_TYPE STREQUAL "DISPLAY_SIM_24BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_SIM_16BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_SIM_8BIT")
5978
# Set FreeType options before adding the subdirectory
@@ -67,11 +86,19 @@ if(DISPLAY_TYPE STREQUAL "DISPLAY_SIM_24BIT" OR DISPLAY_TYPE STREQUAL "DISPLAY_S
6786
CONFIG_TINYFONT_IBMF=0
6887
CONFIG_TINYFONT_DISPLAY_DPI=${TTF_SCREEN_RES_PER_INCH}
6988
)
89+
target_compile_definitions(renderer PRIVATE
90+
CONFIG_EPUB_RENDERER_REPLACE_SUPERSUBSCRIPT_CHARACTERS=0
91+
CONFIG_EPUB_RENDERER_NATIVE_SUPERSUBSCRIPT_CHARACTERS=1
92+
)
7093
else()
7194
target_compile_definitions(tiny-font PUBLIC
7295
CONFIG_TINYFONT_TTF=0
7396
CONFIG_TINYFONT_IBMF=1
7497
)
98+
target_compile_definitions(renderer PRIVATE
99+
CONFIG_EPUB_RENDERER_REPLACE_SUPERSUBSCRIPT_CHARACTERS=1
100+
CONFIG_EPUB_RENDERER_NATIVE_SUPERSUBSCRIPT_CHARACTERS=0
101+
)
75102
endif()
76103

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

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

93-
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)
120+
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)
121+
122+
target_compile_definitions(renderer PUBLIC
123+
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_PARAGRAPH=5003
124+
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_DISPLAY_PAGE=2400
125+
CONFIG_EPUB_RENDERER_CSTR_POOL_SIZE=2000
126+
CONFIG_EPUB_RENDERER_TOKENS_SIZE=500
127+
CONFIG_EPUB_RENDERER_MAX_BYTES_PER_LINE=200
128+
CONFIG_EPUB_RENDERER_LINES_SIZE=36
129+
)
94130

95131
target_include_directories(${PROJECT_NAME} PUBLIC
96132
"${REPO_ROOT_DIR}/src"

lib/Simulator/stubs/esp-idf/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(esp-idf-stubs)
33

4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
46
# Path to the root of the repo
57
set(REPO_ROOT_DIR "${PROJECT_SOURCE_DIR}/../../../..")
68

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#include "esp_log.h"
22

3+
#include <stdio.h>
4+
#include <time.h>
5+
36
void esp_log_level_set(const char *tag, esp_log_level_t level) { return; }
47

58
esp_log_level_t esp_log_level_get(const char *tag) { return ESP_LOG_DEBUG; }
9+
10+
uint32_t esp_log_timestamp(void) {
11+
struct timespec ts;
12+
clock_gettime(CLOCK_MONOTONIC, &ts);
13+
return (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
14+
}
15+
16+
void esp_log_write(esp_log_level_t level, const char *tag, const char *format, ...) {
17+
va_list args;
18+
va_start(args, format);
19+
char buffer[512];
20+
vsnprintf(buffer, sizeof(buffer), format, args);
21+
va_end(args);
22+
fprintf(stdout, "%s", buffer);
23+
}

scripts/epub-render/main.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include <stb_image.h>
1111
#pragma clang diagnostic pop
1212

13+
#include <EPubFile/EPubFile.hpp>
14+
#include <Renderer/Renderer.hpp>
15+
#include <Unzipper/UnzipperFileStream.hpp>
16+
1317
#include "DisplayUtil.hpp"
14-
#include "EPub/EPubFile.hpp"
15-
#include "Renderers/Renderer.hpp"
18+
#include "Storage/SFileUnzipperStream.hpp"
1619
#include "UI/Fonts.hpp"
1720

1821
int main(int argc, char **argv) {
@@ -121,11 +124,14 @@ int main(int argc, char **argv) {
121124
readable->readableType = readableType;
122125

123126
PreferencesStore prefs;
124-
SolDrm solDrm(prefs);
125-
auto epubFile = std::make_shared<EPubFile>(file, readable, solDrm);
126-
127-
Renderer renderer(*display, boundingBoxRect, font);
128-
renderer.setStream(epubFile);
127+
auto solDrm = std::make_shared<SolDrm>(prefs);
128+
auto unzipperStream = std::make_shared<SFileUnzipperStream>(file);
129+
auto epubFile = std::make_shared<EPubFile>(unzipperStream, solDrm);
130+
epubFile->setIsAnArticle(readable->readableType == "article");
131+
auto epubStream = std::make_shared<EPubFileRendererStream>(epubFile);
132+
133+
Renderer renderer(*display, boundingBoxRect, FontHandle{font});
134+
renderer.setStream(epubStream);
129135
renderer.renderPage(place);
130136
renderer.setLineSpacing(lineSpacing);
131137

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ set(components
1010
miniz
1111
ulp
1212
astubs
13-
pugixml
1413
improv
1514
ArduinoJson
1615
Adafruit-GFX-Library

0 commit comments

Comments
 (0)