~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/extension/internal/win32.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define __SP_MODULE_WIN32_C__
2
 
 
3
 
/*
4
 
 * Windows stuff
5
 
 *
6
 
 * Author:
 
1
/** @file
 
2
 * @brief Windows-specific stuff
 
3
 */
 
4
/* Author:
7
5
 *   Lauris Kaplinski <lauris@kaplinski.com>
8
6
 *
9
7
 * This code is in public domain
10
8
 */
11
9
 
 
10
#ifdef WIN32
 
11
 
12
12
#ifdef HAVE_CONFIG_H
13
13
# include "config.h"
14
14
#endif
15
15
 
16
16
#include <glib/gmem.h>
17
17
#include <libnr/nr-macros.h>
18
 
#include <libnr/nr-matrix.h>
 
18
#include <2geom/transforms.h>
19
19
 
20
20
#include "display/nr-arena-item.h"
21
21
#include "display/nr-arena.h"
22
22
#include "document.h"
23
23
 
24
24
#include "win32.h"
25
 
#include "system.h"
 
25
#include "extension/system.h"
26
26
#include "extension/print.h"
27
27
#include <gtk/gtk.h>
28
28
 
40
40
static void
41
41
my_gdk_event_handler (GdkEvent *event)
42
42
{
43
 
        if (SPWin32Modal) {
44
 
                /* Win32 widget is modal, filter events */
45
 
                switch (event->type) {
46
 
                case GDK_NOTHING:
47
 
                case GDK_DELETE:
48
 
                case GDK_SCROLL:
49
 
                case GDK_BUTTON_PRESS:
50
 
                case GDK_2BUTTON_PRESS:
51
 
                case GDK_3BUTTON_PRESS:
52
 
                case GDK_BUTTON_RELEASE:
53
 
                case GDK_KEY_PRESS:
54
 
                case GDK_KEY_RELEASE:
55
 
                case GDK_DRAG_STATUS:
56
 
                case GDK_DRAG_ENTER:
57
 
                case GDK_DRAG_LEAVE:
58
 
                case GDK_DRAG_MOTION:
59
 
                case GDK_DROP_START:
60
 
                case GDK_DROP_FINISHED:
61
 
                        return;
62
 
                        break;
63
 
                default:
64
 
                        break;
65
 
                }
66
 
        }
67
 
        gtk_main_do_event (event);
 
43
    if (SPWin32Modal) {
 
44
        /* Win32 widget is modal, filter events */
 
45
        switch (event->type) {
 
46
        case GDK_NOTHING:
 
47
        case GDK_DELETE:
 
48
        case GDK_SCROLL:
 
49
        case GDK_BUTTON_PRESS:
 
50
        case GDK_2BUTTON_PRESS:
 
51
        case GDK_3BUTTON_PRESS:
 
52
        case GDK_BUTTON_RELEASE:
 
53
        case GDK_KEY_PRESS:
 
54
        case GDK_KEY_RELEASE:
 
55
        case GDK_DRAG_STATUS:
 
56
        case GDK_DRAG_ENTER:
 
57
        case GDK_DRAG_LEAVE:
 
58
        case GDK_DRAG_MOTION:
 
59
        case GDK_DROP_START:
 
60
        case GDK_DROP_FINISHED:
 
61
            return;
 
62
            break;
 
63
        default:
 
64
            break;
 
65
        }
 
66
    }
 
67
    gtk_main_do_event (event);
68
68
}
69
69
 
70
70
void
71
71
PrintWin32::main_init (int argc, char **argv, const char *name)
72
72
{
73
 
        gdk_event_handler_set ((GdkEventFunc) my_gdk_event_handler, NULL, NULL);
 
73
    gdk_event_handler_set ((GdkEventFunc) my_gdk_event_handler, NULL, NULL);
74
74
}
75
75
 
76
76
void
87
87
static VOID CALLBACK
88
88
my_timer (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
89
89
{
90
 
        int cdown = 0;
91
 
        while ((cdown++ < SP_FOREIGN_MAX_ITER) && gdk_events_pending ()) {
92
 
                gtk_main_iteration_do (FALSE);
93
 
        }
94
 
        gtk_main_iteration_do (FALSE);
 
90
    int cdown = 0;
 
91
    while ((cdown++ < SP_FOREIGN_MAX_ITER) && gdk_events_pending ()) {
 
92
        gtk_main_iteration_do (FALSE);
 
93
    }
 
94
    gtk_main_iteration_do (FALSE);
95
95
}
96
96
 
97
97
 
100
100
gboolean
101
101
PrintWin32::is_os_wide()
102
102
{
103
 
        static gboolean initialized = FALSE;
104
 
        static gboolean is_wide = FALSE;
105
 
        static OSVERSIONINFOA osver;
106
 
 
107
 
        if ( !initialized )
108
 
        {
109
 
                BOOL result;
110
 
 
111
 
                initialized = TRUE;
112
 
 
113
 
                memset (&osver, 0, sizeof(OSVERSIONINFOA));
114
 
                osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
115
 
                result = GetVersionExA (&osver);
116
 
                if (result)
117
 
                {
118
 
                        if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
119
 
                                is_wide = TRUE;
120
 
                }
121
 
                // If we can't even call to get the version, fall back to ANSI API
122
 
        }
123
 
 
124
 
        return is_wide;
 
103
    static gboolean initialized = FALSE;
 
104
    static gboolean is_wide = FALSE;
 
105
    static OSVERSIONINFOA osver;
 
106
 
 
107
    if ( !initialized )
 
108
    {
 
109
        BOOL result;
 
110
 
 
111
        initialized = TRUE;
 
112
 
 
113
        memset (&osver, 0, sizeof(OSVERSIONINFOA));
 
114
        osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
 
115
        result = GetVersionExA (&osver);
 
116
        if (result)
 
117
        {
 
118
            if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
 
119
                is_wide = TRUE;
 
120
        }
 
121
        // If we can't even call to get the version, fall back to ANSI API
 
122
    }
 
123
 
 
124
    return is_wide;
125
125
}
126
126
 
127
127
 
129
129
 
130
130
PrintWin32::PrintWin32 (void)
131
131
{
132
 
        /* Nothing here */
 
132
    /* Nothing here */
133
133
}
134
134
 
135
135
 
136
136
PrintWin32::~PrintWin32 (void)
137
137
{
138
 
        DeleteDC (_hDC);
 
138
    DeleteDC (_hDC);
139
139
}
140
140
 
141
141
 
146
146
print_hook (HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
147
147
{
148
148
#if 0
149
 
        int cdown = 0;
150
 
        while ((cdown++ < SP_FOREIGN_MAX_ITER) && gdk_events_pending ()) {
151
 
                gtk_main_iteration_do (FALSE);
152
 
        }
153
 
        gtk_main_iteration_do (FALSE);
 
149
    int cdown = 0;
 
150
    while ((cdown++ < SP_FOREIGN_MAX_ITER) && gdk_events_pending ()) {
 
151
        gtk_main_iteration_do (FALSE);
 
152
    }
 
153
    gtk_main_iteration_do (FALSE);
154
154
#endif
155
 
        return 0;
 
155
    return 0;
156
156
}
157
157
 
158
158
unsigned int
159
159
PrintWin32::setup (Inkscape::Extension::Print *mod)
160
160
{
161
 
        HRESULT res;
162
 
        PRINTDLG pd = {
163
 
                sizeof (PRINTDLG),
164
 
                NULL, /* hwndOwner */
165
 
                NULL, /* hDevMode */
166
 
                NULL, /* hDevNames */
167
 
                NULL, /* hDC */
168
 
                PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE, /* Flags */
169
 
                1, 1, 1, 1, /* nFromPage, nToPage, nMinPage, nMaxPage */
170
 
                1, /* nCoies */
171
 
                NULL, /* hInstance */
172
 
                0, /* lCustData */
173
 
                NULL, NULL, NULL, NULL, NULL, NULL
174
 
        };
175
 
        UINT_PTR timer;
176
 
 
177
 
        SPWin32Modal = TRUE;
178
 
        pd.Flags |= PD_ENABLEPRINTHOOK;
179
 
        pd.lpfnPrintHook = print_hook;
180
 
        timer = SetTimer (NULL, 0, 40, my_timer);
181
 
 
182
 
        res = PrintDlg (&pd);
183
 
 
184
 
        KillTimer (NULL, timer);
185
 
        SPWin32Modal = FALSE;
186
 
 
187
 
        if (!res) return FALSE;
188
 
 
189
 
        _hDC = pd.hDC;
 
161
    HRESULT res;
 
162
    PRINTDLG pd = {
 
163
        sizeof (PRINTDLG),
 
164
        NULL, /* hwndOwner */
 
165
        NULL, /* hDevMode */
 
166
        NULL, /* hDevNames */
 
167
        NULL, /* hDC */
 
168
        PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE, /* Flags */
 
169
        1, 1, 1, 1, /* nFromPage, nToPage, nMinPage, nMaxPage */
 
170
        1, /* nCoies */
 
171
        NULL, /* hInstance */
 
172
        0, /* lCustData */
 
173
        NULL, NULL, NULL, NULL, NULL, NULL
 
174
    };
 
175
    UINT_PTR timer;
 
176
 
 
177
    SPWin32Modal = TRUE;
 
178
    pd.Flags |= PD_ENABLEPRINTHOOK;
 
179
    pd.lpfnPrintHook = print_hook;
 
180
    timer = SetTimer (NULL, 0, 40, my_timer);
 
181
 
 
182
    res = PrintDlg (&pd);
 
183
 
 
184
    KillTimer (NULL, timer);
 
185
    SPWin32Modal = FALSE;
 
186
 
 
187
    if (!res) return FALSE;
 
188
 
 
189
    _hDC = pd.hDC;
190
190
 
191
191
#if 0
192
 
        caps = GetDeviceCaps (_hDC, RASTERCAPS);
193
 
        if (caps & RC_BANDING) {
194
 
                printf ("needs banding\n");
195
 
        }
196
 
        if (caps & RC_BITBLT) {
197
 
                printf ("does bitblt\n");
198
 
        }
199
 
        if (caps & RC_DIBTODEV) {
200
 
                printf ("does dibtodev\n");
201
 
        }
202
 
        if (caps & RC_STRETCHDIB) {
203
 
                printf ("does stretchdib\n");
204
 
        }
 
192
    caps = GetDeviceCaps (_hDC, RASTERCAPS);
 
193
    if (caps & RC_BANDING) {
 
194
        printf ("needs banding\n");
 
195
    }
 
196
    if (caps & RC_BITBLT) {
 
197
        printf ("does bitblt\n");
 
198
    }
 
199
    if (caps & RC_DIBTODEV) {
 
200
        printf ("does dibtodev\n");
 
201
    }
 
202
    if (caps & RC_STRETCHDIB) {
 
203
        printf ("does stretchdib\n");
 
204
    }
205
205
#endif
206
 
        if (pd.hDevMode) {
207
 
                DEVMODE *devmodep;
208
 
                devmodep = (DEVMODE *)pd.hDevMode;
209
 
                if (devmodep->dmFields & DM_ORIENTATION) {
210
 
                        _landscape = (devmodep->dmOrientation == DMORIENT_LANDSCAPE);
211
 
                }
212
 
        }
 
206
    if (pd.hDevMode) {
 
207
        DEVMODE *devmodep;
 
208
        devmodep = (DEVMODE *)pd.hDevMode;
 
209
        if (devmodep->dmFields & DM_ORIENTATION) {
 
210
            _landscape = (devmodep->dmOrientation == DMORIENT_LANDSCAPE);
 
211
        }
 
212
    }
213
213
 
214
 
        return TRUE;
 
214
    return TRUE;
215
215
}
216
216
 
217
217
unsigned int
218
218
PrintWin32::begin (Inkscape::Extension::Print *mod, SPDocument *doc)
219
219
{
220
 
        DOCINFO di = {
221
 
                sizeof (DOCINFO),
222
 
                NULL, /* lpszDocName */
223
 
                NULL, /* lpszOutput */
224
 
                NULL, /* lpszDatatype */
225
 
                0 /* DI_APPBANDING */ /* fwType */
226
 
        };
227
 
        int res;
228
 
 
229
 
        _PageWidth = sp_document_width (doc);
230
 
        _PageHeight = sp_document_height (doc);
231
 
 
232
 
        di.lpszDocName = SP_DOCUMENT_NAME (doc);
233
 
 
234
 
        SPWin32Modal = TRUE;
235
 
 
236
 
        res = StartDoc (_hDC, &di);
237
 
        res = StartPage (_hDC);
238
 
 
239
 
        SPWin32Modal = FALSE;
240
 
 
241
 
        return 0;
 
220
    DOCINFO di = {
 
221
        sizeof (DOCINFO),
 
222
        NULL, /* lpszDocName */
 
223
        NULL, /* lpszOutput */
 
224
        NULL, /* lpszDatatype */
 
225
        0 /* DI_APPBANDING */ /* fwType */
 
226
    };
 
227
    int res;
 
228
 
 
229
    _PageWidth = sp_document_width (doc);
 
230
    _PageHeight = sp_document_height (doc);
 
231
 
 
232
    di.lpszDocName = SP_DOCUMENT_NAME (doc);
 
233
 
 
234
    SPWin32Modal = TRUE;
 
235
 
 
236
    res = StartDoc (_hDC, &di);
 
237
    res = StartPage (_hDC);
 
238
 
 
239
    SPWin32Modal = FALSE;
 
240
 
 
241
    return 0;
242
242
}
243
243
 
244
244
unsigned int
245
245
PrintWin32::finish (Inkscape::Extension::Print *mod)
246
246
{
247
 
        int dpiX, dpiY;
248
 
        int pPhysicalWidth, pPhysicalHeight;
249
 
        int pPhysicalOffsetX, pPhysicalOffsetY;
250
 
        int pPrintableWidth, pPrintableHeight;
251
 
        float scalex, scaley;
252
 
        int x0, y0, x1, y1;
253
 
        int width, height;
254
 
        NRMatrix affine;
255
 
        unsigned char *px;
256
 
        int sheight, row;
257
 
        BITMAPINFO bmInfo = {
258
 
                {
259
 
                        sizeof (BITMAPINFOHEADER), // bV4Size
260
 
                        64,      // biWidth
261
 
                        64,      // biHeight
262
 
                        1,       // biPlanes
263
 
                        32,      // biBitCount
264
 
                        BI_RGB,  // biCompression
265
 
                        0,       // biSizeImage
266
 
                        2835,    // biXPelsPerMeter
267
 
                        2835,    // biYPelsPerMeter
268
 
                        0,       // biClrUsed
269
 
                        0        // biClrImportant
270
 
                },
271
 
                { { 0, 0, 0, 0 } } // bmiColors
272
 
        };
273
 
        //RECT wrect;
274
 
        int res;
275
 
 
276
 
        SPWin32Modal = TRUE;
277
 
 
278
 
        // Number of pixels per logical inch
279
 
        dpiX = (int) GetDeviceCaps (_hDC, LOGPIXELSX);
280
 
        dpiY = (int) GetDeviceCaps (_hDC, LOGPIXELSY);
281
 
        // Size in pixels of the printable area
282
 
        pPhysicalWidth = GetDeviceCaps (_hDC, PHYSICALWIDTH);
283
 
        pPhysicalHeight = GetDeviceCaps (_hDC, PHYSICALHEIGHT);
284
 
        // Top left corner of prontable area
285
 
        pPhysicalOffsetX = GetDeviceCaps (_hDC, PHYSICALOFFSETX);
286
 
        pPhysicalOffsetY = GetDeviceCaps (_hDC, PHYSICALOFFSETY);
287
 
        // Size in pixels of the printable area
288
 
        pPrintableWidth = GetDeviceCaps (_hDC, HORZRES);
289
 
        pPrintableHeight = GetDeviceCaps (_hDC, VERTRES);
290
 
 
291
 
        // Scaling from document to device
292
 
        scalex = dpiX / 72.0;
293
 
        scaley = dpiY / 72.0;
294
 
 
295
 
        // We simply map document 0,0 to physical page 0,0
296
 
        affine.c[0] = scalex / 1.25;
297
 
        affine.c[1] = 0.0;
298
 
        affine.c[2] = 0.0;
299
 
        affine.c[3] = scaley / 1.25;
300
 
        affine.c[4] = 0.0;
301
 
        affine.c[5] = 0.0;
302
 
 
303
 
        nr_arena_item_set_transform (mod->root, &affine);
304
 
 
305
 
        // Calculate printable area in device coordinates
306
 
        x0 = pPhysicalOffsetX;
307
 
        y0 = pPhysicalOffsetY;
308
 
        x1 = x0 + pPrintableWidth;
309
 
        y1 = y0 + pPrintableHeight;
310
 
        x1 = MIN (x1, (int) (_PageWidth * scalex));
311
 
        y1 = MIN (y1, (int) (_PageHeight * scaley));
312
 
 
313
 
        width = x1 - x0;
314
 
        height = y1 - y0;
315
 
 
316
 
        px = g_new (unsigned char, 4 * 64 * width);
317
 
        sheight = 64;
318
 
 
319
 
        /* Printing goes here */
320
 
        for (row = 0; row < height; row += 64) {
321
 
                NRPixBlock pb;
322
 
                NRRectL bbox;
323
 
                NRGC gc(NULL);
324
 
                int num_rows;
325
 
                int i;
326
 
 
327
 
                num_rows = sheight;
328
 
                if ((row + num_rows) > height) num_rows = height - row;
329
 
 
330
 
                /* Set area of interest */
331
 
                bbox.x0 = x0;
332
 
                bbox.y0 = y0 + row;
333
 
                bbox.x1 = bbox.x0 + width;
334
 
                bbox.y1 = bbox.y0 + num_rows;
335
 
                /* Update to renderable state */
336
 
                nr_matrix_set_identity (&gc.transform);
337
 
                nr_arena_item_invoke_update (mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
338
 
 
339
 
                nr_pixblock_setup_extern (&pb, NR_PIXBLOCK_MODE_R8G8B8A8N, bbox.x0, bbox.y0, bbox.x1, bbox.y1, px, 4 * (bbox.x1 - bbox.x0), FALSE, FALSE);
340
 
 
341
 
                /* Blitter goes here */
342
 
                bmInfo.bmiHeader.biWidth = bbox.x1 - bbox.x0;
343
 
                bmInfo.bmiHeader.biHeight = -(bbox.y1 - bbox.y0);
344
 
 
345
 
                memset (px, 0xff, 4 * num_rows * width);
346
 
                /* Render */
347
 
                nr_arena_item_invoke_render (NULL, mod->root, &bbox, &pb, 0);
348
 
 
349
 
                /* Swap red and blue channels; we use RGBA, whereas
350
 
                 * the Win32 GDI uses BGRx.
351
 
                 */
352
 
                for ( i = 0 ; i < num_rows * width ; i++ ) {
353
 
                        unsigned char temp=px[i*4];
354
 
                        px[i*4] = px[i*4+2];
355
 
                        px[i*4+2] = temp;
356
 
                }
357
 
 
358
 
                SetStretchBltMode(_hDC, COLORONCOLOR);
359
 
                res = StretchDIBits (_hDC,
360
 
                                                bbox.x0 - x0, bbox.y0 - y0, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0,
361
 
                                                0, 0, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0,
362
 
                                                px,
363
 
                                                &bmInfo,
 
247
    int dpiX, dpiY;
 
248
    int pPhysicalWidth, pPhysicalHeight;
 
249
    int pPhysicalOffsetX, pPhysicalOffsetY;
 
250
    int pPrintableWidth, pPrintableHeight;
 
251
    float scalex, scaley;
 
252
    int x0, y0, x1, y1;
 
253
    int width, height;
 
254
    unsigned char *px;
 
255
    int sheight, row;
 
256
    BITMAPINFO bmInfo = {
 
257
        {
 
258
            sizeof (BITMAPINFOHEADER), // bV4Size
 
259
            64,      // biWidth
 
260
            64,      // biHeight
 
261
            1,       // biPlanes
 
262
            32,      // biBitCount
 
263
            BI_RGB,  // biCompression
 
264
            0,       // biSizeImage
 
265
            2835,    // biXPelsPerMeter
 
266
            2835,    // biYPelsPerMeter
 
267
            0,       // biClrUsed
 
268
            0        // biClrImportant
 
269
        },
 
270
        { { 0, 0, 0, 0 } } // bmiColors
 
271
    };
 
272
    //RECT wrect;
 
273
    int res;
 
274
 
 
275
    SPWin32Modal = TRUE;
 
276
 
 
277
    // Number of pixels per logical inch
 
278
    dpiX = (int) GetDeviceCaps (_hDC, LOGPIXELSX);
 
279
    dpiY = (int) GetDeviceCaps (_hDC, LOGPIXELSY);
 
280
    // Size in pixels of the printable area
 
281
    pPhysicalWidth = GetDeviceCaps (_hDC, PHYSICALWIDTH);
 
282
    pPhysicalHeight = GetDeviceCaps (_hDC, PHYSICALHEIGHT);
 
283
    // Top left corner of prontable area
 
284
    pPhysicalOffsetX = GetDeviceCaps (_hDC, PHYSICALOFFSETX);
 
285
    pPhysicalOffsetY = GetDeviceCaps (_hDC, PHYSICALOFFSETY);
 
286
    // Size in pixels of the printable area
 
287
    pPrintableWidth = GetDeviceCaps (_hDC, HORZRES);
 
288
    pPrintableHeight = GetDeviceCaps (_hDC, VERTRES);
 
289
 
 
290
    // Scaling from document to device
 
291
    scalex = dpiX / 72.0;
 
292
    scaley = dpiY / 72.0;
 
293
 
 
294
    // We simply map document 0,0 to physical page 0,0
 
295
    Geom::Matrix affine = Geom::Scale(scalex / 1.25, scaley / 1.25);
 
296
 
 
297
    nr_arena_item_set_transform (mod->root, affine);
 
298
 
 
299
    // Calculate printable area in device coordinates
 
300
    x0 = pPhysicalOffsetX;
 
301
    y0 = pPhysicalOffsetY;
 
302
    x1 = x0 + pPrintableWidth;
 
303
    y1 = y0 + pPrintableHeight;
 
304
    x1 = MIN (x1, (int) (_PageWidth * scalex));
 
305
    y1 = MIN (y1, (int) (_PageHeight * scaley));
 
306
 
 
307
    width = x1 - x0;
 
308
    height = y1 - y0;
 
309
 
 
310
    px = g_new (unsigned char, 4 * 64 * width);
 
311
    sheight = 64;
 
312
 
 
313
    /* Printing goes here */
 
314
    for (row = 0; row < height; row += 64) {
 
315
        NRPixBlock pb;
 
316
        NRRectL bbox;
 
317
        NRGC gc(NULL);
 
318
        int num_rows;
 
319
        int i;
 
320
 
 
321
        num_rows = sheight;
 
322
        if ((row + num_rows) > height) num_rows = height - row;
 
323
 
 
324
        /* Set area of interest */
 
325
        bbox.x0 = x0;
 
326
        bbox.y0 = y0 + row;
 
327
        bbox.x1 = bbox.x0 + width;
 
328
        bbox.y1 = bbox.y0 + num_rows;
 
329
        /* Update to renderable state */
 
330
        gc.transform.setIdentity();
 
331
        nr_arena_item_invoke_update (mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
 
332
 
 
333
        nr_pixblock_setup_extern (&pb, NR_PIXBLOCK_MODE_R8G8B8A8N, bbox.x0, bbox.y0, bbox.x1, bbox.y1, px, 4 * (bbox.x1 - bbox.x0), FALSE, FALSE);
 
334
 
 
335
        /* Blitter goes here */
 
336
        bmInfo.bmiHeader.biWidth = bbox.x1 - bbox.x0;
 
337
        bmInfo.bmiHeader.biHeight = -(bbox.y1 - bbox.y0);
 
338
 
 
339
        memset (px, 0xff, 4 * num_rows * width);
 
340
        /* Render */
 
341
        nr_arena_item_invoke_render (NULL, mod->root, &bbox, &pb, 0);
 
342
 
 
343
        /* Swap red and blue channels; we use RGBA, whereas
 
344
         * the Win32 GDI uses BGRx.
 
345
         */
 
346
        for ( i = 0 ; i < num_rows * width ; i++ ) {
 
347
            unsigned char temp=px[i*4];
 
348
            px[i*4] = px[i*4+2];
 
349
            px[i*4+2] = temp;
 
350
        }
 
351
 
 
352
        SetStretchBltMode(_hDC, COLORONCOLOR);
 
353
        res = StretchDIBits (_hDC,
 
354
                        bbox.x0 - x0, bbox.y0 - y0, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0,
 
355
                        0, 0, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0,
 
356
                        px,
 
357
                        &bmInfo,
364
358
                        DIB_RGB_COLORS,
365
359
                        SRCCOPY);
366
360
 
367
 
                /* Blitter ends here */
368
 
 
369
 
                nr_pixblock_release (&pb);
370
 
        }
371
 
 
372
 
        g_free (px);
373
 
 
374
 
        res = EndPage (_hDC);
375
 
        res = EndDoc (_hDC);
376
 
 
377
 
        SPWin32Modal = FALSE;
378
 
 
379
 
        return 0;
 
361
        /* Blitter ends here */
 
362
 
 
363
        nr_pixblock_release (&pb);
 
364
    }
 
365
 
 
366
    g_free (px);
 
367
 
 
368
    res = EndPage (_hDC);
 
369
    res = EndDoc (_hDC);
 
370
 
 
371
    SPWin32Modal = FALSE;
 
372
 
 
373
    return 0;
380
374
}
381
375
 
382
376
/* File dialogs */
384
378
char *
385
379
PrintWin32::get_open_filename (unsigned char *dir, unsigned char *filter, unsigned char *title)
386
380
{
387
 
        char fnbuf[4096] = {0};
388
 
        OPENFILENAME ofn = {
389
 
                sizeof (OPENFILENAME),
390
 
                NULL, /* hwndOwner */
391
 
                NULL, /* hInstance */
392
 
                (const CHAR *)filter, /* lpstrFilter */
393
 
                NULL, /* lpstrCustomFilter */
394
 
                0, /* nMaxCustFilter  */
395
 
                1, /* nFilterIndex */
396
 
                fnbuf, /* lpstrFile */
397
 
                sizeof (fnbuf), /* nMaxFile */
398
 
                NULL, /* lpstrFileTitle */
399
 
                0, /* nMaxFileTitle */
400
 
                (const CHAR *)dir, /* lpstrInitialDir */
401
 
                (const CHAR *)title, /* lpstrTitle */
402
 
                OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY, /* Flags */
403
 
                0, /* nFileOffset */
404
 
                0, /* nFileExtension */
405
 
                NULL, /* lpstrDefExt */
406
 
                0, /* lCustData */
407
 
                NULL, /* lpfnHook */
408
 
                NULL /* lpTemplateName */
409
 
        };
410
 
        int retval;
411
 
        UINT_PTR timer;
412
 
 
413
 
        SPWin32Modal = TRUE;
414
 
        timer = SetTimer (NULL, 0, 40, my_timer);
415
 
 
416
 
        retval = GetOpenFileName (&ofn);
417
 
 
418
 
        KillTimer (NULL, timer);
419
 
        SPWin32Modal = FALSE;
420
 
 
421
 
        if (!retval) {
422
 
                int errcode;
423
 
                errcode = CommDlgExtendedError();
424
 
                return NULL;
 
381
    char fnbuf[4096] = {0};
 
382
    OPENFILENAME ofn = {
 
383
        sizeof (OPENFILENAME),
 
384
        NULL, /* hwndOwner */
 
385
        NULL, /* hInstance */
 
386
        (const CHAR *)filter, /* lpstrFilter */
 
387
        NULL, /* lpstrCustomFilter */
 
388
        0, /* nMaxCustFilter  */
 
389
        1, /* nFilterIndex */
 
390
        fnbuf, /* lpstrFile */
 
391
        sizeof (fnbuf), /* nMaxFile */
 
392
        NULL, /* lpstrFileTitle */
 
393
        0, /* nMaxFileTitle */
 
394
        (const CHAR *)dir, /* lpstrInitialDir */
 
395
        (const CHAR *)title, /* lpstrTitle */
 
396
        OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY, /* Flags */
 
397
        0, /* nFileOffset */
 
398
        0, /* nFileExtension */
 
399
        NULL, /* lpstrDefExt */
 
400
        0, /* lCustData */
 
401
        NULL, /* lpfnHook */
 
402
        NULL /* lpTemplateName */
 
403
    };
 
404
    int retval;
 
405
    UINT_PTR timer;
 
406
 
 
407
    SPWin32Modal = TRUE;
 
408
    timer = SetTimer (NULL, 0, 40, my_timer);
 
409
 
 
410
    retval = GetOpenFileName (&ofn);
 
411
 
 
412
    KillTimer (NULL, timer);
 
413
    SPWin32Modal = FALSE;
 
414
 
 
415
    if (!retval) {
 
416
        int errcode;
 
417
        errcode = CommDlgExtendedError();
 
418
        return NULL;
425
419
    }
426
 
        return g_strdup (fnbuf);
 
420
    return g_strdup (fnbuf);
427
421
}
428
422
 
429
423
char *
430
424
PrintWin32::get_write_filename (unsigned char *dir, unsigned char *filter, unsigned char *title)
431
425
{
432
 
        return NULL;
 
426
    return NULL;
433
427
}
434
428
 
435
429
char *
436
430
PrintWin32::get_save_filename (unsigned char *dir, unsigned int *spns)
437
431
{
438
 
        char fnbuf[4096] = {0};
439
 
        OPENFILENAME ofn = {
440
 
                sizeof (OPENFILENAME),
441
 
                NULL, /* hwndOwner */
442
 
                NULL, /* hInstance */
443
 
                "Inkscape SVG (*.svg)\0*\0Plain SVG (*.svg)\0*\0", /* lpstrFilter */
444
 
                NULL, /* lpstrCustomFilter */
445
 
                0, /* nMaxCustFilter  */
446
 
                1, /* nFilterIndex */
447
 
                fnbuf, /* lpstrFile */
448
 
                sizeof (fnbuf), /* nMaxFile */
449
 
                NULL, /* lpstrFileTitle */
450
 
                0, /* nMaxFileTitle */
451
 
                (const CHAR *)dir, /* lpstrInitialDir */
452
 
                "Save document to file", /* lpstrTitle */
453
 
                OFN_HIDEREADONLY, /* Flags */
454
 
                0, /* nFileOffset */
455
 
                0, /* nFileExtension */
456
 
                NULL, /* lpstrDefExt */
457
 
                0, /* lCustData */
458
 
                NULL, /* lpfnHook */
459
 
                NULL /* lpTemplateName */
460
 
        };
461
 
        int retval;
462
 
        UINT_PTR timer;
463
 
 
464
 
        SPWin32Modal = TRUE;
465
 
        timer = SetTimer (NULL, 0, 40, my_timer);
466
 
 
467
 
        retval = GetSaveFileName (&ofn);
468
 
 
469
 
        KillTimer (NULL, timer);
470
 
        SPWin32Modal = FALSE;
471
 
 
472
 
        if (!retval) {
473
 
                int errcode;
474
 
                errcode = CommDlgExtendedError();
475
 
                return NULL;
 
432
    char fnbuf[4096] = {0};
 
433
    OPENFILENAME ofn = {
 
434
        sizeof (OPENFILENAME),
 
435
        NULL, /* hwndOwner */
 
436
        NULL, /* hInstance */
 
437
        "Inkscape SVG (*.svg)\0*\0Plain SVG (*.svg)\0*\0", /* lpstrFilter */
 
438
        NULL, /* lpstrCustomFilter */
 
439
        0, /* nMaxCustFilter  */
 
440
        1, /* nFilterIndex */
 
441
        fnbuf, /* lpstrFile */
 
442
        sizeof (fnbuf), /* nMaxFile */
 
443
        NULL, /* lpstrFileTitle */
 
444
        0, /* nMaxFileTitle */
 
445
        (const CHAR *)dir, /* lpstrInitialDir */
 
446
        "Save document to file", /* lpstrTitle */
 
447
        OFN_HIDEREADONLY, /* Flags */
 
448
        0, /* nFileOffset */
 
449
        0, /* nFileExtension */
 
450
        NULL, /* lpstrDefExt */
 
451
        0, /* lCustData */
 
452
        NULL, /* lpfnHook */
 
453
        NULL /* lpTemplateName */
 
454
    };
 
455
    int retval;
 
456
    UINT_PTR timer;
 
457
 
 
458
    SPWin32Modal = TRUE;
 
459
    timer = SetTimer (NULL, 0, 40, my_timer);
 
460
 
 
461
    retval = GetSaveFileName (&ofn);
 
462
 
 
463
    KillTimer (NULL, timer);
 
464
    SPWin32Modal = FALSE;
 
465
 
 
466
    if (!retval) {
 
467
        int errcode;
 
468
        errcode = CommDlgExtendedError();
 
469
        return NULL;
476
470
    }
477
 
        *spns = (ofn.nFilterIndex != 2);
478
 
        return g_strdup (fnbuf);
 
471
    *spns = (ofn.nFilterIndex != 2);
 
472
    return g_strdup (fnbuf);
479
473
}
480
474
 
481
475
#include "clear-n_.h"
483
477
void
484
478
PrintWin32::init (void)
485
479
{
486
 
        Inkscape::Extension::Extension * ext;
 
480
    Inkscape::Extension::Extension * ext;
487
481
 
488
 
        /* SVG in */
 
482
    /* SVG in */
489
483
    ext = Inkscape::Extension::build_from_mem(
490
 
                "<inkscape-extension>\n"
491
 
                        "<name>" N_("Windows 32-bit Print") "</name>\n"
492
 
                        "<id>" SP_MODULE_KEY_PRINT_WIN32 "</id>\n"
493
 
                        "<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"
494
 
                        "<print/>\n"
495
 
                "</inkscape-extension>", new PrintWin32());
 
484
        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
 
485
            "<name>" N_("Windows 32-bit Print") "</name>\n"
 
486
            "<id>" SP_MODULE_KEY_PRINT_WIN32 "</id>\n"
 
487
            "<param name=\"textToPath\" type=\"boolean\">true</param>\n"
 
488
            "<print/>\n"
 
489
        "</inkscape-extension>", new PrintWin32());
496
490
 
497
 
        return;
 
491
    return;
498
492
}
499
493
 
500
494
}  /* namespace Internal */
501
495
}  /* namespace Extension */
502
496
}  /* namespace Inkscape */
 
497
 
 
498
#endif // ifdef WIN32
 
499
 
 
500
/*
 
501
  Local Variables:
 
502
  mode:c++
 
503
  c-file-style:"stroustrup"
 
504
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
505
  indent-tabs-mode:nil
 
506
  fill-column:99
 
507
  End:
 
508
*/
 
509
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :