Merge branch 'newest' into master_base

This commit is contained in:
dumganhar 2011-11-23 21:47:21 +08:00
commit cfa42fa8a1
2 changed files with 52 additions and 45 deletions

View File

@ -69,31 +69,45 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * pBuffer = NULL;
unsigned char * pData = 0;
string fullPath;
if ((! pszFileName) || (! pszMode))
{
return 0;
}
fullPath = fullPathFromRelativePath(pszFileName);
do
{
// read the file from hardware
FILE *fp = fopen(pszFileName, pszMode);
// read rrom other path than user set it
FILE *fp = fopen(fullPath.c_str(), pszMode);
CC_BREAK_IF(!fp);
unsigned long size;
fseek(fp,0,SEEK_END);
*pSize = ftell(fp);
size = ftell(fp);
fseek(fp,0,SEEK_SET);
pBuffer = new unsigned char[*pSize];
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
pData = new unsigned char[size];
size = fread(pData,sizeof(unsigned char), size,fp);
fclose(fp);
if (pSize)
{
*pSize = size;
}
} while (0);
if (! pBuffer && getIsPopupNotify())
if (! pData && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName).append(") failed!");
msg.append(fullPath.c_str()).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pBuffer;
return pData;
}
void CCFileUtils::setResource(const char* pszZipFileName)

View File

@ -43,11 +43,12 @@ public:
CC_SAFE_DELETE(m_pCanvas);
}
bool drawText(const char * pszText, CCSize& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 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
@ -55,7 +56,7 @@ public:
font.Construct(FONT_STYLE_PLAIN, fontSize);
// calculate text size
if (CCSize::CCSizeEqualToSize(dimensions, CCSizeZero))
if (dimensions.width <= 0)
{
Dimension dim;
font.GetTextExtent(strText, strText.GetLength(), dim);
@ -63,16 +64,11 @@ public:
dimensions.height = dim.height;
}
CC_SAFE_DELETE(m_pCanvas);
CC_BREAK_IF(dimensions.width <= 0 || dimensions.height <= 0);
m_pCanvas = new Canvas();
m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
CC_BREAK_IF(dimensions.width <= 0);
// Create an EnrichedText
m_pEnrichedText = new EnrichedText();
m_pEnrichedText->Construct(Dimension(dimensions.width, dimensions.height));
m_pEnrichedText->Construct(Dimension(dimensions.width, 10));
switch (alignment)
{
@ -130,6 +126,13 @@ public:
// 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);
@ -169,7 +172,7 @@ bool CCImage::initWithString(
BitmapDC& dc = sharedBitmapDC();
CCSize size(nWidth, nHeight);
Dimension size(nWidth, nHeight);
bRet = dc.drawText(pText, size, eAlignMask, pFontName, nSize);
@ -186,23 +189,13 @@ bool CCImage::initWithString(
CC_BREAK_IF(!m_pData);
memcpy(m_pData, bufferInfo.pPixels, nLen);
if (bufferInfo.bitsPerPixel == 32)
{
if (bufferInfo.width * 4 != bufferInfo.pitch)
{
m_nWidth = bufferInfo.pitch / 4;
}
else
{
m_nWidth = bufferInfo.width;
}
}
int iBytesPerPixel = bufferInfo.bitsPerPixel/8;
m_nWidth = bufferInfo.pitch / iBytesPerPixel;
m_nHeight = bufferInfo.height;
m_bHasAlpha = true;
m_bPreMulti = false;
m_nBitsPerComponent = bufferInfo.bitsPerPixel / 4;
m_nBitsPerComponent = 8;
dc.m_pCanvas->Unlock();
bRet = true;