@etpinard/gl-text

中文文档
1.1.6发布于 2018/07/06MITCommonJS近 30 天下载 2107

Render text with WebGL

原始使用文档
文档目录8 节
  1. Usage
  2. API
  3. let text = new Text(gl|regl|canvas|container|options?)
  4. text.update(options)
  5. text.render()
  6. text.destroy()
  7. Properties
  8. License

gl-text unstable

Render bitmap text with WebGL.

Usage

npm install gl-text

const Text = require('gl-text')

let text1 = new Text()

text1.update({
    position: [50, 50],
    text: 'ABC',
    font: '16px Helvetica, sans-serif'
})
text1.render()

// create another text renderer on the same context
let text2 = new Text(text1.gl)
text2.update({
    font: {
        family: ['Helvetica', 'Arial', 'sans-serif'],
        size: '1rem'
    }
})

API

let text = new Text(gl|regl|canvas|container|options?)

Create text renderer instance for the WebGL context gl, regl instance, canvas/container element or based on options:

OptionMeaning
reglExisting regl instance. By default new one is created.
gl/contextExisting WebGL context. By default new one is created.
canvasExisting canvas element.
containerExisting container element. By default new canvas is created within the container.

No arguments call creates new fullscreen canvas.

text.update(options)

Update state of a Text instance.

OptionDescription
textText string or array of strings to display.
positionPosition of the text on the screen within the range, a couple [x, y] or array [[x ,y], [x, y], ...] corresponding to text.
alignHorizontal alignment relative to the position. Can be one of left, right, center/middle, start, end, or a number of em units. By default left. Can be an array, corresponding to text.
baselineVertical alignment value, by default middle. Can be a string one of top, hanging, middle, alphabetic, ideographic, bottom etc. (see font-measure) or a number of em units, denoting 0 as alphabetic baseline. Can be an array corresponding to text.
colorText color or array of colors. By default black.
fontFont family, CSS font string or an object with font properties like {family, size, style}, see css-font. Can be an array.
fontSize/emFont-size, can be changed independently of font.
kerningEnable font kerning, by default true. Disable for the case of monospace fonts. See detect-kerning package.
offsetShift position by the number of ems. Useful for organizing multiple lines, indentation, sub/sup script etc. Does not get affected by position change. Can be a number for x-offset only or a couple [x, y] for single position or array [[x, y], [x, y], ...] for multiple positions.
rangeData area corresponding to position in viewport. Useful for organizing zoom/pan. By default is the same as the viewport [0, 0, canvas.width, canvas.height].
scale/translateAn alternative to range.
viewportVisible area within the canvas, an array [left, top, width, height] or rectangle {x, y, width, height}, see parse-rect.

text.render()

Draw text.

text.destroy()

Dispose text renderer.

Properties

  • text.gl - WebGL context.
  • text.canvas - canvas element.
  • text.regl - regl instance.

License

© 2018 Dmitry Yv. MIT License

Development supported by plot.ly.

版本与发布记录

@etpinard/gl-text 共发布 1 个版本,首次发布于 2018/07/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.6latest2018/07/068 年前

关于 @etpinard/gl-text 的常见问题

@etpinard/gl-text 是什么?

Render text with WebGL

如何安装 @etpinard/gl-text?

在项目目录运行 npm install @etpinard/gl-text,或使用 pnpm add / yarn add / bun add。

@etpinard/gl-text 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/etpinard__gl-text 是否存在。

@etpinard/gl-text 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@etpinard/gl-text 可以商用吗?

@etpinard/gl-text 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@etpinard/gl-text 的下载量有多少?

根据 npm 官方下载统计,@etpinard/gl-text 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,107 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@etpinard/gl-text 还在维护吗?

最新版本 1.1.6 发布于 2018/07/06(8 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/07/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。