-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathServerSideFontMetrics.C
More file actions
66 lines (56 loc) · 1.52 KB
/
ServerSideFontMetrics.C
File metadata and controls
66 lines (56 loc) · 1.52 KB
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
/*
* Copyright (C) 2014 Emweb bv, Herent, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include "Wt/WException.h"
#include "Wt/WFontMetrics.h"
#include "Wt/WPaintDevice.h"
#include "Wt/WPainter.h"
#ifdef WT_HAS_WPDFIMAGE
#include "Wt/WPdfImage.h"
#endif // WT_HAS_WPDFIMAGE
#include "ServerSideFontMetrics.h"
namespace Wt {
ServerSideFontMetrics::ServerSideFontMetrics()
{
#ifdef WT_HAS_WPDFIMAGE
img_.reset(new WPdfImage(100, 100));
painter_.reset(new WPainter(img_.get()));
#endif // WT_HAS_WPDFIMAGE
}
ServerSideFontMetrics::~ServerSideFontMetrics()
{ }
WFontMetrics ServerSideFontMetrics::fontMetrics(const WFont& font)
{
#ifdef WT_HAS_WPDFIMAGE
painter_->setFont(font);
return painter_->device()->fontMetrics();
#else
throw WException("ServerSideFontMetrics not available");
#endif // WT_HAS_WPDFIMAGE
}
WTextItem
ServerSideFontMetrics::measureText(const WFont& font,
const WString& text, double maxWidth,
bool wordWrap)
{
#ifdef WT_HAS_WPDFIMAGE
painter_->setFont(font);
WTextItem t = painter_->device()->measureText(text, maxWidth, wordWrap);
const double REL_ERROR = 1.02;
return WTextItem(t.text(), t.width() * REL_ERROR,
t.nextWidth() > 0 ? t.nextWidth() * REL_ERROR : t.nextWidth());
#else
throw WException("ServerSideFontMetrics not available");
#endif // WT_HAS_WPDFIMAGE
}
bool ServerSideFontMetrics::available()
{
#ifdef WT_HAS_WPDFIMAGE
return true;
#else
return false;
#endif // WT_HAS_WPDFIMAGE
}
}