emf-inout.cpp revision 51a4b3a1f5ff786faa6711432cf1930ef14d4e0c
/** @file
* @brief Windows-only Enhanced Metafile input and output.
*/
/* Authors:
* Ulf Erikson <ulferikson@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2006-2008 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
#define EMF_DRIVER
#include "sp-root.h"
#include "sp-path.h"
#include "style.h"
#include "print.h"
#include "display/drawing-item.h"
#include "unit-constants.h"
#include "clear-n_.h"
#include "document.h"
#include "libunicode-convert/unicode-convert.h"
#include "emf-print.h"
#include "emf-inout.h"
#include "uemf.h"
#define PRINT_EMF "org.inkscape.print.emf"
#ifndef U_PS_JOIN_MASK
#endif
namespace Inkscape {
namespace Extension {
namespace Internal {
static bool clipset = false;
/** Construct a PNG in memory from an RGB from the EMF file
from:
which was based on:
gcc -Wall -o testpng testpng.c -lpng
*/
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/* A coloured pixel. */
typedef struct {
} pixel_t;
/* A picture. */
typedef struct {
} bitmap_t;
/* structure to store PNG image bytes */
typedef struct {
char *buffer;
/* Given "bitmap", this returns the pixel of bitmap at the point
("x", "y"). */
{
}
/* Write "bitmap" to a PNG file specified by "path"; returns 0 on
success, non-zero on error. */
void
{
/* allocate or grow buffer */
if(p->buffer)
else
if(!p->buffer)
/* copy new bytes to end of buffer */
}
size_t x, y;
/* The following number is set by trial and error only. I cannot
see where it it is documented in the libpng manual.
*/
int pixel_size = 3;
int depth = 8;
return;
}
return;
}
/* Set up error handling. */
return;
}
/* Set image attributes. */
/* Initialize rows of PNG. */
}
}
/* Write the image data to memory */
}
}
/* convert an EMF RGB(A) color to 0RGB
inverse of gethexcolor() in emf-print.cpp
*/
(U_RGBAGetB(color) );
return(out);
}
{
return;
}
{
return;
}
bool
{
return FALSE;
return TRUE;
}
static void
{
unsigned int ret;
doc->ensureUpToDate();
/* Start */
/* fixme: This has to go into module constructor somehow */
/* Create new arena */
/* Print document */
if (ret) {
}
/* Release arena */
/* end */
return;
}
void
{
return;
// reserve FixPPT2 for opacity bug. Currently EMF does not export opacity values
bool new_FixPPTPatternAsHatch = mod->get_param_bool("FixPPTPatternAsHatch"); // force all patterns as standard EMF hatch
TableGen( //possibly regenerate the unicode-convert tables
);
ext->set_param_bool("FixPPTCharPos",new_FixPPTCharPos); // Remember to add any new ones to PrintEmf::init or a mysterious failure will result!
return;
}
typedef struct {
int type;
int level;
char *lpEMFR;
} EMF_OBJECT, *PEMF_OBJECT;
typedef struct {
int size; // number of slots allocated in strings
int count; // number of slots used in strings
char **strings; // place to store strings
} EMF_STRINGS, *PEMF_STRINGS;
typedef struct emf_device_context {
char *font_name;
bool stroke_set;
int stroke_mode; // enumeration from drawmode, not used if fill_set is not True
int stroke_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill
bool fill_set;
int fill_mode; // enumeration from drawmode, not used if fill_set is not True
int fill_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill
bool textColorSet;
bool bkColorSet;
#define EMF_MAX_DC 128
typedef struct emf_callback_data {
int level;
int arcdir; //U_AD_COUNTERCLOCKWISE 1 or U_AD_CLOCKWISE 2
float MMX;
float MMY;
unsigned int id;
unsigned int drawtype; // one of 0 or U_EMR_FILLPATH, U_EMR_STROKEPATH, U_EMR_STROKEANDFILLPATH
char *pDesc;
// both of these end up in <defs> under the names shown here. These structures allow duplicates to be avoided.
EMF_STRINGS hatches; // hold pattern names, all like EMFhatch#_$$$$$$ where # is the EMF hatch code and $$$$$$ is the color
int n_obj;
/* Add another 100 blank slots to the hatches array.
*/
void enlarge_hatches(PEMF_CALLBACK_DATA d){
}
/* See if the pattern name is already in the list. If it is return its position (1->n, not 1-n-1)
*/
int i;
}
return(0);
}
/* (Conditionally) add a hatch. If a matching hatch already exists nothing happens. If one
does not exist it is added to the hatches list and also entered into <defs>.
*/
char tmpcolor[8];
}
switch(hatchType){
case U_HS_SOLIDTEXTCLR:
case U_HS_DITHEREDTEXTCLR:
}
break;
case U_HS_SOLIDBKCLR:
case U_HS_DITHEREDBKCLR:
}
break;
default:
break;
}
// EMF can take solid colors from background or the default text color but on conversion to inkscape
// these need to go to a defined color. Consequently the hatchType also has to go to a solid color, otherwise
// on export the background/text might not match at the time this is written, and the colors will shift.
if(!idx){ // add it if not already present
*(d->defs) += "\n";
*(d->defs) += " <pattern id=\"";
*(d->defs) += "\"\n";
switch(hatchType){
case U_HS_HORIZONTAL:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" >\n";
*(d->defs) += " <path d=\"M 0 0 6 0\" style=\"fill:none;stroke:#";
*(d->defs) += "\" />\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_VERTICAL:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" >\n";
*(d->defs) += " <path d=\"M 0 0 0 6\" style=\"fill:none;stroke:#";
*(d->defs) += "\" />\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_FDIAGONAL:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" viewBox=\"0 0 6 6\" preserveAspectRatio=\"none\" >\n";
*(d->defs) += " <line x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#";
*(d->defs) += "\" id=\"sub";
*(d->defs) += "\"/>\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(6,0)\"/>\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(-6,0)\"/>\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_BDIAGONAL:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" viewBox=\"0 0 6 6\" preserveAspectRatio=\"none\" >\n";
*(d->defs) += " <line x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#";
*(d->defs) += "\" id=\"sub";
*(d->defs) += "\"/>\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(6,0)\"/>\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(-6,0)\"/>\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_CROSS:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" >\n";
*(d->defs) += " <path d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#";
*(d->defs) += "\" />\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_DIAGCROSS:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" viewBox=\"0 0 6 6\" preserveAspectRatio=\"none\" >\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(0,0)\"/>\n";
*(d->defs) += " <use xlink:href=\"#sub";
*(d->defs) += "\" transform=\"translate(0,0)\"/>\n";
*(d->defs) += " </pattern>\n";
break;
case U_HS_SOLIDCLR:
case U_HS_DITHEREDCLR:
case U_HS_SOLIDTEXTCLR:
case U_HS_DITHEREDTEXTCLR:
case U_HS_SOLIDBKCLR:
case U_HS_DITHEREDBKCLR:
default:
*(d->defs) += " patternUnits=\"userSpaceOnUse\" width=\"6\" height=\"6\" x=\"0\" y=\"0\" >\n";
*(d->defs) += " <path d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#";
*(d->defs) += ";stroke:none";
*(d->defs) += "\" />\n";
*(d->defs) += " </pattern>\n";
break;
}
}
return(idx-1);
}
/* Add another 100 blank slots to the images array.
*/
void enlarge_images(PEMF_CALLBACK_DATA d){
}
/* See if the image string is already in the list. If it is return its position (1->n, not 1-n-1)
*/
int i;
}
return(0);
}
/* (Conditionally) add an image. If a matching image already exists nothing happens. If one
does not exist it is added to the images list and also entered into <defs>.
U_EMRCREATEMONOBRUSH records only work when the bitmap is monochrome. If we hit one that isn't
set idx to 2^32-1 and let the caller handle it.
*/
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){
if(!cbBits ||
!cbBmi ||
(iUsage != U_DIB_RGB_COLORS) ||
!get_DIB_params( // this returns pointers and values, but allocates no memory
pEmr,
&px,
&ct,
&numCt,
&width,
&height,
)){
if(numCt==2){
}
else { // createmonobrush renders on other platforms this way
return(0xFFFFFFFF);
}
}
if(!DIB_to_RGBA(
px, // DIB pixel array
ct, // DIB color table
numCt, // DIB color table number of entries
&rgba_px, // U_RGBA pixel array (32 bits), created by this routine, caller must free.
width, // Width of pixel array in record
height, // Height of pixel array in record
colortype, // DIB BitCount Enumeration
numCt, // Color table used if not 0
invert // If DIB rows are in opposite order from RGBA rows
) &&
{
toPNG( // Get the image from the RGBA px into mempng
&mempng,
rgba_px);
}
}
}
else {
// insert a random 3x4 blotch otherwise
width = 3;
height = 4;
base64String = strdup("iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAIAAAA7ljmRAAAAA3NCSVQICAjb4U/gAAAALElEQVQImQXBQQ2AMAAAsUJQMSWI2H8qME1yMshojwrvGB8XcHKvR1XtOTc/8HENumHCsOMAAAAASUVORK5CYII=");
}
if(!idx){ // add it if not already present
*(d->defs) += "\n";
*(d->defs) += " <image id=\"";
*(d->defs) += "\"\n ";
*(d->defs) += "\n";
*(d->defs) += base64String;
*(d->defs) += "\"\n";
*(d->defs) += " />\n";
*(d->defs) += "\n";
*(d->defs) += " <pattern id=\"";
*(d->defs) += "_ref\"\n ";
*(d->defs) += "\n patternUnits=\"userSpaceOnUse\"";
*(d->defs) += " >\n";
*(d->defs) += " <use id=\"";
*(d->defs) += "_ign\" ";
*(d->defs) += " xlink:href=\"#";
*(d->defs) += "\" />\n";
*(d->defs) += " </pattern>\n";
}
return(idx-1);
}
static void
{
// SVGOStringStream tmp_id;
char tmp[1024] = {0};
float fill_rgb[3];
float stroke_rgb[3];
// for U_EMR_BITBLT with no image, try to approximate some of these operations/
// Assume src color is "white"
if(d->dwRop3){
switch(d->dwRop3){
case U_PATINVERT: // treat all of these as black
case U_SRCINVERT:
case U_DSTINVERT:
case U_BLACKNESS:
case U_SRCERASE:
case U_NOTSRCCOPY:
break;
case U_SRCCOPY: // treat all of these as white
case U_NOTSRCERASE:
case U_PATCOPY:
case U_WHITENESS:
break;
case U_SRCPAINT: // use the existing color
case U_SRCAND:
case U_MERGECOPY:
case U_MERGEPAINT:
case U_PATPAINT:
default:
break;
}
d->dwRop3 = 0; // might as well reset it here, it must be set for each BITBLT
}
// Implement some of these, the ones where the original screen color does not matter.
// The options that merge screen and pen colors cannot be done correctly because we
// have no way of knowing what color is already on the screen. For those just pass the
// pen color through.
switch(d->dwRop2){
case U_R2_BLACK:
break;
case U_R2_NOTMERGEPEN:
case U_R2_MASKNOTPEN:
break;
case U_R2_NOTCOPYPEN:
break;
case U_R2_MASKPENNOT:
case U_R2_NOT:
case U_R2_XORPEN:
case U_R2_NOTMASKPEN:
case U_R2_NOTXORPEN:
case U_R2_NOP:
case U_R2_MERGENOTPEN:
case U_R2_COPYPEN:
case U_R2_MASKPEN:
case U_R2_MERGEPENNOT:
case U_R2_MERGEPEN:
break;
case U_R2_WHITE:
break;
default:
break;
}
// tmp_id << "\n\tid=\"" << (d->id++) << "\"";
// *(d->outsvg) += tmp_id.str().c_str();
*(d->outsvg) += "\n\tstyle=\"";
tmp_style << "fill:none;";
} else {
// both of these use the url(#) method
case DRAW_PATTERN:
break;
case DRAW_IMAGE:
break;
case DRAW_PAINT:
default: // <-- this should never happen, but just in case...
"fill:#%02x%02x%02x;",
SP_COLOR_F_TO_U(fill_rgb[0]),
break;
}
"fill-rule:%s;",
tmp_style << "fill-opacity:1;";
if (d->dc[d->level].fill_set && d->dc[d->level].stroke_set && d->dc[d->level].style.stroke_width.value == 1 &&
{
}
}
tmp_style << "stroke:none;";
} else {
// both of these use the url(#) method
case DRAW_PATTERN:
break;
case DRAW_IMAGE:
break;
case DRAW_PAINT:
default: // <-- this should never happen, but just in case...
"stroke:#%02x%02x%02x;",
break;
}
tmp_style << "stroke-width:" <<
tmp_style << "stroke-linecap:" <<
"unknown") << ";";
tmp_style << "stroke-linejoin:" <<
"unknown") << ";";
// Set miter limit if known, even if it is not needed immediately (not miter)
tmp_style << "stroke-miterlimit:" <<
{
tmp_style << "stroke-dasharray:";
if (i)
tmp_style << ",";
}
tmp_style << ";";
tmp_style << "stroke-dashoffset:0;";
} else {
tmp_style << "stroke-dasharray:none;";
}
tmp_style << "stroke-opacity:1;";
}
tmp_style << "\" ";
if (clipset)
clipset = false;
}
static double
{
double tmp;
return(tmp);
}
static double
{
double tmp;
return(tmp);
}
static double
{
double wpx = px * d->dc[d->level].worldTransform.eM11 + py * d->dc[d->level].worldTransform.eM21 + d->dc[d->level].worldTransform.eDx;
double x = _pix_x_to_point(d, wpx);
return x;
}
static double
{
double wpy = px * d->dc[d->level].worldTransform.eM12 + py * d->dc[d->level].worldTransform.eM22 + d->dc[d->level].worldTransform.eDy;
double y = _pix_y_to_point(d, wpy);
return y;
}
static double
{
// double ppy = 0;
double dx = ppx * d->dc[d->level].worldTransform.eM11; // + ppy * d->dc[d->level].worldTransform.eM21
double dy = ppx * d->dc[d->level].worldTransform.eM12; // + ppy * d->dc[d->level].worldTransform.eM22
return tmp;
}
static void
{
if (!pEmr)
return;
case U_PS_DASH:
case U_PS_DOT:
case U_PS_DASHDOT:
case U_PS_DASHDOTDOT:
{
int i = 0;
if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash)))
}
}
if (penstyle==U_PS_DASHDOTDOT) {
}
break;
}
case U_PS_SOLID:
default:
{
break;
}
}
case U_PS_ENDCAP_ROUND:
{
break;
}
case U_PS_ENDCAP_SQUARE:
{
break;
}
case U_PS_ENDCAP_FLAT:
default:
{
break;
}
}
case U_PS_JOIN_BEVEL:
{
break;
}
case U_PS_JOIN_MITER:
{
break;
}
case U_PS_JOIN_ROUND:
default:
{
break;
}
}
} else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
//d->dc[d->level].style.stroke_width.value = 1.0;
}
double r, g, b;
}
static void
{
if (!pEmr)
return;
case U_PS_USERSTYLE:
{
if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash)))
// Doing it this way typically results in a pattern that is tiny, better to assume the array
// double dash_length = pix_to_size_point( d, pEmr->elp.elpStyleEntry[i] );
}
} else {
}
break;
}
case U_PS_DASH:
case U_PS_DOT:
case U_PS_DASHDOT:
case U_PS_DASHDOTDOT:
{
int i = 0;
if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash)))
}
}
if (penstyle==U_PS_DASHDOTDOT) {
}
break;
}
case U_PS_SOLID:
/* includes these for now, some should maybe not be in here
case U_PS_NULL:
case U_PS_INSIDEFRAME:
case U_PS_ALTERNATE:
case U_PS_STYLE_MASK:
*/
default:
{
break;
}
}
case U_PS_ENDCAP_ROUND:
{
break;
}
case U_PS_ENDCAP_SQUARE:
{
break;
}
case U_PS_ENDCAP_FLAT:
default:
{
break;
}
}
case U_PS_JOIN_BEVEL:
{
break;
}
case U_PS_JOIN_MITER:
{
break;
}
case U_PS_JOIN_ROUND:
default:
{
break;
}
}
if (pEmr->elp.elpPenStyle == U_PS_NULL) { // draw nothing, but fill out all the values with something
double r, g, b;
}
else {
} else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
//d->dc[d->level].style.stroke_width.value = 1.0;
}
double r, g, b;
}
}
else if(pEmr->elp.elpBrushStyle == U_BS_DIBPATTERN || pEmr->elp.elpBrushStyle == U_BS_DIBPATTERNPT){
d->dc[d->level].stroke_idx = add_image(d, pEmr, pEmr->cbBits, pEmr->cbBmi, *(uint32_t *) &(pEmr->elp.elpColor), pEmr->offBits, pEmr->offBmi);
}
else { // U_BS_PATTERN and anything strange that falls in, stroke is solid textColor
double r, g, b;
}
}
}
static void
{
if(iType == U_EMR_CREATEBRUSHINDIRECT){
double r, g, b;
}
}
}
tidx = add_image(d, (void *) pEmr, pEmr->cbBits, pEmr->cbBmi, pEmr->iUsage, pEmr->offBits, pEmr->offBmi);
double r, g, b;
}
else {
}
}
}
}
static void
{
if (!pEmr)return;
/* The logfont information always starts with a U_LOGFONT structure but the U_EMREXTCREATEFONTINDIRECTW
is defined as U_LOGFONT_PANOSE so it can handle one of those if that is actually present. Currently only logfont
is supported, and the remainder, it it really is a U_LOGFONT_PANOSE record, is ignored
*/
/* snap the font_size to the nearest 1/32nd of a point.
(The size is converted from Pixels to points, snapped, and converted back.)
See the notes where d->W2Pscale[XY] are set for the reason why.
Typically this will set the font to the desired exact size. If some peculiar size
was intended this will, at worst, make it .03125 off, which is unlikely to be a problem. */
d->dc[d->level].style.font_style.value = (pEmr->elfw.elfLogFont.lfItalic ? SP_CSS_FONT_STYLE_ITALIC : SP_CSS_FONT_STYLE_NORMAL);
// malformed EMF with empty filename may exist, ignore font change if encountered
if(ctmp){
if(*ctmp){
}
else { // Malformed EMF might specify an empty font name
d->dc[d->level].font_name = strdup("Arial"); // Default font, EMF spec says device can pick whatever it wants
}
}
d->dc[d->level].style.baseline_shift.value = ((pEmr->elfw.elfLogFont.lfEscapement + 3600) % 3600) / 10; // use baseline_shift instead of text_transform to avoid overflow
}
static void
{
// We are keeping a copy of the EMR rather than just a structure. Currently that is not necessary as the entire
// EMF is read in at once and is stored in a big malloc. However, in past versions it was handled
// reord by record, and we might need to do that again at some point in the future if we start running into EMF
// files too big to fit into memory.
}
}
static void
{
delete_object(d, index);
}
}
/* Identify probable Adobe Illustrator produced EMF files, which do strange things with the scaling.
The few so far observed all had this format.
*/
int ret=0;
char *ptr;
if(pEmr->nDescription)string = U_Utf16leToUtf8((uint16_t *)((char *) pEmr + pEmr->offDescription), pEmr->nDescription, NULL);
if(string){
}
return(ret);
}
/**
\fn create a UTF-32LE buffer and fill it with UNICODE unknown character
\param count number of copies of the Unicode unknown character to fill with
*/
if(!res)throw "Inkscape fatal memory allocation error - cannot continue";
return res;
}
/**
\fn store SVG for an image given the pixmap and various coordinate information
\param d
\param pEmr
\param dl (double) destination left in inkscape pixels
\param dt (double) destination top in inkscape pixels
\param dr (double) destination right in inkscape pixels
\param db (double) destination bottom in inkscape pixels
\param sl (int) source left in pixels in the src image
\param st (int) source top in pixels in the src image
\param iUsage
\param offBits
\param cbBits
\param offBmi
\param cbBmi
*/
// The image ID is filled in much later when tmp_image is converted
if(!cbBits ||
!cbBmi ||
(iUsage != U_DIB_RGB_COLORS) ||
!get_DIB_params( // this returns pointers and values, but allocates no memory
pEmr,
&px,
&ct,
&numCt,
&width,
&height,
)){
}
if(!DIB_to_RGBA(
px, // DIB pixel array
ct, // DIB color table
numCt, // DIB color table number of entries
&rgba_px, // U_RGBA pixel array (32 bits), created by this routine, caller must free.
width, // Width of pixel array
height, // Height of pixel array
colortype, // DIB BitCount Enumeration
numCt, // Color table used if not 0
invert // If DIB rows are in opposite order from RGBA rows
) &&
{
rgba_px, // full pixel array from DIB
width, // Width of pixel array
height, // Height of pixel array
);
toPNG( // Get the image from the RGBA px into mempng
&mempng,
sub_px);
}
}
tmp_image << base64String ;
}
else {
// insert a random 3x4 blotch otherwise
tmp_image << "iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAIAAAA7ljmRAAAAA3NCSVQICAjb4U/gAAAALElEQVQImQXBQQ2AMAAAsUJQMSWI2H8qME1yMshojwrvGB8XcHKvR1XtOTc/8HENumHCsOMAAAAASUVORK5CYII=";
}
*(d->outsvg) += "\n\t <image\n";
*(d->outsvg) += "/> \n";
*(d->path) = "";
}
/**
\fn myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DATA lpData)
\param contents binary contents of an EMF file
\param length length in bytes of contents
\param d Inkscape data structures returned by this call
*/
//THis was a callback, just build it into a normal function
{
int OK =1;
while(OK){
// Uncomment the following to track down toxic records
//std::cout << "record type: " << lpEMFR->iType << " length: " << lpEMFR->nSize << " offset: " << off <<std::endl;
// std::cout << "BEFORE DRAW logic d->mask: " << std::hex << d->mask << " emr_mask: " << emr_mask << std::dec << std::endl;
/*
std::cout << "BEFORE DRAW"
<< " test0 " << ( d->mask & U_DRAW_VISIBLE)
<< " test1 " << ( d->mask & U_DRAW_FORCE)
<< " test2 " << (emr_mask & U_DRAW_ALTERS)
<< " test3 " << (emr_mask & U_DRAW_VISIBLE)
<< " test4 " << !(d->mask & U_DRAW_ONLYTO)
<< " test5 " << ((d->mask & U_DRAW_ONLYTO) && !(emr_mask & U_DRAW_ONLYTO) )
<< std::endl;
*/
&&
(
||
((d->mask & U_DRAW_ONLYTO) && !(emr_mask & U_DRAW_ONLYTO) ) // *TO records can only be followed by other *TO records
)
)
)
){
// std::cout << "PATH DRAW at TOP" << std::endl;
if(d->drawtype){ // explicit draw type EMR record
output_style(d, d->drawtype);
}
}
else {
}
*(d->outsvg) += "\n\t";
*(d->outsvg) += " \" /> \n";
*(d->path) = "";
// reset the flags
d->mask = 0;
d->drawtype = 0;
}
// std::cout << "AFTER DRAW logic d->mask: " << std::hex << d->mask << " emr_mask: " << emr_mask << std::dec << std::endl;
{
case U_EMR_HEADER:
{
dbg_str << "<!-- U_EMR_HEADER -->\n";
*(d->outdef) += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
if (d->pDesc) {
*(d->outdef) += "<!-- ";
*(d->outdef) += " -->\n";
}
tmp_outdef << "<svg\n";
tmp_outdef << " xmlns:svg=\"http://www.w3.org/2000/svg\"\n";
tmp_outdef << " xmlns=\"http://www.w3.org/2000/svg\"\n";
tmp_outdef << " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n";
tmp_outdef << " xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n"; // needed for sodipodi:role
tmp_outdef << " version=\"1.0\"\n";
/* inclusive-inclusive, so the size is 1 more than the difference */
/*
This can cause problems later due to accuracy limits in the EMF. A high resolution
EMF might have a final W2Pscale[XY] of 0.074998, and adjusting the (integer) device size
by 1 will still not get it exactly to 0.075. Later when the font size is calculated it
can end up as 29.9992 or 22.4994 instead of the intended 30 or 22.5. This is handled by
snapping font sizes to the nearest .01. The best estimate is made by using both values.
*/
}
/* Adobe Illustrator files set mapmode to MM_ANISOTROPIC and somehow or other this
converts the rclFrame values from MM_HIMETRIC to MM_HIENGLISH, with another factor of 3 thrown
in for good measure. Ours not to question why...
*/
}
// Upper left corner, from header rclBounds, in device units, usually both 0, but not always
tmp_outdef <<
// d->defs holds any defines which are read in.
// Init the new emf_obj list elements to null, provided the
// dynamic allocation succeeded.
{
for( int i=0; i < d->n_obj; ++i )
} //if
} else {
}
break;
}
case U_EMR_POLYBEZIER:
{
dbg_str << "<!-- U_EMR_POLYBEZIER -->\n";
uint32_t i,j;
break;
tmp_str <<
"\n\tM " <<
tmp_str << "\n\tC ";
tmp_str <<
}
}
break;
}
case U_EMR_POLYGON:
{
dbg_str << "<!-- U_EMR_POLYGON -->\n";
uint32_t i;
break;
tmp_str <<
"\n\tM " <<
tmp_str <<
"\n\tL " <<
}
tmp_path << " z";
break;
}
case U_EMR_POLYLINE:
{
dbg_str << "<!-- U_EMR_POLYLINE -->\n";
uint32_t i;
break;
tmp_str <<
"\n\tM " <<
tmp_str <<
"\n\tL " <<
}
break;
}
case U_EMR_POLYBEZIERTO:
{
dbg_str << "<!-- U_EMR_POLYBEZIERTO -->\n";
uint32_t i,j;
tmp_path << "\n\tC ";
tmp_path <<
}
}
break;
}
case U_EMR_POLYLINETO:
{
dbg_str << "<!-- U_EMR_POLYLINETO -->\n";
uint32_t i;
tmp_path <<
"\n\tL " <<
}
break;
}
case U_EMR_POLYPOLYLINE:
case U_EMR_POLYPOLYGON:
{
dbg_str << "<!-- U_EMR_POLYPOLYLINE -->\n";
dbg_str << "<!-- U_EMR_POLYPOLYGON -->\n";
unsigned int n, i, j;
i = 0;
poly_path << "\n\tM " <<
i++;
poly_path << "\n\tL " <<
i++;
}
tmp_str << " z";
tmp_str << " \n";
}
break;
}
case U_EMR_SETWINDOWEXTEX:
{
dbg_str << "<!-- U_EMR_SETWINDOWEXTEX -->\n";
}
}
}
d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].sizeWnd.cx;
d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].sizeWnd.cy;
}
else {
}
/* scales logical to EMF pixels, but we need logical to Inkscape pixels */
break;
}
case U_EMR_SETWINDOWORGEX:
{
dbg_str << "<!-- U_EMR_SETWINDOWORGEX -->\n";
break;
}
case U_EMR_SETVIEWPORTEXTEX:
{
dbg_str << "<!-- U_EMR_SETVIEWPORTEXTEX -->\n";
}
}
}
d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].sizeWnd.cx;
d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].sizeWnd.cy;
}
else {
}
/* scales logical to EMF pixels, but we need logical to Inkscape pixels */
break;
}
case U_EMR_SETVIEWPORTORGEX:
{
dbg_str << "<!-- U_EMR_SETVIEWPORTORGEX -->\n";
break;
}
case U_EMR_EOF:
{
dbg_str << "<!-- U_EMR_EOF -->\n";
tmp_outsvg << "</g>\n";
tmp_outsvg << "</svg>\n";
OK=0;
break;
}
case U_EMR_SETMAPMODE:
{
dbg_str << "<!-- U_EMR_SETMAPMODE -->\n";
case U_MM_TEXT:
default:
// Use values from the header.
break;
case U_MM_LOMETRIC: // 1 LU = 0.1 mm
break;
case U_MM_HIMETRIC: // 1 LU = 0.01 mm
break;
case U_MM_LOENGLISH: // 1 LU = 0.1 in
break;
case U_MM_HIENGLISH: // 1 LU = 0.01 in
break;
case U_MM_TWIPS: // 1 LU = 1/1440 in
break;
case U_MM_ISOTROPIC: // ScaleIn[XY] should be set elsewhere by SETVIEWPORTEXTEX and SETWINDOWEXTEX
break;
case U_MM_ANISOTROPIC:
break;
}
break;
}
case U_EMR_SETPOLYFILLMODE:
{
dbg_str << "<!-- U_EMR_SETPOLYFILLMODE -->\n";
break;
}
case U_EMR_SETROP2:
{
dbg_str << "<!-- U_EMR_SETROP2 -->\n";
break;
}
case U_EMR_SETSTRETCHBLTMODE:
{
dbg_str << "<!-- U_EMR_SETSTRETCHBLTMODE -->\n";
break;
}
case U_EMR_SETTEXTALIGN:
{
dbg_str << "<!-- U_EMR_SETTEXTALIGN -->\n";
break;
}
case U_EMR_SETCOLORADJUSTMENT:
dbg_str << "<!-- U_EMR_SETCOLORADJUSTMENT -->\n";
break;
case U_EMR_SETTEXTCOLOR:
{
dbg_str << "<!-- U_EMR_SETTEXTCOLOR -->\n";
break;
}
case U_EMR_SETBKCOLOR:
{
dbg_str << "<!-- U_EMR_SETBKCOLOR -->\n";
break;
}
case U_EMR_MOVETOEX:
{
dbg_str << "<!-- U_EMR_MOVETOEX -->\n";
tmp_path <<
"\n\tM " <<
break;
}
case U_EMR_INTERSECTCLIPRECT:
{
dbg_str << "<!-- U_EMR_INTERSECTCLIPRECT -->\n";
clipset = true;
if ((rc.left == rc_old.left) && (rc.top == rc_old.top) && (rc.right == rc_old.right) && (rc.bottom == rc_old.bottom))
break;
tmp_rectangle << "\n<clipPath\n\tclipPathUnits=\"userSpaceOnUse\" ";
tmp_rectangle << "\n<rect ";
tmp_rectangle << "\n</clipPath>";
*(d->path) = "";
break;
}
case U_EMR_SAVEDC:
dbg_str << "<!-- U_EMR_SAVEDC -->\n";
if (d->level < EMF_MAX_DC) {
d->dc[d->level + 1].font_name = strdup(d->dc[d->level].font_name); // or memory access problems because font name pointer duplicated
}
}
break;
case U_EMR_RESTOREDC:
{
dbg_str << "<!-- U_EMR_RESTOREDC -->\n";
}
else {
}
if (d->dc[old_level].style.stroke_dash.dash && (old_level==0 || (old_level>0 && d->dc[old_level].style.stroke_dash.dash!=d->dc[old_level-1].style.stroke_dash.dash))){
}
}
old_level--;
}
break;
}
case U_EMR_SETWORLDTRANSFORM:
{
dbg_str << "<!-- U_EMR_SETWORLDTRANSFORM -->\n";
break;
}
{
dbg_str << "<!-- U_EMR_MODIFYWORLDTRANSFORM -->\n";
{
case U_MWT_IDENTITY:
break;
case U_MWT_LEFTMULTIPLY:
{
// d->dc[d->level].worldTransform = pEmr->xform * worldTransform;
float a13 = 0.0;
float a23 = 0.0;
float a33 = 1.0;
//float b13 = 0.0;
//float b23 = 0.0;
//float b33 = 1.0;
//float c13 = a11*b13 + a12*b23 + a13*b33;;
//float c23 = a21*b13 + a22*b23 + a23*b33;;
//float c33 = a31*b13 + a32*b23 + a33*b33;;
break;
}
case U_MWT_RIGHTMULTIPLY:
{
// d->dc[d->level].worldTransform = worldTransform * pEmr->xform;
float a13 = 0.0;
float a23 = 0.0;
float a33 = 1.0;
//float b13 = 0.0;
//float b23 = 0.0;
//float b33 = 1.0;
//float c13 = a11*b13 + a12*b23 + a13*b33;;
//float c23 = a21*b13 + a22*b23 + a23*b33;;
//float c33 = a31*b13 + a32*b23 + a33*b33;;
break;
}
// case MWT_SET:
default:
break;
}
break;
}
case U_EMR_SELECTOBJECT:
{
dbg_str << "<!-- U_EMR_SELECTOBJECT -->\n";
if (index & U_STOCK_OBJECT) {
switch (index) {
case U_NULL_BRUSH:
break;
case U_BLACK_BRUSH:
case U_DKGRAY_BRUSH:
case U_GRAY_BRUSH:
case U_LTGRAY_BRUSH:
case U_WHITE_BRUSH:
{
float val = 0;
switch (index) {
case U_BLACK_BRUSH:
break;
case U_DKGRAY_BRUSH:
break;
case U_GRAY_BRUSH:
break;
case U_LTGRAY_BRUSH:
break;
case U_WHITE_BRUSH:
break;
}
break;
}
case U_NULL_PEN:
break;
case U_BLACK_PEN:
case U_WHITE_PEN:
{
break;
}
}
} else {
{
case U_EMR_CREATEPEN:
select_pen(d, index);
break;
case U_EMR_CREATEMONOBRUSH:
select_brush(d, index);
break;
case U_EMR_EXTCREATEPEN:
select_extpen(d, index);
break;
select_font(d, index);
break;
}
}
}
break;
}
case U_EMR_CREATEPEN:
{
dbg_str << "<!-- U_EMR_CREATEPEN -->\n";
break;
}
{
dbg_str << "<!-- U_EMR_CREATEBRUSHINDIRECT -->\n";
break;
}
case U_EMR_DELETEOBJECT:
dbg_str << "<!-- U_EMR_DELETEOBJECT -->\n";
break;
case U_EMR_ANGLEARC:
dbg_str << "<!-- U_EMR_ANGLEARC -->\n";
break;
case U_EMR_ELLIPSE:
{
dbg_str << "<!-- U_EMR_ELLIPSE -->\n";
double cx = (l + r) / 2.0;
double cy = (t + b) / 2.0;
*(d->outsvg) += " <ellipse ";
*(d->outsvg) += "\n\t";
*(d->outsvg) += "/> \n";
*(d->path) = "";
break;
}
case U_EMR_RECTANGLE:
{
dbg_str << "<!-- U_EMR_RECTANGLE -->\n";
tmp_rectangle << "\n\tz";
break;
}
case U_EMR_ROUNDRECT:
{
dbg_str << "<!-- U_EMR_ROUNDRECT -->\n";
tmp_rectangle << "\n\tC " << l << ", " << t + (1-f)*cny << " " << l + (1-f)*cnx << ", " << t << " " << l + cnx << ", " << t << " ";
tmp_rectangle << "\n\tC " << r - (1-f)*cnx << ", " << t << " " << r << ", " << t + (1-f)*cny << " " << r << ", " << t + cny << " ";
tmp_rectangle << "\n\tC " << r << ", " << b - (1-f)*cny << " " << r - (1-f)*cnx << ", " << b << " " << r - cnx << ", " << b << " ";
tmp_rectangle << "\n\tC " << l + (1-f)*cnx << ", " << b << " " << l << ", " << b - (1-f)*cny << " " << l << ", " << b - cny << " ";
tmp_rectangle << "\n\tz";
break;
}
case U_EMR_ARC:
{
dbg_str << "<!-- U_EMR_ARC -->\n";
int f1;
tmp_path << "\n\tM " << pix_to_x_point(d, start.x, start.y) << "," << pix_to_y_point(d, start.x, start.y);
tmp_path << " A " << pix_to_x_point(d, size.x, size.y)/2.0 << "," << pix_to_y_point(d, size.x, size.y)/2.0 ;
tmp_path << " 0 ";
}
else {
dbg_str << "<!-- ARC record is invalid -->\n";
}
break;
}
case U_EMR_CHORD:
{
dbg_str << "<!-- U_EMR_CHORD -->\n";
int f1;
tmp_path << "\n\tM " << pix_to_x_point(d, start.x, start.y) << "," << pix_to_y_point(d, start.x, start.y);
tmp_path << " A " << pix_to_x_point(d, size.x, size.y)/2.0 << "," << pix_to_y_point(d, size.x, size.y)/2.0 ;
tmp_path << " 0 ";
tmp_path << " z ";
}
else {
dbg_str << "<!-- CHORD record is invalid -->\n";
}
break;
}
case U_EMR_PIE:
{
dbg_str << "<!-- U_EMR_PIE -->\n";
int f1;
tmp_path << "\n\tM " << pix_to_x_point(d, center.x, center.y) << "," << pix_to_y_point(d, center.x, center.y);
tmp_path << "\n\tL " << pix_to_x_point(d, start.x, start.y) << "," << pix_to_y_point(d, start.x, start.y);
tmp_path << " A " << pix_to_x_point(d, size.x, size.y)/2.0 << "," << pix_to_y_point(d, size.x, size.y)/2.0;
tmp_path << " 0 ";
tmp_path << " z ";
}
else {
dbg_str << "<!-- PIE record is invalid -->\n";
}
break;
}
case U_EMR_LINETO:
{
dbg_str << "<!-- U_EMR_LINETO -->\n";
tmp_path <<
"\n\tL " <<
break;
}
case U_EMR_ARCTO:
{
dbg_str << "<!-- U_EMR_ARCTO -->\n";
int f1;
// draw a line from current position to start
tmp_path << "\n\tL " << pix_to_x_point(d, start.x, start.y) << "," << pix_to_y_point(d, start.x, start.y);
tmp_path << "\n\tM " << pix_to_x_point(d, start.x, start.y) << "," << pix_to_y_point(d, start.x, start.y);
tmp_path << " A " << pix_to_x_point(d, size.x, size.y)/2.0 << "," << pix_to_y_point(d, size.x, size.y)/2.0 ;
tmp_path << " 0 ";
}
else {
dbg_str << "<!-- ARCTO record is invalid -->\n";
}
break;
}
case U_EMR_SETARCDIRECTION:
{
dbg_str << "<!-- U_EMR_SETARCDIRECTION -->\n";
}
break;
}
case U_EMR_SETMITERLIMIT:
{
dbg_str << "<!-- U_EMR_SETMITERLIMIT -->\n";
//The function takes a float but saves a 32 bit int in the U_EMR_SETMITERLIMIT record.
break;
}
case U_EMR_BEGINPATH:
{
dbg_str << "<!-- U_EMR_BEGINPATH -->\n";
// The next line should never be needed, should have been handled before main switch
*(d->path) = "";
break;
}
case U_EMR_ENDPATH:
{
dbg_str << "<!-- U_EMR_ENDPATH -->\n";
d->mask &= (0xFFFFFFFF - U_DRAW_ONLYTO); // clear the OnlyTo bit (it might not have been set), prevents any further path extension
break;
}
case U_EMR_CLOSEFIGURE:
{
dbg_str << "<!-- U_EMR_CLOSEFIGURE -->\n";
// EMF may contain multiple closefigures on one path
tmp_path << "\n\tz";
d->mask |= U_DRAW_CLOSED;
break;
}
case U_EMR_FILLPATH:
{
dbg_str << "<!-- U_EMR_FILLPATH -->\n";
if(!(d->mask & U_DRAW_CLOSED)){ // Close a path not explicitly closed by an EMRCLOSEFIGURE, otherwise fill makes no sense
tmp_path << "\n\tz";
d->mask |= U_DRAW_CLOSED;
}
d->drawtype = U_EMR_FILLPATH;
}
break;
}
case U_EMR_STROKEANDFILLPATH:
{
dbg_str << "<!-- U_EMR_STROKEANDFILLPATH -->\n";
if(!(d->mask & U_DRAW_CLOSED)){ // Close a path not explicitly closed by an EMRCLOSEFIGURE, otherwise fill makes no sense
tmp_path << "\n\tz";
d->mask |= U_DRAW_CLOSED;
}
}
break;
}
case U_EMR_STROKEPATH:
{
dbg_str << "<!-- U_EMR_STROKEPATH -->\n";
d->drawtype = U_EMR_STROKEPATH;
}
break;
}
case U_EMR_ABORTPATH:
{
dbg_str << "<!-- U_EMR_ABORTPATH -->\n";
*(d->path) = "";
d->drawtype = 0;
break;
}
case U_EMR_COMMENT:
{
dbg_str << "<!-- U_EMR_COMMENT -->\n";
if ( *szTxt) {
}
szTxt++;
}
}
tmp_outsvg << " <!-- \"";
tmp_outsvg << "\" -->\n";
}
break;
}
case U_EMR_EXTSELECTCLIPRGN:
{
dbg_str << "<!-- U_EMR_EXTSELECTCLIPRGN -->\n";
clipset = false;
break;
}
case U_EMR_BITBLT:
{
dbg_str << "<!-- U_EMR_BITBLT -->\n";
//source position within the bitmap, in pixels
int sw = 0; // extract all of the image
int sh = 0;
// Treat all nonImage bitblts as a rectangular write. Definitely not correct, but at
// least it leaves objects where the operations should have been.
// should be an application of a DIBPATTERNBRUSHPT, use a solid color instead
tmp_rectangle << "\n\tz";
d->mask |= U_DRAW_CLOSED; // Bitblit is not really open or closed, but we need it to fill, and this is the flag for that
}
else {
}
break;
}
case U_EMR_STRETCHBLT:
{
dbg_str << "<!-- U_EMR_STRETCHBLT -->\n";
// Always grab image, ignore modes.
//source position within the bitmap, in pixels
}
break;
}
case U_EMR_MASKBLT:
{
dbg_str << "<!-- U_EMR_MASKBLT -->\n";
// Always grab image, ignore masks and modes.
int sw = 0; // extract all of the image
int sh = 0;
}
break;
}
case U_EMR_STRETCHDIBITS:
{
// Some applications use multiple EMF operations, including multiple STRETCHDIBITS to create
// images with transparent regions. PowerPoint does this with rotated images, for instance.
// Parsing all of that to derive a single resultant image object is left for a later version
// of this code. In the meantime, every STRETCHDIBITS goes directly to an image. The Inkscape
// user can sort out transparency later using Gimp, if need be.
dbg_str << "<!-- U_EMR_STRETCHDIBITS -->\n";
break;
}
{
dbg_str << "<!-- U_EMR_EXTCREATEFONTINDIRECTW -->\n";
break;
}
case U_EMR_EXTTEXTOUTA:
case U_EMR_EXTTEXTOUTW:
case U_EMR_SMALLTEXTOUT:
{
dbg_str << "<!-- U_EMR_EXTTEXTOUTA/W -->\n";
int roff = sizeof(U_EMRSMALLTEXTOUT); //offset to the start of the variable fields, only used with U_EMR_SMALLTEXTOUT
int cChars;
}
else {
cChars = 0;
}
}
double dfact;
if (d->dc[d->level].textAlign & U_TA_BASEBIT){ dfact = 0.00; } // alignments 0x10 to U_TA_BASELINE 0x18
else if(d->dc[d->level].textAlign & U_TA_BOTTOM){ dfact = -0.35; } // alignments U_TA_BOTTOM 0x08 to 0x0E, factor is approximate
x += dfact * std::sin(d->dc[d->level].style.baseline_shift.value*M_PI/180.0)*fabs(d->dc[d->level].style.font_size.computed);
y += dfact * std::cos(d->dc[d->level].style.baseline_shift.value*M_PI/180.0)*fabs(d->dc[d->level].style.font_size.computed);
}
else {
}
/* These should be JUST ASCII, but they might not be...
If it holds Utf-8 or plain ASCII the first call will succeed.
If not, assume that it holds Latin1.
If that fails then someting is really screwed up!
*/
if(!dup_wt)dup_wt = U_Latin1ToUtf32le((char *) pEmr + pEmr->emrtext.offString, pEmr->emrtext.nChars, NULL);
}
dup_wt = U_Utf16leToUtf32le((uint16_t *)((char *) pEmr + pEmr->emrtext.offString), pEmr->emrtext.nChars, NULL);
}
else { // U_EMR_SMALLTEXTOUT
}
else {
}
}
msdepua(dup_wt); //convert everything in Microsoft's private use area. For Symbol, Wingdings, Dingbats
}
char *ansi_text;
// Empty string or starts with an invalid escape/control sequence, which is bogus text. Throw it out before g_markup_escape_text can make things worse
}
if (ansi_text) {
// gchar *p = ansi_text;
// while (*p) {
// if (*p < 32 || *p >= 127) {
// g_free(ansi_text);
// ansi_text = g_strdup("");
// break;
// }
// p++;
// }
// float text_rgb[3];
// sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), text_rgb );
// if (!d->dc[d->level].textColorSet) {
// d->dc[d->level].textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]),
// SP_COLOR_F_TO_U(text_rgb[1]),
// SP_COLOR_F_TO_U(text_rgb[2]));
// }
char tmp[128];
"fill:#%02x%02x%02x;",
//bool o = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);
(d->dc[d->level].style.font_weight.value >= SP_CSS_FONT_WEIGHT_500 && d->dc[d->level].style.font_weight.value <= SP_CSS_FONT_WEIGHT_900);
// EMF textalignment is a bit strange: 0x6 is center, 0x2 is right, 0x0 is left, the value 0x4 is also drawn left
int lcr = ((d->dc[d->level].textAlign & U_TA_CENTER) == U_TA_CENTER) ? 2 : ((d->dc[d->level].textAlign & U_TA_CENTER) == U_TA_LEFT) ? 0 : 1;
ts << "<text\n";
ts << " xml:space=\"preserve\"\n";
ts << " transform=\""
<< " " << x << " " << y << ")"
<< "\"\n";
}
ts << "><tspan sodipodi:role=\"line\"";
ts << " style=\""
<< tmp
<< "font-style:" << (i ? "italic" : "normal") << ";"
<< "font-weight:" << (b ? "bold" : "normal") << ";"
<< "\"\n";
ts << " >";
ts << escaped_text;
ts << "</tspan>";
ts << "</text>\n";
}
break;
}
case U_EMR_POLYBEZIER16:
{
dbg_str << "<!-- U_EMR_POLYBEZIER16 -->\n";
uint32_t i,j;
break;
tmp_str <<
"\n\tM " <<
tmp_str << "\n\tC ";
tmp_str <<
}
}
break;
}
case U_EMR_POLYGON16:
{
dbg_str << "<!-- U_EMR_POLYGON16 -->\n";
unsigned int i;
unsigned int first = 0;
// skip the first point?
tmp_poly << "\n\tM " <<
tmp_poly << "\n\tL " <<
}
tmp_path << "\n\tz";
d->mask |= U_DRAW_CLOSED;
break;
}
case U_EMR_POLYLINE16:
{
dbg_str << "<!-- U_EMR_POLYLINE16 -->\n";
uint32_t i;
break;
tmp_str <<
"\n\tM " <<
tmp_str <<
"\n\tL " <<
}
break;
}
case U_EMR_POLYBEZIERTO16:
{
dbg_str << "<!-- U_EMR_POLYBEZIERTO16 -->\n";
uint32_t i,j;
tmp_path << "\n\tC ";
tmp_path <<
}
}
break;
}
case U_EMR_POLYLINETO16:
{
dbg_str << "<!-- U_EMR_POLYLINETO16 -->\n";
uint32_t i;
tmp_path <<
"\n\tL " <<
}
break;
}
case U_EMR_POLYPOLYLINE16:
case U_EMR_POLYPOLYGON16:
{
dbg_str << "<!-- U_EMR_POLYPOLYLINE16 -->\n";
dbg_str << "<!-- U_EMR_POLYPOLYGON16 -->\n";
unsigned int n, i, j;
i = 0;
poly_path << "\n\tM " <<
i++;
poly_path << "\n\tL " <<
i++;
}
tmp_str << " z";
tmp_str << " \n";
}
break;
}
case U_EMR_CREATEMONOBRUSH:
{
dbg_str << "<!-- U_EMR_CREATEDIBPATTERNBRUSHPT -->\n";
break;
}
{
dbg_str << "<!-- U_EMR_CREATEDIBPATTERNBRUSHPT -->\n";
break;
}
case U_EMR_EXTCREATEPEN:
{
dbg_str << "<!-- U_EMR_EXTCREATEPEN -->\n";
break;
}
case U_EMR_SETICMMODE:
{
dbg_str << "<!-- U_EMR_SETICMMODE -->\n";
break;
}
// U_EMR_SMALLTEXTOUT is handled with U_EMR_EXTTEXTOUTA/W above
/* Gradient fill is doable for rectangles because those correspond to linear gradients. However,
the general case for the triangle fill, with a different color in each corner of the triangle,
has no SVG equivalent and cannot be easily emulated with SVG gradients. Except that so far
I (DM) have not been able to make an EMF with a rectangular gradientfill record which is not
completely toxic to other EMF readers. So far now, do nothing.
*/
default:
dbg_str << "<!-- U_EMR_??? -->\n";
break;
} //end of switch
// When testing, uncomment the following to place a comment for each processed EMR record in the SVG
// *(d->outsvg) += dbg_str.str().c_str();
} //end of while
// When testing, uncomment the following to show the final SVG derived from the EMF
//std::cout << *(d->outsvg) << std::endl;
(void) emr_properties(U_EMR_INVALID); // force the release of the lookup table memory, returned value is irrelevant
return 1;
}
// Aldus Placeable Header ===================================================
// Since we are a 32bit app, we have to be sure this structure compiles to
// be identical to a 16 bit app's version. To do this, we use the #pragma
// to adjust packing, we use a uint16_t for the hmf handle, and a SMALL_RECT
// for the bbox rectangle.
#pragma pack( 2 )
typedef struct _SMALL_RECT {
} SMALL_RECT, *PSMALL_RECT;
typedef struct
{
} APMHEADER, *PAPMHEADER;
}
}
{
memset(&d, 0, sizeof(d));
}
d.dc[0].font_name = strdup("Arial"); // Default font, EMF spec says device can pick whatever it wants
return NULL;
}
d.mask = 0;
d.drawtype = 0;
d.dwRop2 = U_R2_COPYPEN;
d.dwRop3 = 0;
d.W2PscaleX = 1.0;
d.W2PscaleY = 1.0;
char *contents;
if (d.pDesc)
// std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), strlen(d.outsvg->c_str()), TRUE);
delete d.outsvg;
delete d.path;
delete d.outdef;
delete d.defs;
if (d.emf_obj) {
int i;
for (i=0; i<d.n_obj; i++)
delete_object(&d, i);
delete[] d.emf_obj;
}
for(int i=0; i<=d.level;i++){
}
return doc;
}
void
{
/* EMF in */
"<id>org.inkscape.input.emf</id>\n"
"<input>\n"
"<extension>.emf</extension>\n"
"<output_extension>org.inkscape.output.emf</output_extension>\n"
"</input>\n"
"</inkscape-extension>", new Emf());
/* EMF out */
"<id>org.inkscape.output.emf</id>\n"
"<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n"
"<param name=\"TnrToSymbol\" gui-text=\"" N_("Map Unicode to Symbol font") "\" type=\"boolean\">true</param>\n"
"<param name=\"TnrToWingdings\" gui-text=\"" N_("Map Unicode to Wingdings") "\" type=\"boolean\">true</param>\n"
"<param name=\"TnrToZapfDingbats\" gui-text=\"" N_("Map Unicode to Zapf Dingbats") "\" type=\"boolean\">true</param>\n"
"<param name=\"UsePUA\" gui-text=\"" N_("Use MS Unicode PUA (0xF020-0xF0FF) for converted characters") "\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTCharPos\" gui-text=\"" N_("Compensate for PPT font bug") "\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTDashLine\" gui-text=\"" N_("Convert dashed/dotted lines to single lines") "\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTGrad2Polys\" gui-text=\"" N_("Convert gradients to colored polygon series") "\" type=\"boolean\">false</param>\n"
"<param name=\"FixPPTPatternAsHatch\" gui-text=\"" N_("Map all fill patterns to standard EMF hatches") "\" type=\"boolean\">false</param>\n"
"<output>\n"
"<extension>.emf</extension>\n"
"</output>\n"
"</inkscape-extension>", new Emf());
return;
}
} } } /* namespace Inkscape, Extension, Implementation */
/*
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 :