wmf-print.cpp revision 4435dfc4450d7433e8a61703233aaf1830458d2c
/** @file
* @brief Windows 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 "2geom/sbasis-to-bezier.h"
#include "2geom/svg-elliptical-arc.h"
#include "2geom/pathvector.h"
#include "2geom/bezier-curve.h"
#include "2geom/hvlinesegment.h"
#include "helper/geom-curves.h"
#include "sp-item.h"
#include "style.h"
#include "inkscape-version.h"
#include "sp-root.h"
#include "unit-constants.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 "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 "wmf-print.h"
#include <string.h>
extern "C" {
#include "libunicode-convert/unicode-convert.h"
}
namespace Inkscape {
namespace Extension {
namespace Internal {
#define PXPERMETER 2835
#define MAXDISP 2.0 // This should be set in the output dialog. This is ok for experimenting, no more than 2 pixel deviation. Not actually used at present
struct FFNEXUS {
char *fontname; //Font name
double f1; //Vertical (rotating) offset factor (* font height)
double f2; //Vertical (nonrotating) offset factor (* font height)
double f3; //Horizontal (nonrotating) offset factor (* font height)
};
struct GRADVALUES{
double r; // radius or unused
void *grad; // to access the stops information
int mode; // DRAW_LINEAR_GRADIENT or DRAW_RADIAL_GRADIENT, if GRADVALUES is valid, else any value
};
/* globals */
static FFNEXUS *wmf_long_fflist = NULL; //all the fonts described in ...\share\extensions\fontfix.conf
static GRADVALUES gv;
char fontname[128];
if(wmf_long_fflist)return;
#ifdef WIN32
#else
#endif
//open the input
// throw "boom";
}
continue;
}
if(instr[0]=='#'){
continue;
}
// not a comment, get the 4 values from the line
if(elements!=4){
g_error("Expected \"f1 f2 f3 Fontname\" but did not find it in file: %s\n", path_to_ffconf.c_str());
// throw "boom";
}
if(ptr){
}
else {
}
}
}
/* Looks for the fontname in the long list. If it does not find it, it adds the default values
to the short list with this fontname. If it does find it, then it adds the specified values.
*/
void PrintWmf::search_long_fflist(const char *fontname, double *f1, double *f2, double *f3){ //this is not called by any other source files
if(!wmf_long_fflist){
g_message("Programming error search_long_fflist called before read_system_fflist\n");
throw "boom";
}
while(ptr){
}
//tmp points at either the found name, or the default, the first entry in wmf_long_fflist
if(!wmf_short_fflist){
}
else {
}
}
/* Looks for the fontname in the short list. If it does not find it, it looks in the wmf_long_fflist.
Either way it returns the f1, f2, f3 parameters for the font, even if these are for the default.
*/
void PrintWmf::search_short_fflist(const char *fontname, double *f1, double *f2, double *f3){ //this is not called by any other source files
if(!wmf_long_fflist){
g_message("Programming error search_short_fflist called before read_system_fflist\n");
throw "boom";
}
// This speeds things up a lot - if the same font is called twice in a row, pull it out immediately
while(ptr){
}
//reach this point only if there is no match
}
void PrintWmf::smuggle_adxky_out(const char *string, int16_t **adx, double *ky, int *ndx, float scale){
float fdx;
int i;
if(!*ndx)return; // this could happen with an empty string
cptr += 7;
if(!ladx)throw "Out of memory";
}
cptr++; // skip 2nd fake terminator
}
/* convert an 0RGB color to EMF U_COLORREF.
inverse of sethexcolor() in emf-inout.cpp
*/
(color >> 0) & 0xFF
);
return(out);
}
/* Translate inkscape weights to WMF weights.
*/
// 400 is tested first, as it is the most common case
return(U_FW_NORMAL);
}
{
// all of the class variables are initialized elsewhere, many in PrintWmf::Begin,
}
{
/* restore default signal handling for SIGPIPE */
#endif
return;
}
{
return TRUE;
}
{
// std::cout << "begin " << std::endl;
char *rec;
// WMF header the only things that can be set are the page size in inches (w,h) and the dpi
// width and height in px
// initialize a few global variables
if(nv){
char *p2;
}
bool pageBoundingBox;
if (pageBoundingBox) {
} else {
}
if(!rec){
throw "Fatal programming error in PrintWmf::begin at WMRSETMAPMODE";
}
throw "Fatal programming error in PrintWmf::begin at WMRSETWINDOWEXT";
}
throw "Fatal programming error in PrintWmf::begin at WMRSETWINDOWORG";
}
throw "Fatal programming error in PrintWmf::begin at WMRSETMAPMODE";
}
// bkmode never changes
throw "Fatal programming error in PrintWmf::begin at U_WMRSETBKMODE";
}
throw "Fatal programming error in PrintWmf::begin at U_WMRSETPOLYFILLMODE";
}
// Text alignment never changes
throw "Fatal programming error in PrintWmf::text at U_WMRSETTEXTALIGN_set";
}
throw "Fatal programming error in PrintWmf::text at U_WMRSETTEXTCOLOR_set";
}
throw "Fatal programming error in PrintWmf::begin at U_WMRSETROP2";
}
hmiterlimit=5;
throw "Fatal programming error in PrintWmf::begin at wmiterlimit_set";
}
// create a pen as object 0. We never use it (except by mistake). Its purpose it to make all of the other object indices >=1
throw "Fatal programming error in PrintWmf::begin at wcreatepenindirect_set";
}
// create a null pen. If no specific pen is set, this is used
throw "Fatal programming error in PrintWmf::begin at wcreatepenindirect_set";
}
destroy_pen(); // make this pen active
// create a null brush. If no specific brush is set, this is used
throw "Fatal programming error in PrintWmf::begin at wcreatebrushindirect_set";
}
destroy_brush(); // make this brush active
// std::cout << "end begin" << std::endl;
return 0;
}
{
// std::cout << "finish " << std::endl;
char *rec;
if (!wt) return 0;
// get rid of null brush
throw "Fatal programming error in PrintWmf::finish at wdeleteobject_set null brush";
}
// get rid of null pen
throw "Fatal programming error in PrintWmf::finish at wdeleteobject_set null pen";
}
// get rid of object 0, which was a pen that was used to shift the other object indices to >=1.
hpen=0;
throw "Fatal programming error in PrintWmf::finish at wdeleteobject_set filler object";
}
throw "Fatal programming error in PrintWmf::finish";
}
// std::cout << "end finish" << std::endl;
return 0;
}
const char * /*comment*/)
{
// std::cout << "comment " << std::endl;
if (!wt) return 0;
// earlier versions had flush of fill here, but it never executed and was removed
// std::cout << "end comment" << std::endl;
return 0;
}
// Extract hatchType, hatchColor from a name like
// *MFhatch<hatchType>_<hatchColor> (WMF or EMF hatches are the same)
// Where the first one is a number and the second a color in hex.
// hatchType and hatchColor have been set with defaults before this is called.
//
int val;
// name should be EMFhatch or WMFhatch but *MFhatch will be accepted
val = 0;
name++;
}
*hatchType = -1;
}
else {
name++;
}
}
//
// Recurse down from a brush pattern, try to figure out what it is.
// If an image is found set a pointer to the epixbuf, else set that to NULL
// If a pattern is found with a name like [EW]MFhatch3_3F7FFF return hatchType=3, hatchColor=3F7FFF (as a uint32_t),
// otherwise hatchType is set to -1 and hatchColor is not defined.
//
void PrintWmf::brush_classify(SPObject *parent, int depth, GdkPixbuf **epixbuf, int *hatchType, U_COLORREF *hatchColor){
if(depth==0){
*hatchType = -1;
*hatchColor = U_RGB(0,0,0);
}
depth++;
// first look along the pattern chain, if there is one
if(SP_IS_PATTERN(parent)){
for (SPPattern *pat_i = SP_PATTERN(parent); pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if(SP_IS_IMAGE(pat_i)){
return;
}
if(*hatchType != -1)return;
// still looking? Look at this pattern's children, if there are any
}
}
}
else if(SP_IS_IMAGE(parent)){
return;
}
else { // some inkscape rearrangements pass through nodes between pattern and image which are not classified as either.
}
}
}
//swap R/B in 4 byte pixel
char tmp;
}
}
/* opacity weighting of two colors as float. v1 is the color, op is its opacity, v2 is the background color */
}
if(last>=1){
float rgbs[3];
float rgbe[3];
/* Replace opacity at start & stop with that fraction background color, then average those two for final color. */
);
}
else {
}
return cr;
}
if(mode==DRAW_RADIAL_GRADIENT){
if (rg->gradientTransform_set) {
}
}
else if(mode==DRAW_LINEAR_GRADIENT){
gv.r = 0; // unused
if (lg->gradientTransform_set) {
}
}
else {
throw "Fatal programming error, hold_gradient() in wmf-print.cpp called with invalid draw mode";
}
return 1;
}
// fcolor is defined when gradients are being expanded, it is the color of one stripe or ring.
{
// std::cout << "create_brush " << std::endl;
float rgb[3];
char *rec;
int hatchType;
if (!wt) return 0;
// set a default fill in case we can't figure out a better way to do it
fmode = U_ALTERNATE;
else { hatchColor = U_RGB(0, 0, 0); }
fmode = style->fill_rule.computed == 0 ? U_WINDING : (style->fill_rule.computed == 2 ? U_ALTERNATE : U_ALTERNATE);
}
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){
}
else if(lg){
}
}
}
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:
throw "Fatal programming error in PrintWmf::create_brush at createbrushindirect_set";
}
break;
case DRAW_IMAGE:
char *px;
char *rgba_px;
int numCt;
// Not sure why the next swap is needed because the preceding does it, and the code is identical
// to that in stretchdibits_set, which does not need this.
Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0);
throw "Fatal programming error in PrintWmf::create_brush at createdibpatternbrushpt_set";
}
break;
}
throw "Fatal programming error in PrintWmf::create_brush at wselectobject_set";
}
if(fmode != hpolyfillmode){
throw "Fatal programming error in PrintWmf::create_brush at U_WMRSETPOLYFILLMODE_set";
}
}
// std::cout << "end create_brush " << std::endl;
return 0;
}
void PrintWmf::destroy_brush()
{
// std::cout << "destroy_brush " << std::endl;
char *rec;
// WMF lets any object be deleted whenever, and the chips fall where they may...
if (hbrush){
throw "Fatal programming error in PrintWmf::destroy_brush";
}
hbrush = 0;
}
// (re)select the null brush
throw "Fatal programming error in PrintWmf::destroy_brush";
}
// std::cout << "end destroy_brush" << std::endl;
}
{
int modstyle;
// std::cout << "create_pen " << std::endl;
if (!wt) return 0;
// set a default stroke in case we can't figure out a better way to do it
modstyle = 0;
if (style) { // override some or all of the preceding
float rgb[3];
// WMF does not support hatched, bitmap, or gradient pens, just set the color.
using Geom::X;
using Geom::Y;
if(!style->stroke_width.computed){return 0;} //if width is 0 do not (reset) the pen, it should already be NULL_PEN
// most WMF readers will ignore linecap and linejoin, but set them anyway. Inkscape itself can read them back in.
else { modstyle |= U_PS_ENDCAP_SQUARE; }
// most WMF readers will ignore miterlimit, but set it anyway. Inkscape itself can read it back in
throw "Fatal programming error in PrintWmf::create_pen at wmiterlimit_set";
}
}
modstyle |= U_PS_JOIN_MITER; }
else { modstyle |= U_PS_JOIN_BEVEL; }
{
if(!FixPPTDashLine){ // if this is set code elsewhere will break dots/dashes into many smaller lines.
penstyle = U_PS_DASH;// userstyle not supported apparently, for now map all Inkscape dot/dash to just dash
}
}
}
throw "Fatal programming error in PrintWmf::create_pen at wcreatepenindirect_set";
}
throw "Fatal programming error in PrintWmf::create_pen at wselectobject_set";
}
return 0;
// std::cout << "end create_pen" << std::endl;
}
// delete the defined pen object
void PrintWmf::destroy_pen()
{
// std::cout << "destroy_pen hpen: " << hpen<< std::endl;
// WMF lets any object be deleted whenever, and the chips fall where they may...
if (hpen){
throw "Fatal programming error in PrintWmf::destroy_pen";
}
hpen = 0;
}
// (re)select the null pen
throw "Fatal programming error in PrintWmf::destroy_pen";
}
// std::cout << "end destroy_pen " << std::endl;
}
unsigned int PrintWmf::bind(Inkscape::Extension::Print * /*mod*/, Geom::Affine const &transform, float /*opacity*/)
{
// std::cout << "bind " << std::endl;
if (!m_tr_stack.empty()) {
} else {
}
// std::cout << "end bind" << std::endl;
return 1;
}
{
// std::cout << "release " << std::endl;
m_tr_stack.pop();
// std::cout << "end release" << std::endl;
return 1;
}
#define clrweight(a,b,t) ((1-t)*((double) a) + (t)*((double) b))
);
return result;
}
// return the color between c1 and c2, c1 for t=0, c2 for t=1.0
// now handle the opacity, mix the RGB with background at the weighted opacity
return result;
}
/* convert from center ellipse to SVGEllipticalArc ellipse
From:
http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
A point (x,y) on the arc can be found by:
{x,y} = {cx,cy} + {cosF,-sinF,sinF,cosF} x {rxcosT,rysinT}
where
{cx,cy} is the center of the ellipse
F is the rotation angle of the X axis of the ellipse from the true X axis
T is the rotation angle around the ellipse
{,,,} is the rotation matrix
rx,ry are the radii of the ellipse's axes
For SVG parameterization need two points.
Arbitrarily we can use T=0 and T=pi
Since the sweep is 180 the flags are always 0:
F is in RADIANS, but the SVGEllipticalArc needs degrees!
*/
Geom::PathVector PrintWmf::center_ellipse_as_SVG_PathV(Geom::Point ctr, double rx, double ry, double F){
using Geom::X;
using Geom::Y;
char text[256];
sprintf(text," M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z",x1,y1, rx,ry,F*360./(2.*M_PI),x2,y2, rx,ry,F*360./(2.*M_PI),x1,y1);
return outres;
}
/* rx2,ry2 must be larger than rx1,ry1!
angle is in RADIANS
*/
Geom::PathVector PrintWmf::center_elliptical_ring_as_SVG_PathV(Geom::Point ctr, double rx1, double ry1, double rx2, double ry2, double F){
using Geom::X;
using Geom::Y;
char text[512];
sprintf(text," M %f,%f A %f %f %f 0 1 %f %f A %f %f %f 0 1 %f %f z M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z",
return outres;
}
/* Elliptical hole in a large square extending from -50k to +50k */
Geom::PathVector PrintWmf::center_elliptical_hole_as_SVG_PathV(Geom::Point ctr, double rx, double ry, double F){
using Geom::X;
using Geom::Y;
char text[256];
sprintf(text," M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z M 50000,50000 50000,-50000 -50000,-50000 -50000,50000 z",
return outres;
}
/* rectangular cutter.
ctr "center" of rectangle (might not actually be in the center with respect to leading/trailing edges
pos vector from center to leading edge
neg vector from center to trailing edge
width vector to side edge
*/
Geom::PathVector PrintWmf::rect_cutter(Geom::Point ctr, Geom::Point pos, Geom::Point neg, Geom::Point width){
return outres;
}
/* Convert from SPWindRule to livarot's FillRule
This is similar to what sp_selected_path_boolop() does
*/
if(wr == SP_WIND_RULE_EVENODD){
fr = fill_oddEven;
}
else {
fr = fill_nonZero;
}
return fr;
}
{
// std::cout << "fill " << std::endl;
using Geom::X;
using Geom::Y;
use_fill = true;
use_stroke = false;
fill_transform = tf;
/*
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 WMF 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]));
istop++;
}
}
}
double start;
double stop;
/* before lower end of gradient, overlap first slice position */
/* after high end of gradient, overlap last slice poosition */
Geom::PathVector pathvr = sp_pathvector_boolop(pathvc, pathv, bool_op_inters, (FillRule) fill_nonZero, frb);
istop++;
}
}
}
else {
throw "Fatal programming error in PrintWmf::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;
}
}
if (
)
{
use_fill = false;
}
}
// std::cout << "end fill" << std::endl;
return 0;
}
{
// std::cout << "stroke " << std::endl;
use_stroke = true;
// use_fill was set in ::fill, if it is needed, if not, the null brush is used, it should be already set
// 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).
else { first_frag = fragment; }
if(i>=n_dash)i=0;
}
}
else {
}
use_stroke = false;
use_fill = false;
// std::cout << "end stroke " << std::endl;
return 0;
}
// Draws simple_shapes, those with closed WMR_* 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.
{
// std::cout << "print_simple_shape " << std::endl <<std::flush;
int nodes = 0;
int moves = 0;
int lines = 0;
int curves = 0;
{
moves++;
nodes++;
{
nodes++;
if ( is_straight_curve(*cit) ) {
lines++;
}
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;
// }
}
// pens and brushes already set by caller, do not touch them
if (polygon) {
if (rectangle){
U_RECT16 rcl = U_RECT16_set((U_POINT16) {lpPoints[0].x, lpPoints[0].y}, (U_POINT16) {lpPoints[2].x, lpPoints[2].y});
}
else {
}
}
else if (ellipse) {
U_RECT16 rcl = U_RECT16_set((U_POINT16) {lpPoints[6].x, lpPoints[3].y}, (U_POINT16) {lpPoints[0].x, lpPoints[9].y});
}
}
done = true;
}
delete[] lpPoints;
// std::cout << "end simple_shape " << std::endl;
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. Images lose their rotation, one corner stays in the same place.
2. Transparency is lost on export. (A limitation of the WMF format.)
3. Probably messes up if row stride != w*4
4. 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) */
{
// std::cout << "image " << std::endl;
throw "Fatal programming error in PrintWmf::image at EMRHEADER";
}
char *px;
int numCt;
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)
);
throw "Fatal programming error in PrintWmf::image at U_WMRSTRETCHDIB_set";
}
// std::cout << "end image" << std::endl;
return 0;
}
// may also be called with a simple_shape or an empty path, whereupon it just returns without doing anything
{
// std::cout << "print_pathv " << std::endl << std::flush;
// WMF does not have beziers, need to convert to ONLY linears with something like this:
/**
* For all Subpaths in the <path>
*/
/* If the path consists entirely of closed subpaths use polypolygon, for all paths. Otherwise use
polygon or polyline separately on each path. The former allows path delimited donuts and the like, which
cannot be represented in WMF with polygon or polyline because there is no external way to combine paths
as there is in EMF or SVG */
int nPolys=0;
int totPoints = 0;
{
totPoints += 1 + pit->size_default(); // big array, will hold all points, for all polygons. Size_default ignores first point in each path.
else { nPolys=0; break; }
}
if(nPolys){ // a single polypolygon
if(!pt16ptr)return(false);
{
using Geom::X;
using Geom::Y;
/**
* For each segment in the subpath
*/
{
}
}
throw "Fatal programming error in PrintWmf::print_pathv at U_WMRPOLYPOLYGON_set";
}
}
else { // one or more polyline or polygons (but not all polygons, that would be the preceding case)
{
using Geom::X;
using Geom::Y;
/* Figure out how many points there are, make an array big enough to hold them, and store
all the points. This is the same for open or closed path. Note that size_default() ignores
the first point, for some reason.
*/
if(!pt16ptr)break;
/**
* For each segment in the subpath
*/
{
}
throw "Fatal programming error in PrintWmf::print_pathv at U_WMRPOLYGON/POLYLINE_set";
}
}
}
}
// clean out brush and pen, but only after all parts of the draw complete
if (use_fill){ destroy_brush(); }
if (use_stroke){ destroy_pen(); }
// std::cout << "end pathv" << std::endl;
return TRUE;
}
{
}
unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *text, Geom::Point const &p,
{
// std::cout << "text " << std::endl;
if (!wt) 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
int ndx;
smuggle_adxky_out(text, &adx, &ky, &ndx, PX2WORLD * std::min(tf.expansionX(),tf.expansionY())); // side effect: free() adx
char *text2 = strdup(text); // because U_Utf8ToUtf16le calls iconv which does not like a const char *
//translates Unicode as Utf16le to NonUnicode, if possible. If any translate, all will, and all to
//the same font, because of code in Layout::print
// The preceding hopefully handled conversions to symbol, wingdings or zapf dingbats. Now slam everything
// else down into latin1, which is all WMF can handle. If the language isn't English expect terrible results.
//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;
}
}
}
}
/* Note that text font sizes are stored into the WMF as fairly small integers and that limits their precision.
The WMF output files produced here have been designed so that the integer valued pt sizes
land right on an integer value in the WMF 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.
char *facename;
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 WMF which is scaled
0,
rot,
rot,
facename);
throw "Fatal programming error in PrintWmf::text at wcreatefontindirect_set";
}
}
throw "Fatal programming error in PrintWmf::text at wselectobject_set";
}
float rgb[3];
// only change the text color when it needs to be changed
throw "Fatal programming error in PrintWmf::text at U_WMRSETTEXTCOLOR_set";
}
}
// Text alignment:
// - (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 WMF text alignment must always be TA_BASELINE|TA_LEFT.
// this is set at the beginning of the file and never changed
// Transparent text background, never changes, set at the beginning of the file
//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 WMF 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
rec = U_WMREXTTEXTOUT_set((U_POINT16) {xpos, ypos}, ndx, U_ETO_NONE, latin1_text, adx, U_RCL16_DEF);
throw "Fatal programming error in PrintWmf::text at U_WMREXTTEXTOUTW_set";
}
throw "Fatal programming error in PrintWmf::text at wdeleteobject_set";
}
// std::cout << "end text" << std::endl;
return 0;
}
{
// std::cout << "init " << std::endl;
/* WMF print */
"<name>Windows Metafile Print</name>\n"
"<id>org.inkscape.print.wmf</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=\"FixPPTPatternAsHatch\" type=\"boolean\">false</param>\n"
"<print/>\n"
"</inkscape-extension>", new PrintWmf());
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 :