-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bestFit breakpoint issue (#1567)
Co-authored-by: Dmitry Ivakhnenko <jeetiss@yandex.ru>
- Loading branch information
1 parent
46a4b0c
commit 5d2d688
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@react-pdf/textkit': patch | ||
--- | ||
|
||
fixed line breaks for the case when the word in a text is bigger than the given width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/textkit/tests/engines/linebreaker/bestFit.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import applyBestFit from '../../../src/engines/linebreaker/bestFit'; | ||
|
||
const width = 50; | ||
|
||
describe('bestFit', () => { | ||
test('should return at least one breakpoint', () => { | ||
const node = [ | ||
{ | ||
type: 'box', | ||
width: 25, | ||
}, | ||
{ | ||
type: 'glue', | ||
width: 0, | ||
stretch: 10000, | ||
shrink: 0, | ||
}, | ||
{ | ||
type: 'penalty', | ||
width: 0, | ||
penalty: -10000, | ||
}, | ||
]; | ||
|
||
const breakpoints = applyBestFit(node, [width]); | ||
expect(breakpoints.length).toBe(1); | ||
}); | ||
|
||
test('should break lines when the subnode is bigger than the given widths', () => { | ||
const node = [ | ||
{ | ||
type: 'box', | ||
width: 55, | ||
}, | ||
{ | ||
type: 'glue', | ||
width: 5, | ||
stretch: 1, | ||
shrink: 1, | ||
}, | ||
{ | ||
type: 'box', | ||
width: 55, | ||
}, | ||
{ | ||
type: 'glue', | ||
width: 5, | ||
stretch: 1, | ||
shrink: 1, | ||
}, | ||
{ | ||
type: 'box', | ||
width: 25, | ||
}, | ||
{ | ||
type: 'glue', | ||
width: 0, | ||
stretch: 10000, | ||
shrink: 0, | ||
}, | ||
{ | ||
type: 'penalty', | ||
width: 0, | ||
penalty: -10000, | ||
}, | ||
]; | ||
|
||
const breakpoints = applyBestFit(node, [width]); | ||
|
||
expect(breakpoints.length).toBe(3); | ||
}); | ||
}); |