diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp
index 0e231a60884e10008b1675510b358ea8f4a12331..6e0a7bf0b6e13bd59de1e24c36813617ee62ad47 100644 (file)
#include "libnr/nr-point-matrix-ops.h"
#include "libnr/nr-rect.h"
#include "libnr/nr-matrix.h"
-#include "libnr/nr-matrix-ops.h"
+#include "libnr/nr-matrix-ops.h"
#include "libnr/nr-matrix-scale-ops.h"
#include "libnr/nr-matrix-translate-ops.h"
#include "libnr/nr-scale-translate-ops.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-path.h"
#include "libnr/nr-pixblock.h"
+#include <libnr/n-art-bpath-2geom.h>
#include "display/canvas-bpath.h"
#include "sp-item.h"
#if !defined(_WIN32) && !defined(__WIN32__)
(void) signal(SIGPIPE, SIG_DFL);
#endif
- return;
+ return;
}
d.y1 = _height;
} else {
SPItem* doc_item = SP_ITEM(sp_document_root(doc));
- sp_item_invoke_bbox(doc_item, &d, from_2geom(sp_item_i2r_affine(doc_item)), TRUE);
+ sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
}
d.x0 *= IN_PER_PX;
// Get a Reference DC
HDC hScreenDC = GetDC( NULL );
- // Create the Metafile
- if (PrintWin32::is_os_wide())
- hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, NULL );
+ // Get the physical characteristics of the reference DC
+ int PixelsX = GetDeviceCaps( hScreenDC, HORZRES );
+ int PixelsY = GetDeviceCaps( hScreenDC, VERTRES );
+ int MMX = GetDeviceCaps( hScreenDC, HORZSIZE );
+ int MMY = GetDeviceCaps( hScreenDC, VERTSIZE );
+
+ CHAR buff[1024];
+ ZeroMemory(buff, sizeof(buff));
+ snprintf(buff, sizeof(buff)-1, "Inkscape %s (%s)", INKSCAPE_VERSION, __DATE__);
+ INT len = strlen(buff);
+ CHAR *p1 = strrchr(ansi_uri, '\\');
+ CHAR *p2 = strrchr(ansi_uri, '/');
+ CHAR *p = MAX(p1, p2);
+ if (p)
+ p++;
else
- hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, NULL );
+ p = ansi_uri;
+ snprintf(buff+len+1, sizeof(buff)-len-2, "%s", p);
+
+ // Create the Metafile
+ if (PrintWin32::is_os_wide()) {
+ WCHAR wbuff[1024];
+ ZeroMemory(wbuff, sizeof(wbuff));
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buff, sizeof(buff)/sizeof(buff[0]), wbuff, sizeof(wbuff)/sizeof(wbuff[0]));
+ hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, wbuff );
+ }
+ else {
+ hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, buff );
+ }
// Release the reference DC
ReleaseDC( NULL, hScreenDC );
SetMapMode( hdc, MM_ANISOTROPIC );
// Set the Windows extent
- SetWindowExtEx( hdc, (int) (dwInchesX*dwDPI), (int) (dwInchesY*dwDPI), NULL );
+ int windowextX = (int) ceil(dwInchesX*dwDPI);
+ int windowextY = (int) ceil(dwInchesY*dwDPI);
+ SetWindowExtEx( hdc, windowextX, windowextY, NULL );
// Set the viewport extent to reflect
// dwInchesX" x dwInchesY" in device units
- SetViewportExtEx( hdc,
- (int) ((float) dwInchesX*25.4f*PX_PER_MM),
- (int) ((float) dwInchesY*25.4f*PX_PER_MM),
- NULL );
+ int viewportextX = (int)((float)dwInchesX*25.4f*(float)PixelsX/(float)MMX);
+ int viewportextY = (int)((float)dwInchesY*25.4f*(float)PixelsY/(float)MMY);
+ SetViewportExtEx( hdc, viewportextX, viewportextY, NULL );
+
+ if (1) {
+ snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY);
+ GdiComment(hdc, strlen(buff), (BYTE*) buff);
+
+ snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN);
+ GdiComment(hdc, strlen(buff), (BYTE*) buff);
+ }
SetRect( &rc, 0, 0, (int) ceil(dwInchesX*dwDPI), (int) ceil(dwInchesY*dwDPI) );
g_free(unicode_fn);
m_tr_stack.push( NR::scale(1, -1) * NR::translate(0, sp_document_height(doc)));
+
return 0;
}
unsigned int
PrintEmfWin32::fill(Inkscape::Extension::Print *mod,
- const_NRBPath const *bpath, NR::Matrix const *transform, SPStyle const *style,
+ Geom::PathVector const &pathv, NR::Matrix const *transform, SPStyle const *style,
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
{
if (!hdc) return 0;
return 0;
}
- fill_path = copy_bpath( bpath->path );
+ NArtBpath * bpath = BPath_from_2GeomPath(pathv);
+ fill_path = copy_bpath( bpath );
+ g_free(bpath);
fill_transform = tf;
fill_pbox = *pbox;
unsigned int
PrintEmfWin32::stroke (Inkscape::Extension::Print *mod,
- const const_NRBPath *bpath, const NR::Matrix *transform, const SPStyle *style,
+ Geom::PathVector const &pathv, const NR::Matrix *transform, const SPStyle *style,
const NRRect *pbox, const NRRect *dbox, const NRRect *bbox)
{
if (!hdc) return 0;
NR::Matrix tf = m_tr_stack.top();
- stroke_and_fill = ( cmp_bpath( bpath->path, fill_path ) == 0 );
+ NArtBpath * bpath = BPath_from_2GeomPath(pathv);
+
+ stroke_and_fill = ( cmp_bpath( bpath, fill_path ) == 0 );
if (!stroke_and_fill) {
flush_fill(); // flush any pending fills
return 0;
}
- print_bpath(bpath->path, &tf, pbox);
+ print_bpath(bpath, &tf, pbox);
if (stroke_and_fill) {
if (!simple_shape)
StrokePath( hdc );
}
+ g_free(bpath);
destroy_pen();
return 0;
@@ -649,14 +689,26 @@ PrintEmfWin32::print_simple_shape(const NArtBpath *bpath, const NR::Matrix *tran
}
bool done = false;
- bool circular = (lpPoints[0].x == lpPoints[i-1].x) && (lpPoints[0].y == lpPoints[i-1].y);
+ bool closed = (lpPoints[0].x == lpPoints[i-1].x) && (lpPoints[0].y == lpPoints[i-1].y);
bool polygon = false;
+ bool polyline = false;
+ bool rectangle = false;
bool ellipse = false;
- if (moves == 1 && moves+lines == nodes && circular) {
+ if (moves == 1 && moves+lines == nodes && closed) {
polygon = true;
+ if (nodes==5) {
+ 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;
+ }
+ }
+ }
+ else if (moves == 1 && moves+lines == nodes) {
+ polyline = true;
}
- else if (moves == 1 && nodes == 5 && moves+curves == nodes && circular) {
+ else if (moves == 1 && nodes == 5 && moves+curves == nodes && closed) {
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 &&
@@ -668,7 +720,7 @@ PrintEmfWin32::print_simple_shape(const NArtBpath *bpath, const NR::Matrix *tran
}
}
- if (polygon || ellipse) {
+ if (polygon || polyline || ellipse) {
HPEN hpenTmp = NULL;
HPEN hpenOld = NULL;
HBRUSH hbrushTmp = NULL;
@@ -686,7 +738,13 @@ PrintEmfWin32::print_simple_shape(const NArtBpath *bpath, const NR::Matrix *tran
}
if (polygon) {
- Polygon( hdc, lpPoints, nodes );
+ if (rectangle)
+ Rectangle( hdc, lpPoints[0].x, lpPoints[0].y, lpPoints[2].x, lpPoints[2].y );
+ else
+ Polygon( hdc, lpPoints, nodes );
+ }
+ else if (polyline) {
+ Polyline( hdc, lpPoints, nodes );
}
else if (ellipse) {
Ellipse( hdc, lpPoints[6].x, lpPoints[3].y, lpPoints[0].x, lpPoints[9].y);
@@ -825,21 +883,17 @@ PrintEmfWin32::text(Inkscape::Extension::Print *mod, char const *text, NR::Point
lf->lfEscapement = 0;
lf->lfOrientation = 0;
lf->lfWeight =
- style->font_weight.value == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_NORMAL ? FW_NORMAL :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD ? FW_BOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_LIGHTER ? FW_EXTRALIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLDER ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
FW_NORMAL;
- lf->lfItalic = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC);
+ lf->lfItalic = (style->font_style.computed == SP_CSS_FONT_STYLE_ITALIC);
lf->lfUnderline = style->text_decoration.underline;
lf->lfStrikeOut = style->text_decoration.line_through;
lf->lfCharSet = DEFAULT_CHARSET;
@@ -865,21 +919,17 @@ PrintEmfWin32::text(Inkscape::Extension::Print *mod, char const *text, NR::Point
lf->lfEscapement = 0;
lf->lfOrientation = 0;
lf->lfWeight =
- style->font_weight.value == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_NORMAL ? FW_NORMAL :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD ? FW_BOLD :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_LIGHTER ? FW_EXTRALIGHT :
- style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLDER ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
FW_NORMAL;
- lf->lfItalic = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC);
+ lf->lfItalic = (style->font_style.computed == SP_CSS_FONT_STYLE_ITALIC);
lf->lfUnderline = style->text_decoration.underline;
lf->lfStrikeOut = style->text_decoration.line_through;
lf->lfCharSet = DEFAULT_CHARSET;
@@ -902,10 +952,13 @@ PrintEmfWin32::text(Inkscape::Extension::Print *mod, char const *text, NR::Point
sp_color_get_rgb_floatv( &style->fill.value.color, rgb );
SetTextColor(hdc, RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]));
- int align =
- style->text_align.value == SP_CSS_TEXT_ALIGN_RIGHT ? TA_RIGHT :
- style->text_align.value == SP_CSS_TEXT_ALIGN_CENTER ? TA_CENTER : TA_LEFT;
- SetTextAlign(hdc, TA_BASELINE | align);
+ // 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 EMF text alignment must always be TA_BASELINE|TA_LEFT.
+ SetTextAlign(hdc, TA_BASELINE | TA_LEFT);
+
+ // Transparent text background
SetBkMode(hdc, TRANSPARENT);
NR::Matrix tf = m_tr_stack.top();