Jump to content

Bitmap font support for Cocoonjs.


Ezelia
 Share

Recommended Posts

Hi all.

 

I followed some discussion here about bitmap font support for cocoonjs, and saw that in the current Pixi.js code there is the following code.

            var responseXML = this.ajaxRequest.responseXML;            if(!responseXML || /MSIE 9/i.test(navigator.userAgent) || navigator.isCocoonJS) {                if(typeof(window.DOMParser) === 'function') {                    var domparser = new DOMParser();                    responseXML = domparser.parseFromString(this.ajaxRequest.responseText, 'text/xml');                } else {                    var div = document.createElement('div');                    div.innerHTML = this.ajaxRequest.responseText;                    responseXML = div;                }            }

but even with this, it don't work on cocoonjs for me, cocoonjs complains about "getNamedItem".
 

Don't know if it's only me or it's not working for everyone.

so I tried another approach to fix this, instead of parsing the bitmap file in XML I parsed it with regex, and I got a working parser for all platforms since it only rely on regexp.

 

 

here is how the modified parser looks like (I removed PIXI stuff so you can see how the parser works)

//parse general information ===var textureUrl = str.match(/<page[^>]+file\=\"([^\"]+)\"[^>]+>/i)[1];var data = {};data.font = str.match(/<info[^>]+face\=\"([^\"]+)\"[^>]+>/i)[1];data.size = parseInt(str.match(/<info[^>]+size\=\"([^\"]+)\"[^>]+>/i)[1], 10);data.lineHeight = parseInt(str.match(/<common[^>]+lineHeight\=\"([^\"]+)\"[^>]+>/i)[1], 10);//parse chars ===data.chars = {};//we only want those fields,//also used to translate fields names if needed (ex. xoffset ==> xOffset)var fields = {    'id': 'id',    'xoffset': 'xOffset',    'yoffset': 'yOffset',    'xadvance': 'xAdvance',    'x': 'x',    'y': 'y',    'width': 'width',    'height': 'height',    'first': 'first',    'second': 'second',    'amount': 'amount'};//we don't replace anything here, we only use the replace callback to parse the string.str.replace(/<char ([^>]+)>/gi, function () {    var attr = arguments[1];    var obj = {};    attr.replace(/(([a-z]+)\=\"([0-9\-]+))\"/gi, function () {        var left = arguments[2].toLowerCase();        if (!fields[left]) return;                                            obj[fields[left] = parseInt(arguments[3]);    });    obj.kerning = {};    if (obj.id)        data.chars[obj.id] = obj;    delete obj.id;    return attr;});//parse kernings ===str.replace(/<kerning ([^>]+)>/gi, function () {    var attr = arguments[1];    var obj = {};    attr.replace(/(([a-z]+)\=\"([0-9\-]+))\"/gi, function () {        var left = arguments[2].toLowerCase();        if (!fields[left]) return;                                            obj[fields[left] = parseInt(arguments[3]);    });    if (obj.second)        data.chars[obj.second] = obj;    return attr;});

if you think this can help, I'll make a pull request on Pixi repo :)

Link to comment
Share on other sites

yes fnt format is correct, I used the one with phaser examples to make sure.

I'm using Android 4.2.

 

cannot test with the launcher, I think I have something wrong in my example that prevent the launcher to run.

but I noticed that the launcher still have the old ludei logo, when my cocoonjs build has the new logo, so I think it don't use the sale version ...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...