latex-text-renderer.cpp revision d8f3a78f8c37c308259f309af4ca766ee45dfcd2
/** \file
*
* The idea stems from GNUPlot's epslatex terminal output :-)
*/
/*
* Authors:
* Johan Engelen <goejendaagh@zonnet.nl>
* Miklos Erdelyi <erdelyim@gmail.com>
*
* 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 "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 extension to which the tex code should be written. Output goes to <filename>.tex.
*/
bool
{
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"
"%% \\setlength{\\unitlength}{<desired width>}\n"
"%% \\input{<filename>.tex}\n"
"%% instead of\n"
"%% \\includegraphics[width=<desired width>]{<filename>.pdf}\n"
"\n"
"\\begingroup \n"
" \\makeatletter \n"
" \\providecommand\\color[2][]{% \n"
" \\GenericError{(Inkscape) \\space\\space\\@spaces}{% \n"
" Color is used for the text in Inkscape, but the color package color is not loaded. \n"
" }{Either use black text in Inkscape or load the package \n"
" color.sty in LaTeX.}% \n"
" \\renewcommand\\color[2][]{}% \n"
" }%% \n"
" \\providecommand\\rotatebox[2]{#2}% \n"
" \\makeatother \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;
SPUse *use = SP_USE(item);
push_transform(tp);
translated = true;
}
if (use->child && SP_IS_ITEM(use->child)) {
renderItem(SP_ITEM(use->child));
}
if (translated) {
pop_transform();
}
*/
}
void
{
// get position and alignment
case SP_CSS_TEXT_ANCHOR_START:
alignment = "[l]";
break;
case SP_CSS_TEXT_ANCHOR_END:
alignment = "[r]";
break;
default:
alignment = "";
break;
}
// determine color (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
// TODO: how to handle ICC colors?
// give priority to fill color
has_color = true;
has_color = 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 (has_rotation) {
}
if (has_rotation) {
}
}
void
{
/* SPFlowtext *group = SP_FLOWTEXT(item);
// write to LaTeX
Inkscape::SVGOStringStream os;
os << " \\begin{picture}(" << _width << "," << _height << ")%%\n";
os << " \\gplgaddtomacro\\gplbacktext{%%\n";
os << " \\csname LTb\\endcsname%%\n";
os << "\\put(0,0){\\makebox(0,0)[lb]{\\strut{}Position}}%%\n";
fprintf(_stream, "%s", os.str().c_str());
*/
}
void
{
}
void
{
// Check item's visibility
return;
}
if (SP_IS_ROOT(item)) {
return sp_root_render(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 {
}
// 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
// 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:encoding=utf-8:textwidth=99 :