File: WSvgTest.C

package info (click to toggle)
witty 3.3.3%2Bdfsg-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,228 kB
  • ctags: 26,694
  • sloc: cpp: 147,809; ansic: 77,999; xml: 16,331; sh: 1,303; makefile: 198; java: 86; sql: 14
file content (106 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#include <boost/test/unit_test.hpp>

#include <iostream>
#include <fstream>

#include <Wt/WSvgImage>
#include <Wt/WRectF>
#include <Wt/WPainter>
#include <Wt/WPen>

BOOST_AUTO_TEST_CASE( svg_test_drawWrappedText )
{
  static std::string text = 
    "ceci n'est pas un text et ceci n'est pas une pipe non plus";

  Wt::WSvgImage svgImage(1800, 800);
  Wt::WPainter p(&svgImage);
  
  //horizontal alignment
  {
  Wt::WRectF r(5, 5, 150, 100);
  p.drawText(r, Wt::AlignLeft | Wt::AlignTop, Wt::TextWordWrap, text);
  p.drawRect(r);
  }

  {
  Wt::WRectF r(160, 5, 150, 100);
  p.drawText(r, Wt::AlignRight | Wt::AlignTop, Wt::TextWordWrap, text);
  p.drawRect(r);
  }

  {
  Wt::WRectF r(315, 5, 150, 100);
  p.drawText(r, Wt::AlignCenter | Wt::AlignTop, Wt::TextWordWrap, text);
  p.drawRect(r);
  }
  
  {
  Wt::WRectF r(470, 5, 150, 100);
  p.drawText(r, Wt::AlignJustify | Wt::AlignTop, Wt::TextWordWrap, text);
  p.drawRect(r);
  }

  //red text
  {
  Wt::WRectF r(625, 5, 150, 100);
  p.setPen(Wt::WPen(Wt::red));
  p.drawText(r, Wt::AlignJustify | Wt::AlignTop, Wt::TextWordWrap, text);
  p.drawRect(r);
  }

  p.end();
  std::ofstream f("wrapped_text.svg");
  svgImage.write(f);
}

BOOST_AUTO_TEST_CASE( svg_test_drawSingleText )
{
  static std::string text = 
    "ceci n'est pas un text et ceci n'est pas une pipe non plus";

  Wt::WSvgImage svgImage(1800, 800);
  Wt::WPainter p(&svgImage);

  //horizontal alignment
  {
  Wt::WRectF r(5, 5, 150, 100);
  p.drawText(r, Wt::AlignLeft | Wt::AlignTop, text);
  p.drawRect(r);
  }

  {
  Wt::WRectF r(5, 110, 150, 100);
  p.drawText(r, Wt::AlignRight | Wt::AlignTop, text);
  p.drawRect(r);
  }

  {
  Wt::WRectF r(5, 215, 150, 100);
  p.drawText(r, Wt::AlignCenter | Wt::AlignTop, text);
  p.drawRect(r);
  }
  
  {
  Wt::WRectF r(5, 320, 150, 100);
  p.drawText(r, Wt::AlignJustify | Wt::AlignTop, text);
  p.drawRect(r);
  }

  //red text
  {
  Wt::WRectF r(5, 425, 150, 100);
  p.setPen(Wt::WPen(Wt::red));
  p.drawText(r, Wt::AlignJustify | Wt::AlignTop, text);
  p.drawRect(r);
  }

  p.end();
  std::ofstream f("singleline_text.svg");
  svgImage.write(f);
}