blob: 68841ef54ecf61efabb43b9339985b12bac0d3aa (
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
99
100
101
102
103
104
105
106
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* An internal raster export which passes the generated PNG output
* to an external file. In the future this module could host more of
* the PNG generation code that isn't needed for other raster export options.
*
* Authors:
* Martin Owens <doctormo@geek-2.com>
*
* Copyright (C) 2021 Authors
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "png-output.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <glibmm.h>
#include <giomm.h>
#include "clear-n_.h"
namespace Inkscape {
namespace Extension {
namespace Internal {
void PngOutput::export_raster(Inkscape::Extension::Output * /*module*/,
const SPDocument * /*doc*/, std::string const &png_file, gchar const *filename)
{
// We want to move the png file to the new location
Glib::RefPtr<Gio::File> input_fn = Gio::File::create_for_path(png_file);
Glib::RefPtr<Gio::File> output_fn = Gio::File::create_for_path(filename);
try {
// This file must be copied because the permissions must be created
// based on it's target location and not the temp directory.
input_fn->copy(output_fn, Gio::FILE_COPY_OVERWRITE | Gio::FILE_COPY_TARGET_DEFAULT_PERMS);
}
catch (const Gio::Error& e) {
std::cerr << "Moving resource " << png_file
<< " to " << filename
<< " failed: " << e.what().raw() << std::endl;
}
}
void PngOutput::init()
{
// clang-format off
Inkscape::Extension::build_from_mem(
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
"<name>" N_("Portable Network Graphic") "</name>\n"
"<id>" SP_MODULE_KEY_RASTER_PNG "</id>\n"
"<param name='png_interlacing' type='bool' gui-text='" N_("Interlacing") "'>false</param>"
"<param name='png_bitdepth' type='optiongroup' appearance='combo' gui-text='" N_("Bit Depth") "'>"
"<option value='99'>" N_("RGBA 8") "</option>" // First because it's the default option
"<option value='100'>" N_("RGBA 16") "</option>"
"<option value='67'>" N_("GrayAlpha 8") "</option>"
"<option value='68'>" N_("GrayAlpha 16") "</option>"
"<option value='35'>" N_("RGB 8") "</option>"
"<option value='36'>" N_("RGB 16") "</option>"
"<option value='0'>" N_("Gray 1") "</option>"
"<option value='1'>" N_("Gray 2") "</option>"
"<option value='2'>" N_("Gray 4") "</option>"
"<option value='3'>" N_("Gray 8") "</option>"
"<option value='4'>" N_("Gray 16") "</option>"
"</param>"
"<param name='png_compression' type='optiongroup' appearance='combo' gui-text='" N_("Compression") "'>"
"<option value='0'>" N_("0 - No Compression") "</option>"
"<option value='1'>" N_("1 - Best Speed") "</option>"
"<option value='2'>2</option>"
"<option value='3'>3</option>"
"<option value='4'>4</option>"
"<option value='5'>5</option>"
"<option value='6'>" N_("6 - Default Compression") "</option>" // First because it's default (and broken)
"<option value='7'>7</option>"
"<option value='8'>8</option>"
"<option value='9'>" N_("9 - Best Compression") "</option>"
"</param>"
"<param name='png_phys' gui-text='" N_("pHYs DPI") "' type='float' min='0.0' max='100000.0'>0.0</param>"
"<param name='png_antialias' gui-text='" N_("Antialias") "' type='int' min='0' max='3'>2</param>"
"<output raster=\"true\">\n"
"<extension>.png</extension>\n"
"<mimetype>image/png</mimetype>\n"
"<filetypename>" N_("Portable Network Graphic (*.png)") "</filetypename>\n"
"<filetypetooltip>" N_("Default raster graphic export") "</filetypetooltip>\n"
"</output>\n"
"</inkscape-extension>",
new PngOutput());
// clang-format on
}
} // 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 :
|