[hot fixed]closed issue#4999:fixed label is unsharp if it's created by smaller font.

This commit is contained in:
Dhilan007 2014-05-06 10:36:55 +08:00
parent c91f94fa5c
commit e412f91103
8 changed files with 21 additions and 13 deletions

View File

@ -1079,7 +1079,10 @@ bool Texture2D::initWithString(const char *text, const std::string& fontName, fl
bool Texture2D::initWithString(const char *text, const FontDefinition& textDefinition)
{
if(!text || 0 == strlen(text))
{
return false;
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture data
VolatileTextureMgr::addStringTexture(this, text, textDefinition);
@ -1127,9 +1130,11 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
textDef._stroke._strokeSize *= contentScaleFactor;
textDef._shadow._shadowEnabled = false;
Data outData = Device::getTextureDataForText(text,textDef,align,imageWidth,imageHeight);
Data outData = Device::getTextureDataForText(text, textDef, align, imageWidth, imageHeight, _hasPremultipliedAlpha);
if(outData.isNull())
{
return false;
}
Size imageSize = Size((float)imageWidth, (float)imageHeight);
pixelFormat = convertDataToFormat(outData.getBytes(), imageWidth*imageHeight*4, PixelFormat::RGBA8888, pixelFormat, &outTempData, &outTempDataLen);
@ -1140,11 +1145,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
{
free(outTempData);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
_hasPremultipliedAlpha = true;
#else
_hasPremultipliedAlpha = false;
#endif
return ret;
}

View File

@ -64,7 +64,7 @@ public:
*/
static void setAccelerometerInterval(float interval);
static Data getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &widht,int &height);
static Data getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha);
private:
CC_DISALLOW_IMPLICIT_CONSTRUCTORS(Device);

View File

@ -167,7 +167,7 @@ static BitmapDC& sharedBitmapDC()
return s_BmpDC;
}
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
do
@ -196,6 +196,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
width = dc._width;
height = dc._height;
ret.fastSet(dc._data,width * height * 4);
hasPremultipliedAlpha = true;
} while (0);
return ret;

View File

@ -452,7 +452,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
}
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
@ -481,6 +481,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
height = (short)info.height;
width = (short)info.width;
ret.fastSet(info.data,width * height * 4);
hasPremultipliedAlpha = true;
} while (0);
return ret;

View File

@ -480,7 +480,7 @@ static BitmapDC& sharedBitmapDC()
return s_BmpDC;
}
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
do
@ -493,6 +493,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
height = dc.iMaxLineHeight;
dc.reset();
ret.fastSet(dc._data,width * height * 4);
hasPremultipliedAlpha = true;
} while (0);
return ret;

View File

@ -224,7 +224,7 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
return ret;
}
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
do {
@ -239,6 +239,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
height = (short)info.height;
width = (short)info.width;
ret.fastSet(info.data,width * height * 4);
hasPremultipliedAlpha = true;
} while (0);
return ret;

View File

@ -377,7 +377,7 @@ static BitmapDC& sharedBitmapDC()
return s_BmpDC;
}
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
do
@ -429,7 +429,9 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
}
ret.fastSet(dataBuf,dataLen);
hasPremultipliedAlpha = false;
} while (0);
return ret;
}

View File

@ -147,7 +147,7 @@ void Device::setAccelerometerInterval(float interval)
Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height)
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
{
Data ret;
ssize_t dataLen;
@ -157,6 +157,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
if (data)
{
ret.fastSet(data, dataLen);
hasPremultipliedAlpha = false;
}
return ret;