2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrpEnrichedText.h
20 * @brief This is the header file for the %EnrichedText class.
22 * This header file contains the definitions of the %EnrichedText class.
26 #ifndef _FGRP_ENRICHED_TEXT_H_
27 #define _FGRP_ENRICHED_TEXT_H_
30 #include <FBaseUtilLinkInfo.h>
31 #include <FGrpTextElement.h>
33 namespace Tizen { namespace Graphics
36 * @enum TextHorizontalAlignment
38 * Defines the horizontal alignment of the text.
42 enum TextHorizontalAlignment
44 TEXT_ALIGNMENT_LEFT = 1, /**< The position of the text is towards the left of the object */
45 TEXT_ALIGNMENT_CENTER, /**< The position of the text is towards the center of the object */
46 TEXT_ALIGNMENT_RIGHT, /**< The position of the text is towards the right of the object */
47 TEXT_ALIGNMENT_HORIZONTAL_MAX, // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
48 TEXT_ALIGNMENT_HORIZONTAL_MIN = 0 // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
52 * @enum TextVerticalAlignment
54 * Defines the vertical alignment of the text.
58 enum TextVerticalAlignment
60 TEXT_ALIGNMENT_TOP = 1, /**< The position of the text is towards the top of the object */
61 TEXT_ALIGNMENT_MIDDLE, /**< The position of the text is towards the middle of the object */
62 TEXT_ALIGNMENT_BOTTOM, /**< The position of the text is towards the bottom of the object */
63 TEXT_ALIGNMENT_BASELINE, /**< The position of the text is aligned along the baseline of the object */
64 TEXT_ALIGNMENT_VERTICAL_MAX, // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
65 TEXT_ALIGNMENT_VERTICAL_MIN = 0 // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
71 * Defines the style of wrapping of the text in %EnrichedText.
77 TEXT_WRAP_NONE = 1, /**< The wrapping of text is not applied */
78 TEXT_WRAP_CHARACTER_WRAP, /**< The wrapping of text is applied at the character unit */
79 TEXT_WRAP_WORD_WRAP, /**< The wrapping of text is applied at the word unit */
80 TEXT_WRAP_MAX, // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
81 TEXT_WRAP_MIN = 0 // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application.
86 * @brief This class provides enriched text content.
90 * @final This class is not intended for extension.
92 * The %EnrichedText class provides methods that enable your application to support texts with various styles, such
93 * as font, color, and layout. An %EnrichedText instance can be drawn to a Canvas.
95 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/graphics/enriched_text.htm">EnrichedText</a>.
97 * The following example demonstrates how to use the %EnrichedText class.
102 #include <FGraphics.h>
104 using namespace Tizen::App;
105 using namespace Tizen::Graphics;
108 MyClass::EnrichedTextSample(void)
110 result r = E_SUCCESS;
111 EnrichedText* pEnrichedText = null;
112 TextElement* pTextElement1 = null;
113 TextElement* pTextElement2 = null;
114 Bitmap* pBitmap = null;
116 // Creates an EnrichedText instance and sets the attributes
117 pEnrichedText = new EnrichedText();
118 r = pEnrichedText->Construct(Dimension(200, 200));
123 pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
124 pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM);
125 pEnrichedText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
126 pEnrichedText->SetTextAbbreviationEnabled(true);
128 // Creates a TextElement and sets attributes
129 pTextElement1 = new TextElement();
130 r = pTextElement1->Construct(L"0123456789");
135 pTextElement1->SetTextColor(Color::GetColor(COLOR_ID_BLUE));
138 font.Construct(FONT_STYLE_BOLD, 40);
139 pTextElement1->SetFont(font);
142 // Creates another TextElement and sets the attributes
143 pTextElement2 = new TextElement();
144 r = pTextElement2->Construct(L"abcdefghijklmn\nABCDEFGHIJKLMN");
149 pTextElement2->SetTextColor(Color::GetColor(COLOR_ID_VIOLET));
151 // Creates a bitmap and scales the size
152 pBitmap = App::GetInstance()->GetAppResource()->GetBitmapN(L"example.bmp");
153 pBitmap->Scale(Dimension(40, 40));
155 // Adds the TextElement and the bitmap to the EnrichedText
156 pEnrichedText->Add(*pTextElement1);
157 pEnrichedText->Add(*pTextElement2);
158 pEnrichedText->Add(*pBitmap);
163 r = canvas.Construct();
168 canvas.SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
170 canvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), Rectangle(50, 50, 380, 380));
172 // Draws the covered area of the EnrichedText in the Canvas coordinate
174 pEnrichedText->GetSize(width, height);
175 canvas.FillRectangle(Color::GetColor(COLOR_ID_GREY), Rectangle(60, 60, width, height));
177 // Draws the EnrichedText at the specified Point
178 canvas.DrawText(Point(60, 60), *pEnrichedText);
183 pEnrichedText->RemoveAll(true);
184 delete pEnrichedText;
191 pEnrichedText->RemoveAll(true);
192 delete pEnrichedText;
204 class _OSP_EXPORT_ EnrichedText
205 : public Tizen::Base::Object
209 * This is the default constructor for this class.
213 * @remarks After creating an instance of this class, one of the Construct() methods must be called explicitly
214 * to initialize this instance.
219 * This is the destructor for this class.
223 virtual ~EnrichedText(void);
226 * Initializes this instance of %EnrichedText with the specified parameter.
230 * @return An error code
231 * @param[in] dim The dimension to set for %EnrichedText @n
232 * The width and height must be greater than @c 0.
233 * @exception E_SUCCESS The method is successful.
234 * @exception E_OUT_OF_MEMORY The memory is insufficient.
235 * @exception E_INVALID_ARG The specified input parameter is invalid.
237 result Construct(const Tizen::Graphics::Dimension& dim);
240 * Inserts the TextElement instance in the %EnrichedText instance at the specified index.
244 * @return An error code
245 * @param[in] elementIndex The index at which the text element is to add
246 * @param[in] element The TextElement to add
247 * @exception E_SUCCESS The method is successful.
248 * @exception E_INVALID_ARG A specified input parameter is invalid.
250 result InsertAt(int elementIndex, TextElement& element);
253 * Removes the TextElement instance at the specified index of the %EnrichedText instance.
257 * @return An error code
258 * @param[in] elementIndex The index of TextElement
259 * @param[in] deallocate Set to @c true to deallocate the TextElement instance, @n
261 * @exception E_SUCCESS The method is successful.
262 * @exception E_INVALID_ARG A specified input parameter is invalid.
265 result RemoveAt(int elementIndex, bool deallocate);
268 * Removes the TextElement instance from the %EnrichedText instance.
272 * @return An error code
273 * @param[in] element The TextElement to remove
274 * @param[in] deallocate Set to @c true to deallocate the TextElement instance, @n
276 * @exception E_SUCCESS The method is successful.
279 result Remove(TextElement& element, bool deallocate);
282 * Adds the specified TextElement instance to the %EnrichedText instance.
286 * @return An error code
287 * @param[in] element The TextElement to append
288 * @exception E_SUCCESS The method is successful.
289 * @exception E_INVALID_ARG The specified input parameter is invalid.
292 result Add(TextElement& element);
296 * Removes all the %TextElement instances from the %EnrichedText instance.
298 * @brief <i> [Deprecated] </i>
299 * @deprecated This method is deprecated. Instead of this method, use the RemoveAll().
303 * @return An error code
304 * @param[in] deallocate Set to @c true to deallocate the %TextElement instance, @n
306 * @exception E_SUCCESS The method is successful.
310 result RemoveAllTextElements(bool deallocate);
313 * Removes all the text and image elements from the %EnrichedText instance.
317 * @return An error code
318 * @param[in] deallocate Set to @c true to deallocate the elements to be removed, @n
320 * @exception E_SUCCESS The method is successful.
321 * @exception E_SYSTEM An unknown operating system error has occurred.
324 result RemoveAll(bool deallocate);
327 * Gets the %TextElement instance at the specified index from the %EnrichedText instance.
331 * @return The %TextElement instance at the specified index, @n
332 * else @c null if the method fails
333 * @param[in] elementIndex The index of the %TextElement
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_INVALID_ARG The specified input parameter is invalid.
336 * @remarks The specific error code can be accessed using the GetLastResult() method.
338 TextElement* GetTextElementAt(int elementIndex) const;
341 * Gets the count of the %TextElement instances.
345 * @return The count of the %TextElement instances
347 int GetTextElementCount(void) const;
350 * Sets the text size.
354 * @return An error code
355 * @param[in] size The new size of the %EnrichedText @n
356 * The width and height must be greater than @c 0.
357 * @exception E_SUCCESS The method is successful.
358 * @exception E_OUT_OF_RANGE The value of the parameter is outside the valid range defined by the method.
360 result SetSize(const Tizen::Graphics::Dimension& size);
363 * Sets the text size.
367 * @return An error code
368 * @param[in] width The new width of %EnrichedText @n
369 * It must be greater than @c 0.
370 * @param[in] height The new height of %EnrichedText @n
371 * It must be greater than @c 0.
372 * @exception E_SUCCESS The method is successful.
373 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
375 result SetSize(int width, int height);
382 * @return An instance of %Dimension containing the width and the height of the %EnrichedText instance
385 Tizen::Graphics::Dimension GetSize(void) const;
388 * Gets the size of the %EnrichedText instance.
392 * @param[out] width The width of the control
393 * @param[out] height The height of the control
395 void GetSize(int& width, int& height) const;
398 * Gets the width of the %EnrichedText instance.
404 int GetWidth(void) const;
407 * Gets the height of the %EnrichedText instance.
413 int GetHeight(void) const;
417 * Sets the vertical alignment.
421 * @return An error code
422 * @param[in] alignment The vertical alignment of the text
423 * @exception E_SUCCESS The method is successful.
424 * @exception E_INVALID_ARG The specified input parameter is invalid.
426 result SetVerticalAlignment(TextVerticalAlignment alignment);
429 * Sets the horizontal alignment.
433 * @return An error code
434 * @param[in] alignment The horizontal alignment of the text
435 * @exception E_SUCCESS The method is successful.
436 * @exception E_INVALID_ARG The specified input parameter is invalid.
438 result SetHorizontalAlignment(TextHorizontalAlignment alignment);
441 * Gets the vertical alignment.
445 * @return alignment The vertical alignment of the text
447 TextVerticalAlignment GetVerticalAlignment(void) const;
450 * Gets the horizontal alignment.
454 * @return alignment The horizontal alignment of the text
456 TextHorizontalAlignment GetHorizontalAlignment(void) const;
459 * Sets the text wrap style.
463 * @return An error code
464 * @param[in] wrap The text wrapping style
465 * @exception E_SUCCESS The method is successful.
466 * @exception E_INVALID_ARG The specified input parameter is invalid.
468 result SetTextWrapStyle(TextWrap wrap);
471 * Gets the text wrap style.
475 * @return wrap The text wrapping style in the %EnrichedText bounds
477 TextWrap GetTextWrapStyle(void) const;
480 * Sets the text abbreviation status.
484 * @return An error code
485 * @param[in] enable Set to @c true to enable text abbreviation, @n
487 * @exception E_SUCCESS The method is successful.
489 result SetTextAbbreviationEnabled(bool enable);
492 * Checks whether the text abbreviation is enabled.
496 * @return @c true if the text abbreviation is enabled, @n
499 bool IsTextAbbreviationEnabled(void) const;
502 * Sets the line spacing.
506 * @return An error code
507 * @param[in] lineSpace The space between lines
508 * @exception E_SUCCESS The method is successful.
509 * @exception E_INVALID_ARG The specified input parameter is invalid.
512 result SetLineSpace(int lineSpace);
515 * Gets the line spacing.
519 * @return space The space between lines
521 int GetLineSpace(void) const;
524 * Refreshes the texts and bitmap according to the %EnrichedText instance's attributes. @n
525 * If some attributes are changed (such as changes using @ref SetSize), you can get the exact
526 * information of the text position or the number of lines after this method is called.
533 * Gets the total line count of the text in the %EnrichedText instance.
537 * @return The total line count
539 int GetTotalLineCount(void) const;
542 * Gets the height of the text in the %EnrichedText instance.
546 * @return The line height
548 int GetTotalLineHeight(void) const;
551 * Gets the displayed line count of the text in the %EnrichedText instance. @n
555 * @return The displayed line count
557 int GetDisplayLineCount(void) const;
560 * Gets the length of the specified line.
564 * @return The line length, @n
565 * else @c -1 if the method fails
566 * @param[in] lineIndex The index of the specified line
567 * @exception E_SUCCESS The method is successful.
568 * @exception E_INVALID_ARG The specified input parameter is invalid.
569 * @remarks The specific error code can be accessed using the GetLastResult() method.
571 int GetLineLength(int lineIndex) const;
574 * Gets the first character index of the specified line.
578 * @return The first text offset, @n
579 * else @c -1 if the method fails
580 * @param[in] lineIndex The line index of the %EnrichedText object
581 * @exception E_SUCCESS The method is successful.
582 * @exception E_INVALID_ARG The specified input parameter is invalid.
583 * @remarks The specific error code can be accessed using the GetLastResult() method.
585 int GetFirstTextIndex(int lineIndex) const;
588 * Gets the line index of the specified character.
592 * @return The line index, @n
593 * else @c -1 if the method fails
594 * @param[in] textIndex The text index
595 * @exception E_SUCCESS The method is successful.
596 * @exception E_INVALID_ARG The specified input parameter is invalid.
597 * @remarks The specific error code can be accessed using the GetLastResult() method.
599 int GetLineIndex(int textIndex) const;
602 * Gets the line height of the specified line.
606 * @return The line height, @n
607 * else @c -1 if the method fails
608 * @param[in] lineIndex The line index
609 * @exception E_SUCCESS The method is successful.
610 * @exception E_INVALID_ARG The specified input parameter is invalid.
611 * @remarks The specific error code can be accessed using the GetLastResult() method.
613 int GetLineHeight(int lineIndex) const;
616 * Gets the text length of the %EnrichedText object.
620 * @return The text length
622 int GetTextLength(void) const;
625 * Gets the extent of the %EnrichedText instance on the assumption that all TextElements are
626 * expanded to one line.
630 * @return An error code
631 * @param[in] startTextIndex The starting text index of the %EnrichedText
632 * @param[in] textLength The length of the specified text @n
633 * It must be greater than or equal to @c 0.
634 * @param[out] width The width of the specified text
635 * @param[out] height The height of the specified text
636 * @param[out] actualLength The actual text length measured
637 * @exception E_SUCCESS The method is successful.
638 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
639 * @exception E_INVALID_ARG A specified input parameter is invalid.
641 result GetTextExtent(int startTextIndex, int textLength, int& width, int& height, int& actualLength) const;
644 * Gets the extent of the %EnrichedText instance on the assumption that all %TextElements are
645 * expanded to one line.
648 * @return An error code
649 * @param[in] startTextIndex The starting text index of the EnrichedText
650 * @param[in] textLength The length of the specified text @n
651 * It must be greater than or equal to @c 0.
652 * @param[out] size The extent of the specified text
653 * @param[out] actualLength The actual text length measured
654 * @exception E_SUCCESS The method is successful.
655 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
656 * @exception E_INVALID_ARG A specified input parameter is invalid.
658 result GetTextExtent(int startTextIndex, int textLength, Tizen::Graphics::Dimension& size, int& actualLength) const;
661 * Gets the extent of the %EnrichedText instance on the assumption that all %TextElements are
662 * not expanded to one line. This function is useful for finding the extent of EnrichedText spanning multiple lines.
665 * @return An instance of %Dimension containing the extent of the %EnrichedText instance, @n
666 * else (-1, -1) if the method fails
668 Tizen::Graphics::Dimension GetTextExtent(void) const;
671 * Adds the specified bitmap image to the %EnrichedText instance.
675 * @return An error code
676 * @param[in] bitmap The bitmap to draw @n
677 * The bitmap must be constructed before being passed to this method.
678 * @exception E_SUCCESS The method is successful.
679 * @exception E_SYSTEM An unknown operating system error has occurred.
680 * @exception E_OUT_OF_MEMORY The memory is insufficient.
681 * @exception E_INVALID_ARG The specified input parameter is invalid.
683 result Add(const Tizen::Graphics::Bitmap& bitmap);
686 * Inserts the specified bitmap image to the %EnrichedText instance at the specified index.
690 * @return An error code
691 * @param[in] bitmap The @c bitmap to draw @n
692 * The bitmap must be constructed before being passed to this method.
693 * @param[in] elementIndex The index at which the @c bitmap image is to add
694 * @exception E_SUCCESS The method is successful.
695 * @exception E_SYSTEM An unknown operating system error has occurred.
696 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method.
697 * @exception E_OUT_OF_MEMORY The memory is insufficient.
698 * @exception E_INVALID_ARG A specified input parameter is invalid.
700 result InsertAt(int elementIndex, const Tizen::Graphics::Bitmap& bitmap);
703 * Gets the information about the link at the specified position.
707 * @return An error code
708 * @param[in] point A point that is within the %EnrichedText object
709 * @param[out] linkInfo The LinkInfo object that represents the link at the specified position
710 * @exception E_SUCCESS The method is successful.
711 * @exception E_INVALID_ARG A specified input parameter is invalid.
712 * @exception E_OBJ_NOT_FOUND The required instance is not found.
713 * @remarks The method throws @c E_OBJ_NOT_FOUND if there is no linked text at the specified position.
714 * @see Tizen::Base::Utility::LinkInfo
716 result GetLinkInfoFromPosition(const Point& point, Tizen::Base::Utility::LinkInfo& linkInfo) const;
720 * Gets the information about the link at the specified position.
724 * @return An error code
725 * @param[in] x The x-coordinate of a point that is within the %EnrichedText object
726 * @param[in] y The y-coordinate of a point that is within the %EnrichedText object
727 * @param[out] linkInfo The LinkInfo object that represents the link at the specified position
728 * @exception E_SUCCESS The method is successful.
729 * @exception E_INVALID_ARG A specified input parameter is invalid.
730 * @exception E_OBJ_NOT_FOUND The required instance is not found.
731 * @remarks The method throws @c E_OBJ_NOT_FOUND if there is no linked text at the specified position.
732 * @see Tizen::Base::Utility::LinkInfo
734 result GetLinkInfoFromPosition(int x, int y, Tizen::Base::Utility::LinkInfo& linkInfo) const;
737 * Gets the vertical alignment among text and bitmap element.
741 * @return The vertical alignment among the text and the bitmap element
743 TextVerticalAlignment GetElementVerticalAlignment(void) const;
746 * Sets the vertical alignment among text and bitmap element.
750 * @return An error code
751 * @param[in] alignment The vertical alignment among the text and the bitmap element
752 * @exception E_SUCCESS The method is successful.
753 * @exception E_INVALID_ARG The specified input parameter is invalid.
754 * @remarks This method sets how one element is positioned relative to the other elements. @n
755 * The vertical alignment of text and bitmap elements are decided based on the maximum height among elements.
756 * @remarks The default alignment TEXT_ALIGNMENT_BOTTOM.
758 result SetElementVerticalAlignment(TextVerticalAlignment alignment);
761 friend class _EnrichedTextImpl;
764 // This value is for internal use only. Using this value can cause behavioral, security-related,
765 // and consistency-related issues in the application.
767 class _EnrichedTextImpl * __pImpl;
770 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
772 EnrichedText(const EnrichedText& font);
775 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
777 EnrichedText& operator =(const EnrichedText& rhs);
780 }} // Tizen::Graphics
782 #endif // _FGRP_ENRICHED_TEXT_H_