mirror of https://github.com/axmolengine/axmol.git
Merge pull request #11720 from WenhaiLin/v3-label-outline
Label:Fixed outline doesn't match with the characters exactly.
This commit is contained in:
commit
ba1e77d656
|
@ -269,10 +269,11 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid
|
|||
break;
|
||||
}
|
||||
|
||||
outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6;
|
||||
outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6);
|
||||
outRect.size.width = (_fontRef->glyph->metrics.width >> 6);
|
||||
outRect.size.height = (_fontRef->glyph->metrics.height >> 6);
|
||||
auto& metrics = _fontRef->glyph->metrics;
|
||||
outRect.origin.x = metrics.horiBearingX >> 6;
|
||||
outRect.origin.y = -(metrics.horiBearingY >> 6);
|
||||
outRect.size.width = (metrics.width >> 6);
|
||||
outRect.size.height = (metrics.height >> 6);
|
||||
|
||||
xAdvance = (static_cast<int>(_fontRef->glyph->metrics.horiAdvance >> 6));
|
||||
|
||||
|
@ -294,35 +295,46 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid
|
|||
break;
|
||||
}
|
||||
|
||||
auto outlineWidth = (bbox.xMax - bbox.xMin)>>6;
|
||||
auto outlineHeight = (bbox.yMax - bbox.yMin)>>6;
|
||||
long glyphMinX = outRect.origin.x;
|
||||
long glyphMaxX = outRect.origin.x + outWidth;
|
||||
long glyphMinY = -outHeight - outRect.origin.y;
|
||||
long glyphMaxY = -outRect.origin.y;
|
||||
|
||||
auto blendWidth = outlineWidth > outWidth ? outlineWidth : outWidth;
|
||||
auto blendHeight = outlineHeight > outHeight ? outlineHeight : outHeight;
|
||||
auto outlineMinX = bbox.xMin >> 6;
|
||||
auto outlineMaxX = bbox.xMax >> 6;
|
||||
auto outlineMinY = bbox.yMin >> 6;
|
||||
auto outlineMaxY = bbox.yMax >> 6;
|
||||
auto outlineWidth = outlineMaxX - outlineMinX;
|
||||
auto outlineHeight = outlineMaxY - outlineMinY;
|
||||
|
||||
long index,index2;
|
||||
auto blendImageMinX = MIN(outlineMinX, glyphMinX);
|
||||
auto blendImageMaxY = MAX(outlineMaxY, glyphMaxY);
|
||||
auto blendWidth = MAX(outlineMaxX, glyphMaxX) - blendImageMinX;
|
||||
auto blendHeight = blendImageMaxY - MIN(outlineMinY, glyphMinY);
|
||||
|
||||
long index, index2;
|
||||
auto blendImage = new unsigned char[blendWidth * blendHeight * 2];
|
||||
memset(blendImage, 0, blendWidth * blendHeight * 2);
|
||||
|
||||
auto px = (blendWidth - outlineWidth) / 2;
|
||||
auto py = (blendHeight - outlineHeight) / 2;
|
||||
auto px = outlineMinX - blendImageMinX;
|
||||
auto py = blendImageMaxY - outlineMaxY;
|
||||
for (int x = 0; x < outlineWidth; ++x)
|
||||
{
|
||||
for (int y = 0; y < outlineHeight; ++y)
|
||||
{
|
||||
index = px + x + ( (py + y) * blendWidth );
|
||||
index = px + x + ((py + y) * blendWidth);
|
||||
index2 = x + (y * outlineWidth);
|
||||
blendImage[2 * index] = outlineBitmap[index2];
|
||||
}
|
||||
}
|
||||
|
||||
px = (blendWidth - outWidth) / 2;
|
||||
py = (blendHeight - outHeight) / 2;
|
||||
px = glyphMinX - blendImageMinX;
|
||||
py = blendImageMaxY - glyphMaxY;
|
||||
for (int x = 0; x < outWidth; ++x)
|
||||
{
|
||||
for (int y = 0; y < outHeight; ++y)
|
||||
{
|
||||
index = px + x + ( (y + py) * blendWidth );
|
||||
index = px + x + ((y + py) * blendWidth);
|
||||
index2 = x + (y * outWidth);
|
||||
blendImage[2 * index + 1] = copyBitmap[index2];
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ NewLabelTests::NewLabelTests()
|
|||
ADD_TEST_CASE(LabelSystemFontColor);
|
||||
ADD_TEST_CASE(LabelIssue10773Test);
|
||||
ADD_TEST_CASE(LabelIssue10576Test);
|
||||
ADD_TEST_CASE(LabelIssue11699Test);
|
||||
};
|
||||
|
||||
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
|
||||
|
@ -1913,3 +1914,23 @@ std::string LabelIssue10576Test::subtitle() const
|
|||
{
|
||||
return "You should see another string displayed correctly after 2 seconds.";
|
||||
}
|
||||
|
||||
LabelIssue11699Test::LabelIssue11699Test()
|
||||
{
|
||||
auto center = VisibleRect::center();
|
||||
|
||||
auto label = Label::createWithTTF("中国", "fonts/HKYuanMini.ttf", 150);
|
||||
label->enableOutline(Color4B::RED, 2);
|
||||
label->setPosition(center.x, center.y);
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
std::string LabelIssue11699Test::title() const
|
||||
{
|
||||
return "Test for Issue #11699";
|
||||
}
|
||||
|
||||
std::string LabelIssue11699Test::subtitle() const
|
||||
{
|
||||
return "Outline should match with the characters exactly.";
|
||||
}
|
||||
|
|
|
@ -576,4 +576,15 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class LabelIssue11699Test : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelIssue11699Test);
|
||||
|
||||
LabelIssue11699Test();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue