handwritten and stroke order

This commit is contained in:
Xieamoe 2024-02-14 22:01:00 -08:00
parent 7961c775d2
commit 9b66d3caf8
No known key found for this signature in database
GPG key ID: 5B82D290CCD94C6D
4 changed files with 45 additions and 1 deletions

View file

@ -9,6 +9,7 @@ project(
HOMEPAGE_URL "https://github.com/Ajatt-Tools/gd-tools" HOMEPAGE_URL "https://github.com/Ajatt-Tools/gd-tools"
LANGUAGES CXX LANGUAGES CXX
) )
option(GUIX "Build for Guix" OFF) # OFF by default
include(cmake/project-is-top-level.cmake) include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake) include(cmake/variables.cmake)

View file

@ -41,7 +41,7 @@ EXAMPLES
struct stroke_order_params struct stroke_order_params
{ {
std::string_view gd_word{}; std::string_view gd_word{};
std::string_view font_size{ "10rem" }; std::string_view font_size{ "5rem" };
std::string_view font_family{ "KanjiStrokeOrders" }; std::string_view font_family{ "KanjiStrokeOrders" };
std::size_t max_len{ default_len }; std::size_t max_len{ default_len };
@ -90,3 +90,36 @@ void stroke_order(std::span<std::string_view const> const args)
ajt::print("{}\n", ex.what()); ajt::print("{}\n", ex.what());
} }
} }
//Later just use stroke_order to print it
void print_css_hw(stroke_order_params const& params)
{
static constexpr std::string_view css = R"EOF(
<style>
.gd_echo_{} {{
font-size: {};
font-family: "ArmedLemon";
}}
</style>
)EOF";
ajt::print(css, this_pid, params.font_size);
}
void print_with_hw(stroke_order_params const& params)
{
if (params.gd_word.length() <= params.max_len) {
ajt::print("<div class=\"gd_echo_{}\">{}</div>\n", this_pid, params.gd_word);
print_css_hw(params);
}
}
void handwritten(std::span<std::string_view const> const args)
{
try {
print_with_hw(fill_args<stroke_order_params>(args));
} catch (gd::help_requested const& ex) {
ajt::print(help_text);
} catch (gd::runtime_error const& ex) {
ajt::print("{}\n", ex.what());
}
}

View file

@ -3,3 +3,5 @@
#include "precompiled.h" #include "precompiled.h"
void stroke_order(std::span<std::string_view const> const args); void stroke_order(std::span<std::string_view const> const args);
void handwritten(std::span<std::string_view const> const args);

View file

@ -82,6 +82,10 @@ auto take_action(std::span<std::string_view const> const args) -> void
return search_anki_cards(rest); return search_anki_cards(rest);
case "gd-echo"_h: case "gd-echo"_h:
return stroke_order(rest); return stroke_order(rest);
case "gd-strokeorder"_h:
return stroke_order(rest);
case "gd-handwritten"_h:
return handwritten(rest);
case "gd-massif"_h: case "gd-massif"_h:
return massif(rest); return massif(rest);
case "gd-images"_h: case "gd-images"_h:
@ -102,6 +106,10 @@ auto take_action(std::span<std::string_view const> const args) -> void
return search_anki_cards(rest); return search_anki_cards(rest);
case "echo"_h: case "echo"_h:
return stroke_order(rest); return stroke_order(rest);
case "strokeorder"_h:
return stroke_order(rest);
case "handwritten"_h:
return handwritten(rest);
case "massif"_h: case "massif"_h:
return massif(rest); return massif(rest);
case "images"_h: case "images"_h: