-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathufontmetrics.hpp
81 lines (66 loc) · 2.8 KB
/
ufontmetrics.hpp
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
/* ==================================================== ======== ======= *
*
* ufontmetrics.hpp
* Ubit GUI Toolkit - Version 6
* (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
*
* ***********************************************************************
* COPYRIGHT NOTICE :
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
* IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
* YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
* GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
* EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
* SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
* ***********************************************************************/
#ifndef _ufontmetrics_hpp_
#define _ufontmetrics_hpp_ 1
namespace ubit {
class UFontMetrics {
public:
UFontMetrics();
UFontMetrics(const UFont&, UDisp*);
UFontMetrics(const UFontDesc&, UDisp*);
///< Note: the UFontDesc argument must NOT be destroyed while this UFontMetrics is used.
UFontMetrics(UUpdateContext&);
~UFontMetrics();
void set(const UFont&, UDisp* = null);
void set(const UFontDesc&, UDisp* = null);
float getAscent() const;
float getDescent() const;
float getHeight() const;
float getWidth(char) const;
float getWidth(const UStr&) const;
float getWidth(const UStr&, int from_char, int len = -1) const;
float getWidth(const char* str, int str_len = -1) const;
int getCharPos(const char* str, int str_len, float x) const;
///< converts x pos to char pos.
float getXPos(const char* str, int str_len, int char_pos) const;
///< converts char pos to x pos.
bool getSubTextSize(const char* s, int s_len, UDimension&, float available_width,
int& s_sublen, int& change_line) const;
/**< returns font metrics of a substring that verifies certain conditions.
* Notes:
* - the substring starts from the beginning of 'str' and ends at
* the 1st \n or 1st " " that is before 'available_width'.
* - it is equal to 'str' otherwise.
* - returns w and h that this substring occupies and its length 'sublen'
* - change_line = 1 si line must be changed because of size
* and 2 if a \n was found
*/
static bool
getClippedText(const UHardFont*, float clip_x, float clip_width,
const char* str, int str_len,
float x0, float y0, int& charpos_begin, int& charpos_end,
float& xpos_begin, float& xpos_end);
/**< returns the substring that is enclosed in the current clip.
* utilise par drawString en mode OpenGL pour eviter de dessiner
* ce qui sort de la zone de clipping
*/
protected:
UDisp* disp;
const UFontDesc* fd;
bool own_fd;
};
}
#endif