latex-text-renderer.cpp revision 07b7f1aaaf1087716e784a50cf574a059f7018d3
/** \file
*
* The idea stems from GNUPlot's epslatex terminal output :-)
*/
/*
* Authors:
* Johan Engelen <goejendaagh@zonnet.nl>
* Miklos Erdelyi <erdelyim@gmail.com>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2006-2010 Authors
*
* Licensed under GNU GPL
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "latex-text-renderer.h"
#include <signal.h>
#include <errno.h>
#include "libnrtype/Layout-TNG.h"
#include "sp-item.h"
#include "sp-item-group.h"
#include "style.h"
#include "sp-root.h"
#include "sp-use.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "sp-rect.h"
#include "text-editing.h"
#include <unit-constants.h>
namespace Inkscape {
namespace Extension {
namespace Internal {
/**
* This method is called by the PDF, EPS and PS output extensions.
* @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
bool pdflatex)
{
doc->ensureUpToDate();
bool pageBoundingBox = true;
// we want to export the given item only
}
else {
// we want to export the entire document from root
}
if (!base)
return false;
/* Create renderer */
if (ret) {
/* Render document */
if (ret) {
}
}
delete renderer;
return ret;
}
{
}
LaTeXTextRenderer::~LaTeXTextRenderer(void)
{
if (_stream) {
}
/* restore default signal handling for SIGPIPE */
#endif
if (_filename) {
}
return;
}
/** This should create the output LaTeX file, and assign it to _stream.
* @return Returns true when succesfull
*/
bool
if (!osf) {
return false;
}
}
if (_stream) {
/* fixme: this is kinda icky */
#endif
}
/* flush this to test output stream as early as possible */
g_strerror(errno));
}
g_print("Output to LaTeX file failed\n");
/* fixme: should use pclose() for pipes */
return false;
}
return true;
}
static char const preamble[] =
"%% To include the image in your LaTeX document, write\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>.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"
"%%\n"
"\\begingroup%\n"
" \\makeatletter%\n"
" \\providecommand\\color[2][]{%\n"
" \\errmessage{(Inkscape) Color is used for the text in Inkscape, but the package \'color.sty\' is not loaded}%\n"
" \\renewcommand\\color[2][]{}%\n"
" }%\n"
" \\providecommand\\transparent[1]{%\n"
" \\errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package \'transparent.sty\' is not loaded}%\n"
" \\renewcommand\\transparent[1]{}%\n"
" }%\n"
" \\providecommand\\rotatebox[2]{#2}%\n";
static char const postamble[] =
" \\end{picture}%\n"
"\\endgroup%\n";
void
{
}
void
{
}
void
{
while (l) {
if (SP_IS_ITEM(o)) {
renderItem (SP_ITEM (o));
}
l = g_slist_remove (l, o);
}
}
void
{
bool translated = false;
translated = true;
}
}
if (translated) {
}
}
void
{
if (!strtext) {
return;
}
// replace carriage return with double slash
// get position and alignment
// Align vertically on the baseline of the font (retreived from the anchor point)
// Align horizontally on anchorpoint
case SP_CSS_TEXT_ANCHOR_START:
alignment = "[lb]";
break;
case SP_CSS_TEXT_ANCHOR_END:
alignment = "[rb]";
break;
default:
alignment = "[b]";
break;
}
// determine color and transparency (for now, use rgb color model as it is most native to Inkscape)
bool has_color = false; // if the item has no color set, don't force black color
bool has_transparency = false;
// TODO: how to handle ICC colors?
// give priority to fill color
has_color = true;
has_color = true;
}
if (opacity < 1.0) {
has_transparency = true;
}
// get rotation
// write to LaTeX
if (has_color) {
os << "\\color[rgb]{" << SP_RGBA32_R_F(rgba) << "," << SP_RGBA32_G_F(rgba) << "," << SP_RGBA32_B_F(rgba) << "}";
}
if (_pdflatex && has_transparency) {
}
if (has_rotation) {
}
// Walk through all spans in the text object.
// Write span strings to LaTeX, associated with font weight and style.
{
{
is_bold = true;
os << "\\textbf{";
}
{
is_italic = true;
os << "\\textit{";
}
{
is_oblique = true;
os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so...
}
if (!spanstr) {
continue;
}
// replace carriage return with double slash
os << spanstr_new;
}
if (has_rotation) {
}
}
void
{
/*
Flowtext is possible by using a minipage! :)
Flowing in rectangle is possible, not in arb shape.
*/
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
}
// get position and alignment
// Align on topleft corner.
justification = "\\raggedright ";
break;
justification = "\\raggedleft ";
break;
justification = "\\centering ";
default:
// no need to add LaTeX code for standard justified output :)
break;
}
// determine color and transparency (for now, use rgb color model as it is most native to Inkscape)
bool has_color = false; // if the item has no color set, don't force black color
bool has_transparency = false;
// TODO: how to handle ICC colors?
// give priority to fill color
has_color = true;
has_color = true;
}
if (opacity < 1.0) {
has_transparency = true;
}
// get rotation
// write to LaTeX
if (has_color) {
os << "\\color[rgb]{" << SP_RGBA32_R_F(rgba) << "," << SP_RGBA32_G_F(rgba) << "," << SP_RGBA32_B_F(rgba) << "}";
}
if (_pdflatex && has_transparency) {
}
if (has_rotation) {
}
os << justification;
// Walk through all spans in the text object.
// Write span strings to LaTeX, associated with font weight and style.
{
{
is_bold = true;
os << "\\textbf{";
}
{
is_italic = true;
os << "\\textit{";
}
{
is_oblique = true;
os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so...
}
if (!spanstr) {
continue;
}
// replace carriage return with double slash
os << spanstr_new;
}
os << "\\end{minipage}";
if (has_rotation) {
}
}
{
}
void
{
// Check item's visibility
return;
}
if (SP_IS_ROOT(item)) {
} else if (SP_IS_GROUP(item)) {
return sp_group_render(item);
} else if (SP_IS_TEXT(item)) {
return sp_text_render(item);
} else if (SP_IS_FLOWTEXT(item)) {
return sp_flowtext_render(item);
}
// We are not interested in writing the other SPItem types to LaTeX
}
void
{
}
bool
{
// The boundingbox calculation here should be exactly the same as the one by CairoRenderer::setupDocument !
if (!base) {
}
if (pageBoundingBox) {
} else {
}
if (!d) {
g_message("LaTeXTextRenderer: could not retrieve boundingbox.");
return false;
}
// scale all coordinates, such that the width of the image is 1, this is convenient for scaling the image in LaTeX
if (!pageBoundingBox)
{
}
// flip y-axis
// write the info to LaTeX
// scaling of the image when including it in LaTeX
os << " \\ifx\\svgwidth\\undefined%\n";
os << " \\ifx\\svgscale\\undefined%\n";
os << " \\relax%\n";
os << " \\else%\n";
os << " \\setlength{\\unitlength}{\\unitlength * \\real{\\svgscale}}%\n";
os << " \\fi%\n";
os << " \\else%\n";
os << " \\setlength{\\unitlength}{\\svgwidth}%\n";
os << " \\fi%\n";
os << " \\global\\let\\svgwidth\\undefined%\n";
os << " \\global\\let\\svgscale\\undefined%\n";
os << " \\makeatother%\n";
// strip pathname, as it is probably desired. Having a specific path in the TeX file is not convenient.
return true;
}
{
return _transform_stack.top();
}
void
{
if(_transform_stack.size()){
} else {
}
}
void
{
}
} /* namespace Internal */
} /* namespace Extension */
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :