Giter Site home page Giter Site logo

tomchen / bdfparser-js Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 2.0 2.46 MB

BDF (Glyph Bitmap Distribution) format bitmap font file parser library in TypeScript (JavaScript) ๐Ÿ”ฃ๐Ÿ“œ

Home Page: https://font.tomchen.org/bdfparser_js/

License: MIT License

JavaScript 1.56% TypeScript 98.24% Shell 0.21%
font parser bitmap-font bitmap-fonts bdf-format bdf bdf-font bdf-fonts bitmap node

bdfparser-js's People

Contributors

tomchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bdfparser-js's Issues

Avoiding anti-aliasing when rendering bitmap fonts on a canvas

Dear Tom
First of all, thank you very much for this library; it is already of great use to me.
I am reaching out to you because I am currently struggling with rendering a small (5x7) BDF font on a canvas: The font is hard to read due to anti-aliasing effects (see screenshot below). Do you have any experience with this, or do you know how to get a pixel-perfect bitmap rendering? I already tried to disable canvasContext.imageSmoothingEnabled without any luck.
2022-02-28_19-19

Background: I want to render the website on a low-resolution LED matrix.

Thank you very much for any ideas.
Cheers and have a nice day, remolueoend

Recommended way to position drawing within canvas?

What is the recommended way to change the position where the bitmap is drawn on the canvas using draw2canvas()? I noticed that x and y are hardcoded to start at 0 in the function definition (below) and using context.moveTo() does not seem to have any effect.

bdfparser-js/src/bdfparser.ts

Lines 1796 to 1829 in 71a4ee3

/**
* Draw the bitmap to HTML canvas
*
* @param context - Canvas 2D context (`canvas.getContext("2d")`)
* @param pixelcolors - Object mapping `'0'`/`'1'`/`'2'` in the bitmap data to color
*
* @returns The `Bitmap` object itself
*
* @see online docs: {@link https://font.tomchen.org/bdfparser_js/bitmap#draw2canvas}
*/
draw2canvas(
context: CanvasContext,
pixelcolors?: Record<'0' | '1' | '2', string | null> | null
): this {
const _pixelcolors = pixelcolors ?? {
'0': null,
'1': 'black',
'2': 'red',
}
this.todata(2).forEach((line, y) => {
line.forEach((pixel, x) => {
const s = pixel.toString()
if (s === '0' || s === '1' || s === '2') {
const color = _pixelcolors[s]
if (color !== null && color !== undefined) {
context.fillStyle = color
context.fillRect(x, y, 1, 1)
}
}
})
})
return this
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.