Browse Source

compile w lasem

master
alistair 3 years ago
parent
commit
d7bdc1b79a
  1. 15
      CMakeLists.txt
  2. 160
      main.cpp

15
CMakeLists.txt

@ -15,6 +15,11 @@ cmake_minimum_required(VERSION 3.17) @@ -15,6 +15,11 @@ cmake_minimum_required(VERSION 3.17)
include(FetchContent)
############## ONLY REQUIRED FOR lasem ##########################
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
###################################################################
FetchContent_Declare(spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog"
GIT_TAG "v1.8.2"
@ -49,7 +54,11 @@ endif() @@ -49,7 +54,11 @@ endif()
ADD_EXECUTABLE(stgen3 util.cpp darkhttpd.c duktape/src/duktape.c markdown.cpp main.cpp)
target_include_directories(stgen3 PRIVATE include duktape/src)
target_include_directories(stgen3 PRIVATE include duktape/src itexToMML/itex-src
lib/lasem/src )
# Horrible Horrible headers for lasem
target_include_directories(stgen3 PRIVATE ${GLIB_INCLUDE_DIRS} /usr/include/cairo /usr/include/gdk-pixbuf-2.0 /usr/include/pango-1.0 /usr/include/harfbuzz/)
add_custom_command(
OUTPUT default-templates.h
@ -59,8 +68,10 @@ add_custom_command( @@ -59,8 +68,10 @@ add_custom_command(
)
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/MultiMarkdown/build/libMultiMarkdown.a)
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/itexToMML/itex-src/libitex2MML.a)
target_link_libraries(stgen3 PRIVATE tinyxml2)
target_link_libraries(stgen3 PRIVATE lexbor)
target_link_libraries(stgen3 PRIVATE lexbor )
target_link_libraries(stgen3 PRIVATE source-highlight)
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/lib/lasem/src/.libs/liblasem-0.6.a)
install(TARGETS stgen3)

160
main.cpp

@ -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()
{

Loading…
Cancel
Save