mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6090 from dumganhar/iss4383-label-missing-letters
closed #4383: Fixed missing letters if using old LabelTTF and running on iPhone 64bit simulator(device).
This commit is contained in:
commit
5c57ba5aea
|
@ -199,6 +199,18 @@ typedef struct
|
||||||
|
|
||||||
} tImageInfo;
|
} tImageInfo;
|
||||||
|
|
||||||
|
static bool s_isIOS7OrHigher = false;
|
||||||
|
|
||||||
|
static inline void lazyCheckIOS7()
|
||||||
|
{
|
||||||
|
static bool isInited = false;
|
||||||
|
if (!isInited)
|
||||||
|
{
|
||||||
|
s_isIOS7OrHigher = [[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
|
||||||
|
isInited = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
|
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
|
||||||
{
|
{
|
||||||
NSArray *listItems = [str componentsSeparatedByString: @"\n"];
|
NSArray *listItems = [str componentsSeparatedByString: @"\n"];
|
||||||
|
@ -209,7 +221,6 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
|
||||||
textRect.height = constrainSize->height > 0 ? constrainSize->height
|
textRect.height = constrainSize->height > 0 ? constrainSize->height
|
||||||
: 0x7fffffff;
|
: 0x7fffffff;
|
||||||
|
|
||||||
|
|
||||||
for (NSString *s in listItems)
|
for (NSString *s in listItems)
|
||||||
{
|
{
|
||||||
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect];
|
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect];
|
||||||
|
@ -222,6 +233,9 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
|
||||||
dim.height += tmp.height;
|
dim.height += tmp.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dim.width = ceilf(dim.width);
|
||||||
|
dim.height = ceilf(dim.height);
|
||||||
|
|
||||||
return dim;
|
return dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,8 +244,12 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
|
||||||
#define ALIGN_CENTER 3
|
#define ALIGN_CENTER 3
|
||||||
#define ALIGN_BOTTOM 2
|
#define ALIGN_BOTTOM 2
|
||||||
|
|
||||||
|
|
||||||
static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, const char * fontName, int size, tImageInfo* info)
|
static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, const char * fontName, int size, tImageInfo* info)
|
||||||
{
|
{
|
||||||
|
// lazy check whether it is iOS7 device
|
||||||
|
lazyCheckIOS7();
|
||||||
|
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -376,7 +394,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
||||||
{
|
{
|
||||||
CGContextSetTextDrawingMode(context, kCGTextStroke);
|
CGContextSetTextDrawingMode(context, kCGTextStroke);
|
||||||
|
|
||||||
if([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
|
if(s_isIOS7OrHigher)
|
||||||
{
|
{
|
||||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||||
paragraphStyle.alignment = nsAlign;
|
paragraphStyle.alignment = nsAlign;
|
||||||
|
@ -412,7 +430,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
||||||
|
|
||||||
// actually draw the text in the context
|
// actually draw the text in the context
|
||||||
[str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:nsAlign];
|
[str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:nsAlign];
|
||||||
|
|
||||||
CGContextEndTransparencyLayer(context);
|
CGContextEndTransparencyLayer(context);
|
||||||
|
|
||||||
// pop the context
|
// pop the context
|
||||||
|
|
|
@ -804,7 +804,7 @@ LabelsEmpty::LabelsEmpty()
|
||||||
label1->setPosition(Point(s.width/2, s.height-100));
|
label1->setPosition(Point(s.width/2, s.height-100));
|
||||||
|
|
||||||
// LabelTTF
|
// LabelTTF
|
||||||
auto label2 = LabelTTF::create("", "fonts/arial.ttf", 24);
|
auto label2 = LabelTTF::create("", "Arial", 24);
|
||||||
addChild(label2, 0, kTagBitmapAtlas2);
|
addChild(label2, 0, kTagBitmapAtlas2);
|
||||||
label2->setPosition(Point(s.width/2, s.height/2));
|
label2->setPosition(Point(s.width/2, s.height/2));
|
||||||
|
|
||||||
|
@ -1000,7 +1000,7 @@ void LabelTTFTest::updateAlignment()
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_label);
|
CC_SAFE_RELEASE(_label);
|
||||||
|
|
||||||
_label = LabelTTF::create(this->getCurrentAlignment(), "fonts/Marker Felt.ttf", 32,
|
_label = LabelTTF::create(this->getCurrentAlignment(), "Marker Felt", 32,
|
||||||
blockSize, _horizAlign, _vertAlign);
|
blockSize, _horizAlign, _vertAlign);
|
||||||
_label->retain();
|
_label->retain();
|
||||||
|
|
||||||
|
@ -1115,7 +1115,7 @@ std::string LabelTTFMultiline::subtitle() const
|
||||||
LabelTTFChinese::LabelTTFChinese()
|
LabelTTFChinese::LabelTTFChinese()
|
||||||
{
|
{
|
||||||
auto size = Director::getInstance()->getWinSize();
|
auto size = Director::getInstance()->getWinSize();
|
||||||
auto label = LabelTTF::create("中国", "fonts/Marker Felt.ttf", 30);
|
auto label = LabelTTF::create("中国", "Marker Felt", 30);
|
||||||
label->setPosition(Point(size.width / 2, size.height /2));
|
label->setPosition(Point(size.width / 2, size.height /2));
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
}
|
}
|
||||||
|
@ -1350,7 +1350,7 @@ LabelTTFA8Test::LabelTTFA8Test()
|
||||||
addChild(layer, -10);
|
addChild(layer, -10);
|
||||||
|
|
||||||
// LabelBMFont
|
// LabelBMFont
|
||||||
auto label1 = LabelTTF::create("Testing A8 Format", "fonts/Marker Felt.ttf", 48);
|
auto label1 = LabelTTF::create("Testing A8 Format", "Marker Felt", 48);
|
||||||
addChild(label1);
|
addChild(label1);
|
||||||
label1->setColor(Color3B::RED);
|
label1->setColor(Color3B::RED);
|
||||||
label1->setPosition(Point(s.width/2, s.height/2));
|
label1->setPosition(Point(s.width/2, s.height/2));
|
||||||
|
@ -1466,7 +1466,7 @@ TTFFontInit::TTFFontInit()
|
||||||
|
|
||||||
auto font = LabelTTF::create();
|
auto font = LabelTTF::create();
|
||||||
|
|
||||||
font->setFontName("fonts/Marker Felt.ttf");
|
font->setFontName("Marker Felt");
|
||||||
font->setFontSize(48);
|
font->setFontSize(48);
|
||||||
font->setString("It is working!");
|
font->setString("It is working!");
|
||||||
this->addChild(font);
|
this->addChild(font);
|
||||||
|
@ -1500,7 +1500,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
||||||
|
|
||||||
FontDefinition shadowTextDef;
|
FontDefinition shadowTextDef;
|
||||||
shadowTextDef._fontSize = 20;
|
shadowTextDef._fontSize = 20;
|
||||||
shadowTextDef._fontName = std::string("fonts/Marker Felt.ttf");
|
shadowTextDef._fontName = std::string("Marker Felt");
|
||||||
|
|
||||||
shadowTextDef._shadow._shadowEnabled = true;
|
shadowTextDef._shadow._shadowEnabled = true;
|
||||||
shadowTextDef._shadow._shadowOffset = shadowOffset;
|
shadowTextDef._shadow._shadowOffset = shadowOffset;
|
||||||
|
@ -1519,7 +1519,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
||||||
// create the stroke only label
|
// create the stroke only label
|
||||||
FontDefinition strokeTextDef;
|
FontDefinition strokeTextDef;
|
||||||
strokeTextDef._fontSize = 20;
|
strokeTextDef._fontSize = 20;
|
||||||
strokeTextDef._fontName = std::string("fonts/Marker Felt.ttf");
|
strokeTextDef._fontName = std::string("Marker Felt");
|
||||||
|
|
||||||
strokeTextDef._stroke._strokeEnabled = true;
|
strokeTextDef._stroke._strokeEnabled = true;
|
||||||
strokeTextDef._stroke._strokeColor = strokeColor;
|
strokeTextDef._stroke._strokeColor = strokeColor;
|
||||||
|
@ -1539,7 +1539,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
||||||
// create the label stroke and shadow
|
// create the label stroke and shadow
|
||||||
FontDefinition strokeShaodwTextDef;
|
FontDefinition strokeShaodwTextDef;
|
||||||
strokeShaodwTextDef._fontSize = 20;
|
strokeShaodwTextDef._fontSize = 20;
|
||||||
strokeShaodwTextDef._fontName = std::string("fonts/Marker Felt.ttf");
|
strokeShaodwTextDef._fontName = std::string("Marker Felt");
|
||||||
|
|
||||||
strokeShaodwTextDef._stroke._strokeEnabled = true;
|
strokeShaodwTextDef._stroke._strokeEnabled = true;
|
||||||
strokeShaodwTextDef._stroke._strokeColor = strokeShadowColor;
|
strokeShaodwTextDef._stroke._strokeColor = strokeShadowColor;
|
||||||
|
|
Loading…
Reference in New Issue