1
|
#include <Wt/WApplication.h>
|
2
|
#include <Wt/WBrush.h>
|
3
|
#include <Wt/WColor.h>
|
4
|
#include <Wt/WContainerWidget.h>
|
5
|
#include <Wt/WEnvironment.h>
|
6
|
#include <Wt/WFont.h>
|
7
|
#include <Wt/WPaintedWidget.h>
|
8
|
#include <Wt/WPainter.h>
|
9
|
#include <Wt/WPen.h>
|
10
|
#include <Wt/WRectF.h>
|
11
|
#include <Wt/WText.h>
|
12
|
|
13
|
using namespace Wt;
|
14
|
|
15
|
class PaintedWidget : public WPaintedWidget
|
16
|
{
|
17
|
public:
|
18
|
PaintedWidget(AlignmentFlag alignment, WFont& title_font) :
|
19
|
Wt::WPaintedWidget(), alignment_(alignment), titleFont_(title_font) { }
|
20
|
~PaintedWidget() { }
|
21
|
|
22
|
protected:
|
23
|
void paintEvent(WPaintDevice *paintDevice) {
|
24
|
WPainter painter(paintDevice);
|
25
|
|
26
|
auto rect = WRectF(0, 0, 800, 30);
|
27
|
WString text("The quick brown fox jumped over the lazy dog");
|
28
|
|
29
|
painter.fillRect(rect, WBrush(StandardColor::Yellow));
|
30
|
|
31
|
painter.setFont(titleFont_);
|
32
|
painter.drawText(rect, WFlags<AlignmentFlag>(AlignmentFlag::Center) | alignment_, text);
|
33
|
}
|
34
|
|
35
|
private:
|
36
|
AlignmentFlag alignment_;
|
37
|
WFont titleFont_;
|
38
|
};
|
39
|
|
40
|
class TestApp : public WApplication {
|
41
|
public:
|
42
|
TestApp(const WEnvironment& env);
|
43
|
};
|
44
|
|
45
|
TestApp::TestApp(const WEnvironment& env) : WApplication(env)
|
46
|
{
|
47
|
setTitle("Test font clipping");
|
48
|
|
49
|
static std::array<std::pair<AlignmentFlag, std::string>, 3> const alignments {
|
50
|
std::make_pair(AlignmentFlag::Top, "Top"),
|
51
|
std::make_pair(AlignmentFlag::Middle, "Middle"),
|
52
|
std::make_pair(AlignmentFlag::Bottom, "Bottom")
|
53
|
};
|
54
|
|
55
|
static std::array<std::pair<RenderMethod, std::string>, 3> const methods {
|
56
|
std::make_pair(RenderMethod::HtmlCanvas, "canvas"),
|
57
|
std::make_pair(RenderMethod::PngImage, "png" ),
|
58
|
std::make_pair(RenderMethod::InlineSvgVml, "svg" )
|
59
|
};
|
60
|
|
61
|
auto title_font = WFont();
|
62
|
|
63
|
/*
|
64
|
* for testing, manually switch size and font families...
|
65
|
*/
|
66
|
title_font.setSize(WLength(30));
|
67
|
title_font.setFamily(FontFamily::SansSerif, "Arial");
|
68
|
// title_font.setFamily(FontFamily::Serif, "'DejaVu Serif'");
|
69
|
|
70
|
for (auto alignment: alignments) {
|
71
|
root()->addNew<WText>(std::string("<strong>======= alignment: ") +
|
72
|
alignment.second + " =======</strong><br/>");
|
73
|
for (auto method: methods) {
|
74
|
root()->addNew<WText>(std::string("method: ") + method.second);
|
75
|
auto pw = root()->addNew<PaintedWidget>(alignment.first, title_font);
|
76
|
pw->resize(800, 50);
|
77
|
pw->setPreferredMethod(method.first);
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
int main(int argc, char **argv)
|
83
|
{
|
84
|
return WRun(argc, argv, [](const WEnvironment& env) {return std::make_unique<TestApp>(env);});
|
85
|
}
|