Tips and Tricks » History » Version 8
  d3fault d3fault, 08/28/2014 08:43 PM 
  
| 1 | 1 | Pieter Libin | h1. Tips and Tricks | 
|---|---|---|---|
| 2 | |||
| 3 | {{toc}} | ||
| 4 | |||
| 5 | |||
| 6 | 2 | Pieter Libin | h2. Making a hard-copy of painted graphics | 
| 7 | 1 | Pieter Libin | |
| 8 | 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. | ||
| 9 | |||
| 10 | 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. | ||
| 11 | |||
| 12 | 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. | ||
| 13 | |||
| 14 | The WSvgImage class allows you to easily create an SVG image, and save it to a (file) stream, using the following template: | ||
| 15 | |||
| 16 | <pre> | ||
| 17 | WSvgImage image(400, 300); | ||
| 18 | WPainter painter(&image); | ||
| 19 | |||
| 20 | // paint things on the painter, like you normally do in WPaintedWidget::paintEvent(). | ||
| 21 | // | ||
| 22 | // e.g. you could do WCartesianChart *c = ... | ||
| 23 | // c->paint(painter); | ||
| 24 | |||
| 25 | painter.end(); | ||
| 26 | std::ofstream f("image.svg"); | ||
| 27 | image.write(f); | ||
| 28 | f.close(); | ||
| 29 | </pre> | ||
| 30 | 3 | Pieter Libin | |
| 31 | |||
| 32 | |||
| 33 | h2. Creating .CUR files | ||
| 34 | 4 | Pieter Libin | |
| 35 | 3 | Pieter Libin | Creating .CUR files which are valid in Firefox and Chrome can be quite a pickle, especially if you want to specify a custom hotspot. | 
| 36 | This program allows you to create such .CUR files: | ||
| 37 | http://www.rw-designer.com/cursor-maker | ||
| 38 | 5 | Richel Bilderbeek | |
| 39 | h2. Assert | ||
| 40 | |||
| 41 | Under some environments, when linking to the Wt library, 'assert' is removed from the code. This page shows a custom assert to be used with Wt: http://richelbilderbeek.nl/CppWtAssert.htm | ||
| 42 | 8 | d3fault d3fault | |
| 43 | |||
| 44 | h2. Redirect HTTP to HTTPS | ||
| 45 | |||
| 46 | If you want to allow http connections but redirect them to https, you can use the following code in your WApplication constructor: | ||
| 47 | |||
| 48 | <pre> | ||
| 49 | if(env.urlScheme() != "https") | ||
| 50 | { | ||
| 51 | 	redirect("https://" + env.hostName() + url()); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | </pre> |