Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Unicode Combining Diacritical Marks in FlxBitmapText #2309

Merged
merged 5 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions flixel/graphics/frames/FlxBitmapFont.hx
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,15 @@ class FlxBitmapFont extends FlxFramesCollection
font.updateSourceHeight();
return font;
}

/**
* Checks if the specified code is one of the Unicode Combining Diacritical Marks
* @param Code The charactercode we want to check
* @return Bool Returns true if the code is a Unicode Combining Diacritical Mark
*/
public static function isUnicodeComboMark(Code:Int):Bool
SeiferTim marked this conversation as resolved.
Show resolved Hide resolved
{
return ((Code >= 768 && Code <= 879) || (Code >= 6832 && Code <= 6911) || (Code >= 7616 && Code <= 7679) || (Code >= 8400 && Code <= 8447)
|| (Code >= 65056 && Code <= 65071));
}
}
69 changes: 54 additions & 15 deletions flixel/text/FlxBitmapText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class FlxBitmapText extends FlxSprite
}

var clippedFrameRect;
var tmpFrameRect:FlxRect = FlxRect.get();
Gama11 marked this conversation as resolved.
Show resolved Hide resolved

if (clipRect != null)
{
clippedFrameRect = clipRect.intersection(FlxRect.weak(0, 0, frameWidth, frameHeight));
Expand Down Expand Up @@ -440,12 +442,14 @@ class FlxBitmapText extends FlxSprite
_colorParams.setMultipliers(borderRed, borderGreen, borderBlue, bAlpha);
drawItem.addQuad(currFrame, _matrix, _colorParams);
}

var prevAdv:Float = 0;

for (j in 0...textLength)
{
dataPos = j * 3;

currFrame = font.getCharFrame(Std.int(textDrawData[dataPos]));
currFrame = font.getCharFrame(Std.int(textDrawData[dataPos])).copyTo();
SeiferTim marked this conversation as resolved.
Show resolved Hide resolved

currTileX = textDrawData[dataPos + 1];
currTileY = textDrawData[dataPos + 2];
Expand All @@ -455,6 +459,17 @@ class FlxBitmapText extends FlxSprite
clippedFrameRect.copyFrom(clipRect).offset(-currTileX, -currTileY);
currFrame = currFrame.clipTo(clippedFrameRect);
}

if (FlxBitmapFont.isUnicodeComboMark(Std.int(textDrawData[dataPos])))
{
tmpFrameRect.copyFrom(currFrame.frame);
tmpFrameRect.width = Math.min(currFrame.frame.width, prevAdv + letterSpacing);
currFrame.frame = tmpFrameRect;
}
else
{
prevAdv = font.getCharAdvance(Std.int(textDrawData[dataPos]));
}

currFrame.prepareMatrix(_matrix);
_matrix.translate(currTileX - ox, currTileY - oy);
Expand Down Expand Up @@ -1182,6 +1197,8 @@ class FlxBitmapText extends FlxSprite
var spaceWidth:Int = font.spaceWidth;
var lineLength:Int = line.uLength();
var textWidth:Int = this.textWidth;

var charUt8;
Gama11 marked this conversation as resolved.
Show resolved Hide resolved

if (alignment == FlxTextAlign.JUSTIFY)
{
Expand All @@ -1207,33 +1224,44 @@ class FlxBitmapText extends FlxSprite
}

var tabWidth:Int = spaceWidth * numSpacesInTab;

var prevAdv:Float = 0;

for (i in 0...lineLength)
{
charCode = line.uCharCodeAt(i);

if (charCode == FlxBitmapFont.SPACE_CODE)
{
curX += spaceWidth;
curX += spaceWidth + letterSpacing;
prevAdv = spaceWidth;
}
else if (charCode == FlxBitmapFont.TAB_CODE)
{
curX += tabWidth;
curX += tabWidth + letterSpacing;
prevAdv = tabWidth;
}
else
{
charFrame = font.getCharFrame(charCode);
if (charFrame != null)
{
_flashPoint.setTo(curX, curY);

if (FlxBitmapFont.isUnicodeComboMark(charCode))
{
_flashPoint.setTo(curX - prevAdv - letterSpacing, curY);
}
else
{
_flashPoint.setTo(curX, curY);
curX += font.getCharAdvance(charCode) + letterSpacing;
prevAdv = font.getCharAdvance(charCode);
}
charFrame.paint(textBitmap, _flashPoint, true);
var charUt8 = new UnicodeBuffer();
charUt8 = new UnicodeBuffer();
charUt8 = charUt8.addChar(charCode);
curX += font.getCharAdvance(charCode);
}
}

curX += letterSpacing;
}
}

Expand All @@ -1253,6 +1281,8 @@ class FlxBitmapText extends FlxSprite
var spaceWidth:Int = font.spaceWidth;
var lineLength:Int = line.uLength();
var textWidth:Int = this.textWidth;

var prevAdv:Float = 0;

if (alignment == FlxTextAlign.JUSTIFY)
{
Expand Down Expand Up @@ -1285,25 +1315,33 @@ class FlxBitmapText extends FlxSprite

if (charCode == FlxBitmapFont.SPACE_CODE)
{
curX += spaceWidth;
curX += spaceWidth + letterSpacing;
prevAdv = tabWidth;
}
else if (charCode == FlxBitmapFont.TAB_CODE)
{
curX += tabWidth;
curX += tabWidth + letterSpacing;
prevAdv = tabWidth;
}
else
{
charFrame = font.getCharFrame(charCode);
if (charFrame != null)
if (charFrame != null)
{
textData[pos++] = charCode;
textData[pos++] = curX;
if (FlxBitmapFont.isUnicodeComboMark(charCode))
{
textData[pos++] = curX - prevAdv - letterSpacing;
}
else
{
textData[pos++] = curX;
curX += font.getCharAdvance(charCode);
prevAdv = font.getCharAdvance(charCode);
}
textData[pos++] = curY;
curX += font.getCharAdvance(charCode);
}
}

curX += letterSpacing;
}
}

Expand Down Expand Up @@ -1512,6 +1550,7 @@ class FlxBitmapText extends FlxSprite
var textLen:Int = Std.int(textData.length / 3);
var rect = FlxRect.get();
var frameVisible;
var prevAdv:Float = 0;
Gama11 marked this conversation as resolved.
Show resolved Hide resolved

for (i in 0...textLen)
{
Expand Down