npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexr-txtr

v1.0.0

Published

WebGL text utility. uses canvas"

Downloads

3

Readme

Hexr Txtr

Hexr Text Utility. Uses Canvas API to write directly to a texture map. It's intended, primarily, for in game captions and speech bubbles etc. Key features:

  • Uses a power of 2 texture for full filtering options
  • COnfigurable blending mode for the material
  • word wrapping with configurable width and maximum number of lines per 'page'
  • divides the available space in the raw texture map into 'pages' which can be owned by... things.
  • Each page has its own mesh with the proper UV co-ords.
  • mesh is dynamically sized to the height and width of the current text on that 'page'
  • uses THREE.PlaneBufferGeometry

I'll just show the API.

var hexrTxtr = require('hexr-txtr')(config);

The default config, btw, looks like this:

var defaultConfig = {
    fontSizePx : 20, // 
    maxLines : 5,
    lineWidthRatio : 20,
    blend : THREE.NormalBlending,
    minFilter : THREE.LinearFilter,
    magFilter: THREE.LinearFilter
};

There's no clever merging of the defaults implemented yet, so if you're going to override the defaults you need to override the lot.

About that configuration:

fontSizePx

Canvas uses this for the font height. It is also the canonical height of each line. (and yes, this causes a problem with fonts that draw above/below)

The larger the font size, the more detailed the texture (allowing you to scale it more) but the mesh that is generated will still be 1 THREE.JS Unit per line.

maxLines

Hexr Txtr will wrap strings to a specified maximum number of lines. This defines the maximum height of a page. The more lines, the fewer pages you will be able to get from a single Hexr Txtr instance.

lineWidthRatio

Okay so if your font height is 20px and your lineWidthRatio is 20 then that means the width of a line is 20 * 20 or 400px. This is kept as a ratio so that you can tinker with the font

Bear in mind that the width of the raw texture map is rounded up to the nearest power of two, so if you're using very large fonts with very large ratios you could be generating ENORMOUS texture maps which will probably seriously hurt your performance.

blend

Set the THREE constant for the blend mode of the material. Normal blending is good if you want black on white. Additive blending is good for opaque background and white writing.

minFilter

magFilter

You can set the exact texture filters you want here.

Hexr Txtr API

hexrTxtr.getMaxPages()

Gets the number of available pages for this instance.

hexrTxt.getPage(pageIndex)

Pages are zero indexed, so the first page is always zero.

Hexr Txtr Page API

page.mesh

A reference to the page's mesh. Yours to do with what you will.

page.setBackgroundColour(cssHexString)

Set the background colour for the page

page.setTextColour(cssHexString)

Set the text colour for the page

page.setAlignment(left|center|right)

You can only control the horizontal alignment, but this is how you do that.

page.setFont(fontname)

Every page can use its own font as well.

It's up to you to make sure that the font you're using is available to the browser. You have to use the font in a normal HTML element with normal CSS styles otherwise some browsers won't bother to download it.

page.write(string)

Set the current text of the page. You can force a line break with \n, btw. This function returns an object with a width and height property. You can use this to position the text mesh correctly or add some sort of border to it.

License

MIT

Contributing

Yes please.