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

Force RTL characters to left-alignment #27

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function TinySDF(fontSize, buffer, radius, cutoff, fontFamily, fontWeight) {
this.ctx = this.canvas.getContext('2d');
this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily;
this.ctx.textBaseline = 'middle';
this.ctx.textAlign = 'left'; // Necessary so that RTL text doesn't have different alignment
this.ctx.fillStyle = 'black';

// temporary arrays for the distance transform
Expand Down Expand Up @@ -95,10 +96,8 @@ TinySDF.prototype._draw = function (char, getMetrics) {

// If the glyph overflows the canvas size, it will be clipped at the
// bottom/right
// Math.abs is necessary because characters from an RTL script will be
// laid out in the opposite direction
glyphWidth = Math.min(this.size,
Math.ceil(Math.abs(textMetrics.actualBoundingBoxRight - textMetrics.actualBoundingBoxLeft)));
Math.ceil(textMetrics.actualBoundingBoxRight - textMetrics.actualBoundingBoxLeft));
glyphHeight = Math.min(this.size - imgTop,
Math.ceil(textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent));

Expand Down