// FIXME: leaks
result RichTextPanel::Construct(const Dimension& dim, const String & text) {
	result r = E_SUCCESS;
	TextElement* textElement;
	int width, height;
	Color color = Color::GetColor(COLOR_ID_WHITE);
	Font font;

	Dimension textDim;
	int textActualLen;

	enrichedText = new EnrichedText();
	r = enrichedText->Construct(dim);
	TryCatch(r == E_SUCCESS, , "Failed Construct EnrichedText");

	r = font.Construct(FONT_STYLE_PLAIN, TEXT_FONT_SIZE);
	TryCatch(r == E_SUCCESS, , "Failed Construct Font");

	textElement = new TextElement();
	r = textElement->Construct(text);
	TryCatch(r == E_SUCCESS, , "Failed TextElement");
	r = textElement->SetTextColor(color);
	TryCatch(r == E_SUCCESS, , "Failed SetTextColor");
	r = textElement->SetFont(font);
	TryCatch(r == E_SUCCESS, , "Failed SetFont");

	r = enrichedText->Add(*textElement);
	TryCatch(r == E_SUCCESS, , "Failed Add textElement");


	height = enrichedText->GetTotalLineHeight();

	r = enrichedText->GetTextExtent(0, text.GetLength(), textDim, textActualLen);
	TryCatch(r == E_SUCCESS, , "Failed GetTextExtent");
	width = dim.width < textDim.width ? dim.width : textDim.width;

	r = Panel::Construct(Rectangle(0, 0, width, height));
	TryCatch(r == E_SUCCESS, , "Failed Construct RichTextPanel parent");

	TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult(), "Failed GetSize");
	AppLog("Size received: %d x %d", width, height);

	r = SetSize(width, height);
	TryCatch(r == E_SUCCESS, , "Failed SetSize");

//	SetBackgroundColor(color);
	TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult(), "Failed SetBackgroundColor");

	return r;

	CATCH:
	    AppLogException("$${Function:Construct} is failed.", GetErrorMessage(r));

	    if (textElement)
	    	delete textElement;

	    return r;
}
void DrawingClass::FDrawTextToCanvas(Osp::Graphics::Canvas * oncanvas, Osp::Graphics::Rectangle destdim, String text, int fontsize, int fontstyle, bool wordwrap, Osp::Graphics::Color fontcolor, Osp::Graphics::TextHorizontalAlignment halign, Osp::Graphics::TextVerticalAlignment valign) {
	Font font_;
	font_.Construct(fontstyle, fontsize);
	EnrichedText texteel;
	texteel.Construct(Dimension(destdim.width, destdim.height));
	texteel.SetHorizontalAlignment(halign);
	texteel.SetVerticalAlignment(valign);
	if (wordwrap) {
		texteel.SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
	}
	TextElement textel;
	textel.Construct(text);
	textel.SetTextColor(fontcolor);
	textel.SetFont(font_);
	texteel.Add(textel);
	oncanvas->DrawText(Point(destdim.x,destdim.y), texteel);
}
示例#3
0
	virtual result DrawButton(Canvas& canvas)
	{
		canvas.SetBackgroundColor(Color(0, 0, 0, 0));
		canvas.Clear();

		if (_state == BUTTON_STATE_NORMAL)
		{
			canvas.FillRoundRectangle(_pallete[BUTTON_COLOR_BG_NORMAL], Rectangle(0, 0 , _bounds.width, _bounds.height), Dimension(5, 5));
		}
		else
		{
			canvas.FillRoundRectangle(_pallete[BUTTON_COLOR_BG_PRESSED], Rectangle(0, 0 , _bounds.width, _bounds.height), Dimension(5, 5));
		}

        Font font;
        font.Construct(FONT_STYLE_PLAIN, 18);
        canvas.SetFont(font);

        if (_text != L"")
        {
        	EnrichedText enriched;
        	enriched.Construct(Dimension(_bounds.width, _bounds.height));
        	enriched.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
        	enriched.SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);

        	TextElement element;
        	element.Construct(_text);
    		if (_state == BUTTON_STATE_NORMAL)
    		{
    			element.SetTextColor(_pallete[BUTTON_COLOR_FG_NORMAL]);
    		}
    		else
    		{
    			element.SetTextColor(_pallete[BUTTON_COLOR_FG_PRESSED]);
    		}
    		enriched.Add(element);
    		canvas.DrawText(Point(0, 0), enriched);
    		enriched.RemoveAll(false);
        }

		return E_SUCCESS;
	}
示例#4
0
void Dictionary::AddItemTitle(CustomItem *& pItem, String name, int itemWidth)
{
	result r;

	EnrichedText* pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(itemWidth, 200));

	TextElement * pTextElement = new TextElement();
	r = pTextElement->Construct(name);

	Font font;
	font.Construct(FONT_STYLE_BOLD, 40);
	pTextElement->SetFont(font);

	pEnrichedText->Add(*pTextElement);

	AddToDestructList(pTextElement);
	AddToDestructList(pEnrichedText);
	pItem->AddElement(Rectangle(10, 5, itemWidth - 10, 50), ID_FORMAT_STRING, *pEnrichedText);
}
Tizen::Ui::Controls::ListItemBase *
ShoppingListTab1::CreateItem(int index, int itemWidth)
{

	String*	pvalueText;
	DbRow* pRow = theTableLists.GetRow(index);
	if (pRow)
	{
		pRow->GetText(1, pvalueText);
	}

	String strName = *pvalueText;

	int textWidth = GetWidth() - INDENT*2;

	EnrichedText enrichedText;
	enrichedText.Construct(FloatDimension(textWidth, 112));
	enrichedText.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
	enrichedText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
	enrichedText.SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);

	Font pFont;
	pFont.Construct(FONT_STYLE_BOLD, 44.0f);

	TextElement* pTextElement = new (std::nothrow) TextElement();
	pTextElement->Construct(strName + "\n");
	pTextElement->SetFont(pFont);
	enrichedText.Add(*pTextElement);

	int textHeight = enrichedText.GetTotalLineHeight();

	CustomItem* pItem = new CustomItem();
	pItem->Construct(Dimension(GetWidth(), textHeight + INDENT*2), LIST_ANNEX_STYLE_NORMAL);
	pItem->AddElement(Rectangle(INDENT, INDENT, textWidth, textHeight), 0, enrichedText);

	AppAssert(pItemContext);
	pItem->SetContextItem(pItemContext);

	return pItem;

}
示例#6
0
void Dictionary::AddItemPreparing(CustomItem *& pItem, int itemWidth)
{
	result r;

	EnrichedText* pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(itemWidth, 200));
	pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
	pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
	TextElement * pTextElement = new TextElement();
	r = pTextElement->Construct(Utils::GetString("IDS_PREPARING"));

	Font font;
	font.Construct(FONT_STYLE_PLAIN, 25);
	pTextElement->SetFont(font);
	pEnrichedText->Add(*pTextElement);

	AddToDestructList(pTextElement);
	AddToDestructList(pEnrichedText);
	int width, height;
	pEnrichedText->GetSize(width, height);
	pItem->AddElement(Rectangle(0, 5, itemWidth - 10, 30), ID_FORMAT_PREPARING, *pEnrichedText);
}
示例#7
0
void Dictionary::AddItemExamples(CustomItem *& pItem, int itemWidth, String examples)
{
	result r;

	EnrichedText* pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(itemWidth, 200));
	pEnrichedText->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
	pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
	pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);

	TextElement * pTextElement = new TextElement();
	r = pTextElement->Construct(examples);

	Font font;
	font.Construct(FONT_STYLE_PLAIN, 20);
	pTextElement->SetFont(font);

	pEnrichedText->Add(*pTextElement);

	AddToDestructList(pTextElement);
	AddToDestructList(pEnrichedText);

	pItem->AddElement(Rectangle(10, 45, itemWidth - 80, ITEM_HEIGHT - 60), ID_FORMAT_EXAMPLES, *pEnrichedText);
}
 result DrawElement(const Osp::Graphics::Canvas& canvas, const Osp::Graphics::Rectangle& rect, CustomListItemStatus itemStatus)
 {
     result r = E_SUCCESS;

     Canvas* pCanvas = const_cast<Canvas*>(&canvas);

     Font textfont;
     textfont.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 28);

     EnrichedText texteel;
     texteel.Construct(Dimension(rect.width, rect.height));
   	 texteel.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_LEFT);
     texteel.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_MIDDLE);
     texteel.SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
     texteel.SetTextAbbreviationEnabled(true);
     TextElement textelcol;
     textelcol.Construct(text);
     textelcol.SetTextColor(Color::COLOR_WHITE);
     textelcol.SetFont(textfont);
     texteel.Add(textelcol);
     pCanvas->DrawText(Point(0,0), texteel);

     return r;
 }
示例#9
0
    bool drawText(const char * pszText, Dimension& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0)
    {
        bool nRet = false;
        do
        {
            CC_BREAK_IF(pszText == NULL || strlen(pszText) <= 0);
            // text
            Osp::Base::String strText(pszText);
            // Set a font to the TextElement
            Font font;
            bool bUseDefaultFont = true;
            if (fontName != NULL && strlen(fontName) > 0)
            {
                String strFonName(fontName);
                if (strFonName.EndsWith(".ttf") || strFonName.EndsWith(".TTF"))
                {
                    bUseDefaultFont = false;
                    const char* pFullFontPath = CCFileUtils::fullPathFromRelativePath(fontName);
                    font.Construct(pFullFontPath, FONT_STYLE_PLAIN, fontSize);
                }
                else
                {
                    IList* pSystemFontList = Font::GetSystemFontListN();
                    if (pSystemFontList != NULL)
                    {
                        IEnumerator* pEnum = pSystemFontList->GetEnumeratorN();
                        Object* pObj = null;
                        while (pEnum->MoveNext() == E_SUCCESS)
                        {
                            pObj = pEnum->GetCurrent();
                            String* pStrName = static_cast<String*>(pObj);
                            if (pStrName->Equals(strFonName, false))
                            {
                                bUseDefaultFont = false;
                                font.Construct(*pStrName, FONT_STYLE_PLAIN, fontSize);
                                break;
                            }
                        }

                        delete pEnum;

                        pSystemFontList->RemoveAll(true);
                        delete pSystemFontList;
                    }
                }
            }

            if (bUseDefaultFont)
            {
                font.Construct(FONT_STYLE_PLAIN, fontSize);
            }

            // calculate text size
            if (dimensions.width <= 0)
            {
                Dimension dim;
                font.GetTextExtent(strText, strText.GetLength(), dim);
                dimensions.width = dim.width;
                dimensions.height = dim.height;
            }

            CC_BREAK_IF(dimensions.width <= 0);

            // Create an EnrichedText
            m_pEnrichedText = new EnrichedText();
            m_pEnrichedText->Construct(Dimension(dimensions.width, 10));

            switch (alignment)
            {
            case CCImage::kAlignCenter:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
                break;
            case CCImage::kAlignTop:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
                break;
            case CCImage::kAlignTopRight:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
                break;
            case CCImage::kAlignRight:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
                break;
            case CCImage::kAlignBottomRight:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM);
                break;
            case CCImage::kAlignBottom:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM);
                break;
            case CCImage::kAlignBottomLeft:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM);
                break;
            case CCImage::kAlignLeft:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
                break;
            case CCImage::kAlignTopLeft:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
                break;
            default:
                m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
                m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
                break;
            }
            // Set attributes of the EnrichedText
            m_pEnrichedText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
            m_pEnrichedText->SetTextAbbreviationEnabled(true);

            // Create a TextElement
            TextElement* pTextElement = new TextElement();
            pTextElement->Construct(strText);
            // After Adding, set attributes of the TextElement
            pTextElement->SetTextColor(Color::COLOR_WHITE);
            pTextElement->SetFont(font);
            // Add the TextElement to the EnrichedText
            m_pEnrichedText->Add(*pTextElement);

            m_pEnrichedText->Refresh();
            dimensions.height = m_pEnrichedText->GetTotalLineHeight();
            m_pEnrichedText->SetSize(dimensions.width, dimensions.height);

            CC_SAFE_DELETE(m_pCanvas);
            m_pCanvas = new Canvas();
            m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
            m_pCanvas->DrawText(Point(0, 0), *m_pEnrichedText);

            m_pEnrichedText->RemoveAllTextElements(true);
            CC_SAFE_DELETE(m_pEnrichedText);

            nRet = true;
        } while (0);
        return nRet;
    }