~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to psi/dwmain.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2008 Artifex Software, Inc.
 
1
/* Copyright (C) 2001-2011 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
10
10
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
 
/* $Id: dwmain.c 12103 2011-02-02 17:18:09Z ray $ */
 
13
/* $Id$ */
14
14
/* Ghostscript DLL loader for Windows */
15
15
 
16
16
#include "windows_.h"
49
49
#endif
50
50
const LPSTR szIniSection = "Text";
51
51
 
52
 
 
53
52
GSDLL gsdll;
54
53
void *instance;
55
54
HWND hwndtext;
60
59
{
61
60
    MSG msg;
62
61
    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
63
 
        TranslateMessage(&msg);
64
 
        DispatchMessage(&msg);
 
62
        TranslateMessage(&msg);
 
63
        DispatchMessage(&msg);
65
64
    }
66
65
    /* If text window closing then abort Ghostscript */
67
66
    if (tw->quitnow)
68
 
        return e_Fatal;
 
67
        return e_Fatal;
69
68
    return 0;
70
69
}
71
70
 
100
99
/*********************************************************************/
101
100
 
102
101
/* new dll display device */
103
 
/* 
 
102
/*
104
103
#define DISPLAY_DEBUG
105
104
 */
106
105
 
145
144
#endif
146
145
    img = image_find(handle, device);
147
146
    if (img) {
148
 
        image_delete(img);      /* remove from list but don't free */
149
 
        image_close(img);
 
147
        image_delete(img);      /* remove from list but don't free */
 
148
        image_close(img);
150
149
    }
151
150
    return 0;
152
151
}
153
152
 
154
153
/* Device is about to be resized. */
155
154
/* Resize will only occur if this function returns 0. */
156
 
static int display_presize(void *handle, void *device, int width, int height, 
157
 
        int raster, unsigned int format)
 
155
static int display_presize(void *handle, void *device, int width, int height,
 
156
        int raster, unsigned int format)
158
157
{
159
158
#ifdef DISPLAY_DEBUG
160
159
    char buf[256];
161
160
    sprintf(buf, "display_presize(0x%x, 0x%x, width=%d height=%d raster=%d\n\
162
 
  format=%d)\n", 
 
161
  format=%d)\n",
163
162
       handle, device, width, height, raster, format);
164
163
    text_puts(tw, buf);
165
164
#endif
166
165
    return 0;
167
166
}
168
 
   
 
167
 
169
168
/* Device has been resized. */
170
169
/* New pointer to raster returned in pimage */
171
 
static int display_size(void *handle, void *device, int width, int height, 
172
 
        int raster, unsigned int format, unsigned char *pimage)
 
170
static int display_size(void *handle, void *device, int width, int height,
 
171
        int raster, unsigned int format, unsigned char *pimage)
173
172
{
174
173
    IMAGE *img;
175
174
#ifdef DISPLAY_DEBUG
176
175
    char buf[256];
177
176
    sprintf(buf, "display_size(0x%x, 0x%x, width=%d height=%d raster=%d\n\
178
 
  format=%d image=0x%x)\n", 
 
177
  format=%d image=0x%x)\n",
179
178
       handle, device, width, height, raster, format, pimage);
180
179
    text_puts(tw, buf);
181
180
#endif
184
183
    image_updatesize(img);
185
184
    return 0;
186
185
}
187
 
   
 
186
 
188
187
/* flushpage */
189
188
static int display_sync(void *handle, void *device)
190
189
{
206
205
    IMAGE *img;
207
206
#ifdef DISPLAY_DEBUG
208
207
    char buf[256];
209
 
    sprintf(buf, "display_page(0x%x, 0x%x, copies=%d flush=%d)\n", 
210
 
        handle, device, copies, flush);
 
208
    sprintf(buf, "display_page(0x%x, 0x%x, copies=%d flush=%d)\n",
 
209
        handle, device, copies, flush);
211
210
    text_puts(tw, buf);
212
211
#endif
213
212
    img = image_find(handle, device);
217
216
 
218
217
/* Poll the caller for cooperative multitasking. */
219
218
/* If this function is NULL, polling is not needed */
220
 
static int display_update(void *handle, void *device, 
 
219
static int display_update(void *handle, void *device,
221
220
    int x, int y, int w, int h)
222
221
{
223
222
    IMAGE *img;
226
225
    return poll();
227
226
}
228
227
 
229
 
int display_separation(void *handle, void *device, 
 
228
int display_separation(void *handle, void *device,
230
229
   int comp_num, const char *name,
231
230
   unsigned short c, unsigned short m,
232
231
   unsigned short y, unsigned short k)
233
232
{
234
233
    IMAGE *img;
235
234
#ifdef DISPLAY_DEBUG
236
 
    fprintf(stdout, "display_separation(0x%x, 0x%x, %d '%s' %d,%d,%d,%d)\n", 
237
 
        handle, device, comp_num, name, (int)c, (int)m, (int)y, (int)k);
 
235
    fprintf(stdout, "display_separation(0x%x, 0x%x, %d '%s' %d,%d,%d,%d)\n",
 
236
        handle, device, comp_num, name, (int)c, (int)m, (int)y, (int)k);
238
237
#endif
239
238
    img = image_find(handle, device);
240
239
    if (img)
242
241
    return 0;
243
242
}
244
243
 
245
 
display_callback display = { 
 
244
display_callback display = {
246
245
    sizeof(display_callback),
247
246
    DISPLAY_VERSION_MAJOR,
248
247
    DISPLAY_VERSION_MINOR,
259
258
    display_separation
260
259
};
261
260
 
262
 
 
263
261
/*********************************************************************/
264
262
 
265
263
/* program really starts at WinMain */
276
274
 
277
275
    memset(buf, 0, sizeof(buf));
278
276
    if (load_dll(&gsdll, buf, sizeof(buf))) {
279
 
        text_puts(tw, "Can't load Ghostscript DLL\n");
280
 
        text_puts(tw, buf);
281
 
        text_puts(tw, "\n");
282
 
        return 1;
 
277
        text_puts(tw, "Can't load Ghostscript DLL\n");
 
278
        text_puts(tw, buf);
 
279
        text_puts(tw, "\n");
 
280
        return 1;
283
281
    }
284
282
 
285
283
    if (gsdll.new_instance(&instance, NULL) < 0) {
286
 
        text_puts(tw, "Can't create Ghostscript instance\n");
287
 
        return 1;
 
284
        text_puts(tw, "Can't create Ghostscript instance\n");
 
285
        return 1;
288
286
    }
289
287
 
290
288
#ifdef DEBUG
297
295
    gsdll.set_display_callback(instance, &display);
298
296
 
299
297
    /* insert display device defaults as first arguments */
300
 
    {   int format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | 
301
 
                DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
302
 
        HDC hdc = GetDC(NULL);  /* get hdc for desktop */
303
 
        int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
304
 
        sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY));
 
298
    {   int format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE |
 
299
                DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 
300
        HDC hdc = GetDC(NULL);  /* get hdc for desktop */
 
301
        int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
 
302
        sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY));
305
303
        ReleaseDC(NULL, hdc);
306
 
        if (depth == 32)
307
 
            format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | 
308
 
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
309
 
        else if (depth == 16)
310
 
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | 
311
 
                DISPLAY_DEPTH_16 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST |
312
 
                DISPLAY_NATIVE_555;
313
 
        else if (depth > 8)
314
 
            format = DISPLAY_COLORS_RGB | DISPLAY_ALPHA_NONE | 
315
 
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
316
 
        else if (depth >= 8)
317
 
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | 
318
 
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
319
 
        else if (depth >= 4)
320
 
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | 
321
 
                DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 
304
        if (depth == 32)
 
305
            format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST |
 
306
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 
307
        else if (depth == 16)
 
308
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE |
 
309
                DISPLAY_DEPTH_16 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST |
 
310
                DISPLAY_NATIVE_555;
 
311
        else if (depth > 8)
 
312
            format = DISPLAY_COLORS_RGB | DISPLAY_ALPHA_NONE |
 
313
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 
314
        else if (depth >= 8)
 
315
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE |
 
316
                DISPLAY_DEPTH_8 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 
317
        else if (depth >= 4)
 
318
            format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE |
 
319
                DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
322
320
        sprintf(dformat, "-dDisplayFormat=%d", format);
323
321
    }
324
322
    nargc = argc + 2;
333
331
#endif
334
332
    code = gsdll.init_with_args(instance, nargc, nargv);
335
333
    if (code == 0)
336
 
        code = gsdll.run_string(instance, start_string, 0, &exit_code);
 
334
        code = gsdll.run_string(instance, start_string, 0, &exit_code);
337
335
    code1 = gsdll.exit(instance);
338
336
    if (code == 0 || (code == e_Quit && code1 != 0))
339
 
        code = code1;
 
337
        code = code1;
340
338
#if defined(_MSC_VER) || defined(__BORLANDC__)
341
339
    } __except(exception_code() == EXCEPTION_STACK_OVERFLOW) {
342
340
        code = e_Fatal;
356
354
 
357
355
    exit_status = 0;
358
356
    switch (code) {
359
 
        case 0:
360
 
        case e_Quit:
361
 
            break;
362
 
        case e_Fatal:
363
 
            exit_status = 1;
364
 
            break;
365
 
        case e_Info:
366
 
        default:
367
 
            exit_status = 255;
 
357
        case 0:
 
358
        case e_Quit:
 
359
            break;
 
360
        case e_Fatal:
 
361
            exit_status = 1;
 
362
            break;
 
363
        case e_Info:
 
364
        default:
 
365
            exit_status = 255;
368
366
    }
369
 
    
 
367
 
370
368
    return exit_status;
371
369
}
372
370
 
373
 
 
374
 
 
375
371
void
376
372
set_font(void)
377
373
{
384
380
    fontsize = GetPrivateProfileInt(szIniSection, "FontSize", 10, szIniName);
385
381
 
386
382
    /* set font */
387
 
    text_font(tw, fontname, fontsize); 
 
383
    text_font(tw, fontname, fontsize);
388
384
 
389
385
    /* write ini file */
390
386
    WritePrivateProfileString(szIniSection, "FontName", fontname, szIniName);
392
388
    WritePrivateProfileString(szIniSection, "FontSize", buf, szIniName);
393
389
}
394
390
 
395
 
int PASCAL 
 
391
int PASCAL
396
392
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
397
393
{
398
394
    int dll_exit_status;
403
399
    int argc;
404
400
    LPSTR argv[MAXCMDTOKENS];
405
401
    LPSTR p;
 
402
#ifndef WINDOWS_NO_UNICODE
 
403
    LPSTR pstart;
 
404
#endif
406
405
    char command[256];
407
406
    char *args;
408
407
    char *d, *e;
409
408
    char winposbuf[256];
410
409
    int len = sizeof(winposbuf);
411
410
    int x, y, cx, cy;
412
 
 
 
411
 
413
412
    /* copy the hInstance into a variable so it can be used */
414
413
    ghInstance = hInstance;
415
414
 
416
415
    if (hPrevInstance) {
417
 
        MessageBox((HWND)NULL,"Can't run twice", szAppName, 
418
 
                MB_ICONHAND | MB_OK);
419
 
        return FALSE;
 
416
        MessageBox((HWND)NULL,"Can't run twice", szAppName,
 
417
                MB_ICONHAND | MB_OK);
 
418
        return FALSE;
420
419
    }
421
420
 
422
421
    /* If called with "gswin32c.exe arg1 arg2"
424
423
     *    "arg1 arg2" if called with CreateProcess(NULL, command, ...)
425
424
     *    "arg2"      if called with CreateProcess(command, args, ...)
426
425
     * GetCommandLine() returns
427
 
     *    ""gswin32c.exe" arg1 arg2" 
 
426
     *    ""gswin32c.exe" arg1 arg2"
428
427
     *          if called with CreateProcess(NULL, command, ...)
429
 
     *    "  arg1 arg2"      
 
428
     *    "  arg1 arg2"
430
429
     *          if called with CreateProcess(command, args, ...)
431
 
     * Consequently we must use GetCommandLine() 
 
430
     * Consequently we must use GetCommandLine()
432
431
     */
 
432
#ifdef WINDOWS_NO_UNICODE
433
433
    p = GetCommandLine();
 
434
#else
 
435
    {
 
436
        wchar_t *uni = GetCommandLineW();
 
437
        pstart = p = malloc(wchar_to_utf8(NULL, uni));
 
438
        if (p != NULL)
 
439
            wchar_to_utf8(p, uni);
 
440
    }
 
441
#endif
434
442
 
435
443
    argc = 0;
436
444
    args = (char *)malloc(lstrlen(p)+1);
437
445
    if (args == (char *)NULL) {
438
 
        fprintf(stdout, "Insufficient memory in WinMain()\n");
439
 
        return 1;
 
446
        fprintf(stdout, "Insufficient memory in WinMain()\n");
 
447
        return 1;
440
448
    }
441
 
   
 
449
 
442
450
    /* Parse command line handling quotes. */
443
451
    d = args;
444
452
    while (*p) {
445
 
        /* for each argument */
 
453
        /* for each argument */
446
454
 
447
 
        if (argc >= MAXCMDTOKENS - 1)
448
 
            break;
 
455
        if (argc >= MAXCMDTOKENS - 1)
 
456
            break;
449
457
 
450
458
        e = d;
451
459
        while ((*p) && (*p != ' ')) {
452
 
            if (*p == '\042') {
453
 
                /* Remove quotes, skipping over embedded spaces. */
454
 
                /* Doesn't handle embedded quotes. */
455
 
                p++;
456
 
                while ((*p) && (*p != '\042'))
457
 
                    *d++ =*p++;
458
 
            }
459
 
            else 
460
 
                *d++ = *p;
461
 
            if (*p)
462
 
                p++;
 
460
            if (*p == '\042') {
 
461
                /* Remove quotes, skipping over embedded spaces. */
 
462
                /* Doesn't handle embedded quotes. */
 
463
                p++;
 
464
                while ((*p) && (*p != '\042'))
 
465
                    *d++ =*p++;
 
466
            }
 
467
            else
 
468
                *d++ = *p;
 
469
            if (*p)
 
470
                p++;
463
471
        }
464
 
        *d++ = '\0';
465
 
        argv[argc++] = e;
 
472
        *d++ = '\0';
 
473
        argv[argc++] = e;
466
474
 
467
 
        while ((*p) && (*p == ' '))
468
 
            p++;        /* Skip over trailing spaces */
 
475
        while ((*p) && (*p == ' '))
 
476
            p++;        /* Skip over trailing spaces */
469
477
    }
470
478
    argv[argc] = NULL;
471
479
 
 
480
#ifndef WINDOWS_NO_UNICODE
 
481
    free(pstart);
 
482
#endif
 
483
 
472
484
    if (strlen(argv[0]) == 0) {
473
 
        GetModuleFileName(hInstance, command, sizeof(command)-1);
474
 
        argv[0] = command;
 
485
        GetModuleFileName(hInstance, command, sizeof(command)-1);
 
486
        argv[0] = command;
475
487
    }
476
488
 
477
 
 
478
489
    tw = text_new();
479
490
    if (tw == NULL) {
480
 
        MessageBox((HWND)NULL, "Can't create text window", 
481
 
                szAppName, MB_OK | MB_ICONSTOP);
482
 
        return 1;
 
491
        MessageBox((HWND)NULL, "Can't create text window",
 
492
                szAppName, MB_OK | MB_ICONSTOP);
 
493
        return 1;
483
494
    }
484
495
 
485
496
    /* start up the text window */
486
497
    if (!hPrevInstance) {
487
 
        HICON hicon = LoadIcon(hInstance, (LPSTR)MAKEINTRESOURCE(GSTEXT_ICON));
488
 
        text_register_class(tw, hicon);
 
498
        HICON hicon = LoadIcon(hInstance, (LPSTR)MAKEINTRESOURCE(GSTEXT_ICON));
 
499
        text_register_class(tw, hicon);
489
500
    }
490
501
    set_font();
491
502
    text_size(tw, 80, 80);
492
503
    text_drag(tw, "(", ") run\r");
493
504
    if (win_get_reg_value("Text", winposbuf, &len) == 0) {
494
 
        if (sscanf(winposbuf, "%d %d %d %d", &x, &y, &cx, &cy) == 4)
495
 
            text_setpos(tw, x, y, cx, cy);
 
505
        if (sscanf(winposbuf, "%d %d %d %d", &x, &y, &cx, &cy) == 4)
 
506
            text_setpos(tw, x, y, cx, cy);
496
507
    }
497
508
 
498
509
    /* create the text window */
499
510
    if (text_create(tw, szAppName, cmdShow))
500
 
        exit(1);
 
511
        exit(1);
501
512
 
502
513
    hwndtext = text_get_handle(tw);
503
514
    image_textwindow(hwndtext);
504
515
 
505
516
    dll_exit_status = new_main(argc, argv);
506
 
    
 
517
 
507
518
    if (dll_exit_status && !tw->quitnow) {
508
 
        /* display error message in text window */
509
 
        MSG msg;
510
 
        text_puts(tw, "\nClose this window with the close button on the title bar or the system menu.\n");
511
 
        if (IsIconic(text_get_handle(tw)))
512
 
            ShowWindow(text_get_handle(tw), SW_SHOWNORMAL);
513
 
        BringWindowToTop(text_get_handle(tw));  /* make text window visible */
514
 
        FlashWindow(text_get_handle(tw), TRUE);
515
 
        /* Wait until error message is read */
516
 
        while (!tw->quitnow && GetMessage(&msg, (HWND)NULL, 0, 0)) {
517
 
            TranslateMessage(&msg);
518
 
            DispatchMessage(&msg);
519
 
        }
 
519
        /* display error message in text window */
 
520
        MSG msg;
 
521
        text_puts(tw, "\nClose this window with the close button on the title bar or the system menu.\n");
 
522
        if (IsIconic(text_get_handle(tw)))
 
523
            ShowWindow(text_get_handle(tw), SW_SHOWNORMAL);
 
524
        BringWindowToTop(text_get_handle(tw));  /* make text window visible */
 
525
        FlashWindow(text_get_handle(tw), TRUE);
 
526
        /* Wait until error message is read */
 
527
        while (!tw->quitnow && GetMessage(&msg, (HWND)NULL, 0, 0)) {
 
528
            TranslateMessage(&msg);
 
529
            DispatchMessage(&msg);
 
530
        }
520
531
    }
521
532
 
522
533
    /* Save the text window size */
523
534
    if (text_getpos(tw, &x, &y, &cx, &cy) == 0) {
524
 
        sprintf(winposbuf, "%d %d %d %d", x, y, cx, cy);
525
 
        win_set_reg_value("Text", winposbuf);
 
535
        sprintf(winposbuf, "%d %d %d %d", x, y, cx, cy);
 
536
        win_set_reg_value("Text", winposbuf);
526
537
    }
527
538
 
528
539
    text_destroy(tw);
530
541
 
531
542
    return dll_exit_status;
532
543
}
533
 
 
534
 
 
535