Menu

#1 Submitted by Piotr Strzelczyk / PS_VIEW

open
nobody
None
5
2014-08-18
2008-03-12
No

Hello,

I found your library, and it looked very useful for my project.
I'm writing a new version of our viewer for Postscript files
-- see: http://www.sourceforge.net/psview/ . I introduced some
fixes and modification to your library -- attached you will find
updated files.

The modifications fall into three classes.

=== === === === === === === === === === === === === === === === === === ===
1. Bug fixes:
=== === === === === === === === === === === === === === === === === === ===

52c52
< double m_version = 0.0;
---
> m_version = 0.0;

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
1a. Buglets or, maybe, compilator warnings fixing (it's hard
to distinguish which errors were caused by wxWidgets version
change and which by the compiler level of warnings).
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

663,672c674,686
< static_display_open, /* New device has been opened */
< static_display_preclose, /* Device is about to be closed. */
< static_display_close, /* Device has been closed. */
< static_display_presize, /* Device is about to be resized. */
< static_display_size, /* Device has been resized. */
< static_display_sync, /* flushpage */
< static_display_page, /* showpage */
< static_display_update, /* Notify the caller whenever a
portion of the raster is updated. */
< static_display_memalloc, /* Allocate memory for bitmap */
< static_display_memfree /* Free memory for bitmap */
---
> &static_display_open, /* New device has been opened */
> &static_display_preclose, /* Device is about to be closed. */
> &static_display_close, /* Device has been closed. */
> &static_display_presize, /* Device is about to be resized. */
> &static_display_size, /* Device has been resized. */
> &static_display_sync, /* flushpage */
> &static_display_page, /* showpage */
> &static_display_update, /* Notify the caller whenever a
portion of the raster is updated. */
> &static_display_memalloc, /* Allocate memory for bitmap */
> &static_display_memfree /* Free memory for bitmap */
> #if DISPLAY_VERSION_MAJOR > 1
> , NULL // &static_display_separation /* Special color was
set */
> #endif
1310c1337
< wxCHECK_MSG(Ok(), wxbitmap, wxT("invalid gs image"))
---
> wxCHECK_MSG(Ok(), wxbitmap, wxT("invalid gs image"));
1336c1363
< wxCHECK_MSG(Ok(), wximage, wxT("invalid gs image"))
---
> wxCHECK_MSG(Ok(), wximage, wxT("invalid gs image"));
1381c1408
< wxCHECK_MSG(Ok(), wxColour(0,0,0), wxT("invalid gs image"))
---
> wxCHECK_MSG(Ok(), wxColour(0,0,0), wxT("invalid gs image"));
174c176
< gs::gs_main_instance *m_instance;
---
> void *m_instance;

=== === === === === === === === === === === === === === === === === === ===
2. Next category of changes was caused by the update of wxWidgets
and, moreover, the adjustment of wxGhostscript to Unicode version
of wxWidgets (the first correction is probably also a bug fix
in wxGhostscript):
=== === === === === === === === === === === === === === === === === === ===

306a311
> wxWritableCharBuffer *argb = new wxWritableCharBuffer[argc];
309c314,319
< argv[j] = (char *)(args[j].c_str());
---
> {
> // argv[j] = (char *)(args[j].c_str());
> argb[j] = args[j].char_str(); // PSt version
> argv[j] = argb[j];
> // wxPrintf(wxT("!!! %s\n"), args[j].c_str());
> }
316c326,327
< delete argv;
---
> delete []argv;
> delete []argb;

336c347
< wxUsleep(10); // wait without processing event loop
---
> wxMilliSleep(10); // wait without processing event loop
493c504
< const char *c_str = str.c_str();
---
> const char *c_str = str.char_str();
522c533
< result =
m_gsdll->gsapi_run_string_with_length(m_instance, str.c_str(),
str.Length(), 0, &m_exitcode);
---
> result =
m_gsdll->gsapi_run_string_with_length(m_instance, str.char_str(),
str.Length(), 0, &m_exitcode);
535c546
< result = m_gsdll->gsapi_run_file(m_instance, str.c_str(),
0, &m_exitcode);
---
> result = m_gsdll->gsapi_run_file(m_instance,
str.char_str(), 0, &m_exitcode);
714c728
< int susp = gs->CheckSuspended(gs->DoCallback(NULL, wxString(str,
len), onstdout));
---
> int susp = gs->CheckSuspended(gs->DoCallback(NULL, wxString(str,
wxConvUTF8, len), onstdout));
727c741
< int susp = gs->CheckSuspended(gs->DoCallback(NULL, wxString(str,
len), onstderr));
---
> int susp = gs->CheckSuspended(gs->DoCallback(NULL, wxString(str,
wxConvUTF8, len), onstderr));
1641c1685
< vd->OnText(wxRealPoint(x, y), wxString(ASCIIZ));
---
> vd->OnText(wxRealPoint(x, y), wxString(ASCIIZ, wxConvUTF8));

=== === === === === === === === === === === === === === === === === === ===
3. The third and last class consists of my modifications.
=== === === === === === === === === === === === === === === === === === ===

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
3a. Let's start with cosmetical changes:
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

300c301,303
< args.Insert(wxString::Format(wxT("-dDisplayHandle=%ld"),
(long)this), 0);
---
> if (devicearg == wxT("display"))
> {
> args.Insert(wxString::Format(wxT("-sDisplayHandle=%ld"),
(long)this), 0);
302a306
> }
591c602
< if (m_phase == suspended)
---
> while (m_phase == suspended)
1066a1092
> #ifdef __WXMSW__
1067a1094
> #endif

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
3b. Some changes are hard to classify, but they still are necessary.
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

1412c1440
< int ww, wh;
---
> int ww, wh, vbX, vbY, xUnit, yUnit;
1417,1418c1445,1446
< if (iw < ww)
< region.x += (ww - iw) / 2;
---
> if (iw < ww) region.x += (ww - iw) / 2;
> if (ih < wh) region.y += (wh - ih) / 2;
1420,1421c1448,1454
< if (ih < wh)
< region.y += (wh - ih) / 2;
---
> // Find Out where the window is scrolled to
> GetViewStart(&vbX, &vbY);
> GetScrollPixelsPerUnit(&xUnit, &yUnit);
> vbX *= xUnit;
> vbY *= yUnit;
> region.x -= vbX;
> region.y -= vbY;
1451a1485,1491
> if (ibX!=m_ibx || ibY!=m_iby)
> {
> m_ibx=ibX; m_iby=ibY;
> Refresh();
> return;
> }
>
1459c1499
< wxRect src = dest;
---
> wxRect desto = dest;
1461c1501,1503
< // Adjust the destination if the window is scrolled
---
>
> // PSt: Adjust the destination if the window is scrolled
> // (it should be done by wxScrolledWindow::DoPrepareDC !!!)
1466c1508
< if (dest.x + dest.width > iw)
---
> if (dest.x - ibX + dest.width > iw)
1468c1510
< if (dest.y + dest.height > ih)
---
> if (dest.y - ibY + dest.height > ih)
1472c1514,1515
< m_image.CopyOnto(dc, src, wxPoint(dest.x - ibX, dest.y - ibY));
---
> // GTK
> m_image.CopyOnto(dc, desto, wxPoint(dest.x - ibX, dest.y - ibY));
1473a1517
> // WIN

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
3c. And a controversial but important to performance of my project change.
It can be switched off by defining CALLBACK_POLL_DIVIDER to value 1.
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

732a747,748
> int wxGhostscript::static_pollcnt = CALLBACK_POLL_DIVIDER;
>
734a751,752
> if (--static_pollcnt == 0) {
> static_pollcnt=CALLBACK_POLL_DIVIDER;
740a757,759
> } else {
> return 0;
> }
865a885,891
> static int xb=65535,yb=65535,xe=0,ye=0;
> if (xb>x) xb=x; if (yb>y) yb=y;
> if (xe<x+w) xe=x+w; if (xe<y+h) ye=y+h;
> if (--static_pollcnt == 0) {
> static_pollcnt=CALLBACK_POLL_DIVIDER;
> wxRect rect = wxRect(xb, yb, xe-xb, ye-yb);
> xb=65535,yb=65535,xe=0,ye=0;
875c897,900
< return gs->CheckSuspended(gs->DoCallback(image, wxRect(x, y, w,
h), onupdate)); // top/bottom coordinate sys match ?
---
> return gs->CheckSuspended(gs->DoCallback(image, rect, onupdate));
// top/bottom coordinate sys match ?
> } else {
> return 0;
> }

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
3d. The changes mentioned in 3b and 3c require also a few related changes
in the ghostscript.h file:
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

364c367
< wxGsWindow() : wxScrolledWindow(), m_image(wxNullGsImage) {}
---
> wxGsWindow() : wxScrolledWindow(), m_image(wxNullGsImage)
{m_ibx=0; m_iby=0;}
367,368c370,371
< const wxString& name = "ghostscriptWindow") :
< wxScrolledWindow(parent, id, pos, size, style, name),
m_image(wxNullGsImage) {}
---
> const wxString& name = wxT("ghostscriptWindow")) :
> wxScrolledWindow(parent, id, pos, size, style, name),
m_image(wxNullGsImage) {m_ibx=0; m_iby=0;}
375a379,380
> int m_ibx;
> int m_iby;

71a72,73
> #define CALLBACK_POLL_DIVIDER 100
>
181a184
> static int static_pollcnt;

=== === === === === === === === === === === === === === === === === === ===

I hope that you (and maybe somebody else) will find my corrections
useful. I do not insist on introducing all of this changes, but some
of them are defintively necessary.

Once again -- very many thanks for your code.

Best regards

Piotr Strzelczyk

--
Piotr Strzelczyk
Sopot, Poland

Discussion

  • Nigel Hathaway

    Nigel Hathaway - 2008-03-12

    Patches for PS_VIEW

     
  • Nigel Hathaway

    Nigel Hathaway - 2008-03-19

    wxGhostscript as a tarball

     
  • Nigel Hathaway

    Nigel Hathaway - 2008-03-19

    Logged In: YES
    user_id=487598
    Originator: YES

    File Added: wxghostscript.tar.bz2

     
  • Nigel Hathaway

    Nigel Hathaway - 2008-03-19

    Logged In: YES
    user_id=487598
    Originator: YES

    The first item classified as a bug fix is slightly strange. It is masking a member variable with a local variable. I don't think this is correct.

    I've had a look at the wxWidgets 2.8.7 version and it may be possible to simplify the wxGhostscript class by using (or deriving from) wxBitmap. This seems to be able to create the correct platform bitmap as used by the graphics display system, and give you a pointer to the raw data if requested - which is what we want.

     
  • Nigel Hathaway

    Nigel Hathaway - 2008-03-19

    Logged In: YES
    user_id=487598
    Originator: YES

    The bug fix is correct - it removes the masking (my mistake).

     

Log in to post a comment.