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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSVGExporter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkSVGExporter
* @brief Exports vtkContext2D scenes to SVG.
*
* This exporter draws context2D scenes into a SVG file.
*
* Limitations:
* - The Nearest/Linear texture properties are ignored, since SVG doesn't
* provide any reliable control over interpolation.
* - Embedded fonts are experimental and poorly tested. Viewer support is
* lacking at the time of writing, hence the feature is largely useless. By
* default, fonts are not embedded since they're basically useless bloat.
* (this option is not exposed in vtkSVGExporter).
* - TextAsPath is enabled by default, since viewers differ wildly in how they
* handle text objects (eg. Inkscape renders at expected size, but webkit is
* way too big).
* - Pattern fills and markers are not shown on some viewers, e.g. KDE's okular
* (Webkit seems to work, though).
* - Clipping seems to be broken in most viewers. Webkit is buggy and forces the
* clip coordinates to objectBoundingBox, even when explicitly set to
* userSpaceOnUse.
* - Many viewers anti-alias the output, leaving thin outlines around the
* triangles that make up larger polygons. This is a viewer issue and there
* not much we can do about it from the VTK side of things (and most viewers
* don't seem to have an antialiasing toggle, either...).
*
* If ActiveRenderer is specified then it exports contents of
* ActiveRenderer. Otherwise it exports contents of all renderers.
*/
#ifndef vtkSVGExporter_h
#define vtkSVGExporter_h
#include "vtkExporter.h"
#include "vtkIOExportModule.h" // For export macro
VTK_ABI_NAMESPACE_BEGIN
class vtkContextActor;
class vtkRenderer;
class vtkSVGContextDevice2D;
class vtkXMLDataElement;
class VTKIOEXPORT_EXPORT vtkSVGExporter : public vtkExporter
{
public:
static vtkSVGExporter* New();
vtkTypeMacro(vtkSVGExporter, vtkExporter);
void PrintSelf(ostream& os, vtkIndent indent) override;
/** The title of the exported document. @{ */
vtkSetStringMacro(Title);
vtkGetStringMacro(Title);
/** @} */
/** A description of the exported document. @{ */
vtkSetStringMacro(Description);
vtkGetStringMacro(Description);
/** @} */
/** The name of the exported file. @{ */
vtkSetFilePathMacro(FileName);
vtkGetFilePathMacro(FileName);
/** @} */
/**
* If true, draw all text as path objects rather than text objects. Enabling
* this option will:
*
* - Improve portability (text will look exactly the same everywhere).
* - Increase file size (text objects are much more compact than paths).
* - Prevent text from being easily edited (text metadata is lost).
*
* Note that some text (e.g. MathText) is always rendered as a path.
*
* The default is true, as many browsers and SVG viewers render text
* inconsistently.
*
* @{
*/
vtkSetMacro(TextAsPath, bool);
vtkGetMacro(TextAsPath, bool);
vtkBooleanMacro(TextAsPath, bool);
/**@}*/
/**
* If true, the background will be drawn into the output document. Default
* is true.
* @{
*/
vtkSetMacro(DrawBackground, bool);
vtkGetMacro(DrawBackground, bool);
vtkBooleanMacro(DrawBackground, bool);
/**@}*/
/**
* Set the threshold for subdividing gradient-shaded polygons/line. Default
* value is 1, and lower values yield higher quality and larger files. Larger
* values will reduce the number of primitives, but will decrease quality.
*
* A triangle / line will not be subdivided further if all of it's vertices
* satisfy the equation:
*
* |v1 - v2|^2 < thresh
*
* e.g. the squared norm of the vector between any verts must be greater than
* the threshold for subdivision to occur.
*
* @{
*/
vtkSetMacro(SubdivisionThreshold, float);
vtkGetMacro(SubdivisionThreshold, float);
/**@}*/
protected:
vtkSVGExporter();
~vtkSVGExporter() override;
void WriteData() override;
void WriteSVG();
void PrepareDocument();
void RenderContextActors();
void RenderBackground(vtkRenderer* ren);
void RenderContextActor(vtkContextActor* actor, vtkRenderer* renderer);
char* Title;
char* Description;
char* FileName;
vtkSVGContextDevice2D* Device;
vtkXMLDataElement* RootNode;
vtkXMLDataElement* PageNode;
vtkXMLDataElement* DefinitionNode;
float SubdivisionThreshold;
bool DrawBackground;
bool TextAsPath;
private:
vtkSVGExporter(const vtkSVGExporter&) = delete;
void operator=(const vtkSVGExporter&) = delete;
};
VTK_ABI_NAMESPACE_END
#endif // vtkSVGExporter_h
|