HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 436 forks source link

FlxTextFormatMarkerPair shifted two characters to the right. #1702

Closed xerosugar closed 8 years ago

xerosugar commented 8 years ago

For example, if I work with the following string: "you absolutely must do this" and use '_' as markers the string that gets the applied format is: "solutely m". Expected string is: "absolutely"

Gama11 commented 8 years ago

Please provide some code that reproduces the issue and list your library versions.

xerosugar commented 8 years ago
var formatBlue = new FlxTextFormat(0xff269fff);     
txt.setFormat(null, 43, 0xff000000, FlxTextAlign.LEFT);
txt.applyMarkup("If there’s one piece of knowledge that you _absolutely_ must bring with you, it's this!", [new FlxTextFormatMarkerPair(formatBlue, "_")]);
add(txt);

libs:

Gama11 commented 8 years ago

Reduced it a bit:

package;

import flixel.FlxState;
import flixel.text.FlxText;
import flixel.util.FlxColor;

class PlayState extends FlxState
{
    override public function create():Void
    {
        var text = new FlxText();
        text.applyMarkup("’ _absolutely_ must",
            [new FlxTextFormatMarkerPair(new FlxTextFormat(FlxColor.CYAN), "_")]);
        add(text);
    }
}

Two observations:

Gama11 commented 8 years ago

This working correctly implies that it's probably not an OpenFL issue:

package;

import flixel.FlxG;
import flixel.FlxState;
import flixel.util.FlxColor;
import openfl.text.TextField;
import openfl.text.TextFormat;

class PlayState extends FlxState
{
    override public function create():Void
    {
        bgColor = FlxColor.WHITE;

        var text = new TextField();
        text.text = "’ shifted right";
        text.setTextFormat(new TextFormat(null, null, 0xff0000), 2, 9);
        FlxG.stage.addChild(text);
    }
}
Gama11 commented 8 years ago

This traces 1 on Flash and 3 on neko / cpp:

trace("’".length);

I think we need to use haxe.Utf8 here like in FlxBitmapText.

Gama11 commented 8 years ago

Should be working now.

xerosugar commented 8 years ago

thank you for that very quick turnaround, you're on fire! :fire: