Text past Latin-1, and the showcase in three languages
Two optional modules, each an interface library with a _none twin and a REAKTOR_<NAME> option that defaults on, so an application that wants neither links neither. Locale reads a catalog per language from assets/locale, or compiles them in with REAKTOR_LOCALE_EMBED: key = value lines, gettext plural rules, and numbers, money and dates written the way each catalog says. The atlas bakes what the catalogs use that Aileron has, and --lang picks the language. Text draws what the atlas cannot. A string with any character the atlas lacks is measured and drawn by core/text/text.c instead of Nuklear: direction by mojibake's bidirectional algorithm, shaping by kb_text_shape, glyphs from the first font that has them, rasterized at the size they are drawn, and lines broken by UAX #14. Both libraries come in as submodules. M PLUS 1p is vendored with its OFL notice for the showcase's Japanese, and --font-fallback adds more. The showcase gains a Translations page: the opening of The Ugly Duckling in English, Polish and Japanese, beside a date, a number, money in three currencies and a plural count, each formatted the way that language writes it. A clean-up pass followed: shared helpers for what was duplicated, and comments cut to the few one-liners that guard against a bug. Screenshots and --a11y-dump of all ten tabs, of Polish and Japanese, and of a right-to-left sample were compared before and after it and are byte-identical. The seven tests pass, localetest and texttest among them, and the native and WebAssembly builds both link. The docs follow. DOCUMENTATION.md covers both modules and the formatting keys, DEMO.md shows each of the four applications, benchmarks/README.md becomes BENCHMARKS.md, PERFORMANCE.md drops the per-machine CPU column and the history of the old chart, and the GitHub Pages workflow is added. The showcase and bench windows are titled Showcase and Bench, as notepad and simple already were. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@@ -0,0 +1,67 @@
|
||||
name: Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
EMSCRIPTEN_VERSION: 6.0.9
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Cache emsdk
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/emsdk
|
||||
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
|
||||
|
||||
- name: Install emsdk
|
||||
run: |
|
||||
if [ ! -x "$HOME/emsdk/emsdk" ]; then
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
fi
|
||||
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
|
||||
"$HOME/emsdk/emsdk" activate "$EMSCRIPTEN_VERSION"
|
||||
|
||||
- name: Install Ninja
|
||||
run: sudo apt-get update && sudo apt-get install -y ninja-build
|
||||
|
||||
- name: Build
|
||||
run: EMSDK="$HOME/emsdk" ./build-wasm.sh
|
||||
|
||||
- name: Assemble the site
|
||||
run: |
|
||||
mkdir -p site
|
||||
cp build-wasm/showcase.js build-wasm/showcase.wasm build-wasm/showcase.data site/
|
||||
cp build-wasm/showcase.html site/index.html
|
||||
|
||||
- uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: site
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -22,3 +22,9 @@
|
||||
[submodule "external/onlay"]
|
||||
path = external/onlay
|
||||
url = https://github.com/Alpaq92/Onlay.git
|
||||
[submodule "external/mojibake"]
|
||||
path = external/mojibake
|
||||
url = https://github.com/zaerl/mojibake.git
|
||||
[submodule "external/kb"]
|
||||
path = external/kb
|
||||
url = https://github.com/JimmyLefevre/kb.git
|
||||
|
||||
@@ -8,6 +8,10 @@ C99. Widgets are declared; the look comes from CSS read at runtime.
|
||||
script finds MSVC's. `./build.ps1 <target>` builds one. Targets: `showcase`,
|
||||
`notepad`, `simple`, `bench`, plus the tests in `tools/`.
|
||||
|
||||
CMake options pass straight through: `./build.ps1 -DREAKTOR_A11Y=OFF`,
|
||||
`./build.sh -- -DREAKTOR_A11Y=OFF`. The cache keeps an option, so a later build
|
||||
without the flag does not reset it — pass `=ON` to switch back.
|
||||
|
||||
## Verify against pixels, not source
|
||||
|
||||
Reasoning from a dependency's source about what it will draw has been wrong
|
||||
@@ -40,6 +44,12 @@ regression oracle for every layout or style change.
|
||||
- **Measure the present, not the draw.** On a machine with no GPU, most of a
|
||||
frame is `SDL_RenderPresent`. `build/render/present` split is on the
|
||||
Diagnostics page and in `bench --no-vsync`.
|
||||
- **Text the atlas cannot draw is not Nuklear's to draw.** A string with any
|
||||
character the atlas lacks — Japanese, Arabic — is measured by
|
||||
`core/text/text.c` and drawn from the custom command it swaps in for
|
||||
Nuklear's text command, so a change to how Nuklear or the renderer places
|
||||
glyphs does not reach it. Its bidi levels are matched to mojibake's by order:
|
||||
mojibake 0.3.6 records `byte_offset` at a character's last byte.
|
||||
- **A hidden web page runs no frames.** The web build's main loop waits on
|
||||
`requestAnimationFrame`, which never fires in a background tab, a minimized
|
||||
window or a browser pane that is not on screen. `#a11y` is made in `main()`,
|
||||
@@ -56,3 +66,8 @@ regression oracle for every layout or style change.
|
||||
the runtime strips from `argv`.
|
||||
- `docs/DOCUMENTATION.md` is the whole of it; `PERFORMANCE.md` holds measured
|
||||
numbers only, with the machine named.
|
||||
- An optional module is an interface library plus a `_none` twin defining the
|
||||
same functions, and an application links one of the two; its
|
||||
`REAKTOR_<NAME>` option, default `ON`, swaps in the twin. Localization and
|
||||
text shaping are two modules, not one. A module that is off must leave pixels
|
||||
and `--a11y-dump` byte-identical except for what the module itself produces.
|
||||
|
||||
@@ -144,6 +144,14 @@ if(NOT EMSCRIPTEN)
|
||||
set_target_properties(animtest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(localetest tools/localetest.c
|
||||
core/locale/locale.c core/locale/plural.c
|
||||
core/locale/format.c)
|
||||
target_include_directories(localetest PRIVATE core/locale)
|
||||
target_compile_definitions(localetest PRIVATE REAKTOR_LOCALE_EMBEDDED)
|
||||
set_target_properties(localetest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(laytest tools/laytest.c core/ui/layout.c)
|
||||
target_include_directories(laytest PRIVATE core/ui core/render)
|
||||
target_link_libraries(laytest PRIVATE onlay)
|
||||
@@ -178,31 +186,143 @@ StartupWMClass=showcase
|
||||
")
|
||||
endif()
|
||||
|
||||
set(SYS_SRC "")
|
||||
set(SYS_LIBS "")
|
||||
set(SYS_DEFS "")
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
list(APPEND SYS_SRC platform/a11y/a11y_snapshot.c platform/a11y/a11y_win32.c)
|
||||
elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
option(REAKTOR_A11Y
|
||||
"Serve the accessibility tree to screen readers (UI Automation, AT-SPI, NSAccessibility, the DOM)"
|
||||
ON)
|
||||
|
||||
set(_a11y "${CMAKE_CURRENT_SOURCE_DIR}/platform/a11y")
|
||||
add_library(reaktor_a11y_none INTERFACE)
|
||||
target_sources(reaktor_a11y_none INTERFACE "${_a11y}/a11y_none.c")
|
||||
|
||||
add_library(reaktor_a11y INTERFACE)
|
||||
if(NOT REAKTOR_A11Y)
|
||||
target_link_libraries(reaktor_a11y INTERFACE reaktor_a11y_none)
|
||||
message(STATUS "a11y: off; the tree is built and served to nothing")
|
||||
elseif(EMSCRIPTEN)
|
||||
target_sources(reaktor_a11y INTERFACE "${_a11y}/a11y_web.c")
|
||||
elseif(WIN32)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_win32.c")
|
||||
target_link_libraries(reaktor_a11y INTERFACE uiautomationcore ole32 oleaut32)
|
||||
elseif(APPLE)
|
||||
enable_language(OBJC)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_macos.m")
|
||||
set_source_files_properties("${_a11y}/a11y_macos.m" PROPERTIES
|
||||
COMPILE_OPTIONS "-fobjc-arc")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
target_link_libraries(reaktor_a11y INTERFACE "-framework Cocoa")
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(DBUS QUIET dbus-1)
|
||||
endif()
|
||||
if(DBUS_FOUND)
|
||||
list(APPEND SYS_SRC platform/a11y/a11y_snapshot.c platform/a11y/a11y_atspi.c)
|
||||
list(APPEND SYS_LIBS ${DBUS_LIBRARIES})
|
||||
list(APPEND SYS_DEFS REAKTOR_HAVE_ATSPI)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_atspi.c")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_ATSPI)
|
||||
target_include_directories(reaktor_a11y INTERFACE ${DBUS_INCLUDE_DIRS})
|
||||
target_link_libraries(reaktor_a11y INTERFACE ${DBUS_LIBRARIES})
|
||||
message(STATUS "a11y: AT-SPI over libdbus ${DBUS_VERSION}")
|
||||
else()
|
||||
target_link_libraries(reaktor_a11y INTERFACE reaktor_a11y_none)
|
||||
message(STATUS "a11y: no dbus-1; the AT-SPI bridge is not built")
|
||||
endif()
|
||||
elseif(APPLE AND NOT EMSCRIPTEN)
|
||||
enable_language(OBJC)
|
||||
list(APPEND SYS_SRC platform/a11y/a11y_snapshot.c platform/a11y/a11y_macos.m)
|
||||
list(APPEND SYS_DEFS REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
set_source_files_properties(platform/a11y/a11y_macos.m PROPERTIES
|
||||
COMPILE_OPTIONS "-fobjc-arc")
|
||||
list(APPEND SYS_LIBS "-framework Cocoa")
|
||||
endif()
|
||||
|
||||
option(REAKTOR_LOCALE "Translations, from the catalogs in assets/locale" ON)
|
||||
option(REAKTOR_LOCALE_EMBED "Compile the catalogs in rather than read them at startup" OFF)
|
||||
|
||||
set(_locale "${CMAKE_CURRENT_SOURCE_DIR}/core/locale")
|
||||
add_library(reaktor_locale_none INTERFACE)
|
||||
target_sources(reaktor_locale_none INTERFACE "${_locale}/locale_none.c")
|
||||
|
||||
add_library(reaktor_locale INTERFACE)
|
||||
if(NOT REAKTOR_LOCALE)
|
||||
target_link_libraries(reaktor_locale INTERFACE reaktor_locale_none)
|
||||
message(STATUS "locale: off")
|
||||
else()
|
||||
target_sources(reaktor_locale INTERFACE
|
||||
"${_locale}/locale.c" "${_locale}/plural.c" "${_locale}/format.c"
|
||||
"${_locale}/locale_runtime.c")
|
||||
if(REAKTOR_LOCALE_EMBED)
|
||||
file(GLOB _catalogs CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/assets/locale/*.txt")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_catalogs})
|
||||
set(_gen "/* Generated by CMakeLists.txt from assets/locale. */\n#include \"locale_internal.h\"\n\n")
|
||||
set(_rows "")
|
||||
set(_n 0)
|
||||
foreach(_f IN LISTS _catalogs)
|
||||
get_filename_component(_code "${_f}" NAME_WE)
|
||||
file(READ "${_f}" _hex HEX)
|
||||
file(SIZE "${_f}" _size)
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," _bytes "${_hex}")
|
||||
string(APPEND _gen "static const unsigned char catalog_${_n}[] = {${_bytes}0};\n")
|
||||
string(APPEND _rows " { \"${_code}\", catalog_${_n}, ${_size} },\n")
|
||||
math(EXPR _n "${_n} + 1")
|
||||
endforeach()
|
||||
if(_n EQUAL 0)
|
||||
set(_rows " { 0, 0, 0 },\n")
|
||||
endif()
|
||||
string(APPEND _gen
|
||||
"\nconst struct reaktor_locale_catalog reaktor_locale_catalogs[] = {\n${_rows}};\n"
|
||||
"const int reaktor_locale_catalog_count = ${_n};\n")
|
||||
set(_out "${CMAKE_BINARY_DIR}/gen/locale_catalogs.c")
|
||||
set(_old "")
|
||||
if(EXISTS "${_out}")
|
||||
file(READ "${_out}" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL _gen)
|
||||
file(WRITE "${_out}" "${_gen}")
|
||||
endif()
|
||||
target_sources(reaktor_locale INTERFACE "${_out}")
|
||||
target_compile_definitions(reaktor_locale INTERFACE REAKTOR_LOCALE_EMBEDDED)
|
||||
message(STATUS "locale: ${_n} catalogs compiled in")
|
||||
else()
|
||||
message(STATUS "locale: catalogs read from assets/locale at startup")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_TEXT "Shaping, direction, fallback fonts and Unicode line breaking" ON)
|
||||
|
||||
set(_text "${CMAKE_CURRENT_SOURCE_DIR}/core/text")
|
||||
add_library(reaktor_text_none INTERFACE)
|
||||
target_sources(reaktor_text_none INTERFACE "${_text}/text_none.c")
|
||||
|
||||
add_library(reaktor_text INTERFACE)
|
||||
if(NOT REAKTOR_TEXT)
|
||||
target_link_libraries(reaktor_text INTERFACE reaktor_text_none)
|
||||
message(STATUS "text: off; lines break at spaces, and Aileron draws what it can")
|
||||
else()
|
||||
set(MJB_FEATURE_CHARACTER_NAMES OFF)
|
||||
set(MJB_FEATURE_COLLATION OFF)
|
||||
set(MJB_FEATURE_IDNA OFF)
|
||||
set(MJB_FEATURE_SECURITY OFF)
|
||||
add_subdirectory(${TP}/mojibake EXCLUDE_FROM_ALL)
|
||||
if(EMSCRIPTEN)
|
||||
set_target_properties(mojibake_lib PROPERTIES C_EXTENSIONS ON)
|
||||
endif()
|
||||
|
||||
add_library(kb_text_shape STATIC "${_text}/kb.c")
|
||||
target_include_directories(kb_text_shape PUBLIC "${TP}/kb")
|
||||
if(MSVC)
|
||||
target_compile_options(kb_text_shape PRIVATE /w)
|
||||
else()
|
||||
target_compile_options(kb_text_shape PRIVATE -w)
|
||||
endif()
|
||||
|
||||
target_sources(reaktor_text INTERFACE "${_text}/text.c")
|
||||
target_link_libraries(reaktor_text INTERFACE Mojibake::mojibake kb_text_shape)
|
||||
message(STATUS "text: shaping by kb_text_shape; direction and line breaking by mojibake")
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
add_executable(texttest tools/texttest.c core/render/nk_impl.c)
|
||||
target_include_directories(texttest PRIVATE core/render core/text)
|
||||
target_link_libraries(texttest PRIVATE reaktor_text reaktor_core
|
||||
SDL3::SDL3-static)
|
||||
set_target_properties(texttest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(reaktor_runtime STATIC
|
||||
@@ -219,9 +339,7 @@ add_library(reaktor_runtime STATIC
|
||||
core/ui/layout.c
|
||||
core/ui/style_map.c
|
||||
core/ui/widgets.c
|
||||
platform/a11y/a11y_web.c
|
||||
platform/theme.c
|
||||
${SYS_SRC}
|
||||
runtime/app.c)
|
||||
|
||||
target_include_directories(reaktor_runtime PUBLIC
|
||||
@@ -229,7 +347,9 @@ target_include_directories(reaktor_runtime PUBLIC
|
||||
core/anim
|
||||
core/base
|
||||
core/css
|
||||
core/locale
|
||||
core/render
|
||||
core/text
|
||||
core/ui
|
||||
platform
|
||||
platform/a11y
|
||||
@@ -243,18 +363,6 @@ target_link_libraries(reaktor_runtime PUBLIC
|
||||
SDL3::SDL3-static
|
||||
onlay
|
||||
lcui)
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_runtime PUBLIC uiautomationcore ole32 oleaut32)
|
||||
endif()
|
||||
if(SYS_LIBS)
|
||||
target_link_libraries(reaktor_runtime PUBLIC ${SYS_LIBS})
|
||||
endif()
|
||||
if(DBUS_FOUND)
|
||||
target_include_directories(reaktor_runtime PUBLIC ${DBUS_INCLUDE_DIRS})
|
||||
endif()
|
||||
if(SYS_DEFS)
|
||||
target_compile_definitions(reaktor_runtime PUBLIC ${SYS_DEFS})
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_runtime PUBLIC dxguid)
|
||||
@@ -266,22 +374,27 @@ add_executable(showcase WIN32
|
||||
samples/showcase/showcase.c
|
||||
${APP_RESOURCES})
|
||||
target_include_directories(showcase PRIVATE samples samples/showcase)
|
||||
target_link_libraries(showcase PRIVATE reaktor_runtime)
|
||||
target_link_libraries(showcase PRIVATE
|
||||
reaktor_runtime reaktor_a11y reaktor_locale reaktor_text)
|
||||
|
||||
add_executable(simple WIN32 samples/simple/simple.c ${APP_RESOURCES})
|
||||
target_include_directories(simple PRIVATE samples)
|
||||
target_link_libraries(simple PRIVATE reaktor_runtime)
|
||||
target_link_libraries(simple PRIVATE
|
||||
reaktor_runtime reaktor_a11y_none reaktor_locale_none
|
||||
reaktor_text_none)
|
||||
|
||||
add_executable(notepad WIN32 samples/notepad/notepad.c ${APP_RESOURCES})
|
||||
target_include_directories(notepad PRIVATE samples)
|
||||
target_link_libraries(notepad PRIVATE reaktor_runtime)
|
||||
target_link_libraries(notepad PRIVATE
|
||||
reaktor_runtime reaktor_a11y_none reaktor_locale_none
|
||||
reaktor_text_none)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
# WIN32 like the rest, so no console flashes up. bench reattaches to the
|
||||
# parent's console itself when it has one, which is where stdout goes.
|
||||
add_executable(bench WIN32 samples/bench/bench.c ${APP_RESOURCES})
|
||||
target_include_directories(bench PRIVATE samples)
|
||||
target_link_libraries(bench PRIVATE reaktor_runtime)
|
||||
target_link_libraries(bench PRIVATE
|
||||
reaktor_runtime reaktor_a11y_none reaktor_locale_none
|
||||
reaktor_text_none)
|
||||
set_target_properties(bench PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
@@ -293,6 +406,12 @@ if(EMSCRIPTEN)
|
||||
target_compile_options(plutovg PRIVATE -Oz)
|
||||
target_compile_options(plutosvg PRIVATE -Oz)
|
||||
target_compile_options(reaktor_core PRIVATE -Oz)
|
||||
if(TARGET mojibake_lib)
|
||||
target_compile_options(mojibake_lib PRIVATE -Oz)
|
||||
endif()
|
||||
if(TARGET kb_text_shape)
|
||||
target_compile_options(kb_text_shape PRIVATE -Oz)
|
||||
endif()
|
||||
|
||||
set(WASM_ASSETS "")
|
||||
file(GLOB _reaktor_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
|
||||
@@ -316,6 +435,18 @@ if(EMSCRIPTEN)
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES WASM_ASSETS)
|
||||
|
||||
set(_fallback_font "assets/fonts/MPLUS1p-Regular.ttf")
|
||||
list(REMOVE_ITEM WASM_ASSETS "${_fallback_font}")
|
||||
set(WASM_MODULES "")
|
||||
if(REAKTOR_TEXT AND REAKTOR_LOCALE)
|
||||
list(APPEND WASM_MODULES
|
||||
"SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/${_fallback_font}@/${_fallback_font}")
|
||||
endif()
|
||||
if(REAKTOR_LOCALE AND NOT REAKTOR_LOCALE_EMBED)
|
||||
list(APPEND WASM_MODULES
|
||||
"SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets/locale@/assets/locale")
|
||||
endif()
|
||||
|
||||
set(WASM_ICONS "")
|
||||
foreach(_s IN LISTS _reaktor_srcs)
|
||||
file(STRINGS "${_s}" _lines REGEX "[a-z0-9-]+-outline")
|
||||
@@ -374,6 +505,7 @@ if(EMSCRIPTEN)
|
||||
set_target_properties(showcase PROPERTIES SUFFIX ".html")
|
||||
target_link_options(showcase PRIVATE
|
||||
${WASM_PRELOAD}
|
||||
${WASM_MODULES}
|
||||
-sALLOW_MEMORY_GROWTH=1
|
||||
-sINITIAL_MEMORY=64MB
|
||||
-sSTACK_SIZE=4MB
|
||||
|
||||
@@ -9,7 +9,8 @@ at a control and saying it looked off.
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
./build.sh # build.ps1 on Windows
|
||||
./build/laytest && ./build/a11ytest && ./build/animtest && ./build/keytest
|
||||
for t in laytest onlaytest a11ytest animtest keytest localetest texttest
|
||||
do ./build/$t || break; done
|
||||
```
|
||||
|
||||
`./build-wasm.sh` builds the web target from the same sources and catches
|
||||
@@ -51,6 +52,12 @@ Binding unless you make the case for changing one.
|
||||
none, trace them to something the author published — the file's own metadata
|
||||
counts — then write down what you found and that you assembled the record.
|
||||
`assets/fonts/Aileron-Notice.txt` is the shape to copy.
|
||||
- **An optional feature is a module, and a module can be left out.** It is an
|
||||
interface library with a `_none` twin that defines the same functions, and a
|
||||
`REAKTOR_<NAME>` option, `ON` by default, that swaps the twin in. A build with
|
||||
the module off draws the same pixels and writes the same `--a11y-dump`, except
|
||||
for what the module itself produces. Localization and text shaping are two
|
||||
modules, not one.
|
||||
- **Nothing is drawn when nothing has changed.** Do not add a timer, a polling
|
||||
loop or an unconditional repaint to make something update; make the thing
|
||||
that changed mark the frame dirty.
|
||||
@@ -64,7 +71,7 @@ Binding unless you make the case for changing one.
|
||||
|
||||
For a change of any size, say in the pull request:
|
||||
|
||||
- that both targets build — native and WebAssembly — and the five tests pass;
|
||||
- that both targets build — native and WebAssembly — and the seven tests pass;
|
||||
- **the accessibility dump before and after**, if anything moved. Run with
|
||||
`--a11y-dump <path>` and diff the two; it reports position to the pixel and
|
||||
is the closest thing here to a regression suite;
|
||||
|
||||
@@ -2,19 +2,28 @@
|
||||
|
||||
A Nuklear-powered (GUI) engine for C.
|
||||
|
||||

|
||||
<p align="center">
|
||||
<img src="assets/screenshots/screenshot.png" alt="The Reaktor showcase, split along the diagonal: the same window in the light scheme above the line and the dark scheme below it, showing a centered login card, a tab strip across the top and a scheme switch beside the window controls">
|
||||
</p>
|
||||
|
||||
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)** — the
|
||||
same program, built to WebAssembly.
|
||||
|
||||
Tired of C having no cross-platform GUI — nothing like Avalonia, Shaft or
|
||||
Freya — and of leaning on toolkits that want hundreds of megabytes just to put
|
||||
a dialog on screen? No? I was. So I wrote Reaktor: a GUI library that is
|
||||
complete without being big. A 2.5 MB binary, about 10 MB of RAM, and no GPU
|
||||
complete without being big. A 2.3 MB binary, about 10 MB of RAM, and no GPU
|
||||
required.
|
||||
|
||||
> ⚠️ **Reaktor is in active development**, and breaking changes might occur.
|
||||
|
||||
<p align="center">
|
||||
<a href="docs/PERFORMANCE.md"><img src="assets/rest/benchmark.svg" alt="Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window. Memory: Reaktor 10.0 MB, the same binary on D3D11 60.7 MB and on OpenGL 90.2 MB, Flutter 92.2 MB, Electron 158.3 MB, Kotlin Multiplatform 669.8 MB. CPU as a percent of one core: Reaktor 16.4%, D3D11 14.4%, OpenGL 14.1%, Flutter 16.6%, Electron 39.0%, Kotlin Multiplatform 56.1%"></a>
|
||||
</p>
|
||||
|
||||
How these were measured, and on what, is in
|
||||
[PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
|
||||
## What it is made of
|
||||
|
||||
- **[Nuklear](https://github.com/Immediate-Mode-UI/Nuklear)** draws the
|
||||
@@ -39,17 +48,24 @@ required.
|
||||
DOM subtree on the web. Keyboard focus and shortcuts included.
|
||||
- **HiDPI** — layout in logical pixels, atlas baked at the display's size.
|
||||
- **Light and dark** — follows the system, or pick one.
|
||||
- **Localization** — a catalog per language, plural rules, and numbers, money
|
||||
and dates as each language writes them: English, Polish and Japanese in the
|
||||
showcase.
|
||||
- **Text past Latin-1** — right-to-left direction, shaping for Arabic, Hebrew
|
||||
and the Indic scripts, glyphs from fallback fonts at any size, and line breaks
|
||||
by Unicode's rules, so Japanese wraps properly.
|
||||
- **Modular** — the accessibility bridges, localization and text shaping are
|
||||
modules, each on by default. `-DREAKTOR_A11Y=OFF`, `-DREAKTOR_LOCALE=OFF` or
|
||||
`-DREAKTOR_TEXT=OFF` swaps one for a stub with the same calls, and the rest
|
||||
of the app draws the same pixels.
|
||||
- **Windows, macOS, Linux, the BSDs and WebAssembly** — one set of sources,
|
||||
the same software rasterizer on all five, no GPU required.
|
||||
- **Nothing drawn at rest** — 0% of a core while it sits there.
|
||||
|
||||
Not yet: **localization**. The font atlas bakes Latin-1 only and there is no
|
||||
text shaping or bidi, so anything past Western European scripts does not
|
||||
render — see [docs/DOCUMENTATION.md](docs/DOCUMENTATION.md#localization).
|
||||
|
||||
## Build
|
||||
|
||||
Needs a C99 compiler, CMake and the submodules.
|
||||
Needs CMake, the submodules and a C11 compiler: Reaktor is C99, but mojibake,
|
||||
which the Text module uses, is C11.
|
||||
|
||||
```bash
|
||||
git clone --recursive https://github.com/Alpaq92/Reaktor
|
||||
@@ -88,29 +104,17 @@ position.
|
||||
|
||||
- [docs/DOCUMENTATION.md](docs/DOCUMENTATION.md) — the whole of it: the
|
||||
declarative API, layout, styling, accessibility and animation, then the tree,
|
||||
the tests and the command-line flags.
|
||||
the tests, the command-line flags, localization and text.
|
||||
- [docs/DEMO.md](docs/DEMO.md) — the four applications in this repository and
|
||||
what each one is for.
|
||||
- [docs/PERFORMANCE.md](docs/PERFORMANCE.md) — what it costs, measured on four
|
||||
platforms, and against Flutter, Electron and Compose Multiplatform on one.
|
||||
- [benchmarks/README.md](benchmarks/README.md) — those three as projects of
|
||||
their own, drawing the same picture, and the script that measures them all
|
||||
the same way.
|
||||
- [benchmarks/BENCHMARKS.md](benchmarks/BENCHMARKS.md) — those three as
|
||||
projects of their own, drawing the same picture, and the script that
|
||||
measures them all the same way.
|
||||
- [docs/NOTICE.md](docs/NOTICE.md) — what it depends on, and under what
|
||||
license.
|
||||
|
||||
## Wanted, not yet built
|
||||
|
||||
- **Localization.** Translating what a program says, and letting an
|
||||
application ship more than one language.
|
||||
- **Support for non-Latin scripts.** Everything past Western European text —
|
||||
Cyrillic, Greek, CJK, Arabic, Hebrew, the Indic scripts, and the shaping
|
||||
they need.
|
||||
- **Further optimization, and a pass over the code.** Faster frames, and
|
||||
fewer places doing the same job twice.
|
||||
- **Modularity.** A build today is all or nothing. The accessibility bridges,
|
||||
and the libraries they drag in, should be things you can turn off.
|
||||
|
||||
## License
|
||||
|
||||
MIT. The dependencies keep their own — see [docs/NOTICE.md](docs/NOTICE.md).
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
M PLUS 1p - license notice
|
||||
==========================
|
||||
|
||||
MPLUS1p-Regular.ttf is M PLUS 1p Regular, version 1.062, by The M+ Project
|
||||
Authors, licensed under the SIL Open Font License 1.1. The license text follows
|
||||
unchanged.
|
||||
|
||||
It is the file exactly as Google Fonts ships it:
|
||||
|
||||
https://github.com/google/fonts/blob/a24c920263576ec723d64c1b26f8afabb841601d/ofl/mplus1p/MPLUS1p-Regular.ttf
|
||||
1,758,688 bytes, SHA-256 2f294ad496432b1608f070d310e3aa2adcf1de4af429f4901df97ec4bd361ed1
|
||||
|
||||
The showcase uses it for Japanese, handing it to the Text module, which opens
|
||||
it the first time it needs a character Aileron lacks and rasterizes each glyph
|
||||
when it is first drawn, at the size it is drawn.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Copyright 2016 The M+ Project Authors.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Copyright 2016 The Rounded M+ Project Authors.
|
||||
@@ -0,0 +1,29 @@
|
||||
language = English
|
||||
plural = n != 1
|
||||
locale.title = The Ugly Duckling
|
||||
locale.author = Hans Christian Andersen
|
||||
locale.source = Translated by Mrs. H. B. Paull. Hans Andersen's Fairy Tales, Frederick Warne and Co., 1888. Public domain; the text is Wikisource's.
|
||||
locale.formats = Formats
|
||||
locale.date = Date
|
||||
locale.time = Time
|
||||
locale.number = Number
|
||||
locale.money = Money
|
||||
locale.plural = Plurals
|
||||
locale.count = {n} duckling | {n} ducklings
|
||||
number.decimal = .
|
||||
number.group = ,
|
||||
number.group.min = 1
|
||||
money = {s}{n}
|
||||
money.USD = $
|
||||
money.JPY = ¥
|
||||
money.JPY.digits = 0
|
||||
date.short = M/d/yy
|
||||
date.long = MMMM d, y
|
||||
date.full = EEEE, MMMM d, y
|
||||
time.short = h:mm a
|
||||
time.ampm = AM | PM
|
||||
date.months = January | February | March | April | May | June | July | August | September | October | November | December
|
||||
date.months.short = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
|
||||
date.days = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday
|
||||
date.days.short = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
locale.story = It was lovely summer weather in the country, and the golden corn, the green oats, and the haystacks piled up in the meadows looked beautiful. The stork walking about on his long red legs chattered in the Egyptian language, which he had learnt from his mother. The corn-fields and meadows were surrounded by large forests, in the midst of which were deep pools. It was, indeed, delightful to walk about in the country. In a sunny spot stood a pleasant old farm-house close by a deep river, and from the house down to the water side grew great burdock leaves, so high, that under the tallest of them a little child could stand upright. The spot was as wild as the centre of a thick wood. In this snug retreat sat a duck on her nest, watching for her young brood to hatch; she was beginning to get tired of her task, for the little ones were a long time coming out of their shells, and she seldom had any visitors. The other ducks liked much better to swim about in the river than to climb the slippery banks, and sit under a burdock leaf, to have a gossip with her.
|
||||
@@ -0,0 +1,29 @@
|
||||
language = 日本語
|
||||
plural = 0
|
||||
locale.title = 醜い家鴨の子
|
||||
locale.author = ハンス・クリスチャン・アンデルゼン
|
||||
locale.source = 菊池寛訳(『小学生全集 第五巻 アンデルゼン童話集』興文社・文藝春秋社、1928年)。テキストは青空文庫より。
|
||||
locale.formats = 書式
|
||||
locale.date = 日付
|
||||
locale.time = 時刻
|
||||
locale.number = 数値
|
||||
locale.money = 金額
|
||||
locale.plural = 複数形
|
||||
locale.count = 家鴨の子{n}羽
|
||||
number.decimal = .
|
||||
number.group = ,
|
||||
number.group.min = 1
|
||||
money = {s}{n}
|
||||
money.USD = $
|
||||
money.JPY = ¥
|
||||
money.JPY.digits = 0
|
||||
date.short = y/MM/dd
|
||||
date.long = y年M月d日
|
||||
date.full = y年M月d日EEEE
|
||||
time.short = H:mm
|
||||
time.ampm = 午前 | 午後
|
||||
date.months = 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月
|
||||
date.months.short = 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月
|
||||
date.days = 日曜日 | 月曜日 | 火曜日 | 水曜日 | 木曜日 | 金曜日 | 土曜日
|
||||
date.days.short = 日 | 月 | 火 | 水 | 木 | 金 | 土
|
||||
locale.story = それは田舎の夏のいいお天気の日の事でした。もう黄金色になった小麦や、まだ青い燕麦や、牧場に積み上げられた乾草堆など、みんなきれいな眺めに見える日でした。こうのとりは長い赤い脚で歩きまわりながら、母親から教わった妙な言葉でお喋りをしていました。\n 麦畑と牧場とは大きな森に囲まれ、その真ん中が深い水溜りになっています。全く、こういう田舎を散歩するのは愉快な事でした。\n その中でも殊に日当りのいい場所に、川近く、気持のいい古い百姓家が立っていました。そしてその家からずっと水際の辺りまで、大きな牛蒡の葉が茂っているのです。それは実際ずいぶん丈が高くて、その一番高いのなどは、下に子供がそっくり隠れる事が出来るくらいでした。人気がまるで無くて、全く深い林の中みたいです。この工合のいい隠れ場に一羽の家鴨がその時巣について卵がかえるのを守っていました。けれども、もうだいぶ時間が経っているのに卵はいっこう殻の破れる気配もありませんし、訪ねてくれる仲間もあまりないので、この家鴨は、そろそろ退屈しかけて来ました。他の家鴨達は、こんな、足の滑りそうな土堤を上って、牛蒡の葉の下に坐って、この親家鴨とお喋りするより、川で泳ぎ廻る方がよっぽど面白いのです。
|
||||
@@ -0,0 +1,27 @@
|
||||
language = Polski
|
||||
plural = n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2
|
||||
locale.title = Brzydkie kaczątko
|
||||
locale.author = Hans Christian Andersen
|
||||
locale.source = Przekład Cecylii Niewiadomskiej. Baśnie, Gebethner i Wolff, 1899. Domena publiczna; tekst z Wikiźródeł.
|
||||
locale.formats = Formaty
|
||||
locale.date = Data
|
||||
locale.time = Godzina
|
||||
locale.number = Liczba
|
||||
locale.money = Kwota
|
||||
locale.plural = Liczba mnoga
|
||||
locale.count = {n} kaczątko | {n} kaczątka | {n} kacząt
|
||||
number.decimal = ,
|
||||
number.group =
|
||||
number.group.min = 2
|
||||
money = {n} {s}
|
||||
money.PLN = zł
|
||||
money.JPY.digits = 0
|
||||
date.short = d.MM.y
|
||||
date.long = d MMMM y
|
||||
date.full = EEEE, d MMMM y
|
||||
time.short = HH:mm
|
||||
date.months = stycznia | lutego | marca | kwietnia | maja | czerwca | lipca | sierpnia | września | października | listopada | grudnia
|
||||
date.months.short = sty | lut | mar | kwi | maj | cze | lip | sie | wrz | paź | lis | gru
|
||||
date.days = niedziela | poniedziałek | wtorek | środa | czwartek | piątek | sobota
|
||||
date.days.short = niedz. | pon. | wt. | śr. | czw. | pt. | sob.
|
||||
locale.story = Prześlicznie było na wsi. Lato gorące, pogodne, żółte zboża na polach, owies jeszcze zielony, na łąkach wielkie stogi pachnącego siana, a bociany przechadzają się powoli na wysokich czerwonych nogach i klekocą po egipsku, bo takim językiem nauczyły się mówić od matek. Dokoła wielkie lasy, cieniste, szumiące, a w nich głębokie i ciche jeziora. Prześlicznie i cudownie było na wsi.\nNa pochyłości wzgórza jasne słońce oświetlało stary zamek z wieżycami i gankami, otoczony murem i szeroką wstęgą wolno płynącej wody. Z muru zwieszały się pnące rośliny, a wielkie liście łopianu schylały się aż do wody. I było pod nimi cicho i ciemno, jak w cienistym lesie. Pod jednym z takich liści młoda kaczka usłała sobie gniazdo i siedziała na jajach. Nudziło jej się bardzo, bo żadna z sąsiadek nie miała chęci w tak piękną pogodę rozmawiać z nią o tem, co słychać na świecie. Każda wolała pływać po przejrzystej wodzie, pluskać się i osuszać na ciepłem słoneczku, a ona tylko jedna, jak przykuta siedzi w cieniu na gnieździe.
|
||||
@@ -45,5 +45,5 @@
|
||||
<text x="1377.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">KMP</text>
|
||||
<line x1="785" y1="452.5" x2="1440" y2="452.5" stroke="#4a4a4a" stroke-width="1"/>
|
||||
<text x="40" y="562" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" fill="#b9b9b9">Drawing 64 rotating boxes at 60 fps in an 800×600 window. Lower is better in both panels.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Three Reaktor configurations against the alternatives from other tech stacks, on the same machine — details in benchmarks/README.md.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Three Reaktor configurations against the alternatives from other tech stacks, on the same machine — details in benchmarks/BENCHMARKS.md.</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
@@ -0,0 +1,139 @@
|
||||
# Benchmarks
|
||||
|
||||
Five UI stacks draw the same animation, and one script measures each of them
|
||||
from outside its process. The results are the chart in
|
||||
[`docs/PERFORMANCE.md`](../docs/PERFORMANCE.md).
|
||||
|
||||
| Arm | Directory | Built with |
|
||||
| --- | --- | --- |
|
||||
| Reaktor | `samples/bench/` | `build.ps1` / `build.sh` |
|
||||
| Electron | `electron-bench/` | npm |
|
||||
| Flutter | `flutter-bench/` | Flutter SDK |
|
||||
| Compose Multiplatform | `kmp-bench/` | Gradle |
|
||||
| Shaft | `shaft-bench/` | SwiftPM, macOS only — [see below](#shaft) |
|
||||
|
||||
## Running it
|
||||
|
||||
```powershell
|
||||
./benchmarks/run.ps1 # every arm, 6 s, 60 fps, 10 runs
|
||||
./benchmarks/run.ps1 -Targets electron,kmp -Runs 3
|
||||
./benchmarks/run.ps1 -Csv bars.csv
|
||||
```
|
||||
|
||||
`run.ps1` also takes `-Seconds`, `-Fps` and `-Boxes`. `run.sh` does the same on
|
||||
macOS, Linux and the BSDs, with `--targets`, `--runs`, `--seconds`, `--fps`,
|
||||
`--boxes` and `--csv`. Nothing is built for you: a missing arm is skipped, and
|
||||
the script prints the command that builds it.
|
||||
|
||||
Reaktor runs three times: `reaktor-software`, the renderer it ships with, and
|
||||
`reaktor-d3d11` and `reaktor-opengl`, the same binary on SDL's GPU drivers
|
||||
(`run.sh` also offers `reaktor-metal` on macOS). The other frameworks draw on
|
||||
the GPU, so those two are the like-for-like comparison.
|
||||
|
||||
## What every arm draws
|
||||
|
||||
- An **800×600** drawing area, not counting the window frame.
|
||||
- A **#f7f7f7** background, Reaktor's light theme.
|
||||
- **64 quads**, each spinning around its own center. For box `i`, in a `w`×`h`
|
||||
area, `t` seconds after the first frame:
|
||||
|
||||
```
|
||||
a = t * (1 + 0.05 * i)
|
||||
cx = (i % 8) * (w / 8) + w / 16
|
||||
cy = (i / 8) * (h / 8) + h / 16
|
||||
r = h / 24
|
||||
vertex k = (cx + r * cos(a + k * pi/2), cy + r * sin(a + k * pi/2))
|
||||
fill = rgb(60 + (i * 3) % 190, 140, 220)
|
||||
```
|
||||
|
||||
The divisions are integer divisions, as in `bench.c`, which every other arm
|
||||
was written from.
|
||||
- Antialiasing at each framework's default, which is on in all of them.
|
||||
|
||||
Every arm takes `--bench-seconds N`, `--fps F` (`0` for uncapped) and
|
||||
`--boxes N`, and prints `key value` lines as it quits. `size` has to read
|
||||
`800x600` or the run isn't comparable, and `fps` shows whether the rate held.
|
||||
Some arms also print `ms_per_frame`, but each framework times a different part
|
||||
of the frame, so only the script's numbers compare across arms.
|
||||
|
||||
## How it measures
|
||||
|
||||
Every 100 ms the script samples the whole process tree: the peak of its summed
|
||||
memory, and the processor time charged to it. That puts Electron's five
|
||||
processes and a JVM on the same footing as one C executable. CPU comes out two
|
||||
ways — `CpuCore`, a percent of one core, and `CpuMachine`, the same time over
|
||||
every logical processor — and each figure is the median of all runs.
|
||||
|
||||
- **Keep runs at 6 seconds.** Startup counts, and some arms pay far more for it:
|
||||
at 3 seconds Electron reads 45.5% of a core instead of 37.5%.
|
||||
- **The two scripts read memory differently.** `run.ps1` uses private bytes;
|
||||
`run.sh` uses resident set size, which counts a shared page against every
|
||||
process using it and so inflates Electron and the JVM. Compare `run.sh`
|
||||
numbers only with each other. Without `perl` it also times runs to the whole
|
||||
second — enough to see an arm run, not to quote.
|
||||
|
||||
## Building the arms
|
||||
|
||||
Each arm uses its framework's own toolchain; none is vendored here.
|
||||
|
||||
### Electron
|
||||
|
||||
```bash
|
||||
cd benchmarks/electron-bench
|
||||
npm install
|
||||
```
|
||||
|
||||
Needs Node 20.19+ or 22+; older Node fails with `ERR_REQUIRE_ESM`.
|
||||
`--software` turns hardware acceleration off.
|
||||
|
||||
### Flutter
|
||||
|
||||
```powershell
|
||||
cd benchmarks/flutter-bench
|
||||
./setup.ps1
|
||||
flutter build windows --release
|
||||
```
|
||||
|
||||
Only the Dart is checked in. `setup.ps1` generates the Windows runner and
|
||||
patches in the title and an 800×600 client area. The patches are regexes over
|
||||
generated code, so a Flutter release that changes its template can break them;
|
||||
the `size` line will show it.
|
||||
|
||||
### Compose Multiplatform
|
||||
|
||||
```bash
|
||||
cd benchmarks/kmp-bench
|
||||
gradle createDistributable
|
||||
```
|
||||
|
||||
Needs a full JDK 17+ and Gradle 8.7+ — Android Studio's bundled JBR has no
|
||||
`jpackage`. Run the packaged app, not `gradle run`, or the Gradle daemon is
|
||||
measured too. The JVM gets no heap flags.
|
||||
|
||||
### Shaft
|
||||
|
||||
```bash
|
||||
cd benchmarks/shaft-bench
|
||||
swift build -c release
|
||||
```
|
||||
|
||||
It doesn't link on Windows. SwiftSDL3 0.1.6 never compiles its joystick sources
|
||||
there, so `SDL_SetJoystickVirtualButtonInner` is left undefined, and one Swift
|
||||
package can't add sources to another. Until that changes it runs on macOS only
|
||||
and stays out of the chart.
|
||||
|
||||
To get as far as that link on Windows, build from a developer shell
|
||||
(`vcvars64.bat`), and set `GIT_CONFIG_COUNT=1`, `GIT_CONFIG_KEY_0=core.symlinks`
|
||||
and `GIT_CONFIG_VALUE_0=false` so a dependency's symlink doesn't stop the
|
||||
checkout. The `-bench` suffix on every directory is for SwiftPM, which names a
|
||||
package after its directory: `shaft` would collide with Shaft itself.
|
||||
|
||||
## What still isn't equal
|
||||
|
||||
- **The rasterizer.** Reaktor draws on the CPU by default and the others on the
|
||||
GPU. The GPU arms narrow that gap without closing it: SDL's OpenGL renderer
|
||||
isn't Skia.
|
||||
- **Frame pacing.** At `--fps 60` every arm waits out its frame, then asks for
|
||||
exactly one more. Skipping vsyncs that aren't due yet looks simpler and is
|
||||
wrong — the rate drifts to 41.6 fps in Flutter and 42.7 in Compose, which is
|
||||
why every arm prints `fps`.
|
||||
@@ -1,305 +0,0 @@
|
||||
# The comparison
|
||||
|
||||
The chart in `docs/PERFORMANCE.md` used to have five frameworks in it, and only
|
||||
one of them was measured here: Reaktor's bars came from `samples/bench`, and the
|
||||
other four were read off [ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s
|
||||
README, taken on an M1 Max, with no denominator named for the CPU figure.
|
||||
|
||||
This directory is what replaced them. Four projects that draw the same picture
|
||||
the same way, and one script that measures every arm from outside.
|
||||
|
||||
The chart now carries what came out of it, and it is not what it replaced. The
|
||||
memory ordering survived; the CPU ordering did not. Measuring Flutter over
|
||||
twelve threads gives **1.4%** where that README shows 11.4%, which is an
|
||||
eightfold gap in the direction that says their figure was per-core and
|
||||
Reaktor's per-machine — the two plotted in one panel. On one denominator the
|
||||
software rasterizer first came out the most expensive arm on CPU, which is what
|
||||
a CPU rasterizer among GPU ones should be, and measuring where that went found
|
||||
it was not the rasterizing: a panel background was arriving as two textured,
|
||||
blended triangles where a fill would do. `docs/PERFORMANCE.md` has the numbers.
|
||||
It reads 16.4% of a core now, under Flutter.
|
||||
|
||||
Shaft itself is not in the chart: it does not link on Windows, for a reason
|
||||
that is nothing to do with this benchmark. See below.
|
||||
|
||||
## The picture
|
||||
|
||||
Every arm draws this, and nothing else:
|
||||
|
||||
- An **800×600** drawing area — the content, not the window frame. Each arm
|
||||
reads its real surface size and prints it, so a window that came out the
|
||||
wrong size says so instead of quietly drawing a smaller picture.
|
||||
- The area cleared to **#f7f7f7**, which is `--background-body` from the light
|
||||
theme Reaktor loads.
|
||||
- **64 filled quads**, each rotating about its own center. For box `i`, with
|
||||
`w` and `h` the drawing area and `t` seconds since the first frame:
|
||||
|
||||
```
|
||||
a = t * (1 + 0.05 * i)
|
||||
cx = (i % 8) * (w / 8) + w / 16
|
||||
cy = (i / 8) * (h / 8) + h / 16
|
||||
r = h / 24
|
||||
vertex k = (cx + r * cos(a + k * pi/2), cy + r * sin(a + k * pi/2))
|
||||
fill = rgb(60 + (i * 3) % 190, 140, 220)
|
||||
```
|
||||
|
||||
**Those divisions are integer divisions.** `bench.c` does them in `int`, so a
|
||||
truncated grid step and a truncated radius are part of the picture; an arm
|
||||
that does them in floating point draws its boxes somewhere else.
|
||||
|
||||
- Antialiasing left at each framework's default, which is on for all five.
|
||||
|
||||
`samples/bench/bench.c` is the original, and the source every arm was
|
||||
transcribed from.
|
||||
|
||||
## The protocol
|
||||
|
||||
Each arm takes the same flags, and no environment variables:
|
||||
|
||||
| Flag | Meaning |
|
||||
| --- | --- |
|
||||
| `--bench-seconds N` | run for N seconds, then print and quit |
|
||||
| `--fps F` | hold the run to F frames a second, sleeping out the rest of each frame. `0` free-runs |
|
||||
| `--boxes N` | how many boxes |
|
||||
|
||||
and prints `key value` lines on stdout before exiting:
|
||||
|
||||
| Key | Every arm | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `size` | yes | the drawing area, `800x600` or the run is not comparable |
|
||||
| `frames` | yes | frames actually drawn |
|
||||
| `fps` | yes | the rate it held |
|
||||
| `ms_per_frame` | no | what one frame cost, **by each framework's own reckoning** |
|
||||
| `cpu_at_60fps` | no | `ms_per_frame` against a 16.67 ms budget |
|
||||
|
||||
`ms_per_frame` is not comparable across arms and the table is deliberate about
|
||||
which arms report it. Reaktor measures build, render and present, because it
|
||||
does all three itself — but with vsync on and `--fps 60` its present absorbs the
|
||||
block, so the figure comes out at the frame period and says nothing about the
|
||||
work. `--no-vsync` is how to read that one; `bench.c` says so at the top. Flutter reports build and raster from
|
||||
`addTimingsCallback`. Electron can only time the script that issues the draw
|
||||
calls — Chromium rasterizes and presents in other processes, and none of that
|
||||
is visible from the page. Compose times its draw pass. Shaft exposes no
|
||||
per-frame accounting at all.
|
||||
|
||||
**So the comparable numbers are the ones taken from outside**, which is what
|
||||
`run.ps1` exists for.
|
||||
|
||||
## Measuring
|
||||
|
||||
```powershell
|
||||
./benchmarks/run.ps1 # all arms, 6 s, 60 fps, 10 runs
|
||||
./benchmarks/run.ps1 -Targets electron,kmp -Runs 3
|
||||
./benchmarks/run.ps1 -Csv bars.csv
|
||||
```
|
||||
|
||||
```sh
|
||||
./benchmarks/run.sh # the same, on macOS, Linux and the BSDs
|
||||
./benchmarks/run.sh --targets electron,kmp --runs 3
|
||||
./benchmarks/run.sh --csv bars.csv
|
||||
```
|
||||
|
||||
For each run either script samples the **whole process tree** every 100 ms and
|
||||
keeps the peak of summed memory and the total processor time each process was
|
||||
charged. That is the only honest way to hold Electron — five processes — and a
|
||||
JVM against a single C executable: a framework's own opinion of its memory is
|
||||
its allocator's, not the system's.
|
||||
|
||||
It reports CPU twice, because the Shaft README's figure names no denominator
|
||||
and the two readings differ by the core count:
|
||||
|
||||
- **`CpuCore`** — percent of one core, which is what `bench` prints.
|
||||
- **`CpuMachine`** — the same time over every logical processor.
|
||||
|
||||
The median of `-Runs` — `--runs` — runs is the answer; a single reading
|
||||
against a single reading means nothing on Windows.
|
||||
|
||||
**Do not shorten `-Seconds` and compare across lengths.** Startup is inside the
|
||||
measurement, and the arms that pay most for it pay it once: at three seconds
|
||||
rather than six, Electron reads 45.5% of a core instead of 37.5% and Compose
|
||||
60.7% instead of 50.3%, while Reaktor does not move. Six seconds is the
|
||||
default for that reason.
|
||||
|
||||
Reaktor appears three times on purpose. `reaktor-software` is the default CPU
|
||||
rasterizer and the one it ships; `reaktor-d3d11` and `reaktor-opengl` are the
|
||||
same binary on the two GPU drivers SDL offers here, which is where the other
|
||||
arms draw. `run.sh` names that second one for the platform it is on: it offers
|
||||
`reaktor-metal` on macOS and `reaktor-opengl` everywhere. Comparing like with
|
||||
like means one of those two, and the spread between all three is the cost of
|
||||
the default rather than a cost of the framework.
|
||||
|
||||
Neither script builds anything. An arm whose artifact is missing is skipped,
|
||||
with the command that would produce it.
|
||||
|
||||
**The two samplers do not read the same memory.** `run.ps1` asks Windows for
|
||||
private bytes. `run.sh` has nothing to ask: it takes resident set size, out of
|
||||
`/proc` on Linux and out of `ps` everywhere else, and RSS charges a page that
|
||||
two processes share to both of them. The arms that pay for that are exactly
|
||||
the ones the tree walk exists for — Electron's five processes and the JVM.
|
||||
So a `run.sh` figure belongs beside other `run.sh` figures and nowhere else,
|
||||
and `docs/PERFORMANCE.md`'s bars are a `run.ps1` run.
|
||||
|
||||
Processor time is the same reading in both, to a rounding: `run.sh` reads
|
||||
`utime + stime` out of `/proc/<pid>/stat` on Linux, because Linux's `ps`
|
||||
rounds `TIME` to the whole second and a six second run cannot carry that.
|
||||
Elsewhere `ps` reports hundredths and is taken as it comes.
|
||||
|
||||
Wall time wants better than a second as well, and `date` has no portable way
|
||||
to give it, so `run.sh` reads the clock through `perl`'s `Time::HiRes`. Without
|
||||
perl on `PATH` it says so and falls back to whole seconds, which is enough to
|
||||
see an arm run and not enough to quote.
|
||||
|
||||
## Building the arms
|
||||
|
||||
Each toolchain is the framework's own, and none of them is vendored here.
|
||||
Every arm's directory carries a `-bench` suffix, because one of them has to:
|
||||
SwiftPM takes a root package's identity from its directory name, so a Swift
|
||||
package called `shaft` collides with the `Shaft` dependency it pulls in. The
|
||||
other three could have been named for the framework alone, and are not, so the
|
||||
listing reads the same way down its whole length.
|
||||
|
||||
### Electron — `electron-bench/`
|
||||
|
||||
```bash
|
||||
cd benchmarks/electron-bench
|
||||
npm install
|
||||
```
|
||||
|
||||
Needs **Node 20.19+ or 22+**: Electron's installer is an ES module, and older
|
||||
Node cannot `require` it, which fails as `ERR_REQUIRE_ESM` during the install
|
||||
rather than as anything about versions. The artifact is
|
||||
`node_modules/electron/dist/electron.exe`, which `run.ps1` launches directly
|
||||
rather than through `npm start`, so no shell sits in the process tree.
|
||||
|
||||
`--software` turns Chromium's hardware acceleration off, for a run against
|
||||
Reaktor's default rasterizer rather than against `reaktor-d3d11`.
|
||||
|
||||
### Flutter — `flutter-bench/`
|
||||
|
||||
```powershell
|
||||
cd benchmarks/flutter-bench
|
||||
./setup.ps1
|
||||
flutter build windows --release
|
||||
```
|
||||
|
||||
The Dart is checked in; the Windows runner is not, because `flutter create`
|
||||
writes it. `setup.ps1` generates it and patches the window size in
|
||||
`windows/runner/main.cpp`, which is the only place a Flutter desktop app's
|
||||
size is decided. It patches the window title in the same file and for the same
|
||||
reason: `flutter create` names the window after the package, so this arm comes
|
||||
up called `reaktor_bench` while every other one names the framework that is
|
||||
drawing. `setup.ps1` retitles it **Flutter**.
|
||||
|
||||
That size is the **outer window**, and the client area is what gets drawn, so
|
||||
`setup.ps1` also grows the rect by the window frame in `win32_window.cpp`. Both
|
||||
patches are regexes against a generated file, so both can miss on a Flutter
|
||||
version that reshuffles the template — which is what the `size` line in the
|
||||
output and the warning from `run.ps1` are for.
|
||||
|
||||
### Shaft — `shaft-bench/`
|
||||
|
||||
```bash
|
||||
cd benchmarks/shaft-bench
|
||||
swift build -c release
|
||||
```
|
||||
|
||||
The `-bench` suffix is load-bearing on this one. A root package in a directory
|
||||
called `shaft` takes `shaft` as its identity and collides with the `Shaft`
|
||||
dependency itself — *cyclic dependency between packages ShaftBench ->
|
||||
ShaftBench*.
|
||||
|
||||
**It does not link on Windows.** Not for the reasons you would guess: Shaft's
|
||||
Skia bundle does ship `windows-x64`, and Shaft links D3D12 and DXGI for
|
||||
Windows. Everything compiles — 205 objects, Skia, and this benchmark's own
|
||||
Swift. Then SwiftSDL3 0.1.6 turns out never to compile its `joystick/virtual/`,
|
||||
`joystick/hidapi/` or `joystick/windows/` directories there — its Windows source
|
||||
list also names `src/gpu/d3d11` and `src/render/SDL_d3dmath.c`, neither of which
|
||||
exists in the SDL it vendors — so `SDL_joystick.c` references
|
||||
`SDL_SetJoystickVirtualButtonInner` and nothing defines it. There is no fix from
|
||||
this side: a package cannot add sources to another package's target, and
|
||||
dependencies here are read as they ship.
|
||||
|
||||
Two other things stop it before that, and neither is Shaft's. Both have fixes,
|
||||
so the build now reaches the link from an ordinary user account:
|
||||
|
||||
- **A developer shell.** `swift build` from a plain prompt does not reach
|
||||
dependency resolution at all — it fails compiling the manifest, with
|
||||
*lld-link: could not open 'msvcrt.lib'*. Run `vcvars64.bat` first.
|
||||
- **git told not to attempt symlinks**, through the environment rather than
|
||||
through config:
|
||||
|
||||
```bat
|
||||
set GIT_CONFIG_COUNT=1
|
||||
set GIT_CONFIG_KEY_0=core.symlinks
|
||||
set GIT_CONFIG_VALUE_0=false
|
||||
```
|
||||
|
||||
git reads those above any config file, which is the point: SwiftPM appends
|
||||
`symlinks = true` to every repository it clones, after the `false` git wrote
|
||||
itself, and the last value in the file wins. The environment outranks the
|
||||
file, so SwiftPM cannot append its way past it. Developer Mode or an elevated
|
||||
shell also work and need no environment; this is the version that needs
|
||||
neither.
|
||||
|
||||
Two things it did need, which are fixed and are not that:
|
||||
|
||||
- `dxguid` and `dinput8` in this package's `linkerSettings`. SwiftSDL3 compiles
|
||||
its DirectInput haptic code on Windows without linking the library its GUIDs
|
||||
live in.
|
||||
- Symlinks. One of Shaft's dependencies ships one — currently Rainbow, on its
|
||||
`AGENTS.md` — and creating it is what fails, as *unable to create symlink
|
||||
AGENTS.md: Permission denied*. A global `core.symlinks false` does not help,
|
||||
for the reason above: SwiftPM's per-repository `true` is written later and
|
||||
wins. The environment variables above are what actually settles it.
|
||||
|
||||
Past those two, the build compiles everything — Skia, SwiftSDL3, and this
|
||||
benchmark's own Swift, 25 of 26 steps — and stops at `[26/26] Linking
|
||||
ShaftBench.exe` with the undefined joystick symbols above. That is reproducible
|
||||
today, on Swift 6.3.3, from a non-elevated shell.
|
||||
|
||||
So this arm runs on the macOS its own published figures came from, and its
|
||||
numbers stay out of `docs/PERFORMANCE.md` until it runs here.
|
||||
|
||||
### Kotlin Multiplatform — `kmp-bench/`
|
||||
|
||||
```bash
|
||||
cd benchmarks/kmp-bench
|
||||
gradle createDistributable
|
||||
```
|
||||
|
||||
Compose Multiplatform on the desktop target: Skia through Skiko, on a JVM.
|
||||
Needs **JDK 17+ and Gradle 8.7+**; no wrapper is checked in, because a wrapper
|
||||
is a binary. The JDK has to be a real one: Android Studio's bundled JBR is 17
|
||||
but ships no `jpackage`, and the build stops at `checkRuntime` saying so.
|
||||
|
||||
No toolchain version is pinned in `build.gradle.kts`. The JDK that runs Gradle
|
||||
is the one that compiles this and the one jpackage bundles, so pinning would
|
||||
send Gradle hunting for an exact version on a machine that has a later one.
|
||||
|
||||
Run the packaged distributable rather than `gradle run`, or the Gradle daemon
|
||||
becomes the app's parent process and the sampler charges the run for it.
|
||||
|
||||
The JVM gets no heap flags. What this arm costs out of the box is the thing
|
||||
worth knowing, and a hand-sized heap is a thumb on the memory bar.
|
||||
|
||||
## What is still not equal
|
||||
|
||||
- **The machine.** These five now share a procedure, not a history. Nothing
|
||||
here makes Shaft's published M1 Max figures comparable to a run on your
|
||||
desk — it makes a fresh run of all five comparable to each other.
|
||||
- **The rasterizer.** Reaktor draws on the CPU by default and the others do
|
||||
not. `reaktor-d3d11`, `reaktor-opengl` and `electron --software` are the ways
|
||||
to close that, and none of them closes it completely — SDL's GL path is not
|
||||
Skia's, and Chromium without hardware acceleration is not SDL's software
|
||||
rasterizer either.
|
||||
- **The frame each one is holding to.** At `--fps 60` every arm sleeps out the
|
||||
rest of its frame, and they now sleep the same way on purpose: wait, then ask
|
||||
for exactly one frame. Reaktor sleeps with `SDL_DelayNS`, Electron with a
|
||||
timer before a `requestAnimationFrame`, Flutter with a `Timer` before a
|
||||
`scheduleFrame`, Compose with `delay` before a `withFrameNanos`.
|
||||
|
||||
The other way — letting the vsyncs that are not due pass without drawing —
|
||||
reads as the obvious one and is wrong. It held **41.6 fps in Flutter and 42.7
|
||||
in Compose** instead of 60, because a repaint asked for inside a vsync
|
||||
callback lands on the next vsync and the count drifts. Both were caught by
|
||||
the `fps` line, which is the reason every arm prints one.
|
||||
@@ -1,11 +1,3 @@
|
||||
/* The picture, in canvas 2D. Every constant here is read off
|
||||
* samples/bench/bench.c, including the integer divisions - the grid step and
|
||||
* the radius are truncated there, so they are truncated here too, or the boxes
|
||||
* land a pixel off and the two arms are not drawing the same thing.
|
||||
*
|
||||
* The grid comes off the real drawing area rather than a hardcoded 800x600,
|
||||
* the way bench.c takes win_w and win_h, and the size is printed so a window
|
||||
* that came out the wrong size says so instead of quietly drawing smaller. */
|
||||
'use strict'
|
||||
|
||||
const params = new URLSearchParams(location.search)
|
||||
@@ -72,9 +64,6 @@ function draw(now) {
|
||||
schedule()
|
||||
}
|
||||
|
||||
/* Held to a rate, the wait is a timer and the frame still lands on a vsync.
|
||||
* Free-running, requestAnimationFrame is the vsync and the rate is the
|
||||
* display's - Chromium has no way to be asked for more. */
|
||||
function schedule() {
|
||||
if (FPS <= 0) { requestAnimationFrame(draw); return }
|
||||
|
||||
@@ -84,10 +73,6 @@ function schedule() {
|
||||
else { due = performance.now(); requestAnimationFrame(draw) }
|
||||
}
|
||||
|
||||
/* ms_per_frame is the drawing this script is charged for and nothing else:
|
||||
* Chromium rasterizes and presents on other threads in other processes, and
|
||||
* none of that is visible from here. The comparable number for this arm is
|
||||
* the one the sampler in run.ps1 takes from outside. */
|
||||
function report(elapsed_ms) {
|
||||
window.bench.report({
|
||||
size: W + 'x' + H,
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
/* The rotating boxes of samples/bench/bench.c, drawn by Electron.
|
||||
*
|
||||
* The window is the content area, not the frame: 800x600 of canvas, the same
|
||||
* picture the other four arms draw. The renderer does the drawing and hands
|
||||
* its counters back over IPC; this process prints them and exits, so the
|
||||
* stdout block matches what bench.exe prints. */
|
||||
'use strict'
|
||||
|
||||
const { app, BrowserWindow, ipcMain } = require('electron')
|
||||
@@ -20,8 +14,6 @@ const seconds = flag('--bench-seconds', '5')
|
||||
const fps = flag('--fps', '0')
|
||||
const boxes = flag('--boxes', '64')
|
||||
|
||||
/* Reaktor's default renderer is the CPU one. Chromium's is not, and this is
|
||||
* the only switch that brings the two arms onto the same rasterizer. */
|
||||
if (argv.indexOf('--software') >= 0) app.disableHardwareAcceleration()
|
||||
|
||||
app.whenReady().then(() => {
|
||||
@@ -34,8 +26,6 @@ app.whenReady().then(() => {
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
/* Off, or Chromium quietly stops painting an unfocused window and
|
||||
* the run measures a sleeping process. */
|
||||
backgroundThrottling: false
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,19 +1,3 @@
|
||||
// The rotating boxes of samples/bench/bench.c, drawn by Flutter.
|
||||
//
|
||||
// No Material, no theme, no scaffolding: one CustomPaint over the window, so
|
||||
// what a frame costs is the drawing and not a widget tree neither of the other
|
||||
// arms has.
|
||||
//
|
||||
// The per-frame split comes from addTimingsCallback, which is the one place
|
||||
// Flutter reports what a frame cost after it happened - buildDuration is the
|
||||
// widget and layout pass, rasterDuration is the raster thread. Their sum is
|
||||
// what bench.c calls ms_per_frame.
|
||||
//
|
||||
// A Ticker is the obvious way to drive this and the wrong one. Letting the
|
||||
// vsyncs that are not due pass without repainting held 41.6 fps rather than
|
||||
// 60, because a repaint asked for inside a vsync callback lands on the next
|
||||
// one and the count drifts. So the wait is a timer, the way bench.c sleeps out
|
||||
// the rest of its frame: sleep, then ask for exactly one frame.
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
@@ -28,8 +12,6 @@ late final double _seconds;
|
||||
late final double _fps;
|
||||
late final int _boxes;
|
||||
|
||||
// The size the run was actually drawn at. The window is sized by the platform
|
||||
// runner, not by anything here, so it is reported rather than assumed.
|
||||
Size _painted = Size.zero;
|
||||
|
||||
double _flag(List<String> args, String name, double fallback) {
|
||||
@@ -76,8 +58,6 @@ class _BenchState extends State<_Bench> {
|
||||
}
|
||||
}
|
||||
|
||||
// Moving the notifier is what asks for a frame; the callback below is what
|
||||
// finds out it happened.
|
||||
void _tick() {
|
||||
if (_done) return;
|
||||
if (!_clock.isRunning) _clock.start();
|
||||
@@ -115,8 +95,6 @@ class _BenchState extends State<_Bench> {
|
||||
void _finish(double elapsed) {
|
||||
_done = true;
|
||||
|
||||
// The timings for the last frames have not been reported yet; they arrive
|
||||
// a frame or two later. Nothing is being drawn in the meantime.
|
||||
Future<void>.delayed(const Duration(milliseconds: 300), () {
|
||||
final double perFrame = (_buildMs + _rasterMs) / _frames;
|
||||
|
||||
@@ -157,8 +135,6 @@ class _BoxPainter extends CustomPainter {
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final double t = time.value;
|
||||
|
||||
// The integer divisions are bench.c's, kept integer here for the same
|
||||
// reason: a truncated grid step is part of the picture.
|
||||
final int w = size.width.toInt();
|
||||
final int h = size.height.toInt();
|
||||
final int stepX = w ~/ 8;
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
# Generates the platform runner for the Flutter arm and sizes its window to the
|
||||
# 800x600 the other four draw into.
|
||||
#
|
||||
# The runner is not checked in: `flutter create` writes it, and the size lives
|
||||
# in its C++ rather than in any Dart this benchmark controls. So the size is a
|
||||
# patch applied after the generation, and re-running this is harmless.
|
||||
param([string]$Platform = "windows")
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -14,8 +8,6 @@ if (-not (Get-Command flutter -ErrorAction SilentlyContinue)) {
|
||||
throw "flutter is not on PATH"
|
||||
}
|
||||
|
||||
# `flutter create` regenerates a project's scaffolding, and the benchmark is
|
||||
# scaffolding-shaped: one main.dart. Keep a copy rather than find out.
|
||||
$saved = Get-Content $dart -Raw
|
||||
|
||||
& flutter create --platforms=$Platform --project-name reaktor_bench $here
|
||||
@@ -42,10 +34,6 @@ if ($text -notmatch 'Win32Window::Size\s+size\([^)]*\);') {
|
||||
$sized = [regex]::Replace($text, 'Win32Window::Size\s+size\([^)]*\);',
|
||||
'Win32Window::Size size(800, 600);')
|
||||
|
||||
# `flutter create` titles the window after the package, so this one comes out
|
||||
# called reaktor_bench. Every other arm names the framework that is drawing -
|
||||
# Reaktor, Electron, Kotlin Multiplatform - and a shot of the five is
|
||||
# unreadable if one of them names the benchmark instead.
|
||||
if ($sized -notmatch 'window\.Create\(L"[^"]*",') {
|
||||
throw "could not find the window title in $main"
|
||||
}
|
||||
@@ -55,10 +43,6 @@ Set-Content -Path $main -Value $sized -NoNewline
|
||||
|
||||
Write-Host "window sized to 800x600 and titled Flutter in windows\runner\main.cpp"
|
||||
|
||||
# That size is the outer window: the template hands it straight to CreateWindow,
|
||||
# which leaves a client area smaller by the frame, and the client area is what
|
||||
# gets drawn. Growing the rect by the frame is the whole fix, and it is done by
|
||||
# patching rather than by asking, because Flutter has no API for it.
|
||||
$win32 = Join-Path $here "windows\runner\win32_window.cpp"
|
||||
$adjusted = $false
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Compose Multiplatform on the desktop target, which is what the published
|
||||
// comparison means by Kotlin Multiplatform: Skia through Skiko, on a JVM.
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.20"
|
||||
id("org.jetbrains.kotlin.plugin.compose") version "2.4.20"
|
||||
@@ -16,18 +14,10 @@ dependencies {
|
||||
implementation(compose.desktop.currentOs)
|
||||
}
|
||||
|
||||
// No toolchain is pinned. The JDK that runs Gradle is the one that compiles
|
||||
// this and the one jpackage bundles into the distributable, so the arm is
|
||||
// measured on the JVM the machine actually has - 17 or newer, which is what
|
||||
// Compose needs. Pinning a version here would send Gradle looking for that
|
||||
// exact JDK and fail on a machine that has a later one.
|
||||
|
||||
compose.desktop {
|
||||
application {
|
||||
mainClass = "MainKt"
|
||||
|
||||
// No heap flags. A JVM sized by hand is a thumb on the memory bar,
|
||||
// and what this arm costs out of the box is the thing worth knowing.
|
||||
nativeDistributions {
|
||||
packageName = "reaktor-bench-kmp"
|
||||
packageVersion = "1.0.0"
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
// The rotating boxes of samples/bench/bench.c, drawn by Compose Multiplatform.
|
||||
//
|
||||
// Compose on the desktop is Skia through Skiko inside a Swing window. Two
|
||||
// things about that window had to be found out by running it rather than by
|
||||
// reading about it:
|
||||
//
|
||||
// A WindowState size is the frame, and asking for 800x600 that way draws into
|
||||
// 784x561. So the size is declared by the content instead - the canvas asks
|
||||
// for exactly 800x600 device pixels, converted through the current density so
|
||||
// a scaled display does not quietly change the picture, and the window packs
|
||||
// around it.
|
||||
//
|
||||
// And withFrameNanos is not a rate to sleep in. Skipping the vsyncs that are
|
||||
// not due held 42.7 fps rather than 60, because the state written inside the
|
||||
// callback is drawn a frame later and the loop re-registers after that. So the
|
||||
// wait is an explicit delay, the way bench.c sleeps out the rest of its frame,
|
||||
// and withFrameNanos is asked for one frame once the wait is over.
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -42,9 +25,6 @@ private const val W = 800
|
||||
private const val H = 600
|
||||
private val BACKGROUND = Color(0xFFF7F7F7)
|
||||
|
||||
// Written by the draw pass, read by the report. The drawing happens on the
|
||||
// composition's thread and the report is posted from the frame loop, so the
|
||||
// counters are atomic rather than plain.
|
||||
private val drawNanos = AtomicLong()
|
||||
private val paintedWidth = AtomicLong()
|
||||
private val paintedHeight = AtomicLong()
|
||||
@@ -63,8 +43,6 @@ fun main(args: Array<String>) {
|
||||
application {
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
// Unspecified, so the window packs around what the content asks
|
||||
// for rather than deducting its frame from what it was told.
|
||||
state = rememberWindowState(size = DpSize.Unspecified),
|
||||
resizable = false,
|
||||
title = "Kotlin Multiplatform",
|
||||
@@ -86,9 +64,6 @@ private fun Bench(seconds: Double, fps: Double, boxes: Int) {
|
||||
var frames = 0
|
||||
|
||||
while (true) {
|
||||
// Held to a rate, the wait is an explicit sleep rather than a
|
||||
// vsync block, so the run is charged for the drawing and not the
|
||||
// wait.
|
||||
if (period > 0 && due > 0) {
|
||||
val waitMs = (due - System.nanoTime()) / 1_000_000
|
||||
if (waitMs > 0) delay(waitMs)
|
||||
@@ -131,8 +106,6 @@ private fun Bench(seconds: Double, fps: Double, boxes: Int) {
|
||||
val began = System.nanoTime()
|
||||
val t = time
|
||||
|
||||
// The integer divisions are bench.c's, kept integer here for the same
|
||||
// reason: a truncated grid step is part of the picture.
|
||||
val w = size.width.toInt()
|
||||
val h = size.height.toInt()
|
||||
val stepX = w / 8
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
# Runs the arms of the comparison and measures them all the same way.
|
||||
#
|
||||
# The frame counters come from each app's own stdout. Memory and CPU do not:
|
||||
# they are sampled from outside, over the whole process tree, because Electron
|
||||
# is five processes and a JVM's idea of its own memory is not the operating
|
||||
# system's. One sampler for all five is the only way the bars mean anything
|
||||
# against each other.
|
||||
#
|
||||
# Nothing is built here. Each arm points at an artifact that its own toolchain
|
||||
# produces, and an arm whose artifact is missing is skipped with the command
|
||||
# that would make it.
|
||||
param(
|
||||
[string[]] $Targets = @("reaktor-software", "reaktor-d3d11",
|
||||
"reaktor-opengl", "shaft", "flutter", "electron",
|
||||
@@ -49,7 +38,7 @@ function Get-Arm([string]$name) {
|
||||
@{ exe = Join-Path $here "shaft-bench\.build\release\ShaftBench.exe"
|
||||
args = @()
|
||||
dir = Join-Path $here "shaft-bench"
|
||||
make = "swift build -c release (in benchmarks/shaft-bench; macOS - see the README)" }
|
||||
make = "swift build -c release (in benchmarks/shaft-bench; macOS - see BENCHMARKS.md)" }
|
||||
}
|
||||
"flutter" {
|
||||
@{ exe = Join-Path $here "flutter-bench\build\windows\x64\runner\Release\reaktor_bench.exe"
|
||||
@@ -73,8 +62,6 @@ function Get-Arm([string]$name) {
|
||||
}
|
||||
}
|
||||
|
||||
# Every descendant of a process, so Electron's renderer and GPU children are
|
||||
# counted and a launcher's children are not left out.
|
||||
function Get-ProcessTree([int]$rootId) {
|
||||
$byParent = @{}
|
||||
foreach ($p in Get-CimInstance Win32_Process -Property ProcessId, ParentProcessId) {
|
||||
@@ -103,8 +90,6 @@ function Invoke-Arm($spec, [string[]]$argv) {
|
||||
|
||||
$proc = Start-Process -FilePath $spec.exe -ArgumentList ($spec.args + $argv) -WorkingDirectory $spec.dir -PassThru -RedirectStandardOutput $out -RedirectStandardError $err
|
||||
|
||||
# CPU is kept per process id rather than summed live: a child that exits
|
||||
# mid-run still spent what it spent, and the last reading it gave is it.
|
||||
$cpuMs = @{}
|
||||
$peakPrivate = 0L
|
||||
$tree = @($proc.Id)
|
||||
@@ -217,8 +202,6 @@ foreach ($name in $Targets) {
|
||||
Write-Host ""
|
||||
$rows | Format-Table -AutoSize
|
||||
|
||||
# A window that did not come out 800x600 is not drawing the same picture, and
|
||||
# this is the only place that would say so.
|
||||
foreach ($row in $rows) {
|
||||
if ($row.Size -ne "800x600" -and $row.Size -ne "?") {
|
||||
Write-Host ("warning: {0} drew at {1}, not 800x600" -f $row.Arm, $row.Size)
|
||||
|
||||
@@ -1,34 +1,10 @@
|
||||
#!/bin/sh
|
||||
# run.sh - runs the arms of the comparison on macOS, Linux and the BSDs.
|
||||
# run.ps1 is the Windows one, and the two are deliberately the same shape:
|
||||
# the same flags, the same columns, the same medians.
|
||||
#
|
||||
# The frame counters come from each app's own stdout. Memory and CPU do not:
|
||||
# they are sampled from outside, over the whole process tree, because Electron
|
||||
# is five processes and a JVM's idea of its own memory is not the operating
|
||||
# system's.
|
||||
#
|
||||
# Its memory figures are not run.ps1's. That one reads private bytes; this one
|
||||
# reads resident set size, which counts a page two processes share once for
|
||||
# each of them. Electron and the JVM are where that shows. Compare a run of
|
||||
# this against a run of this.
|
||||
#
|
||||
# Nothing is built here. Each arm points at an artifact that its own toolchain
|
||||
# produces, and an arm whose artifact is missing is skipped with the command
|
||||
# that would make it.
|
||||
#
|
||||
# ./run.sh # all arms, 6 s, 60 fps, 10 runs
|
||||
# ./run.sh --targets electron,kmp --runs 3
|
||||
# ./run.sh --csv bars.csv
|
||||
set -eu
|
||||
|
||||
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
root=$(dirname -- "$here")
|
||||
uname_s=$(uname -s)
|
||||
|
||||
# Reaktor appears three times on purpose: the default CPU rasterizer, and the
|
||||
# same binary on the GPU driver the other arms draw on. SDL's name for that
|
||||
# driver is the platform's.
|
||||
case "$uname_s" in
|
||||
Darwin) targets="reaktor-software reaktor-metal reaktor-opengl shaft flutter electron kmp" ;;
|
||||
*) targets="reaktor-software reaktor-opengl shaft flutter electron kmp" ;;
|
||||
@@ -42,7 +18,9 @@ csv=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--help|-h) sed -n '2,22p' "$0" | cut -c 3-; exit 0 ;;
|
||||
--help|-h)
|
||||
echo "usage: run.sh [--targets a,b] [--seconds N] [--fps N] [--boxes N] [--runs N] [--csv FILE]"
|
||||
exit 0 ;;
|
||||
--targets|--seconds|--fps|--boxes|--runs|--csv) ;;
|
||||
*) echo "run.sh: unknown argument: $1 (try --help)" >&2; exit 2 ;;
|
||||
esac
|
||||
@@ -62,9 +40,6 @@ done
|
||||
|
||||
cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The arms. Each one sets arm_exe, arm_args, arm_dir and arm_make.
|
||||
|
||||
arm_spec() {
|
||||
arm_args=""
|
||||
case "$1" in
|
||||
@@ -109,11 +84,6 @@ arm_spec() {
|
||||
esac
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The sampler.
|
||||
|
||||
# A clock finer than a second. The CPU reading divides by it, and whole
|
||||
# seconds over a six second run is more than a percent of error on its own.
|
||||
perl=$(command -v perl 2>/dev/null || true)
|
||||
[ -n "$perl" ] || echo "run.sh: no perl - wall time falls back to whole seconds" >&2
|
||||
|
||||
@@ -125,8 +95,6 @@ now() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Every descendant of a process, so Electron's renderer and GPU children are
|
||||
# counted and a launcher's children are not left out.
|
||||
tree_of() {
|
||||
ps -eo pid=,ppid= | awk -v root="$1" '
|
||||
{ kids[$2] = kids[$2] " " $1 }
|
||||
@@ -145,9 +113,6 @@ tree_of() {
|
||||
clk_tck=$(getconf CLK_TCK 2>/dev/null || echo 100)
|
||||
page_kb=$(( $(getconf PAGESIZE 2>/dev/null || echo 4096) / 1024 ))
|
||||
|
||||
# One reading of the tree, as "pid cpu_seconds rss_kb" lines. Linux answers
|
||||
# out of /proc because its ps rounds processor time to the whole second;
|
||||
# everywhere else ps carries hundredths and is the whole story.
|
||||
sample_tree() {
|
||||
if [ -r /proc/self/stat ]; then
|
||||
for id in $(echo "$1" | tr ',' ' '); do
|
||||
@@ -174,7 +139,6 @@ sample_tree() {
|
||||
fi
|
||||
}
|
||||
|
||||
# The median of a column of a file, ignoring the runs that did not report it.
|
||||
median_of() {
|
||||
awk -v c="$2" '$c != "-" { print $c }' "$1" | sort -n | awk '
|
||||
{ a[NR] = $1 + 0 }
|
||||
@@ -185,9 +149,6 @@ median_of() {
|
||||
}'
|
||||
}
|
||||
|
||||
# Runs one arm once and prints
|
||||
# "mem_mb cpu_core cpu_machine exit size frames ms_per_frame",
|
||||
# with "-" for anything the arm did not report.
|
||||
run_once() {
|
||||
: > "$tmp/samples"
|
||||
|
||||
@@ -200,9 +161,6 @@ run_once() {
|
||||
tree="$pid"
|
||||
ticks=0
|
||||
while kill -0 "$pid" 2>/dev/null; do
|
||||
# The tree is rebuilt every fifth sample. Walking every process on the
|
||||
# machine at 10 Hz would be a measurable share of what is being
|
||||
# measured, and a child appearing half a second late costs nothing.
|
||||
if [ $(( ticks % 5 )) -eq 0 ]; then tree=$(tree_of "$pid"); fi
|
||||
ticks=$(( ticks + 1 ))
|
||||
sample_tree "$tree" | awk -v t="$ticks" '{ print t, $0 }' >> "$tmp/samples"
|
||||
@@ -212,10 +170,6 @@ run_once() {
|
||||
wait "$pid" || status=$?
|
||||
ended=$(now)
|
||||
|
||||
# CPU is kept per process id rather than summed live: a child that exits
|
||||
# mid-run still spent what it spent, and its last reading is it. Memory is
|
||||
# the peak of the readings of a single tick, which is a moment that
|
||||
# actually happened rather than a sum of separate highs.
|
||||
set -- $(awk '
|
||||
{ if ($3 > cpu[$2]) cpu[$2] = $3; rss[$1] += $4 }
|
||||
END {
|
||||
@@ -238,8 +192,6 @@ key() {
|
||||
awk -v k="$1" '$1 == k && NF == 2 { v = $2 } END { print (v == "" ? "-" : v) }' "$tmp/out"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
tmp=$(mktemp -d)
|
||||
trap 'rm -rf "$tmp"' EXIT INT TERM
|
||||
rows="$tmp/rows"
|
||||
@@ -279,8 +231,6 @@ for name in $targets; do
|
||||
|
||||
[ -s "$per_run" ] || continue
|
||||
|
||||
# The median of the runs is the answer; a single reading against a single
|
||||
# reading means nothing.
|
||||
echo "$name $size $(median_of "$per_run" 1) $(median_of "$per_run" 2) \
|
||||
$(median_of "$per_run" 3) $(median_of "$per_run" 4) $(median_of "$per_run" 5) \
|
||||
$(wc -l < "$per_run" | tr -d ' ')" >> "$rows"
|
||||
@@ -294,8 +244,6 @@ while read -r arm size mem core machine frames per_frame count; do
|
||||
"$arm" "$size" "$mem" "$core" "$machine" "$frames" "$per_frame" "$count"
|
||||
done < "$rows"
|
||||
|
||||
# A window that did not come out 800x600 is not drawing the same picture, and
|
||||
# this is the only place that would say so.
|
||||
while read -r arm size rest; do
|
||||
case "$size" in
|
||||
800x600 | \?) ;;
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
// swift-tools-version: 5.9
|
||||
//
|
||||
// The dependency is Shaft's own package, taken from its repository the way its
|
||||
// CounterTemplate takes it. The Cxx interoperability mode and the C++17
|
||||
// standard are not optional: Shaft's default renderer is Skia, and it does not
|
||||
// build without them.
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
@@ -28,9 +23,6 @@ let package = Package(
|
||||
.interoperabilityMode(.Cxx)
|
||||
],
|
||||
|
||||
// SwiftSDL3 compiles its DirectInput haptic code on Windows but
|
||||
// does not link the library the GUIDs live in, so the executable
|
||||
// does it. Nothing on the other platforms needs this.
|
||||
linkerSettings: [
|
||||
.linkedLibrary("dxguid", .when(platforms: [.windows])),
|
||||
.linkedLibrary("dinput8", .when(platforms: [.windows])),
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
// The rotating boxes of samples/bench/bench.c, drawn by Shaft.
|
||||
//
|
||||
// Shaft is Flutter's design in Swift, on SDL3 with Skia, so this is the same
|
||||
// shape as the Flutter arm: one CustomPaint over the window, repainted from a
|
||||
// notifier rather than by rebuilding the tree.
|
||||
//
|
||||
// What it cannot report is a per-frame split. Shaft has no equivalent of
|
||||
// Flutter's timings callback, so this arm prints frames and the rate it held,
|
||||
// and the cost of the run is the one the sampler in run.ps1 takes from
|
||||
// outside - which is the number the comparison uses for every arm anyway.
|
||||
import Foundation
|
||||
import Shaft
|
||||
import ShaftSetup
|
||||
@@ -25,10 +15,6 @@ let benchSeconds = flag("--bench-seconds", 5)
|
||||
let benchFps = flag("--fps", 0)
|
||||
let benchBoxes = Int(flag("--boxes", 64))
|
||||
|
||||
/// The size the run was actually drawn at, written by the painter. The window
|
||||
/// is the backend's to size, so this is reported rather than assumed. Declared
|
||||
/// before the call below because top-level globals run in order and runApp
|
||||
/// does not return.
|
||||
var painted = Size(0, 0)
|
||||
|
||||
ShaftSetup.useDefault()
|
||||
@@ -50,8 +36,6 @@ final class BenchState: State<BenchApp> {
|
||||
override func initState() {
|
||||
super.initState()
|
||||
|
||||
// The view exists by the time the first frame is over, which is the
|
||||
// earliest the window can be given the size the other arms draw at.
|
||||
SchedulerBinding.shared.addPostFrameCallback { [self] _ in
|
||||
if let view = View.maybeOf(context) as? DesktopView {
|
||||
view.size = Size(800, 600)
|
||||
@@ -79,8 +63,6 @@ final class BenchState: State<BenchApp> {
|
||||
return
|
||||
}
|
||||
|
||||
// Held to a rate, the wait is an explicit timer rather than a vsync
|
||||
// block, so the run is charged for the drawing and not the wait.
|
||||
if benchFps > 0 {
|
||||
due = max(due + 1.0 / benchFps, t)
|
||||
let delay = due - t
|
||||
@@ -127,8 +109,6 @@ final class BoxPainter: CustomPainterBase {
|
||||
override func paint(canvas: Canvas, size: Size) {
|
||||
painted = size
|
||||
|
||||
// The integer divisions are bench.c's, kept integer here for the same
|
||||
// reason: a truncated grid step is part of the picture.
|
||||
let w = Int(size.width)
|
||||
let h = Int(size.height)
|
||||
let stepX = w / 8, halfX = w / 16
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
param([switch]$Serve)
|
||||
|
||||
$extra = @($args)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$root = $PSScriptRoot
|
||||
$outDir = Join-Path $root "build-wasm"
|
||||
@@ -30,7 +31,7 @@ $ErrorActionPreference = 'Continue'
|
||||
& $cmake -S $root -B $outDir -G Ninja `
|
||||
"-DCMAKE_MAKE_PROGRAM=$ninja" `
|
||||
"-DCMAKE_TOOLCHAIN_FILE=$toolchain" `
|
||||
"-DCMAKE_BUILD_TYPE=Release" 2>&1 | ForEach-Object { "$_" }
|
||||
"-DCMAKE_BUILD_TYPE=Release" @extra 2>&1 | ForEach-Object { "$_" }
|
||||
$rc = $LASTEXITCODE
|
||||
if ($rc -eq 0) {
|
||||
& $cmake --build $outDir --parallel 2>&1 | ForEach-Object { "$_" }
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
#!/bin/sh
|
||||
# build-wasm.sh - the same sources, linked to a web page.
|
||||
#
|
||||
# ./build-wasm.sh # build
|
||||
# ./build-wasm.sh --serve # build, then serve it on :8000
|
||||
#
|
||||
# The output must be served: a file:// page cannot fetch the .wasm.
|
||||
set -eu
|
||||
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
@@ -19,7 +13,7 @@ while [ $# -gt 0 ]; do
|
||||
shift
|
||||
[ $# -gt 0 ] || { echo "build-wasm.sh: --port needs a number" >&2; exit 2; }
|
||||
port="$1" ;;
|
||||
--help|-h) sed -n '2,7p' "$0" | cut -c 3-; exit 0 ;;
|
||||
--help|-h) echo "usage: build-wasm.sh [--serve] [--port N] [-- CMAKE_ARGS]"; exit 0 ;;
|
||||
--) shift; break ;;
|
||||
*) echo "build-wasm.sh: unknown argument: $1 (try --help)" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
param([string]$Target = "")
|
||||
|
||||
$extra = @($args)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$root = $PSScriptRoot
|
||||
$outDir = Join-Path $root "build"
|
||||
@@ -25,7 +26,8 @@ $bat = Join-Path $env:TEMP "reaktor_build.bat"
|
||||
'@echo off',
|
||||
('call "' + $vcvars + '" >nul 2>&1'),
|
||||
('"' + $cmake + '" -S "' + $root + '" -B "' + $outDir + '" -G Ninja ' +
|
||||
'-DCMAKE_MAKE_PROGRAM="' + $ninja + '" -DCMAKE_BUILD_TYPE=Release'),
|
||||
'-DCMAKE_MAKE_PROGRAM="' + $ninja + '" -DCMAKE_BUILD_TYPE=Release' +
|
||||
(($extra | ForEach-Object { ' "' + $_ + '"' }) -join '')),
|
||||
'if errorlevel 1 exit /b 1',
|
||||
('"' + $cmake + '" --build "' + $outDir + '" --parallel' +
|
||||
$(if ($Target) { ' --target ' + $Target } else { '' })),
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
#!/bin/sh
|
||||
# build.sh - CMake wrapper for macOS, Linux and the BSDs. build.ps1 on Windows.
|
||||
#
|
||||
# ./build.sh # everything
|
||||
# ./build.sh --target NAME # one target
|
||||
# ./build.sh --debug # -DCMAKE_BUILD_TYPE=Debug
|
||||
# -- # pass the rest to cmake
|
||||
set -eu
|
||||
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
@@ -20,7 +14,7 @@ while [ $# -gt 0 ]; do
|
||||
target="$1" ;;
|
||||
--debug) buildtype="Debug" ;;
|
||||
--release) buildtype="Release" ;;
|
||||
--help|-h) sed -n '2,7p' "$0" | cut -c 3-; exit 0 ;;
|
||||
--help|-h) echo "usage: build.sh [--target NAME] [--debug] [-- CMAKE_ARGS]"; exit 0 ;;
|
||||
--) shift; break ;;
|
||||
*) echo "build.sh: unknown argument: $1 (try --help)" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
@@ -68,7 +68,7 @@ typedef struct reaktor_a11y_change {
|
||||
|
||||
#define REAKTOR_A11Y_MAX_NODES 256
|
||||
#define REAKTOR_A11Y_MAX_CHANGES 256
|
||||
#define REAKTOR_A11Y_POOL 8192
|
||||
#define REAKTOR_A11Y_POOL 16384
|
||||
#define REAKTOR_A11Y_MAX_DEPTH 32
|
||||
#define REAKTOR_A11Y_SLOTS 512
|
||||
|
||||
|
||||
@@ -40,11 +40,6 @@ static int copy_out(char *out, size_t cap, const char *src)
|
||||
int reaktor_root(char *out, size_t cap)
|
||||
{
|
||||
|
||||
/* Resolved once. Finding it means asking for the executable's own path
|
||||
* and then probing for .reaktor-root at every level up the tree - and the
|
||||
* answer cannot change while the process runs. Every asset the app opens
|
||||
* comes through here, and a theme switch empties the icon cache and would
|
||||
* otherwise re-resolve for each icon on screen. */
|
||||
static char cached[REAKTOR_PATH_CAP];
|
||||
static int resolved;
|
||||
|
||||
|
||||
@@ -276,13 +276,6 @@ static void trim(const char *s, size_t *start, size_t *end)
|
||||
while (*end > *start && isspace((unsigned char)s[*end - 1])) (*end)--;
|
||||
}
|
||||
|
||||
/* [name="value"] -> .name-value, in place, for the one shape that carries
|
||||
* real styling in a document sheet. Anything else in brackets is still
|
||||
* unrepresentable and the rule still goes.
|
||||
*
|
||||
* Writes into `out` and answers its length, or 0 if the selector cannot be
|
||||
* rewritten. The result is never longer than the input: [x="y"] is six
|
||||
* characters of punctuation and .x-y is two. */
|
||||
static size_t selector_rewrite(const char *s, size_t len, char *out,
|
||||
size_t cap)
|
||||
{
|
||||
@@ -298,11 +291,7 @@ static size_t selector_rewrite(const char *s, size_t len, char *out,
|
||||
size_t j = i + 1, eq, ve, vs;
|
||||
|
||||
while (j < len && s[j] != ']' && s[j] != '=') j++;
|
||||
if (j >= len || s[j] != '=') return 0; /* [attr] alone */
|
||||
/* Only a plain equals. ^= $= *= |= ~= select on part of the
|
||||
* value, which a class cannot express - folding the operator
|
||||
* into the name produced a rule registered under something
|
||||
* nothing could ever match, which is worse than dropping it. */
|
||||
if (j >= len || s[j] != '=') return 0;
|
||||
if (j > i + 1 && strchr("^$*|~", s[j - 1])) return 0;
|
||||
eq = j;
|
||||
vs = eq + 1;
|
||||
@@ -403,13 +392,8 @@ static void collect_one(void *c, const char *p, size_t plen,
|
||||
vars_set(ctx->m, p, plen, v, vlen);
|
||||
}
|
||||
|
||||
/* px is the rem base - html's font-size, 16 unless the sheet says otherwise.
|
||||
* em is what an element inherits, which is body's if it sets one. */
|
||||
typedef struct root_ctx { float px, em; } root_ctx;
|
||||
|
||||
/* A length in px, resolving a unit against the rem base. Used for the two
|
||||
* font-size declarations that establish the bases themselves, so it cannot
|
||||
* call convert_units without going in a circle. */
|
||||
static float base_length(const char *v, size_t vlen, float rem_px)
|
||||
{
|
||||
char b[64];
|
||||
@@ -421,18 +405,12 @@ static float base_length(const char *v, size_t vlen, float rem_px)
|
||||
b[i] = (char)tolower((unsigned char)v[i]);
|
||||
b[vlen] = 0;
|
||||
|
||||
/* The number, and then exactly where it ended. atof would stop at the
|
||||
* first letter and never say so, which is how `1.15rem !important` came
|
||||
* back as 1.15 and was believed. */
|
||||
i = 0;
|
||||
if (b[i] == '-' || b[i] == '+') i++;
|
||||
while (i < vlen && (isdigit((unsigned char)b[i]) || b[i] == '.')) i++;
|
||||
if (i == 0) return 0.0f;
|
||||
n = atof(b);
|
||||
|
||||
/* Only the units this can convert. A sheet may legitimately say pt or
|
||||
* ch or vw; answering 0 leaves the caller on its default, which is a
|
||||
* better wrong answer than treating the number as pixels. */
|
||||
if (strcmp(b + i, "%") == 0) return (float)(n * rem_px / 100.0);
|
||||
if (strcmp(b + i, "rem") == 0) return (float)(n * rem_px);
|
||||
if (strcmp(b + i, "em") == 0) return (float)(n * rem_px);
|
||||
@@ -441,9 +419,6 @@ static float base_length(const char *v, size_t vlen, float rem_px)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/* Whether a selector list names this element on its own - `body` or the
|
||||
* `html, body` a sheet is just as likely to write. An exact four-byte
|
||||
* compare matched only the first spelling and silently missed the second. */
|
||||
static int selector_names(const char *src, size_t s, size_t e,
|
||||
const char *want)
|
||||
{
|
||||
@@ -469,16 +444,12 @@ static void root_one(void *c, const char *p, size_t plen,
|
||||
|
||||
if (plen != 9 || strncmp(p, "font-size", 9) != 0) return;
|
||||
n = base_length(v, vlen, 16.0f);
|
||||
/* html is the rem base. It is the em base only until a body rule says
|
||||
* otherwise - setting both here meant an html rule appearing later in
|
||||
* the concatenated sheets discarded the body size. */
|
||||
if (n > 0.0f) {
|
||||
if (ctx->em == ctx->px) ctx->em = n;
|
||||
ctx->px = n;
|
||||
}
|
||||
}
|
||||
|
||||
/* body's font-size, which is the one nearly every element inherits. */
|
||||
static void body_one(void *c, const char *p, size_t plen,
|
||||
const char *v, size_t vlen)
|
||||
{
|
||||
|
||||
@@ -25,11 +25,6 @@ static struct {
|
||||
int cache_n;
|
||||
css_metrics_t metrics;
|
||||
reaktor_cssvars *vars;
|
||||
/* The sheet's own base, resolved once from `body`, and the parent every
|
||||
* other lookup is computed against. Without it `em` and `rem` fall back
|
||||
* to the 16px initial value: simple.css says `body { font-size: 1.15rem }`,
|
||||
* so its 0.5em padding is 9.2px and we were computing 8.0 - a 15% error
|
||||
* on every length in the sheet, compounding into every widget's size. */
|
||||
css_computed_style_t root;
|
||||
int root_ready;
|
||||
} g;
|
||||
@@ -42,9 +37,6 @@ static void rgba_of(css_color_value_t c, unsigned char out[4])
|
||||
out[3] = (unsigned char)((c >> 24) & 0xff);
|
||||
}
|
||||
|
||||
/* Drop the base style. Called before every cascade into it and on the two
|
||||
* failure paths, so a half-initialized sheet cannot leave the previous
|
||||
* sheet's font size in place as the parent for the next one. */
|
||||
static void base_reset(void)
|
||||
{
|
||||
if (g.root_ready) css_computed_style_destroy(&g.root);
|
||||
@@ -90,16 +82,7 @@ int reaktor_style_init(const char *const *css_paths, int count,
|
||||
css_parser_destroy(parser);
|
||||
free(flat);
|
||||
|
||||
/* Now that the rules are in, establish the base every other lookup is
|
||||
* computed against.
|
||||
*
|
||||
* One cascade, not one per element. css_cascade_style writes the initial
|
||||
* value for every property the declaration leaves out, so cascading
|
||||
* `html` and then `body` into the same computed style erased the first
|
||||
* pass rather than layering on it - and it allocates font_family without
|
||||
* freeing what was there, which leaked on every theme change. `body` is
|
||||
* the one that matters: it is what a document's elements inherit, and it
|
||||
* is where a sheet puts its size. */
|
||||
/* One cascade: a second resets the first and leaks its font_family. */
|
||||
base_reset();
|
||||
{
|
||||
static const css_computed_style_t none;
|
||||
@@ -149,11 +132,6 @@ void reaktor_style_darken(unsigned char rgba[4], float amount)
|
||||
rgba[i] = (unsigned char)(rgba[i] * (1.0f - amount) + 0.5f);
|
||||
}
|
||||
|
||||
/* A length libcss resolved to pixels, or 0.
|
||||
*
|
||||
* It cannot resolve a percentage without a parent of known width, and when it
|
||||
* gives up it leaves the number alone with the unit still set - so `100%`
|
||||
* arrives as the float 100. Anything not in px is not a length we can use. */
|
||||
static float px_of(css_numeric_value_t v, css_unit_t unit)
|
||||
{
|
||||
return unit == CSS_UNIT_PX ? v : 0.0f;
|
||||
@@ -242,18 +220,6 @@ static void resolve(const char *selector, reaktor_style *out)
|
||||
out->max_height = px_of(computed.max_height,
|
||||
computed.unit_bits.max_height);
|
||||
|
||||
/* Only when this rule states it. line-height inherits in CSS, but libcss
|
||||
* reports an explicit `line-height: normal` and an absent declaration
|
||||
* identically - and simple.css sets `normal` on every control, which is
|
||||
* why the browser computes 18.4px/normal for a button while body is 1.5.
|
||||
* Inheriting body's ratio made every control taller than the browser
|
||||
* draws it.
|
||||
*
|
||||
* The kind comes from libcss's own tag, not from the size of the number:
|
||||
* `line-height: 150%` is the same thing as 1.5 and would otherwise have
|
||||
* been taken for a 150px line box. line-height is not in the property
|
||||
* list css_compute_absolute_values walks, so a length is only usable if
|
||||
* it was already written in px. */
|
||||
out->line_height = 0.0f;
|
||||
switch (computed.type_bits.line_height) {
|
||||
case CSS_LINE_HEIGHT_NUMBER: {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#ifndef REAKTOR_STYLE_H
|
||||
#define REAKTOR_STYLE_H
|
||||
|
||||
/* Sides in CSS order, so a reader can carry the order over from the sheet. */
|
||||
enum { REAKTOR_SIDE_TOP = 0, REAKTOR_SIDE_RIGHT, REAKTOR_SIDE_BOTTOM, REAKTOR_SIDE_LEFT };
|
||||
/* Corners likewise: top-left, top-right, bottom-right, bottom-left. */
|
||||
enum { REAKTOR_CORNER_TL = 0, REAKTOR_CORNER_TR, REAKTOR_CORNER_BR, REAKTOR_CORNER_BL };
|
||||
|
||||
typedef struct reaktor_style {
|
||||
@@ -11,25 +9,18 @@ typedef struct reaktor_style {
|
||||
unsigned char fg[4];
|
||||
unsigned char border_col[4];
|
||||
|
||||
/* The one-sided readings most callers want, kept because most of them
|
||||
* only ever ask about a uniform box. */
|
||||
float border;
|
||||
float rounding;
|
||||
float pad_x, pad_y;
|
||||
|
||||
/* And the whole box, because a rule may not be uniform: "padding: 4px
|
||||
* 12px" is two numbers, and reading only padding-left made it one. */
|
||||
float pad[4];
|
||||
float border_w[4];
|
||||
float radius[4];
|
||||
float margin[4];
|
||||
|
||||
/* What the sheet says the box should be, 0 for "it did not say". */
|
||||
float width, height;
|
||||
float min_width, min_height;
|
||||
float max_width, max_height;
|
||||
/* In px. A unitless line-height is a multiple of the font size; it is
|
||||
* resolved here so a caller never has to ask which kind it got. */
|
||||
float line_height;
|
||||
|
||||
int font_px;
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
#include "locale_internal.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define NBSP "\xC2\xA0"
|
||||
|
||||
typedef struct out {
|
||||
char *buf;
|
||||
size_t cap, len;
|
||||
int full;
|
||||
} out;
|
||||
|
||||
static out
|
||||
start(char *buf, size_t cap)
|
||||
{
|
||||
out o = { buf, cap, 0, 0 };
|
||||
|
||||
buf[0] = '\0';
|
||||
return o;
|
||||
}
|
||||
|
||||
static void
|
||||
put(out *o, const char *s, size_t n)
|
||||
{
|
||||
size_t room = o->cap - 1 - o->len;
|
||||
|
||||
if (o->full) return;
|
||||
if (n > room) {
|
||||
n = room;
|
||||
while (n > 0 && ((unsigned char)s[n] & 0xC0) == 0x80) n--;
|
||||
o->full = 1;
|
||||
}
|
||||
memcpy(o->buf + o->len, s, n);
|
||||
o->len += n;
|
||||
o->buf[o->len] = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
puts_(out *o, const char *s)
|
||||
{
|
||||
put(o, s, strlen(s));
|
||||
}
|
||||
|
||||
static void
|
||||
putf(out *o, const char *fmt, int v)
|
||||
{
|
||||
char tmp[16];
|
||||
int n = snprintf(tmp, sizeof tmp, fmt, v);
|
||||
|
||||
if (n > 0) put(o, tmp, (size_t)n < sizeof tmp ? (size_t)n : sizeof tmp - 1);
|
||||
}
|
||||
|
||||
/* reaktor_tr answers key itself, the same pointer, when it has no value. */
|
||||
static const char *
|
||||
conv(const char *key, const char *fallback)
|
||||
{
|
||||
const char *v = reaktor_tr(key);
|
||||
|
||||
return v == key ? fallback : v;
|
||||
}
|
||||
|
||||
static const char *
|
||||
form(const char *list, long i, size_t *len)
|
||||
{
|
||||
const char *end;
|
||||
|
||||
for (; i > 0; i--) {
|
||||
const char *bar = strstr(list, " | ");
|
||||
if (!bar) break;
|
||||
list = bar + 3;
|
||||
}
|
||||
end = strstr(list, " | ");
|
||||
*len = end ? (size_t)(end - list) : strlen(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
number(out *o, double value, int decimals)
|
||||
{
|
||||
const char *dec = conv("number.decimal", ".");
|
||||
const char *group = conv("number.group", ",");
|
||||
int min = atoi(conv("number.group.min", "1"));
|
||||
char digits[64];
|
||||
int n, i, whole;
|
||||
|
||||
if (decimals < 0) decimals = 0;
|
||||
if (decimals > 9) decimals = 9;
|
||||
if (!isfinite(value)) {
|
||||
puts_(o, value != value ? "NaN" : value < 0 ? "-inf" : "inf");
|
||||
return;
|
||||
}
|
||||
n = snprintf(digits, sizeof digits, "%.*f", decimals, fabs(value));
|
||||
if (n <= 0 || n >= (int)sizeof digits) {
|
||||
puts_(o, "?");
|
||||
return;
|
||||
}
|
||||
for (whole = 0; digits[whole] >= '0' && digits[whole] <= '9'; whole++) ;
|
||||
if (value < 0) {
|
||||
for (i = 0; digits[i] && (digits[i] < '1' || digits[i] > '9'); i++) ;
|
||||
if (digits[i]) put(o, "-", 1);
|
||||
}
|
||||
|
||||
if (min < 1) min = 1;
|
||||
for (i = 0; i < whole; i++) {
|
||||
put(o, digits + i, 1);
|
||||
if (whole >= 3 + min && i < whole - 1 && (whole - 1 - i) % 3 == 0)
|
||||
puts_(o, group);
|
||||
}
|
||||
if (decimals > 0 && digits[whole]) {
|
||||
puts_(o, dec);
|
||||
puts_(o, digits + whole + 1);
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_number(char *buf, size_t cap, double value, int decimals)
|
||||
{
|
||||
out o;
|
||||
|
||||
if (!buf || cap == 0) return buf;
|
||||
o = start(buf, cap);
|
||||
number(&o, value, decimals);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap)
|
||||
{
|
||||
const char *v = reaktor_tr(key), *rule, *end;
|
||||
char num[32];
|
||||
size_t len;
|
||||
long i;
|
||||
out o;
|
||||
|
||||
if (!key || !buf || cap == 0 || v == key) return key;
|
||||
rule = conv("plural", NULL);
|
||||
i = rule ? reaktor_plural_eval(rule, n) : -1;
|
||||
if (i < 0) i = n != 1;
|
||||
v = form(v, i, &len);
|
||||
end = v + len;
|
||||
reaktor_format_number(num, sizeof num, (double)n, 0);
|
||||
|
||||
o = start(buf, cap);
|
||||
while (v < end) {
|
||||
if (end - v >= 3 && !strncmp(v, "{n}", 3)) {
|
||||
puts_(&o, num);
|
||||
v += 3;
|
||||
} else {
|
||||
const char *brace = memchr(v + 1, '{', (size_t)(end - v - 1));
|
||||
size_t k = brace ? (size_t)(brace - v) : (size_t)(end - v);
|
||||
|
||||
put(&o, v, k);
|
||||
v += k;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int
|
||||
is_letter(unsigned char c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_money(char *buf, size_t cap, double amount, const char *currency)
|
||||
{
|
||||
const char *pattern, *symbol, *p;
|
||||
char key[40], amt[64];
|
||||
int digits;
|
||||
size_t slen;
|
||||
out o, a;
|
||||
|
||||
if (!buf || cap == 0) return buf;
|
||||
o = start(buf, cap);
|
||||
if (!currency) currency = "";
|
||||
|
||||
snprintf(key, sizeof key, "money.%s", currency);
|
||||
symbol = conv(key, currency);
|
||||
snprintf(key, sizeof key, "money.%s.digits", currency);
|
||||
digits = atoi(conv(key, "2"));
|
||||
pattern = conv("money", "{s}{n}");
|
||||
slen = strlen(symbol);
|
||||
|
||||
a = start(amt, sizeof amt);
|
||||
number(&a, amount, digits);
|
||||
if (amt[0] == '-') put(&o, "-", 1);
|
||||
|
||||
for (p = pattern; *p; ) {
|
||||
if (!strncmp(p, "{n}", 3)) {
|
||||
puts_(&o, amt[0] == '-' ? amt + 1 : amt);
|
||||
if (!strncmp(p + 3, "{s}", 3) && slen &&
|
||||
is_letter((unsigned char)symbol[0]))
|
||||
puts_(&o, NBSP);
|
||||
p += 3;
|
||||
} else if (!strncmp(p, "{s}", 3)) {
|
||||
put(&o, symbol, slen);
|
||||
if (!strncmp(p + 3, "{n}", 3) && slen &&
|
||||
is_letter((unsigned char)symbol[slen - 1]))
|
||||
puts_(&o, NBSP);
|
||||
p += 3;
|
||||
} else {
|
||||
const char *brace = strchr(p + 1, '{');
|
||||
size_t n = brace ? (size_t)(brace - p) : strlen(p);
|
||||
|
||||
put(&o, p, n);
|
||||
p += n;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int
|
||||
weekday(int y, int m, int d)
|
||||
{
|
||||
static const int t[12] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
|
||||
|
||||
if (m < 3) y--;
|
||||
return ((y + y / 4 - y / 100 + y / 400 + t[(m - 1) % 12] + d) % 7 + 7) % 7;
|
||||
}
|
||||
|
||||
static const char MONTHS[] =
|
||||
"January | February | March | April | May | June | July | August | "
|
||||
"September | October | November | December";
|
||||
static const char MONTHS_SHORT[] =
|
||||
"Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec";
|
||||
static const char DAYS[] =
|
||||
"Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday";
|
||||
static const char DAYS_SHORT[] = "Sun | Mon | Tue | Wed | Thu | Fri | Sat";
|
||||
|
||||
static void
|
||||
name(out *o, const char *key, const char *english, int i)
|
||||
{
|
||||
size_t len;
|
||||
const char *f = form(conv(key, english), i, &len);
|
||||
|
||||
put(o, f, len);
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
{
|
||||
static const char *const keys[] = {
|
||||
"date.short", "date.long", "date.full", "time.short"
|
||||
};
|
||||
static const char *const english[] = {
|
||||
"M/d/yy", "MMMM d, y", "EEEE, MMMM d, y", "h:mm a"
|
||||
};
|
||||
const char *p;
|
||||
int year, month, day, hour, minute, wd;
|
||||
out o;
|
||||
|
||||
if (!buf || cap == 0) return buf;
|
||||
o = start(buf, cap);
|
||||
if (!t || style < REAKTOR_DATE_SHORT || style > REAKTOR_TIME_SHORT)
|
||||
return buf;
|
||||
|
||||
year = t->tm_year + 1900;
|
||||
month = t->tm_mon + 1;
|
||||
day = t->tm_mday;
|
||||
hour = t->tm_hour;
|
||||
minute = t->tm_min;
|
||||
if (month < 1 || month > 12) return buf;
|
||||
wd = weekday(year, month, day);
|
||||
|
||||
for (p = conv(keys[style], english[style]); *p; ) {
|
||||
char c = *p;
|
||||
int run = 1;
|
||||
|
||||
if (c == '\'') {
|
||||
const char *close;
|
||||
|
||||
if (p[1] == '\'') { put(&o, "'", 1); p += 2; continue; }
|
||||
close = strchr(p + 1, '\'');
|
||||
run = close ? (int)(close - p - 1) : (int)strlen(p + 1);
|
||||
put(&o, p + 1, (size_t)run);
|
||||
p += run + 1 + (close != NULL);
|
||||
continue;
|
||||
}
|
||||
if (!is_letter((unsigned char)c)) {
|
||||
while (p[run] && p[run] != '\'' && !is_letter((unsigned char)p[run]))
|
||||
run++;
|
||||
put(&o, p, (size_t)run);
|
||||
p += run;
|
||||
continue;
|
||||
}
|
||||
while (p[run] == c) run++;
|
||||
switch (c) {
|
||||
case 'd': putf(&o, run > 1 ? "%02d" : "%d", day); break;
|
||||
case 'M':
|
||||
if (run >= 4) name(&o, "date.months", MONTHS, month - 1);
|
||||
else if (run == 3) name(&o, "date.months.short", MONTHS_SHORT,
|
||||
month - 1);
|
||||
else putf(&o, run > 1 ? "%02d" : "%d", month);
|
||||
break;
|
||||
case 'y':
|
||||
if (run == 2) putf(&o, "%02d", ((year % 100) + 100) % 100);
|
||||
else putf(&o, run > 2 ? "%04d" : "%d", year);
|
||||
break;
|
||||
case 'E':
|
||||
if (run >= 4) name(&o, "date.days", DAYS, wd);
|
||||
else name(&o, "date.days.short", DAYS_SHORT, wd);
|
||||
break;
|
||||
case 'H': putf(&o, run > 1 ? "%02d" : "%d", hour); break;
|
||||
case 'h': putf(&o, run > 1 ? "%02d" : "%d", hour % 12 ? hour % 12 : 12); break;
|
||||
case 'm': putf(&o, run > 1 ? "%02d" : "%d", minute); break;
|
||||
case 'a': name(&o, "time.ampm", "AM | PM", hour >= 12); break;
|
||||
default: put(&o, p, (size_t)run); break;
|
||||
}
|
||||
p += run;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
#include "locale_internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef REAKTOR_LOCALE_EMBEDDED
|
||||
#include <SDL3/SDL.h>
|
||||
#include "reaktor.h"
|
||||
#endif
|
||||
|
||||
#define LOCALE_MAX 32
|
||||
#define LOCALE_CODE 16
|
||||
|
||||
typedef struct locale_entry {
|
||||
const char *key, *value;
|
||||
int line;
|
||||
} locale_entry;
|
||||
|
||||
typedef struct locale_catalog {
|
||||
char code[LOCALE_CODE];
|
||||
char *data;
|
||||
locale_entry *entry;
|
||||
int count;
|
||||
const char *name;
|
||||
} locale_catalog;
|
||||
|
||||
static locale_catalog g_cat[LOCALE_MAX];
|
||||
static int g_count;
|
||||
static int g_current = -1;
|
||||
|
||||
static int
|
||||
by_code(const void *a, const void *b)
|
||||
{
|
||||
return strcmp(((const locale_catalog *)a)->code,
|
||||
((const locale_catalog *)b)->code);
|
||||
}
|
||||
|
||||
static int
|
||||
by_key(const void *a, const void *b)
|
||||
{
|
||||
const locale_entry *x = a, *y = b;
|
||||
int c = strcmp(x->key, y->key);
|
||||
|
||||
return c ? c : x->line - y->line;
|
||||
}
|
||||
|
||||
static char *
|
||||
trim(char *s, char *end)
|
||||
{
|
||||
while (s < end && (*s == ' ' || *s == '\t')) s++;
|
||||
while (end > s && (end[-1] == ' ' || end[-1] == '\t' || end[-1] == '\r'))
|
||||
end--;
|
||||
*end = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
static void
|
||||
unescape(char *s)
|
||||
{
|
||||
char *w = s;
|
||||
|
||||
for (; *s; s++) {
|
||||
if (s[0] == '\\' && s[1] == 'n') { *w++ = '\n'; s++; }
|
||||
else if (s[0] == '\\' && s[1] == '\\') { *w++ = '\\'; s++; }
|
||||
else *w++ = *s;
|
||||
}
|
||||
*w = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
parse(locale_catalog *c, char *data)
|
||||
{
|
||||
char *s = data, *next;
|
||||
int lines = 1, n = 0, i;
|
||||
|
||||
if ((unsigned char)s[0] == 0xEF && (unsigned char)s[1] == 0xBB &&
|
||||
(unsigned char)s[2] == 0xBF)
|
||||
s += 3;
|
||||
for (next = s; *next; next++) lines += *next == '\n';
|
||||
|
||||
c->data = data;
|
||||
c->entry = calloc((size_t)lines, sizeof *c->entry);
|
||||
if (!c->entry) return 0;
|
||||
|
||||
for (i = 0; *s; i++, s = next) {
|
||||
char *eol = strchr(s, '\n');
|
||||
char *sep;
|
||||
|
||||
next = eol ? eol + 1 : s + strlen(s);
|
||||
if (!eol) eol = next;
|
||||
*eol = '\0';
|
||||
|
||||
sep = strstr(s, " = ");
|
||||
if (!sep) continue;
|
||||
c->entry[n].key = trim(s, sep);
|
||||
c->entry[n].value = trim(sep + 3, eol);
|
||||
c->entry[n].line = i;
|
||||
if (!*c->entry[n].key) continue;
|
||||
unescape((char *)c->entry[n].value);
|
||||
n++;
|
||||
}
|
||||
|
||||
qsort(c->entry, (size_t)n, sizeof *c->entry, by_key);
|
||||
for (i = 0, c->count = 0; i < n; i++) {
|
||||
if (c->count && !strcmp(c->entry[c->count - 1].key, c->entry[i].key))
|
||||
continue;
|
||||
c->entry[c->count++] = c->entry[i];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
lookup(const locale_catalog *c, const char *key)
|
||||
{
|
||||
int lo = 0, hi = c->count - 1;
|
||||
|
||||
while (lo <= hi) {
|
||||
int mid = lo + (hi - lo) / 2;
|
||||
int cmp = strcmp(key, c->entry[mid].key);
|
||||
|
||||
if (!cmp) return c->entry[mid].value;
|
||||
if (cmp < 0) hi = mid - 1;
|
||||
else lo = mid + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
add_catalog(const char *code, char *data)
|
||||
{
|
||||
locale_catalog *c;
|
||||
|
||||
if (g_count >= LOCALE_MAX || strlen(code) >= LOCALE_CODE) {
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
c = &g_cat[g_count];
|
||||
memset(c, 0, sizeof *c);
|
||||
strcpy(c->code, code);
|
||||
if (!parse(c, data)) {
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
c->name = lookup(c, "language");
|
||||
if (!c->name) c->name = c->code;
|
||||
g_count++;
|
||||
}
|
||||
|
||||
static void
|
||||
release(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_count; i++) {
|
||||
free(g_cat[i].entry);
|
||||
free(g_cat[i].data);
|
||||
}
|
||||
g_count = 0;
|
||||
g_current = -1;
|
||||
}
|
||||
|
||||
#ifdef REAKTOR_LOCALE_EMBEDDED
|
||||
static void
|
||||
load_all(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < reaktor_locale_catalog_count; i++) {
|
||||
const struct reaktor_locale_catalog *e = &reaktor_locale_catalogs[i];
|
||||
char *data = malloc(e->size + 1);
|
||||
|
||||
if (!data) continue;
|
||||
memcpy(data, e->data, e->size);
|
||||
data[e->size] = '\0';
|
||||
add_catalog(e->code, data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void
|
||||
load_all(void)
|
||||
{
|
||||
char dir[1024], path[1024];
|
||||
char **names;
|
||||
int i, n = 0;
|
||||
|
||||
if (!reaktor_path(dir, sizeof dir, "assets/locale")) return;
|
||||
names = SDL_GlobDirectory(dir, "*.txt", 0, &n);
|
||||
if (!names) return;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *dot = strrchr(names[i], '.');
|
||||
char code[LOCALE_CODE];
|
||||
size_t len = dot ? (size_t)(dot - names[i]) : 0;
|
||||
char *data;
|
||||
|
||||
if (len == 0 || len >= sizeof code) continue;
|
||||
memcpy(code, names[i], len);
|
||||
code[len] = '\0';
|
||||
|
||||
SDL_snprintf(path, sizeof path, "%s/%s", dir, names[i]);
|
||||
data = reaktor_read_file(path, NULL);
|
||||
if (data) add_catalog(code, data);
|
||||
}
|
||||
SDL_free(names);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
reaktor_locale_init(void)
|
||||
{
|
||||
release();
|
||||
load_all();
|
||||
qsort(g_cat, (size_t)g_count, sizeof *g_cat, by_code);
|
||||
return g_count;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_locale_count(void)
|
||||
{
|
||||
return g_count;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_locale_find(const char *code)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; code && i < g_count; i++)
|
||||
if (!strcmp(g_cat[i].code, code)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_locale_code(int index)
|
||||
{
|
||||
return index >= 0 && index < g_count ? g_cat[index].code : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_locale_name(int index)
|
||||
{
|
||||
return index >= 0 && index < g_count ? g_cat[index].name : NULL;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_locale_set(const char *code)
|
||||
{
|
||||
int i = reaktor_locale_find(code);
|
||||
|
||||
if (i < 0) return 0;
|
||||
g_current = i;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_locale_current(void)
|
||||
{
|
||||
return g_current >= 0 ? g_cat[g_current].code : "";
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_tr(const char *key)
|
||||
{
|
||||
const char *v;
|
||||
|
||||
if (!key || g_current < 0) return key;
|
||||
v = lookup(&g_cat[g_current], key);
|
||||
return v ? v : key;
|
||||
}
|
||||
|
||||
static int
|
||||
utf8_next(const unsigned char *s, unsigned *cp)
|
||||
{
|
||||
int len, i;
|
||||
|
||||
if (s[0] < 0x80) { *cp = s[0]; return 1; }
|
||||
else if ((s[0] & 0xE0) == 0xC0) { *cp = s[0] & 0x1F; len = 2; }
|
||||
else if ((s[0] & 0xF0) == 0xE0) { *cp = s[0] & 0x0F; len = 3; }
|
||||
else if ((s[0] & 0xF8) == 0xF0) { *cp = s[0] & 0x07; len = 4; }
|
||||
else return 0;
|
||||
|
||||
for (i = 1; i < len; i++) {
|
||||
if ((s[i] & 0xC0) != 0x80) return 0;
|
||||
*cp = (*cp << 6) | (s[i] & 0x3F);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
by_codepoint(const void *a, const void *b)
|
||||
{
|
||||
unsigned x = *(const unsigned *)a, y = *(const unsigned *)b;
|
||||
|
||||
return x < y ? -1 : x > y;
|
||||
}
|
||||
|
||||
static void
|
||||
scan(const char *text, unsigned **set, int *n, int *cap)
|
||||
{
|
||||
const unsigned char *s = (const unsigned char *)text;
|
||||
|
||||
while (*s) {
|
||||
unsigned cp = 0;
|
||||
int len = utf8_next(s, &cp);
|
||||
|
||||
if (!len) { s++; continue; }
|
||||
s += len;
|
||||
if (cp <= 0xFF) continue;
|
||||
if (*n == *cap) {
|
||||
int grow = *cap ? *cap * 2 : 256;
|
||||
unsigned *more = realloc(*set, (size_t)grow * sizeof **set);
|
||||
|
||||
if (!more) return;
|
||||
*set = more;
|
||||
*cap = grow;
|
||||
}
|
||||
(*set)[(*n)++] = cp;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_locale_codepoints(unsigned *out, int cap)
|
||||
{
|
||||
unsigned *set = NULL;
|
||||
int n = 0, room = 0, unique = 0, i, j;
|
||||
|
||||
for (i = 0; i < g_count; i++)
|
||||
for (j = 0; j < g_cat[i].count; j++) {
|
||||
scan(g_cat[i].entry[j].key, &set, &n, &room);
|
||||
scan(g_cat[i].entry[j].value, &set, &n, &room);
|
||||
}
|
||||
|
||||
if (n) qsort(set, (size_t)n, sizeof *set, by_codepoint);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (unique && set[i] == set[i - 1]) continue;
|
||||
if (out && unique < cap) out[unique] = set[i];
|
||||
unique++;
|
||||
}
|
||||
free(set);
|
||||
return unique;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef REAKTOR_LOCALE_H
|
||||
#define REAKTOR_LOCALE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void reaktor_locale_start(const char *lang);
|
||||
int reaktor_locale_count(void);
|
||||
const char *reaktor_locale_code(int index);
|
||||
const char *reaktor_locale_name(int index);
|
||||
int reaktor_locale_set(const char *code);
|
||||
const char *reaktor_locale_current(void);
|
||||
|
||||
const char *reaktor_tr(const char *key);
|
||||
const char *reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap);
|
||||
|
||||
/* The caller SDL_frees them. */
|
||||
unsigned *reaktor_locale_glyphs(const char *font_path);
|
||||
|
||||
const char *reaktor_format_number(char *buf, size_t cap, double value,
|
||||
int decimals);
|
||||
const char *reaktor_format_money(char *buf, size_t cap, double amount,
|
||||
const char *currency);
|
||||
|
||||
enum {
|
||||
REAKTOR_DATE_SHORT,
|
||||
REAKTOR_DATE_LONG,
|
||||
REAKTOR_DATE_FULL,
|
||||
REAKTOR_TIME_SHORT
|
||||
};
|
||||
|
||||
struct tm;
|
||||
const char *reaktor_format_date(char *buf, size_t cap, const struct tm *t,
|
||||
int style);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef REAKTOR_LOCALE_INTERNAL_H
|
||||
#define REAKTOR_LOCALE_INTERNAL_H
|
||||
|
||||
#include "locale.h"
|
||||
|
||||
int reaktor_locale_init(void);
|
||||
int reaktor_locale_find(const char *code);
|
||||
int reaktor_locale_codepoints(unsigned *out, int cap);
|
||||
long reaktor_plural_eval(const char *expr, unsigned long n);
|
||||
|
||||
#ifdef REAKTOR_LOCALE_EMBEDDED
|
||||
struct reaktor_locale_catalog {
|
||||
const char *code;
|
||||
const unsigned char *data;
|
||||
size_t size;
|
||||
};
|
||||
extern const struct reaktor_locale_catalog reaktor_locale_catalogs[];
|
||||
extern const int reaktor_locale_catalog_count;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "locale.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
void reaktor_locale_start(const char *lang) { (void)lang; }
|
||||
int reaktor_locale_count(void) { return 0; }
|
||||
const char *reaktor_locale_code(int i) { (void)i; return NULL; }
|
||||
const char *reaktor_locale_name(int i) { (void)i; return NULL; }
|
||||
int reaktor_locale_set(const char *c) { (void)c; return 0; }
|
||||
const char *reaktor_locale_current(void) { return ""; }
|
||||
const char *reaktor_tr(const char *key) { return key; }
|
||||
|
||||
const char *
|
||||
reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap)
|
||||
{
|
||||
(void)n; (void)buf; (void)cap;
|
||||
return key;
|
||||
}
|
||||
|
||||
unsigned *
|
||||
reaktor_locale_glyphs(const char *font_path)
|
||||
{
|
||||
(void)font_path;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_number(char *buf, size_t cap, double value, int decimals)
|
||||
{
|
||||
if (buf && cap) snprintf(buf, cap, "%.*f", decimals, value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_money(char *buf, size_t cap, double amount, const char *currency)
|
||||
{
|
||||
if (buf && cap)
|
||||
snprintf(buf, cap, "%s %.2f", currency ? currency : "", amount);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
{
|
||||
if (!buf || !cap) return buf;
|
||||
buf[0] = '\0';
|
||||
if (!t) return buf;
|
||||
if (style == REAKTOR_TIME_SHORT)
|
||||
snprintf(buf, cap, "%02d:%02d", t->tm_hour, t->tm_min);
|
||||
else
|
||||
snprintf(buf, cap, "%04d-%02d-%02d", t->tm_year + 1900, t->tm_mon + 1,
|
||||
t->tm_mday);
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "nk_common.h"
|
||||
#include "locale_internal.h"
|
||||
|
||||
void
|
||||
reaktor_locale_start(const char *lang)
|
||||
{
|
||||
SDL_Locale **pref;
|
||||
int i, n = 0;
|
||||
|
||||
if (reaktor_locale_init() <= 0) return;
|
||||
if (lang) {
|
||||
if (reaktor_locale_set(lang)) return;
|
||||
SDL_Log("no catalog for --lang %s", lang);
|
||||
}
|
||||
pref = SDL_GetPreferredLocales(&n);
|
||||
for (i = 0; pref && i < n; i++)
|
||||
if (pref[i] && reaktor_locale_set(pref[i]->language)) break;
|
||||
SDL_free(pref);
|
||||
if (!reaktor_locale_current()[0] && !reaktor_locale_set("en"))
|
||||
reaktor_locale_set(reaktor_locale_code(0));
|
||||
}
|
||||
|
||||
unsigned *
|
||||
reaktor_locale_glyphs(const char *font_path)
|
||||
{
|
||||
unsigned *cp, *ranges = NULL;
|
||||
void *ttf = NULL;
|
||||
size_t size = 0;
|
||||
int n = reaktor_locale_codepoints(NULL, 0);
|
||||
|
||||
if (n <= 0 || !font_path) return NULL;
|
||||
|
||||
cp = SDL_malloc((size_t)n * sizeof *cp);
|
||||
if (cp) ttf = SDL_LoadFile(font_path, &size);
|
||||
if (cp && ttf) {
|
||||
reaktor_locale_codepoints(cp, n);
|
||||
ranges = reaktor_font_ranges(ttf, cp, n);
|
||||
}
|
||||
SDL_free(ttf);
|
||||
SDL_free(cp);
|
||||
return ranges;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
#include "locale_internal.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PLURAL_DEPTH 64
|
||||
|
||||
typedef struct plural_parser {
|
||||
const char *s;
|
||||
unsigned long n;
|
||||
int depth;
|
||||
int bad;
|
||||
} plural_parser;
|
||||
|
||||
static unsigned long expr(plural_parser *p);
|
||||
|
||||
static void
|
||||
skip(plural_parser *p)
|
||||
{
|
||||
while (isspace((unsigned char)*p->s)) p->s++;
|
||||
}
|
||||
|
||||
static int
|
||||
take(plural_parser *p, const char *op)
|
||||
{
|
||||
size_t len = strlen(op);
|
||||
|
||||
skip(p);
|
||||
if (strncmp(p->s, op, len) != 0) return 0;
|
||||
p->s += len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
primary(plural_parser *p)
|
||||
{
|
||||
unsigned long v = 0;
|
||||
|
||||
skip(p);
|
||||
if (*p->s == 'n') {
|
||||
p->s++;
|
||||
return p->n;
|
||||
}
|
||||
if (isdigit((unsigned char)*p->s)) {
|
||||
while (isdigit((unsigned char)*p->s))
|
||||
v = v * 10 + (unsigned long)(*p->s++ - '0');
|
||||
return v;
|
||||
}
|
||||
if (take(p, "(")) {
|
||||
v = expr(p);
|
||||
if (!take(p, ")")) p->bad = 1;
|
||||
return v;
|
||||
}
|
||||
p->bad = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
unary(plural_parser *p)
|
||||
{
|
||||
unsigned long v;
|
||||
|
||||
skip(p);
|
||||
if (*p->s != '!' || p->s[1] == '=') return primary(p);
|
||||
if (++p->depth > PLURAL_DEPTH) {
|
||||
p->bad = 1;
|
||||
return 0;
|
||||
}
|
||||
p->s++;
|
||||
v = !unary(p);
|
||||
p->depth--;
|
||||
return v;
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
mul(plural_parser *p)
|
||||
{
|
||||
unsigned long v = unary(p), r;
|
||||
|
||||
for (;;) {
|
||||
skip(p);
|
||||
if (*p->s == '*') {
|
||||
p->s++;
|
||||
v *= unary(p);
|
||||
} else if (*p->s == '/' || *p->s == '%') {
|
||||
char op = *p->s++;
|
||||
|
||||
r = unary(p);
|
||||
if (r == 0) {
|
||||
p->bad = 1;
|
||||
return 0;
|
||||
}
|
||||
v = op == '/' ? v / r : v % r;
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
add(plural_parser *p)
|
||||
{
|
||||
unsigned long v = mul(p);
|
||||
|
||||
for (;;) {
|
||||
skip(p);
|
||||
if (*p->s == '+') {
|
||||
p->s++;
|
||||
v += mul(p);
|
||||
} else if (*p->s == '-') {
|
||||
p->s++;
|
||||
v -= mul(p);
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
rel(plural_parser *p)
|
||||
{
|
||||
unsigned long v = add(p), r;
|
||||
|
||||
for (;;) {
|
||||
if (take(p, "<=")) { r = add(p); v = v <= r; }
|
||||
else if (take(p, ">=")) { r = add(p); v = v >= r; }
|
||||
else if (take(p, "<")) { r = add(p); v = v < r; }
|
||||
else if (take(p, ">")) { r = add(p); v = v > r; }
|
||||
else return v;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
eq(plural_parser *p)
|
||||
{
|
||||
unsigned long v = rel(p), r;
|
||||
|
||||
for (;;) {
|
||||
if (take(p, "==")) { r = rel(p); v = v == r; }
|
||||
else if (take(p, "!=")) { r = rel(p); v = v != r; }
|
||||
else return v;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
and_(plural_parser *p)
|
||||
{
|
||||
unsigned long v = eq(p), r;
|
||||
|
||||
while (take(p, "&&")) {
|
||||
r = eq(p);
|
||||
v = v && r;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
or_(plural_parser *p)
|
||||
{
|
||||
unsigned long v = and_(p), r;
|
||||
|
||||
while (take(p, "||")) {
|
||||
r = and_(p);
|
||||
v = v || r;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
expr(plural_parser *p)
|
||||
{
|
||||
unsigned long c, a, b;
|
||||
|
||||
if (++p->depth > PLURAL_DEPTH) {
|
||||
p->bad = 1;
|
||||
return 0;
|
||||
}
|
||||
c = or_(p);
|
||||
if (take(p, "?")) {
|
||||
a = expr(p);
|
||||
if (!take(p, ":")) p->bad = 1;
|
||||
b = expr(p);
|
||||
c = c ? a : b;
|
||||
}
|
||||
p->depth--;
|
||||
return c;
|
||||
}
|
||||
|
||||
long
|
||||
reaktor_plural_eval(const char *text, unsigned long n)
|
||||
{
|
||||
plural_parser p;
|
||||
const char *at;
|
||||
unsigned long v;
|
||||
|
||||
if (!text) return -1;
|
||||
at = strstr(text, "plural=");
|
||||
p.s = at ? at + 7 : text;
|
||||
p.n = n;
|
||||
p.depth = 0;
|
||||
p.bad = 0;
|
||||
|
||||
v = expr(&p);
|
||||
if (take(&p, ";")) skip(&p);
|
||||
if (p.bad || *p.s) return -1;
|
||||
return (long)v;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "internal.h"
|
||||
#include "locale.h"
|
||||
|
||||
static const int g_font_px[FONT_STEPS] =
|
||||
{ 12, 14, 16, 19, 23, 28, 34, 41 };
|
||||
@@ -190,15 +191,7 @@ reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
|
||||
if (b.w <= 0.0f || b.h <= 0.0f) return;
|
||||
|
||||
/* Snap the whole shape to the pixel grid before it is cut into pieces.
|
||||
*
|
||||
* The renderer snaps every vertex anyway, but it does it per rectangle
|
||||
* and after the arithmetic - so a corner blit ending at b.y+b.h-R and a
|
||||
* band starting at the same fractional number could round to different
|
||||
* rows and leave the one between them unpainted. That is a hairline of
|
||||
* whatever is underneath, straight across the shape, and it showed at
|
||||
* the rounded ends of the progress bar. Snapping first makes every
|
||||
* sub-rectangle an integer, so the pieces meet exactly. */
|
||||
/* Snapped first, or the pieces round apart. */
|
||||
{
|
||||
float x0 = (float)(int)(b.x + 0.5f);
|
||||
float y0 = (float)(int)(b.y + 0.5f);
|
||||
@@ -238,10 +231,6 @@ reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
q = nk_subimage_handle(h, (nk_ushort)d, (nk_ushort)d, from[i]);
|
||||
nk_draw_image(cv, corner[i], &q, col);
|
||||
}
|
||||
/* Three pieces that meet edge to edge, not two that overlap: every
|
||||
* coordinate here is an integer now, so abutting is exact, and a
|
||||
* color with alpha under 255 is painted once rather than composited
|
||||
* twice over the middle. */
|
||||
if (b.h > d)
|
||||
nk_fill_rect(cv, nk_rect(b.x, b.y + R, b.w, b.h - d), 0.0f, col);
|
||||
if (b.w > d) {
|
||||
@@ -275,6 +264,31 @@ centre_glyphs_optically(struct nk_font *f)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nbsp_as_space(struct nk_font *f)
|
||||
{
|
||||
const struct nk_font_glyph *sp;
|
||||
struct nk_font_glyph *nbsp;
|
||||
|
||||
if (!f || !f->glyphs) return;
|
||||
sp = nk_font_find_glyph(f, 0x20);
|
||||
nbsp = (struct nk_font_glyph *)nk_font_find_glyph(f, 0xA0);
|
||||
if (!sp || !nbsp || nbsp == sp || nbsp == f->fallback) return;
|
||||
*nbsp = *sp;
|
||||
nbsp->codepoint = 0xA0;
|
||||
}
|
||||
|
||||
static void
|
||||
finish_face(struct nk_font *f, float height, const char *path)
|
||||
{
|
||||
if (!f) return;
|
||||
f->handle.height = height;
|
||||
centre_glyphs_optically(f);
|
||||
nbsp_as_space(f);
|
||||
/* After centering: the Text module reads the baseline. */
|
||||
reaktor_text_attach_font(f, path);
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
pick_font(App *app, int px, int bold)
|
||||
{
|
||||
@@ -285,9 +299,6 @@ pick_font(App *app, int px, int bold)
|
||||
int d = g_font_px[i] > px ? g_font_px[i] - px : px - g_font_px[i];
|
||||
if (d < bd) { bd = d; best = i; }
|
||||
}
|
||||
/* Bold at the step that was asked for, and the regular face at that same
|
||||
* step if the bold one did not bake - the size is the more important of
|
||||
* the two to get right. */
|
||||
if (bold && app->bolds[best]) return &app->bolds[best]->handle;
|
||||
if (app->faces[best]) return &app->faces[best]->handle;
|
||||
return app->ctx->style.font;
|
||||
@@ -298,8 +309,8 @@ rebuild_font(App *app)
|
||||
{
|
||||
struct nk_font_atlas *atlas;
|
||||
struct nk_font *font = NULL;
|
||||
char path[1024];
|
||||
int have_font;
|
||||
char path[1024], bpath[1024];
|
||||
int have_font, is_default = 0, i;
|
||||
|
||||
have_font = reaktor_path(path, sizeof(path), FONT_FILE);
|
||||
if (app->atlas && !have_font) {
|
||||
@@ -308,42 +319,44 @@ rebuild_font(App *app)
|
||||
return;
|
||||
}
|
||||
|
||||
reaktor_text_attach_font(NULL, NULL);
|
||||
if (app->atlas) {
|
||||
nk_font_atlas_clear(app->atlas);
|
||||
SDL_memset(app->faces, 0, sizeof(app->faces));
|
||||
SDL_memset(app->bolds, 0, sizeof(app->bolds));
|
||||
app->face_bold = NULL;
|
||||
}
|
||||
SDL_free(app->glyphs);
|
||||
app->glyphs = NULL;
|
||||
|
||||
atlas = nk_sdl_font_stash_begin(app->ctx);
|
||||
app->atlas = atlas;
|
||||
|
||||
if (have_font) {
|
||||
struct nk_font_config cfg = nk_font_config(0);
|
||||
int i;
|
||||
const char *slash = SDL_strrchr(path, '/');
|
||||
const char *bslash = SDL_strrchr(path, 92);
|
||||
|
||||
if (bslash > slash) slash = bslash;
|
||||
SDL_snprintf(bpath, sizeof(bpath), "%.*s%s",
|
||||
slash ? (int)(slash - path + 1) : 0, path,
|
||||
SDL_strrchr(FONT_BOLD_FILE, '/') + 1);
|
||||
app->glyphs = reaktor_locale_glyphs(path);
|
||||
|
||||
cfg.oversample_h = 1;
|
||||
cfg.oversample_v = 1;
|
||||
cfg.pixel_snap = 1;
|
||||
if (app->glyphs) cfg.range = app->glyphs;
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
app->faces[i] = nk_font_atlas_add_from_file(
|
||||
atlas, path, (float)reaktor_px(g_font_px[i]), &cfg);
|
||||
if (g_font_px[i] == FONT_SIZE) font = app->faces[i];
|
||||
if (!font) font = app->faces[i];
|
||||
}
|
||||
{
|
||||
const char *slash = SDL_strrchr(path, '/');
|
||||
const char *bslash = SDL_strrchr(path, 92);
|
||||
const char *base = SDL_strrchr(FONT_BOLD_FILE, '/') + 1;
|
||||
char bpath[1024];
|
||||
|
||||
if (bslash > slash) slash = bslash;
|
||||
SDL_snprintf(bpath, sizeof(bpath), "%.*s%s",
|
||||
slash ? (int)(slash - path + 1) : 0, path, base);
|
||||
for (i = 0; i < FONT_STEPS; i++)
|
||||
app->bolds[i] = nk_font_atlas_add_from_file(
|
||||
atlas, bpath, (float)reaktor_px(g_font_px[i]), &cfg);
|
||||
app->face_bold = app->bolds[0];
|
||||
}
|
||||
for (i = 0; i < FONT_STEPS; i++)
|
||||
app->bolds[i] = nk_font_atlas_add_from_file(
|
||||
atlas, bpath, (float)reaktor_px(g_font_px[i]), &cfg);
|
||||
app->face_bold = app->bolds[0];
|
||||
if (!font)
|
||||
SDL_snprintf(app->font_status, sizeof(app->font_status),
|
||||
"FALLBACK (ProggyClean) - could not load %s", path);
|
||||
@@ -354,6 +367,7 @@ rebuild_font(App *app)
|
||||
|
||||
if (!font) {
|
||||
font = nk_font_atlas_add_default(atlas, (float)reaktor_px(FONT_SIZE), NULL);
|
||||
is_default = 1;
|
||||
} else {
|
||||
SDL_snprintf(app->font_status, sizeof(app->font_status),
|
||||
"Aileron, %d sizes %d-%dpx%s", FONT_STEPS,
|
||||
@@ -363,31 +377,11 @@ rebuild_font(App *app)
|
||||
|
||||
nk_sdl_font_stash_end(app->ctx);
|
||||
|
||||
{
|
||||
int i, is_face = 0;
|
||||
|
||||
for (i = 0; i < FONT_STEPS; i++)
|
||||
if (app->faces[i]) {
|
||||
app->faces[i]->handle.height = (float)g_font_px[i];
|
||||
if (app->faces[i] == font) is_face = 1;
|
||||
}
|
||||
for (i = 0; i < FONT_STEPS; i++)
|
||||
if (app->bolds[i])
|
||||
app->bolds[i]->handle.height = (float)g_font_px[i];
|
||||
if (font && !is_face) font->handle.height = (float)FONT_SIZE;
|
||||
}
|
||||
|
||||
{
|
||||
int i, done = 0;
|
||||
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
centre_glyphs_optically(app->faces[i]);
|
||||
if (app->faces[i] == font) done = 1;
|
||||
}
|
||||
for (i = 0; i < FONT_STEPS; i++)
|
||||
centre_glyphs_optically(app->bolds[i]);
|
||||
if (font && !done) centre_glyphs_optically(font);
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
finish_face(app->faces[i], (float)g_font_px[i], path);
|
||||
finish_face(app->bolds[i], (float)g_font_px[i], bpath);
|
||||
}
|
||||
if (is_default) finish_face(font, (float)FONT_SIZE, NULL);
|
||||
|
||||
nk_font_atlas_cleanup(atlas);
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
#define NK_INCLUDE_FONT_BAKING
|
||||
#define NK_INCLUDE_DEFAULT_FONT
|
||||
|
||||
/* Nuklear's default fires a button on press, which needs a frame
|
||||
* while the mouse is held. A browser delivers press and release in
|
||||
* one task, so that frame never happens and the button never fires. */
|
||||
/* A browser delivers press and release in one task. */
|
||||
#define NK_BUTTON_TRIGGER_ON_RELEASE
|
||||
|
||||
#include "../../external/nuklear/nuklear.h"
|
||||
|
||||
/* The caller SDL_frees the ranges. */
|
||||
nk_rune *reaktor_font_ranges(const unsigned char *ttf, const unsigned *cp,
|
||||
int n);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,3 +5,33 @@
|
||||
|
||||
#define NK_SDL3_RENDERER_IMPLEMENTATION
|
||||
#include "nk_sdl3_renderer.h"
|
||||
|
||||
nk_rune *
|
||||
reaktor_font_ranges(const unsigned char *ttf, const unsigned *cp, int n)
|
||||
{
|
||||
stbtt_fontinfo info;
|
||||
nk_rune *out;
|
||||
int i, at = 0, run = 0;
|
||||
|
||||
if (!ttf || n < 0 ||
|
||||
!stbtt_InitFont(&info, ttf, stbtt_GetFontOffsetForIndex(ttf, 0)))
|
||||
return NULL;
|
||||
out = SDL_malloc(((size_t)n * 2 + 3) * sizeof *out);
|
||||
if (!out) return NULL;
|
||||
|
||||
out[at++] = 0x0020;
|
||||
out[at++] = 0x00FF;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!stbtt_FindGlyphIndex(&info, (int)cp[i])) {
|
||||
run = 0;
|
||||
} else if (run && cp[i] == out[at - 1] + 1) {
|
||||
out[at - 1] = cp[i];
|
||||
} else {
|
||||
out[at++] = cp[i];
|
||||
out[at++] = cp[i];
|
||||
run = 1;
|
||||
}
|
||||
}
|
||||
out[at] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
/* nuklear - public domain */
|
||||
|
||||
/* VENDORED COPY - see docs/NOTICE.md.
|
||||
*
|
||||
* Nuklear's SDL3 backend, taken from external/nuklear/demo/sdl3_renderer/
|
||||
* and changed to bake and upload the font atlas 8-bit indexed rather than
|
||||
* RGBA32. It could not stay an include: the format is chosen inside
|
||||
* nk_sdl_font_stash_end, and this project does not edit submodules.
|
||||
*
|
||||
* Grep REAKTOR for the changed hunks. Re-vendoring means re-applying them.
|
||||
*/
|
||||
/* VENDORED COPY - see docs/NOTICE.md. Changes are marked REAKTOR. */
|
||||
|
||||
/*
|
||||
* ==============================================================
|
||||
@@ -48,7 +40,7 @@ NK_API void nk_sdl_font_stash_end(struct nk_context* ctx);
|
||||
#endif
|
||||
NK_API int nk_sdl_handle_event(struct nk_context* ctx, SDL_Event *evt);
|
||||
NK_API void nk_sdl_render(struct nk_context* ctx, enum nk_anti_aliasing);
|
||||
/* REAKTOR: fills and strokes feathered independently - see nk_sdl_render_ex. */
|
||||
/* REAKTOR: fill and stroke feathering apart. */
|
||||
NK_API void nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA, enum nk_anti_aliasing line_AA);
|
||||
NK_API void nk_sdl_update_TextInput(struct nk_context* ctx);
|
||||
NK_API void nk_sdl_shutdown(struct nk_context* ctx);
|
||||
@@ -56,6 +48,8 @@ NK_API nk_handle nk_sdl_get_userdata(struct nk_context* ctx);
|
||||
NK_API void nk_sdl_set_userdata(struct nk_context* ctx, nk_handle userdata);
|
||||
NK_API void nk_sdl_style_set_debug_font(struct nk_context* ctx);
|
||||
NK_API struct nk_allocator nk_sdl_allocator(void);
|
||||
/* REAKTOR: exported for the Text module. */
|
||||
NK_API bool nk_sdl_set_coverage_palette(SDL_Texture *tex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -78,13 +72,7 @@ struct nk_sdl_device {
|
||||
struct nk_buffer cmds;
|
||||
struct nk_draw_null_texture tex_null;
|
||||
SDL_Texture *font_tex;
|
||||
/* REAKTOR: the white texel Nuklear multiplies untextured geometry by.
|
||||
*
|
||||
* nk_font_atlas_end points tex_null at the atlas, so every draw command -
|
||||
* shapes as much as text - arrives carrying font_tex and the two cannot be
|
||||
* told apart by handle. Giving it a 1x1 texture of its own makes the
|
||||
* handle mean what it says, which is what the glyph snapping in
|
||||
* nk_sdl_render tests on. */
|
||||
/* REAKTOR: white texel for untextured geometry. */
|
||||
SDL_Texture *white_tex;
|
||||
};
|
||||
|
||||
@@ -161,10 +149,8 @@ nk_sdl_allocator()
|
||||
return allocator;
|
||||
}
|
||||
|
||||
/* REAKTOR: the palette that makes an INDEX8 atlas equal the RGBA32 one -
|
||||
* entry i is white at alpha i. SDL keeps its own reference, so this frees
|
||||
* ours. */
|
||||
static bool
|
||||
/* REAKTOR: entry i is white at alpha i. */
|
||||
NK_API bool
|
||||
nk_sdl_set_coverage_palette(SDL_Texture *tex)
|
||||
{
|
||||
SDL_Palette *pal = SDL_CreatePalette(256);
|
||||
@@ -201,18 +187,7 @@ nk_sdl_device_upload_atlas(struct nk_context* ctx, const void *image, int width,
|
||||
sdl->ogl.font_tex = NULL;
|
||||
}
|
||||
|
||||
/* REAKTOR: 8-bit indexed, not ARGB8888.
|
||||
*
|
||||
* A baked glyph is coverage: nk_font_bake_convert writes
|
||||
* ((alpha << 24) | 0x00FFFFFF) per pixel, so three of four bytes are a
|
||||
* constant and the color comes from the vertex. SDL3 has no A8 format,
|
||||
* so the alpha8 bake goes up as INDEX8 with a palette whose entry i is
|
||||
* white at alpha i - the same texture, a quarter the size. Every SDL3
|
||||
* backend registers INDEX8.
|
||||
*
|
||||
* Falling back matters: an indexed texture with no palette samples an
|
||||
* undefined one, which would put every glyph wrong with nothing to say
|
||||
* why. The conversion buffer is only allocated once indexed has lost. */
|
||||
/* REAKTOR: 8-bit indexed. */
|
||||
sdl->ogl.font_tex = SDL_CreateTexture(sdl->renderer, SDL_PIXELFORMAT_INDEX8, SDL_TEXTUREACCESS_STATIC, width, height);
|
||||
if (sdl->ogl.font_tex && !nk_sdl_set_coverage_palette(sdl->ogl.font_tex)) {
|
||||
SDL_DestroyTexture(sdl->ogl.font_tex);
|
||||
@@ -298,13 +273,7 @@ nk_sdl_render(struct nk_context* ctx, enum nk_anti_aliasing AA)
|
||||
nk_sdl_render_ex(ctx, AA, AA);
|
||||
}
|
||||
|
||||
/* REAKTOR: Nuklear feathers fills (shape_AA) and strokes (line_AA) separately,
|
||||
* and on a rasterizer with no partial coverage they fail differently. A fill's
|
||||
* feather is a ring half a pixel outside a fill shrunk by half a pixel; landed
|
||||
* whole it is a half-tone column between a panel's border and its fill, and a
|
||||
* rule between menu items. A stroke's feather is what grades a border's curve,
|
||||
* and it is also what covers the fill's staircase underneath. So the software
|
||||
* renderer wants strokes feathered and fills not, which one flag cannot say. */
|
||||
/* REAKTOR: fill and stroke feathering apart. */
|
||||
NK_API void
|
||||
nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
enum nk_anti_aliasing line_AA)
|
||||
@@ -350,12 +319,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
config.vertex_size = sizeof(struct nk_sdl_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex);
|
||||
config.tex_null = sdl->ogl.tex_null;
|
||||
/* REAKTOR: 22 was upstream's, and at that count a small circle is a
|
||||
* visible polygon on the software renderer, which cannot feather a
|
||||
* fill. The circles a page draws are Ionicons now (see showcase.c),
|
||||
* so this only reaches what Nuklear still draws itself and the
|
||||
* fallbacks for a glyph that failed to load - a few dozen more
|
||||
* vertices a frame, and none of them is a polygon. */
|
||||
/* REAKTOR: 22 upstream. */
|
||||
config.circle_segment_count = 48;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
@@ -368,24 +332,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
nk_buffer_init(&ebuf, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
|
||||
nk_convert(&sdl->ctx, &sdl->ogl.cmds, &vbuf, &ebuf, &config);
|
||||
|
||||
/* REAKTOR: on the software renderer, every vertex goes on the grid.
|
||||
*
|
||||
* SDL's software backend turns each vertex into a whole pixel by
|
||||
* truncation - SDL_render_sw.c does (int)(x * scale), and the
|
||||
* rasterizer below it works on integer SDL_Points. There is no partial
|
||||
* coverage anywhere in that path, which costs twice over: a rect whose
|
||||
* edge lands on .5 covers one row more or less than a GPU would (the
|
||||
* tab underline arriving as two lines with a gap, the top row of the
|
||||
* window a shade dark), and Nuklear's antialiasing - geometry a
|
||||
* fraction of a pixel wide, meant to be blended - lands whole, as a
|
||||
* hairline around every rounded rect.
|
||||
*
|
||||
* Storing round(x) + 0.5 answers both. SDL's truncation then lands on
|
||||
* round(x), which is what a hardware backend does, and the feather
|
||||
* collapses onto the pixel it was fading toward instead of onto its
|
||||
* neighbour. Both are the reason this is not done on hardware, where
|
||||
* the same rounding would flatten a feather that would otherwise have
|
||||
* blended - see the glyph snapping below. */
|
||||
/* REAKTOR: software vertices on the pixel grid. */
|
||||
is_sw = SDL_strcmp(SDL_GetRendererName(sdl->renderer), "software") == 0;
|
||||
if (is_sw) {
|
||||
nk_byte *v = (nk_byte *)nk_buffer_memory(&vbuf);
|
||||
@@ -406,8 +353,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
/* Ensure alpha blending is enabled for geometry rendering. */
|
||||
saved_blend = SDL_BLENDMODE_INVALID;
|
||||
SDL_GetRenderDrawBlendMode(sdl->renderer, &saved_blend);
|
||||
/* The fill fast path below writes the draw color, which belongs to
|
||||
* whoever set it - the clear, a frame from now. */
|
||||
/* REAKTOR: saved for the fill fast path. */
|
||||
SDL_GetRenderDrawColorFloat(sdl->renderer, &saved_r, &saved_g,
|
||||
&saved_b, &saved_a);
|
||||
SDL_SetRenderDrawBlendMode(sdl->renderer, SDL_BLENDMODE_BLEND);
|
||||
@@ -416,25 +362,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
{
|
||||
if (!cmd->elem_count) continue;
|
||||
|
||||
/* REAKTOR: glyph quads land on whole pixels here too.
|
||||
*
|
||||
* A glyph is a quad sampling the atlas. Nuklear advances the pen
|
||||
* by fractional widths, so a quad can start mid-pixel; hardware
|
||||
* then samples the atlas between texels and softens the glyph,
|
||||
* where the pass above has already put the software renderer on
|
||||
* the grid. Left alone that is most of what separates the two
|
||||
* backends - about twenty thousand pixels a page, all of it
|
||||
* against text.
|
||||
*
|
||||
* Rounding the quad here puts both on the same texel grid. It is
|
||||
* also what type rendering normally does: a bitmap baked for this
|
||||
* size, drawn 1:1 on the pixel grid, is what the baker intended.
|
||||
*
|
||||
* Shapes have to be left out of it, which is what white_tex is
|
||||
* for: nk_font_atlas_end points tex_null at the atlas, so without
|
||||
* a handle of its own this test matches every draw command and
|
||||
* rounds the feather flat - a hard stripe down the inside of
|
||||
* every panel. */
|
||||
/* REAKTOR: glyph quads on the pixel grid. */
|
||||
if (!is_sw && cmd->texture.ptr == (void *)sdl->ogl.font_tex) {
|
||||
nk_byte *v = (nk_byte *)nk_buffer_memory(&vbuf);
|
||||
nk_uint k;
|
||||
@@ -458,39 +386,12 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
{
|
||||
const void *vertices = nk_buffer_memory_const(&vbuf);
|
||||
|
||||
/* REAKTOR: shapes ask for no texture at all.
|
||||
*
|
||||
* white_tex is one opaque white texel, and sampling it
|
||||
* multiplies the vertex color by one - the same pixels a
|
||||
* null texture draws. A GPU does not care either way. A CPU
|
||||
* rasterizer does: the same full-window quad costs 6.95 ms
|
||||
* as textured geometry and 16.38 ms textured and blended,
|
||||
* against 0.12 ms for the fill it amounts to. Handing the
|
||||
* renderer NULL takes the sampler out of the inner loop for
|
||||
* every shape, which is every panel, row and border. Text
|
||||
* still arrives with font_tex and is untouched. */
|
||||
/* REAKTOR: shapes untextured. */
|
||||
SDL_Texture *tex = (SDL_Texture *)cmd->texture.ptr;
|
||||
|
||||
if (tex == sdl->ogl.white_tex) tex = NULL;
|
||||
|
||||
/* REAKTOR: an axis-aligned quad of one color is a fill, not
|
||||
* two triangles.
|
||||
*
|
||||
* nk_convert flattens every shape to triangles, and a CPU
|
||||
* rasterizer pays for that literally: the same full-window
|
||||
* coverage costs 6.95 ms walked as geometry against 0.12 ms
|
||||
* as a fill. An empty window is exactly this command and
|
||||
* nothing else - one quad, six indices - and so is most of
|
||||
* what a real page draws, every panel, row and separator
|
||||
* among them.
|
||||
*
|
||||
* Six indices, no texture and one color across all of them is
|
||||
* the whole test. It cannot match a rounded rect or an
|
||||
* antialiased edge, because Nuklear feathers those into more
|
||||
* geometry than this, and it cannot match a gradient, because
|
||||
* the colors would differ. Hardware is left alone: it draws
|
||||
* triangles for free and the rounding below is only applied
|
||||
* to the software path. */
|
||||
/* REAKTOR: one-color quads as fills. */
|
||||
if (is_sw && tex == NULL && cmd->elem_count == 6) {
|
||||
const nk_byte *vb = (const nk_byte *)vertices;
|
||||
const float *pos[6];
|
||||
@@ -524,9 +425,6 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
if (!(x1 > x0 && y1 > y0)) ok = 0;
|
||||
}
|
||||
|
||||
/* Every vertex on a corner, and all four corners used:
|
||||
* anything else is a shape that happens to have six
|
||||
* indices, not the rectangle they would describe. */
|
||||
if (ok) {
|
||||
for (k = 0; k < 6; k++) {
|
||||
int cx = pos[k][0] == x1;
|
||||
@@ -544,11 +442,6 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
|
||||
if (ok) {
|
||||
SDL_FRect fr;
|
||||
/* Thin rules are left to blend. A one pixel high
|
||||
* fill lands differently without it - the separators
|
||||
* on the Buttons page move a shade - and they cost
|
||||
* nothing to draw either way. Area is where the
|
||||
* saving is, and where the two agree. */
|
||||
int opaque = c0[3] >= 1.0f &&
|
||||
x1 - x0 >= 2.0f && y1 - y0 >= 2.0f;
|
||||
|
||||
@@ -557,11 +450,6 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
fr.w = x1 - x0;
|
||||
fr.h = y1 - y0;
|
||||
|
||||
/* Source-over with an alpha of one is the source, so
|
||||
* an opaque fill has nothing to read the destination
|
||||
* for. Saying so is most of the saving: the blend is
|
||||
* a read-modify-write per pixel and the write is not.
|
||||
*/
|
||||
if (opaque)
|
||||
SDL_SetRenderDrawBlendMode(sdl->renderer,
|
||||
SDL_BLENDMODE_NONE);
|
||||
@@ -715,15 +603,12 @@ nk_sdl_font_stash_end(struct nk_context* ctx)
|
||||
NK_ASSERT(ctx);
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
/* REAKTOR: alpha8, to match the upload. Also keeps the 4x RGBA buffer out
|
||||
* of the startup peak - the bake holds it live alongside the alpha8 one. */
|
||||
/* REAKTOR: alpha8. */
|
||||
image = nk_font_atlas_bake(&sdl->atlas, &w, &h, NK_FONT_ATLAS_ALPHA8);
|
||||
NK_ASSERT(image);
|
||||
nk_sdl_device_upload_atlas(&sdl->ctx, image, w, h);
|
||||
nk_font_atlas_end(&sdl->atlas, nk_handle_ptr(sdl->ogl.font_tex), &sdl->ogl.tex_null);
|
||||
/* REAKTOR: see white_tex in struct nk_sdl_device. If it cannot be made,
|
||||
* tex_null keeps pointing at the atlas and everything still draws - only
|
||||
* the glyph test in nk_sdl_render loses its precision. */
|
||||
/* REAKTOR: see white_tex. */
|
||||
if (!sdl->ogl.white_tex) {
|
||||
Uint32 px = 0xFFFFFFFFu;
|
||||
sdl->ogl.white_tex = SDL_CreateTexture(sdl->renderer,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#define KB_TEXT_SHAPE_IMPLEMENTATION
|
||||
#include "kb_text_shape.h"
|
||||
@@ -0,0 +1,947 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "nk_common.h"
|
||||
#include "nk_sdl3_renderer.h"
|
||||
#include "text.h"
|
||||
|
||||
#include "../../external/nuklear/src/stb_truetype.h"
|
||||
#include "kb_text_shape.h"
|
||||
#include "mojibake.h"
|
||||
|
||||
#define FONTS_MAX 16
|
||||
#define FACES_MAX 32
|
||||
#define CONFIGS_MAX 64
|
||||
#define BUCKETS 4096
|
||||
#define SHAPED_MAX (1 << 15)
|
||||
#define SLOTS_MAX (1 << 14)
|
||||
#define PAGE 512
|
||||
#define PAGES_MAX 8
|
||||
|
||||
typedef char text_command_fits[
|
||||
offsetof(struct nk_command_text, string) >= sizeof(struct nk_command_custom)
|
||||
? 1 : -1];
|
||||
|
||||
typedef struct text_font {
|
||||
char path[1024];
|
||||
char name[64];
|
||||
unsigned char *data;
|
||||
int state;
|
||||
stbtt_fontinfo info;
|
||||
kbts_font kb;
|
||||
float unit;
|
||||
Uint8 *drawn;
|
||||
int drawn_n;
|
||||
} text_font;
|
||||
|
||||
typedef struct text_face {
|
||||
struct nk_font *font;
|
||||
int file;
|
||||
int baseline_known;
|
||||
float baseline;
|
||||
nk_text_width_f atlas_width;
|
||||
} text_face;
|
||||
|
||||
typedef struct shaped {
|
||||
float x, y;
|
||||
Uint16 id;
|
||||
Uint8 font;
|
||||
} shaped;
|
||||
|
||||
typedef struct shape_entry {
|
||||
Uint32 hash;
|
||||
int file, len, text;
|
||||
int glyph, glyphs, next;
|
||||
float width;
|
||||
} shape_entry;
|
||||
|
||||
typedef struct text_char {
|
||||
int cp, font;
|
||||
kbts_script script;
|
||||
Uint8 level, start;
|
||||
} text_char;
|
||||
|
||||
typedef struct text_run {
|
||||
int from, to, font;
|
||||
Uint8 level;
|
||||
kbts_script script;
|
||||
} text_run;
|
||||
|
||||
typedef struct kb_config {
|
||||
int font;
|
||||
kbts_script script;
|
||||
kbts_shape_config *shape;
|
||||
kbts_glyph_config *glyph;
|
||||
kbts_shape_scratchpad *scratch;
|
||||
} kb_config;
|
||||
|
||||
typedef struct glyph_slot {
|
||||
Uint32 key;
|
||||
Sint16 left, top;
|
||||
Uint16 x, y, w, h;
|
||||
Uint8 page;
|
||||
} glyph_slot;
|
||||
|
||||
typedef struct glyph_page {
|
||||
SDL_Texture *tex;
|
||||
int argb;
|
||||
int x, y, row;
|
||||
} glyph_page;
|
||||
|
||||
typedef struct text_draw {
|
||||
int face, len;
|
||||
float height;
|
||||
struct nk_color fg;
|
||||
const char *text;
|
||||
} text_draw;
|
||||
|
||||
static text_font g_font[FONTS_MAX];
|
||||
static int g_fonts;
|
||||
static int g_fallback[FONTS_MAX];
|
||||
static int g_fallbacks;
|
||||
static struct nk_allocator g_raster;
|
||||
|
||||
static text_face g_face[FACES_MAX];
|
||||
static int g_faces;
|
||||
|
||||
static shape_entry *g_entry;
|
||||
static shaped *g_glyph;
|
||||
static char *g_bytes;
|
||||
static int g_entries, g_entry_cap, g_glyphs, g_glyph_cap;
|
||||
static int g_byte_n, g_byte_cap;
|
||||
static int g_bucket[BUCKETS];
|
||||
|
||||
static text_char *g_ch;
|
||||
static text_run *g_run;
|
||||
static int *g_order;
|
||||
static int g_ch_cap, g_run_cap, g_order_cap;
|
||||
|
||||
static kb_config g_config[CONFIGS_MAX];
|
||||
static int g_configs;
|
||||
static kbts_glyph_storage g_storage;
|
||||
|
||||
static glyph_slot *g_slot;
|
||||
static int g_slot_cap, g_slots, g_full;
|
||||
static glyph_page g_page[PAGES_MAX];
|
||||
static int g_pages, g_page_at;
|
||||
static Uint8 *g_bitmap;
|
||||
static Uint32 *g_pixels;
|
||||
static int g_bitmap_cap, g_pixel_cap;
|
||||
|
||||
static SDL_Renderer *g_renderer;
|
||||
static text_draw *g_draw;
|
||||
static int g_draws, g_draw_cap;
|
||||
static unsigned g_seq;
|
||||
static int g_seq_known, g_took;
|
||||
|
||||
static void *
|
||||
grow(void *p, int *cap, int need, size_t size)
|
||||
{
|
||||
int n = *cap > 0 ? *cap : 64;
|
||||
|
||||
if (need <= *cap) return p;
|
||||
while (n < need) n *= 2;
|
||||
p = SDL_realloc(p, (size_t)n * size);
|
||||
if (p) *cap = n;
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
font_add(const char *path)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_fonts; i++)
|
||||
if (SDL_strcmp(g_font[i].path, path) == 0) return i;
|
||||
if (g_fonts == FONTS_MAX || SDL_strlen(path) >= sizeof g_font[0].path)
|
||||
return -1;
|
||||
SDL_zero(g_font[g_fonts]);
|
||||
SDL_strlcpy(g_font[g_fonts].path, path, sizeof g_font[0].path);
|
||||
return g_fonts++;
|
||||
}
|
||||
|
||||
static void
|
||||
font_name(text_font *f)
|
||||
{
|
||||
const char *s, *base, *dot;
|
||||
int len = 0, i, at = 0;
|
||||
|
||||
s = stbtt_GetFontNameString(&f->info, &len, STBTT_PLATFORM_ID_MICROSOFT,
|
||||
STBTT_MS_EID_UNICODE_BMP, STBTT_MS_LANG_ENGLISH, 1);
|
||||
for (i = 0; s && i + 1 < len && at + 1 < (int)sizeof f->name; i += 2)
|
||||
if (s[i] == 0 && s[i + 1] >= 0x20 && s[i + 1] < 0x7F)
|
||||
f->name[at++] = s[i + 1];
|
||||
f->name[at] = 0;
|
||||
if (at > 0) return;
|
||||
base = SDL_strrchr(f->path, '/');
|
||||
if (SDL_strrchr(f->path, 92) > base) base = SDL_strrchr(f->path, 92);
|
||||
base = base ? base + 1 : f->path;
|
||||
dot = SDL_strrchr(base, '.');
|
||||
SDL_snprintf(f->name, sizeof f->name, "%.*s",
|
||||
dot ? (int)(dot - base) : (int)SDL_strlen(base), base);
|
||||
}
|
||||
|
||||
static int
|
||||
font_open(int i)
|
||||
{
|
||||
text_font *f = &g_font[i];
|
||||
size_t size = 0;
|
||||
int at;
|
||||
|
||||
if (f->state) return f->state > 0;
|
||||
f->state = -1;
|
||||
f->data = SDL_LoadFile(f->path, &size);
|
||||
if (f->data && size <= (size_t)SDL_MAX_SINT32) {
|
||||
at = stbtt_GetFontOffsetForIndex(f->data, 0);
|
||||
if (at >= 0 && stbtt_InitFont(&f->info, f->data, at)) {
|
||||
/* Nuklear's stb_truetype allocates through userdata. */
|
||||
if (!g_raster.alloc) g_raster = nk_sdl_allocator();
|
||||
f->info.userdata = &g_raster;
|
||||
f->kb = kbts_FontFromMemory(f->data, (int)size, 0, NULL, NULL);
|
||||
if (kbts_FontIsValid(&f->kb)) {
|
||||
f->unit = stbtt_ScaleForPixelHeight(&f->info, 1.0f);
|
||||
f->state = 1;
|
||||
font_name(f);
|
||||
return 1;
|
||||
}
|
||||
kbts_FreeFont(&f->kb);
|
||||
}
|
||||
}
|
||||
SDL_Log("text: could not open the font %s", f->path);
|
||||
SDL_free(f->data);
|
||||
f->data = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_add_fallback(const char *path)
|
||||
{
|
||||
int i = path ? font_add(path) : -1;
|
||||
|
||||
if (i >= 0 && g_fallbacks < FONTS_MAX) g_fallback[g_fallbacks++] = i;
|
||||
}
|
||||
|
||||
static int
|
||||
face_of(const struct nk_font *font)
|
||||
{
|
||||
static int last;
|
||||
int i;
|
||||
|
||||
if (last < g_faces && g_face[last].font == font) return last;
|
||||
for (i = 0; i < g_faces; i++)
|
||||
if (g_face[i].font == font) return last = i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
atlas_draws(const struct nk_font *font, const char *s, int len)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < len) {
|
||||
const struct nk_font_glyph *g;
|
||||
nk_rune cp;
|
||||
int n;
|
||||
|
||||
if (!((unsigned char)s[i] & 0x80)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
n = nk_utf_decode(s + i, &cp, len - i);
|
||||
if (n <= 0) return 1;
|
||||
g = nk_font_find_glyph(font, cp);
|
||||
if (g == font->fallback && cp != font->fallback_codepoint) return 0;
|
||||
i += n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static float
|
||||
baseline(text_face *f)
|
||||
{
|
||||
const struct nk_font_glyph *x;
|
||||
text_font *t = &g_font[f->file];
|
||||
float scale;
|
||||
int x0, y0, x1, y1;
|
||||
|
||||
if (f->baseline_known) return f->baseline;
|
||||
f->baseline_known = 1;
|
||||
f->baseline = f->font->info.ascent + 0.5f;
|
||||
x = nk_font_find_glyph(f->font, 'x');
|
||||
if (x && x != f->font->fallback && font_open(f->file)) {
|
||||
scale = stbtt_ScaleForPixelHeight(&t->info, f->font->info.height);
|
||||
stbtt_GetCodepointBitmapBox(&t->info, 'x', scale, scale, &x0, &y0, &x1, &y1);
|
||||
f->baseline = x->y1 - (float)y1;
|
||||
}
|
||||
return f->baseline;
|
||||
}
|
||||
|
||||
static int
|
||||
decode(const char *s, int len)
|
||||
{
|
||||
text_char *p;
|
||||
int n = 0, at = 0;
|
||||
|
||||
if (!(p = grow(g_ch, &g_ch_cap, len, sizeof *g_ch))) return 0;
|
||||
g_ch = p;
|
||||
while (at < len) {
|
||||
kbts_decode d = kbts_DecodeUtf8(s + at, (kbts_un)(len - at));
|
||||
|
||||
SDL_zero(g_ch[n]);
|
||||
g_ch[n++].cp = d.Valid ? d.Codepoint : 0xFFFD;
|
||||
at += d.SourceCharactersConsumed > 0 ? d.SourceCharactersConsumed : 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
levels(const char *s, int len, int n)
|
||||
{
|
||||
mjb_bidi_paragraph p;
|
||||
int i, k = 0;
|
||||
|
||||
for (i = 0; i < n && g_ch[i].cp < 0x0590; i++) {}
|
||||
if (i == n ||
|
||||
mjb_bidi_resolve(s, (size_t)len, MJB_ENC_UTF_8, MJB_DIRECTION_AUTO, &p)
|
||||
!= MJB_STATUS_OK)
|
||||
return;
|
||||
/* mojibake 0.3.6 puts byte_offset at a character's last byte. */
|
||||
for (i = 0; i < n; i++) {
|
||||
if (k < (int)p.count && (int)p.chars[k].codepoint == g_ch[i].cp)
|
||||
g_ch[i].level = p.chars[k++].level;
|
||||
else
|
||||
g_ch[i].level = i > 0 ? g_ch[i - 1].level : p.paragraph_level;
|
||||
}
|
||||
mjb_bidi_paragraph_free(&p);
|
||||
}
|
||||
|
||||
static void
|
||||
segment(int n)
|
||||
{
|
||||
kbts_break_state st;
|
||||
kbts_break b;
|
||||
kbts_script known = KBTS_SCRIPT_DONT_KNOW;
|
||||
int i;
|
||||
|
||||
kbts_BreakBegin(&st, KBTS_DIRECTION_DONT_KNOW,
|
||||
KBTS_JAPANESE_LINE_BREAK_STYLE_NORMAL, 0);
|
||||
for (i = 0; i < n; i++) {
|
||||
kbts_BreakAddCodepoint(&st, g_ch[i].cp, 1, i == n - 1);
|
||||
while (kbts_Break(&st, &b)) {
|
||||
if (b.Position < 0 || b.Position >= n) continue;
|
||||
if (b.Flags & KBTS_BREAK_FLAG_GRAPHEME) g_ch[b.Position].start = 1;
|
||||
if (b.Flags & KBTS_BREAK_FLAG_SCRIPT) g_ch[b.Position].script = b.Script;
|
||||
}
|
||||
}
|
||||
g_ch[0].start = 1;
|
||||
for (i = 0; i < n && known == KBTS_SCRIPT_DONT_KNOW; i++) known = g_ch[i].script;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (g_ch[i].script != KBTS_SCRIPT_DONT_KNOW) known = g_ch[i].script;
|
||||
else g_ch[i].script = known;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
covers(int font, int from, int to)
|
||||
{
|
||||
kbts_font_coverage_test t;
|
||||
int i;
|
||||
|
||||
kbts_FontCoverageTestBegin(&t, &g_font[font].kb);
|
||||
for (i = from; i < to; i++) kbts_FontCoverageTestCodepoint(&t, g_ch[i].cp);
|
||||
return kbts_FontCoverageTestEnd(&t);
|
||||
}
|
||||
|
||||
static int
|
||||
first_covering(int base, int from, int to)
|
||||
{
|
||||
int k;
|
||||
|
||||
if (covers(base, from, to)) return base;
|
||||
for (k = 0; k < g_fallbacks; k++)
|
||||
if (font_open(g_fallback[k]) && covers(g_fallback[k], from, to))
|
||||
return g_fallback[k];
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
choose_fonts(int base, int n)
|
||||
{
|
||||
int i, j, k, pick;
|
||||
|
||||
for (i = 0; i < n; i = j) {
|
||||
for (j = i + 1; j < n && !g_ch[j].start; j++) {}
|
||||
pick = first_covering(base, i, j);
|
||||
if (pick < 0 && j > i + 1) pick = first_covering(base, i, i + 1);
|
||||
if (pick < 0) pick = i > 0 ? g_ch[i - 1].font : base;
|
||||
for (k = i; k < j; k++) g_ch[k].font = pick;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
split(int n)
|
||||
{
|
||||
text_run *p;
|
||||
int i, r = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (r == 0 || g_ch[i].level != g_ch[i - 1].level ||
|
||||
g_ch[i].script != g_ch[i - 1].script ||
|
||||
g_ch[i].font != g_ch[i - 1].font) {
|
||||
if ((p = grow(g_run, &g_run_cap, r + 1, sizeof *g_run)) != NULL) {
|
||||
g_run = p;
|
||||
g_run[r].from = i;
|
||||
g_run[r].font = g_ch[i].font;
|
||||
g_run[r].level = g_ch[i].level;
|
||||
g_run[r].script = g_ch[i].script;
|
||||
r++;
|
||||
} else if (r == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
g_run[r - 1].to = i + 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
order(int runs)
|
||||
{
|
||||
int hi = 0, lo = 256, lv, i, j, a, b, t;
|
||||
|
||||
for (i = 0; i < runs; i++) {
|
||||
g_order[i] = i;
|
||||
if (g_run[i].level > hi) hi = g_run[i].level;
|
||||
if ((g_run[i].level & 1) && g_run[i].level < lo) lo = g_run[i].level;
|
||||
}
|
||||
for (lv = hi; lv >= lo; lv--) {
|
||||
for (i = 0; i < runs;) {
|
||||
if (g_run[g_order[i]].level < lv) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
for (j = i; j < runs && g_run[g_order[j]].level >= lv; j++) {}
|
||||
for (a = i, b = j - 1; a < b; a++, b--) {
|
||||
t = g_order[a];
|
||||
g_order[a] = g_order[b];
|
||||
g_order[b] = t;
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
config_free(kb_config *c)
|
||||
{
|
||||
if (c->scratch) kbts_DestroyShapeScratchpad(c->scratch);
|
||||
if (c->glyph) kbts_DestroyGlyphConfig(c->glyph);
|
||||
if (c->shape) kbts_DestroyShapeConfig(c->shape);
|
||||
SDL_zerop(c);
|
||||
}
|
||||
|
||||
static kb_config *
|
||||
config_for(int font, kbts_script script)
|
||||
{
|
||||
kbts_feature_override plain;
|
||||
kb_config *c = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_configs && !c; i++)
|
||||
if (g_config[i].font == font && g_config[i].script == script)
|
||||
c = &g_config[i];
|
||||
if (c && c->scratch) return c;
|
||||
if (!c) {
|
||||
if (g_configs == CONFIGS_MAX) {
|
||||
for (i = 0; i < g_configs; i++) config_free(&g_config[i]);
|
||||
g_configs = 0;
|
||||
}
|
||||
c = &g_config[g_configs];
|
||||
c->font = font;
|
||||
c->script = script;
|
||||
c->shape = kbts_CreateShapeConfig(&g_font[font].kb, script,
|
||||
KBTS_LANGUAGE_DONT_KNOW, NULL, NULL);
|
||||
plain.Tag = KBTS_FEATURE_TAG_kern;
|
||||
plain.Value = 0;
|
||||
c->glyph = c->shape ? kbts_CreateGlyphConfig(c->shape, &plain, 1, NULL, NULL)
|
||||
: NULL;
|
||||
if (!c->glyph) {
|
||||
config_free(c);
|
||||
return NULL;
|
||||
}
|
||||
g_configs++;
|
||||
}
|
||||
c->scratch = kbts_CreateShapeScratchpad(c->shape, NULL, NULL);
|
||||
return c->scratch ? c : NULL;
|
||||
}
|
||||
|
||||
static float
|
||||
shape_run(const text_run *r, float pen)
|
||||
{
|
||||
text_font *f = &g_font[r->font];
|
||||
kb_config *c = config_for(r->font, r->script);
|
||||
kbts_glyph_iterator it;
|
||||
kbts_glyph *g;
|
||||
shaped *out;
|
||||
void *p;
|
||||
int i;
|
||||
|
||||
if (!c) return pen;
|
||||
kbts_ClearActiveGlyphs(&g_storage);
|
||||
for (i = r->from; i < r->to; i++)
|
||||
if (!kbts_PushGlyph(&g_storage, &f->kb, g_ch[i].cp, c->glyph, i)) return pen;
|
||||
if (kbts_ShapeDirect(c->scratch, &g_storage,
|
||||
(r->level & 1) ? KBTS_DIRECTION_RTL : KBTS_DIRECTION_LTR,
|
||||
&it) != KBTS_SHAPE_ERROR_NONE) {
|
||||
/* A scratchpad keeps its error. */
|
||||
kbts_DestroyShapeScratchpad(c->scratch);
|
||||
c->scratch = NULL;
|
||||
return pen;
|
||||
}
|
||||
while (kbts_GlyphIteratorNext(&it, &g)) {
|
||||
if (!(p = grow(g_glyph, &g_glyph_cap, g_glyphs + 1, sizeof *g_glyph)))
|
||||
break;
|
||||
g_glyph = p;
|
||||
out = &g_glyph[g_glyphs++];
|
||||
out->x = pen + (float)g->OffsetX * f->unit;
|
||||
out->y = (float)g->OffsetY * f->unit;
|
||||
out->id = g->Id;
|
||||
out->font = (Uint8)r->font;
|
||||
pen += (float)g->AdvanceX * f->unit;
|
||||
}
|
||||
return pen;
|
||||
}
|
||||
|
||||
static int
|
||||
shape(int file, const char *s, int len)
|
||||
{
|
||||
shape_entry *e;
|
||||
Uint32 hash = 2166136261u ^ (Uint32)file;
|
||||
void *p;
|
||||
float pen = 0.0f;
|
||||
int i, n, runs, first;
|
||||
|
||||
for (i = 0; i < len; i++) hash = (hash ^ (Uint8)s[i]) * 16777619u;
|
||||
for (i = g_bucket[hash & (BUCKETS - 1)]; i > 0; i = g_entry[i - 1].next) {
|
||||
e = &g_entry[i - 1];
|
||||
if (e->hash == hash && e->file == file && e->len == len &&
|
||||
SDL_memcmp(g_bytes + e->text, s, (size_t)len) == 0)
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
if (len <= 0 || !font_open(file) || (n = decode(s, len)) <= 0) return -1;
|
||||
levels(s, len, n);
|
||||
segment(n);
|
||||
choose_fonts(file, n);
|
||||
runs = split(n);
|
||||
if (!(p = grow(g_order, &g_order_cap, runs, sizeof *g_order))) return -1;
|
||||
g_order = p;
|
||||
order(runs);
|
||||
if (!(p = grow(g_entry, &g_entry_cap, g_entries + 1, sizeof *g_entry))) return -1;
|
||||
g_entry = p;
|
||||
if (!(p = grow(g_bytes, &g_byte_cap, g_byte_n + len, 1))) return -1;
|
||||
g_bytes = p;
|
||||
|
||||
first = g_glyphs;
|
||||
for (i = 0; i < runs; i++) pen = shape_run(&g_run[g_order[i]], pen);
|
||||
|
||||
e = &g_entry[g_entries];
|
||||
e->hash = hash;
|
||||
e->file = file;
|
||||
e->len = len;
|
||||
e->text = g_byte_n;
|
||||
e->glyph = first;
|
||||
e->glyphs = g_glyphs - first;
|
||||
e->width = pen;
|
||||
e->next = g_bucket[hash & (BUCKETS - 1)];
|
||||
g_bucket[hash & (BUCKETS - 1)] = g_entries + 1;
|
||||
SDL_memcpy(g_bytes + g_byte_n, s, (size_t)len);
|
||||
g_byte_n += len;
|
||||
return g_entries++;
|
||||
}
|
||||
|
||||
static void
|
||||
shapes_forget(void)
|
||||
{
|
||||
SDL_free(g_entry);
|
||||
SDL_free(g_glyph);
|
||||
SDL_free(g_bytes);
|
||||
g_entry = NULL;
|
||||
g_glyph = NULL;
|
||||
g_bytes = NULL;
|
||||
g_entries = g_entry_cap = g_glyphs = g_glyph_cap = g_byte_n = g_byte_cap = 0;
|
||||
SDL_memset(g_bucket, 0, sizeof g_bucket);
|
||||
}
|
||||
|
||||
static int
|
||||
page_new(void)
|
||||
{
|
||||
glyph_page *p = &g_page[g_pages];
|
||||
SDL_Texture *tex;
|
||||
|
||||
if (g_pages == PAGES_MAX || !g_renderer) return 0;
|
||||
SDL_zerop(p);
|
||||
tex = SDL_CreateTexture(g_renderer, SDL_PIXELFORMAT_INDEX8,
|
||||
SDL_TEXTUREACCESS_STATIC, PAGE, PAGE);
|
||||
if (tex && !nk_sdl_set_coverage_palette(tex)) {
|
||||
SDL_DestroyTexture(tex);
|
||||
tex = NULL;
|
||||
}
|
||||
if (!tex) {
|
||||
tex = SDL_CreateTexture(g_renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STATIC, PAGE, PAGE);
|
||||
p->argb = 1;
|
||||
}
|
||||
if (!tex) return 0;
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
|
||||
p->tex = tex;
|
||||
g_pages++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
pack(int w, int h, int *x, int *y)
|
||||
{
|
||||
glyph_page *p = g_page_at > 0 ? &g_page[g_page_at - 1] : NULL;
|
||||
|
||||
if (w + 2 > PAGE || h + 2 > PAGE) return -1;
|
||||
if (p && p->x + w + 2 > PAGE) {
|
||||
p->x = 0;
|
||||
p->y += p->row;
|
||||
p->row = 0;
|
||||
}
|
||||
if (!p || p->y + h + 2 > PAGE) {
|
||||
if (g_page_at == g_pages && !page_new()) return -1;
|
||||
p = &g_page[g_page_at++];
|
||||
p->x = p->y = p->row = 0;
|
||||
}
|
||||
*x = p->x + 1;
|
||||
*y = p->y + 1;
|
||||
p->x += w + 2;
|
||||
if (h + 2 > p->row) p->row = h + 2;
|
||||
return g_page_at - 1;
|
||||
}
|
||||
|
||||
static int
|
||||
upload(int page, int x, int y, int w, int h, text_font *f, int id, float scale)
|
||||
{
|
||||
SDL_Rect r;
|
||||
void *p;
|
||||
int bw = w + 2, bh = h + 2, i;
|
||||
|
||||
if (!(p = grow(g_bitmap, &g_bitmap_cap, bw * bh, 1))) return 0;
|
||||
g_bitmap = p;
|
||||
SDL_memset(g_bitmap, 0, (size_t)(bw * bh));
|
||||
stbtt_MakeGlyphBitmap(&f->info, g_bitmap + bw + 1, w, h, bw, scale, scale, id);
|
||||
r.x = x - 1;
|
||||
r.y = y - 1;
|
||||
r.w = bw;
|
||||
r.h = bh;
|
||||
if (!g_page[page].argb)
|
||||
return SDL_UpdateTexture(g_page[page].tex, &r, g_bitmap, bw);
|
||||
if (!(p = grow(g_pixels, &g_pixel_cap, bw * bh, sizeof *g_pixels))) return 0;
|
||||
g_pixels = p;
|
||||
for (i = 0; i < bw * bh; i++)
|
||||
g_pixels[i] = (Uint32)g_bitmap[i] << 24 | 0x00FFFFFF;
|
||||
return SDL_UpdateTexture(g_page[page].tex, &r, g_pixels, bw * 4);
|
||||
}
|
||||
|
||||
static glyph_slot *
|
||||
slot_at(glyph_slot *table, int cap, Uint32 key)
|
||||
{
|
||||
int i = (int)(((key * 2654435761u) >> 16) & (Uint32)(cap - 1));
|
||||
|
||||
while (table[i].key && table[i].key != key) i = (i + 1) & (cap - 1);
|
||||
return &table[i];
|
||||
}
|
||||
|
||||
static int
|
||||
slots_grow(void)
|
||||
{
|
||||
int cap = g_slot_cap ? g_slot_cap * 2 : 1024, i;
|
||||
glyph_slot *t;
|
||||
|
||||
if (cap > SLOTS_MAX || !(t = SDL_calloc((size_t)cap, sizeof *t))) return 0;
|
||||
for (i = 0; i < g_slot_cap; i++)
|
||||
if (g_slot[i].key) *slot_at(t, cap, g_slot[i].key) = g_slot[i];
|
||||
SDL_free(g_slot);
|
||||
g_slot = t;
|
||||
g_slot_cap = cap;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const glyph_slot *
|
||||
glyph_get(int font, int id, int px)
|
||||
{
|
||||
text_font *f = &g_font[font];
|
||||
glyph_slot *s;
|
||||
Uint32 key;
|
||||
float scale;
|
||||
int x0, y0, x1, y1, x = 0, y = 0, page = 0;
|
||||
|
||||
if (px < 1) px = 1;
|
||||
if (px > 4095) px = 4095;
|
||||
key = (Uint32)font << 28 | (Uint32)px << 16 | (Uint32)id;
|
||||
if (!g_slot && !slots_grow()) return NULL;
|
||||
s = slot_at(g_slot, g_slot_cap, key);
|
||||
if (s->key) return s;
|
||||
if (g_slots + 1 > g_slot_cap / 4 * 3) {
|
||||
if (!slots_grow()) {
|
||||
g_full = 1;
|
||||
return NULL;
|
||||
}
|
||||
s = slot_at(g_slot, g_slot_cap, key);
|
||||
}
|
||||
|
||||
scale = stbtt_ScaleForPixelHeight(&f->info, (float)px);
|
||||
stbtt_GetGlyphBitmapBox(&f->info, id, scale, scale, &x0, &y0, &x1, &y1);
|
||||
if (x1 > x0 && y1 > y0) {
|
||||
page = pack(x1 - x0, y1 - y0, &x, &y);
|
||||
if (page < 0) {
|
||||
g_full = 1;
|
||||
return NULL;
|
||||
}
|
||||
if (!upload(page, x, y, x1 - x0, y1 - y0, f, id, scale)) return NULL;
|
||||
} else {
|
||||
x1 = x0;
|
||||
y1 = y0;
|
||||
}
|
||||
s->key = key;
|
||||
s->left = (Sint16)x0;
|
||||
s->top = (Sint16)y0;
|
||||
s->x = (Uint16)x;
|
||||
s->y = (Uint16)y;
|
||||
s->w = (Uint16)(x1 - x0);
|
||||
s->h = (Uint16)(y1 - y0);
|
||||
s->page = (Uint8)page;
|
||||
g_slots++;
|
||||
return s;
|
||||
}
|
||||
|
||||
static void
|
||||
glyphs_forget(void)
|
||||
{
|
||||
SDL_free(g_slot);
|
||||
g_slot = NULL;
|
||||
g_slot_cap = g_slots = g_page_at = g_full = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mark_drawn(int font, int id)
|
||||
{
|
||||
text_font *f = &g_font[font];
|
||||
|
||||
if (!f->drawn && !(f->drawn = SDL_calloc(8192, 1))) return;
|
||||
if (f->drawn[id >> 3] & (1 << (id & 7))) return;
|
||||
f->drawn[id >> 3] |= (Uint8)(1 << (id & 7));
|
||||
f->drawn_n++;
|
||||
}
|
||||
|
||||
static float
|
||||
measure(nk_handle handle, float height, const char *s, int len)
|
||||
{
|
||||
const struct nk_font *font = (const struct nk_font *)handle.ptr;
|
||||
int face = face_of(font), e = -1;
|
||||
|
||||
if (face < 0) return 0.0f;
|
||||
if (!atlas_draws(font, s, len)) {
|
||||
g_took = 1;
|
||||
e = shape(g_face[face].file, s, len);
|
||||
}
|
||||
return e < 0 ? g_face[face].atlas_width(handle, height, s, len)
|
||||
: g_entry[e].width * height;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_attach_font(struct nk_font *font, const char *path)
|
||||
{
|
||||
text_face *f;
|
||||
int file;
|
||||
|
||||
if (!font) {
|
||||
g_faces = g_draws = g_seq_known = 0;
|
||||
glyphs_forget();
|
||||
return;
|
||||
}
|
||||
if (!path || g_faces == FACES_MAX || font->handle.width == measure) return;
|
||||
if ((file = font_add(path)) < 0) return;
|
||||
f = &g_face[g_faces++];
|
||||
f->font = font;
|
||||
f->file = file;
|
||||
f->baseline_known = 0;
|
||||
f->atlas_width = font->handle.width;
|
||||
font->handle.width = measure;
|
||||
}
|
||||
|
||||
static void
|
||||
draw(void *canvas, short x, short y, unsigned short w, unsigned short h,
|
||||
nk_handle data)
|
||||
{
|
||||
struct nk_draw_list *list = (struct nk_draw_list *)canvas;
|
||||
struct nk_rect clip = list->clip_rect;
|
||||
const text_draw *d;
|
||||
text_face *f;
|
||||
struct nk_color fg;
|
||||
float px, k, top;
|
||||
int e, i;
|
||||
|
||||
if (data.id < 0 || data.id >= g_draws) return;
|
||||
if (!(clip.x < x + w && x < clip.x + clip.w && clip.y < y + h && y < clip.y + clip.h))
|
||||
return;
|
||||
d = &g_draw[data.id];
|
||||
f = &g_face[d->face];
|
||||
if ((e = shape(f->file, d->text, d->len)) < 0) return;
|
||||
px = f->font->info.height * d->height / f->font->handle.height;
|
||||
k = d->height / px;
|
||||
top = baseline(f) * px / f->font->info.height;
|
||||
fg = d->fg;
|
||||
fg.a = (nk_byte)((float)fg.a * list->config.global_alpha);
|
||||
for (i = 0; i < g_entry[e].glyphs; i++) {
|
||||
const shaped *g = &g_glyph[g_entry[e].glyph + i];
|
||||
const glyph_slot *s = glyph_get(g->font, g->id, (int)(px + 0.5f));
|
||||
struct nk_image im;
|
||||
float gx, gy;
|
||||
|
||||
if (!s || !s->w) continue;
|
||||
gx = SDL_floorf(g->x * px + 0.5f) + (float)s->left;
|
||||
gy = SDL_floorf(top - g->y * px + 0.5f) + (float)s->top;
|
||||
im = nk_subimage_ptr(g_page[s->page].tex, PAGE, PAGE,
|
||||
nk_rect((float)s->x, (float)s->y, (float)s->w, (float)s->h));
|
||||
nk_draw_list_add_image(list, im,
|
||||
nk_rect((float)x + gx * k, (float)y + gy * k,
|
||||
(float)s->w * k, (float)s->h * k),
|
||||
fg);
|
||||
if (g->font != f->file) mark_drawn(g->font, g->id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
{
|
||||
const struct nk_command *cmd;
|
||||
|
||||
g_renderer = renderer;
|
||||
/* The same frame again: its text commands are already custom ones. */
|
||||
if (g_faces == 0 || (g_seq_known && ctx->seq == g_seq)) return;
|
||||
g_seq = ctx->seq;
|
||||
g_seq_known = 1;
|
||||
g_draws = 0;
|
||||
if (!g_took) return;
|
||||
g_took = 0;
|
||||
if (g_glyphs > SHAPED_MAX) shapes_forget();
|
||||
if (g_full) glyphs_forget();
|
||||
|
||||
nk_foreach(cmd, ctx) {
|
||||
struct nk_command_text *t = (struct nk_command_text *)cmd;
|
||||
struct nk_command_custom *c = (struct nk_command_custom *)cmd;
|
||||
const struct nk_font *font;
|
||||
text_draw d;
|
||||
void *p;
|
||||
short x, y;
|
||||
unsigned short w, h;
|
||||
int face;
|
||||
|
||||
if (cmd->type != NK_COMMAND_TEXT || t->font->width != measure) continue;
|
||||
font = (const struct nk_font *)t->font->userdata.ptr;
|
||||
face = face_of(font);
|
||||
if (face < 0 || atlas_draws(font, t->string, t->length) ||
|
||||
!font_open(g_face[face].file))
|
||||
continue;
|
||||
if (!(p = grow(g_draw, &g_draw_cap, g_draws + 1, sizeof *g_draw))) break;
|
||||
g_draw = p;
|
||||
d.face = face;
|
||||
d.len = t->length;
|
||||
d.height = t->height;
|
||||
d.fg = t->foreground;
|
||||
d.text = t->string;
|
||||
x = t->x;
|
||||
y = t->y;
|
||||
w = t->w;
|
||||
h = t->h;
|
||||
c->header.type = NK_COMMAND_CUSTOM;
|
||||
c->x = x;
|
||||
c->y = y;
|
||||
c->w = w;
|
||||
c->h = h;
|
||||
c->callback_data = nk_handle_id(g_draws);
|
||||
c->callback = draw;
|
||||
g_draw[g_draws++] = d;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_break(const char *s, int len, int limit)
|
||||
{
|
||||
mjb_next_line_state st;
|
||||
mjb_break_type t;
|
||||
int best = 0;
|
||||
|
||||
if (len <= 0 || limit <= 0) return 0;
|
||||
st.index = 0;
|
||||
while ((t = mjb_next_line_break(s, (size_t)len, MJB_ENC_UTF_8, &st))
|
||||
!= MJB_BT_NOT_SET) {
|
||||
/* The boundary is before the character ending at st.index. */
|
||||
int at = (int)st.index;
|
||||
|
||||
if (at > len) {
|
||||
at = len;
|
||||
} else {
|
||||
at--;
|
||||
while (at > 0 && ((unsigned char)s[at] & 0xC0) == 0x80) at--;
|
||||
}
|
||||
if (at > limit) break;
|
||||
if (t == MJB_BT_ALLOWED || t == MJB_BT_MANDATORY) best = at;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_rtl(const char *s, int len)
|
||||
{
|
||||
int i = 0, isolate = 0;
|
||||
|
||||
while (i < len) {
|
||||
kbts_decode d = kbts_DecodeUtf8(s + i, (kbts_un)(len - i));
|
||||
mjb_character ch;
|
||||
|
||||
i += d.SourceCharactersConsumed > 0 ? d.SourceCharactersConsumed : 1;
|
||||
if (!d.Valid) continue;
|
||||
if (d.Codepoint < 0x80) {
|
||||
if (!isolate && ((d.Codepoint | 0x20) >= 'a' && (d.Codepoint | 0x20) <= 'z'))
|
||||
return 0;
|
||||
continue;
|
||||
}
|
||||
if (mjb_codepoint_info((mjb_codepoint)d.Codepoint, &ch) != MJB_STATUS_OK)
|
||||
continue;
|
||||
switch (ch.bidirectional) {
|
||||
case MJB_PR_BIDI_CLASS_LRI:
|
||||
case MJB_PR_BIDI_CLASS_RLI:
|
||||
case MJB_PR_BIDI_CLASS_FSI: isolate++; break;
|
||||
case MJB_PR_BIDI_CLASS_PDI: if (isolate) isolate--; break;
|
||||
case MJB_PR_BIDI_CLASS_L: if (!isolate) return 0; break;
|
||||
case MJB_PR_BIDI_CLASS_R:
|
||||
case MJB_PR_BIDI_CLASS_AL: if (!isolate) return 1; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_describe(char *buf, int cap)
|
||||
{
|
||||
int i, at = 0;
|
||||
|
||||
if (cap <= 0) return;
|
||||
buf[0] = 0;
|
||||
for (i = 0; i < g_fallbacks && at < cap; i++) {
|
||||
const text_font *f = &g_font[g_fallback[i]];
|
||||
|
||||
if (f->drawn_n > 0)
|
||||
at += SDL_snprintf(buf + at, (size_t)(cap - at), "%s%s for %d glyph%s",
|
||||
at ? ", " : "", f->name, f->drawn_n,
|
||||
f->drawn_n == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef REAKTOR_TEXT_H
|
||||
#define REAKTOR_TEXT_H
|
||||
|
||||
struct nk_context;
|
||||
struct nk_font;
|
||||
struct SDL_Renderer;
|
||||
|
||||
void reaktor_text_add_fallback(const char *path);
|
||||
void reaktor_text_attach_font(struct nk_font *font, const char *path);
|
||||
void reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer);
|
||||
|
||||
/* Where the next line starts, at or before limit; 0 if nowhere. */
|
||||
int reaktor_text_break(const char *s, int len, int limit);
|
||||
int reaktor_text_rtl(const char *s, int len);
|
||||
void reaktor_text_describe(char *buf, int cap);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "text.h"
|
||||
|
||||
void reaktor_text_add_fallback(const char *path) { (void)path; }
|
||||
|
||||
void
|
||||
reaktor_text_attach_font(struct nk_font *font, const char *path)
|
||||
{
|
||||
(void)font; (void)path;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
{
|
||||
(void)ctx; (void)renderer;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_break(const char *s, int len, int limit)
|
||||
{
|
||||
(void)len;
|
||||
for (; limit > 0; limit--)
|
||||
if (s[limit - 1] == ' ') return limit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_rtl(const char *s, int len)
|
||||
{
|
||||
(void)s; (void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_text_describe(char *buf, int cap)
|
||||
{
|
||||
if (cap > 0) buf[0] = 0;
|
||||
}
|
||||
@@ -10,9 +10,6 @@ static int g_space;
|
||||
static int g_unsettled;
|
||||
static int g_settled_run;
|
||||
|
||||
/* Give up asking for another frame after this many. A tree that has
|
||||
* not settled by now is not going to: it is a box whose name changes
|
||||
* every frame, not one still measuring itself. */
|
||||
#define REAKTOR_SETTLE_TRIES 16
|
||||
static int g_settle_tries;
|
||||
static const char *g_stuck;
|
||||
@@ -51,10 +48,6 @@ reaktor_frame_end(void)
|
||||
if (!g_unsettled) {
|
||||
g_settle_tries = 0;
|
||||
} else if (g_settle_tries < REAKTOR_SETTLE_TRIES) {
|
||||
/* Boxes are placed a frame late, so a tree that has just
|
||||
* grown one needs another frame to draw into. Nothing else
|
||||
* is going to ask for it - the app draws on events only - so
|
||||
* a synthetic event is what wakes the loop. */
|
||||
SDL_Event e;
|
||||
|
||||
g_settle_tries++;
|
||||
@@ -113,9 +106,6 @@ reaktor_box_open(unsigned char dir, const reaktor_box *b)
|
||||
box = *b;
|
||||
box.dir = dir;
|
||||
|
||||
/* The outermost container takes the panel's width. Without this a
|
||||
* root box has no width until something measures it, and two
|
||||
* adjacent declared blocks could not be siblings. */
|
||||
if (g_depth == 0 && box.w <= 0.0f)
|
||||
box.w = nk_window_get_content_region_size(g_ctx).x;
|
||||
|
||||
@@ -147,8 +137,6 @@ reaktor_box_open(unsigned char dir, const reaktor_box *b)
|
||||
g_boxok[g_depth + 1] = 1;
|
||||
}
|
||||
} else {
|
||||
/* No rect yet: first frame for this box. Recorded rather
|
||||
* than guessed at, and the frame is redrawn. */
|
||||
if (g_depth < REAKTOR_LAY_DEPTH) g_boxok[g_depth + 1] = 0;
|
||||
if (!g_stuck) g_stuck = box.name ? box.name : "(a container)";
|
||||
g_unsettled++;
|
||||
@@ -217,8 +205,6 @@ width_of(unsigned id)
|
||||
return reaktor_layout_rect(&g_app->lay, id, &r) ? r.w : 0.0f;
|
||||
}
|
||||
|
||||
/* Report the widget, claim its slot, and answer whether it has a rect
|
||||
* to draw into. Every widget below starts with this and returns on 0. */
|
||||
static int
|
||||
place(unsigned char role, const char *name, const char *value, unsigned state,
|
||||
const char *keys, const reaktor_box *b, unsigned *out_id)
|
||||
@@ -246,8 +232,6 @@ style_font(const char *selector)
|
||||
return g_ctx->style.font;
|
||||
}
|
||||
|
||||
/* A size for an axis the caller left alone. Zero means "no default here",
|
||||
* and a box that fills an axis keeps whatever the layout gives it. */
|
||||
static void
|
||||
box_default(reaktor_box *b, float w, float h)
|
||||
{
|
||||
@@ -255,18 +239,12 @@ box_default(reaktor_box *b, float w, float h)
|
||||
if (h > 0.0f && b->h <= 0.0f && !(b->flags & REAKTOR_LAY_FILL_Y)) b->h = h;
|
||||
}
|
||||
|
||||
/* The height four widgets settle on when they are given none. */
|
||||
static float
|
||||
row_height(float extra)
|
||||
{
|
||||
return g_ctx->style.font->height + extra;
|
||||
}
|
||||
|
||||
/* One rule laid over another, the narrower winning wherever it says
|
||||
* anything. There is no "was declared" bit in reaktor_style - a property the
|
||||
* rule omits reads as zero - so a zero is taken as silence. That is wrong for
|
||||
* an authored `padding: 0`, and it is the best this can do until the resolver
|
||||
* carries the declared set. */
|
||||
static void
|
||||
overlay(reaktor_style *base, const reaktor_style *over)
|
||||
{
|
||||
@@ -293,17 +271,6 @@ overlay(reaktor_style *base, const reaktor_style *over)
|
||||
if (over->font_px > 0) base->font_px = over->font_px;
|
||||
}
|
||||
|
||||
/* The size the sheet asks for, when the page has not asked for one itself.
|
||||
*
|
||||
* `element` is the rule a widget is by default: a button is `button` whether
|
||||
* or not the page named a selector, which is what lets a stylesheet change
|
||||
* how big things are rather than only what color they are. A selector the
|
||||
* page did name is tried first and falls back to the element rule.
|
||||
*
|
||||
* pad_x/pad_y are Nuklear's own padding, used only when no rule matches. */
|
||||
/* The selector to style by: what the page named when some sheet defines it,
|
||||
* and the element rule otherwise. A class only one stylesheet knows about
|
||||
* therefore costs nothing under another. */
|
||||
static const char *
|
||||
rule_or(const char *selector, const char *element)
|
||||
{
|
||||
@@ -323,10 +290,6 @@ box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
reaktor_style st;
|
||||
float extra_w, extra_h;
|
||||
|
||||
/* The element rule first, then the page's selector over the top - both,
|
||||
* in that order, the way a sheet is meant to be read. Taking whichever
|
||||
* matched first meant a narrow rule that sets one property threw away
|
||||
* every metric the element rule supplied. */
|
||||
memset(&st, 0, sizeof(st));
|
||||
if (element) reaktor_style_get(element, &st);
|
||||
if (selector) {
|
||||
@@ -362,10 +325,6 @@ box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
box->w = w;
|
||||
}
|
||||
if (box->h <= 0.0f && !(box->flags & REAKTOR_LAY_FILL_Y)) {
|
||||
/* The content box is the line box, not the font's own height: a
|
||||
* sheet saying line-height 1.5 wants half a line of air around its
|
||||
* text, and that is most of why a document's controls are roomier
|
||||
* than a toolbar's. */
|
||||
float line = st.line_height > 0.0f ? st.line_height : f->height;
|
||||
float h = st.height > 0.0f ? st.height : line + extra_h;
|
||||
if (h < st.min_height) h = st.min_height;
|
||||
@@ -373,12 +332,6 @@ box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
box->h = h;
|
||||
}
|
||||
|
||||
/* And the space around it. A sheet written for a document says how far
|
||||
* apart its controls sit with margins - simple.css puts 0.5rem under
|
||||
* every button, input and select, and that vertical rhythm is most of
|
||||
* what the sheet looks like. Reading the margins and then not applying
|
||||
* them left the widgets the right size in the wrong places. A margin the
|
||||
* page set itself wins, the same way its sizes do. */
|
||||
if (st.matched) {
|
||||
if (box->mt <= 0.0f) box->mt = st.margin[REAKTOR_SIDE_TOP];
|
||||
if (box->mr <= 0.0f) box->mr = st.margin[REAKTOR_SIDE_RIGHT];
|
||||
@@ -429,8 +382,6 @@ reaktor_button(const reaktor_button_spec *s)
|
||||
|
||||
r = nk_widget_bounds(g_ctx);
|
||||
|
||||
/* The rule this button is painted from: what the page named, if any sheet
|
||||
* defines it, and `button` otherwise. */
|
||||
sel = rule_or(s->style, "button");
|
||||
styled = push_style_font(s->style);
|
||||
if (s->repeat) nk_button_set_behavior(g_ctx, NK_BUTTON_REPEATER);
|
||||
@@ -457,13 +408,123 @@ reaktor_button(const reaktor_button_spec *s)
|
||||
return hit;
|
||||
}
|
||||
|
||||
#define WRAP_LINES 256
|
||||
|
||||
typedef struct wrapped {
|
||||
float space;
|
||||
int lines, end[WRAP_LINES];
|
||||
} wrapped;
|
||||
|
||||
static int
|
||||
wrap_guess(const struct nk_user_font *f, const char *s, int len, float space)
|
||||
{
|
||||
float w = 0.0f;
|
||||
int at = 0;
|
||||
nk_rune cp;
|
||||
|
||||
while (at < len) {
|
||||
int n = nk_utf_decode(s + at, &cp, len - at);
|
||||
float g;
|
||||
|
||||
if (n <= 0) return at ? at : len;
|
||||
g = f->width(f->userdata, f->height, s + at, n);
|
||||
if (w + g > space && at > 0) {
|
||||
int brk;
|
||||
|
||||
if (cp == ' ') return at + n;
|
||||
brk = reaktor_text_break(s, len, at);
|
||||
return brk > 0 ? brk : at;
|
||||
}
|
||||
w += g;
|
||||
at += n;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
wrap_fit(const struct nk_user_font *f, const char *s, int len, float space)
|
||||
{
|
||||
int end = wrap_guess(f, s, len, space);
|
||||
|
||||
for (;;) {
|
||||
int trim = end, brk;
|
||||
|
||||
while (trim > 0 && s[trim - 1] == ' ') trim--;
|
||||
if (trim <= 0 || f->width(f->userdata, f->height, s, trim) <= space)
|
||||
return end;
|
||||
brk = reaktor_text_break(s, len, trim - 1);
|
||||
if (brk <= 0 || brk >= end) return end;
|
||||
end = brk;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
wrap_lines(const struct nk_user_font *f, const char *s, float space, wrapped *w)
|
||||
{
|
||||
int len = (int)strlen(s), done = 0, lines = 0;
|
||||
|
||||
while (done < len) {
|
||||
done += wrap_fit(f, s + done, len - done, space);
|
||||
if (lines < WRAP_LINES) w->end[lines] = done;
|
||||
lines++;
|
||||
}
|
||||
w->space = space;
|
||||
w->lines = lines;
|
||||
return lines > 0 ? lines : 1;
|
||||
}
|
||||
|
||||
static void
|
||||
wrap_draw(const struct nk_user_font *f, const char *s, struct nk_color fg,
|
||||
const wrapped *w)
|
||||
{
|
||||
const struct nk_style *st = &g_ctx->style;
|
||||
struct nk_rect b, line;
|
||||
int len = (int)strlen(s), done = 0, k, rtl;
|
||||
char marked[1024];
|
||||
|
||||
if (nk_widget(&b, g_ctx) == NK_WIDGET_INVALID) return;
|
||||
rtl = reaktor_text_rtl(s, len);
|
||||
line = nk_rect(b.x + st->text.padding.x, b.y + st->text.padding.y,
|
||||
b.w - 2.0f * st->text.padding.x, f->height);
|
||||
fg = nk_rgb_factor(fg, st->text.color_factor);
|
||||
for (k = 0; done < len && line.y + line.h <= b.y + b.h; k++) {
|
||||
int n = w && w->space == line.w && k < w->lines && k < WRAP_LINES
|
||||
? w->end[k] - done
|
||||
: wrap_fit(f, s + done, len - done, line.w);
|
||||
const char *text = s + done;
|
||||
int bytes = n;
|
||||
struct nk_rect at = line;
|
||||
|
||||
if (rtl) {
|
||||
float width;
|
||||
|
||||
if (n + 3 <= (int)sizeof marked) {
|
||||
memcpy(marked, "\xE2\x80\x8F", 3);
|
||||
memcpy(marked + 3, text, (size_t)n);
|
||||
text = marked;
|
||||
bytes = n + 3;
|
||||
}
|
||||
width = f->width(f->userdata, f->height, text, bytes);
|
||||
at.x += at.w - width;
|
||||
at.w = width;
|
||||
} else {
|
||||
while (bytes > 0 && text[bytes - 1] == ' ') bytes--;
|
||||
}
|
||||
nk_draw_text(nk_window_get_canvas(g_ctx), at, text, bytes, f,
|
||||
st->window.background, fg);
|
||||
done += n;
|
||||
line.y += f->height;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_label(const reaktor_label_spec *s)
|
||||
{
|
||||
reaktor_box box;
|
||||
const struct nk_user_font *f;
|
||||
wrapped lines;
|
||||
unsigned id;
|
||||
int styled;
|
||||
int styled, measured = 0;
|
||||
|
||||
if (!g_app || !s || !s->text) return;
|
||||
box = s->box;
|
||||
@@ -473,14 +534,17 @@ reaktor_label(const reaktor_label_spec *s)
|
||||
f = style_font(s->style);
|
||||
|
||||
if (s->wrap) {
|
||||
struct nk_vec2 pad = g_ctx->style.text.padding;
|
||||
float own = width_of(id);
|
||||
float avail = (own > 0.0f ? own : g_width[g_widths - 1]) - 4.0f;
|
||||
float tw = f->width(f->userdata, f->height, s->text,
|
||||
(int)strlen(s->text));
|
||||
int lines = (avail > 1.0f && tw > avail) ? (int)(tw / avail) + 2 : 1;
|
||||
float avail = (float)(int)(own > 0.0f ? own : g_width[g_widths - 1]);
|
||||
struct nk_rect prev;
|
||||
|
||||
if (box.h <= 0.0f) box.h = (f->height + 3.0f) * (float)lines;
|
||||
if (box.h <= 0.0f) {
|
||||
box.h = f->height * (float)wrap_lines(f, s->text, avail - 2.0f * pad.x,
|
||||
&lines)
|
||||
+ 2.0f * pad.y;
|
||||
measured = 1;
|
||||
}
|
||||
if (!reaktor_layout_rect(&g_app->lay, id, &prev) || prev.h != box.h)
|
||||
g_unsettled++;
|
||||
} else {
|
||||
@@ -496,18 +560,11 @@ reaktor_label(const reaktor_label_spec *s)
|
||||
nk_flags a = s->align == REAKTOR_CENTRE ? NK_TEXT_CENTERED
|
||||
: s->align == REAKTOR_RIGHT ? NK_TEXT_RIGHT
|
||||
: NK_TEXT_LEFT;
|
||||
struct nk_color c = reaktor_token(s->color, g_ctx->style.text.color);
|
||||
|
||||
styled = push_style_font(s->style);
|
||||
if (s->color) {
|
||||
struct nk_color c = reaktor_token(s->color,
|
||||
g_ctx->style.text.color);
|
||||
if (s->wrap) nk_label_colored_wrap(g_ctx, s->text, c);
|
||||
else nk_label_colored(g_ctx, s->text, a, c);
|
||||
} else if (s->wrap) {
|
||||
nk_label_wrap(g_ctx, s->text);
|
||||
} else {
|
||||
nk_label(g_ctx, s->text, a);
|
||||
}
|
||||
if (s->wrap) wrap_draw(f, s->text, c, measured ? &lines : NULL);
|
||||
else nk_label_colored(g_ctx, s->text, a, c);
|
||||
if (styled) nk_style_pop_font(g_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,6 @@ enum {
|
||||
REAKTOR_LAY_PACK_SPREAD = 1u << 7
|
||||
};
|
||||
|
||||
/* A box. w/h is a size, and a *floor* when the same axis also fills:
|
||||
* a fixed track is w alone, a minimum that grows is w with FILL_X, a
|
||||
* fraction is FILL_X with weight. gap is between a box's children,
|
||||
* margins are outside the box itself. */
|
||||
typedef struct reaktor_box {
|
||||
unsigned char dir;
|
||||
const char *name;
|
||||
@@ -39,9 +35,6 @@ typedef struct reaktor_box {
|
||||
#define REAKTOR_LAY_DEPTH 32
|
||||
#define REAKTOR_LAY_SLOTS 512
|
||||
|
||||
/* Where a box landed, kept by id from one frame to the next: gen is
|
||||
* the frame that wrote it, so a stale slot can be told from a fresh
|
||||
* one without clearing the table. */
|
||||
typedef struct reaktor_lay_slot {
|
||||
unsigned id;
|
||||
unsigned gen;
|
||||
@@ -75,19 +68,6 @@ void reaktor_layout_close(reaktor_layout *l);
|
||||
|
||||
void reaktor_layout_end(reaktor_layout *l);
|
||||
|
||||
/* The rect for a box, or 0 if it has none yet.
|
||||
*
|
||||
* Boxes are placed a frame late, and that is structural rather than a
|
||||
* shortcut: a frame declares its boxes as it draws them, so the last
|
||||
* sibling is declared long after the first is drawn and no sibling's
|
||||
* share is known when it is needed. A frame therefore draws into the
|
||||
* rects computed at the end of the previous one. A box seen for the
|
||||
* first time answers 0 and is skipped for one frame rather than drawn
|
||||
* somewhere wrong.
|
||||
*
|
||||
* The id is the accessibility node's, so a box is found again by its
|
||||
* name: a widget whose text changes every frame is a new box every
|
||||
* frame and never gets a rect at all. */
|
||||
int reaktor_layout_rect(const reaktor_layout *l, unsigned id,
|
||||
struct nk_rect *out);
|
||||
|
||||
|
||||
@@ -48,11 +48,6 @@ push_button_style(App *app, struct nk_context *ctx, const char *selector)
|
||||
reaktor_style_get(selector, &s);
|
||||
if (!s.matched) return f;
|
||||
|
||||
/* The state rules, read rather than computed. :hover used to supply only
|
||||
* a background and :active nothing at all - it was the base color ten
|
||||
* per cent darker, which is a decision a stylesheet is entitled to make
|
||||
* and this was making for it. The darkening is still the fallback, for a
|
||||
* sheet that styles :hover and stops there. */
|
||||
snprintf(state, sizeof(state), "%s:hover", selector);
|
||||
reaktor_style_get(state, &hov);
|
||||
snprintf(state, sizeof(state), "%s:active", selector);
|
||||
|
||||
@@ -303,8 +303,6 @@ reaktor_progress_bar(App *app, struct nk_context *ctx, nk_size *cur, nk_size max
|
||||
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_normal, clear);
|
||||
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_hover, clear);
|
||||
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_active, clear);
|
||||
/* Both borders: Nuklear strokes the widget and the cursor separately,
|
||||
* and the cursor's is the one that showed as a hairline across the fill. */
|
||||
nk_style_push_float(ctx, &ctx->style.progress.border, 0.0f);
|
||||
nk_style_push_float(ctx, &ctx->style.progress.cursor_border, 0.0f);
|
||||
nk_progress(ctx, cur, max, modifiable);
|
||||
@@ -483,9 +481,6 @@ reaktor_button_label(App *app, struct nk_context *ctx, const char *label)
|
||||
return css_button(app, ctx, "button", label);
|
||||
}
|
||||
|
||||
/* The same three buttons, painted from a rule the page named. A class the
|
||||
* sheet does not define falls back to `button`, so a selector that is only
|
||||
* meaningful to one stylesheet costs nothing under another. */
|
||||
int
|
||||
reaktor_button_label_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *label)
|
||||
@@ -774,10 +769,6 @@ reaktor_note_here(App *app, struct nk_context *ctx, unsigned char role,
|
||||
return id;
|
||||
}
|
||||
|
||||
/* The face a rule asks for, falling back to a size named in the code.
|
||||
*
|
||||
* Every caller of this used to be a bare reaktor_font(app, 13, 0) - a number
|
||||
* the stylesheet could not reach, on a page claiming the look lives in CSS. */
|
||||
const struct nk_user_font *
|
||||
reaktor_style_font(App *app, const char *selector, int px, int bold)
|
||||
{
|
||||
@@ -800,10 +791,6 @@ reaktor_popup_rounding(void)
|
||||
return dlg.rounding > 8.0f ? 8.0f : dlg.rounding;
|
||||
}
|
||||
|
||||
/* A menu popup's chrome. The row spacing here is not cosmetic: it is the 2
|
||||
* that reaktor_menu_height counts, and a popup opened without it is a row
|
||||
* short of the height it asked for, which leaves the last item on the
|
||||
* clipped edge with nothing to click. */
|
||||
void
|
||||
reaktor_menu_style_push(struct nk_context *ctx)
|
||||
{
|
||||
@@ -831,8 +818,6 @@ reaktor_menu_height(int rows)
|
||||
return rows * REAKTOR_MENU_ROW + (rows - 1) * REAKTOR_MENU_GAP + 10.0f;
|
||||
}
|
||||
|
||||
/* One menu row: the pointer cursor, the accessibility node and the item
|
||||
* itself, plus an accelerator drawn at the right edge when there is one. */
|
||||
int
|
||||
reaktor_menu_item(App *app, struct nk_context *ctx, const char *label,
|
||||
const char *accel, int contextual)
|
||||
@@ -887,7 +872,14 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
|
||||
out->mode = app->render_mode;
|
||||
out->frame_rate = app->frame_rate;
|
||||
out->drag_rate = app->drag_rate;
|
||||
out->font = app->font_status;
|
||||
{
|
||||
static char line[sizeof app->font_status + 200];
|
||||
char drawn[200];
|
||||
|
||||
reaktor_text_describe(drawn, sizeof drawn);
|
||||
if (drawn[0]) SDL_snprintf(line, sizeof line, "%s; %s", app->font_status, drawn);
|
||||
out->font = drawn[0] ? line : app->font_status;
|
||||
}
|
||||
out->vsync = app->vsync_on;
|
||||
out->aa = !app->aa ? "off"
|
||||
: !app->renderer_is_sw ? "on"
|
||||
@@ -914,10 +906,6 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
|
||||
}
|
||||
|
||||
{
|
||||
/* Sampled twice a second, not per frame. On Linux this parses
|
||||
* /proc/self/statm and /proc/self/smaps_rollup, and the second makes
|
||||
* the kernel walk every mapping - on the one page whose job is to
|
||||
* report honest frame timings, which it would then be inflating. */
|
||||
static size_t rss, priv;
|
||||
static unsigned taken;
|
||||
unsigned now = SDL_GetTicks();
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
# The four applications
|
||||
|
||||
This repository builds four programs. They share `runtime/` and `core/` byte
|
||||
for byte — the whole of the difference between them is in `samples/`.
|
||||
for byte; what differs is `samples/`, and which optional modules each links.
|
||||
The showcase takes all three — the accessibility bridges, Locale and Text. The
|
||||
other three take none, so they show what the runtime costs by itself, and a
|
||||
screen reader finds nothing in them.
|
||||
|
||||
| | Size | What it is for |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | ~2,800 lines | Every widget, both schemes, and how far the CSS seam reaches |
|
||||
| `showcase` | ~3,000 lines | Every widget, both schemes, three languages, and how far the CSS seam reaches |
|
||||
| `notepad` | ~290 lines | A text editor that opens, edits and saves a file |
|
||||
| `bench` | ~160 lines | The workload the published figures are measured on, here and in the other four frameworks |
|
||||
| `bench` | ~220 lines | The workload the published figures are measured on, here and in the other four frameworks |
|
||||
| `simple` | ~60 lines | One button that closes the window |
|
||||
|
||||
```bash
|
||||
@@ -28,24 +31,39 @@ application owns what is drawn and what the keys mean.
|
||||
which is the honest measure of how much of an application the runtime is
|
||||
already doing.
|
||||
|
||||
## showcase
|
||||
## Showcase
|
||||
|
||||
Nine pages — Login, Buttons, Inputs, Display, Layout, Popups, Animation,
|
||||
Styling, Diagnostics. It is the reference for what the library can draw, and
|
||||
it is also where the project's claims are tested rather than asserted:
|
||||
<p align="center">
|
||||
<img src="../assets/screenshots/showcase.png" alt="The Reaktor showcase under the system titlebar, following the system's dark scheme: a tab strip across the top with system selected, and the Login page's centered card">
|
||||
</p>
|
||||
|
||||
Ten pages — Login, Buttons, Inputs, Display, Layout, Popups, Animation,
|
||||
Styling, Translations, Diagnostics. It is the reference for what the library
|
||||
can draw, and it is also where the project's claims are tested rather than
|
||||
asserted:
|
||||
|
||||
- **Styling** reads simple.css over the top of tiny.css at the flick of a
|
||||
checkbox, and prints what each rule resolved to beside the widgets it
|
||||
painted — so the page cannot say one thing while the screen shows another.
|
||||
- **Translations** sets the opening of *The Ugly Duckling* in English, Polish
|
||||
and Japanese, three public-domain translations read from the catalogs, and
|
||||
beside it the day the story was first published, a number, one amount in
|
||||
three currencies and a count of ducklings, each formatted the way that
|
||||
language writes it. The Japanese is the Text module's, drawn from M PLUS 1p
|
||||
at the size each heading and paragraph is set in.
|
||||
- **Diagnostics** reports the renderer, where each frame's milliseconds went
|
||||
and where each megabyte went, live.
|
||||
- **Animation** draws all 31 easing curves from the same function the widgets
|
||||
animate through.
|
||||
|
||||
It draws its own titlebar, which is why it carries a tab strip and window
|
||||
controls that the other two do not.
|
||||
controls that the others do not.
|
||||
|
||||
## notepad
|
||||
## Notepad
|
||||
|
||||
<p align="center">
|
||||
<img src="../assets/screenshots/notepad.png" alt="Notepad in the dark scheme under its native titlebar: a File and Help menu bar, the editor open on its own source, notepad.c, and a status line with the file name and its character count">
|
||||
</p>
|
||||
|
||||
A real text editor in one file: a menu bar, a multiline field, a status line,
|
||||
open and save through the platform's own file dialog, and five keyboard
|
||||
@@ -53,22 +71,28 @@ shortcuts. It exists because a showcase can hide a lot — a page of widgets
|
||||
never has to answer what happens when a document is modified, or where the
|
||||
menu's last item lands when the popup is a pixel too short.
|
||||
|
||||
## bench
|
||||
## Bench
|
||||
|
||||
Sixty-four boxes rotating as fast as the display will take them, for however
|
||||
many seconds `--bench-seconds` asks for, and then what the run cost on stdout:
|
||||
<p align="center">
|
||||
<img src="../assets/screenshots/bench.png" alt="The bench window under its native titlebar, drawn with --renderer direct3d11, which antialiases the edges: an eight-by-eight grid of rotating squares shading from blue at the top to pink at the bottom">
|
||||
</p>
|
||||
|
||||
Sixty-four boxes rotating, as fast as the display will take them or flat out
|
||||
with `--no-vsync`, for however many seconds `--bench-seconds` asks for, and then
|
||||
what the run cost on stdout. Six seconds flat out, on the Windows VM that
|
||||
[PERFORMANCE.md](PERFORMANCE.md#where-the-numbers-came-from) names:
|
||||
|
||||
```
|
||||
size 800x600
|
||||
frames 525
|
||||
fps 87.4
|
||||
ms_build 0.02
|
||||
ms_render 0.09
|
||||
ms_present 11.30
|
||||
ms_per_frame 11.42
|
||||
cpu_at_60fps 68.5
|
||||
cpu_percent 99.3
|
||||
private_mb 9.6
|
||||
frames 4290
|
||||
fps 715.0
|
||||
ms_build 0.03
|
||||
ms_render 0.07
|
||||
ms_present 1.27
|
||||
ms_per_frame 1.37
|
||||
cpu_at_60fps 8.2
|
||||
cpu_percent 97.4
|
||||
private_mb 7.1
|
||||
```
|
||||
|
||||
`--boxes <n>` changes the workload and `--fps <n>` holds it to a rate, sleeping
|
||||
@@ -87,13 +111,17 @@ drawing and the number holds to a tenth.
|
||||
It is deliberately the thing this library is worst at. Every other figure in
|
||||
[PERFORMANCE.md](PERFORMANCE.md) is a count of frames, because nothing is drawn
|
||||
while nothing changes — an animation that never stops throws that advantage
|
||||
away and measures the drawing instead of the design. Reaktor's two bars in the
|
||||
chart there come from this program; the other three come from `benchmarks/`,
|
||||
which is the same picture written in Flutter, Electron and Compose
|
||||
Multiplatform, so that the comparison is one workload and one sampler rather
|
||||
than five readings from five machines.
|
||||
away and measures the drawing instead of the design. Reaktor's three bars in
|
||||
the chart there come from this program, one per renderer; the other three come
|
||||
from `benchmarks/`, which is the same picture written in Flutter, Electron and
|
||||
Compose Multiplatform, so that the comparison is one workload and one sampler
|
||||
rather than six readings from six machines.
|
||||
|
||||
## simple
|
||||
## Simple
|
||||
|
||||
<p align="center">
|
||||
<img src="../assets/screenshots/simple.png" alt="Simple in the dark scheme under its native titlebar: one Close button centered in a small window">
|
||||
</p>
|
||||
|
||||
One centered button that closes the window, in sixty lines including the
|
||||
five functions it does not use. It is the smallest thing that is still an
|
||||
|
||||
@@ -10,8 +10,10 @@ Using it, and working on it.
|
||||
**Inside** — [The architecture](#the-architecture) · [The tree](#the-tree) ·
|
||||
[The style pipeline](#the-style-pipeline) ·
|
||||
[The frame loop](#the-frame-loop) · [Tests](#tests) ·
|
||||
[Build options](#build-options) ·
|
||||
[Command-line flags](#command-line-flags) · [The renderer](#the-renderer) ·
|
||||
[The web build](#the-web-build) · [Localization](#localization) ·
|
||||
[Text](#text) ·
|
||||
[Nuklear behaviors](#nuklear-behaviors-that-have-already-cost-an-afternoon)
|
||||
|
||||
---
|
||||
@@ -172,6 +174,11 @@ For the widgets the library has no spec for, report them yourself:
|
||||
reaktor_note(app, REAKTOR_A11Y_TREEITEM, label, NULL, state, bounds);
|
||||
```
|
||||
|
||||
`-DREAKTOR_A11Y=OFF` builds without the platform bridges, and so does an
|
||||
application that links `reaktor_a11y_none` — see
|
||||
[Build options](#build-options). The tree itself is still built, because layout
|
||||
finds a box again by its accessibility id; only serving it is dropped.
|
||||
|
||||
## Animation
|
||||
|
||||
A number that takes time to change, keyed by the same accessibility id.
|
||||
@@ -238,16 +245,21 @@ core/render Nuklear impl, the SDL3 backend, drawing, SVG icons
|
||||
core/ui the declarative API, layout, widgets, style map, keys, focus
|
||||
core/a11y the shadow tree and its diff
|
||||
core/anim eased values keyed by a11y id
|
||||
core/locale the Locale module: catalogs, lookup, plurals, formatting
|
||||
core/text the Text module: direction, shaping, fallback glyphs, line breaking
|
||||
platform/ system theme, and one accessibility bridge per platform
|
||||
assets/locale the showcase's catalogs, one file per language
|
||||
runtime/ app.c: the window, the event loop, the frame
|
||||
samples/ showcase, notepad, simple, bench
|
||||
tools/ the tests, the icon compiler, vmwalk
|
||||
benchmarks/ bench's workload in four other frameworks, and one sampler
|
||||
external/ eight submodules, read as they ship
|
||||
external/ ten submodules, read as they ship
|
||||
```
|
||||
|
||||
`runtime/` and `core/` build into `reaktor_runtime`, a static library the four
|
||||
executables link. Nothing in `core/` knows which application it is in.
|
||||
executables link — all but `core/locale`, `core/text` and the bridges, which
|
||||
are the modules, compiled into the programs that take them. Nothing in `core/` knows
|
||||
which application it is in.
|
||||
|
||||
## The style pipeline
|
||||
|
||||
@@ -296,7 +308,7 @@ on four platforms.
|
||||
|
||||
## Tests
|
||||
|
||||
Five, built by default, run from `build/`:
|
||||
Seven, built by default, run from `build/`:
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
@@ -305,6 +317,8 @@ Five, built by default, run from `build/`:
|
||||
| `a11ytest` | node identity, the diff, the pool |
|
||||
| `animtest` | curves, retarget, eviction |
|
||||
| `keytest` | chord parsing and formatting |
|
||||
| `localetest` | catalog parsing, lookup, plural expressions, formatting |
|
||||
| `texttest` | line breaks, paragraph direction, measuring, and the order glyphs reach the vertex buffer in — against the fonts in `assets/fonts`, with no window; built only with the Text module |
|
||||
|
||||
Beyond that, verification is the **accessibility dump**: run with
|
||||
`--a11y-dump <path>` and every node's role, name, value, state and
|
||||
@@ -316,6 +330,74 @@ And when a fix is visual, **look at the framebuffer**. `--shot <path.bmp>`
|
||||
writes the window once it settles, then quits. Reasoning from a library's source
|
||||
about where it puts a glyph produces confident, wrong answers.
|
||||
|
||||
## Build options
|
||||
|
||||
Passed to CMake. Both scripts forward them:
|
||||
|
||||
```bash
|
||||
./build.sh -- -DREAKTOR_A11Y=OFF # macOS, Linux, the BSDs
|
||||
```
|
||||
|
||||
```powershell
|
||||
.\build.ps1 -DREAKTOR_A11Y=OFF # Windows
|
||||
.\build-wasm.ps1 -DREAKTOR_A11Y=OFF # the web build; build-wasm.sh takes -- as build.sh does
|
||||
```
|
||||
|
||||
| Option | Default | Effect |
|
||||
| --- | --- | --- |
|
||||
| `REAKTOR_A11Y` | `ON` | Serve the accessibility tree to screen readers: UI Automation, AT-SPI, NSAccessibility, the DOM |
|
||||
| `REAKTOR_LOCALE` | `ON` | Translations, from the catalogs in `assets/locale` — see [Localization](#localization) |
|
||||
| `REAKTOR_LOCALE_EMBED` | `OFF` | Compile the catalogs into the executable rather than read them at startup |
|
||||
| `REAKTOR_TEXT` | `ON` | Direction, shaping and fallback glyphs for the text the font atlas cannot draw, and line breaks by Unicode's rules — see [Text](#text) |
|
||||
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Linux and the BSDs |
|
||||
|
||||
**CMake remembers an option.** A later build without the flag keeps whatever
|
||||
was set last, so turn one back on by passing `=ON`, not by leaving it out.
|
||||
|
||||
**A module is two libraries, and the application links one of them.**
|
||||
`reaktor_a11y` or `reaktor_a11y_none`, `reaktor_locale` or
|
||||
`reaktor_locale_none`, `reaktor_text` or `reaktor_text_none`: both halves
|
||||
define the same functions, and each is an interface library, so its sources are
|
||||
compiled into the program that links it and nowhere else. The showcase takes
|
||||
all three modules; `simple`, `notepad` and `bench` take the `_none` halves, and
|
||||
show what the runtime costs with nothing added. An option switched off turns a
|
||||
module into its `_none` half for every program that links it.
|
||||
|
||||
```cmake
|
||||
target_link_libraries(myapp PRIVATE
|
||||
reaktor_runtime reaktor_a11y reaktor_locale reaktor_text_none)
|
||||
```
|
||||
|
||||
**`REAKTOR_A11Y=OFF` removes the bridges and nothing else.** The UI Automation,
|
||||
AT-SPI and NSAccessibility bridges and the web DOM subtree are not compiled, and
|
||||
the libraries only they need are not linked: `uiautomationcore`, `ole32` and
|
||||
`oleaut32` on Windows, `dbus-1` on Linux and the BSDs. (Cocoa stays on macOS;
|
||||
SDL links it for itself.) The accessibility tree is still built, because layout
|
||||
finds boxes by its ids and animations are keyed to them, so `--a11y-dump` keeps
|
||||
working. A switched-off build draws the same pixels and writes the same dump as
|
||||
a default one; a screen reader just finds nothing in it.
|
||||
|
||||
It trims little, because the bridges are small — see
|
||||
[PERFORMANCE.md](PERFORMANCE.md#modules). The reason to turn it off is the
|
||||
libraries, and on Linux, not needing `dbus-1` at all.
|
||||
|
||||
**`REAKTOR_LOCALE=OFF` leaves every string as its key.** `reaktor_tr` answers
|
||||
with the key it was given, the atlas bakes Latin-1 alone, and the web build
|
||||
stops packing the catalogs and the Japanese font — most of the showcase's
|
||||
`.data`.
|
||||
|
||||
**`REAKTOR_LOCALE_EMBED=ON` writes the catalogs into the executable.** CMake
|
||||
reads every `assets/locale/*.txt` at configure time into a generated C file,
|
||||
and a catalog added or edited later reconfigures on the next build. The program
|
||||
then needs no `assets/locale` beside it; the Japanese font is still read from
|
||||
`assets/fonts`.
|
||||
|
||||
**`REAKTOR_TEXT=OFF` leaves mojibake and kb_text_shape out of the build.**
|
||||
Nothing is reordered or shaped, no glyph comes from another font, and a line
|
||||
breaks after a space. A catalog Aileron can draw — Polish — is untouched,
|
||||
because what Aileron has is Locale's to bake; the Japanese one comes out as
|
||||
boxes.
|
||||
|
||||
## Command-line flags
|
||||
|
||||
**Reaktor reads no environment variables.** Every default is compiled in, and
|
||||
@@ -330,13 +412,15 @@ sees it, so an application's own arguments are unaffected:
|
||||
| `--shot <path.bmp>` | Write the window once it settles, then quit |
|
||||
| `--a11y-dump <path>` | Write the accessibility tree once it settles |
|
||||
| `--theme <system\|light\|dark>` | Which color scheme to open in |
|
||||
| `--lang <code>` | Which catalog to open in, by its file name: `en`, `pl`, `ja` |
|
||||
| `--font-fallback <path>` | A font for the Text module to take glyphs from when the UI font has none, tried before any the application adds; give it again for more |
|
||||
| `--renderer <name>` | `software` (the default), `auto` to let SDL pick, or a driver name |
|
||||
|
||||
The showcase adds two of its own, through `sample_args`:
|
||||
|
||||
| Flag | Effect |
|
||||
| --- | --- |
|
||||
| `--tab <0-8>` | Login, Buttons, Inputs, Display, Layout, Popups, Animation, Styling, Diagnostics |
|
||||
| `--tab <0-9>` | Login, Buttons, Inputs, Display, Layout, Popups, Animation, Styling, Translations, Diagnostics |
|
||||
| `--scroll <px>` | How far that page starts scrolled |
|
||||
|
||||
And `bench` adds four:
|
||||
@@ -387,8 +471,9 @@ and no amount of re-deriving it will make it show.
|
||||
`core/render/nk_sdl3_renderer.h` is Nuklear's SDL3 backend, vendored rather
|
||||
than included because one of the changes is inside `nk_sdl_font_stash_end`.
|
||||
Every deviation is marked `REAKTOR`: an 8-bit indexed atlas instead of RGBA32,
|
||||
a 1×1 white texture for untextured geometry, pixel snapping, and independent
|
||||
feathering of fills and strokes.
|
||||
a 1×1 white texture for untextured geometry, pixel snapping, independent
|
||||
feathering of fills and strokes, and the atlas's palette made public so the
|
||||
[Text](#text) module's glyph textures can share it.
|
||||
|
||||
## The web build
|
||||
|
||||
@@ -397,36 +482,188 @@ Same sources, same `CMakeLists.txt`. `./build-wasm.sh` needs
|
||||
`notepad.html` in `build-wasm/`, to be served over HTTP — a `file://` page
|
||||
cannot fetch the `.wasm`.
|
||||
|
||||
Every push to `master` publishes the showcase to
|
||||
[GitHub Pages](https://alpaq92.github.io/Reaktor/), as the site's front page —
|
||||
`.github/workflows/pages.yml`, pinned to the emscripten the published sizes were
|
||||
built with.
|
||||
|
||||
Assets are packaged with `--preload-file` and only the files the sources
|
||||
actually name — the list is grepped at configure time, which took the bundle
|
||||
from 3.55 MB to 1.30 MB. `tools/shell.html` is the page; its loading overlay
|
||||
sets `pointer-events: none`, without which a full-viewport overlay swallows
|
||||
every canvas click and the app looks dead.
|
||||
from 3.55 MB to 1.30 MB. The showcase alone also packs `assets/locale` and the
|
||||
Japanese font, which `simple` and `notepad` never open. `tools/shell.html` is
|
||||
the page; its loading overlay sets `pointer-events: none`, without which a
|
||||
full-viewport overlay swallows every canvas click and the app looks dead.
|
||||
|
||||
## Localization
|
||||
|
||||
Not supported, and the missing piece is not the one people expect.
|
||||
The Locale module translates what a program says and formats what it counts:
|
||||
a catalog per language, a lookup by key, plural forms, and numbers, money and
|
||||
dates written the way the language writes them. The showcase's Translations
|
||||
page is the working example — one page and one piece of code, in English,
|
||||
Polish and Japanese.
|
||||
|
||||
Translating the strings is the easy third. The other two are why no amount of
|
||||
string work would make a Japanese or Arabic build render:
|
||||
**A catalog** is `assets/locale/<code>.txt`, one entry a line:
|
||||
|
||||
- **Glyph coverage.** `rebuild_font` never sets `cfg.range`, so Nuklear bakes
|
||||
its default U+0020-U+00FF. Latin-1 and nothing else: no Cyrillic, no Greek,
|
||||
no CJK, no Arabic, no Devanagari. Nuklear ships
|
||||
`nk_font_cyrillic_glyph_ranges`, `nk_font_chinese_glyph_ranges` and
|
||||
`nk_font_korean_glyph_ranges`, so the ranges exist - but the atlas is
|
||||
already 1024x1024 for 8 sizes in two weights, and CJK is thousands of
|
||||
glyphs per size.
|
||||
- **Shaping and direction.** Nuklear positions one glyph after another by
|
||||
advance width. That is correct for Latin, Cyrillic and Greek and wrong for
|
||||
Arabic (contextual forms, right-to-left), Hebrew (right-to-left) and the
|
||||
Indic scripts (reordering, conjuncts). There is no shaping engine and no
|
||||
bidi algorithm anywhere in the tree.
|
||||
```
|
||||
language = Polski
|
||||
plural = n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2
|
||||
file.save = Zapisz
|
||||
file.count = {n} plik | {n} pliki | {n} plików
|
||||
number.decimal = ,
|
||||
money.PLN = zł
|
||||
date.long = d MMMM y
|
||||
```
|
||||
|
||||
What is already in place, for whatever it is worth: the accessibility tree
|
||||
carries the same strings the widgets draw, so a translated interface is a
|
||||
translated screen reader with no extra work, and the declarative specs take
|
||||
`const char *` rather than baking text into the drawing code.
|
||||
A line splits at its first ` = `, and in a value `\n` is a newline and `\\` a
|
||||
backslash. `language` is the catalog's name for itself, which is what a
|
||||
language switch shows; `plural` is a gettext plural expression, as in a `.po`
|
||||
header. There is no comment syntax, because a key is free text.
|
||||
|
||||
```c
|
||||
char buf[64];
|
||||
time_t now = time(NULL);
|
||||
|
||||
reaktor_button(&(reaktor_button_spec){ .label = reaktor_tr("file.save") });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_trn("file.count", n, buf, sizeof buf) }); /* 3 pliki */
|
||||
|
||||
reaktor_format_money(buf, sizeof buf, 1234.5, "PLN"); /* 1234,50 zł */
|
||||
reaktor_format_date(buf, sizeof buf, localtime(&now), REAKTOR_DATE_LONG);
|
||||
```
|
||||
|
||||
`reaktor_tr` answers the current catalog's value, or the key itself when there
|
||||
is none, so a string nobody translated shows up as its key rather than as
|
||||
nothing. `reaktor_trn` picks one of the ` | ` forms by the catalog's rule, and
|
||||
writes `{n}` as the number, formatted.
|
||||
|
||||
**Formatting** reads the keys a catalog carries for it, and a key a catalog
|
||||
leaves out is formatted the way English is:
|
||||
|
||||
| Key | English | What it says |
|
||||
| --- | --- | --- |
|
||||
| `number.decimal` | `.` | The decimal separator |
|
||||
| `number.group` | `,` | The grouping separator |
|
||||
| `number.group.min` | `1` | The fewest digits allowed ahead of the first separator |
|
||||
| `money` | `{s}{n}` | Where the symbol and the amount go |
|
||||
| `money.<code>` | the code | A currency's symbol |
|
||||
| `money.<code>.digits` | `2` | A currency's decimals |
|
||||
| `date.short` | `M/d/yy` | A pattern, as are the three below |
|
||||
| `date.long` | `MMMM d, y` | |
|
||||
| `date.full` | `EEEE, MMMM d, y` | |
|
||||
| `time.short` | `h:mm a` | |
|
||||
| `date.months`, `date.months.short` | `January \| February \| …` | Twelve forms |
|
||||
| `date.days`, `date.days.short` | `Sunday \| Monday \| …` | Seven forms, Sunday first |
|
||||
| `time.ampm` | `AM \| PM` | |
|
||||
|
||||
A pattern is made of `d dd M MM MMM MMMM y yy EEE EEEE H HH h hh m mm a`, with
|
||||
anything in `'quotes'` kept as it is. The weekday is worked out from the date,
|
||||
not read from `tm_wday`. Each call writes at most `cap` bytes, terminator
|
||||
included, and answers `buf`.
|
||||
|
||||
No table of conventions sits behind this: a catalog says how its language
|
||||
writes a number the way it says how it writes "Save". The Polish one puts
|
||||
no-break spaces where a line must not break, between groups of digits and
|
||||
between an amount and its symbol. A symbol made of letters that would touch the
|
||||
amount is kept off it by one regardless, so `PLN 12.00` rather than
|
||||
`PLN12.00`.
|
||||
|
||||
**The language** is `--lang` when a catalog has that code; otherwise the first
|
||||
of the system's preferred languages that one has; otherwise English; otherwise
|
||||
the first catalog. `reaktor_locale_set` switches at any time, and the next
|
||||
frame draws in it.
|
||||
|
||||
**Leave `.name` to the translated text**, so a screen reader reads what is
|
||||
drawn. The price is that a language switch makes every translated widget a new
|
||||
one: placed a frame late, once, and dropping focus if it had it.
|
||||
|
||||
**The atlas bakes what the catalogs use** and Aileron has: Latin-1, plus every
|
||||
such character, at every size in both weights. The characters Aileron lacks
|
||||
are the [Text](#text) module's to draw.
|
||||
|
||||
**Formatting stops at the patterns above.** No time zones, no calendar but the
|
||||
Gregorian, and digits grouped in threes only — not the Indian lakh.
|
||||
|
||||
The accessibility tree carries the same strings the widgets draw, so a
|
||||
translated interface is a translated screen reader with no extra work.
|
||||
|
||||
## Text
|
||||
|
||||
Nuklear draws a string from the font atlas, one glyph after another, left to
|
||||
right. The Text module draws every string that needs more than that, and
|
||||
breaks lines the way Unicode says to. A string whose characters are all baked
|
||||
into the atlas is left to Nuklear, so Latin text costs what it always did.
|
||||
|
||||
- **Direction** by the Unicode bidirectional algorithm, through
|
||||
[mojibake](https://github.com/zaerl/mojibake). Arabic and Hebrew run right to
|
||||
left, with the numbers and Latin words inside them the right way round, and
|
||||
a bracket faces the way its direction needs. A wrapped paragraph that starts
|
||||
right to left keeps to the right edge, and every line keeps the paragraph's
|
||||
direction.
|
||||
- **Shaping** by [kb_text_shape](https://github.com/JimmyLefevre/kb). Each run
|
||||
of one direction, one script and one font goes through OpenType's rules for
|
||||
its script: Arabic letters join, marks sit on their letters, Devanagari moves
|
||||
its vowel signs and forms conjuncts. Kerning is off, as it is in the atlas,
|
||||
so a word is as wide wherever it is drawn.
|
||||
- **Fallback glyphs** from the first font that has them: the face's own file,
|
||||
then each `--font-fallback` in the order given, then each font the
|
||||
application adds with `reaktor_text_add_fallback`. A font is chosen a
|
||||
grapheme at a time, so a letter and its marks come from the same one.
|
||||
- **Every size and weight.** Nothing is baked ahead of time. A glyph is
|
||||
rasterized the first time it is drawn, at the size it is drawn, into 512×512
|
||||
textures of the module's own, and lands on the pixel grid the way the atlas's
|
||||
glyphs do. A bold face takes its fallback glyphs from the same fonts as a
|
||||
regular one, so the showcase's bold Japanese is M PLUS 1p Regular. The
|
||||
Diagnostics page's font row counts the glyphs drawn from fallback fonts.
|
||||
- **Lines break by UAX #14**, through mojibake: between Japanese characters but
|
||||
not before a full stop or a small kana, after a hyphen, never inside a
|
||||
number. A wrapped label is measured with the breaks it is drawn with, and each
|
||||
line is measured whole — shaped text is not the sum of its glyphs — so its
|
||||
box is exactly as tall as its lines.
|
||||
|
||||
**How it gets in.** `rebuild_font` hands the module every face after the bake,
|
||||
and the module takes over each face's width function, so Nuklear measures a
|
||||
string the way the module will draw it. Each frame, before `nk_sdl_render_ex`
|
||||
turns the commands into vertices, the runtime calls `reaktor_text_prepare`,
|
||||
which turns each text command the atlas cannot draw into a custom command in
|
||||
the same place in the list — so the text still draws over what is under it and
|
||||
under what is over it — and the custom command's callback adds the glyph
|
||||
quads. Shaping is cached by string and font file, and does not depend on size;
|
||||
rasterized glyphs are cached by font, glyph and size. Each cache starts over
|
||||
when it fills.
|
||||
|
||||
**Fonts are the application's to supply.** The showcase ships M PLUS 1p for its
|
||||
Japanese catalog, added in `sample_args`, and nothing else; a program that
|
||||
shows Arabic, Hebrew or an Indic script points the module at a font that has
|
||||
it:
|
||||
|
||||
```bash
|
||||
./build/showcase --font-fallback C:/Windows/Fonts/segoeui.ttf --font-fallback C:/Windows/Fonts/Nirmala.ttc
|
||||
```
|
||||
|
||||
Segoe UI has Arabic and Hebrew, Nirmala UI the Indic scripts. A font collection
|
||||
is read at its first font.
|
||||
|
||||
Without the module, `reaktor_text_none` breaks a line after a space, or in a run
|
||||
with none before the glyph that would not fit — keeping that glyph, which
|
||||
`nk_label_wrap` loses.
|
||||
|
||||
mojibake is built with only what the module calls, its collation, IDNA,
|
||||
security and character-name tables left out. kb_text_shape is one header,
|
||||
compiled once, in `core/text/kb.c`. Between them they are most of what the
|
||||
module costs — see [PERFORMANCE.md](PERFORMANCE.md#modules).
|
||||
|
||||
Not there yet:
|
||||
|
||||
- **Editing shaped text.** A text field measures its caret a glyph at a time,
|
||||
which is right for Japanese and wrong inside a joined Arabic word, and the
|
||||
caret moves in the order the text is stored, not the order it is shown.
|
||||
- **A single-line label in a right-to-left language** is still set against the
|
||||
left edge; only wrapped paragraphs keep to the right one.
|
||||
- **Language-specific forms.** The shaper is told a script but not a language,
|
||||
so a font's Serbian or Urdu variants go unused.
|
||||
- **Color glyphs, emoji and vertical text.**
|
||||
- **Normalization, case mapping and collation**, which mojibake has and
|
||||
nothing calls yet.
|
||||
|
||||
## Nuklear behaviors that have already cost an afternoon
|
||||
|
||||
@@ -469,3 +706,10 @@ Each was found the hard way. None is a bug.
|
||||
- **`nk_rule_horizontal` fills its whole widget rect** — the row height *is*
|
||||
the line thickness.
|
||||
- **`nk_sdl_font_stash_begin` leaks the atlas it replaces.**
|
||||
- **`nk_label_wrap` breaks at spaces only**, and a line without one keeps the
|
||||
glyph that overflowed, where the clip hides it — a character lost from the end
|
||||
of every line of Japanese. `reaktor_label` breaks its own lines.
|
||||
- **A merged font joins the atlas's *first* font**, not the one added last:
|
||||
`merge_mode` extends `atlas->fonts`, whichever face the call was meant for.
|
||||
- **`cfg.range` is read on every glyph lookup**, not only while baking. The
|
||||
ranges have to live as long as the fonts do, which is why `App` holds them.
|
||||
|
||||
@@ -8,7 +8,7 @@ README. `git submodule status` prints the current pins.
|
||||
| Component | Used for | License |
|
||||
| --- | --- | --- |
|
||||
| [SDL](https://github.com/libsdl-org/SDL) | Window, input, renderer, system theme, file dialog | zlib |
|
||||
| [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) | Immediate-mode widgets, font baking, the SDL3 backend | MIT **or** public domain, your choice |
|
||||
| [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) | Immediate-mode widgets, font baking, the SDL3 backend, and the stb_truetype the Text module rasterizes with | MIT **or** public domain, your choice |
|
||||
| [LCUI](https://github.com/lc-soft/LCUI) | `libcss` (parse, match, cascade) and `yutil` | MIT |
|
||||
| [Onlay](https://github.com/Alpaq92/Onlay) | Computing the rectangles — a fork of [randrew/layout](https://github.com/randrew/layout) | MIT |
|
||||
| [tiny.css](https://github.com/ihsan6133/tiny.css) | The stylesheet the whole look comes from | MIT |
|
||||
@@ -16,11 +16,24 @@ README. `git submodule status` prints the current pins.
|
||||
| [Ionicons](https://github.com/ionic-team/ionicons) | Every icon, read as SVG at runtime | MIT |
|
||||
| [plutosvg](https://github.com/sammycage/plutosvg) | Rasterizing those SVGs | MIT |
|
||||
| [plutovg](https://github.com/sammycage/plutovg) | The canvas plutosvg draws on (nested submodule) | MIT |
|
||||
| [mojibake](https://github.com/zaerl/mojibake) | Unicode's bidirectional algorithm (UAX #9) and line breaking rules (UAX #14), for the Text module | MIT |
|
||||
| [kb_text_shape](https://github.com/JimmyLefevre/kb) | OpenType shaping, script segmentation and font coverage, for the Text module | zlib |
|
||||
|
||||
Only two of LCUI's libraries are built — `libcss` and `yutil` — not the
|
||||
toolkit. SDL is built static, with audio, joystick, haptic, HID, sensor,
|
||||
camera, power, GPU, tray and offscreen disabled, along with the render backends
|
||||
this application can never select.
|
||||
this application can never select. mojibake is built with its own collation,
|
||||
IDNA, security and character-name options off, since nothing here calls them.
|
||||
kb_text_shape is a single header, compiled once in `core/text/kb.c`. It shapes
|
||||
and does not rasterize, so the Text module draws its glyphs with the
|
||||
stb_truetype Nuklear already compiles.
|
||||
|
||||
The shaper was to have been [hamza](https://github.com/saidwho12/hamza), which
|
||||
is not used, so it has no row above. Its license file is MIT, but its sources
|
||||
still carry the LGPL headers that file replaced; its feature tables stop at
|
||||
Arabic, Buginese, Hangul and Hebrew, with none for the Indic scripts; and MSVC's
|
||||
C compiler cannot build it, since it declares an empty struct and uses GNU's
|
||||
range designators. kb_text_shape has none of those problems.
|
||||
|
||||
## The one dependency that is not a submodule
|
||||
|
||||
@@ -47,8 +60,9 @@ maintenance question pointed the same way.
|
||||
`external/nuklear/demo/sdl3_renderer/` and covered by Nuklear's license
|
||||
above. Every deviation from upstream is marked `REAKTOR`: the atlas is baked
|
||||
and uploaded 8-bit indexed rather than RGBA32; untextured geometry samples a
|
||||
1×1 white texture of its own; vertices are put on the pixel grid; and
|
||||
`nk_sdl_render_ex` feathers fills and strokes independently.
|
||||
1×1 white texture of its own; vertices are put on the pixel grid;
|
||||
`nk_sdl_render_ex` feathers fills and strokes independently; and the atlas's
|
||||
palette is made public, for the Text module's glyph textures to share.
|
||||
|
||||
It could not stay an include because the first of those is chosen inside
|
||||
`nk_sdl_font_stash_end`, and this project does not edit submodules. The cost is
|
||||
@@ -65,7 +79,8 @@ not one to build a distributable on.
|
||||
|
||||
| Font | Role | License | Terms |
|
||||
| --- | --- | --- | --- |
|
||||
| **Aileron** | The UI face — Regular at five sizes, Bold for the title | CC0 1.0 | `assets/fonts/Aileron-Notice.txt` |
|
||||
| **Aileron** | The UI face — Regular and Bold, each at eight sizes | CC0 1.0 | `assets/fonts/Aileron-Notice.txt` |
|
||||
| **M PLUS 1p** | Japanese, for the characters Aileron lacks, at whatever size they are drawn | OFL 1.1 | `assets/fonts/MPLUS1p-Notice.txt` |
|
||||
|
||||
Aileron is by Sora Sagano of DOT COLON. Its download ships no license file
|
||||
either, so the terms were traced to their source: the font's own `name` table
|
||||
@@ -79,6 +94,34 @@ It is an OTF; Nuklear bakes through stb_truetype, which reads CFF outlines, so
|
||||
the format costs nothing. Switching face is one line — `FONT_FILE` in
|
||||
`core/render/draw.c`.
|
||||
|
||||
M PLUS 1p is by The M+ Project Authors. `MPLUS1p-Regular.ttf` is the file as
|
||||
Google Fonts ships it, byte for byte, and `MPLUS1p-Notice.txt` names the commit
|
||||
it came from and its SHA-256, then reproduces the Open Font License unchanged.
|
||||
The OFL lets a font be bundled with software that is not itself under the OFL,
|
||||
as long as the font is not sold on its own; it carries no Reserved Font Name.
|
||||
The showcase hands it to the Text module, which opens it only once it needs a
|
||||
character Aileron lacks — the Japanese catalog's; see
|
||||
[the texts](#the-texts-on-the-translations-page).
|
||||
|
||||
## The texts on the Translations page
|
||||
|
||||
The showcase's catalogs, `assets/locale/`, carry the opening of Hans Christian
|
||||
Andersen's *The Ugly Duckling* (1843) in three translations, chosen because
|
||||
each was published before 1931 by a translator who died before 1956:
|
||||
|
||||
| Language | Translation | Translator died | Text from |
|
||||
| --- | --- | --- | --- |
|
||||
| English | Mrs. H. B. Paull, *Hans Andersen's Fairy Tales*, Frederick Warne and Co., 1888 | 1888 | Wikisource |
|
||||
| Polish | Cecylia Niewiadomska, *Baśnie*, Gebethner i Wolff, Warsaw, 1899 | 1925 | Polish Wikisource, from the National Library's scan |
|
||||
| Japanese | 菊池寛 (Kikuchi Kan), 小学生全集 第五巻『アンデルゼン童話集』, 興文社・文藝春秋社, 1928 | 1948 | Aozora Bunko, in modern spelling |
|
||||
|
||||
So all three are public domain in the United States, in every country that
|
||||
counts seventy years from the translator's death, and in Japan. The few that
|
||||
count longer - Mexico a hundred years, Colombia eighty - still protect the
|
||||
Japanese one; no Japanese translation of an Andersen tale clears them with a
|
||||
translator whose dates can be checked. Each catalog repeats its own
|
||||
attribution, and the page prints it under the story.
|
||||
|
||||
## The mark
|
||||
|
||||
`assets/icons/` is original work under this project's MIT license: the icon in its
|
||||
@@ -94,13 +137,15 @@ asked to build one. Nothing in that directory is part of a Reaktor build.
|
||||
|
||||
## What is redistributed
|
||||
|
||||
A native build links SDL, libcss, yutil, plutosvg and plutovg statically and
|
||||
compiles Nuklear and Onlay into the binary, so it carries the zlib and MIT
|
||||
terms above — all satisfied by shipping this file with it.
|
||||
A native build links SDL, libcss, yutil, plutosvg and plutovg statically, and
|
||||
mojibake and kb_text_shape when it takes the Text module, and compiles Nuklear
|
||||
and Onlay into the binary, so it carries the zlib and MIT terms above — all
|
||||
satisfied by shipping this file with it.
|
||||
|
||||
The application does **not** embed the stylesheets, the icons, the mark or the
|
||||
font. It opens them at runtime from the submodule checkout, resolved against
|
||||
the `.reaktor-root` marker, so a distributable build ships those files beside
|
||||
the binary. The WebAssembly build is the exception: Emscripten packages the
|
||||
files actually referenced into the `.data` bundle, which is why it needs no
|
||||
checkout beside it.
|
||||
The application does **not** embed the stylesheets, the icons, the mark, the
|
||||
fonts or the catalogs — the catalogs only when built with
|
||||
`-DREAKTOR_LOCALE_EMBED=ON`. It opens them at runtime from the submodule
|
||||
checkout, resolved against the `.reaktor-root` marker, so a distributable build
|
||||
ships those files beside the binary. The WebAssembly build is the exception:
|
||||
Emscripten packages the files actually referenced into the `.data` bundle,
|
||||
which is why it needs no checkout beside it.
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
# Performance
|
||||
|
||||
**Every pixel here is drawn by the CPU.** Nuklear turns the widgets into a
|
||||
list of shapes, SDL's software rasterizer fills them in, and no graphics card
|
||||
is asked for on any platform — [the renderer](DOCUMENTATION.md#the-renderer)
|
||||
explains why not. Which should be the expensive way to do this, and isn't,
|
||||
because of the other half of the design:
|
||||
**Every pixel is drawn by the CPU.** Nuklear turns the widgets into shapes, SDL's
|
||||
software rasterizer fills them in, and no graphics card is required on any
|
||||
platform — [the renderer](DOCUMENTATION.md#the-renderer) explains why.
|
||||
|
||||
**Nothing is drawn until something changes.** SDL sleeps on the event queue,
|
||||
and a frame is built only when the picture would actually differ. So the cost
|
||||
of running this is not a rate you pay per second — it is a price per frame,
|
||||
multiplied by how often the user makes one happen. A window nobody is touching
|
||||
costs nothing at all.
|
||||
|
||||
That is the sentence to keep in mind for everything below. **CPU is a count of
|
||||
**Nothing is drawn until something changes.** SDL sleeps on the event queue and
|
||||
builds a frame only when the picture would differ, so an untouched window costs
|
||||
nothing. Two consequences explain every number below: **CPU is a count of
|
||||
frames, not a load**, and **memory is a floor, not a curve** — once the font
|
||||
atlas and the icons are baked, nothing else grows.
|
||||
atlas and icons are baked, nothing grows.
|
||||
|
||||
The four-platform figures were taken on the build that shipped a single
|
||||
executable, at 1.00× scale in a 960×680 window. The tree now builds four, and
|
||||
the current Windows sizes are `showcase.exe` 2,531,328, `notepad.exe`
|
||||
2,370,560, `simple.exe` 2,341,888 and `bench.exe` 2,322,944 — the runtime is the
|
||||
same library in each, so everything below still describes what one of them
|
||||
costs to run.
|
||||
The four-platform figures were taken on an older build that shipped a single
|
||||
executable, at 1.00× scale in a 960×680 window. The runtime is the same library
|
||||
in all four of today's executables, so they still describe what one costs. On
|
||||
Windows today: `showcase.exe` 3,338,240 bytes, `notepad.exe` 2,360,320,
|
||||
`simple.exe` 2,331,136, `bench.exe` 2,312,704. The showcase links all three
|
||||
optional modules; the other three link none.
|
||||
|
||||
## Against the others
|
||||
|
||||
@@ -31,65 +25,43 @@ Memory: Reaktor 10.0 MB, the same binary on D3D11 60.7 MB and on OpenGL
|
||||
CPU as a percent of one core: Reaktor 16.4%, D3D11 14.4%, OpenGL 14.1%,
|
||||
Flutter 16.6%, Electron 39.0%, Kotlin Multiplatform 56.1%](../assets/rest/benchmark.svg)
|
||||
|
||||
The workload is not original. It is
|
||||
[ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s benchmark — 64 boxes
|
||||
rotating at 60 fps in an 800×600 window — and the comparison started as a
|
||||
reading of the five figures in its README. Those are gone from the chart now.
|
||||
They were taken on an M1 Max with no denominator named for the CPU column, and
|
||||
mixing them with a run on this desk was comparing two machines and calling it a
|
||||
comparison of frameworks. **Shaft's own figures are excluded, and Shaft is not
|
||||
plotted at all, because it does not build on Windows** — see below. The
|
||||
picture it defined is what survived, and every bar above is a run of it here.
|
||||
The workload is [ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s: 64 boxes
|
||||
rotating at 60 fps in an 800×600 window. Every bar is a run of it on one
|
||||
machine, by one procedure — [`benchmarks/`](../benchmarks/BENCHMARKS.md) has the
|
||||
projects and the runner. Reaktor appears three times because `--renderer`
|
||||
changes what it is. Shaft itself isn't plotted: it doesn't link on Windows.
|
||||
|
||||
Four frameworks drawing that picture on one machine, measured by one
|
||||
procedure, with Reaktor entered three times because `--renderer` changes what
|
||||
it is: `benchmarks/` holds the other three as projects of their own — plus a
|
||||
fourth for Shaft, which is the one that did not run — and
|
||||
`benchmarks/run.ps1` runs them and samples each from outside over its whole
|
||||
process tree, because Electron is five processes and a JVM's idea of its own
|
||||
memory is not the system's.
|
||||
| Arm | Memory | CPU, one core |
|
||||
| --- | --- | --- |
|
||||
| **Reaktor**, `software` | **10.0 MB** | **16.4%** |
|
||||
| **Reaktor**, `direct3d11` | 60.7 MB | 14.4% |
|
||||
| **Reaktor**, `opengl` | 90.2 MB | 14.1% |
|
||||
| Flutter | 92.2 MB | 16.6% |
|
||||
| Electron | 158.3 MB | 39.0% |
|
||||
| Kotlin Multiplatform | 669.8 MB | 56.1% |
|
||||
|
||||
**The two panels agree, which they did not use to.** Reaktor draws this in a
|
||||
ninth of Flutter's memory and a sixty-seventh of Compose's, and it is also the
|
||||
cheapest arm on CPU that is not one of its own GPU backends.
|
||||
- **Reaktor draws this in a ninth of Flutter's memory** and a sixty-seventh of
|
||||
Compose's, and is the cheapest arm on CPU apart from its own GPU backends.
|
||||
- **The GPU backends buy about two points of CPU for six to nine times the
|
||||
memory.** That's why the default stays software. On a GPU driver Reaktor
|
||||
costs what the GPU frameworks cost: `opengl` is 90.2 MB against Flutter's
|
||||
92.2, and `direct3d11`, `opengl` and Flutter fall within 2.5 points on CPU.
|
||||
Nuklear-through-SDL and Skia-through-Flutter share almost nothing above the
|
||||
driver, so at that size the number is the GL context and its buffers, not the
|
||||
framework.
|
||||
|
||||
| Arm | Memory | CPU, one core | CPU, all 12 threads |
|
||||
| --- | --- | --- | --- |
|
||||
| **Reaktor**, software | **10.0 MB** | **16.4%** | **1.4%** |
|
||||
| **Reaktor**, `direct3d11` | 60.7 MB | 14.4% | 1.2% |
|
||||
| **Reaktor**, `opengl` | 90.2 MB | 14.1% | 1.2% |
|
||||
| Flutter | 92.2 MB | 16.6% | 1.4% |
|
||||
| Electron | 158.3 MB | 39.0% | 3.3% |
|
||||
| Kotlin Multiplatform | 669.8 MB | 56.1% | 4.7% |
|
||||
### Why the top row used to read 67.3%
|
||||
|
||||
**That top row used to read 67.3%, and the paragraph under it used to explain
|
||||
why a CPU rasterizer among GPU ones should be the most expensive thing in the
|
||||
table.** It was not paying for rasterizing. It was paying for being asked the
|
||||
wrong way: `nk_convert` flattens every shape to triangles, so a panel
|
||||
background arrived as two textured, alpha-blended triangles covering the
|
||||
window. Measured three ways, the same coverage costs 16.38 ms as textured
|
||||
blended geometry, 6.95 ms untextured, and 0.12 ms as a fill. The renderer now
|
||||
recognises an axis-aligned quad of one color and issues the fill, and skips the
|
||||
blend when the color is opaque, because source-over with an alpha of one is the
|
||||
source. A frame of this benchmark went from 11.48 ms to 2.12 ms and an empty
|
||||
window from 8.06 ms to 0.54 ms, drawing the same pixels to within one least
|
||||
significant bit — `--renderer direct3d11` is unchanged to the bit. The lesson
|
||||
is the one at the top of this file: the cost was in the asking, not the
|
||||
drawing, and only measuring the present found it.
|
||||
It wasn't rasterizing. `nk_convert` flattens every shape into triangles, so a
|
||||
panel background arrived as two textured, alpha-blended triangles covering the
|
||||
window. The same coverage costs **16.38 ms** as textured blended geometry,
|
||||
**6.95 ms** untextured, and **0.12 ms** as a fill.
|
||||
|
||||
The first three rows are one executable. `--renderer` is the whole difference,
|
||||
and what it now buys is about two points of CPU for six to nine times the
|
||||
memory — which is no longer much of a trade, and is the reason the default
|
||||
stays where it is. On a GPU driver Reaktor costs what the GPU frameworks cost:
|
||||
**`opengl` lands on 90.2 MB against Flutter's 92.2**, and the CPU figures of
|
||||
all four GPU-drawing arms sit inside two and a half points of each other. Those
|
||||
two have almost nothing in common above the driver — Nuklear through SDL
|
||||
against Skia through the Flutter engine — which is the point: at that size the
|
||||
number is the GL context and its buffers, not the framework on top of it.
|
||||
|
||||
Both CPU columns are given because the question has to be asked: at 12 threads
|
||||
the two readings differ by a factor of twelve, and a comparison that does not
|
||||
say which one it means is not saying anything.
|
||||
The renderer now recognizes an axis-aligned quad of one color and issues a
|
||||
fill, and skips blending when the color is opaque. A frame of this benchmark
|
||||
went from **11.48 ms to 2.12 ms**, and an empty window from 8.06 ms to 0.54 ms.
|
||||
The pixels match to within one least significant bit, and `--renderer
|
||||
direct3d11` output is unchanged to the bit. Only measuring the present found it.
|
||||
|
||||
### How it was measured
|
||||
|
||||
@@ -97,82 +69,16 @@ say which one it means is not saying anything.
|
||||
./benchmarks/run.ps1 -Seconds 6 -Fps 60 -Runs 10
|
||||
```
|
||||
|
||||
`--fps 60` holds every arm to a real 60 fps and sleeps out the rest of each
|
||||
frame, so a process is charged for the drawing and not the wait. Each figure is
|
||||
the median of ten six-second runs. Three full passes moved the CPU medians by
|
||||
up to three points and the memory by less than a megabyte, so read the CPU
|
||||
column to the point and the memory column to the tenth. Startup is inside the measurement, so
|
||||
the run length matters — at three seconds instead of six, Electron reads 45.5%
|
||||
and Compose 60.7%, while Reaktor does not move.
|
||||
Every arm is held to 60 fps and sleeps out the rest of each frame, so it is
|
||||
charged for drawing, not waiting. Each figure is the median of ten 6-second
|
||||
runs; across three passes CPU moved by up to three points and memory by under a
|
||||
megabyte. Memory is the peak of summed private bytes across the process tree,
|
||||
and the JVM runs with no heap flags.
|
||||
|
||||
Memory is the peak of summed private bytes across the process tree, which for
|
||||
the JVM is with no heap flags: 670 MB is what Compose costs out of the box, not
|
||||
what it can be squeezed to.
|
||||
|
||||
What a single Reaktor frame costs is a separate question, and `--fps 60` is the
|
||||
wrong run to ask it in: with vsync on, the block lands inside the present and
|
||||
the frame reads as the whole 16.6 ms period. `--no-vsync` is the run that
|
||||
answers it, and here the frame goes from **11.42 ms on the software rasterizer
|
||||
to 0.41 on `direct3d11` and 0.27 on `opengl`** — in every case almost all of it
|
||||
the present.
|
||||
|
||||
Those are the drivers this SDL build actually has. `direct3d12` and `vulkan`
|
||||
say *not available* and fall back to D3D11, which is worth knowing before
|
||||
reading a figure attributed to them; `opengles2` does start, at 0.26 ms and
|
||||
143.7 MB, the memory being ANGLE's. The Diagnostics page prints the backend SDL
|
||||
settled on next to the one that was asked for, which is the only way to tell a
|
||||
fallback from a measurement.
|
||||
|
||||
The two renderers then disagree about whether that is the whole story.
|
||||
`bench` extrapolates its software frame to 68.2% of a core at 60 fps and the
|
||||
sampler charges the process 68.6%, which is as close as two different
|
||||
instruments get. For `direct3d11` `bench` says 2.5% and the sampler says 16.5%.
|
||||
Neither is wrong: the drawing really is that cheap, and the difference is
|
||||
everything the process is charged for that no frame counter can see — the
|
||||
driver's threads, the presentation, the wakeups that pace the rate. It is the
|
||||
reason the bars come from outside.
|
||||
|
||||
### What these replaced
|
||||
|
||||
The previous bars had five frameworks, but only Reaktor's were ours — the other
|
||||
four came from [ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s README, taken
|
||||
on an M1 Max, with no denominator named for the CPU figure. Reaktor's own
|
||||
numbers barely moved when they were measured properly: **9.6 MB against 10.0**,
|
||||
and 6.1% of the machine against **5.6%**. Everything around them did.
|
||||
|
||||
**The denominator was the whole trouble.** That panel was labeled percent of
|
||||
twelve cores, and on twelve cores Flutter measures **1.4%** here where their
|
||||
README shows 11.4%. Eightfold, in the direction that says their figure was per
|
||||
core — so the old chart was plotting one per-machine number against four
|
||||
per-core ones, in the same panel, which flattered the per-machine one by about
|
||||
twelve. On one denominator the memory ordering survives, and the CPU ordering
|
||||
went through two upheavals rather than one: first the software rasterizer came
|
||||
out the most expensive arm in the table, which is what a CPU rasterizer among
|
||||
GPU ones should be, and then it turned out not to be rasterizing that was
|
||||
expensive — see the fills above — and it came back to 16.4%.
|
||||
|
||||
Compose's 235.1 MB becoming 669.8 is a second kind of difference and not the
|
||||
same kind of finding. The JVM sizes its heap from the machine's RAM, so that
|
||||
bar says as much about this machine as it does about Compose.
|
||||
|
||||
**Shaft itself is absent, and not for want of trying.** Its Skia bundle ships
|
||||
Windows binaries and Shaft links D3D12 for Windows, but SwiftSDL3 0.1.6 never
|
||||
compiles its `joystick/virtual/`, `joystick/hidapi/` or `joystick/windows/`
|
||||
directories there, so `SDL_joystick.c` has nothing to link against. Everything
|
||||
else builds — Skia, and the benchmark's own Swift, 25 of 26 steps — and then
|
||||
the executable does not link:
|
||||
|
||||
```
|
||||
lld-link: error: undefined symbol: SDL_SetJoystickVirtualButtonInner
|
||||
```
|
||||
|
||||
That is the whole of it. Two earlier walls turned out to be this machine rather
|
||||
than Shaft, and both are gone: the build needs a developer shell, and it needs
|
||||
git told not to attempt symlinks. `benchmarks/README.md` has the commands. What
|
||||
remains cannot be fixed from this side — a package cannot add sources to
|
||||
another package's target, and dependencies here are read as they ship — so
|
||||
`benchmarks/shaft-bench` stays in the tree, building up to the link, waiting on
|
||||
a SwiftSDL3 that lists its Windows sources correctly.
|
||||
The bars come from that outside sampler rather than the apps' own frame
|
||||
counters, which miss driver threads and presentation: for `direct3d11`, `bench`
|
||||
extrapolated 2.5% of a core where the sampler charged 16.5%. `direct3d12` and
|
||||
`vulkan` are not available in this SDL build and fall back to D3D11.
|
||||
|
||||
## Size
|
||||
|
||||
@@ -187,18 +93,54 @@ a SwiftSDL3 that lists its Windows sources correctly.
|
||||
| Web bundle (macOS emsdk) | 1,389,145 |
|
||||
| Web bundle (GhostBSD emsdk) | 1,389,525 |
|
||||
|
||||
Everything links statically — SDL, libcss, plutosvg, plutovg, with Nuklear and
|
||||
Onlay compiled in — so nothing but the C runtime loads from outside the binary.
|
||||
The three emsdk builds agree to 211 bytes end to end, so the Closure and
|
||||
`wasm-opt` differences between host platforms turn out not to matter (Windows
|
||||
and Linux both on emscripten 6.0.9). The Linux bundle is 1,221,689 of `.wasm`,
|
||||
86,001 of packaged assets, 80,045 of `.js` and 1,451 of `.html`. GhostBSD makes
|
||||
a fourth and widens the spread to 380 bytes, but on emscripten 6.0.3 rather
|
||||
than 6.0.9 — so that gap is a toolchain version as much as a host.
|
||||
Everything links statically — SDL, libcss, plutosvg and plutovg, with Nuklear
|
||||
and Onlay compiled in, and mojibake and kb_text_shape wherever the Text module
|
||||
is — so nothing but the C runtime loads from outside the binary.
|
||||
|
||||
The Windows binary also carries the icon as a linked resource: 125 KB, nine
|
||||
sizes, the 256×256 one stored as PNG. `tools/mkicon.c` builds it from the SVG,
|
||||
by hand when needed.
|
||||
The Windows, Linux and macOS web bundles agree to within 211 bytes, so host
|
||||
differences in Closure and `wasm-opt` don't matter (Windows and Linux both on
|
||||
emscripten 6.0.9). The Linux bundle is 1,221,689 bytes of `.wasm`, 86,001 of
|
||||
packaged assets, 80,045 of `.js` and 1,451 of `.html`. GhostBSD widens the
|
||||
spread to 380 bytes, but on emscripten 6.0.3, so that gap is as much toolchain
|
||||
as host.
|
||||
|
||||
The Windows binary carries its icon as a linked resource: 125 KB, nine sizes,
|
||||
the 256×256 one stored as PNG. `tools/mkicon.c` builds it from the SVG.
|
||||
|
||||
### Modules
|
||||
|
||||
Each module off in turn, on the same machine and toolchain; the web figures
|
||||
are Windows emsdk 6.0.9. Only the showcase links them, so only the showcase is
|
||||
measured.
|
||||
|
||||
| `showcase` | Default | Module off | Saved |
|
||||
| --- | --- | --- | --- |
|
||||
| `.exe`, accessibility bridges | 3,338,240 | 3,324,928 | 13,312 (0.40%) |
|
||||
| `.exe`, Locale | 3,338,240 | 3,322,880 | 15,360 (0.46%) |
|
||||
| `.exe`, Text | 3,338,240 | 2,551,296 | 786,944 (23.6%) |
|
||||
| `.wasm` + `.js`, accessibility bridges | 1,851,832 | 1,848,990 | 2,842 (0.15%) |
|
||||
| `.wasm` + `.js`, Locale | 1,851,832 | 1,837,332 | 14,500 (0.78%) |
|
||||
| `.wasm` + `.js`, Text | 1,851,832 | 1,361,532 | 490,300 (26.5%) |
|
||||
| `.data`, Locale | 1,867,379 | 101,758 | 1,765,621 (94.6%) |
|
||||
| `.data`, Text | 1,867,379 | 108,691 | 1,758,688 (94.2%) |
|
||||
|
||||
**The bridges are small**: switching them off drops their libraries, not bytes.
|
||||
Pixels and `--a11y-dump` stay byte-identical; only a screen reader notices, as
|
||||
Windows UI Automation finds 92 elements on the Buttons page and none without
|
||||
them.
|
||||
|
||||
**Text is mostly tables and a font.** Of its 787 KB, kb_text_shape's object file
|
||||
is 113 KB of code and 443 KB of tables, and mojibake adds its line-breaking and
|
||||
bidirectional data. The `.data` it saves is M PLUS 1p, 1,758,688 bytes. Locale
|
||||
is 15 KB of code and 6,933 bytes of catalogs; compiled in
|
||||
(`-DREAKTOR_LOCALE_EMBED=ON`), `showcase.exe` is 3,344,896 bytes.
|
||||
|
||||
**Text costs memory once it draws.** Medians of private bytes over ten launches
|
||||
each: on the Diagnostics page, 8.0 MB with every module, 7.6 MB with Text off
|
||||
and 8.2 MB with Locale off, Text's 0.4 MB being kb_text_shape's tables, which
|
||||
are not `const` and so are committed without being touched. On the Translations
|
||||
page, 10.8 MB against 7.7 MB without Text: M PLUS 1p held open to rasterize
|
||||
from, what kb_text_shape parses out of it, the glyph texture and the caches.
|
||||
|
||||
## Memory
|
||||
|
||||
@@ -209,97 +151,89 @@ Idle on the Login tab.
|
||||
| Committed / private / footprint | **9.0 MB** | **4.3 MB** | **~30 MB** | **5.1 MB** |
|
||||
| Resident / working set | **29–34 MB** | **11.4 MB** | **33–36 MB** | **11.9 MB** |
|
||||
|
||||
Two different questions, not two estimates of one: committed is what the
|
||||
process asked the system to back, resident is what is in RAM now including
|
||||
shared library pages that are not this process's to give back.
|
||||
The rows answer different questions: committed is what the process asked the
|
||||
system to back; resident is what's in RAM right now, including shared library
|
||||
pages that aren't the process's to give back.
|
||||
|
||||
**Linux started at 123.6 MB, and almost none of it was ours.** SDL's X11
|
||||
driver sets up OpenGL whatever renderer you ask it for, and on a machine with
|
||||
no GPU that OpenGL is Mesa's software one, which drags in LLVM: 53 MB of
|
||||
libLLVM, 10 of Mesa, 30 of heap. Compiling SDL's GL drivers out took it to the
|
||||
4.3 MB above; `-DREAKTOR_SDL_GL=ON` puts them back.
|
||||
**Linux started at 123.6 MB, almost none of it ours.** SDL's X11 driver sets up
|
||||
OpenGL whatever renderer you ask for, and on a machine with no GPU that means
|
||||
Mesa's software OpenGL, which loads LLVM: 53 MB of libLLVM, 10 of Mesa, 30 of
|
||||
heap. Compiling SDL's GL drivers out brought it to 4.3 MB;
|
||||
`-DREAKTOR_SDL_GL=ON` puts them back.
|
||||
|
||||
**GhostBSD lands beside Linux on both rows**, 0.5 MB apart on resident and 0.8
|
||||
on the other, which is what the same rasterizer on the same X11 with the same
|
||||
absent GPU should do. Of its 5.1 MB, 2.5 MB is a single SysV shared segment of
|
||||
2,611,200 bytes — 960×680×4, SDL's framebuffer handed to the X server through
|
||||
MIT-SHM — leaving 2.6 MB that is genuinely this process's. That one mapping is
|
||||
the buffer the macOS paragraph below is about, shared here rather than copied.
|
||||
The column is swap-backed resident, not Linux's private-clean-plus-dirty:
|
||||
`reaktor_process_memory` in `core/base/util.c` branches on `_WIN32` and
|
||||
`__linux__` only, so on FreeBSD the app reports zero for its own memory and
|
||||
these came from `ps` and `procstat -v`, as macOS came from `vmmap`.
|
||||
**GhostBSD lands beside Linux**, within 0.5 MB on resident and 0.8 MB on the
|
||||
other row — as expected for the same rasterizer on the same X11 with no GPU. Of
|
||||
its 5.1 MB, 2.5 MB is one SysV shared segment of 2,611,200 bytes (960×680×4):
|
||||
SDL's framebuffer, handed to the X server over MIT-SHM. That leaves 2.6 MB that
|
||||
is genuinely the process's own. That column is swap-backed resident, not Linux's
|
||||
private clean-plus-dirty: `reaktor_process_memory` in `core/base/util.c` handles
|
||||
only `_WIN32` and `__linux__`, so on FreeBSD these came from `ps` and
|
||||
`procstat -v`, as macOS came from `vmmap`.
|
||||
|
||||
**macOS is ~7× Linux, and the gap is outside this code.** `vmmap` splits the
|
||||
~30 MB into ~15 MB of Cocoa floor and ~12 MB of heap, most of that three
|
||||
~2.5 MB bitmaps — SDL's render target, its staging copy, the font atlas. X11
|
||||
shares one buffer between app and server; macOS keeps a private copy at every
|
||||
step of the compositor, which is why it does not sit near Linux. The floor
|
||||
without a renderer rewrite is 26–28 MB, and a Retina display pushes committed
|
||||
toward 50 MB.
|
||||
~30 MB into ~15 MB of Cocoa floor and ~12 MB of heap, most of that three ~2.5 MB
|
||||
bitmaps: SDL's render target, its staging copy, and the font atlas. X11 shares
|
||||
one buffer between app and server; macOS keeps a private copy at each step of
|
||||
the compositor. Without a renderer rewrite the floor is 26–28 MB, and a Retina
|
||||
display pushes committed toward 50 MB.
|
||||
|
||||
Windows spreads about 2 MB between identical runs, so a single reading against
|
||||
a single reading means nothing; ten launches per arm resolve about 1 MB. When
|
||||
that is not enough, `tools/vmwalk.c` attributes another process's private bytes
|
||||
to named buckets and prints what it could not account for rather than
|
||||
pretending the buckets are exhaustive. Build it with
|
||||
`cmake --build build --target vmwalk`.
|
||||
Windows varies by about 2 MB between identical runs, so compare ten launches,
|
||||
not one; that resolves about 1 MB. For finer attribution, `tools/vmwalk.c`
|
||||
splits another process's private bytes into named buckets and reports what it
|
||||
couldn't account for. Build it with `cmake --build build --target vmwalk`.
|
||||
|
||||
## CPU
|
||||
|
||||
**At rest: 0% of one core** on Windows, Linux and GhostBSD, every tab. Not
|
||||
"low" — nothing. macOS settles around **0.3–0.5%**: CoreAnimation ticks the
|
||||
window periodically and each tick wakes `SDL_WaitEvent` for a no-op iteration.
|
||||
The cost is the wake, not a frame.
|
||||
**At rest: 0% of a core** on Windows, Linux and GhostBSD, on every tab. macOS
|
||||
settles around **0.3–0.5%**: CoreAnimation ticks the window now and then, and
|
||||
each tick wakes `SDL_WaitEvent` for an iteration that draws nothing.
|
||||
|
||||
Forced to redraw at a fixed rate, 960×680:
|
||||
Forced to redraw continuously, at 960×680:
|
||||
|
||||
| Page | Windows | Linux | macOS | GhostBSD |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Login | 6.8–6.9 ms/frame | 6.2–6.7 ms/frame | 17.5–20.5 ms/frame | 6.2–8.3 ms/frame |
|
||||
| Buttons (the busiest) | 11.5–12.2 ms/frame | 11.7–13.0 ms/frame | 29.6–30.2 ms/frame | 13.4–15.3 ms/frame |
|
||||
|
||||
The same rasterizer on all four, so Windows and Linux agreeing is expected
|
||||
rather than lucky. macOS pays an extra pass: SDL's Metal renderer uploads the
|
||||
software bitmap to a texture and presents that, the same private copy at every
|
||||
step that dominates the memory table. Cost is linear in frames — a pointer
|
||||
swept across a row of buttons draws one per hover crossing.
|
||||
It's the same rasterizer on all four, so Windows and Linux agreeing is
|
||||
expected. macOS pays an extra pass: SDL's Metal renderer uploads the software
|
||||
bitmap to a texture and presents that — the same private copy that dominates
|
||||
its memory. Cost scales with frames: sweeping the pointer across a row of
|
||||
buttons draws one per hover crossing.
|
||||
|
||||
GhostBSD's frame is present, not drawing: 6.7 ms of the Login median's 7.1 and
|
||||
11.1 ms of the Buttons median's 14.8 go to the present alone. Its X server
|
||||
drives VMware's SVGA II with no 3D, so a frame is a software blit into the
|
||||
virtual framebuffer and then out to the host. The other three columns' splits
|
||||
were not recorded; these ranges are p10–p90 of 31 samples.
|
||||
On GhostBSD the frame is mostly present: 6.7 ms of Login's 7.1 ms median, and
|
||||
11.1 ms of Buttons' 14.8. Its X server drives VMware's SVGA II with no 3D, so a
|
||||
frame is a software blit into the virtual framebuffer, then out to the host. The
|
||||
other platforms' splits weren't recorded; the ranges are p10–p90 of 31 samples.
|
||||
|
||||
The accessibility tree adds **4.2 µs** to a drawn frame (82 nodes), below the
|
||||
noise above. And the figure that made the software default worth it: on the
|
||||
GPU-less VM, `direct3d11` falls back to WARP and the frame goes from 4.7 ms to
|
||||
**20.3 ms**. A machine with a real GPU inverts that — see
|
||||
**Against the others**.
|
||||
The accessibility tree adds **4.2 µs** to a drawn frame (82 nodes) — below the
|
||||
noise above. And the number that made software the default: on the GPU-less VM,
|
||||
`direct3d11` falls back to WARP and a frame goes from 4.7 ms to **20.3 ms**
|
||||
(measured before the fill fix). With a real GPU that reverses — see **Against
|
||||
the others**.
|
||||
|
||||
## What it needs to run
|
||||
|
||||
**No GPU** — a machine that can run a browser can run this. Budget about
|
||||
**10 MB of RAM** and a few hundred triangles a frame. Two things a deployment
|
||||
does need: the asset files, found by walking up to the `.reaktor-root` marker
|
||||
(the web build packages them into its `.data` bundle), and a served web build,
|
||||
since a `file://` page cannot fetch the `.wasm`.
|
||||
**No GPU** — anything that can run a browser can run this. Budget about **10 MB
|
||||
of RAM** and a few hundred triangles a frame. A deployment needs two things: the
|
||||
asset files, found by walking up to the `.reaktor-root` marker (the web build
|
||||
packs them into its `.data` bundle), and, for the web build, an HTTP server,
|
||||
since a `file://` page can't fetch the `.wasm`.
|
||||
|
||||
## Where the numbers came from
|
||||
|
||||
- **Windows** — 11 Pro (26200), x64, MSVC Release, in a VirtualBox VM with no
|
||||
Direct3D 11 adapter. Everything below **Size** was taken here.
|
||||
Direct3D 11 adapter. Everything from **Size** down was taken here.
|
||||
- **Windows, with a GPU** — 11 Pro (26200), x64, MSVC Release, Ryzen 5 4600H
|
||||
(6 cores / 12 threads), GeForce RTX 2060, 1920×1080 at 120 Hz, no display
|
||||
scaling. All five bars of **Against the others** were taken here, in the
|
||||
800×600 window every arm asks for. The other three frameworks were built
|
||||
here too: Electron 44.3.0 on Node 22, Flutter 3.38.0, and Compose
|
||||
Multiplatform 1.12.0 on Kotlin 2.4.20 and a Temurin JDK 21.
|
||||
- **Linux** — Debian 13, x86_64, GCC Release, X11, also without a GPU.
|
||||
scaling. Everything in **Against the others** was taken here, in the 800×600
|
||||
window every arm asks for, with Electron 44.3.0 on Node 22, Flutter 3.38.0,
|
||||
and Compose Multiplatform 1.12.0 on Kotlin 2.4.20 and a Temurin JDK 21.
|
||||
- **Linux** — Debian 13, x86_64, GCC Release, X11, no GPU.
|
||||
- **macOS** — 11.7 Big Sur, Intel iMac, Apple Clang 12, 1024×768 non-Retina,
|
||||
built with `-DCMAKE_OSX_SYSROOT=…/MacOSX11.3.sdk`.
|
||||
- **GhostBSD** — 26.1-R15.0p2, x86_64, Clang 19.1.7, X11, VMware, no 3D.
|
||||
- **The four platform columns** — 1.00× scale, 960×680 window.
|
||||
|
||||
The **Diagnostics** page reports the renderer, the frame breakdown and the
|
||||
resident set live, which is where to reproduce any of this.
|
||||
The **Diagnostics** page shows the renderer, the frame breakdown and the
|
||||
resident set live — that's where to reproduce any of this.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "a11y.h"
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_init(reaktor_a11y_action activate,
|
||||
reaktor_a11y_action focus, void *user)
|
||||
{
|
||||
(void)activate; (void)focus; (void)user;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
{
|
||||
(void)a; (void)focus_id;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_drain(void)
|
||||
{
|
||||
}
|
||||
@@ -109,15 +109,11 @@ reaktor_snap_update(const reaktor_a11y *a, unsigned focus_id)
|
||||
static const char *
|
||||
copy_text(int at, char **buf, size_t *left)
|
||||
{
|
||||
const char *src;
|
||||
size_t n;
|
||||
|
||||
if (at < 0 || *left < 2) return NULL;
|
||||
src = g.str + at;
|
||||
n = strlen(src);
|
||||
if (n > *left - 1) n = *left - 1;
|
||||
memcpy(*buf, src, n);
|
||||
(*buf)[n] = '\0';
|
||||
/* libdbus aborts on invalid UTF-8. */
|
||||
n = SDL_utf8strlcpy(*buf, g.str + at, *left);
|
||||
{
|
||||
const char *out = *buf;
|
||||
*buf += n + 1;
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef struct reaktor_snap_node {
|
||||
float num, lo, hi, step;
|
||||
} reaktor_snap_node;
|
||||
|
||||
#define REAKTOR_SNAP_TEXT 512
|
||||
#define REAKTOR_SNAP_TEXT 4096
|
||||
|
||||
int reaktor_snap_init(reaktor_a11y_action activate, reaktor_a11y_action focus,
|
||||
void *user);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#include "a11y.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
static reaktor_a11y_action g_activate, g_focus;
|
||||
static void *g_user;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
reaktor_a11y_web_activate(unsigned id)
|
||||
{
|
||||
@@ -102,12 +101,13 @@ EM_JS(void, web_a11y_node, (unsigned id, unsigned parent, const char *role,
|
||||
set('aria-valuemax', ranged ? String(hi) : null);
|
||||
set('aria-keyshortcuts', k ? k : null);
|
||||
|
||||
el.style.left = x + 'px'; el.style.top = y + 'px';
|
||||
el.style.width = w + 'px'; el.style.height = h + 'px';
|
||||
|
||||
var p = parent ? a.nodes[parent] : a.root;
|
||||
if (!p) p = a.root;
|
||||
if (el.parentNode !== p || p.lastChild !== el) p.appendChild(el);
|
||||
|
||||
el.ax = x; el.ay = y;
|
||||
el.style.left = (x - (p.ax || 0)) + 'px'; el.style.top = (y - (p.ay || 0)) + 'px';
|
||||
el.style.width = w + 'px'; el.style.height = h + 'px';
|
||||
});
|
||||
|
||||
EM_JS(void, web_a11y_end, (unsigned focus), {
|
||||
@@ -160,27 +160,3 @@ reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
}
|
||||
web_a11y_end(focus_id);
|
||||
}
|
||||
|
||||
#elif !defined(_WIN32) && !defined(REAKTOR_HAVE_ATSPI) && !defined(REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_init(reaktor_a11y_action activate,
|
||||
reaktor_a11y_action focus, void *user)
|
||||
{
|
||||
g_activate = activate;
|
||||
g_focus = focus;
|
||||
g_user = user;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
{
|
||||
(void)a; (void)focus_id;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_drain(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -758,11 +758,6 @@ reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
IRawElementProviderSimple_Release(&r->simple);
|
||||
}
|
||||
}
|
||||
/* On a change, not on every push. A push happens whenever the diff is
|
||||
* non-empty - any frame where a label's text or a widget's rect moved -
|
||||
* and re-announcing the same focus to a listening client on each of them
|
||||
* is both a lie and a COM object per frame. The AT-SPI and web bridges
|
||||
* already guard it this way. */
|
||||
if (focus_id != g_last_focus) {
|
||||
g_last_focus = focus_id;
|
||||
if (focus_id) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "internal.h"
|
||||
#include "declare.h"
|
||||
#include "anim.h"
|
||||
#include "locale.h"
|
||||
#include "sample.h"
|
||||
|
||||
static int
|
||||
@@ -22,12 +23,6 @@ reaktor_rss_mark(int step)
|
||||
reaktor_process_memory(&reaktor_rss[step], &reaktor_priv[step]);
|
||||
}
|
||||
|
||||
/* The flags the runtime owns, taken out of argv so the application never
|
||||
* sees them. What is left keeps its order, which is how the notepad still
|
||||
* finds the filename it was given.
|
||||
*
|
||||
* Answers the new argc. A flag that wants a value and is given none is left
|
||||
* in place rather than silently swallowing the next argument. */
|
||||
static int
|
||||
take_flags(App *app, int argc, char **argv)
|
||||
{
|
||||
@@ -40,6 +35,8 @@ take_flags(App *app, int argc, char **argv)
|
||||
if (v && SDL_strcmp(a, "--shot") == 0) { app->shot_path = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--a11y-dump") == 0) { app->dump_path = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--renderer") == 0) { app->renderer_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--lang") == 0) { app->lang_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--font-fallback") == 0) { reaktor_text_add_fallback(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--theme") == 0) {
|
||||
if (SDL_strcmp(v, "light") == 0) app->theme_mode = THEME_LIGHT;
|
||||
else if (SDL_strcmp(v, "dark") == 0) app->theme_mode = THEME_DARK;
|
||||
@@ -80,7 +77,6 @@ load_theme(App *app)
|
||||
sheets[n++] = core;
|
||||
sheets[n++] = own;
|
||||
|
||||
/* The override slot, read only while the application asks for it. */
|
||||
if (!app->css_override_off) {
|
||||
const char *want = USER_SHEET;
|
||||
SDL_IOStream *f;
|
||||
@@ -252,16 +248,6 @@ SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
app->theme_mode = THEME_SYSTEM;
|
||||
argc = take_flags(app, argc, argv);
|
||||
|
||||
/* The software rasterizer, on every platform. The app draws nothing at
|
||||
* rest, so a GPU buys it nothing it can measure, and one rasterizer
|
||||
* everywhere is one set of pixels to reason about - which matters because
|
||||
* the feathering rules in nk_sdl3_renderer.h are written against this
|
||||
* one. The detection below only labels what it got.
|
||||
*
|
||||
* --renderer lifts that, for measuring what the choice costs rather than
|
||||
* asserting it. Anything but "software" is handed to SDL as the driver to
|
||||
* try, and "auto" lets it pick; the feathering is then not what these
|
||||
* sources were written against, so the picture may differ. */
|
||||
if (app->renderer_pref && SDL_strcmp(app->renderer_pref, "software") != 0) {
|
||||
SDL_strlcpy(app->render_mode, app->renderer_pref,
|
||||
sizeof(app->render_mode));
|
||||
@@ -367,6 +353,8 @@ SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
if (!app->ctx) return SDL_APP_FAILURE;
|
||||
reaktor_rss_mark(RSS_NUKLEAR);
|
||||
|
||||
/* Before the atlas, which bakes what the catalogs need. */
|
||||
reaktor_locale_start(app->lang_pref);
|
||||
rebuild_font(app);
|
||||
reaktor_rss_mark(RSS_FONT);
|
||||
|
||||
@@ -377,7 +365,6 @@ SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
app->cur_pointer = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
|
||||
app->cur_text = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
||||
|
||||
/* The override slot starts empty; turning it on is the switch's job. */
|
||||
app->css_override_off = 1;
|
||||
|
||||
sample_args(app, argc, argv);
|
||||
@@ -749,6 +736,7 @@ SDL_AppIterate(void *appstate)
|
||||
fill = NK_ANTI_ALIASING_OFF;
|
||||
if (app->sw_noaa) line = NK_ANTI_ALIASING_OFF;
|
||||
}
|
||||
reaktor_text_prepare(ctx, app->ren);
|
||||
nk_sdl_render_ex(ctx, fill, line);
|
||||
}
|
||||
t_present0 = SDL_GetPerformanceCounter();
|
||||
@@ -768,11 +756,6 @@ SDL_AppIterate(void *appstate)
|
||||
}
|
||||
app->want_quit = 1;
|
||||
} else {
|
||||
/* Ask for another frame. A settled frame is not otherwise
|
||||
* guaranteed to be a drawn one: the app stops scheduling
|
||||
* frames the moment nothing is changing, which is exactly
|
||||
* when the picture is worth taking - so without this the
|
||||
* wait is for an event that never comes. */
|
||||
SDL_Event e;
|
||||
|
||||
app->dirty = 1;
|
||||
|
||||
@@ -1,27 +1,3 @@
|
||||
/* The workload the published comparison is measured on: rotating boxes,
|
||||
* drawn as fast as the display will take them.
|
||||
*
|
||||
* It is deliberately the case this library is worst at. Reaktor draws nothing
|
||||
* when nothing has changed, so every figure in PERFORMANCE.md is a count of
|
||||
* frames rather than a rate - and an animation that never stops removes that
|
||||
* advantage entirely. A benchmark that let it idle would be measuring the
|
||||
* design instead of the drawing.
|
||||
*
|
||||
* Answers on stdout after --bench-seconds and quits, so the numbers come from
|
||||
* the same counters the Diagnostics page reads.
|
||||
*
|
||||
* Two of them need a word. private_mb is what the process asked the system to
|
||||
* back, and it is stable to a tenth. cpu_percent is not: the same 386 frames
|
||||
* get charged anywhere from 0.3% to 99.6% of a core, because SDL's vsync wait
|
||||
* blocks on the compositor when it can and spins when it cannot, and the
|
||||
* charge follows the wait rather than the drawing. So --no-vsync takes the
|
||||
* wait out: frames run back to back, every millisecond in the run is work,
|
||||
* and ms_per_frame is what one frame actually costs. cpu_at_60fps is that
|
||||
* against a 16.67 ms budget, which is the number worth comparing.
|
||||
*
|
||||
* --fps holds the run to a rate instead, sleeping out the rest of each frame.
|
||||
* That charges the process for the drawing and not the wait, so cpu_percent
|
||||
* becomes a measured answer to the question cpu_at_60fps only extrapolates. */
|
||||
#include "internal.h"
|
||||
#include "declare.h"
|
||||
#include "sample.h"
|
||||
@@ -65,8 +41,6 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
g_cpu0 = reaktor_process_cpu_ms();
|
||||
}
|
||||
|
||||
/* Last frame's, not this one's - the runtime writes these after it
|
||||
* presents. One frame of 386 is not worth threading a callback for. */
|
||||
g_build_ms += app->build_ms_x100 / 100.0;
|
||||
g_render_ms += app->render_ms_x100 / 100.0;
|
||||
g_present_ms += app->present_ms_x100 / 100.0;
|
||||
@@ -120,9 +94,6 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Held to a rate, the wait is an explicit sleep rather than a vsync
|
||||
* block, so what the process is charged over the run is the drawing and
|
||||
* nothing else - which is what cpu_percent is worth reading here. */
|
||||
if (g_fps > 0.0) {
|
||||
Uint64 period = (Uint64)(1000000000.0 / g_fps + 0.5);
|
||||
Uint64 now = SDL_GetTicksNS();
|
||||
@@ -133,8 +104,6 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
else g_due_ns = now;
|
||||
}
|
||||
|
||||
/* Keep the frames coming. Nothing else will ask: the whole point of the
|
||||
* runtime is that it stops when the picture stops changing. */
|
||||
{
|
||||
SDL_Event e;
|
||||
|
||||
@@ -160,7 +129,7 @@ sample_window(reaktor_window_spec *out)
|
||||
{
|
||||
out->w = 800;
|
||||
out->h = 600;
|
||||
out->title = "Reaktor";
|
||||
out->title = "Bench";
|
||||
}
|
||||
|
||||
SDL_HitTestResult SDLCALL
|
||||
@@ -183,18 +152,10 @@ sample_args(App *app, int argc, char **argv)
|
||||
|
||||
(void)app;
|
||||
|
||||
/* Linked as a windowed app so no console flashes up when it is run
|
||||
* from a shortcut, which costs the stdout a console app gets for free.
|
||||
* Borrowing the parent's console hands it back, and when there is none
|
||||
* to borrow the prints go nowhere and the run is still valid. */
|
||||
#ifdef _WIN32
|
||||
{
|
||||
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
/* A handle already here means a pipe or a file the caller set up,
|
||||
* and reopening CONOUT$ over it would send the answers to a console
|
||||
* instead of to whoever asked for them. Only borrow a console when
|
||||
* there is nothing to write to at all. */
|
||||
if ((!out || out == INVALID_HANDLE_VALUE) &&
|
||||
AttachConsole(ATTACH_PARENT_PROCESS)) {
|
||||
FILE *f;
|
||||
|
||||
@@ -33,9 +33,6 @@ hash_of(const char *p, int n)
|
||||
return h;
|
||||
}
|
||||
|
||||
/* The length first, because it settles it without touching the text: an
|
||||
* insertion or a deletion changes it, and only an edit that happens to keep
|
||||
* the length the same has to be hashed. This runs on every drawn frame. */
|
||||
static int
|
||||
dirty(void)
|
||||
{
|
||||
@@ -229,8 +226,6 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
int
|
||||
sample_key(App *app, const SDL_Event *e)
|
||||
{
|
||||
/* reaktor_chord rather than a raw modifier test: it folds Cmd and Ctrl
|
||||
* together, so the same table works on macOS without a second spelling. */
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_N)) { new_file(); return 1; }
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_O)) {
|
||||
if (!reaktor_file_open(app))
|
||||
|
||||
@@ -9,7 +9,7 @@ sample_window(reaktor_window_spec *out)
|
||||
{
|
||||
out->w = WINDOW_WIDTH;
|
||||
out->h = WINDOW_HEIGHT;
|
||||
out->title = "Reaktor";
|
||||
out->title = "Showcase";
|
||||
out->borderless = 1;
|
||||
}
|
||||
|
||||
@@ -61,13 +61,15 @@ sample_tab(void)
|
||||
return g_tab;
|
||||
}
|
||||
|
||||
/* --tab and --scroll open the window on one page, scrolled to one place, so
|
||||
* two runs can be compared without clicking either of them into position.
|
||||
* The runtime has already taken its own flags out of argv. */
|
||||
void
|
||||
sample_args(App *app, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char font[1024];
|
||||
int i;
|
||||
|
||||
/* After every --font-fallback. */
|
||||
if (reaktor_path(font, sizeof font, "assets/fonts/MPLUS1p-Regular.ttf"))
|
||||
reaktor_text_add_fallback(font);
|
||||
|
||||
for (i = 1; i + 1 < argc; i++) {
|
||||
int n = SDL_atoi(argv[i + 1]);
|
||||
@@ -327,18 +329,64 @@ login_card(App *app, struct nk_context *ctx, float win_w, float body_y,
|
||||
nk_style_pop_style_item(ctx);
|
||||
}
|
||||
|
||||
static style_frame
|
||||
push_strip_look(struct nk_context *ctx, struct nk_color fg, struct nk_color wash)
|
||||
{
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.normal,
|
||||
nk_style_item_color(nk_rgba(0, 0, 0, 0)));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.hover,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.active,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_normal, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_hover, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_active, fg);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
|
||||
return (style_frame){ 3, 3, 2, 0, 0 };
|
||||
}
|
||||
|
||||
static struct nk_color
|
||||
strip_wash(void)
|
||||
{
|
||||
return reaktor_token("--background-hover", nk_rgba(128, 128, 128, 40));
|
||||
}
|
||||
|
||||
int
|
||||
sample_option(App *app, struct nk_context *ctx, const char *label, float w,
|
||||
int on)
|
||||
{
|
||||
struct nk_color fg = reaktor_token(on ? "--links" : "--text-muted", app->text);
|
||||
struct nk_rect b;
|
||||
style_frame look;
|
||||
unsigned id;
|
||||
int hit;
|
||||
|
||||
if (w <= 0.0f) {
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
w = f->width(f->userdata, f->height, label, (int)strlen(label))
|
||||
+ 2.0f * (float)TAB_PAD_X;
|
||||
}
|
||||
nk_layout_row_push(ctx, w);
|
||||
b = nk_widget_bounds(ctx);
|
||||
hot_push(app, b, 1, 1);
|
||||
|
||||
look = push_strip_look(ctx, fg, strip_wash());
|
||||
id = reaktor_note(app, REAKTOR_A11Y_RADIO, label, NULL,
|
||||
on ? REAKTOR_A11Y_CHECKED : 0u, b);
|
||||
hit = nk_button_label(ctx, label);
|
||||
if (reaktor_focus_activated(app, id)) hit = 1;
|
||||
pop_style(ctx, look);
|
||||
return hit && !on;
|
||||
}
|
||||
|
||||
static void
|
||||
tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
{
|
||||
const struct nk_user_font *font = pick_font(app, 16, 0);
|
||||
unsigned char c[4];
|
||||
struct nk_color accent = reaktor_style_token("--links", c)
|
||||
? col_of(c) : app->text;
|
||||
struct nk_color muted = reaktor_style_token("--text-muted", c)
|
||||
? col_of(c) : app->text;
|
||||
struct nk_color wash = reaktor_style_token("--background-hover", c)
|
||||
? col_of(c) : nk_rgba(128, 128, 128, 40);
|
||||
struct nk_color clear = nk_rgba(0, 0, 0, 0);
|
||||
struct nk_color accent = reaktor_token("--links", app->text);
|
||||
struct nk_color muted = reaktor_token("--text-muted", app->text);
|
||||
struct nk_color wash = strip_wash();
|
||||
struct nk_command_buffer *canvas;
|
||||
struct nk_rect strip;
|
||||
struct nk_rect active_r = nk_rect(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
@@ -347,10 +395,9 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
const float SW_PAD_X = 8.0f;
|
||||
const float TAB_SEP = 10.0f;
|
||||
const float TAB_EDGE = 4.0f;
|
||||
float sep = TAB_SEP, edge = TAB_EDGE;
|
||||
float sep = TAB_SEP;
|
||||
int i;
|
||||
|
||||
(void)win_w;
|
||||
strip = nk_widget_bounds(ctx);
|
||||
if (!nk_group_begin(ctx, "tabs", NK_WINDOW_NO_SCROLLBAR)) return;
|
||||
canvas = nk_window_get_canvas(ctx);
|
||||
@@ -376,20 +423,25 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
(int)strlen(n)) + 2.0f * (float)TAB_PAD_X;
|
||||
used += themew[i];
|
||||
}
|
||||
/* Tighter than a tab. A tab's padding is what separates it from the
|
||||
* tab beside it; this one stands alone at the end of the strip, so
|
||||
* the same padding just reads as a wide gray slab when it lights up. */
|
||||
sw_w = font->width(font->userdata, font->height, swl,
|
||||
(int)strlen(swl)) + 2.0f * SW_PAD_X;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
sw_w = 0.0f;
|
||||
#endif
|
||||
rest = (float)win_w - used - sw_w - sep - edge - 2.0f * 4.0f
|
||||
rest = (float)win_w - used - sw_w - TAB_SEP - TAB_EDGE - 2.0f * 4.0f
|
||||
- (float)(TAB_COUNT + 5) * 4.0f;
|
||||
|
||||
if (rest < 0.0f) { sep += rest; rest = 0.0f; }
|
||||
if (sep < 8.0f) { edge += sep - 8.0f; sep = 8.0f; }
|
||||
if (edge < 4.0f) edge = 4.0f;
|
||||
if (rest < 0.0f) {
|
||||
float over = -rest - (TAB_SEP - 8.0f);
|
||||
float trim = SDL_ceilf(over / (float)(TAB_COUNT + 3));
|
||||
|
||||
sep = over > 0.0f ? 8.0f : TAB_SEP + rest;
|
||||
rest = 0.0f;
|
||||
if (trim > 2.0f * ((float)TAB_PAD_X - 6.0f))
|
||||
trim = 2.0f * ((float)TAB_PAD_X - 6.0f);
|
||||
for (i = 0; over > 0.0f && i < TAB_COUNT; i++) tabw[i] -= trim;
|
||||
for (i = 0; over > 0.0f && i < 3; i++) themew[i] -= trim;
|
||||
}
|
||||
}
|
||||
|
||||
nk_style_push_font(ctx, font);
|
||||
@@ -397,25 +449,14 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
for (i = 0; i < TAB_COUNT; i++) {
|
||||
const char *name = reaktor_tab_names[i];
|
||||
float w = tabw[i];
|
||||
struct nk_color fg = (i == sample_tab()) ? accent : muted;
|
||||
struct nk_rect b;
|
||||
style_frame look;
|
||||
|
||||
nk_layout_row_push(ctx, w);
|
||||
b = nk_widget_bounds(ctx);
|
||||
hot_push(app, b, 1, 1);
|
||||
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.normal,
|
||||
nk_style_item_color(clear));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.hover,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.active,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_normal, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_hover, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_active, fg);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
|
||||
|
||||
look = push_strip_look(ctx, i == sample_tab() ? accent : muted, wash);
|
||||
{
|
||||
unsigned id = reaktor_note(app, REAKTOR_A11Y_TAB, name, NULL,
|
||||
i == sample_tab() ? REAKTOR_A11Y_SELECTED
|
||||
@@ -431,15 +472,7 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
if (hit) set_tab(app, i);
|
||||
}
|
||||
if (i == sample_tab()) active_r = b;
|
||||
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
pop_style(ctx, look);
|
||||
}
|
||||
nk_layout_row_push(ctx, rest);
|
||||
nk_spacing(ctx, 1);
|
||||
@@ -448,40 +481,11 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
reaktor_note_push(app, REAKTOR_A11Y_GROUP, "Color scheme", NULL, 0,
|
||||
strip);
|
||||
for (i = 0; i < 3; i++) {
|
||||
struct nk_color fg = (i == app->theme_mode) ? accent : muted;
|
||||
struct nk_rect b;
|
||||
|
||||
nk_layout_row_push(ctx, themew[i]);
|
||||
b = nk_widget_bounds(ctx);
|
||||
hot_push(app, b, 1, 1);
|
||||
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.normal,
|
||||
nk_style_item_color(clear));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.hover,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.active,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_normal, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_hover, fg);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_active, fg);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
|
||||
|
||||
reaktor_note(app, REAKTOR_A11Y_RADIO, g_theme_names[i], NULL,
|
||||
i == app->theme_mode ? REAKTOR_A11Y_CHECKED : 0u, b);
|
||||
if (nk_button_label(ctx, g_theme_names[i]) && i != app->theme_mode) {
|
||||
if (sample_option(app, ctx, g_theme_names[i], themew[i],
|
||||
i == app->theme_mode)) {
|
||||
app->theme_pending = i + 1;
|
||||
app->dirty = 1;
|
||||
}
|
||||
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
}
|
||||
|
||||
nk_layout_row_push(ctx, sep);
|
||||
@@ -492,25 +496,13 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
nk_layout_row_push(ctx, sw_w);
|
||||
{
|
||||
struct nk_rect b = nk_widget_bounds(ctx);
|
||||
style_frame look;
|
||||
|
||||
hot_push(app, b, 1, 1);
|
||||
reaktor_note(app, REAKTOR_A11Y_BUTTON, swl, NULL, 0, b);
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.normal,
|
||||
nk_style_item_color(clear));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.hover,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.active,
|
||||
nk_style_item_color(wash));
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_normal, muted);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_hover, muted);
|
||||
nk_style_push_color(ctx, &ctx->style.button.text_active, muted);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
|
||||
/* The slot pushed above is the wash, so the label has to fit inside
|
||||
* it with the sheet's own button padding taken off - and tiny.css
|
||||
* asks for nearly all of SW_PAD_X. Zero here: the wash is the
|
||||
* padding. */
|
||||
look = push_strip_look(ctx, muted, wash);
|
||||
nk_style_push_vec2(ctx, &ctx->style.button.padding, nk_vec2(0.0f, 0.0f));
|
||||
look.vec2s = 1;
|
||||
|
||||
if (nk_button_label(ctx, swl)) {
|
||||
#ifdef __APPLE__
|
||||
@@ -528,16 +520,7 @@ tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
app->dirty = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
nk_style_pop_vec2(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_color(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
pop_style(ctx, look);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
@@ -9,6 +10,7 @@
|
||||
#include "showcase.h"
|
||||
#include "declare.h"
|
||||
#include "anim.h"
|
||||
#include "locale.h"
|
||||
#include "style.h"
|
||||
|
||||
|
||||
@@ -23,7 +25,7 @@ const char *const reaktor_rss_names[RSS_STEPS] = {
|
||||
|
||||
const char *const reaktor_tab_names[TAB_COUNT] = {
|
||||
"Login", "Buttons", "Inputs", "Display", "Layout", "Popups", "Animation",
|
||||
"Styling", "Diagnostics"
|
||||
"Styling", "Translations", "Diagnostics"
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -882,9 +884,9 @@ page_display(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "nk_label_wrap breaks on words inside the row it was "
|
||||
"given, which is why the paragraphs on these pages "
|
||||
"measure their own height first.",
|
||||
.text = "A wrapped label breaks between words inside the row "
|
||||
"it was given, which is why the paragraphs on these "
|
||||
"pages measure their own height first.",
|
||||
.wrap = 1,
|
||||
.box = { .h = 40.0f, .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
@@ -1775,10 +1777,6 @@ page_styling(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "the same widgets as everywhere else");
|
||||
|
||||
REAKTOR_COLUMN(.gap = 10.0f) {
|
||||
/* No heights anywhere below. Every widget here takes the size its
|
||||
* rule asks for, and the rows take the height of what is in them -
|
||||
* which is the whole of what this page is claiming. Give any of them
|
||||
* a .h and the sheet stops being able to change it. */
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
@@ -1901,6 +1899,127 @@ diag_row(App *app, struct nk_context *ctx, const char *name, const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
format_row(struct nk_context *ctx, const char *label, const char *value)
|
||||
{
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = label, .color = "--text-muted", .box = { .w = 110.0f } });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = value, .wrap = 1, .box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
page_translations_formats(struct nk_context *ctx)
|
||||
{
|
||||
struct tm day;
|
||||
char date[96], time[32], number[48], money[192], plural[192];
|
||||
char a[48], b[48], c[48];
|
||||
|
||||
memset(&day, 0, sizeof day);
|
||||
day.tm_year = 1843 - 1900;
|
||||
day.tm_mon = 10;
|
||||
day.tm_mday = 11;
|
||||
day.tm_hour = 10;
|
||||
day.tm_min = 30;
|
||||
reaktor_format_date(date, sizeof date, &day, REAKTOR_DATE_FULL);
|
||||
reaktor_format_date(time, sizeof time, &day, REAKTOR_TIME_SHORT);
|
||||
reaktor_format_number(number, sizeof number, 1234567.891, 2);
|
||||
SDL_snprintf(money, sizeof money, "%s \xC2\xB7 %s \xC2\xB7 %s",
|
||||
reaktor_format_money(a, sizeof a, 1234.5, "PLN"),
|
||||
reaktor_format_money(b, sizeof b, 1234.5, "USD"),
|
||||
reaktor_format_money(c, sizeof c, 123456.0, "JPY"));
|
||||
SDL_snprintf(plural, sizeof plural, "%s \xC2\xB7 %s \xC2\xB7 %s",
|
||||
reaktor_trn("locale.count", 1, a, sizeof a),
|
||||
reaktor_trn("locale.count", 5, b, sizeof b),
|
||||
reaktor_trn("locale.count", 22, c, sizeof c));
|
||||
|
||||
REAKTOR_COLUMN(.w = 360.0f, .gap = ctx->style.window.spacing.y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.formats"), .style = "h4",
|
||||
.color = "--text-bright", .box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
format_row(ctx, reaktor_tr("locale.date"), date);
|
||||
format_row(ctx, reaktor_tr("locale.time"), time);
|
||||
format_row(ctx, reaktor_tr("locale.number"), number);
|
||||
format_row(ctx, reaktor_tr("locale.money"), money);
|
||||
format_row(ctx, reaktor_tr("locale.plural"), plural);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
page_translations(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
{
|
||||
const char *story = reaktor_tr("locale.story");
|
||||
char para[4096];
|
||||
|
||||
(void)s;
|
||||
if (reaktor_locale_count() == 0) {
|
||||
section(app, ctx, "No catalogs",
|
||||
"This build has nothing to translate with: it was configured "
|
||||
"with -DREAKTOR_LOCALE=OFF, or assets/locale was left behind "
|
||||
"when it was copied.");
|
||||
return;
|
||||
}
|
||||
|
||||
section(app, ctx, "The same page in three languages",
|
||||
"Pick a language and everything under the line is looked up by "
|
||||
"key in its catalog; the code that draws it does not know which "
|
||||
"one it was. Polish is Aileron, from the font atlas. Aileron has "
|
||||
"no Japanese, so the Text module shapes it and draws it from "
|
||||
"M PLUS 1p, at whatever size it is set in.");
|
||||
api(app, ctx, "reaktor_tr / reaktor_trn / reaktor_format_date / "
|
||||
"reaktor_format_money");
|
||||
|
||||
{
|
||||
int i, n = reaktor_locale_count();
|
||||
struct nk_rect row;
|
||||
|
||||
nk_layout_row_begin(ctx, NK_STATIC, (float)(TAB_H - 6), n);
|
||||
row = nk_widget_bounds(ctx);
|
||||
row.w = nk_window_get_content_region_size(ctx).x;
|
||||
reaktor_note_push(app, REAKTOR_A11Y_GROUP, "Language", NULL, 0, row);
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *code = reaktor_locale_code(i);
|
||||
|
||||
if (sample_option(app, ctx, reaktor_locale_name(i), 0.0f,
|
||||
!strcmp(code, reaktor_locale_current())))
|
||||
reaktor_locale_set(code);
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
nk_layout_row_end(ctx);
|
||||
}
|
||||
rule(ctx);
|
||||
|
||||
REAKTOR_ROW(.gap = 40.0f, .flags = REAKTOR_LAY_WRAP) {
|
||||
REAKTOR_COLUMN(.w = SDL_min(nk_window_get_content_region_size(ctx).x, 640.0f),
|
||||
.gap = ctx->style.window.spacing.y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.title"), .style = "h4",
|
||||
.color = "--text-bright",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.author"), .color = "--text-muted",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
while (*story) {
|
||||
size_t n = strcspn(story, "\n");
|
||||
size_t len = n < sizeof para ? n : sizeof para - 1;
|
||||
|
||||
memcpy(para, story, len);
|
||||
para[len] = '\0';
|
||||
story += n + (story[n] == '\n');
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = para, .wrap = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.source"), .color = "--text-muted",
|
||||
.wrap = 1, .box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
page_translations_formats(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
#define DIAG_ROWS(ctx) \
|
||||
REAKTOR_COLUMN(.w = nk_widget_bounds(ctx).w, \
|
||||
.gap = (ctx)->style.window.spacing.y)
|
||||
@@ -2090,6 +2209,7 @@ reaktor_showcase_page(App *app, struct nk_context *ctx, int tab,
|
||||
case TAB_POPUPS: page_popups(app, ctx, s); break;
|
||||
case TAB_ANIM: page_animation(app, ctx, s); break;
|
||||
case TAB_STYLING: page_styling(app, ctx, s); break;
|
||||
case TAB_TRANSLATIONS: page_translations(app, ctx, s); break;
|
||||
case TAB_DIAG: page_diagnostics(app, ctx, s); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ enum {
|
||||
TAB_POPUPS,
|
||||
TAB_ANIM,
|
||||
TAB_STYLING,
|
||||
TAB_TRANSLATIONS,
|
||||
TAB_DIAG,
|
||||
TAB_COUNT
|
||||
};
|
||||
@@ -77,6 +78,9 @@ void sample_tablist_keys(char *out, int cap);
|
||||
int sample_tab(void);
|
||||
void set_tab(App *app, int tab);
|
||||
|
||||
int sample_option(App *app, struct nk_context *ctx, const char *label,
|
||||
float w, int on);
|
||||
|
||||
void reaktor_showcase_page(App *app, struct nk_context *ctx, int tab,
|
||||
float w, float h);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "style.h"
|
||||
#include "layout.h"
|
||||
#include "ui.h"
|
||||
#include "text.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
@@ -26,23 +27,12 @@
|
||||
#define WINDOW_HEIGHT 680
|
||||
#define FONT_SIZE 16
|
||||
|
||||
/* The ladder pick_font snaps to: a fifth of a step apart, from body text to
|
||||
* a page heading. It used to stop at 19, so a stylesheet asking for a heading
|
||||
* got 19px however large it asked and a document's whole type scale collapsed
|
||||
* into one size. Geometric rather than a list of sizes read off some
|
||||
* particular sheet, so no size is privileged and nothing goes stale.
|
||||
*
|
||||
* Every step is baked twice, regular and bold - a sheet that can set
|
||||
* font-size but not font-weight is only half reading the sheet. */
|
||||
#define FONT_STEPS 8
|
||||
|
||||
#define IMG_CACHE_MAX 48
|
||||
|
||||
#define TITLE_PX 16
|
||||
|
||||
/* One definition, in runtime/app.c. As statics in this header they were a
|
||||
* private copy per translation unit: app.c filled its own and the Diagnostics
|
||||
* page read widgets.c's, which was zero and always would be. */
|
||||
extern size_t reaktor_rss[RSS_STEPS];
|
||||
extern size_t reaktor_priv[RSS_STEPS];
|
||||
void reaktor_rss_mark(int step);
|
||||
@@ -91,6 +81,8 @@ struct App {
|
||||
char font_status[160];
|
||||
struct nk_font_atlas *atlas;
|
||||
int atlas_w, atlas_h, atlas_bpp;
|
||||
/* Nuklear reads these until the next bake. */
|
||||
unsigned *glyphs;
|
||||
|
||||
struct nk_text_edit edit;
|
||||
char edit_buf[128];
|
||||
@@ -116,11 +108,10 @@ struct App {
|
||||
int ctl_n;
|
||||
int want_quit;
|
||||
|
||||
/* --shot and --a11y-dump: a run that can be compared with the last one.
|
||||
* NULL unless the flag was given. */
|
||||
const char *shot_path;
|
||||
const char *dump_path;
|
||||
const char *renderer_pref;
|
||||
const char *lang_pref;
|
||||
|
||||
struct nk_rect field_rect;
|
||||
int field_rect_valid;
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "locale_internal.h"
|
||||
|
||||
#define CATALOG(code, text) \
|
||||
{ code, (const unsigned char *)(text), sizeof(text) - 1 }
|
||||
|
||||
/* On purpose: out of order, and pl malformed in each way the loader allows. */
|
||||
const struct reaktor_locale_catalog reaktor_locale_catalogs[] = {
|
||||
CATALOG("pl",
|
||||
"\xEF\xBB\xBF" "language = Polski\r\n"
|
||||
"plural = n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2\r\n"
|
||||
"hello = Cze\xC5\x9B\xC4\x87\r\n"
|
||||
"files = %d plik | %d pliki | %d plik\xC3\xB3w\r\n"
|
||||
"Use #tags = U\xC5\xBCyj #tag\xC3\xB3w\r\n"
|
||||
"Price = total = Cena = suma\r\n"
|
||||
"[Draft] Save = [Szkic] Zapisz \r\n"
|
||||
"story = Pierwszy\\nDrugi \\\\ trzeci\r\n"
|
||||
"hello = the second one loses\r\n"
|
||||
"a line with no separator\r\n"
|
||||
"number.decimal = ,\r\n"
|
||||
"number.group = \xC2\xA0\r\n"
|
||||
"number.group.min = 2\r\n"
|
||||
"money = {n}\xC2\xA0{s}\r\n"
|
||||
"money.PLN = z\xC5\x82\r\n"
|
||||
"money.JPY.digits = 0\r\n"
|
||||
"date.full = EEEE, d MMMM y\r\n"
|
||||
"time.short = HH:mm\r\n"
|
||||
"date.months = stycznia | lutego | marca | kwietnia | maja | czerwca | "
|
||||
"lipca | sierpnia | wrze\xC5\x9Bnia | pa\xC5\xBA" "dziernika | listopada | "
|
||||
"grudnia\r\n"
|
||||
"date.days = niedziela | poniedzia\xC5\x82" "ek | wtorek | \xC5\x9Broda | "
|
||||
"czwartek | pi\xC4\x85tek | sobota\r\n"
|
||||
"matches = {n}\xC2\xA0zapa\xC5\x82ka | {n}\xC2\xA0zapa\xC5\x82ki | "
|
||||
"{n}\xC2\xA0zapa\xC5\x82" "ek\r\n"),
|
||||
CATALOG("en",
|
||||
"language = English\n"
|
||||
"plural = n != 1\n"
|
||||
"hello = Hello\n"
|
||||
"files = %d file | %d files\n"),
|
||||
CATALOG("ja",
|
||||
"language = \xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E\n"
|
||||
"plural = 0\n"
|
||||
"hello = \xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF\n"
|
||||
"files = %d \xE5\x80\x8B\xE3\x81\xAE\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"
|
||||
"money.JPY = \xEF\xBF\xA5\n"
|
||||
"money.JPY.digits = 0\n"
|
||||
"date.short = ''yy\n"
|
||||
"date.long = y\xE5\xB9\xB4M\xE6\x9C\x88" "d\xE6\x97\xA5\n"
|
||||
"time.short = a h'\xE6\x99\x82'mm'\xE5\x88\x86'\n"
|
||||
"time.ampm = \xE5\x8D\x88\xE5\x89\x8D | \xE5\x8D\x88\xE5\xBE\x8C\n"),
|
||||
};
|
||||
const int reaktor_locale_catalog_count =
|
||||
(int)(sizeof reaktor_locale_catalogs / sizeof reaktor_locale_catalogs[0]);
|
||||
|
||||
static int failures;
|
||||
|
||||
static void
|
||||
check(const char *what, long got, long want)
|
||||
{
|
||||
if (got == want) return;
|
||||
printf("FAIL %s: got %ld, want %ld\n", what, got, want);
|
||||
failures++;
|
||||
}
|
||||
|
||||
static void
|
||||
check_str(const char *what, const char *got, const char *want)
|
||||
{
|
||||
if (got && want && !strcmp(got, want)) return;
|
||||
printf("FAIL %s: got \"%s\", want \"%s\"\n", what, got ? got : "(null)",
|
||||
want ? want : "(null)");
|
||||
failures++;
|
||||
}
|
||||
|
||||
static void
|
||||
plural(const char *expr, unsigned long n, long want)
|
||||
{
|
||||
char what[160];
|
||||
|
||||
snprintf(what, sizeof what, "plural \"%.100s\" for n=%lu", expr, n);
|
||||
check(what, reaktor_plural_eval(expr, n), want);
|
||||
}
|
||||
|
||||
static void
|
||||
plurals(void)
|
||||
{
|
||||
const char *pl = "n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2";
|
||||
const char *ru = "n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2";
|
||||
const char *ar = "n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5";
|
||||
char deep[4096];
|
||||
int i;
|
||||
|
||||
plural("n != 1", 0, 1);
|
||||
plural("n != 1", 1, 0);
|
||||
plural("n != 1", 2, 1);
|
||||
|
||||
plural(pl, 0, 2); plural(pl, 1, 0); plural(pl, 2, 1);
|
||||
plural(pl, 4, 1); plural(pl, 5, 2); plural(pl, 12, 2);
|
||||
plural(pl, 14, 2); plural(pl, 21, 2); plural(pl, 22, 1);
|
||||
plural(pl, 25, 2); plural(pl, 101, 2); plural(pl, 102, 1);
|
||||
plural(pl, 112, 2); plural(pl, 124, 1);
|
||||
|
||||
plural(ru, 1, 0); plural(ru, 11, 2); plural(ru, 21, 0);
|
||||
plural(ru, 2, 1); plural(ru, 5, 2); plural(ru, 111, 2);
|
||||
|
||||
plural(ar, 0, 0); plural(ar, 1, 1); plural(ar, 2, 2);
|
||||
plural(ar, 3, 3); plural(ar, 10, 3); plural(ar, 11, 4);
|
||||
plural(ar, 99, 4); plural(ar, 100, 5); plural(ar, 102, 5);
|
||||
|
||||
plural("0", 7, 0);
|
||||
plural("!n", 0, 1);
|
||||
plural("!n", 3, 0);
|
||||
plural("n+1-2*3/3%4 == n-1", 5, 1);
|
||||
plural("nplurals=2; plural=n != 1;", 1, 0);
|
||||
plural("nplurals=2; plural=n != 1;", 2, 1);
|
||||
plural("nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : 2);", 11, 2);
|
||||
|
||||
plural("", 1, -1);
|
||||
plural("n ==", 1, -1);
|
||||
plural("(n", 1, -1);
|
||||
plural("n / 0", 1, -1);
|
||||
plural("n % (1-1)", 1, -1);
|
||||
plural("banana", 1, -1);
|
||||
plural("n n", 1, -1);
|
||||
plural("1 ? 2", 1, -1);
|
||||
check("plural of NULL", reaktor_plural_eval(NULL, 1), -1);
|
||||
|
||||
for (i = 0; i < 2000; i++) deep[i] = '(';
|
||||
deep[i] = 'n';
|
||||
for (i = 0; i < 2000; i++) deep[2001 + i] = ')';
|
||||
deep[4001] = '\0';
|
||||
plural(deep, 1, -1);
|
||||
for (i = 0; i < 4000; i++) deep[i] = '!';
|
||||
deep[4000] = 'n';
|
||||
deep[4001] = '\0';
|
||||
plural(deep, 1, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
catalogs(void)
|
||||
{
|
||||
char buf[64];
|
||||
unsigned cps[64];
|
||||
int i, n, sorted = 1, dup = 0, has_s = 0, has_ko = 0, has_ni = 0,
|
||||
has_o = 0;
|
||||
|
||||
check_str("no current catalog answers with the key", reaktor_tr("hello"),
|
||||
"hello");
|
||||
check("catalogs loaded", reaktor_locale_init(), 3);
|
||||
check("count", reaktor_locale_count(), 3);
|
||||
check_str("sorted by code: 0", reaktor_locale_code(0), "en");
|
||||
check_str("sorted by code: 1", reaktor_locale_code(1), "ja");
|
||||
check_str("sorted by code: 2", reaktor_locale_code(2), "pl");
|
||||
check_str("name from `language`", reaktor_locale_name(2), "Polski");
|
||||
check_str("a name in its own script", reaktor_locale_name(1),
|
||||
"\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E");
|
||||
check("find pl", reaktor_locale_find("pl"), 2);
|
||||
check("find an unknown code", reaktor_locale_find("xx"), -1);
|
||||
check("an unknown code is refused", reaktor_locale_set("xx"), 0);
|
||||
check_str("and leaves no current catalog", reaktor_locale_current(), "");
|
||||
|
||||
check("set pl", reaktor_locale_set("pl"), 1);
|
||||
check_str("current", reaktor_locale_current(), "pl");
|
||||
check_str("byte-order mark and CRLF", reaktor_tr("language"), "Polski");
|
||||
check_str("the first of a repeated key", reaktor_tr("hello"),
|
||||
"Cze\xC5\x9B\xC4\x87");
|
||||
check_str("a key with a hash", reaktor_tr("Use #tags"),
|
||||
"U\xC5\xBCyj #tag\xC3\xB3w");
|
||||
check_str("split at the first \" = \"", reaktor_tr("Price"),
|
||||
"total = Cena = suma");
|
||||
check_str("a key with brackets, spaces trimmed",
|
||||
reaktor_tr("[Draft] Save"), "[Szkic] Zapisz");
|
||||
check_str("escapes", reaktor_tr("story"), "Pierwszy\nDrugi \\ trzeci");
|
||||
check_str("a missing key answers with itself", reaktor_tr("missing"),
|
||||
"missing");
|
||||
check_str("a non-entry line is not a key",
|
||||
reaktor_tr("a line with no separator"),
|
||||
"a line with no separator");
|
||||
|
||||
check_str("pl 1 plik", reaktor_trn("files", 1, buf, sizeof buf), "%d plik");
|
||||
check_str("pl 2 pliki", reaktor_trn("files", 2, buf, sizeof buf), "%d pliki");
|
||||
check_str("pl 5 plikow", reaktor_trn("files", 5, buf, sizeof buf),
|
||||
"%d plik\xC3\xB3w");
|
||||
check_str("pl 12 plikow", reaktor_trn("files", 12, buf, sizeof buf),
|
||||
"%d plik\xC3\xB3w");
|
||||
check_str("pl 22 pliki", reaktor_trn("files", 22, buf, sizeof buf),
|
||||
"%d pliki");
|
||||
check_str("pl 104 pliki", reaktor_trn("files", 104, buf, sizeof buf),
|
||||
"%d pliki");
|
||||
check_str("a form truncated to the buffer",
|
||||
reaktor_trn("files", 1, buf, 4), "%d ");
|
||||
check_str("plural of a missing key answers with it",
|
||||
reaktor_trn("nope", 3, buf, sizeof buf), "nope");
|
||||
|
||||
reaktor_locale_set("en");
|
||||
check_str("en 1 file", reaktor_trn("files", 1, buf, sizeof buf), "%d file");
|
||||
check_str("en 0 files", reaktor_trn("files", 0, buf, sizeof buf), "%d files");
|
||||
|
||||
reaktor_locale_set("ja");
|
||||
check_str("one form serves every n",
|
||||
reaktor_trn("files", 5, buf, sizeof buf),
|
||||
"%d \xE5\x80\x8B\xE3\x81\xAE\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB");
|
||||
|
||||
n = reaktor_locale_codepoints(NULL, 0);
|
||||
check("codepoints counted without a buffer",
|
||||
reaktor_locale_codepoints(cps, (int)(sizeof cps / sizeof cps[0])), n);
|
||||
for (i = 0; i < n && i < 64; i++) {
|
||||
if (i && cps[i] <= cps[i - 1]) { sorted = 0; dup += cps[i] == cps[i - 1]; }
|
||||
has_s |= cps[i] == 0x015B;
|
||||
has_ko |= cps[i] == 0x3053;
|
||||
has_ni |= cps[i] == 0x65E5;
|
||||
has_o |= cps[i] == 0x00F3;
|
||||
}
|
||||
check("codepoints ascending", sorted, 1);
|
||||
check("codepoints unique", dup, 0);
|
||||
check("codepoints include s-acute", has_s, 1);
|
||||
check("codepoints include hiragana ko", has_ko, 1);
|
||||
check("codepoints include the kanji in the language name", has_ni, 1);
|
||||
check("codepoints leave out Latin-1", has_o, 0);
|
||||
|
||||
check("init again reloads cleanly", reaktor_locale_init(), 3);
|
||||
check_str("and forgets the current catalog", reaktor_locale_current(), "");
|
||||
}
|
||||
|
||||
static void
|
||||
formats(void)
|
||||
{
|
||||
struct tm eve, dawn;
|
||||
char buf[96];
|
||||
|
||||
memset(&eve, 0, sizeof eve);
|
||||
eve.tm_year = 1845 - 1900; eve.tm_mon = 11; eve.tm_mday = 31;
|
||||
eve.tm_hour = 21; eve.tm_min = 30;
|
||||
dawn = eve;
|
||||
dawn.tm_hour = 0; dawn.tm_min = 5;
|
||||
|
||||
reaktor_locale_init();
|
||||
|
||||
reaktor_locale_set("en");
|
||||
check_str("en number", reaktor_format_number(buf, sizeof buf, 1234567.891, 2),
|
||||
"1,234,567.89");
|
||||
check_str("en number below grouping",
|
||||
reaktor_format_number(buf, sizeof buf, 999, 0), "999");
|
||||
check_str("en number grouped at four digits",
|
||||
reaktor_format_number(buf, sizeof buf, 1000, 0), "1,000");
|
||||
check_str("a half rounds to even, as printf and CLDR both round it",
|
||||
reaktor_format_number(buf, sizeof buf, 2.5, 0), "2");
|
||||
check_str("no sign on a negative that rounds to zero",
|
||||
reaktor_format_number(buf, sizeof buf, -0.004, 2), "0.00");
|
||||
check_str("en negative", reaktor_format_number(buf, sizeof buf, -1234.5, 1),
|
||||
"-1,234.5");
|
||||
check_str("a symbol that is a code keeps off the amount",
|
||||
reaktor_format_money(buf, sizeof buf, 1234.5, "PLN"),
|
||||
"PLN\xC2\xA0" "1,234.50");
|
||||
check_str("en negative money",
|
||||
reaktor_format_money(buf, sizeof buf, -3, "USD"),
|
||||
"-USD\xC2\xA0" "3.00");
|
||||
check_str("en short date",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_SHORT),
|
||||
"12/31/45");
|
||||
check_str("en long date",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_LONG),
|
||||
"December 31, 1845");
|
||||
check_str("en full date, with the weekday worked out",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_FULL),
|
||||
"Wednesday, December 31, 1845");
|
||||
check_str("en time", reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_TIME_SHORT),
|
||||
"9:30 PM");
|
||||
check_str("en time past midnight",
|
||||
reaktor_format_date(buf, sizeof buf, &dawn, REAKTOR_TIME_SHORT),
|
||||
"12:05 AM");
|
||||
|
||||
reaktor_locale_set("pl");
|
||||
check_str("pl number", reaktor_format_number(buf, sizeof buf, 1234567.891, 2),
|
||||
"1\xC2\xA0" "234\xC2\xA0" "567,89");
|
||||
check_str("pl leaves four digits ungrouped",
|
||||
reaktor_format_number(buf, sizeof buf, 1234, 0), "1234");
|
||||
check_str("pl groups five", reaktor_format_number(buf, sizeof buf, 12345, 0),
|
||||
"12\xC2\xA0" "345");
|
||||
check_str("pl money", reaktor_format_money(buf, sizeof buf, 1234.5, "PLN"),
|
||||
"1234,50\xC2\xA0z\xC5\x82");
|
||||
check_str("pl negative money",
|
||||
reaktor_format_money(buf, sizeof buf, -1234.5, "PLN"),
|
||||
"-1234,50\xC2\xA0z\xC5\x82");
|
||||
check_str("a currency with no decimals",
|
||||
reaktor_format_money(buf, sizeof buf, 123456, "JPY"),
|
||||
"123\xC2\xA0" "456\xC2\xA0JPY");
|
||||
check_str("pl full date",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_FULL),
|
||||
"\xC5\x9Broda, 31 grudnia 1845");
|
||||
check_str("pl time", reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_TIME_SHORT),
|
||||
"21:30");
|
||||
check_str("{n} in a plural form, formatted",
|
||||
reaktor_trn("matches", 12345, buf, sizeof buf),
|
||||
"12\xC2\xA0" "345\xC2\xA0zapa\xC5\x82" "ek");
|
||||
check_str("{n} with the few form",
|
||||
reaktor_trn("matches", 22, buf, sizeof buf),
|
||||
"22\xC2\xA0zapa\xC5\x82ki");
|
||||
check_str("a form cut between characters, not through one",
|
||||
reaktor_trn("matches", 1, buf, 9), "1\xC2\xA0zapa");
|
||||
|
||||
reaktor_locale_set("ja");
|
||||
check_str("ja money", reaktor_format_money(buf, sizeof buf, 123456, "JPY"),
|
||||
"\xEF\xBF\xA5" "123,456");
|
||||
check_str("ja long date",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_LONG),
|
||||
"1845\xE5\xB9\xB4" "12\xE6\x9C\x88" "31\xE6\x97\xA5");
|
||||
check_str("ja time, with quotes and the day half",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_TIME_SHORT),
|
||||
"\xE5\x8D\x88\xE5\xBE\x8C 9\xE6\x99\x82" "30\xE5\x88\x86");
|
||||
check_str("a doubled quote is one quote",
|
||||
reaktor_format_date(buf, sizeof buf, &eve, REAKTOR_DATE_SHORT),
|
||||
"'45");
|
||||
check_str("a date cut between characters",
|
||||
reaktor_format_date(buf, 7, &eve, REAKTOR_DATE_LONG), "1845");
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
plurals();
|
||||
catalogs();
|
||||
formats();
|
||||
|
||||
if (failures) {
|
||||
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
|
||||
return 1;
|
||||
}
|
||||
printf("locale: all checks passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
#!/bin/sh
|
||||
# make-bundle.sh - assemble build/reaktor.app around the plain binary.
|
||||
#
|
||||
# make-bundle.sh BUNDLE BINARY INFOPLIST SOURCE_ROOT
|
||||
#
|
||||
# A CMake POST_BUILD step on macOS. The CLI binary and the Finder bundle both
|
||||
set -eu
|
||||
|
||||
bundle=$1
|
||||
@@ -56,7 +51,7 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
# The same set CMake scans for the WASM preload; keep the two in step.
|
||||
# Same set as the WASM scan in CMakeLists.txt.
|
||||
srcs=$(ls "$root/src/"*.h "$root/core/"*/*.c "$root/core/"*/*.h \
|
||||
"$root/platform/"*.c "$root/platform/"*/*.c \
|
||||
"$root/runtime/"*.c "$root/samples/"*.h \
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<!doctype html>
|
||||
<!-- emcc --shell-file: the page the wasm build is wrapped in. -->
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "nk_common.h"
|
||||
#include "reaktor.h"
|
||||
#include "text.h"
|
||||
|
||||
#define FONT_FILE "assets/fonts/Aileron-Regular.otf"
|
||||
#define JAPANESE_FILE "assets/fonts/MPLUS1p-Regular.ttf"
|
||||
|
||||
#define RLO "\xE2\x80\xAE"
|
||||
#define LRO "\xE2\x80\xAD"
|
||||
#define PDF "\xE2\x80\xAC"
|
||||
#define SHALOM "\xD7\xA9\xD7\x9C\xD7\x95\xD7\x9D"
|
||||
#define HI "\xE6\x97\xA5"
|
||||
#define HON "\xE6\x9C\xAC"
|
||||
#define NIHON HI HON
|
||||
|
||||
struct vertex {
|
||||
float x, y, u, v;
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static int failures;
|
||||
|
||||
static void
|
||||
check(const char *what, long got, long want)
|
||||
{
|
||||
if (got == want) return;
|
||||
printf("FAIL %s: got %ld, want %ld\n", what, got, want);
|
||||
failures++;
|
||||
}
|
||||
|
||||
static void
|
||||
check_near(const char *what, float got, float want)
|
||||
{
|
||||
if (SDL_fabs(got - want) < 0.01) return;
|
||||
printf("FAIL %s: got %.3f, want %.3f\n", what, got, want);
|
||||
failures++;
|
||||
}
|
||||
|
||||
static void
|
||||
breaks(void)
|
||||
{
|
||||
check("after the space", reaktor_text_break("Hello world", 11, 7), 6);
|
||||
check("not inside a number", reaktor_text_break("a 1,234", 7, 5), 2);
|
||||
check("between kanji and kana", reaktor_text_break(NIHON "\xE3\x81\xA7\xE3\x81\x99", 12, 6), 6);
|
||||
check("not before a full stop",
|
||||
reaktor_text_break("\xE3\x81\xA7\xE3\x81\x99\xE3\x80\x82", 9, 6), 3);
|
||||
}
|
||||
|
||||
static void
|
||||
directions(void)
|
||||
{
|
||||
check("Latin", reaktor_text_rtl("abc", 3), 0);
|
||||
check("Hebrew first", reaktor_text_rtl(SHALOM " abc", 12), 1);
|
||||
check("Latin first", reaktor_text_rtl("abc " SHALOM, 12), 0);
|
||||
check("digits are not strong", reaktor_text_rtl("123 " SHALOM, 12), 1);
|
||||
check("Japanese", reaktor_text_rtl(NIHON, 6), 0);
|
||||
}
|
||||
|
||||
static float
|
||||
width(const struct nk_font *font, const char *s)
|
||||
{
|
||||
return font->handle.width(font->handle.userdata, font->handle.height, s,
|
||||
(int)strlen(s));
|
||||
}
|
||||
|
||||
static int
|
||||
frame(struct nk_context *ctx, SDL_Renderer *ren, const char *text,
|
||||
struct nk_buffer *verts)
|
||||
{
|
||||
static const struct nk_draw_vertex_layout_element layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct vertex, x)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct vertex, u)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
const struct nk_draw_command *cmd;
|
||||
struct nk_convert_config cfg;
|
||||
struct nk_buffer cmds, idx;
|
||||
int quads = 0;
|
||||
|
||||
if (nk_begin(ctx, "text", nk_rect(0, 0, 400, 60), NK_WINDOW_NO_SCROLLBAR)) {
|
||||
nk_layout_row_dynamic(ctx, 20, 1);
|
||||
nk_label(ctx, text, NK_TEXT_LEFT);
|
||||
}
|
||||
nk_end(ctx);
|
||||
|
||||
memset(&cfg, 0, sizeof cfg);
|
||||
cfg.vertex_layout = layout;
|
||||
cfg.vertex_size = sizeof(struct vertex);
|
||||
cfg.vertex_alignment = NK_ALIGNOF(struct vertex);
|
||||
cfg.circle_segment_count = cfg.curve_segment_count = cfg.arc_segment_count = 22;
|
||||
cfg.global_alpha = 1.0f;
|
||||
nk_buffer_init_default(&cmds);
|
||||
nk_buffer_init_default(&idx);
|
||||
nk_buffer_init_default(verts);
|
||||
reaktor_text_prepare(ctx, ren);
|
||||
nk_convert(ctx, &cmds, verts, &idx, &cfg);
|
||||
nk_draw_foreach(cmd, ctx, &cmds)
|
||||
if (cmd->texture.ptr) quads += (int)cmd->elem_count / 6;
|
||||
nk_buffer_free(&cmds);
|
||||
nk_buffer_free(&idx);
|
||||
nk_clear(ctx);
|
||||
return quads;
|
||||
}
|
||||
|
||||
static int
|
||||
same_vertices(struct nk_buffer *a, struct nk_buffer *b)
|
||||
{
|
||||
return a->needed == b->needed &&
|
||||
!memcmp(nk_buffer_memory_const(a), nk_buffer_memory_const(b), a->needed);
|
||||
}
|
||||
|
||||
static void
|
||||
drawing(void)
|
||||
{
|
||||
struct nk_font_atlas atlas;
|
||||
struct nk_font_config cfg = nk_font_config(16.0f);
|
||||
struct nk_context ctx;
|
||||
struct nk_buffer rtl, ltr, wrong;
|
||||
struct nk_font *font;
|
||||
nk_text_width_f atlas_width;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *ren;
|
||||
char path[1024], japanese[1024], line[200];
|
||||
int w, h;
|
||||
|
||||
if (!reaktor_path(path, sizeof path, FONT_FILE) ||
|
||||
!reaktor_path(japanese, sizeof japanese, JAPANESE_FILE)) {
|
||||
printf("FAIL no %s or %s\n", FONT_FILE, JAPANESE_FILE);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
reaktor_text_add_fallback(japanese);
|
||||
surface = SDL_CreateSurface(64, 64, SDL_PIXELFORMAT_ARGB8888);
|
||||
ren = surface ? SDL_CreateSoftwareRenderer(surface) : NULL;
|
||||
if (!ren) {
|
||||
printf("FAIL no software renderer: %s\n", SDL_GetError());
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
|
||||
cfg.oversample_h = cfg.oversample_v = 1;
|
||||
cfg.pixel_snap = 1;
|
||||
nk_font_atlas_init_default(&atlas);
|
||||
nk_font_atlas_begin(&atlas);
|
||||
font = nk_font_atlas_add_from_file(&atlas, path, 16.0f, &cfg);
|
||||
if (!font || !nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_ALPHA8)) {
|
||||
printf("FAIL could not bake %s\n", path);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
nk_font_atlas_end(&atlas, nk_handle_id(0), NULL);
|
||||
nk_init_default(&ctx, &font->handle);
|
||||
|
||||
atlas_width = font->handle.width;
|
||||
reaktor_text_attach_font(font, path);
|
||||
|
||||
check_near("Latin measures as before", width(font, "Ab"),
|
||||
atlas_width(font->handle.userdata, 16.0f, "Ab", 2));
|
||||
check("Japanese has width", width(font, NIHON) > 10.0f, 1);
|
||||
check_near("Japanese adds up", width(font, NIHON),
|
||||
width(font, HI) + width(font, HON));
|
||||
check_near("direction does not change width", width(font, RLO "ab" PDF),
|
||||
width(font, LRO "ba" PDF));
|
||||
|
||||
check("two Japanese glyphs drawn", frame(&ctx, ren, NIHON, &rtl), 2);
|
||||
nk_buffer_free(&rtl);
|
||||
|
||||
check("forced right to left drawn", frame(&ctx, ren, RLO "ab" HI PDF, &rtl), 3);
|
||||
frame(&ctx, ren, LRO HI "ba" PDF, <r);
|
||||
frame(&ctx, ren, LRO "ab" HI PDF, &wrong);
|
||||
check("right to left is reversed", same_vertices(&rtl, <r), 1);
|
||||
check("and order shows", same_vertices(&rtl, &wrong), 0);
|
||||
nk_buffer_free(&rtl);
|
||||
nk_buffer_free(<r);
|
||||
nk_buffer_free(&wrong);
|
||||
|
||||
reaktor_text_describe(line, sizeof line);
|
||||
check("the fallback counted", strcmp(line, "M PLUS 1p for 2 glyphs"), 0);
|
||||
if (strcmp(line, "M PLUS 1p for 2 glyphs")) printf(" described: \"%s\"\n", line);
|
||||
|
||||
reaktor_text_attach_font(NULL, NULL);
|
||||
nk_free(&ctx);
|
||||
nk_font_atlas_clear(&atlas);
|
||||
SDL_DestroyRenderer(ren);
|
||||
SDL_DestroySurface(surface);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
breaks();
|
||||
directions();
|
||||
drawing();
|
||||
|
||||
if (failures) {
|
||||
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
|
||||
return 1;
|
||||
}
|
||||
printf("text: all checks passed\n");
|
||||
return 0;
|
||||
}
|
||||