Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // character set image in base64 -- 144x256 image of IBM VGA Code Page 37 with a matrix of 16x16 characters each with a width of 9px wide by 16px high
- // note this is not the actual full base 64 string, as it would be too large to paste in here however,
- // if you want to see the full base string, you can just ask me, and I'll be happy to send it
- let baseString = "data:image/png;base64,iVBORw0KGgoAAAANggg=="; // note: is truncated ^^
- // create a texture from our base64 encoded image
- let newTex = PIXI.Texture.from( baseString );
- // nearest so it doesn't become blurry or filtered
- newTex.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;
- // create the font descriptor in xml format
- let objStr =
- `<?xml version="1.0"?>
- <font>
- <info face="Px437" size="16" bold="0" italic="0" charset="ASCII" unicode="0" stretchH="100" smooth="0" aa="0" padding="0,0,0,0" spacing="0,0"/>
- <common lineHeight="16" base="12" scaleW="144" scaleH="256" pages="1" packed="0"/>
- <pages>
- <page id="0" file=""/>
- </pages>
- <chars count="256">`;
- // generating each character descriptor, which is easy programatically since the chars are uniform 9x16 px
- for( var i = 0; i < 256; i++ )
- {
- let x = ( i % 16) * 9;
- let y = Math.floor( i / 16 ) * 16;
- objStr += "\n\t\t\t\t\t";
- objStr += ( `<char id="` + i + `" x="` + x + `" y="` + y + `" width="9" height="16" xoffset="0" yoffset="0" xadvance="9" page="0" chnl="15"/>` );
- }
- objStr +=
- `
- </chars>
- </font>`;
- // so apparently most if not all browsers have a parse function to do either html or xml
- let xp = new DOMParser();
- // so now we parse the xml into an XMLDocument type object
- let xd = xp.parseFromString( objStr, "text/xml" );
- // this is for pixi 5 so if I end upgrading to later versions, I will probably have to change this
- PIXI.BitmapText.registerFont( xd, newTex );
- function GenerateCharacterLookup() : Map<string, string>
- {
- // so these are the "visible" code page 437 characters -- with the exception of 11 and 13 which can't be displayed because they're
- // line feed and carriage return characters -- so those two characters I've copied from two other characters. One was a musical note
- // and the other was the one that is a square with a circle in it.
- let codePage437Chars = " ☺☻♥♦♣♠•◘○■♂♀♫♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■"
- // the key will be the unicode version or the 'visible' version of the keys you want to convert
- // the value will be these characters after their converted into their ascii equivalents.
- let lookupTable = new Map<string, string>();
- // iterate through all characters
- for (let i = 0; i < codePage437Chars.length; i++)
- {
- // the characters as you would see them for the key
- let char = codePage437Chars[i];
- // ascii equivalent -- technically is also unicode, but cover chars 0-255
- let asciiEqu = String.fromCharCode(i);
- // so let's build the table
- lookupTable.set(char, asciiEqu);
- }
- return lookupTable;
- }
- let characterLookup = GenerateCharacterLookup();
- // this will take the string you want to display
- function ConvertString( myString : string, lookup : Map<string, string> ) : string
- {
- let returnString = "";
- // go through your string
- for( let i = 0; i < myString.length; i++ )
- {
- // and get the proper ascii position, to get the character
- // representing what's in the table.
- returnString += lookup.get( myString.charAt( i ) );
- }
- return returnString;
- }
- // so now we have our string
- let testStr = ConvertString( "«░▒▓»▲▲▲ UP / DOWN ▼▼▼«▓▒░»", characterLookup );
- // we also have our font that we registered before hand
- let bitmapText = new PIXI.BitmapText( testStr, { font : { name : "Px437", size : 16 }, align : "left" } );
- bitmapText.x = 512+58;
- bitmapText.y = 200;
- this._uiLayer.addChild( bitmapText );
Add Comment
Please, Sign In to add comment