summaryrefslogtreecommitdiffstats
path: root/src/extension/internal/latex-text-renderer.h
blob: a96a2631a4e391fbf29163f439a4552a0ce7bd76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef EXTENSION_INTERNAL_LATEX_TEXT_RENDERER_H_SEEN
#define EXTENSION_INTERNAL_LATEX_TEXT_RENDERER_H_SEEN

/** \file
 * Declaration of LaTeXTextRenderer, used for rendering the accompanying LaTeX file when exporting to PDF/EPS/PS + LaTeX 
 */
/*
 * Authors:
 *  Johan Engelen <goejendaagh@zonnet.nl>
 *
 * Copyright (C) 2010 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "extension/extension.h"
#include <2geom/affine.h>
#include <stack>

class SPItem;
class SPRoot;
class SPGroup;
class SPUse;
class SPText;
class SPFlowtext;

namespace Inkscape {
namespace Extension {
namespace Internal {

bool latex_render_document_text_to_file(SPDocument *doc, gchar const *filename,
                                        const gchar * const exportId, bool exportDrawing, bool exportCanvas, float bleedmargin_px,
                                        bool pdflatex);

class LaTeXTextRenderer {
public:
    LaTeXTextRenderer(bool pdflatex);
    virtual ~LaTeXTextRenderer();

    bool setTargetFile(gchar const *filename);

    /** Initializes the LaTeXTextRenderer according to the specified
    SPDocument. Important to set the boundingbox to the pdf boundingbox */
    bool setupDocument(SPDocument *doc, bool pageBoundingBox, float bleedmargin_px, SPItem *base);

    /** Traverses the object tree and invokes the render methods. */
    void renderItem(SPItem *item);

protected:
    enum LaTeXOmitTextPageState {
        EMPTY,
        GRAPHIC_ON_TOP,
        NEW_PAGE_ON_GRAPHIC
    };

    FILE * _stream;
    gchar * _filename;

    bool _pdflatex; /** true if outputting for pdfLaTeX*/

    LaTeXOmitTextPageState _omittext_state;
    gulong _omittext_page;

    void push_transform(Geom::Affine const &transform);
    Geom::Affine const & transform();
    void pop_transform();
    std::stack<Geom::Affine> _transform_stack;

    void writePreamble();
    void writePostamble();

    void writeGraphicPage();

    void sp_item_invoke_render(SPItem *item);
    void sp_root_render(SPRoot *item);
    void sp_group_render(SPGroup *group);
    void sp_use_render(SPUse *use);
    void sp_text_render(SPText *text);
    void sp_flowtext_render(SPFlowtext *flowtext);
};

}  /* namespace Internal */
}  /* namespace Extension */
}  /* namespace Inkscape */

#endif /* !EXTENSION_INTERNAL_LATEX_TEXT_RENDERER_H_SEEN */

/*
  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 :