Project

General

Profile

Changing Qt painting code to run in Wt as well

Added by Tony Rietwyk almost 10 years ago

Hi Everybody,

I have an existing Qt based custom graphic that draws musical notation using QPainter and a special font Bravura. Most of the interface appears the same, so I am hoping that I can get away with using typedefs to switch between QPainter and WPainter, QBrush and WBrush, etc. Note that I don't expect to create a QWidget - so issues of threading, etc. should not be relevant. Some issues found already:

1) I use QFontDatabase.addApplicationFont to load the font from a Qt resource. Is there a Wt equivalent that makes a bundled font available to WPainter?

2) I use QPainter.drawText( x, y, text ) to draw each font symbol. WPainter.drawText seems to insist on having a specific rectangle. I can see that AlignBaseline | AlignLeft should give the same result, but I'm not clear how to specify the WRect in that case. Maybe I should use AlignTop | AlignLeft, and adjust the positions by the height of the font?

3) Has anyone tried anything similar to this?

4) If I were to convert the whole app to Wt, are there examples of creating a desktop exe with say embedded WebKit or Chromium talking internally without a server? What about in mobile devices embedding the system web browser?

Regards,

Tony


Replies (1)

RE: Changing Qt painting code to run in Wt as well - Added by Koen Deforche almost 10 years ago

Hey,

(1) font loading is quite different, and in Wt will depend also on the target (client-side rendering using canvas/SVG/... or server-side rendering using PDF/PNG/...).

For client-side rendering you need to make sure you load the font in the browser (as a web font), and then you can reference it from WFont().

For server-side rendering you can load the font in your device (e.g. WPdfImage::addFontCollection()) but then you need to make sure pango is disabled from your build. To use your font in this case you need to reference it from WFont() by setting a name that matches the font file (e.g. 'Arial' for a file 'Arial.ttf').

(2) Depending on the alignment parameters some of the rectangle corner points are indeed not used. AlignBaseline is not supported however but I believe we should add it (it would behave like AlignBottom but aligning the baseline to the rect bottom). Feel free to create a feature ticket for it.

(3) No, not in C. We did do something similar in Java though, by implementing a 'java.awt.PaintDevice' that writes to a WPaintDevice. Perhaps it's equally feasible to implement a QPaintDevice that forwards to a WPaintDevice? That would actually be nice to have in the 'libwtwithqt' library.

(4) We did both approaches, but using a loopback server in both cases. In theory it should be possible to by-pass the server, but I'm unsure if there are enough benefits.

Koen

    (1-1/1)