parent
44b71e479a
commit
0dc7b6e5e0
14 changed files with 519 additions and 5 deletions
@ -0,0 +1,68 @@ |
||||
#include "LatexGlade.h" |
||||
|
||||
#include "../../control/tools/ImageHandler.h" |
||||
#include "../../model/TexImage.h" |
||||
|
||||
#include "../../util/LatexAction.h" |
||||
|
||||
LatexGlade::LatexGlade(GladeSearchpath * gladeSearchPath) : |
||||
GladeGui(gladeSearchPath, "texdialog.glade", "texDialog") { |
||||
XOJ_INIT_TYPE(LatexGlade); |
||||
|
||||
this->theLatex = NULL; |
||||
|
||||
//GtkWidget * vbox = get("texVBox");
|
||||
//g_return_if_fail(vbox != NULL);
|
||||
this->texBox = get("texEntry"); |
||||
gtk_entry_set_max_length(GTK_ENTRY(this->texBox),50); |
||||
|
||||
gtk_widget_show(this->texBox); |
||||
} |
||||
|
||||
LatexGlade::~LatexGlade() { |
||||
XOJ_CHECK_TYPE(LatexGlade); |
||||
|
||||
XOJ_RELEASE_TYPE(LatexGlade); |
||||
|
||||
} |
||||
|
||||
void LatexGlade::setTex(gchar * texString) |
||||
{ |
||||
this->theLatex = texString; |
||||
} |
||||
gchar * LatexGlade::getTex() |
||||
{ |
||||
return this->theLatex; |
||||
} |
||||
|
||||
void LatexGlade::save() { |
||||
this->theLatex = g_strdup(gtk_entry_get_text(GTK_ENTRY(this->texBox))); |
||||
} |
||||
|
||||
void LatexGlade::load() { |
||||
printf("Latex::load()\n"); |
||||
|
||||
if (theLatex == NULL) |
||||
{ |
||||
theLatex = "x^2"; |
||||
} |
||||
gtk_entry_set_text(GTK_ENTRY(this->texBox), this->theLatex); |
||||
|
||||
|
||||
} |
||||
|
||||
void LatexGlade::show(GtkWindow * parent){ |
||||
XOJ_CHECK_TYPE(LatexGlade); |
||||
this->load(); |
||||
gtk_window_set_transient_for(GTK_WINDOW(this->window),parent); |
||||
int res = gtk_dialog_run(GTK_DIALOG(this->window)); |
||||
if (res == 1) { |
||||
printf("Checkbox OK-d.\n"); |
||||
this->save(); |
||||
} |
||||
else |
||||
{ |
||||
this->theLatex = ""; |
||||
} |
||||
gtk_widget_hide(this->window); |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Latex implementation |
||||
* |
||||
* @author W Brenna |
||||
* http://wbrenna.ca
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __LATEXGLADE_H__ |
||||
#define __LATEXGLADE_H__ |
||||
|
||||
#include "../../model/LayerListener.h" |
||||
#include <gtk/gtk.h> |
||||
#include <glib/gstdio.h> |
||||
#include "../../model/TexImage.h" |
||||
#include <XournalType.h> |
||||
#include "../../gui/GladeGui.h" |
||||
|
||||
|
||||
class LatexGlade : public GladeGui { |
||||
public: |
||||
LatexGlade(GladeSearchpath * gladeSearchPath); |
||||
virtual ~LatexGlade(); |
||||
|
||||
public: |
||||
virtual void show(GtkWindow * parent); |
||||
void save(); |
||||
void load(); |
||||
void setTex(gchar * texString); |
||||
gchar * getTex(); |
||||
|
||||
|
||||
private: |
||||
XOJ_TYPE_ATTRIB; |
||||
GtkWidget * texBox; |
||||
gchar * theLatex; |
||||
}; |
||||
|
||||
#endif /* __LATEXGLADE_H__ */ |
||||
@ -0,0 +1,169 @@ |
||||
#include "TexTexImage.h" |
||||
#include <serializing/ObjectOutputStream.h> |
||||
#include <serializing/ObjectInputStream.h> |
||||
#include <pixbuf-utils.h> |
||||
|
||||
TexImage::TexImage() : |
||||
Element(ELEMENT_TEXIMAGE) { |
||||
|
||||
XOJ_INIT_TYPE(TexImage); |
||||
|
||||
this->sizeCalculated = true; |
||||
this->image = NULL; |
||||
this->data = NULL; |
||||
this->dLen = 0; |
||||
this->read = false; |
||||
|
||||
//text tags
|
||||
this->text = NULL; |
||||
this->textlen = 0; |
||||
} |
||||
|
||||
TexImage::~TexImage() { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
if (this->image) { |
||||
cairo_surface_destroy(this->image); |
||||
this->image = NULL; |
||||
} |
||||
|
||||
XOJ_RELEASE_TYPE(TexImage); |
||||
} |
||||
|
||||
void TexImage::setWidth(double width) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
this->width = width; |
||||
} |
||||
|
||||
void TexImage::setHeight(double height) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
this->height = height; |
||||
} |
||||
|
||||
cairo_status_t TexImage::cairoReadFunction(TexImage * image, unsigned char * data, unsigned int length) { |
||||
XOJ_CHECK_TYPE_OBJ(image, TexImage); |
||||
|
||||
for (int i = 0; i < length; i++, image->read++) { |
||||
if (image->read >= image->dLen) { |
||||
return CAIRO_STATUS_READ_ERROR; |
||||
} |
||||
data[i] = image->data[image->read]; |
||||
} |
||||
|
||||
return CAIRO_STATUS_SUCCESS; |
||||
} |
||||
|
||||
void TexImage::setImage(unsigned char * data, int len) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
if (this->image) { |
||||
cairo_surface_destroy(this->image); |
||||
this->image = NULL; |
||||
} |
||||
if (this->data) { |
||||
g_free(this->data); |
||||
} |
||||
this->data = data; |
||||
this->dLen = len; |
||||
} |
||||
|
||||
void TexImage::setImage(GdkPixbuf * img) { |
||||
setTexImage(f_pixbuf_to_cairo_surface(img)); |
||||
} |
||||
|
||||
void TexImage::setImage(cairo_surface_t * image) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
if (this->image) { |
||||
cairo_surface_destroy(this->image); |
||||
this->image = NULL; |
||||
} |
||||
if (this->data) { |
||||
g_free(this->data); |
||||
} |
||||
this->data = NULL; |
||||
this->dLen = 0; |
||||
|
||||
this->image = image; |
||||
} |
||||
|
||||
void TexImage::setText(unsigned char * text, int textlen) |
||||
{ |
||||
this->text = text; |
||||
this->textlen = textlen; |
||||
} |
||||
|
||||
unsigned char * TexImage::getText() |
||||
{ |
||||
return this->text; |
||||
} |
||||
|
||||
cairo_surface_t * TexImage::getImage() { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
if (this->image == NULL && this->dLen != 0) { |
||||
this->read = 0; |
||||
this->image = cairo_image_surface_create_from_png_stream((cairo_read_func_t) &cairoReadFunction, this); |
||||
g_free(this->data); |
||||
this->data = NULL; |
||||
this->dLen = 0; |
||||
} |
||||
|
||||
return this->image; |
||||
} |
||||
|
||||
void TexImage::scale(double x0, double y0, double fx, double fy) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
this->x -= x0; |
||||
this->x *= fx; |
||||
this->x += x0; |
||||
this->y -= y0; |
||||
this->y *= fy; |
||||
this->y += y0; |
||||
|
||||
this->width *= fx; |
||||
this->height *= fy; |
||||
} |
||||
|
||||
void TexImage::serialize(ObjectOutputStream & out) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
out.writeObject("TexImage"); |
||||
|
||||
serializeElement(out); |
||||
|
||||
out.writeDouble(this->width); |
||||
out.writeDouble(this->height); |
||||
|
||||
out.writeTexImage(this->image); |
||||
|
||||
out.endObject(); |
||||
} |
||||
|
||||
void TexImage::readSerialized(ObjectInputStream & in) throw (InputStreamException) { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
|
||||
in.readObject("TexImage"); |
||||
|
||||
readSerializedElement(in); |
||||
|
||||
this->width = in.readDouble(); |
||||
this->height = in.readDouble(); |
||||
|
||||
if (this->image) { |
||||
cairo_surface_destroy(this->image); |
||||
this->image = NULL; |
||||
} |
||||
|
||||
this->image = in.readTexImage(); |
||||
|
||||
in.endObject(); |
||||
} |
||||
|
||||
void TexImage::calcSize() { |
||||
XOJ_CHECK_TYPE(TexImage); |
||||
} |
||||
|
||||
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* An Image on the document |
||||
* |
||||
* @author Xournal Team |
||||
* http://xournal.sf.net
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __IMAGE_H__ |
||||
#define __IMAGE_H__ |
||||
|
||||
#include "Element.h" |
||||
#include <XournalType.h> |
||||
|
||||
class TexImage: public Element { |
||||
public: |
||||
TexImage(); |
||||
virtual ~TexImage(); |
||||
|
||||
public: |
||||
void setWidth(double width); |
||||
void setHeight(double height); |
||||
|
||||
void setImage(unsigned char * data, int len); |
||||
void setImage(cairo_surface_t * image); |
||||
void setImage(GdkPixbuf * img); |
||||
cairo_surface_t * getImage(); |
||||
|
||||
virtual void scale(double x0, double y0, double fx, double fy); |
||||
|
||||
//text tag to alow latex
|
||||
void setText(unsigned char * text, int textlen); |
||||
//returns length
|
||||
unsigned char * getText(); |
||||
|
||||
public: |
||||
// Serialize interface
|
||||
void serialize(ObjectOutputStream & out); |
||||
void readSerialized(ObjectInputStream & in) throw (InputStreamException); |
||||
|
||||
private: |
||||
virtual void calcSize(); |
||||
|
||||
static cairo_status_t cairoReadFunction(Image * image, unsigned char *data, unsigned int length); |
||||
private: |
||||
XOJ_TYPE_ATTRIB; |
||||
|
||||
|
||||
cairo_surface_t * image; |
||||
|
||||
unsigned char * data; |
||||
int dLen; |
||||
|
||||
int read; |
||||
//text
|
||||
unsigned char * text; |
||||
int textlen; |
||||
}; |
||||
|
||||
#endif /* __IMAGE_H__ */ |
||||
@ -0,0 +1,95 @@ |
||||
#include "LatexAction.h" |
||||
#include "../control/Control.h" |
||||
#include "../model/Stroke.h" |
||||
#include "../model/Layer.h" |
||||
#include "../gui/PageView.h" |
||||
#include "../gui/XournalView.h" |
||||
|
||||
//some time - clean up these includes
|
||||
#include <serializing/ObjectOutputStream.h> |
||||
#include <serializing/HexObjectEncoding.h> |
||||
|
||||
|
||||
#include "../control/tools/ImageHandler.h" |
||||
#include "../model/TexImage.h" |
||||
#include <glib/gstdio.h> |
||||
|
||||
#include "../cfg.h" |
||||
#include <glib.h> |
||||
|
||||
LatexAction::LatexAction(gchar * myTex) { |
||||
//this->control = control;
|
||||
|
||||
this->theLatex = myTex; |
||||
|
||||
this->texfile = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, CONFIG_DIR, G_DIR_SEPARATOR_S, "tex", NULL); |
||||
this->texfilefull = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, CONFIG_DIR, G_DIR_SEPARATOR_S, "tex.png", NULL); |
||||
printf("%s \n",this->texfile); |
||||
|
||||
//set up the default positions.
|
||||
this->myx = 0; |
||||
this->myy = 0; |
||||
} |
||||
|
||||
LatexAction::~LatexAction() { |
||||
g_free(this->texfile); |
||||
g_free(this->texfilefull); |
||||
} |
||||
|
||||
void LatexAction::runCommand(){ |
||||
/*
|
||||
* at some point, I may need to sanitize theLatex |
||||
*/ |
||||
printf("Command is being run.\n"); |
||||
const gchar* mtex = "mathtex"; |
||||
gchar* mathtex = g_find_program_in_path(mtex); |
||||
if (!mathtex) |
||||
{ |
||||
printf("Error: problem finding mathtex. Doing nothing...\n"); |
||||
return; |
||||
} |
||||
printf("Found mathtex in your path!\n"); |
||||
g_free(mathtex); |
||||
gchar* command = NULL; |
||||
//can change font colour later with more features
|
||||
const gchar * fontcolour = "black"; |
||||
command = g_strdup_printf( |
||||
"%s -m 0 \"\\png\\usepackage{color}\\color{%s}\\%s %s\" -o %s", |
||||
mtex, strlen(fontcolour) ? fontcolour : "black",
|
||||
"normalsize", |
||||
this->theLatex, this->texfile); |
||||
|
||||
gint rt = 0; |
||||
void(*texhandler)(int) = signal(SIGCHLD,SIG_DFL); |
||||
gboolean success = g_spawn_command_line_sync(command,NULL,NULL,&rt,NULL); |
||||
signal(SIGCHLD,texhandler); |
||||
if (!success) |
||||
{ |
||||
printf("Latex Command execution failed.\n"); |
||||
return; |
||||
} |
||||
g_free(command); |
||||
printf("Tex command: \"%s\" was successful; in file %s.\n",this->theLatex,this->texfilefull); |
||||
|
||||
} |
||||
|
||||
void LatexAction::mathtexAddImage(Control * control, double x, double y) { |
||||
printf("Adding element\n"); |
||||
} |
||||
|
||||
void LatexAction::mathtexModImage(TexImage * img, Layer * layer) |
||||
{ |
||||
//get the image we're looking at and take care of all that
|
||||
|
||||
//get theLatex and query for modifications
|
||||
//this->texlen = img->getText(this->theLatex);
|
||||
|
||||
this->myx = img->getX(); |
||||
this->myy = img->getY(); |
||||
|
||||
//remove image
|
||||
//
|
||||
layer->removeElement(img,false); |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Latex implementation |
||||
* |
||||
* @author W Brenna |
||||
* http://wbrenna.ca
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __LATEXACTION_H__ |
||||
#define __LATEXACTION_H__ |
||||
|
||||
#include "../model/LayerListener.h" |
||||
#include <gtk/gtk.h> |
||||
#include <glib/gstdio.h> |
||||
#include "../model/TexImage.h" |
||||
|
||||
|
||||
class Control; |
||||
|
||||
class LatexAction { |
||||
public: |
||||
LatexAction(gchar * myTex); |
||||
virtual ~LatexAction(); |
||||
|
||||
public: |
||||
void mathtexModImage(TexImage * img, Layer * layer); |
||||
void mathtexAddImage(Control * control, double x, double y); |
||||
void runCommand(); |
||||
|
||||
|
||||
private: |
||||
// Control * control;
|
||||
gchar * theLatex; |
||||
gchar * texfile; |
||||
gchar * texfilefull; |
||||
double myx, myy; |
||||
}; |
||||
|
||||
#endif /* __LATEXACTION_H__ */ |
||||
Loading…
Reference in new issue