Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
emf-inout.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Ulf Erikson <ulferikson@users.sf.net>
7 * David Mathog
8 *
9 * Copyright (C) 2006-2008 Authors
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13#ifndef SEEN_EXTENSION_INTERNAL_EMF_H
14#define SEEN_EXTENSION_INTERNAL_EMF_H
15
18#include <3rdparty/libuemf/uemf_endian.h> // for U_emf_record_sizeok()
19#include "extension/internal/metafile-inout.h" // picks up PNG
21#include "style.h"
22#include "text_reassemble.h"
23
25
26#define DIRTY_NONE 0x00
27#define DIRTY_TEXT 0x01
28#define DIRTY_FILL 0x02
29#define DIRTY_STROKE 0x04
30
31struct EMF_OBJECT {
32 int type = 0;
33 int level = 0;
34 char *lpEMFR = nullptr;
35};
36
38 int size = 0; // number of slots allocated in strings
39 int count = 0; // number of slots used in strings
40 char **strings = nullptr; // place to store strings
41};
42
44{
46 // SPStyle: class with constructor
47 font_name(nullptr),
48 clip_id(0),
50 fill_set(false), fill_mode(0), fill_idx(0), fill_recidx(0),
51 dirty(0),
52 // sizeWnd, sizeView, winorg, vieworg,
53 ScaleInX(0), ScaleInY(0),
54 ScaleOutX(0), ScaleOutY(0),
55 bkMode(U_TRANSPARENT),
56 // bkColor, textColor
57 textAlign(0)
58 // worldTransform, cur
59 {
60 sizeWnd = sizel_set( 0.0, 0.0 );
61 sizeView = sizel_set( 0.0, 0.0 );
62 winorg = point32_set( 0.0, 0.0 );
63 vieworg = point32_set( 0.0, 0.0 );
64 bkColor = U_RGB(255, 255, 255); // default foreground color (white)
65 textColor = U_RGB(0, 0, 0); // default foreground color (black)
66 worldTransform.eM11 = 1.0;
67 worldTransform.eM12 = 0.0;
68 worldTransform.eM21 = 0.0;
69 worldTransform.eM22 = 1.0;
70 worldTransform.eDx = 0.0;
71 worldTransform.eDy = 0.0;
72 cur = point32_set( 0, 0 );
73 }
74
76 char *font_name;
77 int clip_id; // 0 if none, else 1 + index into clips
79 int stroke_mode; // enumeration from drawmode, not used if fill_set is not True
80 int stroke_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill
81 int stroke_recidx;// record used to regenerate hatch when it needs to be redone due to bkmode, textmode, etc. change
83 int fill_mode; // enumeration from drawmode, not used if fill_set is not True
84 int fill_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill
85 int fill_recidx; // record used to regenerate hatch when it needs to be redone due to bkmode, textmode, etc. change
86 int dirty; // holds the dirty bits for text, stroke, fill
93 uint16_t bkMode;
96 uint32_t textAlign;
99};
100
101inline constexpr auto EMF_MAX_DC = 128;
102
104{
106 // dc: array, structure w/ constructor
107 level(0),
108 E2IdirY(1.0),
109 D2PscaleX(1.0), D2PscaleY(1.0),
110 MM100InX(0), MM100InY(0),
111 PixelsInX(0), PixelsInY(0),
112 PixelsOutX(0), PixelsOutY(0),
115 mask(0),
116 arcdir(U_AD_COUNTERCLOCKWISE),
117 dwRop2(U_R2_COPYPEN), dwRop3(0),
118 MMX(0),MMY(0),
119 drawtype(0),
120 pDesc(nullptr),
121 // hatches, images, gradients, struct w/ constructor
122 tri(nullptr),
123 n_obj(0)
124 // emf_obj;
125 {}
126
127 Glib::ustring outsvg;
128 Glib::ustring path;
129 Glib::ustring outdef;
130 Glib::ustring defs;
131
132 EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]; // FIXME: This should be dynamic..
133 int level;
134
135 double E2IdirY; // EMF Y direction relative to Inkscape Y direction. Will be negative for MM_LOMETRIC etc.
136 double D2PscaleX,D2PscaleY; // EMF device to Inkscape Page scale.
137 float MM100InX, MM100InY; // size of the drawing in hundredths of a millimeter
138 float PixelsInX, PixelsInY; // size of the drawing, in EMF device pixels
139 float PixelsOutX, PixelsOutY; // size of the drawing, in Inkscape pixels
140 double ulCornerInX,ulCornerInY; // Upper left corner, from header rclBounds, in logical units
141 double ulCornerOutX,ulCornerOutY; // Upper left corner, in Inkscape pixels
142 uint32_t mask; // Draw properties
143 int arcdir; //U_AD_COUNTERCLOCKWISE 1 or U_AD_CLOCKWISE 2
144
145 uint32_t dwRop2; // Binary raster operation, 0 if none (use brush/pen unmolested)
146 uint32_t dwRop3; // Ternary raster operation, 0 if none (use brush/pen unmolested)
147
148 float MMX;
149 float MMY;
150
151 unsigned int drawtype; // one of 0 or U_EMR_FILLPATH, U_EMR_STROKEPATH, U_EMR_STROKEANDFILLPATH
152 char *pDesc;
153 // both of these end up in <defs> under the names shown here. These structures allow duplicates to be avoided.
154 EMF_STRINGS hatches; // hold pattern names, all like EMFhatch#_$$$$$$ where # is the EMF hatch code and $$$$$$ is the color
155 EMF_STRINGS images; // hold images, all like Image#, where # is the slot the image lives.
156 EMF_STRINGS gradients; // hold gradient names, all like EMF[HV]_$$$$$$_$$$$$$ where $$$$$$ are the colors
157 EMF_STRINGS clips; // hold clipping paths, referred to be the slot where the clipping path lives
158 TR_INFO *tri; // Text Reassembly data structure
159
160 int n_obj;
162};
164
165class Emf : public Metafile
166{
167public:
168 bool check(Inkscape::Extension::Extension *module) override; //Can this module load (always yes for now)
169
170 void save(Inkscape::Extension::Output *mod, // Save the given document to the given filename
171 SPDocument *doc,
172 char const *filename) override;
173
174 std::unique_ptr<SPDocument> open(Inkscape::Extension::Input *mod, char const *uri, bool is_importing) override;
175
176 static void init();
177
178protected:
179 static void print_document_to_file(SPDocument *doc, const gchar *filename);
180 static double current_scale(PEMF_CALLBACK_DATA d);
181 static std::string current_matrix(PEMF_CALLBACK_DATA d, double x, double y, int useoffset);
182 static double current_rotation(PEMF_CALLBACK_DATA d);
183 static void enlarge_hatches(PEMF_CALLBACK_DATA d);
184 static int in_hatches(PEMF_CALLBACK_DATA d, char *test);
185 static uint32_t add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hatchColor);
186 static void enlarge_images(PEMF_CALLBACK_DATA d);
187 static int in_images(PEMF_CALLBACK_DATA d, const char *test);
188 static uint32_t add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint32_t cbBmi,
189 uint32_t iUsage, uint32_t offBits, uint32_t offBmi);
191 static int in_gradients(PEMF_CALLBACK_DATA d, const char *test);
192 static uint32_t add_gradient(PEMF_CALLBACK_DATA d, uint32_t gradientType, U_TRIVERTEX tv1, U_TRIVERTEX tv2);
193
194 static void enlarge_clips(PEMF_CALLBACK_DATA d);
195 static int in_clips(PEMF_CALLBACK_DATA d, const char *test);
196 static void add_clips(PEMF_CALLBACK_DATA d, const char *clippath, unsigned int logic);
197
198 static void output_style(PEMF_CALLBACK_DATA d, int iType);
199 static double _pix_x_to_point(PEMF_CALLBACK_DATA d, double px);
200 static double _pix_y_to_point(PEMF_CALLBACK_DATA d, double py);
201 static double pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py);
202 static double pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py);
203 static double pix_to_abs_size(PEMF_CALLBACK_DATA d, double px);
204 static void snap_to_faraway_pair(double *x, double *y);
205 static std::string pix_to_xy(PEMF_CALLBACK_DATA d, double x, double y);
206 static void select_pen(PEMF_CALLBACK_DATA d, int index);
207 static void select_extpen(PEMF_CALLBACK_DATA d, int index);
208 static void select_brush(PEMF_CALLBACK_DATA d, int index);
209 static void select_font(PEMF_CALLBACK_DATA d, int index);
210 static void delete_object(PEMF_CALLBACK_DATA d, int index);
211 static void insert_object(PEMF_CALLBACK_DATA d, int index, int type, PU_ENHMETARECORD pObj);
212 static int AI_hack(PU_EMRHEADER pEmr);
213 static uint32_t *unknown_chars(size_t count);
214 static void common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr,
215 double dx, double dy, double dw, double dh, int sx, int sy, int sw, int sh,
216 uint32_t iUsage, uint32_t offBits, uint32_t cbBits, uint32_t offBmi, uint32_t cbBmi);
217 static int myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DATA d);
218 static void free_emf_strings(EMF_STRINGS name);
219
220};
221
222} // namespace Inkscape::Extension::Internal
223
224#endif /* EXTENSION_INTERNAL_EMF_H */
225
226/*
227 Local Variables:
228 mode:c++
229 c-file-style:"stroustrup"
230 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
231 indent-tabs-mode:nil
232 fill-column:99
233 End:
234*/
235// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
int test()
Definition 2junctions.cpp:5
The object that is the basis for the Extension system.
Definition extension.h:133
static void enlarge_clips(PEMF_CALLBACK_DATA d)
static void free_emf_strings(EMF_STRINGS name)
static int myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DATA d)
static int in_clips(PEMF_CALLBACK_DATA d, const char *test)
static void add_clips(PEMF_CALLBACK_DATA d, const char *clippath, unsigned int logic)
static double _pix_y_to_point(PEMF_CALLBACK_DATA d, double py)
static void select_pen(PEMF_CALLBACK_DATA d, int index)
static uint32_t add_gradient(PEMF_CALLBACK_DATA d, uint32_t gradientType, U_TRIVERTEX tv1, U_TRIVERTEX tv2)
static double current_scale(PEMF_CALLBACK_DATA d)
static uint32_t add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint32_t cbBmi, uint32_t iUsage, uint32_t offBits, uint32_t offBmi)
static void delete_object(PEMF_CALLBACK_DATA d, int index)
static void enlarge_hatches(PEMF_CALLBACK_DATA d)
static double pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py)
static std::string current_matrix(PEMF_CALLBACK_DATA d, double x, double y, int useoffset)
static int AI_hack(PU_EMRHEADER pEmr)
static void enlarge_images(PEMF_CALLBACK_DATA d)
static uint32_t add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hatchColor)
bool check(Inkscape::Extension::Extension *module) override
Verify any dependencies.
Definition emf-inout.cpp:64
static void insert_object(PEMF_CALLBACK_DATA d, int index, int type, PU_ENHMETARECORD pObj)
static void select_font(PEMF_CALLBACK_DATA d, int index)
static std::string pix_to_xy(PEMF_CALLBACK_DATA d, double x, double y)
static void print_document_to_file(SPDocument *doc, const gchar *filename)
Definition emf-inout.cpp:70
static void enlarge_gradients(PEMF_CALLBACK_DATA d)
static void snap_to_faraway_pair(double *x, double *y)
std::unique_ptr< SPDocument > open(Inkscape::Extension::Input *mod, char const *uri, bool is_importing) override
Open a file.
static void output_style(PEMF_CALLBACK_DATA d, int iType)
static uint32_t * unknown_chars(size_t count)
static int in_hatches(PEMF_CALLBACK_DATA d, char *test)
static void select_extpen(PEMF_CALLBACK_DATA d, int index)
static double current_rotation(PEMF_CALLBACK_DATA d)
static double pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py)
static double _pix_x_to_point(PEMF_CALLBACK_DATA d, double px)
static double pix_to_abs_size(PEMF_CALLBACK_DATA d, double px)
void save(Inkscape::Extension::Output *mod, SPDocument *doc, char const *filename) override
static int in_gradients(PEMF_CALLBACK_DATA d, const char *test)
static void common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr, double dx, double dy, double dw, double dh, int sx, int sy, int sw, int sh, uint32_t iUsage, uint32_t offBits, uint32_t cbBits, uint32_t offBmi, uint32_t cbBmi)
static int in_images(PEMF_CALLBACK_DATA d, const char *test)
static void select_brush(PEMF_CALLBACK_DATA d, int index)
Typed SVG document implementation.
Definition document.h:101
An SVG style object.
Definition style.h:45
Metafile input - common functions.
EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]
Definition emf-inout.h:132
Information for the entire text reassembly system.
WMF manual 2.2.2.8.
Definition uemf.h:474
The first U_ENHMETARECORD record in the metafile.
Definition uemf.h:2127
General form of an EMF record.
Definition uemf.h:2071
WMF manual 2.2.2.15.
Definition uemf.h:546
WMF manual 2.2.2.22.
Definition uemf.h:608
For GRADIENT_[TRIANGLE|U_RECT].
Definition uemf.h:1766
For U_EMR[FILLRGN|STRETCHBLT|MASKBLT|PLGBLT] xformSrc field.
Definition uemf.h:2011
U_FLOAT eDx
X offset in logical units.
Definition uemf.h:2016
U_FLOAT eM12
Matrix element M12.
Definition uemf.h:2013
U_FLOAT eM21
Matrix element M21.
Definition uemf.h:2014
U_FLOAT eM11
Matrix element M11.
Definition uemf.h:2012
U_FLOAT eDy
Y offset in logical units.
Definition uemf.h:2017
U_FLOAT eM22
Matrix element M22.
Definition uemf.h:2015
SPStyle - a style object for SPItem objects.
int index
text_reassemble.h from libTERE
Glib::ustring name
Definition toolbars.cpp:55
Structures, definitions, and function prototypes for EMF files.
Defintions and prototype for function for converting EMF records between Big Endian and Little Endian...
Defintions and prototype for function for converting EMF records between Big Endian and Little Endian...