emf-print.cpp revision 0a2eb3db73cd91971ada6cd48256c2592ed29f54
/** @file
* @brief Enhanced Metafile printing
*//*
* Authors:
* Ulf Erikson <ulferikson@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
* David Mathog
*
* Copyright (C) 2006-2009 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
* References:
* - How to Create & Play Enhanced Metafiles in Win32
* - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
* - Metafile Functions
* - Metafile Structures
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <glibmm/miscutils.h>
#include <libuemf/symbol_convert.h>
#include <sp-clippath.h>
#include "helper/geom-curves.h"
#include "sp-item.h"
#include "style.h"
#include "inkscape-version.h"
#include "sp-root.h"
#include "document.h"
#include "path-prefix.h"
#include "sp-pattern.h"
#include "sp-image.h"
#include "sp-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-linear-gradient.h"
#include "display/cairo-utils.h"
#include "sp-shape.h"
#include "splivarot.h" // pieces for union on shapes
#include "2geom/svg-path-parser.h" // to get from SVG text to Geom::Path
#include "display/canvas-bpath.h" // for SPWindRule
#include "display/cairo-utils.h" // for Inkscape::Pixbuf::PF_CAIRO
#include "emf-print.h"
namespace Inkscape {
namespace Extension {
namespace Internal {
#define PXPERMETER 2835
/* globals */
static double PX2WORLD;
static bool FixPPTCharPos, FixPPTDashLine, FixPPTGrad2Polys, FixPPTLinGrad, FixPPTPatternAsHatch, FixImageRot;
void PrintEmf::smuggle_adxkyrtl_out(const char *string, uint32_t **adx, double *ky, int *rtl, int *ndx, float scale)
{
float fdx;
int i;
if (!*ndx) {
return; // this could happen with an empty string
}
cptr += 7;
if (!ladx) {
g_message("Out of memory");
}
}
cptr++; // skip 2nd fake terminator
}
{
// all of the class variables are initialized elsewhere, many in PrintEmf::Begin,
}
{
return TRUE;
}
{
char *rec;
// Typically PX2WORLD is 1200/90, using inkscape's default dpi
// width and height in px
// initialize a few global variables
if (nv) {
char *p2;
if (*p2) {
lc = 0;
}
}
bool pageBoundingBox;
if (pageBoundingBox) {
} else {
if (bbox) {
d = *bbox;
}
}
// dwInchesX x dwInchesY in micrometer units, 1200 dpi/25.4 -> dpmm
(void) drawing_size((int) ceil(dwInchesX * 25.4), (int) ceil(dwInchesY * 25.4),1200.0/25.4, &rclBounds, &rclFrame);
// set up the reference device as 100 X A4 horizontal, (1200 dpi/25.4 -> dpmm). Extra digits maintain dpi better in EMF
int MMX = 216;
int MMY = 279;
// set up the description: (version string)0(file)00
char buff[1024];
if (p) {
p++;
} else {
p = ansi_uri;
}
// construct the EMRHEADER record and append it to the EMF in memory
g_error("Fatal programming error in PrintEmf::begin at EMRHEADER");
}
// Simplest mapping mode, supply all coordinates in pixels
g_error("Fatal programming error in PrintEmf::begin at EMRSETMAPMODE");
}
// In earlier versions this was used to scale from inkscape's dpi of 90 to
// the files 1200 dpi, taking into account PX2WORLD which was 20. Now PX2WORLD
// is set so that this matrix is unitary. The usual value of PX2WORLD is 1200/90,
// but might be different if the internal dpi is changed.
worldTransform.eDx = 0;
worldTransform.eDy = 0;
g_error("Fatal programming error in PrintEmf::begin at EMRMODIFYWORLDTRANSFORM");
}
if (1) {
g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1");
}
snprintf(buff, sizeof(buff) - 1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, Inkscape::Util::Quantity::convert(dwInchesX, "in", "mm"), Inkscape::Util::Quantity::convert(dwInchesY, "in", "mm"));
g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1");
}
}
/* set some parameters, else the program that reads the EMF may default to other values */
g_error("Fatal programming error in PrintEmf::begin at U_EMRSETBKMODE_set");
}
g_error("Fatal programming error in PrintEmf::begin at U_EMRSETPOLYFILLMODE_set");
}
// Text alignment: (only changed if RTL text is encountered )
// - (x,y) coordinates received by this filter are those of the point where the text
// actually starts, and already takes into account the text object's alignment;
// - for this reason, the EMF text alignment must always be TA_BASELINE|TA_LEFT.
g_error("Fatal programming error in PrintEmf::begin at U_EMRSETTEXTALIGN_set");
}
g_error("Fatal programming error in PrintEmf::begin at U_EMRSETTEXTCOLOR_set");
}
g_error("Fatal programming error in PrintEmf::begin at U_EMRSETROP2_set");
}
/* miterlimit is set with eah pen, so no need to check for it changes as in WMF */
return 0;
}
{
char *rec;
if (!et) {
return 0;
}
// earlier versions had flush of fill here, but it never executed and was removed
g_error("Fatal programming error in PrintEmf::finish");
}
return 0;
}
const char * /*comment*/)
{
if (!et) {
return 0;
}
// earlier versions had flush of fill here, but it never executed and was removed
return 0;
}
// fcolor is defined when gradients are being expanded, it is the color of one stripe or ring.
{
float rgb[3];
char *rec;
int hatchType;
if (!et) {
return 0;
}
// set a default fill in case we can't figure out a better way to do it
fmode = U_ALTERNATE;
if (fcolor) {
hatchColor = *fcolor;
} else {
hatchColor = U_RGB(0, 0, 0);
}
#if 0
// opacity not supported by EMF
if (opacity <= 0.0) {
}
#endif
fmode = style->fill_rule.computed == 0 ? U_WINDING : (style->fill_rule.computed == 2 ? U_ALTERNATE : U_ALTERNATE);
if (pixbuf) {
} else { // pattern
}
}
if (FixPPTPatternAsHatch) {
}
}
// currently we do not do anything with gradients, the code below just sets the color to the average of the stops
if (SP_IS_LINEARGRADIENT(paintserver)) {
} else if (SP_IS_RADIALGRADIENT(paintserver)) {
} else {
// default fill
}
if (rg) {
if (FixPPTGrad2Polys) {
} else {
}
} else if (lg) {
if (FixPPTGrad2Polys || FixPPTLinGrad) {
} else {
}
}
}
} else { // if (!style)
// default fill
}
switch (fill_mode) {
case DRAW_LINEAR_GRADIENT: // fill with average color unless gradients are converted to slices
case DRAW_RADIAL_GRADIENT: // ditto
case DRAW_PAINT:
case DRAW_PATTERN:
// SVG text has no background attribute, so OPAQUE mode ALWAYS cancels after the next draw, otherwise it would mess up future text output.
if (usebk) {
g_error("Fatal programming error in PrintEmf::create_brush at U_EMRSETBKCOLOR_set");
}
g_error("Fatal programming error in PrintEmf::create_brush at U_EMRSETBKMODE_set");
}
}
g_error("Fatal programming error in PrintEmf::create_brush at createbrushindirect_set");
}
break;
case DRAW_IMAGE:
char *px;
char *rgba_px;
int numCt;
// pixbuf can be either PF_CAIRO or PF_GDK, and these have R and B bytes swapped
Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0);
g_error("Fatal programming error in PrintEmf::create_brush at createdibpatternbrushpt_set");
}
break;
}
g_error("Fatal programming error in PrintEmf::create_brush at selectobject_set");
}
if (fmode != hpolyfillmode) {
g_error("Fatal programming error in PrintEmf::create_brush at U_EMRSETPOLYdrawmode_set");
}
}
return 0;
}
void PrintEmf::destroy_brush()
{
char *rec;
// before an object may be safely deleted it must no longer be selected
// select in a stock object to deselect this one, the stock object should
// never be used because we always select in a new one before drawing anythingrestore previous brush, necessary??? Would using a default stock object not work?
g_error("Fatal programming error in PrintEmf::destroy_brush at selectobject_set");
}
if (hbrush) {
g_error("Fatal programming error in PrintEmf::destroy_brush");
}
hbrush = 0;
}
}
{
U_NUM_STYLEENTRY n_dash = 0;
int linestyle = U_PS_SOLID;
int linecap = 0;
int linejoin = 0;
int hatchType;
char *rgba_px;
int numCt = 0;
if (!et) {
return 0;
}
// set a default stroke in case we can't figure out a better way to do it
hatchColor = U_RGB(0, 0, 0);
if (style) {
float rgb[3];
if (pixbuf) {
// pixbuf can be either PF_CAIRO or PF_GDK, and these have R and B bytes swapped
Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0);
} else { // pattern
if (usebk) { // OPAQUE mode ALWAYS cancels after the next draw, otherwise it would mess up future text output.
g_error("Fatal programming error in PrintEmf::create_pen at U_EMRSETBKCOLOR_set");
}
g_error("Fatal programming error in PrintEmf::create_pen at U_EMRSETBKMODE_set");
}
}
}
}
if (FixPPTPatternAsHatch) {
}
}
// currently we do not do anything with gradients, the code below has no net effect.
if (SP_IS_LINEARGRADIENT(paintserver)) {
if (lg->gradientTransform_set) {
}
} else if (SP_IS_RADIALGRADIENT(paintserver)) {
yhandle_point += c;
xhandle_point += c;
if (rg->gradientTransform_set) {
c = c * rg->gradientTransform;
}
} else {
// default fill
}
} else if (style->stroke.isColor()) { // test last, always seems to be set, even for other types above
} else {
// default fill
}
using Geom::X;
using Geom::Y;
return 0; //if width is 0 do not (reset) the pen, it should already be NULL_PEN
}
}
}
if (FixPPTDashLine) { // will break up line into many smaller lines. Override gradient if that was set, cannot do both.
} else {
unsigned i = 0;
}
i++;
}
if (linestyle == U_PS_USERSTYLE) {
for (i = 0; i < n_dash; i++) {
}
}
}
}
elp = extlogpen_set(
dash);
} else { // if (!style)
linejoin = 0;
elp = extlogpen_set(
1,
U_RGB(0, 0, 0),
0,
NULL);
}
g_error("Fatal programming error in PrintEmf::create_pen at extcreatepen_set");
}
if (Bmi) {
}
if (px) {
}
g_error("Fatal programming error in PrintEmf::create_pen at selectobject_set");
}
if (linejoin == U_PS_JOIN_MITER) {
if (miterlimit < 1) {
miterlimit = 1;
}
g_error("Fatal programming error in PrintEmf::create_pen at U_EMRSETMITERLIMIT_set");
}
}
if (n_dash) {
delete[] dash;
}
return 0;
}
// set the current pen to the stock object NULL_PEN and then delete the defined pen object, if there is one.
void PrintEmf::destroy_pen()
{
// before an object may be safely deleted it must no longer be selected
// select in a stock object to deselect this one, the stock object should
// never be used because we always select in a new one before drawing anythingrestore previous brush, necessary??? Would using a default stock object not work?
g_error("Fatal programming error in PrintEmf::destroy_pen at selectobject_set");
}
if (hpen) {
g_error("Fatal programming error in PrintEmf::destroy_pen");
}
hpen = 0;
}
}
/* Return a Path consisting of just the corner points of the single path in a a PathVector. If the
PathVector has more than one path, or that one path is open, or any of its segments are curved, then the
returned PathVector is . If the input path is already just straight lines and vertices the output will be the
same as the sole path in the input. */
{
++pit2;
*vertices = 0;
if (!is_straight_curve(*cit)) {
*vertices = 0;
return(bad);
}
continue;
}
// P1 is the center point of a turn of some angle
if(!*vertices){
}
*vertices += 1;
}
return(output);
}
/* Returns the simplified PathVector (no matter what).
Sets is_rect if it is a rectangle.
Sets angle that will rotate side closest to horizontal onto horizontal.
*/
{
int vertices;
*is_rect = false;
int vertex_count=0;
/* Get the ends of the LAST line segment.
Find minimum rotation to align rectangle with X,Y axes. (Very degenerate if it is rotated 45 degrees.) */
}
}
/* For increased numerical stability, snap the angle to the nearest 1/100th of a degree. */
// P1 is center of a turn that is not 90 degrees. Limit comes from cos(89.9) = .001745
vertex_count++;
}
if(vertex_count == 4){
*is_rect=true;
}
}
return(pR);
}
/* Compare a vector with a rectangle's orientation (angle needed to rotate side(s)
closest to horizontal to exactly horizontal) and return:
0 none of the following
1 parallel to horizontal
2 parallel to vertical
3 antiparallel to horizontal
4 antiparallel to vertical
*/
int stat = 0;
Geom::Point v2 = Geom::Point(1,0) * Geom::Rotate(-angle); // unit horizontal side (sign change because Y increases DOWN)
if(!stat){
}
return(stat);
}
/* retrieve the point at the indicated corner:
0 UL (and default)
1 UR
2 LR
3 LL
Needed because the start can be any point, and the direction could run either
clockwise or counterclockwise. This should work even if the corners of the rectangle
are slightly displaced.
*/
}
int LR; // 1 if Left, 0 if Right
int UL; // 1 if Lower, 0 if Upper (as viewed on screen, y coordinates increase downwards)
switch(corner){
case 1: //UR
LR = 0;
UL = 0;
break;
case 2: //LR
LR = 0;
UL = 1;
break;
case 3: //LL
LR = 1;
UL = 1;
break;
default: //UL
LR = 1;
UL = 0;
break;
}
Geom::Point v1 = Geom::Point(1,0) * Geom::Rotate(-angle); // unit horizontal side (sign change because Y increases DOWN)
Geom::Point v2 = Geom::Point(0,1) * Geom::Rotate(-angle); // unit vertical side (sign change because Y increases DOWN)
}
return(P1);
}
using Geom::X;
using Geom::Y;
return(tv);
}
/* Examine clip. If there is a (new) one then apply it. If there is one and it is the
same as the preceding one, leave the preceding one active. If style is NULL
terminate the current clip, if any, and return.
*/
char *rec;
if(!style){
if(scpActive){ // clear the existing clip
g_error("Fatal programming error in PrintEmf::fill at U_EMRRESTOREDC_set");
}
}
} else {
/* The current implementation converts only one level of clipping. If there were more
clips further up the stack they should be combined with the pathvector using "and". Since this
comes up rarely, and would involve a lot of searching (all the way up the stack for every
draw operation), it has not yet been implemented.
Note, to debug this section of code use print statements on sp_svg_write_path(combined_pathvector).
*/
/* find the first clip_ref at object or up the stack. There may not be one. */
while(1) {
if(scp)break;
}
if(scpActive){ // clear the existing clip
g_error("Fatal programming error in PrintEmf::fill at U_EMRRESTOREDC_set");
}
}
if (scp) { // set the new clip
/* because of units and who knows what other transforms that might be applied above we
need the full transform all the way to the root.
*/
while(1) {
if(!scan_item)break;
}
tf *= Geom::Scale(_doc_unit_scale);; // Transform must be in PIXELS, no matter what the document unit is.
/* find the clipping path */
// return sp_group_render(item);
} else if (SP_IS_SHAPE(item)) {
} else { // not implemented
}
}
// the sole purpose of this SAVEDC is to let us clear the clipping region later.
rec = U_EMRSAVEDC_set();
g_error("Fatal programming error in PrintEmf::image at U_EMRSAVEDC_set");
}
g_error("Fatal programming error in PrintEmf::do_clip_if_present at U_EMRSELECTCLIPPATH_set");
}
}
else {
}
} // change or remove clipping
} // scp exists
} // style exists
}
Geom::PathVector PrintEmf::merge_PathVector_with_group(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform)
{
if(!SP_IS_GROUP(item))return(new_combined_pathvector); // sanity test, only a group should be passed in, return empty if something else happens
if (SP_IS_GROUP(item)) {
new_combined_pathvector = merge_PathVector_with_group(new_combined_pathvector, item, tfc); // could be endlessly recursive on a badly formed SVG
} else if (SP_IS_SHAPE(item)) {
} else { // not implemented
}
}
return new_combined_pathvector;
}
Geom::PathVector PrintEmf::merge_PathVector_with_shape(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform)
{
if(!SP_IS_SHAPE(item))return(new_combined_pathvector); // sanity test, only a shape should be passed in, return empty if something else happens
if(combined_pathvector.empty()){
}
else {
new_combined_pathvector = sp_pathvector_boolop(new_vect * tfc, combined_pathvector, bool_op_union , (FillRule) fill_oddEven, (FillRule) fill_oddEven);
}
}
return new_combined_pathvector;
}
{
char *rec;
using Geom::X;
using Geom::Y;
use_fill = true;
use_stroke = false;
fill_transform = tf;
/* native linear gradients are only used if the object is a rectangle AND the gradient is parallel to the sides of the object */
bool is_Rect = false;
double angle;
int rectDir=0;
if(is_Rect){
/* Gradientfill records can only be used if the gradient is parallel to the sides of the rectangle.
That must be checked here so that we can fall back to another form of gradient fill if it is not
the case. */
}
}
if (brush_stat) { // only happens if the style is a gradient
/*
Handle gradients. Uses modified livarot as 2geom boolops is currently broken.
Can handle gradients with multiple stops.
The overlap is needed to avoid antialiasing artifacts when edges are not strictly aligned on pixel boundaries.
There is an inevitable loss of accuracy saving through an EMF file because of the integer coordinate system.
Keep the overlap quite large so that loss of accuracy does not remove an overlap.
*/
destroy_pen(); //this sets the NULL_PEN, otherwise gradient slices may display with boundaries, see longer explanation below
float rgb[3];
double divisions = 128.0;
int nstops;
int istop = 1;
float opa; // opacity at stop
doff = 0.0;
doff_base = 0.0;
double start;
double stop;
/* radial gradient might stop part way through the shape, fill with outer color from there to "infinity".
Do this first so that outer colored ring will overlay it.
*/
pathvc = center_elliptical_hole_as_SVG_PathV(gv.p1, rx * (1.0 - overlap / range), ry * (1.0 - overlap / range), asin(xuv[Y]));
}
pathvc = center_elliptical_ring_as_SVG_PathV(gv.p1, rx * start / range, ry * start / range, rx * stop / range, ry * stop / range, asin(xuv[Y]));
if (doff >= doff_range) {
istop++;
continue; // could happen on a rounding error
}
}
}
if(is_Rect){
int gMode;
/* coordinates: upper left, upper right, and lower right corners of the rectangle.
inkscape transform already applied, but needs to be scaled to EMF coordinates. */
/* The basic rectangle for all of these is placed with its UL corner at 0,0 with a size wRect,hRect.
Actual gradientfill records are either this entire rectangle or slices of it as defined by the stops.
This rectangle has already been transformed by tf (whatever rotation/scale) Inkscape had applied to it.
*/
Geom::Affine tf2 = Geom::Rotate(-angle); // the rectangle may be drawn skewed to the coordinate system
rec = U_EMRSAVEDC_set();
g_error("Fatal programming error in PrintEmf::image at U_EMRSAVEDC_set");
}
g_error("Fatal programming error in PrintEmf::image at EMRMODIFYWORLDTRANSFORM");
}
}
else {
}
}
else {
}
g_error("Fatal programming error in PrintEmf::fill at U_EMRGRADIENTFILL_set");
}
}
g_error("Fatal programming error in PrintEmf::fill at U_EMRRESTOREDC_set");
}
}
else {
double start;
double stop;
/* before lower end of gradient, overlap first slice position */
/* after high end of gradient, overlap last slice position */
}
Geom::PathVector pathvr = sp_pathvector_boolop(pathvc, pathv, bool_op_inters, (FillRule) fill_nonZero, frb);
if (doff >= doff_range) {
istop++;
continue; // could happen on a rounding error
}
}
}
}
} else {
g_error("Fatal programming error in PrintEmf::fill, invalid gradient type detected");
}
use_fill = false; // gradients handled, be sure stroke does not use stroke and fill
} else {
/*
Inkscape was not calling create_pen for objects with no border.
This was because it never called stroke() (next method).
PPT, and presumably others, pick whatever they want for the border if it is not specified, so no border can
become a visible border.
To avoid this force the pen to NULL_PEN if we can determine that no pen will be needed after the fill.
*/
destroy_pen(); //this sets the NULL_PEN
}
/* postpone fill in case stroke also required AND all stroke paths closed
Dashes converted to line segments will "open" a closed path.
*/
bool all_closed = true;
all_closed = false;
}
}
}
if (
) {
use_fill = false;
}
}
return 0;
}
{
use_stroke = true;
// use_fill was set in ::fill, if it is needed
return 0;
}
// convert the path, gets its complete length, and then make a new path with parameter length instead of t
Geom::Piecewise<Geom::D2<Geom::SBasis> > tmp_pathpw3; // new (discontinuous) path, composed of dots/dashes
int i = 0; //dash index
double tlength; // length of tmp_pathpw
double elength; // end of gragment
}
// go around the dash array repeatedly until the entire path is consumed (but not beyond).
}
if (slength) {
} else {
}
if (i >= n_dash) {
i = 0;
}
}
} else {
}
use_stroke = false;
use_fill = false;
if (usebk) { // OPAQUE was set, revert to TRANSPARENT
usebk = false;
g_error("Fatal programming error in PrintEmf::stroke at U_EMRSETBKMODE_set");
}
}
return 0;
}
// Draws simple_shapes, those with closed EMR_* primitives, like polygons, rectangles and ellipses.
// These use whatever the current pen/brush are and need not be followed by a FILLPATH or STROKEPATH.
// For other paths it sets a few flags and returns.
{
int nodes = 0;
int moves = 0;
int lines = 0;
int curves = 0;
moves++;
nodes++;
nodes++;
if (is_straight_curve(*cit)) {
lines++;
} else if (&*cit) {
curves++;
}
}
}
if (!nodes) {
return false;
}
int i = 0;
/**
* For all Subpaths in the <path>
*/
using Geom::X;
using Geom::Y;
i = i + 1;
/**
* For all segments in the subpath
*/
if (is_straight_curve(*cit)) {
//Geom::Point p0 = cit->initialPoint();
//p0[X] = (p0[X] * PX2WORLD);
//p0[Y] = (p0[Y] * PX2WORLD);
//int32_t const x0 = (int32_t) round(p0[X]);
//int32_t const y0 = (int32_t) round(p0[Y]);
i = i + 1;
//Geom::Point p0 = points[0];
//p0[X] = (p0[X] * PX2WORLD);
//p0[Y] = (p0[Y] * PX2WORLD);
//int32_t const x0 = (int32_t) round(p0[X]);
//int32_t const y0 = (int32_t) round(p0[Y]);
i = i + 3;
}
}
}
bool done = false;
bool polygon = false;
bool rectangle = false;
bool ellipse = false;
polygon = true;
// if (nodes==5) { // disable due to LP Bug 407394
// if (lpPoints[0].x == lpPoints[3].x && lpPoints[1].x == lpPoints[2].x &&
// lpPoints[0].y == lpPoints[1].y && lpPoints[2].y == lpPoints[3].y)
// {
// rectangle = true;
// }
// }
// if (lpPoints[0].x == lpPoints[1].x && lpPoints[1].x == lpPoints[11].x &&
// lpPoints[5].x == lpPoints[6].x && lpPoints[6].x == lpPoints[7].x &&
// lpPoints[2].x == lpPoints[10].x && lpPoints[3].x == lpPoints[9].x && lpPoints[4].x == lpPoints[8].x &&
// lpPoints[2].y == lpPoints[3].y && lpPoints[3].y == lpPoints[4].y &&
// lpPoints[8].y == lpPoints[9].y && lpPoints[9].y == lpPoints[10].y &&
// lpPoints[5].y == lpPoints[1].y && lpPoints[6].y == lpPoints[0].y && lpPoints[7].y == lpPoints[11].y)
// { // disable due to LP Bug 407394
// ellipse = true;
// }
}
g_error("Fatal programming error in PrintEmf::print_simple_shape at selectobject_set pen");
}
g_error("Fatal programming error in PrintEmf::print_simple_shape at selectobject_set brush");
}
}
if (polygon) {
if (rectangle) {
}, (U_POINTL) {
});
} else {
}
} else if (ellipse) {
}, (U_POINTL) {
});
}
}
done = true;
// replace the handle we moved above, assuming there was something set already
g_error("Fatal programming error in PrintEmf::print_simple_shape at selectobject_set pen");
}
g_error("Fatal programming error in PrintEmf::print_simple_shape at selectobject_set brush");
}
}
}
delete[] lpPoints;
return done;
}
/** Some parts based on win32.cpp by Lauris Kaplinski <lauris@kaplinski.com>. Was a part of Inkscape
in the past (or will be in the future?) Not in current trunk. (4/19/2012)
Limitations of this code:
1. Transparency is lost on export. (Apparently a limitation of the EMF format.)
2. Probably messes up if row stride != w*4
3. There is still a small memory leak somewhere, possibly in a pixbuf created in a routine
that calls this one and passes px, but never removes the rest of the pixbuf. The first time
this is called it leaked 5M (in one test) and each subsequent call leaked around 200K more.
If this routine is reduced to
if(1)return(0);
and called for a single 1280 x 1024 image then the program leaks 11M per call, or roughly the
size of two bitmaps.
*/
unsigned char *rgba_px, /** array of pixel values, Gdk::Pixbuf bitmap format */
unsigned int w, /** width of bitmap */
unsigned int h, /** height of bitmap */
unsigned int rs, /** row stride (normally w*4) */
Geom::Affine const &tf_rect, /** affine transform only used for defining location and size of rect, for all other tranforms, use the one from m_tr_stack */
{
g_error("Fatal programming error in PrintEmf::image at EMRHEADER");
}
char *px;
int numCt;
/* map the integer Dest coordinates back into pLL2, so that the rounded part does not destabilize the transform offset below */
if (!FixImageRot) { /* Rotate images - some programs cannot read them in correctly if they are rotated */
rec = U_EMRSAVEDC_set();
g_error("Fatal programming error in PrintEmf::image at U_EMRSAVEDC_set");
}
g_error("Fatal programming error in PrintEmf::image at EMRMODIFYWORLDTRANSFORM");
}
}
U_RCL_DEF, //! Bounding rectangle in device units
Dest, //! Destination UL corner in logical units
cDest, //! Destination W & H in logical units
Src, //! Source UL corner in logical units
cSrc, //! Source W & H in logical units
U_DIB_RGB_COLORS, //! DIBColors Enumeration
U_SRCCOPY, //! RasterOPeration Enumeration
Bmi, //! (Optional) bitmapbuffer (U_BITMAPINFO section)
h * rs, //! size in bytes of px
px //! (Optional) bitmapbuffer (U_BITMAPINFO section)
);
g_error("Fatal programming error in PrintEmf::image at U_EMRSTRETCHDIBITS_set");
}
if (numCt) {
}
if (!FixImageRot) {
g_error("Fatal programming error in PrintEmf::image at U_EMRRESTOREDC_set");
}
}
return 0;
}
unsigned int PrintEmf::draw_pathv_to_EMF(Geom::PathVector const &pathv, const Geom::Affine &transform) {
char *rec;
/* inkscape to EMF scaling is done below, but NOT the rotation/translation transform,
that is handled by the EMF MODIFYWORLDTRANSFORM record
*/
rec = U_EMRBEGINPATH_set();
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRBEGINPATH_set");
}
/**
* For all Subpaths in the <path>
*/
using Geom::X;
using Geom::Y;
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRMOVETOEX_set");
}
/**
* For all segments in the subpath
*/
if (is_straight_curve(*cit)) {
//Geom::Point p0 = cit->initialPoint();
//p0[X] = (p0[X] * PX2WORLD);
//p0[Y] = (p0[Y] * PX2WORLD);
//int32_t const x0 = (int32_t) round(p0[X]);
//int32_t const y0 = (int32_t) round(p0[Y]);
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRLINETO_set");
}
//Geom::Point p0 = points[0];
//p0[X] = (p0[X] * PX2WORLD);
//p0[Y] = (p0[Y] * PX2WORLD);
//int32_t const x0 = (int32_t) round(p0[X]);
//int32_t const y0 = (int32_t) round(p0[Y]);
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRPOLYBEZIERTO_set");
}
} else {
g_warning("logical error, because pathv_to_linear_and_cubic_beziers was used");
}
}
rec = U_EMRCLOSEFIGURE_set();
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRCLOSEFIGURE_set");
}
}
}
g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRENDPATH_set");
}
return(0);
}
// may also be called with a simple_shape or an empty path, whereupon it just returns without doing anything
{
if (use_fill) {
destroy_brush(); // these must be cleared even if nothing is drawn or hbrush,hpen fill up
}
if (use_stroke) {
destroy_pen();
}
return TRUE;
}
if (use_fill && !use_stroke) {
g_error("Fatal programming error in PrintEmf::fill at U_EMRFILLPATH_set");
}
} else if (use_fill && use_stroke) {
g_error("Fatal programming error in PrintEmf::stroke at U_EMRSTROKEANDFILLPATH_set");
}
} else if (!use_fill && use_stroke) {
g_error("Fatal programming error in PrintEmf::stroke at U_EMRSTROKEPATH_set");
}
}
// clean out brush and pen, but only after all parts of the draw complete
if (use_fill) {
}
if (use_stroke) {
destroy_pen();
}
return TRUE;
}
unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *text, Geom::Point const &p,
{
return 0;
}
int fix90n = 0;
double rotb = -std::atan2(tf[1], tf[0]); // rotation for baseline offset for superscript/subscript, used below
double ky;
// the dx array is smuggled in like: text<nul>w1 w2 w3 ...wn<nul><nul>, where the widths are floats 7 characters wide, including the space
smuggle_adxkyrtl_out(text, &adx, &ky, &rtl, &ndx, PX2WORLD * std::min(tf.expansionX(), tf.expansionY())); // side effect: free() adx
if (rtl > 0) {
} else {
}
if (textalignment != htextalignment) {
g_error("Fatal programming error in PrintEmf::text at U_EMRSETTEXTALIGN_set");
}
}
char *text2 = strdup(text); // because U_Utf8ToUtf16le calls iconv which does not like a const char *
//translates Unicode to NonUnicode, if possible. If any translate, all will, and all to
//the same font, because of code in Layout::print
//PPT gets funky with text within +-1 degree of a multiple of 90, but only for SOME fonts.Snap those to the central value
//Some funky ones: Arial, Times New Roman
//Some not funky ones: Symbol and Verdana.
//Without a huge table we cannot catch them all, so just the most common problem ones.
if (FixPPTCharPos) {
switch (newfont) {
case CVTSYM:
break;
case CVTZDG:
break;
case CVTWDG:
break;
default: //also CVTNON
break;
}
fix90n = 2;
}
}
}
}
/* Note that text font sizes are stored into the EMF as fairly small integers and that limits their precision.
The EMF output files produced here have been designed so that the integer valued pt sizes
land right on an integer value in the EMF file, so those are exact. However, something like 18.1 pt will be
somewhat off, so that when it is read back in it becomes 18.11 pt. (For instance.)
*/
int textheight = round(-style->font_size.computed * PX2WORLD * std::min(tf.expansionX(), tf.expansionY()));
if (!hfont) {
// Get font face name. Use changed font name if unicode mapped to one
// of the special fonts.
if (!newfont) {
} else {
}
// Scale the text to the minimum stretch. (It tends to stay within bounding rectangles even if
// it was streteched asymmetrically.) Few applications support text from EMF which is scaled
0,
g_error("Fatal programming error in PrintEmf::text at extcreatefontindirectw_set");
}
}
g_error("Fatal programming error in PrintEmf::text at selectobject_set");
}
float rgb[3];
// only change the text color when it needs to be changed
g_error("Fatal programming error in PrintEmf::text at U_EMRSETTEXTCOLOR_set");
}
}
//Handle super/subscripts and vertical kerning
/* Previously used this, but vertical kerning was not supported
p2[Geom::X] -= style->baseline_shift.computed * std::sin( rotb );
p2[Geom::Y] -= style->baseline_shift.computed * std::cos( rotb );
*/
//Conditionally handle compensation for PPT EMF import bug (affects PPT 2003-2010, at least)
if (FixPPTCharPos) {
dx = 0.0;
dy = 0.0;
} else {
}
}
// The number of characters in the string is a bit fuzzy. ndx, the number of entries in adx is
// the number of VISIBLE characters, since some may combine from the UTF (8 originally,
// now 16) encoding. Conversely strlen() or wchar16len() would give the absolute number of
// encoding characters. Unclear if emrtext wants the former or the latter but for now assume the former.
// This is currently being smuggled in from caller as part of text, works
// MUCH better than the fallback hack below
// uint32_t *adx = dx_set(textheight, U_FW_NORMAL, slen); // dx is needed, this makes one up
char *rec2;
if (rtl > 0) {
} else { // RTL text, U_TA_RTLREADING should be enough, but set this one too just in case
}
g_error("Fatal programming error in PrintEmf::text at U_EMREXTTEXTOUTW_set");
}
// Must deselect an object before deleting it. Put the default font (back) in.
g_error("Fatal programming error in PrintEmf::text at selectobject_set");
}
if (hfont) {
g_error("Fatal programming error in PrintEmf::text at deleteobject_set");
}
}
return 0;
}
{
/* EMF print */
"<name>Enhanced Metafile Print</name>\n"
"<id>org.inkscape.print.emf</id>\n"
"<param name=\"destination\" type=\"string\"></param>\n"
"<param name=\"textToPath\" type=\"boolean\">true</param>\n"
"<param name=\"pageBoundingBox\" type=\"boolean\">true</param>\n"
"<param name=\"FixPPTCharPos\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTDashLine\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTGrad2Polys\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTLinGrad\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTPatternAsHatch\" type=\"boolean\">false</param>\n"
"<param name=\"FixImageRot\" type=\"boolean\">false</param>\n"
"<print/>\n"
"</inkscape-extension>", new PrintEmf());
return;
}
} /* 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 :