ubit
ufontmetrics.hpp
1 /* ==================================================== ======== ======= *
2  *
3  * ufontmetrics.hpp
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _ufontmetrics_hpp_
18 #define _ufontmetrics_hpp_ 1
19 namespace ubit {
20 
21 class UFontMetrics {
22 public:
23  UFontMetrics();
24 
25  UFontMetrics(const UFont&, UDisp*);
26 
27  UFontMetrics(const UFontDesc&, UDisp*);
29 
31 
32  ~UFontMetrics();
33 
34  void set(const UFont&, UDisp* = null);
35  void set(const UFontDesc&, UDisp* = null);
36 
37  float getAscent() const;
38  float getDescent() const;
39  float getHeight() const;
40 
41  float getWidth(char) const;
42  float getWidth(const UStr&) const;
43  float getWidth(const UStr&, int from_char, int len = -1) const;
44  float getWidth(const char* str, int str_len = -1) const;
45 
46  int getCharPos(const char* str, int str_len, float x) const;
48 
49  float getXPos(const char* str, int str_len, int char_pos) const;
51 
52  bool getSubTextSize(const char* s, int s_len, UDimension&, float available_width,
53  int& s_sublen, int& change_line) const;
64  static bool
65  getClippedText(const UHardFont*, float clip_x, float clip_width,
66  const char* str, int str_len,
67  float x0, float y0, int& charpos_begin, int& charpos_end,
68  float& xpos_begin, float& xpos_end);
74 protected:
75  UDisp* disp;
76  const UFontDesc* fd;
77  bool own_fd;
78 };
79 
80 }
81 #endif
2D Dimension.
Definition: ugeom.hpp:55
[Impl] Native Font.
Definition: uhardfont.hpp:35
Display Context.
Definition: udisp.hpp:44
int getCharPos(const char *str, int str_len, float x) const
converts x pos to char pos.
Definition: ufontmetrics.cpp:145
[impl] Internal representation for fonts.
Definition: ufontImpl.hpp:24
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.
Definition: ufontmetrics.cpp:243
Font of a UElem or UBox container.
Definition: ufont.hpp:30
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
float getXPos(const char *str, int str_len, int char_pos) const
converts char pos to x pos.
Definition: ufontmetrics.cpp:170
Definition: ufontmetrics.hpp:21
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.
Definition: ufontmetrics.cpp:187
Ubit String.
Definition: ustr.hpp:72