Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / extension / internal / latex-text-renderer.cpp
index 28bba1bebcec4271a54e4cfa7e434525d024825d..fd99afe31b71f2fedd8c9dd503d97e277ce4d44d 100644 (file)
@@ -1,5 +1,3 @@
-#define EXTENSION_INTERNAL_LATEX_TEXT_RENDERER_CPP
-
 /** \file
  * Rendering LaTeX file (pdf/eps/ps+latex output)
  *
@@ -9,6 +7,8 @@
  * Authors:
  *   Johan Engelen <goejendaagh@zonnet.nl>
  *   Miklos Erdelyi <erdelyim@gmail.com>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2006-2010 Authors
  *
@@ -51,14 +51,14 @@ namespace Internal {
 
 /**
  * This method is called by the PDF, EPS and PS output extensions.
- * @param filename This should be the filename without extension to which the tex code should be written. Output goes to <filename>.tex.
+ * @param filename This should be the filename without '_tex' extension to which the tex code should be written. Output goes to <filename>_tex, note the underscore instead of period.
  */
 bool
 latex_render_document_text_to_file( SPDocument *doc, gchar const *filename,
                                     const gchar * const exportId, bool exportDrawing, bool exportCanvas,
                                     bool pdflatex)
 {
-    sp_document_ensure_up_to_date(doc);
+    doc->ensureUpToDate();
 
     SPItem *base = NULL;
 
@@ -70,7 +70,7 @@ latex_render_document_text_to_file( SPDocument *doc, gchar const *filename,
     }
     else {
         // we want to export the entire document from root
-        base = SP_ITEM(sp_document_root(doc));
+        base = SP_ITEM(doc->getRoot());
         pageBoundingBox = !exportDrawing;
     }
 
@@ -132,7 +132,7 @@ LaTeXTextRenderer::setTargetFile(gchar const *filename) {
 
         _filename = g_path_get_basename(filename);
 
-        gchar *filename_ext = g_strdup_printf("%s.tex", filename);
+        gchar *filename_ext = g_strdup_printf("%s_tex", filename);
         Inkscape::IO::dump_fopen_call(filename_ext, "K");
         FILE *osf = Inkscape::IO::fopen_utf8name(filename_ext, "w+");
         if (!osf) {
@@ -176,14 +176,26 @@ LaTeXTextRenderer::setTargetFile(gchar const *filename) {
 
 static char const preamble[] =
 "%% To include the image in your LaTeX document, write\n"
-"%%   \\input{<filename>.tex}\n"
+"%%   \\input{<filename>.pdf_tex}\n"
 "%%  instead of\n"
 "%%   \\includegraphics{<filename>.pdf}\n"
 "%% To scale the image, write\n"
-"%%   \\def{\\svgwidth}{<desired width>}\n"
-"%%   \\input{<filename>.tex}\n"
+"%%   \\def\\svgwidth{<desired width>}\n"
+"%%   \\input{<filename>.pdf_tex}\n"
 "%%  instead of\n"
 "%%   \\includegraphics[width=<desired width>]{<filename>.pdf}\n"
+"%%\n"
+"%% Images with a different path to the parent latex file can\n"
+"%% be accessed with the `import' package (which may need to be\n"
+"%% installed) using\n"
+"%%   \\usepackage{import}\n"
+"%% in the preamble, and then including the image with\n"
+"%%   \\import{<path to file>}{<filename>.pdf_tex}\n"
+"%% Alternatively, one can specify\n"
+"%%   \\graphicspath{{<path to file>/}}\n"
+"%% \n"
+"%% For more information, please see info/svg-inkscape on CTAN:\n"
+"%%   http://tug.ctan.org/tex-archive/info/svg-inkscape\n"
 "\n"
 "\\begingroup\n"
 "  \\makeatletter\n"
@@ -299,7 +311,7 @@ LaTeXTextRenderer::sp_text_render(SPItem *item)
     }
 
     // get rotation
-    Geom::Matrix i2doc = sp_item_i2doc_affine(item);
+    Geom::Matrix i2doc = item->i2doc_affine();
     Geom::Matrix wotransl = i2doc.without_translation();
     double degrees = -180/M_PI * Geom::atan2(wotransl.xAxis());
     bool has_rotation = !Geom::are_near(degrees,0.);
@@ -350,13 +362,13 @@ Flowing in rectangle is possible, not in arb shape.
     g_free(strtext);
     g_strfreev(splitstr);
 
-    if (!flowtext->has_internal_frame()) {
-        // has_internal_frame includes a check that frame is a SPRect
+    SPItem *frame_item = flowtext->get_frame(NULL);
+    if (!frame_item || !SP_IS_RECT(frame_item)) {
         g_warning("LaTeX export: non-rectangular flowed text shapes are not supported, skipping text.");
         return; // don't know how to handle non-rect frames yet. is quite uncommon for latex users i think
     }
 
-    SPRect *frame = SP_RECT(flowtext->get_frame(NULL));
+    SPRect *frame = SP_RECT(frame_item);
     Geom::Rect framebox = sp_rect_get_rect(frame) * transform();
 
     // get position and alignment
@@ -365,13 +377,13 @@ Flowing in rectangle is possible, not in arb shape.
     gchar const *justification = "";
     switch (flowtext->layout.paragraphAlignment(flowtext->layout.begin())) {
     case Inkscape::Text::Layout::LEFT:
-        justification = "\\raggedright";
+        justification = "\\raggedright ";
         break;
     case Inkscape::Text::Layout::RIGHT:
-        justification = "\\raggedleft";
+        justification = "\\raggedleft ";
         break;
     case Inkscape::Text::Layout::CENTER:
-        justification = "\\centering";
+        justification = "\\centering ";
     case Inkscape::Text::Layout::FULL:
     default:
         // no need to add LaTeX code for standard justified output :)
@@ -400,7 +412,7 @@ Flowing in rectangle is possible, not in arb shape.
     }
 
     // get rotation
-    Geom::Matrix i2doc = sp_item_i2doc_affine(item);
+    Geom::Matrix i2doc = item->i2doc_affine();
     Geom::Matrix wotransl = i2doc.without_translation();
     double degrees = -180/M_PI * Geom::atan2(wotransl.xAxis());
     bool has_rotation = !Geom::are_near(degrees,0.);
@@ -478,15 +490,16 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, SPItem *
 {
 // The boundingbox calculation here should be exactly the same as the one by CairoRenderer::setupDocument !
 
-    if (!base)
-        base = SP_ITEM(sp_document_root(doc));
+    if (!base) {
+        base = SP_ITEM(doc->getRoot());
+    }
 
     Geom::OptRect d;
     if (pageBoundingBox) {
         d = Geom::Rect( Geom::Point(0,0),
-                        Geom::Point(sp_document_width(doc), sp_document_height(doc)) );
+                        Geom::Point(doc->getWidth(), doc->getHeight()) );
     } else {
-        sp_item_invoke_bbox(base, d, sp_item_i2d_affine(base), TRUE, SPItem::RENDERING_BBOX);
+        base->invoke_bbox( d, base->i2d_affine(), TRUE, SPItem::RENDERING_BBOX);
     }
     if (!d) {
         g_message("LaTeXTextRenderer: could not retrieve boundingbox.");
@@ -505,7 +518,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, SPItem *
     }
 
     // flip y-axis
-    push_transform( Geom::Scale(1,-1) * Geom::Translate(0, sp_document_height(doc)) );
+    push_transform( Geom::Scale(1,-1) * Geom::Translate(0, doc->getHeight()) );
 
     // write the info to LaTeX
     Inkscape::SVGOStringStream os;
@@ -566,4 +579,4 @@ LaTeXTextRenderer::pop_transform()
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :