Compare commits
2 commits
35ce1d8e19
...
e787b94ae1
Author | SHA1 | Date | |
---|---|---|---|
e787b94ae1 | |||
9fad3c41b2 |
3 changed files with 83 additions and 5 deletions
|
@ -16,6 +16,8 @@ namespace Tablegen
|
||||||
void GeneratePage(const std::string& path, const Settings& settings = Settings::Default());
|
void GeneratePage(const std::string& path, const Settings& settings = Settings::Default());
|
||||||
|
|
||||||
# ifdef TABLEGEN_EXPOSE_XML
|
# ifdef TABLEGEN_EXPOSE_XML
|
||||||
|
void GenerateAsChild(pugi::xml_node& node, const Settings& settings = Settings::Default());
|
||||||
|
|
||||||
pugi::xml_document GenerateDocument(const Settings& settings = Settings::Default());
|
pugi::xml_document GenerateDocument(const Settings& settings = Settings::Default());
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,15 +115,14 @@ namespace Tablegen
|
||||||
doc.save_file("test.html", " ", formatOptions);
|
doc.save_file("test.html", " ", formatOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
pugi::xml_document GenerateDocument(const Settings& settings)
|
void GenerateAsChild(pugi::xml_node& node, const Settings& settings)
|
||||||
{
|
{
|
||||||
pugi::xml_document doc;
|
pugi::xml_node tableRoot = node;
|
||||||
pugi::xml_node tableRoot = doc;
|
|
||||||
|
|
||||||
if (settings.FullDocument == Flag::Enable) {
|
if (settings.FullDocument == Flag::Enable) {
|
||||||
doc.append_child(pugi::node_doctype).set_value("html");
|
node.append_child(pugi::node_doctype).set_value("html");
|
||||||
|
|
||||||
pugi::xml_node html = doc.append_child("html");
|
pugi::xml_node html = node.append_child("html");
|
||||||
|
|
||||||
pugi::xml_node head = html.append_child("head");\
|
pugi::xml_node head = html.append_child("head");\
|
||||||
head.append_child("title").append_child(pugi::node_pcdata).set_value("Kanji Table");
|
head.append_child("title").append_child(pugi::node_pcdata).set_value("Kanji Table");
|
||||||
|
@ -200,7 +199,12 @@ namespace Tablegen
|
||||||
styles.append_child(pugi::node_pcdata).set_value(Styles(settings, indent, tagIndent,
|
styles.append_child(pugi::node_pcdata).set_value(Styles(settings, indent, tagIndent,
|
||||||
staticImg, animatedImg));
|
staticImg, animatedImg));
|
||||||
script.append_child(pugi::node_pcdata).set_value(Script(indent, tagIndent, buttons));
|
script.append_child(pugi::node_pcdata).set_value(Script(indent, tagIndent, buttons));
|
||||||
|
}
|
||||||
|
|
||||||
|
pugi::xml_document GenerateDocument(const Settings& settings)
|
||||||
|
{
|
||||||
|
pugi::xml_document doc;
|
||||||
|
GenerateAsChild(doc);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
72
README.md
72
README.md
|
@ -60,3 +60,75 @@ AnimateFile("084b8.svg", "084b8-out.svg", AnimationSettings {
|
||||||
.DelayBetweenStrokes = 50ms,
|
.DelayBetweenStrokes = 50ms,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Megane
|
||||||
|
|
||||||
|
A tiny library that loads the `kvg-index.json` into a dictionary to translate the UTF-8
|
||||||
|
representation of kanji characters into the ID that kanjivg uses to refer to the characters.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
```cpp
|
||||||
|
auto lookup = Megane::Megane("/path/to/kvg-index.json");
|
||||||
|
auto id = lookup.GetCode("日"); // id should contain "065e5.svg"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tablegen
|
||||||
|
|
||||||
|
This library generates a table of kanji images from a specified list with various configurable
|
||||||
|
values. It's made up of the following interface:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::string GeneratePage(const Settings& settings = Settings::Default());
|
||||||
|
|
||||||
|
void GeneratePage(const std::string& path, const Settings& settings = Settings::Default());
|
||||||
|
|
||||||
|
#ifdef TABLEGEN_EXPOSE_XML
|
||||||
|
void GenerateAsChild(pugi::xml_node& node, const Settings& settings = Settings::Default());
|
||||||
|
|
||||||
|
pugi::xml_document GenerateDocument(const Settings& settings = Settings::Default());
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
The first function returns a serialized HTML document in a string
|
||||||
|
(can return just the table by changing the `FullDocument` value in the settings).
|
||||||
|
The second function dumps the same document inside a file at the specified path.
|
||||||
|
The final two functions are hidden behing the `TABLEGEN_EXPOSE_XML` preprocessor flag, because they
|
||||||
|
expose the library that Tablegen uses internally to generate the document. They let the user
|
||||||
|
modify the XML tree before it gets serialized into the final document. The first of these functions
|
||||||
|
takes in a reference to the node that will act as the parent of the generated table.
|
||||||
|
The second function returns a whole XML document.
|
||||||
|
|
||||||
|
Some caveats:
|
||||||
|
- `GenerateDocument` returns a `pugi::xml_document`, which cannot be assigned as a child
|
||||||
|
of anothe node. You don't want to use this function if you plan to generate a full document
|
||||||
|
with the table as a child (the `FullDocument` option isn't applicable in all cases either).
|
||||||
|
- The default serialisation options do not generate a valid document, some specific options
|
||||||
|
need to be set for the document to be valid (currently `pugi::format_no_escapes`,
|
||||||
|
and `pugi::format_no_declaration`, but this is an implementation detail of the pugixml library).
|
||||||
|
|
||||||
|
The default settings generate a table with no characters (and horrible styling), you will need to
|
||||||
|
specify custom settings like this for actual use:
|
||||||
|
```cpp
|
||||||
|
auto doc = GeneratePage({
|
||||||
|
.FullDocument = Flag::Enable,
|
||||||
|
.OverrideIndentLevel = Flag::Disable,
|
||||||
|
.IndentLevel = 0,
|
||||||
|
.TableWidth = 90,
|
||||||
|
.TableMargin = 5,
|
||||||
|
.TableItemWidth = 30,
|
||||||
|
.TableItemPadding = 2,
|
||||||
|
.TableItemColour = RGB::FromHex("#666666"),
|
||||||
|
.LabelFontSize = 1.75,
|
||||||
|
.LabelFontUnits = FontSizeUnits::Em,
|
||||||
|
.ButtonColour = RGB::FromHex("#FF6347"),
|
||||||
|
.ButtonHoverColour = RGB::FromHex("#FFA500"),
|
||||||
|
.ButtonAnimationLength = 0.5,
|
||||||
|
.CharactersPerRow = 3,
|
||||||
|
.ImageFormat = "http://the.url/where/you/have/images/{}.svg",
|
||||||
|
.AnimationFormat = "http://the.url/where/you/have/animations/{}.svg",
|
||||||
|
.Characters = {
|
||||||
|
/* The actual characters you want in the table, example: */
|
||||||
|
{ .Label = "Day", .ImagePath = "%E6%97%A5", .AnimationPath = "%E6%97%A5", },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue