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

fix incorrect text width with newer (1.43?) Pango #2184

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Added
### Fixed
* Add missing property `canvas` to the `CanvasRenderingContext2D` type
* Fixed glyph positions getting rounded, resulting text having a slight `letter-spacing` effect

2.11.0
==================
Expand Down
7 changes: 7 additions & 0 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ Context2d::Context2d(Canvas *canvas) {
_canvas = canvas;
_context = canvas->createCairoContext();
_layout = pango_cairo_create_layout(_context);

// As of January 2023, Pango rounds glyph positions which renders text wider
// or narrower than the browser. See #2184 for more information
#if PANGO_VERSION_CHECK(1, 44, 0)
pango_context_set_round_glyph_positions(pango_layout_get_context(_layout), FALSE);
#endif

states.emplace();
state = &states.top();
pango_layout_set_font_description(_layout, state->fontDescription);
Expand Down
5 changes: 5 additions & 0 deletions test/public/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,11 @@ tests['measureText()'] = function (ctx) {
drawWithBBox('right', 195, 195)
}

tests['glyph advances (#2184)'] = function (ctx) {
ctx.font = '8px Arial'
ctx.fillText('A float is a box that is shifted to the left or right on the current line.', 0, 8)
}

tests['image sampling (#1084)'] = function (ctx, done) {
let loaded1, loaded2
const img1 = new Image()
Expand Down