Merge pull request 'fix handwritten and strokeorder' (#2) from xieamoe/gd-tools-plus:main into main

Reviewed-on: https://codeberg.org/hashirama/gd-tools/pulls/2
This commit is contained in:
千住柱間 2024-02-15 17:21:21 +00:00
commit 787dcd91ee
5 changed files with 50 additions and 6 deletions

View file

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

View file

@ -136,8 +136,8 @@
(method git-fetch)
(uri (git-reference
(url "https://codeberg.org/xieamoe/gd-tools-plus.git")
(commit "71da66e0f1")))
(sha256 (base32 "0nys30qy5930004j7xnipxbn9d9k4xgbv7lzcdkrm9mapjzryh95"))))
(commit "9b66d3caf8")))
(sha256 (base32 "135flpfkp2sjgah92546vpznxz712c5prvbdj93637y9pyrw9rci"))))
(build-system cmake-build-system)
(arguments
@ -177,6 +177,6 @@
(home-page "https://codeberg.org/hashirama/gd-tools/")
(license
(list license:gpl3+
license:zlib))))
gd-tools
license:zlib))))
gd-tools

View file

@ -41,7 +41,7 @@ EXAMPLES
struct stroke_order_params
{
std::string_view gd_word{};
std::string_view font_size{ "10rem" };
std::string_view font_size{ "5rem" };
std::string_view font_family{ "KanjiStrokeOrders" };
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());
}
}
//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"
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);
case "gd-echo"_h:
return stroke_order(rest);
case "gd-strokeorder"_h:
return stroke_order(rest);
case "gd-handwritten"_h:
return handwritten(rest);
case "gd-massif"_h:
return massif(rest);
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);
case "echo"_h:
return stroke_order(rest);
case "strokeorder"_h:
return stroke_order(rest);
case "handwritten"_h:
return handwritten(rest);
case "massif"_h:
return massif(rest);
case "images"_h: