Project

General

Profile

Tips and Tricks » History » Version 10

Roel Standaert, 01/30/2023 12:38 PM
Remove obsolete info about assert, linking with Wt should not normally disable asserts

1 10 Roel Standaert
Tips and Tricks
2
===============
3 1 Pieter Libin
4
{{toc}}
5
6 10 Roel Standaert
Getting rid of that annoying "?\_=" in your clean internal path/URL
7
-------------------------------------------------------------------
8 9 d3fault d3fault
9 10 Roel Standaert
For reasons not exactly clear to this author, Wt prepends ?\_= to every internal path by default. They way to fix this behavior is simple yet delicate. Doing it wrong can give you subtle and intermittent problems (I saw an occassional segfault when I wasn't using relative paths).  
10
1) cd into the directory of your binary, then: \`ln -s /usr/share/Wt/resources resources\` (alternatively, make a copy of the Wt-provided resources folder to your current directory)  
11
2) When launching your executable, tell it that that resources folder is also in your docroot. You can specify multiple docroots by separating them with a semicolon, like this: \`---docroot ".;/resources"\`. The double quotes are to prevent the shell from terminating the statement and are necessary. The way you type "/resources" must be exact (putting an absolute path, or even "resources" without the leading slash, will lead to problems!)  
12 9 d3fault d3fault
tl;dr:
13
14 10 Roel Standaert
    $ cd /home/user/myProject/
15
    $ ln -s /usr/share/Wt/resources resources
16
    $ ./myWtApp --http-address 0.0.0.0 --http-port 6669 --docroot ".;/resources"
17 1 Pieter Libin
18 10 Roel Standaert
Making a hard-copy of painted graphics
19
--------------------------------------
20 1 Pieter Libin
21
The primary use for the Wt painting API is to paint on a WPaintedWidget. Internally, this uses either a VML, SVG or HTML 5 canvas painting device to deliver the painting to the browser.
22
23
It is also possible to paint directly to an SVG image, which is a standardized generic vector graphics format, and increasingly supported by various tools.
24
25 10 Roel Standaert
You could use the SVG image as a starting point for exporting the painted graphics to raster format. Using the [imagemagick](http://www.imagemagick.org/script/index.php) or [graphicsmagick](http://www.graphicsmagick.org/) libraries, you can convert from SVG to other formats using the library API or using the command line 'convert' tool. Using [inkscape](http://www.inkscape.org/), a sophisticated SVG editor, you may get high quality SVG rendering (with, compared to imagemagick, much better font support) from the command-line (see the manpage). Another option may be [librsvg](http://librsvg.sourceforge.net).
26 1 Pieter Libin
27
The WSvgImage class allows you to easily create an SVG image, and save it to a (file) stream, using the following template:
28
29 10 Roel Standaert
    WSvgImage image(400, 300);
30
    WPainter painter(&image);
31 1 Pieter Libin
32 10 Roel Standaert
    // paint things on the painter, like you normally do in WPaintedWidget::paintEvent().
33
    //
34
    // e.g. you could do WCartesianChart *c = ...
35
    // c->paint(painter);
36 3 Pieter Libin
37 10 Roel Standaert
    painter.end();
38
    std::ofstream f("image.svg");
39
    image.write(f);
40
    f.close();
41 5 Richel Bilderbeek
42 10 Roel Standaert
Creating .CUR files
43
-------------------
44 5 Richel Bilderbeek
45 10 Roel Standaert
Creating .CUR files which are valid in Firefox and Chrome can be quite a pickle, especially if you want to specify a custom hotspot.  
46
This program allows you to create such .CUR files:  
47 8 d3fault d3fault
http://www.rw-designer.com/cursor-maker
48
49 10 Roel Standaert
Redirect HTTP to HTTPS
50
----------------------
51 8 d3fault d3fault
52
If you want to allow http connections but redirect them to https, you can use the following code in your WApplication constructor:
53
54 10 Roel Standaert
    if(env.urlScheme() != "https")
55
    {
56
        redirect("https://" + env.hostName() + url());
57
        return;
58
    }