|
|
|
@ -18,6 +18,22 @@
@@ -18,6 +18,22 @@
|
|
|
|
|
#include <thread> |
|
|
|
|
#include <queue> |
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
/*
|
|
|
|
|
* https://gitlab.gnome.org/GNOME/lasem/-/tree/master/
|
|
|
|
|
Requirements: |
|
|
|
|
|
|
|
|
|
gobject, glib, gio, gdk-pixbuf, gdk, cairo, pangocairo, libxml, bison, flex |
|
|
|
|
|
|
|
|
|
For the runtime, the following ttf fonts should be installed: cmr10, cmmi10, cmex10 and cmsy10. |
|
|
|
|
They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in debian/ubuntu. |
|
|
|
|
*/ |
|
|
|
|
#include <lsm.h> |
|
|
|
|
#include <lsmmathml.h> |
|
|
|
|
#include <lsmsvg.h> |
|
|
|
|
#include <cairo-svg.h> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#include <json.hpp> |
|
|
|
|
#include <date.h> |
|
|
|
|
#include <spdlog/spdlog.h> |
|
|
|
@ -35,11 +51,15 @@
@@ -35,11 +51,15 @@
|
|
|
|
|
|
|
|
|
|
#include "srchighlight.hpp" |
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
#include "itex2MML.h" |
|
|
|
|
|
|
|
|
|
namespace lex { |
|
|
|
|
extern "C" { |
|
|
|
|
//#include <lexbor/dom/dom.h>
|
|
|
|
|
#include "lexbor_base.h" |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct Dom { |
|
|
|
|
|
|
|
|
|
lxb_html_document_t *document;
|
|
|
|
@ -75,12 +95,145 @@ struct Dom {
@@ -75,12 +95,145 @@ struct Dom {
|
|
|
|
|
lxb_dom_collection_destroy(collection, true); |
|
|
|
|
lxb_html_document_destroy(document); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
namespace imtex { |
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
static bool |
|
|
|
|
_hide_before_object (LsmDomDocument *document, const char *id) |
|
|
|
|
{ |
|
|
|
|
LsmDomNode *node; |
|
|
|
|
LsmDomNode *sibling; |
|
|
|
|
LsmDomNode *parent; |
|
|
|
|
|
|
|
|
|
if (!LSM_IS_SVG_DOCUMENT (document)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
node = LSM_DOM_NODE (lsm_svg_document_get_element_by_id (LSM_SVG_DOCUMENT (document), id)); |
|
|
|
|
if (!LSM_IS_DOM_NODE (node)) { |
|
|
|
|
//fprintf (stderr, _("Element '%s' not found"), id);
|
|
|
|
|
//fprintf (stderr, "\n");
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (parent = lsm_dom_node_get_parent_node (node); |
|
|
|
|
LSM_IS_DOM_NODE (parent); |
|
|
|
|
node = parent, parent = lsm_dom_node_get_parent_node (parent)) { |
|
|
|
|
for (sibling = lsm_dom_node_get_first_child (parent); |
|
|
|
|
LSM_IS_DOM_NODE (sibling); |
|
|
|
|
sibling = lsm_dom_node_get_next_sibling (sibling)) { |
|
|
|
|
if (sibling != node && LSM_IS_SVG_ELEMENT (sibling)) |
|
|
|
|
lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (sibling), "display", "none"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Imtex { |
|
|
|
|
|
|
|
|
|
double option_ppi = 72.0; |
|
|
|
|
double option_zoom = 1.0; |
|
|
|
|
double width_pt = 2.0; |
|
|
|
|
double height_pt = 2.0; |
|
|
|
|
|
|
|
|
|
Imtex () { |
|
|
|
|
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2,36,0) |
|
|
|
|
g_type_init (); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* |
|
|
|
|
* cairo_status_t cairo_surface_write_to_png_stream (cairo_surface_t *surface, |
|
|
|
|
cairo_write_func_t write_func, |
|
|
|
|
void *closure); |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
static cairo_status_t cairo_stream_to_buffer_func (void *closure, |
|
|
|
|
const unsigned char *data, unsigned int datalen)
|
|
|
|
|
{ |
|
|
|
|
std::vector<char> *cairobuffer = (std::vector<char> *)closure; |
|
|
|
|
|
|
|
|
|
for (int i = 0 ; i < datalen ; i ++) { |
|
|
|
|
cairobuffer->push_back(data[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (cairo_status_t)0; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
std::string get_svg_from_itex(const std::string& itex) { |
|
|
|
|
auto doc =
|
|
|
|
|
LSM_DOM_DOCUMENT(lsm_mathml_document_new_from_itex (itex.c_str(), itex.size(), NULL)); |
|
|
|
|
|
|
|
|
|
if (doc == NULL) { |
|
|
|
|
spdlog::error("Failed to parse itex"); |
|
|
|
|
return itex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* if (!_hide_before_object (doc, option_element_id)) {
|
|
|
|
|
g_object_unref (doc); |
|
|
|
|
spdlog::error("Invalid document?"); |
|
|
|
|
return itex; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (doc == NULL) { |
|
|
|
|
spdlog::error("Failed to parse itex"); |
|
|
|
|
return itex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto view = lsm_dom_document_create_view (doc); |
|
|
|
|
lsm_dom_view_set_resolution (view, option_ppi); |
|
|
|
|
lsm_dom_view_get_size (view, &width_pt, &height_pt, NULL); |
|
|
|
|
// lsm_dom_view_get_size_pixels (view, &width, &height, NULL);
|
|
|
|
|
double offset_x_pt = 0.0; |
|
|
|
|
double offset_y_pt = 0.0; |
|
|
|
|
|
|
|
|
|
//auto surface = cairo_svg_surface_create (output_filename,
|
|
|
|
|
// width_pt, height_pt);
|
|
|
|
|
|
|
|
|
|
auto surface = cairo_svg_surface_create_for_stream(cairo_stream_to_buffer_func, NULL, width_pt, height_pt); |
|
|
|
|
|
|
|
|
|
cairo_t * cairo = cairo_create(surface); |
|
|
|
|
//cairo_surface_destory(surface);
|
|
|
|
|
|
|
|
|
|
//cairo_scale (cairo, option_zoom, option_zoom);
|
|
|
|
|
|
|
|
|
|
lsm_dom_view_render(view, cairo, -offset_x_pt, -offset_y_pt); |
|
|
|
|
|
|
|
|
|
cairo_destroy (cairo); |
|
|
|
|
|
|
|
|
|
g_object_unref (view); |
|
|
|
|
|
|
|
|
|
g_object_unref (doc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const std::string SITE_CONFIG_FNAME = "stgen.json"; |
|
|
|
|
const std::string DEFAULT_PUBLISH_ROOT = "public"; |
|
|
|
|
const std::string DEFAULT_SOURCE_DIR = "."; |
|
|
|
@ -917,9 +1070,6 @@ class builder {
@@ -917,9 +1070,6 @@ class builder {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
build()
|
|
|
|
|
{ |
|
|
|
|