Skip to content

Commit 8b2550b

Browse files
committed
preserve zero advance glyphs in latest Noto Sans Arabic
1 parent 2929482 commit 8b2550b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/layout-text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function isWsPreserved(whiteSpace: WhiteSpace) {
4343
return whiteSpace === 'pre' || whiteSpace === 'pre-wrap';
4444
}
4545

46-
function isSpaceOrTabOrNewline(c: string) {
46+
export function isSpaceOrTabOrNewline(c: string) {
4747
return c === ' ' || c === '\t' || c === '\n';
4848
}
4949

src/paint.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {BlockContainer, ReplacedBox, Inline, IfcInline} from './layout-flow.ts';
22
import {Image} from './layout-image.ts';
33
import {G_CL, G_AX, G_SZ} from './text-harfbuzz.ts';
4-
import {ShapedItem, Paragraph} from './layout-text.ts';
4+
import {ShapedItem, Paragraph, isSpaceOrTabOrNewline} from './layout-text.ts';
55
import {Box, FormattingBox} from './layout-box.ts';
66
import {binarySearchOf} from './util.ts';
77

@@ -26,12 +26,22 @@ export interface PaintBackend {
2626
}
2727

2828
function getTextOffsetsForUncollapsedGlyphs(item: ShapedItem) {
29+
const s = item.paragraph.string;
2930
const glyphs = item.glyphs;
3031
let glyphStart = 0;
3132
let glyphEnd = glyphs.length - G_SZ;
3233

33-
while (glyphStart < glyphs.length && glyphs[glyphStart + G_AX] === 0) glyphStart += G_SZ;
34-
while (glyphEnd >= 0 && glyphs[glyphEnd + G_AX] === 0) glyphEnd -= G_SZ;
34+
while (
35+
glyphStart < glyphs.length &&
36+
glyphs[glyphStart + G_AX] === 0 &&
37+
isSpaceOrTabOrNewline(s[glyphs[glyphStart + G_CL]])
38+
) glyphStart += G_SZ;
39+
40+
while (
41+
glyphEnd >= 0 &&
42+
glyphs[glyphEnd + G_AX] === 0 &&
43+
isSpaceOrTabOrNewline(s[glyphs[glyphEnd + G_CL]])
44+
) glyphEnd -= G_SZ;
3545

3646
if (glyphStart in glyphs && glyphEnd in glyphs) {
3747
let textStart, textEnd;

test/paint.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,15 @@ describe('Painting', function () {
675675
]);
676676
});
677677

678+
it('doesn\'t break clusters when trimming whitespace', function () {
679+
registerFontAsset('NotoSansArabic/NotoSansArabic-Regular.ttf');
680+
this.layout('<div style="font: 10px Noto Sans Arabic;">والمهارة</div>');
681+
expect(this.paint().getCalls()).to.deep.equal([
682+
{t: 'text', x: 0, y: 13.74, text: 'والمهارة', fillColor: '#000'}
683+
]);
684+
unregisterFontAsset('NotoSansArabic/NotoSansArabic-Regular.ttf');
685+
});
686+
678687
// TODO: would go better in a general box.spec.js
679688
describe('Pixel snapping', function () {
680689
it('snaps the border box', function () {

0 commit comments

Comments
 (0)