AW: AW: wxDC - Standalone and with CGI?

As i cannot find a way - neither in PIL nor in ImageMagick - to draw rotated
text (i took short views on both API's, did i miss something?) i need to
stay on my wxDC code. So the Xvnc or Xvfb thing will be the last chance to
get the CGI running. If somebody knows how to do that please post some
instructions to the list.
Thank you.
Oliver

···

-----Ursprüngliche Nachricht-----
Von: Oliver Walczak [mailto:oliver.walczak@momatec.de]
Gesendet: Donnerstag, 4. Dezember 2003 09:07
An: wxPython-users@lists.wxwindows.org
Betreff: AW: AW: [wxPython-users] wxDC - Standalone and with CGI?

Dear Robin,
Thank you a lot for your comprehensive contribution.
I use WinXP mainly for the client but the CGI will be focused to a Linux
server. However, i think that tools like Chaco constrict my goals too much.
The thing about ImageMagick i was pretty wrong i think, however, i just
heard that but it's never a good idea to talk after anyones mouth :wink:
I will try the XServer thing even if it sounds quite tricky and i'm far
beyond to be a Linux guru, but if it doesn't work it might be worth to port
everything to PIL. For any suggestions about the "dummy" Xserver and how to
do that i was very thankful.
All the best
Oliver

-----Ursprüngliche Nachricht-----
Von: cbarker [mailto:cbarker] Im Auftrag von Chris Barker
Gesendet: Mittwoch, 3. Dezember 2003 19:48
An: wxPython-users@lists.wxwindows.org
Betreff: Re: AW: [wxPython-users] wxDC - Standalone and with CGI?

Oliver Walczak wrote:

I didn't consider yet. As i began the project i was lucky to set up a

double

buffered drawing framework so easily with wxPython. The idea about the
server sided image creation came up much later. Do you know drawing
libraries which can be used to draw and show images in an interactive
window? I know ImageMagick but i heard this project was nearly dead.
Oliver

A few ideas:

1) What platform are you on? on *nix, you need to have an Xserver
running for wxWindows to connect to when it initializes. However, I
recall a suggestion on this mailing list a good while back that there is
a headless X server around that does nothing but look like an Xserver to
X clients, and you could run that on your server, and wxWindows would
think it was talking to a GUI. I'll probably try to get this working
myslef in the next few months, but havn't yet. A search of the web
should turn up what you need.

2) PIL should work fine as well, though with a different API that a DC.

3) PythonMagic does look viable...is it really dying?

4) The SciPy/Chaco folks are using Antigrain: for their bitmap
rendering...it should produce very nice output.:
http://www.antigrain.com/

They have presumably written python wrapper for it, as Chaco is Python
project. I don't know how hard it would be to use them by themsleves,
but it's worth checking out. They are focusing on Windows at the moment,
so you're likely to have more work to so on other platforms, but their
goal is cross platform support, so it shouldn't be too hard.

Please let us know what you come up with..others have had the saem
issues.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Hi Oliver,

I think, you could do something like that with PIL:
create a new image with the text, rotate the image and combine your
text-image with the image, the text should be drawn on (with
Image.composite(img1, img2,mask) or with img1.paste(img2)).
With PIL it should be possible to create a "text-image" with a
transparent background.
I haven't tested it, but it could be a way, thus I don't know, how the
text will be rendered. I had some problems with antialiasing in PIL...+

Bye,

Bjoern.

···

Am Donnerstag, 4. Dezember 2003 10:09 schrieb Oliver Walczak:

As i cannot find a way - neither in PIL nor in ImageMagick - to draw
rotated text (i took short views on both API's, did i miss
something?) i need to stay on my wxDC code. So the Xvnc or Xvfb thing
will be the last chance to get the CGI running. If somebody knows how
to do that please post some instructions to the list.
Thank you.
Oliver

--
small office solutions
info@sosnetz.de - http://www.sosnetz.de

Hi all

After much investigation into the question of printing, I have come to the
conclusion that wxPostScriptDC is just not suitable for printing text-based
reports to non-PostScript printers. I cannot comment on PostScript printers,
as I do not have one to test with.

I will explain my reasons, and I will be delighted if someone can point out
where my reasoning is faulty, as I would much prefer to use it if possible.

I am using Redhat 9, Python 2.2.3, and wxPython 2.4.1.2u. My printer is an
HP LaserJet IIIP with PCL5, set up with the Ghostscript ljet4 driver.

Here is my test page -

    def OnPrintPage(self, page):
        dc = self.GetDC()
        if self.IsPreview():
            font = dc.GetFont()
        else:
            font = wxFont(80,wxMODERN,wxNORMAL,wxNORMAL)
        font.SetWeight(wxBOLD)
        dc.SetFont(font)
        dc.DrawText('This is a heading',20,10)
        font.SetWeight(wxLIGHT)
        dc.SetFont(font)
        dc.DrawText('This is a detail line',20,30)
        dc.DrawText('This is another detail line',20,40)
        font.SetUnderlined(True) # doesn't work, but docs do say Windows
only
        dc.SetFont(font)
        dc.DrawText('This is a total line',20,60)
        return True

Problems are as follows -

Performance - if I click 'Print' from the Print Preview dialog, it takes
about 5 seconds before the light on the HP comes on to indicate that it has
received the page. A similar page from OpenOffice Writer takes about half a
second to do the same thing. Printing the same page from MSW using
wxPrinterDC also takes about half a second.

Version - if I print to a file, wxPostScriptDC produces a file with
'PS-Adobe-2.0' at the top, with a length of 29937 bytes. If I print the
equivalent OpenOffice Writer page to a file, it produces a file with
'PS-Adobe-3.0' at the top, with a length of 449114 bytes. I do not know if
this is significant, but see my next point.

Raw text - I tried both ps2ascii and pstotext to extract the text from the
above files, for sending to a dot-matrix printer. Both of them extracted the
text successfully from the OpenOffice Writer file (pstotext was better, as
it included newlines where appropriate). When I ran them against the
wxPostScriptDC file, they both only extracted a formfeed.

Fonts - wxPostScriptDC seems to ignore all attempts to set a font according
to its face name, both for previewing and for printing. It does respond to
different family names, but the differences between them are minimal.

Scaling - in preview mode, the default point size of 10 is acceptable. If
not in preview mode, I have to set the point size to 80 to get a reasonable
output. It took me a while to realise this, but it explains why previously
my text appeared as a tiny row of dots. My workaround is to loop through
each point size from 1 to 99, set the font, get the TextExtent of a single
character, and extract the height. I continue the loop until I reach an
acceptable height.

Any comments will be appreciated. First prize for me will be for someone to
say that I am doing it all wrong, and explain how I am supposed to use
wxPostScriptDC correctly. Second prize will be to say that these are valid
points, and they will be addressed in a future release.

In any event, I have abandoned this for now, and have gone back to the way I
have done printing for the last 20 years - read the printer manual, and send
raw strings of text and control characters to the printer to get it to do
what I want. The downside of this approach is that I cannot embed images :frowning:

Thanks in advance

Frank Millman

Frank Millman wrote:

Hi all

After much investigation into the question of printing, I have come to the
conclusion that wxPostScriptDC is just not suitable for printing text-based
reports to non-PostScript printers. I cannot comment on PostScript printers,
as I do not have one to test with.

Please send this message to wx-dev or wx-users as I don't know much about postscript printing either.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frank Millman wrote:

After much investigation into the question of printing, I have come to the
conclusion that wxPostScriptDC is just not suitable for printing text-based
reports to non-PostScript printers.

You may be right, but I think some of your problems can be solved.
However, I have really only done a little bit with this.

I cannot comment on PostScript printers,
as I do not have one to test with.

I doubt that would make much difference, ghostscript is very robust.

Here is my test page -

If you put this is a complete sample app, I(and probably some others)
will give it a test, and see what we can do.

Performance - if I click 'Print' from the Print Preview dialog, it takes
about 5 seconds before the light on the HP comes on to indicate that it has
received the page.

What if you save it as postscript and print that directly with "lpr
test.ps"

Version - if I print to a file, wxPostScriptDC produces a file with
'PS-Adobe-2.0' at the top, with a length of 29937 bytes. If I print the
equivalent OpenOffice Writer page to a file, it produces a file with
'PS-Adobe-3.0' at the top, with a length of 449114 bytes. I do not know if
this is significant, but see my next point.

off the top of my head, and order of magnitude smaller looks good, not
bad!

Raw text - I tried both ps2ascii and pstotext to extract the text from the
above files, for sending to a dot-matrix printer.

This is probably not the way to go anyway. You're just asking for
problems. If you need to print to a text printer, you might as well just
create the text as text.

Scaling - in preview mode, the default point size of 10 is acceptable. If
not in preview mode, I have to set the point size to 80 to get a reasonable
output. It took me a while to realise this, but it explains why previously
my text appeared as a tiny row of dots.

check what you get for :
wxPrintout.GetPPIPrinter()

or maybe DC.GetPPI()

My workaround is to loop through

each point size from 1 to 99, set the font, get the TextExtent of a single
character, and extract the height. I continue the loop until I reach an
acceptable height.

You certainly shouldn't have to do that!

This is all a little fuzzy for me too, but I think you might need to do
something with DC.SetUserScale(). The issue is that Postscript uses
points as it's native unit, but wxDCs require integer arguments (darn
that C++). If you were to work in Points, you couldn't get sub-point
resolution, so I think the default is to set it up to use 1/10 pt as the
standard unit (720 ppi). That may be what is messing things up for you.

Any comments will be appreciated. First prize for me will be for someone to
say that I am doing it all wrong, and explain how I am supposed to use
wxPostScriptDC correctly.

Are you using the wxPrintout() class?

Also, there were some posts to this list recently by Jean-Michel Fauth
about some of the strang printing issues...I would look for them.

Again, post a working sample app, and I'll take a look.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker wrote:

Also, there were some posts to this list recently by Jean-Michel Fauth
about some of the strang printing issues...I would look for them.

It looks like Jean-Michel's comments got posted to the Wiki:

http://wiki.wxpython.org:80/index.cgi/MoreCommentsOnPrinting

and of course, look at:

http://wiki.wxpython.org:80/index.cgi/Printing

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

I've started experimenting a little, and got the following results using
wxHtmlEasyPrinting:

It produces fine postscript, it prints fast, I can extract the text
fine. Underlining does not appear to work. I didn't try to do anythong
fancy with fonts.

I do have another suggestion or two:

        font.SetWeight(wxBOLD)

I've had some problems with GTK and changing fonts in place. You might
want to create a new font with the properties you want, rather than
change the existing font.

I may get a chance to do a little more with the raw PostscriptDC next
week, but maybe this will help.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

oops, I forgot to give you my code in teh last post:

-Chris

TestHTML.py (2.68 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov