Render latex as PDf instead of an image - scaleable

#375
presentation
Andreas Butti 7 years ago
parent 27fee2c3c2
commit b6774e3b5b
  1. 17
      src/control/Control.cpp
  2. 1
      src/control/Control.h
  3. 1
      src/control/LatexController.cpp
  4. 2
      src/control/xojfile/LoadHandler.cpp
  5. 1
      src/gui/Layout.cpp
  6. 7
      src/model/Element.h
  7. 52
      src/model/TexImage.cpp
  8. 48
      src/model/TexImage.h
  9. 57
      src/view/DocumentView.cpp
  10. 24
      src/view/DocumentView.h

@ -2948,23 +2948,6 @@ void Control::clipboardPasteImage(GdkPixbuf* img)
clipboardPaste(image);
}
void Control::clipboardPasteTex(GdkPixbuf* img, const char* text, int textLength)
{
XOJ_CHECK_TYPE(Control);
TexImage* image = new TexImage();
image->setImage(img);
int width = gdk_pixbuf_get_width(img);
int height = gdk_pixbuf_get_height(img);
image->setWidth(width);
image->setHeight(height);
image->setText(string(text, textLength));
clipboardPaste(image);
}
void Control::clipboardPaste(Element* e)
{
XOJ_CHECK_TYPE(Control);

@ -251,7 +251,6 @@ public:
virtual void clipboardPasteEnabled(bool enabled);
virtual void clipboardPasteText(string text);
virtual void clipboardPasteImage(GdkPixbuf* img);
virtual void clipboardPasteTex(GdkPixbuf* img, const char* text, int textLength);
virtual void clipboardPasteXournal(ObjectInputStream& in);
virtual void deleteSelection();

@ -391,6 +391,7 @@ TexImage* LatexController::loadRendered()
}
TexImage* img = convertDocumentToImage(pdf);
img->setPdf(pdf);
g_object_unref(pdf);

@ -682,7 +682,7 @@ void LoadHandler::parseTexImage()
const char* imText = LoadHandlerHelper::getAttrib("text", false, this);
const char* compatibilityTest = LoadHandlerHelper::getAttrib("texlength", false, this);
int imTextLen = strlen(imText);
if(compatibilityTest != NULL)
if (compatibilityTest != NULL)
{
imTextLen = LoadHandlerHelper::getAttribInt("texlength", this);
}

@ -202,7 +202,6 @@ void Layout::layoutPages()
// get from mapper (some may have changed to accomodate paired setting etc.)
bool isPairedPages = mapper.getPairedPages();
int pagesOffset = mapper.getFirstPageOffset();
int rows = mapper.getRows();
int columns = mapper.getColumns();

@ -94,9 +94,14 @@ protected:
bool sizeCalculated;
private:
/**
* Type of this element
*/
ElementType type;
// The color in RGB format
/**
* The color in RGB format
*/
int color;
};

@ -4,14 +4,14 @@
#include <serializing/ObjectInputStream.h>
#include <serializing/ObjectOutputStream.h>
// TODO Serialize PDF
TexImage::TexImage()
: Element(ELEMENT_TEXIMAGE)
{
XOJ_INIT_TYPE(TexImage);
this->sizeCalculated = true;
this->image = NULL;
this->read = false;
}
TexImage::~TexImage()
@ -24,6 +24,12 @@ TexImage::~TexImage()
this->image = NULL;
}
if (this->pdf)
{
g_object_unref(this->pdf);
this->pdf = NULL;
}
XOJ_RELEASE_TYPE(TexImage);
}
@ -41,6 +47,12 @@ Element* TexImage::clone()
img->text = this->text;
img->data = this->data;
if (this->pdf)
{
img->pdf = this->pdf;
g_object_ref(img->pdf);
}
img->image = cairo_surface_reference(this->image);
return img;
@ -129,6 +141,40 @@ cairo_surface_t* TexImage::getImage()
return this->image;
}
/**
* @return The PDF Document, if rendered as .pdf
*
* The document needs to be referenced, if it will be hold somewhere
*/
PopplerDocument* TexImage::getPdf()
{
XOJ_CHECK_TYPE(TexImage);
return this->pdf;
}
/**
* @param pdf The PDF Document, if rendered as .pdf
*
* The PDF will be referenced
*/
void TexImage::setPdf(PopplerDocument* pdf)
{
XOJ_CHECK_TYPE(TexImage);
if (this->pdf != nullptr)
{
g_object_unref(this->pdf);
}
this->pdf = pdf;
if (this->pdf != nullptr)
{
g_object_ref(this->pdf);
}
}
void TexImage::scale(double x0, double y0, double fx, double fy)
{
XOJ_CHECK_TYPE(TexImage);
@ -147,6 +193,8 @@ void TexImage::scale(double x0, double y0, double fx, double fy)
void TexImage::rotate(double x0, double y0, double xo, double yo, double th)
{
XOJ_CHECK_TYPE(TexImage);
// Rotation for TexImages not yet implemented
}
void TexImage::serialize(ObjectOutputStream& out)

@ -14,6 +14,9 @@
#include "Element.h"
#include <XournalType.h>
#include <poppler.h>
class TexImage: public Element
{
public:
@ -24,15 +27,36 @@ public:
void setWidth(double width);
void setHeight(double height);
/**
* Set the Image, if rendered as image
*/
void setImage(string data);
void setImage(cairo_surface_t* image);
void setImage(GdkPixbuf* img);
/**
* Get the Image, if rendered as image
*/
cairo_surface_t* getImage();
/**
* @return The PDF Document, if rendered as .pdf
*
* The document needs to be referenced, if it will be hold somewhere
*/
PopplerDocument* getPdf();
/**
* @param pdf The PDF Document, if rendered as .pdf
*
* The PDF will be referenced
*/
void setPdf(PopplerDocument* pdf);
virtual void scale(double x0, double y0, double fx, double fy);
virtual void rotate(double x0, double y0, double xo, double yo, double th);
//text tag to alow latex
// text tag to alow latex
void setText(string text);
string getText();
@ -50,12 +74,28 @@ private:
private:
XOJ_TYPE_ATTRIB;
/**
* Tex PDF Document, if rendered as PDF
*/
PopplerDocument* pdf = NULL;
cairo_surface_t* image;
/**
* Tex image, if rendered as image
*/
cairo_surface_t* image = NULL;
/**
* PNG Image
*/
string data;
string::size_type read;
//text
/**
* Read position in data
*/
string::size_type read = 0;
/**
* Tex String
*/
string text;
};

@ -17,20 +17,8 @@
DocumentView::DocumentView()
{
XOJ_INIT_TYPE(DocumentView);
this->page = NULL;
this->cr = NULL;
this->lX = -1;
this->lY = -1;
this->lWidth = -1;
this->lHeight = -1;
this->width = 0;
this->height = 0;
this->dontRenderEditingStroke = 0;
this->backgroundPainter = new MainBackgroundPainter();
this->markAudioStroke = false;
}
DocumentView::~DocumentView()
@ -144,26 +132,51 @@ void DocumentView::drawImage(cairo_t* cr, Image* i)
cairo_set_matrix(cr, &defaultMatrix);
}
void DocumentView::drawTexImage(cairo_t* cr, TexImage* i)
void DocumentView::drawTexImage(cairo_t* cr, TexImage* texImage)
{
XOJ_CHECK_TYPE(DocumentView);
cairo_matrix_t defaultMatrix = { 0 };
cairo_get_matrix(cr, &defaultMatrix);
cairo_surface_t* img = i->getImage();
int width = cairo_image_surface_get_width(img);
int height = cairo_image_surface_get_height(img);
PopplerDocument* pdf = texImage->getPdf();
if (pdf != nullptr)
{
if (poppler_document_get_n_pages(pdf) < 1)
{
g_warning("Got latex PDf without pages!: %s", texImage->getText().c_str());
return;
}
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
PopplerPage* page = poppler_document_get_page(pdf, 0);
double xFactor = i->getElementWidth() / width;
double yFactor = i->getElementHeight() / height;
double pageWidth = 0;
double pageHeight = 0;
poppler_page_get_size(page, &pageWidth, &pageHeight);
cairo_scale(cr, xFactor, yFactor);
double xFactor = texImage->getElementWidth() / pageWidth;
double yFactor = texImage->getElementHeight() / pageHeight;
cairo_set_source_surface(cr, img, i->getX() / xFactor, i->getY() / yFactor);
cairo_paint(cr);
cairo_scale(cr, xFactor, yFactor);
poppler_page_render(page, cr);
}
else
{
cairo_surface_t* img = texImage->getImage();
int width = cairo_image_surface_get_width(img);
int height = cairo_image_surface_get_height(img);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
double xFactor = texImage->getElementWidth() / width;
double yFactor = texImage->getElementHeight() / height;
cairo_scale(cr, xFactor, yFactor);
cairo_set_source_surface(cr, img, texImage->getX() / xFactor, texImage->getY() / yFactor);
cairo_paint(cr);
}
cairo_set_matrix(cr, &defaultMatrix);
}

@ -96,7 +96,7 @@ public:
private:
void drawText(cairo_t* cr, Text* t);
void drawImage(cairo_t* cr, Image* i);
void drawTexImage(cairo_t* cr, TexImage* i);
void drawTexImage(cairo_t* cr, TexImage* texImage);
void drawElement(cairo_t* cr, Element* e);
@ -105,17 +105,17 @@ private:
private:
XOJ_TYPE_ATTRIB;
cairo_t* cr;
PageRef page;
double width;
double height;
bool dontRenderEditingStroke;
bool markAudioStroke;
double lX;
double lY;
double lWidth;
double lHeight;
cairo_t* cr = NULL;
PageRef page = NULL;
double width = 0;
double height = 0;
bool dontRenderEditingStroke = false;
bool markAudioStroke = false;
double lX = -1;
double lY = -1;
double lWidth = -1;
double lHeight = -1;
MainBackgroundPainter* backgroundPainter;
};

Loading…
Cancel
Save