Mobile API Reference  MicroStrategy 2019
TextObject.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : TextObject.h
3 // AUTHOR : Fangyao Ma
4 // CREATION : 2008-06-06
5 // Copyright (C) MicroStrategy Incorporated 2008
6 // All Rights Reserved
7 //==============================================================================================
8 
9 #ifndef MsiChart_TextObject_h
10 #define MsiChart_TextObject_h 1
11 
12 #include "RectangleObject.h"
13 #include "FormatFont.h"
14 
15 namespace MsiChart
16 {
17  const Int32 XOffset = 2;
18  const Int32 YOffset = 2;
19 
22  {
27  };
28 
31  {
41  };
42 
43  typedef enum EnumTextBorderStyle
44  {
45  TBS_NONE = 0,
51 
52  struct TextExtent
53  {
54  /*TextExtent(const cairo_text_extents_t& iCairoTextExtent)
55  : width(iCairoTextExtent.width)
56  , x_bearing(iCairoTextExtent.x_bearing)
57  , x_advance(iCairoTextExtent.x_advance)
58  {}*/
59  TextExtent(float iWidth)
60  : width(iWidth)
61  , x_bearing(0)
62  , x_advance(iWidth)
63  {}
65  : width(0.0)
66  , x_bearing(0.0)
67  , x_advance(0.0)
68  {}
69 
70  double width;
71  double x_bearing;
72  double x_advance;
73  };
74 
80  {
81  public:
82  friend class TextObject;
86  void Clear();
87 
97  void ParseText(const MBase::String& irText, const wchar_t iSeparator, Int32 iWordLengthLimit = -1);
98 
104  void UpdateText(ChartContext::Ptr iChartContextPtr,FormatFont* ipDeviceFont);
105 
111  void PartitionBy(Int32 iDestWidth, bool iIsStrigent = true);
112 
117  void GetPartitionRange(std::vector<Int32>& orVecIndex) const;
118 
122  Int32 GetMaxWidth() const;
123 
128  Int32 GetLineCount() const;
129 
134  void SetLineCount(Int32 iLineCount);
140  double GetOneLineWidth(Int32 iLineIndex) const;
141 
147  double GetOneLineXBearing(Int32 iLineIndex) const;
148 
154  MBase::ReturnWString GetOneLineString(Int32 iLineIndex) const;
155 
162  MBase::ReturnWString TruncateWord(const MBase::String& irString, Int32 iWordLengthLimit) const;
163 
167  Int32 GetSpaceWidth() const;
168  private:
169  std::vector<MBase::String> mVecStr;
170  std::vector<Int32> mInitVecPartition;
171  std::vector<Int32> mVecPartition;
172  std::vector<TextExtent> mVecSize;
173  double mSpaceWidth;
174  MBase::String mText;
175  double mMaxWordWidth;
176  };
177 
181  class TextObject: public ShapeObject
182  {
183  public:
185 
189  TextObject(const TripleId& irTripleId,
190  GraphObjectManager* ipManager,
191  Rect2D iRect,
192  GraphCollectionObject* ipParentObject = NULL,
193  bool iClientDrag = false);
194 
198  TextObject(const TripleId& irTripleId,
199  GraphObjectManager* ipManager,
200  GraphCollectionObject* ipParentObject = NULL);
201 
202  virtual ~TextObject();
203 
204  // virtual functions from GraphObject
205  virtual void DrawOutLine();
206  virtual bool PointInObject(const Point2D& irPoint);
207  virtual bool ObjectInRectangle(const Rect2D& irRect);
208  virtual void Draw() const;
209  virtual void GetOptions(Int32 iPropertyId, CComVariant* opValue) const;
210  virtual void GenerateImageMap(ImageMap& iorImageMap);
211 
212  // pure virtual function from ShapeObject
213  virtual void GetBoundingRect(Rect2D& orBoundingRect) const;
214 
215  // Public method
220  void GetBoundingRectNoRotation(Rect2D& orBoundingRect) const;
221 
226  void SetText(const MBase::String& irText, Int32 iWordLengthLimit = -1);
227 
233  void GetText(MBase::String& orText, bool iIsOriginalText = false);
234 
240  void SetRect(const Rect2D& irRect);
241 
242  void GetRect(Rect2D& orRect) const;
243 
248  // void GetRect(Rect2D& orRect);
249 
255 
262  void MoveTo(Int32 iDestX, Int32 iDestY, Int32 iAnchor = TOP_LEFT);
263 
269  void MoveToCenter(float iDestX, float iDestY);
270 
276  void SetTextWidthLimit(Int32 iWidthLimit, bool iIsStringent = true);
277 
281  void SetIsShown(bool iIsShown);
282 
286  bool GetIsShown();
287 
291  void CalculateDeviceRect() const;
292 
293  TextObject::Ptr Clone() const;
294 
300  void GetTransformedRect(Rect2D& orRect) const;
308  bool HasOverlapForSameRotation(TextObject* ipTextObject, Int32 iLabelSpan = 0, REC_EXP_DIRECTION iSpanDirection = REC_EXP_INVALID) const;
309 
313  Int32 GetLineCount() const;
314 
318  Int32 GetOneLineHeight() const;
319 
323  void RestoreWidthAndHeight();
324 
328  void SetLineCount(Int32 iLineCount);
329 
333  Int32 GetStringLength() const;
334 
335  void SetBorderStyleAndColor(EnumTextBorderStyle iStyle, Int32 iColor, Int32 iDirection);
336 
340  void EnableLargerTruncationLimit(bool iUseLargerTruncationLimit);
341 
342  bool IsTruncated() const;
343 
344  bool MaybeTruncated() const;
345 
346  bool IsTooCloseTo(TextObject* ipTextObject, double iDistance, Int32 iAnchorStyle);
347  void SetLineCountEnforced(bool iIsEnforeced = false);
348 
349  Int32 GetWidthHeightMargin(bool iIsWidth);
350 
351 
352  protected:
353  virtual void GetClockwisePolygon(std::vector<Point2D>& orPolygon) const;
354 
359 
363  void hFillTextFrame(const Rect2D& irTextFrameRect) const;
364 
371  void hFormatSingleLineText(Point2D& irStartPoint, Int32 iLineIndex) const;
372 
377  void hGetDevicePolygon(std::vector<Point2D>& orDevicePolygon) const;
378 
379  void hGetDevicePolygon(const Rect2D irRect, std::vector<Point2D>& orDevicePolygon) const;
380 
385  double hGetRadian() const;
386 
394  void hTruncate(Int32 iLineIndex, MBase::String& orStr, double& orTextWidth, double& orTextXBearing) const;
395 
399  void hCalculateParas();
400 
404 
405  mutable Rect2D mRect;
408  bool mIsShown;
409 
415  mutable bool mIsRectCalculated;
421  mutable bool mIsTruncated;
422  EnumTextBorderStyle mBorderStyle[4];//left right top bottom
423  int mBorderColor[4];//left right top bottom
424 
425 
426 
427  // EnumVerticalAlign mVerticalAlign; ///< Vertical Alignment
428 
429  private:
430  virtual void hGetFormatFromParent();
431 
432  void hAdjustRect() const;
433 
437  void hInitFormat();
438 
439  };
440 
441 
442  inline void TextObject::SetIsShown(bool iIsShown)
443  {
444  mIsShown = iIsShown;
445  }
446 
448  {
449  return mIsShown;
450  }
451 
452  inline void TextObject::MoveToCenter(float iDestX, float iDestY)
453  {
454  mRect.x = static_cast<Int32>(iDestX - mRect.width / 2.0f + 0.5f);
455  mRect.y = static_cast<Int32>(iDestY - mRect.height / 2.0f + 0.5f);
456  }
457 
459  {
460  return (Int32)mText.length();
461  }
462 
463  inline void TextObject::GetRect(Rect2D& orRect) const
464  {
465  orRect = mRect;
466  }
467 
468  inline void TextObject::SetBorderStyleAndColor(EnumTextBorderStyle iStyle, Int32 iColor, Int32 iDirection)
469  {
470  _ASSERT(iDirection < 4);
471  mBorderStyle[iDirection] = iStyle;
472  mBorderColor[iDirection] = iColor;
473  }
474 
475  inline void TextObject::EnableLargerTruncationLimit(bool iUseLargerTruncationLimit)
476  {
477  mUseLargerTruncationLimit = iUseLargerTruncationLimit;
478  }
479 
480  inline bool TextObject::IsTruncated() const
481  {
482  return mIsTruncated;
483  }
484 
486  {
487  return iIsWidth ? mWidthEdgeMargin : mHeightEdgeMargin;
488  }
489 
490 }
491 
492 #endif
double width
Definition: TextObject.h:70
Definition: TextObject.h:39
Int32 mTextWidthLimit
Definition: TextObject.h:416
Int32 mWidthEdgeMargin
Definition: TextObject.h:410
Int32 GetMaxWidth() const
void SetTextWidthLimit(Int32 iWidthLimit, bool iIsStringent=true)
Int32 GetLineCount() const
#define _ASSERT(x)
Definition: Asserte.h:34
bool mIsTruncated
If it is truncated.
Definition: TextObject.h:421
double x_advance
Definition: TextObject.h:72
Int32 GetStringLength() const
Definition: TextObject.h:458
double GetOneLineWidth(Int32 iLineIndex) const
void SetBorderStyleAndColor(EnumTextBorderStyle iStyle, Int32 iColor, Int32 iDirection)
Definition: TextObject.h:468
void EnableLargerTruncationLimit(bool iUseLargerTruncationLimit)
Definition: TextObject.h:475
bool mIsLineCountEnforced
Line count is set and should not be changed.
Definition: TextObject.h:420
Int32 mDoubleLineMargin
Definition: TextObject.h:413
TextObject(const TripleId &irTripleId, GraphObjectManager *ipManager, Rect2D iRect, GraphCollectionObject *ipParentObject=NULL, bool iClientDrag=false)
void GetBoundingRectNoRotation(Rect2D &orBoundingRect) const
bool mIsRectCalculated
Definition: TextObject.h:415
void SetLineCount(Int32 iLineCount)
Definition: TextObject.h:32
Int32 mTextLineSpace
Definition: TextObject.h:412
MBase::String mFullText
The untouched content.
Definition: TextObject.h:403
void ParseText(const MBase::String &irText, const wchar_t iSeparator, Int32 iWordLengthLimit=-1)
void SetLineCountEnforced(bool iIsEnforeced=false)
Definition: TextObject.h:38
const Int32 XOffset
Offset used for explode the rectangle area.
Definition: TextObject.h:17
Definition: GraphCollectionObject.h:19
Int32 mFontHeight
Definition: TextObject.h:414
const Int32 YOffset
Offset used for explode the rectangle area.
Definition: TextObject.h:18
void SetRect(const Rect2D &irRect)
bool mUseLargerTruncationLimit
Default is true.
Definition: TextObject.h:418
Definition: TextObject.h:36
bool mClientDrag
Definition: TextObject.h:407
int mBorderColor[4]
Definition: TextObject.h:423
double hGetRadian() const
double x_bearing
Definition: TextObject.h:71
Definition: TextObject.h:52
Definition: ReturnString.h:85
Int32 mHeightEdgeMargin
Definition: TextObject.h:411
bool IsTooCloseTo(TextObject *ipTextObject, double iDistance, Int32 iAnchorStyle)
virtual void DrawOutLine()
virtual void GetClockwisePolygon(std::vector< Point2D > &orPolygon) const
bool HasOverlapForSameRotation(TextObject *ipTextObject, Int32 iLabelSpan=0, REC_EXP_DIRECTION iSpanDirection=REC_EXP_INVALID) const
Definition: ShapeObject.h:20
Int32 GetOneLineHeight() const
void hFormatSingleLineText(Point2D &irStartPoint, Int32 iLineIndex) const
FormatFont::Ptr GetFormatFont()
void hFillTextFrame(const Rect2D &irTextFrameRect) const
Definition: TextObject.h:49
void hGetDevicePolygon(std::vector< Point2D > &orDevicePolygon) const
Definition: TextObject.h:25
Definition: TextObject.h:24
void SetIsShown(bool iIsShown)
Definition: TextObject.h:442
MBase::ReturnWString GetOneLineString(Int32 iLineIndex) const
void MoveTo(Int32 iDestX, Int32 iDestY, Int32 iAnchor=TOP_LEFT)
Int32 width
Width of current rectangle.
Definition: Rect2D.h:124
Int32 GetLineCount() const
#define Int32
Definition: BasicTypes.h:20
bool GetIsShown()
Definition: TextObject.h:447
Int32 GetSpaceWidth() const
bool MaybeTruncated() const
Definition: TextObject.h:34
Definition: TextObject.h:181
virtual void GenerateImageMap(ImageMap &iorImageMap)
Definition: TextObject.h:35
FormatFont::Ptr mFormatFontPtr
Stores the font info of the text object.
Definition: TextObject.h:401
Definition: Rect2D.h:18
double GetOneLineXBearing(Int32 iLineIndex) const
Definition: TextObject.h:37
bool IsTruncated() const
Definition: TextObject.h:480
void SetLineCount(Int32 iLineCount)
Definition: TextObject.h:23
EnumTextBorderStyle mBorderStyle[4]
Definition: TextObject.h:422
int x
X-coordinate of left edge.
Definition: Rect2D.h:122
MSynch::SmartPtr< TextObject > Ptr
Definition: TextObject.h:184
Definition: TextObject.h:48
TextExtent()
Definition: TextObject.h:64
REC_EXP_DIRECTION
Definition: Rect2D.h:16
Definition: TextObject.h:40
virtual void GetBoundingRect(Rect2D &orBoundingRect) const
void SetText(const MBase::String &irText, Int32 iWordLengthLimit=-1)
void GetText(MBase::String &orText, bool iIsOriginalText=false)
bool mIsShown
Definition: TextObject.h:408
Definition: ChartContext.h:542
void ApplyUnderlineorStrikeThroughFormat() const
SubTextHolder mSubTextHolder
To handle word wrapping.
Definition: TextObject.h:406
virtual void GetOptions(Int32 iPropertyId, CComVariant *opValue) const
std::basic_string< WCHAR, std::char_traits< WCHAR >, Allocator< WCHAR > > String
Definition: BaseString.h:26
TextObject::Ptr Clone() const
virtual void Draw() const
MBase::ReturnWString TruncateWord(const MBase::String &irString, Int32 iWordLengthLimit) const
EnumVerticalAlign
Vertical Alignment.
Definition: TextObject.h:21
Definition: ABLPlot.h:21
Int32 height
Height of current rectangle.
Definition: Rect2D.h:125
std::vector< AreaRec * > ImageMap
Definition: ImageMap.h:99
void GetTransformedRect(Rect2D &orRect) const
Definition: TextObject.h:47
Definition: TextObject.h:46
void MoveToCenter(float iDestX, float iDestY)
Definition: TextObject.h:452
void PartitionBy(Int32 iDestWidth, bool iIsStrigent=true)
virtual bool PointInObject(const Point2D &irPoint)
void GetPartitionRange(std::vector< Int32 > &orVecIndex) const
Int32 mLineCount
Definition: TextObject.h:419
Definition: Msi_ccomvariant.h:24
Int32 GetWidthHeightMargin(bool iIsWidth)
Definition: TextObject.h:485
virtual bool ObjectInRectangle(const Rect2D &irRect)
Definition: TextObject.h:33
Rect2D mRect
The rectangle area enclosing the text.
Definition: TextObject.h:405
EnumTextBorderStyle
Definition: TextObject.h:43
void GetRect(Rect2D &orRect) const
Definition: TextObject.h:463
MBase::String mText
The text content.
Definition: TextObject.h:402
int y
Y-coordinate of left edge.
Definition: Rect2D.h:123
Definition: TextObject.h:45
#define NULL
Definition: Null.h:10
Definition: GraphObjectManager.h:37
void UpdateText(ChartContext::Ptr iChartContextPtr, FormatFont *ipDeviceFont)
void CalculateDeviceRect() const
TextExtent(float iWidth)
Definition: TextObject.h:59
bool mIsStringent
Definition: TextObject.h:417
Use four Int32 values to represent a 2D rectangle.
Definition: Rect2D.h:25
Definition: TextObject.h:79
EnumAnchorPoint
Anchor point of 8 angle points and 1 center point of one rectangle area.
Definition: TextObject.h:30
void hTruncate(Int32 iLineIndex, MBase::String &orStr, double &orTextWidth, double &orTextXBearing) const
Definition: TextObject.h:26
Definition: Common.h:397
Definition: FormatFont.h:86