You.i Engine
YiTextSceneNode.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_TEXT_SCENE_NODE_H_
3 #define _YI_TEXT_SCENE_NODE_H_
4 
8 #include "utility/YiColor.h"
9 
12 class CYITextSceneNodePriv;
13 
80 {
81 public:
82  enum class Justification : uint8_t
83  {
84  Left = 0,
85  Right,
86  Center
87  };
88 
90  {
92 
93  bool operator==(const YI_TEXT_STYLE_DEF &other) const;
94  bool operator!=(const YI_TEXT_STYLE_DEF &other) const;
95 
97  int32_t m_fontSize;
98  int32_t m_leading;
99  bool m_isAllCaps;
102  int32_t m_baselineShift;
103  int32_t m_tracking;
104  int32_t m_kerning;
107  };
108 
109  struct YI_TEXT_DEF
110  {
111  YI_TEXT_DEF();
112 
114  size_t m_length;
117  bool m_multiline;
118  bool m_ellipses;
123  std::vector<YI_TEXT_STYLE_DEF> m_styles;
124  };
125 
127  virtual ~CYITextSceneNode();
128 
136  float GetTextWidth();
137 
145  float GetTextHeight();
146 
153 
160 
167  void SetTextOffsetX(float textOffsetX);
168 
175  void SetTextMaxWidth(float maxWidth);
176 
186  bool SetFont(const CYIString &fontFamilyName, const CYIString &fontStyle, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
187 
195  void SetFontID(ssize_t fontID, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
196 
208  bool SetFontFamily(const CYIString &fontFamilyName, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
209 
221  bool SetFontStyle(const CYIString &fontStyleName, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
222 
228  void SetFontSize(int32_t fontSize, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
229 
235  void SetFontColor(const CYIColor &Color, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
236 
242  void SetAllCaps(bool enable, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
243 
249  void SetScriptMode(CYITextEngine::ScriptMode scriptMode, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
250 
256  void SetBaselineShift(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
257 
263  void SetTracking(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
264 
270  void SetKerning(int32_t baselineShift, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
271 
277  void SetLeading(int32_t leading, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
278 
284  void SetEllipses(bool enable);
285 
290  void SetMaximumNumberOfLines(int32_t numberOfLines);
291 
300  void SetAdjustsFontSizeToFit(bool adjustsFontSizeToFit);
301 
307  void SetMinimumFontScale(float minimumFontScale);
308 
312  void SetMultiline(bool enable);
313 
314  virtual void SetSize(const glm::vec3 &size, bool dirtyLayout = true) override;
315 
326  void SetText(const CYIString &rText);
327 
341  void SetMarkedUpText(const CYIString &rMarkedUpText, CYITextMarkupParser *pMarkupParser = nullptr, const CYICustomMarkupTagsProvider *pExternalTagsProvider = nullptr);
342 
346  void SetXJustify(Justification xJustify);
347 
355  void SetTrimmingMode(CYITextEngine::TrimmingMode trimmingMode);
356 
363 
375  void SetPointTypeOn(int32_t width = 0);
376 
386  void SetBoxTypeOn(int32_t boxWidth, int32_t boxHeight);
387 
393  void SetLineStyle(CYITextEngine::LineStyle textLineStyle, size_t firstCodepointIndex = 0, size_t length = std::numeric_limits<size_t>::max());
394 
395  float GetTextOffsetX() const;
396  const CYIString &GetText() const;
397  const CYIString &GetMarkedUpText() const;
398  size_t GetLength() const;
399  Justification GetXJustify() const;
400  bool GetMultiline() const;
401  bool GetEllipses() const;
402  int32_t GetMaximumNumberOfLines() const;
403  bool GetAdjustsFontSizeToFit() const;
404  float GetMinimumFontScale() const;
405 
406  ssize_t GetFontID(size_t codepointIndex = 0) const;
407  const CYIString &GetFontFamily(size_t codepointIndex = 0) const;
408  const CYIString &GetFontStyle(size_t codepointIndex = 0) const;
409  size_t GetFontSize(size_t codepointIndex = 0) const;
410  const CYIColor &GetFontColor(size_t codepointIndex = 0) const;
411  bool IsAllCaps(size_t codepointIndex = 0) const;
412  CYITextEngine::LineStyle GetLineStyle(size_t codepointIndex = 0) const;
413  int32_t GetLeading(size_t codepointIndex = 0) const;
414  CYITextEngine::ScriptMode GetScriptMode(size_t codepointIndex = 0) const;
415  int32_t GetBaselineShift(size_t codepointIndex = 0) const;
416  int32_t GetTracking(size_t codepointIndex = 0) const;
417  int32_t GetKerning(size_t codepointIndex = 0) const;
418 
422  const std::vector<YI_TEXT_STYLE_DEF> &GetTextStyles() const;
423 
427  const YI_TEXT_STYLE_DEF &GetTextStyle(size_t codepointIndex) const;
428 
434  void SetTextStyle(const YI_TEXT_STYLE_DEF &style, size_t firstCodepointIndex);
435 
444  void SetTextStyles(const std::vector<YI_TEXT_STYLE_DEF> &styles);
445 
451  void SetEllipsisStyle(const YI_TEXT_STYLE_DEF &style);
452 
457 
466  int32_t GetBoxWidth() const;
475  int32_t GetBoxHeight() const;
476 
483  void SetUseFontTables(bool useFontTables);
484 
488  bool IsUsingFontTables() const;
489 
495  bool IsBoxType() const;
496 
502  bool IsPointType() const;
503 
509  bool IsTruncated() const;
510 
514  virtual YI_FLOAT_RECT GetRectForTextRange(size_t startIndex, size_t endIndex, float horizontalPixelRatio, float verticalPixelRatio);
515 
520 
524  CYITextLayout::TextDirection GetCharacterTextDirection(size_t characterIndex) const;
525 
530  bool IsCharacterRightToLeft(size_t characterIndex) const;
531 
536  bool IsBaseRightToLeft() const;
537 
541  CYITextEngine::PositionInString GetIndexOfPosition(float x, float y, float horizontalPixelRatio, float verticalPixelRatio);
542 
547 
551  void SetTextLayoutFactory(std::function<std::unique_ptr<CYITextLayout>()> textLayoutFactory);
552 
553  virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override;
554  virtual void ApplyMeasurements() override;
555 
561  float GetAdjustedFontSizeScale();
562 
563 protected:
568  const std::shared_ptr<const CYITextLayout> &GetTextLayout(const CYITextEngine::RenderInfo &textRenderInfo);
569 
574 
579 
584 
588  virtual YI_FLOAT_RECT_REL CalculateGlyphBox(const YI_RECT_REL &boxRect);
589 
595  YI_FLOAT_RECT_REL CalculateGlyphBox(const CYITextLayout *pLayout, const YI_FLOAT_RECT_REL &layoutRect) const;
596 
600  virtual void PrepareToDraw() = 0;
601 
602  virtual void WorldBoundingBoxUpdated() override;
603  virtual void UpdateEnd() override;
604  virtual void WorldSurfaceScaleUpdated() override;
605  virtual CYIString GetDumpTreeString() const override;
606 
610  void SetTextDirty();
611 
615  static bool HasAllCaps(const YI_TEXT_DEF &rTextDef);
616 
620  static void UpdateTextForAllCaps(const YI_TEXT_DEF &rTextDef, CYIString &rText);
621 
625  virtual void UpdateTextRect();
626 
635  bool m_isBoxType;
638  std::function<std::unique_ptr<CYITextLayout>()> m_textLayoutFactory;
639 
640 private:
641  friend class CYITextSceneNodePriv;
642 
643  void CreateTextMesh();
644  void UpdateCachedTextLayout() const;
645 
646  float m_textOffsetX;
647  std::shared_ptr<const CYITextLayout> m_pCachedTextLayout;
648  CYITextEngine::RenderInfo m_cachedTextRenderInfo;
649  uint32_t m_meshGlyphsCount;
650 
652 };
653 
658 template<>
660 {
661  return pObject ? (pObject->CanCastTo<CYITextSceneNode>() ? static_cast<const CYITextSceneNode *>(pObject) : nullptr) : nullptr;
662 }
663 
664 #endif // _YI_TEXT_SCENE_NODE_H_
bool m_ellipses
Definition: YiTextSceneNode.h:118
CYIString m_text
Definition: YiTextSceneNode.h:113
static void UpdateTextForAllCaps(const YI_TEXT_DEF &rTextDef, CYIString &rText)
Justification
Definition: YiTextSceneNode.h:82
void SetTextOffsetX(float textOffsetX)
bool m_userSpecifiedWidth
Definition: YiTextSceneNode.h:122
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:97
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:101
CYITextEngine::TrimmingMode m_trimmingMode
Definition: YiTextSceneNode.h:116
Struct used to pass information when rendering text.
Definition: YiTextEngine.h:210
virtual YI_FLOAT_RECT GetRectForTextRange(size_t startIndex, size_t endIndex, float horizontalPixelRatio, float verticalPixelRatio)
int32_t m_tracking
Definition: YiTextSceneNode.h:103
void ResetPerCharacterStyles()
Definition: YiRectangle.h:38
void SetTextStyles(const std::vector< YI_TEXT_STYLE_DEF > &styles)
int32_t m_baselineShift
Definition: YiTextSceneNode.h:102
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:32
std::function< std::unique_ptr< CYITextLayout >)> m_textLayoutFactory
Definition: YiTextSceneNode.h:638
const CYIString & GetText() const
void SetMaximumNumberOfLines(int32_t numberOfLines)
float m_minimumFontScale
Definition: YiTextSceneNode.h:121
void SetXJustify(Justification xJustify)
LineStyle
Definition: YiTextEngine.h:88
virtual void WorldSurfaceScaleUpdated() override
bool IsUsingFontTables() const
int32_t m_leading
Definition: YiTextSceneNode.h:98
void SetMinimumFontScale(float minimumFontScale)
virtual void UpdateEnd() override
virtual ~CYITextSceneNode()
long long ssize_t
Definition: YiPredefWindows.h:21
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 CYIHTTPHeader &lhs, const CYIHTTPHeader &rhs)
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:100
size_t m_length
Definition: YiTextSceneNode.h:114
TextDirection
Enumeration for direction types used in text layout.
Definition: YiTextLayout.h:28
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:637
bool m_isAllCaps
Definition: YiTextSceneNode.h:99
virtual YI_FLOAT_RECT_REL CalculateGlyphBox()
virtual void WorldBoundingBoxUpdated() override
void SetAdjustsFontSizeToFit(bool adjustsFontSizeToFit)
float m_textMaxWidth
Definition: YiTextSceneNode.h:633
virtual void ApplyMeasurements() override
Definition: YiTextMarkupParser.h:15
CYIColor m_Color
Definition: YiTextSceneNode.h:105
Definition: YiTextSceneNode.h:109
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:641
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:123
void SetLineStyle(CYITextEngine::LineStyle textLineStyle, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
const CYITextSceneNode * YiDynamicCast< CYITextSceneNode >(const CYISceneNode *pObject)
Definition: YiTextSceneNode.h:659
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:105
int32_t m_numberOfLines
Definition: YiTextSceneNode.h:119
Definition: YiSceneNode.h:374
Definition: YiRectangle.h:61
A scene node type that renders text.
Definition: YiTextSceneNode.h:79
CYITextLayout::TextDirection GetCharacterTextDirection(size_t characterIndex) const
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:628
Base class for abstracting the layout for text.
Definition: YiTextLayout.h:22
void SetTrimmingMode(CYITextEngine::TrimmingMode trimmingMode)
bool m_multiline
Definition: YiTextSceneNode.h:117
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:106
Definition: YiTextEngine.h:117
int32_t GetMaximumNumberOfLines() const
bool IsAllCaps(size_t codepointIndex=0) const
YI_RECT_REL m_MeasuredBoxRect
Definition: YiTextSceneNode.h:631
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:120
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:630
bool GetMultiline() const
void SetLeading(int32_t leading, size_t firstCodepointIndex=0, size_t length=std::numeric_limits< size_t >::max())
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:259
Definition: YiRectangle.h:86
void SetTextMaxWidth(float maxWidth)
ssize_t m_fontID
Definition: YiTextSceneNode.h:96
bool operator!=(const CYIHTTPHeader &lhs, const CYIHTTPHeader &rhs)
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:104
const CYIColor & GetFontColor(size_t codepointIndex=0) const
A class used to represent a color value.
Definition: YiColor.h:35
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:180
YI_RECT_REL m_BoxRect
Definition: YiTextSceneNode.h:629
float GetTextWidth()
bool m_isBoxType
Definition: YiTextSceneNode.h:635
YI_FLOAT_RECT CalculateTightTextRect()
YI_TEXT_DEF m_TextDef
Definition: YiTextSceneNode.h:627
YI_RECT_REL m_PreferredBoxRect
Definition: YiTextSceneNode.h:632
bool m_textRectDirty
Definition: YiTextSceneNode.h:636
Justification m_XJustify
Definition: YiTextSceneNode.h:115
void SetTextStyle(const YI_TEXT_STYLE_DEF &style, size_t firstCodepointIndex)
bool m_textBufferDirty
Definition: YiTextSceneNode.h:634
Definition: YiTextSceneNode.h:89
ScriptMode
Definition: YiTextEngine.h:73
CYITextEngine::RenderInfo CreateTextRenderInfo()
const YI_TEXT_STYLE_DEF & GetTextStyle(size_t codepointIndex) const
Definition: YiCustomMarkupTagsProvider.h:15
bool IsTruncated() const
CYITextLayout::TextDirection GetBaseTextDirection() const
int32_t GetTracking(size_t codepointIndex=0) const
int32_t GetBoxWidth() const
bool IsCharacterRightToLeft(size_t characterIndex) const