<commit_before># PIXI-CocoonText

This is a plugin for PIXI v3.0.0 and higher. It adds a new text object optimized for mobile and specifically CocoonJS.

```javascript
var foo = new PIXI.cocoontext.CocoonText("This is a text with a cache !",{font:"12px Arial"});
```

It is a modified version of the original PIXI.Text object with the following modifications :

* *Texture cache* : when you create a PIXI.Text object, PIXI needs to use an offscreen canvas to generate your text and use this canvas as a texture. While this is the only way to do it at this moment, this is can be a huge performance bottleneck when you need to create multiple texts in your game. CocoonText provides you an automated cache system to make sure that if you create the same text with the same style a second time, you won't have to create a new canvas/texture. This allows you to preload your texts at the start of your application like you could do for an image or a sound.

* *CocoonJS compatibility* : the way PIXI.Text deals with text resolution is not compatible with CocoonJS v2.0. CocoonText is able to display high density texts for retina screens as long as you provide a font size with a px unit. You can set PIXI.cocoontext.CONST.TEXT_RESOLUTION to set a default resolution for all of your CocoonText objects. This can be useful if you want the best looking texts possible by setting it to the devicePixelRatio multiplied by the scale of your UI.

## Typical use case

Building a button with an "active" and "inactive" state that change the text style with preloaded textures

```javascript
//I set the resolution of my texts to the devicePixelRatio * the scale of my stage
PIXI.cocoontext.CONST.TEXT_RESOLUTION = window.devicePixelRatio * stage.scale.x;

// While my game is loading, I generate the texts I will need later
function preloadTexts()
{
    var myTexts = [
        new PIXI.cocoontext.CocoonText("Homepage",{font:"14px Arial",fill:"#FFFFFF"}),<commit_msg>fix typos<commit_after># PIXI-CocoonText

This is a plugin for PIXI v3.0.0 and higher. It adds a new text object optimized for mobile and specifically CocoonJS. However, CocoonJS is not required.

```javascript
var foo = new PIXI.cocoontext.CocoonText("This is a text with a cache!",{font:"12px Arial"});
```

It is a modified version of the original PIXI.Text object with the following modifications:

* *Texture cache*: when you create a PIXI.Text object, PIXI needs to use an offscreen canvas to generate your text and use this canvas as a texture. While this is the only way to do it for the moment, this can be a huge performance bottleneck when you need to create multiple texts in your game. CocoonText provides you an automated cache system to make sure that if you create the same text with the same style a second time, you won't have to create a new canvas/texture. This allows you to preload your texts at the start of your application like you could do for an image or a sound.

* *CocoonJS compatibility*: the way PIXI.Text deals with text resolution is not compatible with CocoonJS v2.0. CocoonText is able to display high density texts for retina screens as long as you provide a font size with a px unit. You can set PIXI.cocoontext.CONST.TEXT_RESOLUTION to set a default resolution for all of your CocoonText objects. This can be useful if you want the best looking texts possible by setting it to the devicePixelRatio multiplied by the scale of your UI.

## Typical use case

Building a button with an "active" and "inactive" state that changes the text style with preloaded textures

```javascript
//I set the resolution of my texts to the devicePixelRatio * the scale of my stage
PIXI.cocoontext.CONST.TEXT_RESOLUTION = window.devicePixelRatio * stage.scale.x;

// While my game is loading, I generate the texts I will need later
function preloadTexts()
{
    var myTexts = [
        new PIXI.cocoontext.CocoonText("Homepage",{font:"14px Arial",fill:"#FFFFFF"}),
{'fraction_non_alphanumeric': 0.05430093884800812, 'fraction_numerical': 0.004567368688150216, 'mean_word_length': 4.334235453315291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4566821', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1052, 'n_words': 599}