You.i Engine
YiFontUtilities.h
Go to the documentation of this file.
1 #ifndef _YI_FONT_UTILITIES_H_
2 #define _YI_FONT_UTILITIES_H_
3 
4 #include "utility/YiString.h"
5 
6 #include <layout/RunArrays.h>
7 
8 class CYILEFontInstanceFT;
9 
10 U_NAMESPACE_BEGIN
11 class ParagraphLayout;
12 U_NAMESPACE_END
13 
14 
21 {
22 public:
23 
29  class TextInfo
30  {
31  public:
32  TextInfo(ssize_t nFontID, float fFontSize, const CYIString &text);
33  ~TextInfo();
34 
35  const CYIString &GetText() const;
36  ssize_t GetFontID() const;
37  float GetFontSize() const;
38 
39  private:
40  ssize_t nFontID;
41  float fFontSize;
42  CYIString text;
43 
44  U_NAMESPACE_QUALIFIER ParagraphLayout *pParagraphLayout;
45  U_NAMESPACE_QUALIFIER FontRuns fontRuns;
46  CYILEFontInstanceFT *pFontInstance;
47  U_NAMESPACE_QUALIFIER UnicodeString unicodeText;
48  int32_t nCodeUnitCount;
49 
50  friend class CYIFontUtilities;
52  };
53 
54  /*
55  \details Returns the width of the text specified by \a textInfo.
56 
57  \note This function will not handle line break characters.
58 
59  \sa GetParagraphWidth
60  */
61  static float GetTextWidth(const TextInfo &textInfo);
62 
63  /*
64  \details Returns the width of the text specified by \a textInfo confined to a paragraph bound to \a fWidthToFit. This will effectively return the width of the widest line in the text taking into account any line break characters.
65 
66  \note Does not benefit from the text layout caching provided by TextInfo.
67  */
68  static float GetParagraphWidth(const TextInfo &textInfo, float fWidthToFit);
69 
70  /*
71  \details Returns the substring of the text specified by \a textInfo which will fit within the width \a fWidthToFit.
72 
73  The text returned will be terminated on a line boundary (i.e. will not break in the middle of a word, sentence ending punctuation will not be put on a different line, etc.)
74 
75  The width of the returned substring will be populated in \a pfResultingLineWidth if provided.
76 
77  \note This function will not handle line break characters.
78 
79  \note This function may return a string which ends in the middle of a word for languages other than English.
80  */
81  static CYIString GetTextToFit(const TextInfo &textInfo, float fWidthToFit, float *pfResultingLineWidth = nullptr);
82 
83  /*
84  \details Returns the substring of the text specified by \a textInfo which would be the last line of text if it were laid out within the width \a fWidthToFit. If no line breaking occurs, the whole string is returned.
85 
86  The width of the returned substring will be populated in \a pfLastLineWidth and the total number of lines will be populated in \a puLineCount, if provided.
87 
88  \note This function will not handle line break characters.
89  */
90  static CYIString GetLastLine(const TextInfo &textInfo, float fWidthToFit, float *pfLastLineWidth = nullptr, uint32_t *puLineCount = nullptr);
91 
92  /*
93  \details Returns the number of lines required to lay out the text specified by \a textInfo within the width \a fWidthToFit.
94 
95  \note This function will not handle line break characters.
96  */
97  static int32_t GetLineCount(const TextInfo &textInfo, float fWidthToFit);
98 
99  /*
100  \details Returns the leading in pixel units for the font \a nFontID at font size \a fFontSize.
101  */
102  static float GetFontLeading(ssize_t nFontID, float fFontSize);
103 
104 private:
106 };
107 
110 #endif
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
Definition: YiFontUtilities.h:20
const CYIString & GetText() const
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
static float GetParagraphWidth(const TextInfo &textInfo, float fWidthToFit)
float GetFontSize() const
static CYIString GetTextToFit(const TextInfo &textInfo, float fWidthToFit, float *pfResultingLineWidth=nullptr)
Contains information required for laying out text.
Definition: YiFontUtilities.h:29
static CYIString GetLastLine(const TextInfo &textInfo, float fWidthToFit, float *pfLastLineWidth=nullptr, uint32_t *puLineCount=nullptr)
static float GetTextWidth(const TextInfo &textInfo)
friend class CYIFontUtilities
Definition: YiFontUtilities.h:50
TextInfo(ssize_t nFontID, float fFontSize, const CYIString &text)
int ssize_t
Definition: YiPredefWin32.h:133
static int32_t GetLineCount(const TextInfo &textInfo, float fWidthToFit)
ssize_t GetFontID() const
static float GetFontLeading(ssize_t nFontID, float fFontSize)