@ -21,33 +21,8 @@
@@ -21,33 +21,8 @@
# include <thread>
# include <queue>
# include <base64.h>
# define katex_support
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 <lsm.h>
# include <lsmmathml.h>
# include <lsmsvg.h>
# include <glib.h>
# include <glib/gi18n.h>
# include <gio/gio.h>
# include <cairo-pdf.h>
# include <cairo-svg.h>
# include <cairo-ps.h>
}
# include <json.hpp>
# include <date.h>
@ -66,8 +41,6 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in
@@ -66,8 +41,6 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in
# include "srchighlight.hpp"
# include "itex2MML.h"
# include "mtex2MML.h"
namespace lex {
extern " C " {
@ -114,173 +87,6 @@ struct Dom {
@@ -114,173 +87,6 @@ struct Dom {
} ;
} ;
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 ;
public :
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 : : string * cairobuffer = ( std : : string * ) closure ;
for ( int i = 0 ; i < datalen ; i + + ) {
cairobuffer - > push_back ( data [ i ] ) ;
}
return CAIRO_STATUS_SUCCESS ;
}
std : : string get_svg_from_mtex ( const std : : string & itex ) {
char * mml = mtex2MML_parse ( itex . c_str ( ) , itex . size ( ) , MTEX2MML_DELIMITER_PARENS | MTEX2MML_DELIMITER_BRACKETS ) ;
if ( ! mml ) {
spdlog : : error ( " Failed to parse mtex {} " , itex ) ;
return itex ;
}
//auto doc = LSM_DOM_DOCUMENT(mml);
auto doc = lsm_dom_document_new_from_memory ( mml , - 1 , NULL ) ;
mtex2MML_free_string ( mml ) ;
char * tbuffer ;
gsize size ;
lsm_dom_document_save_to_memory ( doc , & tbuffer , & size , NULL ) ;
std : : string mathml { tbuffer , tbuffer + size } ;
// spdlog::info("Mathml: {}", mathml);
g_free ( tbuffer ) ;
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);
std : : string bufer { } ;
cairo_surface_t * surface = cairo_svg_surface_create_for_stream ( cairo_stream_to_buffer_func , ( void * ) & bufer , width_pt , height_pt ) ;
/*
// uncomment this to dump all the svgs in a folder
static int i = 0 ;
i + + ;
std : : ostringstream ss { } ;
ss < < " svg/ " < < i < < " .svg " ;
cairo_surface_t * surface = cairo_svg_surface_create ( ss . str ( ) . c_str ( ) , width_pt , height_pt ) ;
*/
// the render context
cairo_t * cairo = cairo_create ( surface ) ;
cairo_scale ( cairo , option_zoom , option_zoom ) ;
lsm_dom_view_render ( view , cairo , - offset_x_pt , - offset_y_pt ) ;
/*
void
cairo_surface_get_mime_data ( cairo_surface_t * surface ,
const char * mime_type ,
const unsigned char * * data ,
unsigned long * length ) ;
*/
unsigned long sd_len ;
const unsigned char * data ;
cairo_surface_destroy ( surface ) ;
cairo_destroy ( cairo ) ;
g_object_unref ( view ) ;
g_object_unref ( doc ) ;
// bufer contains svg
// mathml contains mathml
return bufer ;
}
} ;
} ;
const std : : string SITE_CONFIG_FNAME = " stgen.json " ;
const std : : string DEFAULT_PUBLISH_ROOT = " public " ;
const std : : string DEFAULT_SOURCE_DIR = " . " ;
@ -508,7 +314,6 @@ class builder {
@@ -508,7 +314,6 @@ class builder {
std : : unordered_map < fs : : path , time_t , pathHash > last_build ;
gnu_highlighter shl { } ;
imtex : : Imtex imtx { } ;
const std : : set < std : : string > apply_templates_exts { " md " , " html " , " txt " , " markdown " , " xml " , " atom " , " rss " } ;