Just need to finish the Control.cpp and PageView.cpp.

presentation
Wilson Brenna 13 years ago
parent 44b71e479a
commit 0dc7b6e5e0
  1. 2
      src/Makefile.am
  2. 1
      src/control/Actions.h
  3. 25
      src/control/Control.cpp
  4. 5
      src/control/Control.h
  5. 68
      src/gui/dialog/LatexGlade.cpp
  6. 42
      src/gui/dialog/LatexGlade.h
  7. 2
      src/gui/toolbarMenubar/ToolMenuHandler.cpp
  8. 2
      src/model/Element.h
  9. 169
      src/model/TexImage.cpp
  10. 63
      src/model/TexImage.h
  11. 95
      src/util/LatexAction.cpp
  12. 42
      src/util/LatexAction.h
  13. 4
      src/util/XournalTypeList.h
  14. 4
      ui/texdialog.glade

@ -74,6 +74,7 @@ xournalpp_SOURCES = \
gui/dialog/PdfPagesDialog.cpp \
gui/dialog/SelectBackgroundColorDialog.cpp \
gui/dialog/SettingsDialog.cpp \
gui/dialog/LatexGlade.cpp \
gui/pageposition/PagePosition.cpp \
gui/pageposition/PagePositionCache.cpp \
gui/pageposition/PagePositionHandler.cpp \
@ -136,6 +137,7 @@ xournalpp_SOURCES = \
model/PageRef.cpp \
model/Point.cpp \
model/Stroke.cpp \
model/TexImage.cpp \
model/Text.cpp \
model/XojPage.cpp \
pdf/cairo/CairoPdf.cpp \

@ -123,6 +123,7 @@ enum ActionType {
ACTION_SELECT_FONT,
ACTION_FONT_BUTTON_CHANGED,
ACTION_TEX,
// Menu View
ACTION_ZOOM_IN = 600,

@ -704,6 +704,9 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent *even
case ACTION_SELECT_COLOR_CUSTOM:
// nothing to do here, the color toolbar item handles the color
break;
case ACTION_TEX:
runLatex();
break;
// Menu View
case ACTION_ZOOM_100:
@ -2665,6 +2668,28 @@ void Control::fontChanged() {
}
}
//The core handler for inserting latex
void Control::runLatex() {
XOJ_CHECK_TYPE(Control);
this->doc->lock();
int pageNr = getCurrentPageNo();
if (pageNr == -1) {
return;
}
PageView * veiw = win->getXournal()->getViewFor(pageNr);
if (view == NULL) {
return;
}
//we get the selection
PageRef page = this->doc->getPage(pageNr);
Layer * layer = page.getSelectedLayer();
}
/**
* GETTER / SETTER
*/

@ -18,6 +18,8 @@
#include "../undo/UndoRedoHandler.h"
#include "ClipboardHandler.h"
#include "settings/Settings.h"
#include "../util/LatexAction.h"
#include "../gui/dialog/LatexGlade.h"
#include "ToolHandler.h"
#include "../model/Document.h"
#include "ZoomControl.h"
@ -70,6 +72,9 @@ public:
// Menu edit
void showSettings();
// Menu tools
void runLatex();
// Menu Help
void showAbout();

@ -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__ */

@ -503,6 +503,8 @@ void ToolMenuHandler::initToolItems() {
registerMenupoint(gui->get("menuToolsTextFont"), ACTION_SELECT_FONT);
registerMenupoint(gui->get("menuEditTex"), ACTION_TEX);
registerMenupoint(gui->get("menuViewToolbarManage"), ACTION_MANAGE_TOOLBAR);
registerMenupoint(gui->get("menuViewToolbarCustomize"), ACTION_CUSTOMIZE_TOOLBAR);

@ -17,7 +17,7 @@
#include <XournalType.h>
enum ElementType {
ELEMENT_STROKE = 1, ELEMENT_IMAGE, ELEMENT_TEXT
ELEMENT_STROKE = 1, ELEMENT_IMAGE, ELEMENT_TEXIMAGE, ELEMENT_TEXT
};
class ShapeContainer {

@ -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__ */

@ -194,8 +194,8 @@ XOJ_DECLARE_TYPE(CustomizeableColorList, 182);
XOJ_DECLARE_TYPE(GotoDialog, 183);
XOJ_DECLARE_TYPE(ToolbarColorNames, 184);
XOJ_DECLARE_TYPE(TextBoxUndoAction, 185);
//XOJ_DECLARE_TYPE(XXXXXXXXXXXXXXXX, 186);
//XOJ_DECLARE_TYPE(XXXXXXXXXXXXXXXX, 187);
XOJ_DECLARE_TYPE(LatexGlade, 186);
XOJ_DECLARE_TYPE(TexImage, 187);
//XOJ_DECLARE_TYPE(XXXXXXXXXXXXXXXX, 188);
//XOJ_DECLARE_TYPE(XXXXXXXXXXXXXXXX, 189);
//XOJ_DECLARE_TYPE(XXXXXXXXXXXXXXXX, 19);

@ -22,7 +22,7 @@
<child>
<widget class="GtkButton" id="texcancelbutton">
<property name="label">gtk-cancel</property>
<property name="response_id">-1</property>
<property name="response_id">2</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@ -41,7 +41,7 @@
<property name="response_id">1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</widget>

Loading…
Cancel
Save