You.i Engine
YiTextSceneNode.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_TEXT_SCENE_NODE_H_
3 #define _YI_TEXT_SCENE_NODE_H_
4 
7 #include "utility/YiColor.h"
8 
11 class CYITextSceneNodePriv;
12 
79 {
80  friend class CYITextSceneNodePriv;
81 
82 public:
83  enum class Justification : uint8_t
84  {
85  Left = 0,
86  Right,
87  Center
88  };
89 
91  {
93 
94  bool operator==(const YI_TEXT_STYLE_DEF &other) const;
95  bool operator!=(const YI_TEXT_STYLE_DEF &other) const;
96 
98  int32_t m_fontSize;
99  int32_t m_leading;
100  bool m_isAllCaps;
103  int32_t m_baselineShift;
104  int32_t m_tracking;
105  int32_t m_kerning;
108  };
109 
110  struct YI_TEXT_DEF
111  {
112  YI_TEXT_DEF();
113 
115  size_t m_length;
118  bool m_multiline;
119  bool m_ellipses;
124  std::vector<YI_TEXT_STYLE_DEF> m_styles;
125  };
126 
128  virtual ~CYITextSceneNode();
129 
137  float GetTextWidth();
138 
146  float GetTextHeight();
147 
154 
161 
168  void SetTextOffsetX(float textOffsetX);
169 
176  void SetTextMaxWidth(float maxWidth);
177 
187  bool SetFont(const CYIString &fontFamilyName, const CYIString &fontStyle, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
188 
196  void SetFontID(ssize_t fontID, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
197 
209  bool SetFontFamily(const CYIString &fontFamilyName, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
210 
222  bool SetFontStyle(const CYIString &fontStyleName, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
223 
229  void SetFontSize(int32_t fontSize, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
230 
236  void SetFontColor(const CYIColor &Color, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
237 
243  void SetAllCaps(bool enable, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
244 
250  void SetScriptMode(CYITextEngine::ScriptMode scriptMode, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
251 
257  void SetBaselineShift(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
258 
264  void SetTracking(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
265 
271  void SetKerning(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
272 
278  void SetLeading(int32_t leading, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
279 
285  void SetEllipses(bool enable);
286 
291  void SetMaximumNumberOfLines(int32_t numberOfLines);
292 
301  void SetAdjustsFontSizeToFit(bool adjustsFontSizeToFit);
302 
308  void SetMinimumFontScale(float minimumFontScale);
309 
313  void SetMultiline(bool enable);
314 
315  virtual void SetSize(const glm::vec3 &size, bool dirtyLayout = true) override;
316 
327  void SetText(const CYIString &rText);
328 
342  void SetMarkedUpText(const CYIString &rMarkedUpText, CYITextMarkupParser *pMarkupParser = nullptr, const CYICustomMarkupTagsProvider *pExternalTagsProvider = nullptr);
343 
347  void SetXJustify(Justification xJustify);
348 
356  void SetTrimmingMode(CYITextEngine::TrimmingMode trimmingMode);
357 
364 
376  void SetPointTypeOn(int32_t width = 0);
377 
387  void SetBoxTypeOn(int32_t boxWidth, int32_t boxHeight);
388 
394  void SetLineStyle(CYITextEngine::LineStyle textLineStyle, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
395 
396  float GetTextOffsetX() const;
397  const CYIString &GetText() const;
398  const CYIString &GetMarkedUpText() const;
399  size_t GetLength() const;
400  Justification GetXJustify() const;
401  bool GetMultiline() const;
402  bool GetEllipses() const;
403  int32_t GetMaximumNumberOfLines() const;
404  bool GetAdjustsFontSizeToFit() const;
405  float GetMinimumFontScale() const;
406 
407  ssize_t GetFontID(size_t codepointIndex = 0) const;
408  const CYIString &GetFontFamily(size_t codepointIndex = 0) const;
409  const CYIString &GetFontStyle(size_t codepointIndex = 0) const;
410  size_t GetFontSize(size_t codepointIndex = 0) const;
411  const CYIColor &GetFontColor(size_t codepointIndex = 0) const;
412  bool IsAllCaps(size_t codepointIndex = 0) const;
413  CYITextEngine::LineStyle GetLineStyle(size_t codepointIndex = 0) const;
414  int32_t GetLeading(size_t codepointIndex = 0) const;
415  CYITextEngine::ScriptMode GetScriptMode(size_t codepointIndex = 0) const;
416  int32_t GetBaselineShift(size_t codepointIndex = 0) const;
417  int32_t GetTracking(size_t codepointIndex = 0) const;
418  int32_t GetKerning(size_t codepointIndex = 0) const;
419 
423  const std::vector<YI_TEXT_STYLE_DEF> &GetTextStyles() const;
424 
428  const YI_TEXT_STYLE_DEF &GetTextStyle(size_t codepointIndex) const;
429 
435  void SetTextStyle(const YI_TEXT_STYLE_DEF &style, size_t firstCodepointIndex);
436 
445  void SetTextStyles(const std::vector<YI_TEXT_STYLE_DEF> &styles);
446 
452  void SetEllipsisStyle(const YI_TEXT_STYLE_DEF &style);
453 
458 
467  int32_t GetBoxWidth() const;
476  int32_t GetBoxHeight() const;
477 
484  void SetUseFontTables(bool useFontTables);
485 
489  bool IsUsingFontTables() const;
490 
496  bool IsBoxType() const;
497 
503  bool IsPointType() const;
504 
508  virtual YI_FLOAT_RECT GetRectForTextRange(size_t startIndex, size_t endIndex, float horizontalPixelRatio, float verticalPixelRatio);
509 
513  bool IsCharacterRightToLeft(size_t charIndex) const;
514 
518  bool IsBaseRightToLeft() const;
519 
523  CYITextEngine::PositionInString GetIndexOfPosition(float x, float y, float horizontalPixelRatio, float verticalPixelRatio);
524 
529 
533  void SetTextLayoutFactory(std::function<std::unique_ptr<CYITextLayout>()> textLayoutFactory);
534 
535  virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override;
536  virtual void ApplyMeasurements() override;
537 
543  float GetAdjustedFontSizeScale();
544 
545 protected:
550  const std::shared_ptr<const CYITextLayout> &GetTextLayout(const CYITextEngine::RenderInfo &textRenderInfo);
551 
560 
565 
569  virtual YI_FLOAT_RECT_REL CalculateGlyphBox(const YI_RECT_REL &boxRect);
570 
576  YI_FLOAT_RECT_REL CalculateGlyphBox(const CYITextLayout *pLayout, const YI_FLOAT_RECT_REL &layoutRect) const;
577 
581  virtual void PrepareToDraw() = 0;
582 
583  virtual void WorldBoundingBoxUpdated() override;
584  virtual void UpdateEnd() override;
585  virtual void WorldSurfaceScaleUpdated() override;
586  virtual CYIString GetDumpTreeString() const override;
587 
591  void SetTextDirty();
592 
596  static bool HasAllCaps(const YI_TEXT_DEF &rTextDef);
597 
601  static void UpdateTextForAllCaps(const YI_TEXT_DEF &rTextDef, CYIString &rText);
602 
606  virtual void UpdateTextRect();
607 
616  bool m_isBoxType;
619  std::function<std::unique_ptr<CYITextLayout>()> m_textLayoutFactory;
620 
621 private:
622  void CreateTextMesh();
623  void UpdateCachedTextLayout() const;
624 
625  float m_textOffsetX;
626  std::shared_ptr<const CYITextLayout> m_pCachedTextLayout;
627  CYITextEngine::RenderInfo m_cachedTextRenderInfo;
628 
630 };
631 
636 #ifdef YI_FUNCTION_SPECIALIZATION_FULLY_SUPPORTED
637 template<>
638 inline const CYITextSceneNode *YiDynamicCast<CYITextSceneNode>(const CYISceneNode *pObject)
639 {
640  return pObject ? (pObject->CanCastTo<CYITextSceneNode>() ? static_cast<const CYITextSceneNode *>(pObject) : nullptr) : nullptr;
641 }
642 #endif
643 
644 #endif // _YI_TEXT_SCENE_NODE_H_
bool m_ellipses
Definition: YiTextSceneNode.h:119
CYIString m_text
Definition: YiTextSceneNode.h:114
static void UpdateTextForAllCaps(const YI_TEXT_DEF &rTextDef, CYIString &rText)
Justification
Definition: YiTextSceneNode.h:83
void SetTextOffsetX(float textOffsetX)
bool IsCharacterRightToLeft(size_t charIndex) const
bool m_userSpecifiedWidth
Definition: YiTextSceneNode.h:123
virtual void SpecializeTextRenderInfo(CYITextEngine::RenderInfo *pInfo)
void SetScriptMode(CYITextEngine::ScriptMode scriptMode, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
void SetBoxTypeOn(int32_t boxWidth, int32_t boxHeight)
CYITextEngine::PositionInString GetOffsetPosition(CYITextEngine::PositionInString initialPosition, int8_t offset)
int32_t m_fontSize
Definition: YiTextSceneNode.h:98
void SetPointTypeOn(int32_t width=0)
static bool HasAllCaps(const YI_TEXT_DEF &rTextDef)
ssize_t GetFontID(size_t codepointIndex=0) const
bool GetAdjustsFontSizeToFit() const
virtual void SetSize(const glm::vec3 &size, bool dirtyLayout=true) override
CYITextEngine::ScriptMode m_scriptMode
Definition: YiTextSceneNode.h:102
CYITextEngine::TrimmingMode m_trimmingMode
Definition: YiTextSceneNode.h:117
Struct used to pass information when rendering text.
Definition: YiTextEngine.h:195
virtual YI_FLOAT_RECT GetRectForTextRange(size_t startIndex, size_t endIndex, float horizontalPixelRatio, float verticalPixelRatio)
int32_t m_tracking
Definition: YiTextSceneNode.h:104
void ResetPerCharacterStyles()
Definition: YiPredef.h:291
void SetTextStyles(const std::vector< YI_TEXT_STYLE_DEF > &styles)
int32_t m_baselineShift
Definition: YiTextSceneNode.h:103
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
std::function< std::unique_ptr< CYITextLayout >)> m_textLayoutFactory
Definition: YiTextSceneNode.h:619
const CYIString & GetText() const
void SetMaximumNumberOfLines(int32_t numberOfLines)
float m_minimumFontScale
Definition: YiTextSceneNode.h:122
void SetXJustify(Justification xJustify)
LineStyle
Definition: YiTextEngine.h:73
virtual void WorldSurfaceScaleUpdated() override
bool IsUsingFontTables() const
int32_t m_leading
Definition: YiTextSceneNode.h:99
void SetMinimumFontScale(float minimumFontScale)
virtual void UpdateEnd() override
virtual ~CYITextSceneNode()
bool SetFontStyle(const CYIString &fontStyleName, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
void SetEllipses(bool enable)
virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override
CYITextEngine::ScriptMode GetScriptMode(size_t codepointIndex=0) const
bool operator!=(const CYIVariant &rLHS, const CYIVariant &rRHS)
All types are supported. Two &#39;invalid&#39; variants are considered to be equal.
bool SetFont(const CYIString &fontFamilyName, const CYIString &fontStyle, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
virtual void UpdateTextRect()
CYITextEngine::LineStyle m_textLineStyle
Definition: YiTextSceneNode.h:101
size_t m_length
Definition: YiTextSceneNode.h:115
const CYIString & GetFontFamily(size_t codepointIndex=0) const
void SetFontID(ssize_t fontID, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
Justification GetXJustify() const
void SetKerning(int32_t baselineShift, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
void SetTextLayoutFactory(std::function< std::unique_ptr< CYITextLayout >()> textLayoutFactory)
size_t GetFontSize(size_t codepointIndex=0) const
bool m_usesFontTables
Definition: YiTextSceneNode.h:618
bool m_isAllCaps
Definition: YiTextSceneNode.h:100
virtual YI_FLOAT_RECT_REL CalculateGlyphBox()
virtual void WorldBoundingBoxUpdated() override
void SetAdjustsFontSizeToFit(bool adjustsFontSizeToFit)
float m_textMaxWidth
Definition: YiTextSceneNode.h:614
virtual void ApplyMeasurements() override
Definition: YiTextMarkupParser.h:15
CYIColor m_Color
Definition: YiTextSceneNode.h:106
Definition: YiTextSceneNode.h:110
void SetBaselineShift(int32_t baselineShift, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
bool IsPointType() const
void SetMultiline(bool enable)
void SetUseFontTables(bool useFontTables)
friend class CYITextSceneNodePriv
Definition: YiTextSceneNode.h:80
float GetAdjustedFontSizeScale()
bool IsBaseRightToLeft() const
CYITextEngine::PositionInString GetIndexOfPosition(float x, float y, float horizontalPixelRatio, float verticalPixelRatio)
std::vector< YI_TEXT_STYLE_DEF > m_styles
Definition: YiTextSceneNode.h:124
void SetLineStyle(CYITextEngine::LineStyle textLineStyle, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
float GetMinimumFontScale() const
A scene node is the base type for all nodes which are used by the scene manager; it is an integral pa...
Definition: YiSceneNode.h:99
int32_t m_numberOfLines
Definition: YiTextSceneNode.h:120
Definition: YiSceneNode.h:373
Definition: YiPredef.h:417
A scene node type that renders text.
Definition: YiTextSceneNode.h:78
virtual CYIString GetDumpTreeString() const override
virtual void PrepareToDraw()=0
const std::vector< YI_TEXT_STYLE_DEF > & GetTextStyles() const
const CYIString & GetFontStyle(size_t codepointIndex=0) const
CYIString m_markedUpText
Definition: YiTextSceneNode.h:609
Base class for abstracting the layout for text.
Definition: YiTextLayout.h:22
void SetTrimmingMode(CYITextEngine::TrimmingMode trimmingMode)
bool m_multiline
Definition: YiTextSceneNode.h:118
CYITextEngine::LineStyle GetLineStyle(size_t codepointIndex=0) const
void SetText(const CYIString &rText)
bool IsBoxType() const
void SetMarkedUpText(const CYIString &rMarkedUpText, CYITextMarkupParser *pMarkupParser=nullptr, const CYICustomMarkupTagsProvider *pExternalTagsProvider=nullptr)
int32_t GetBoxHeight() const
const std::shared_ptr< const CYITextLayout > & GetTextLayout(const CYITextEngine::RenderInfo &textRenderInfo)
size_t m_lastCodepointIndex
Definition: YiTextSceneNode.h:107
Definition: YiTextEngine.h:102
int32_t GetMaximumNumberOfLines() const
bool IsAllCaps(size_t codepointIndex=0) const
YI_RECT_REL m_MeasuredBoxRect
Definition: YiTextSceneNode.h:612
int32_t GetLeading(size_t codepointIndex=0) const
bool GetEllipses() const
size_t GetLength() const
float GetTextOffsetX() const
void SetFontSize(int32_t fontSize, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
bool m_adjustsFontSizeToFit
Definition: YiTextSceneNode.h:121
void SetTracking(int32_t baselineShift, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
void SetEllipsisStyle(const YI_TEXT_STYLE_DEF &style)
YI_RECT_REL m_LayoutRect
Definition: YiTextSceneNode.h:611
bool GetMultiline() const
void SetLeading(int32_t leading, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
int ssize_t
Definition: YiPredefWin32.h:131
bool operator==(const CYIVariant &rLHS, const CYIVariant &rRHS)
All types are supported. Two &#39;invalid&#39; variants are considered to be equal.
CYITextEngine::TrimmingMode GetTrimmingMode() const
bool SetFontFamily(const CYIString &fontFamilyName, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:257
Definition: YiPredef.h:530
void SetTextMaxWidth(float maxWidth)
ssize_t m_fontID
Definition: YiTextSceneNode.h:97
int32_t GetBaselineShift(size_t codepointIndex=0) const
void SetAllCaps(bool enable, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
int32_t m_kerning
Definition: YiTextSceneNode.h:105
const CYIColor & GetFontColor(size_t codepointIndex=0) const
A class used to represent a color value.
Definition: YiColor.h:31
float GetTextHeight()
void SetFontColor(const CYIColor &Color, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
int32_t GetKerning(size_t codepointIndex=0) const
const CYIString & GetMarkedUpText() const
TrimmingMode
Enumeration for behavior of trimming whitespace from lines of text.
Definition: YiTextEngine.h:165
YI_RECT_REL m_BoxRect
Definition: YiTextSceneNode.h:610
float GetTextWidth()
bool m_isBoxType
Definition: YiTextSceneNode.h:616
YI_FLOAT_RECT CalculateTightTextRect()
YI_TEXT_DEF m_TextDef
Definition: YiTextSceneNode.h:608
YI_RECT_REL m_PreferredBoxRect
Definition: YiTextSceneNode.h:613
bool m_textRectDirty
Definition: YiTextSceneNode.h:617
Justification m_XJustify
Definition: YiTextSceneNode.h:116
void SetTextStyle(const YI_TEXT_STYLE_DEF &style, size_t firstCodepointIndex)
bool m_textBufferDirty
Definition: YiTextSceneNode.h:615
Definition: YiTextSceneNode.h:90
ScriptMode
Definition: YiTextEngine.h:58
CYITextEngine::RenderInfo CreateTextRenderInfo()
const YI_TEXT_STYLE_DEF & GetTextStyle(size_t codepointIndex) const
Definition: YiCustomMarkupTagsProvider.h:15
int32_t GetTracking(size_t codepointIndex=0) const
int32_t GetBoxWidth() const