Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces show up as blocks #33

Open
RossComputerGuy opened this issue Nov 7, 2018 · 1 comment
Open

Spaces show up as blocks #33

RossComputerGuy opened this issue Nov 7, 2018 · 1 comment

Comments

@RossComputerGuy
Copy link

RossComputerGuy commented Nov 7, 2018

Whenever a space character is rendered, it shows up as a block. I've tried lots of different fonts and I don't think it has to do with the fonts. The 2d context is causing this. Can we please have this fixed?

@sidorares
Copy link
Owner

Sure, I'll have a look.
A bit of documentation on how text is rendered with ntk

when you call .fillText it splits string into glyphs and calls

var ff = this._glyphSet.fontface;
var glyphs = String.fromCharCode.apply(null, text.split('').map( function(c) { return ff.charcode2glyph[c.charCodeAt(0)] }));
Render.CompositeGlyphs32(3, this._backgroundPicture.id, this.picture.id, 0, this._glyphSet.id, 0, 0, [ [x, y, glyphs ] ] );

( "split into glyphs" is actually much difficult task in real life and would require harfbuzz library to du correctly, but for Latin scripts it mostly works juts by treating characters as glyphs )

When you specify font via something like `ctx.font = "Courier 10pt" this code is used:

RC._setFont = function(weight, style, size, unit, family) {
var fc = require('./fontconfig.js');
var pattern = {
family: family,
style: style,
weight: weight
};
var match = fc.listFontsSync(pattern);
var face = new FontFace(this.window.app);
face.loadFont(match.path);
if (!_fonts[family])
_fonts[family] = {};
_fonts[family][weight + '-' + style] = face;
this._setFace(face, size);
};
RC.addFont = function(font) {
this._fonts = this._fonts || {};
if (this._fonts[font.name]) return;
this._fonts[font.name] = font;
};
RC.__defineSetter__('font', function(val) {
if (!val) return;
if ('string' == typeof val) {
var font;
if (font = parseFontStyle(val)) {
this._lastFontString = val;
if (_fonts && _fonts[font.family]) {
var fontObj = _fonts[font.family];
var type = font.weight + '-' + font.style;
var fontFace = fontObj[type];
if (fontFace)
return this._setFace(fontFace, font.size);
}
this._setFont(
font.weight
, font.style
, font.size
, font.unit
, font.family);
}
}
});

  • font file is located using font matcher library
  • file is loaded using truetype2 moduly
  • glyphset is created and each rendered glyph is uploaded to the server ( I'd like to change this part so that glyphs are uploaded lazily only at the point you use them, not the whole font upfront )

"Spaces show up as blocks" problem is likely located somewhere in last two steps ^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants