-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bugfix: Handle TypedArrays and Buffers in deep-merge/clone #1744
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
base: master
Are you sure you want to change the base?
Changes from all commits
6d0ceb8
4fdaf60
505b44b
3052cee
f5ccc92
05f624a
fbc34f1
d724450
731a4c1
4b84c30
84cb1a1
283e00b
b8ca3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -58,8 +58,17 @@ export function normalizedRowStyle(defaultRowStyle, rowStyleInternal, i) { | |||
| rowStyle.borderColor = normalizeSides(rowStyle.borderColor); | ||||
| rowStyle.align = normalizeAlignment(rowStyle.align); | ||||
|
|
||||
| // extract fonts | ||||
| const { font: defaultFont, ...restDefaultStyle } = defaultRowStyle || {}; | ||||
| const { font: font, ...restStyle } = rowStyle || {}; | ||||
| const mergedFont = { | ||||
| ...((font?.src && font) || (defaultFont?.src && defaultFont)), | ||||
| size: font?.size || defaultFont?.size, | ||||
| }; | ||||
|
|
||||
| // Merge defaults | ||||
| rowStyle = deepMerge(defaultRowStyle, rowStyle); | ||||
| rowStyle = deepMerge(restDefaultStyle, restStyle); | ||||
| rowStyle.font = mergedFont; | ||||
|
|
||||
| const document = this.document; | ||||
| const page = document.page; | ||||
|
|
@@ -114,8 +123,17 @@ export function normalizedColumnStyle(defaultColStyle, colStyleInternal, i) { | |||
| colStyle.borderColor = normalizeSides(colStyle.borderColor); | ||||
| colStyle.align = normalizeAlignment(colStyle.align); | ||||
|
|
||||
| // extract fonts | ||||
| const { font: defaultFont, ...restDefaultStyle } = defaultColStyle || {}; | ||||
| const { font: font, ...restStyle } = colStyle || {}; | ||||
| const mergedFont = { | ||||
| ...((font?.src && font) || (defaultFont?.src && defaultFont)), | ||||
| size: font?.size || defaultFont?.size, | ||||
| }; | ||||
|
Comment on lines
+126
to
+132
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that deepMerge was modified to handle binary data, why not use it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just found a bug where merging fonts with font collections would cause problem doc.table({
rowStyles: [{
font: { src: SOME_TTC_FONT, family: FONT_FAMILY },
}]
})
.row([
{ text: 'Hello World', font: { src: SOME_TTF_FONT } }
]);
// throws `Variations require a font with the fvar, gvar and glyf, or CFF2 tables`I think font src should be binded with its family and not be merged with other family names across styles
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another bug, independent of table, just using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bug is caused by style merging in tables propagating font families to other font options. Other than tables the same error seems only be thrown on user errors when they put unsupported families in font options. Manually assigning font properties and avoiding
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the changes ignores font: {size} This is a rabbit hole @hollandjake how about we keep with the following font cell | row | col def: font: string |buffer We kill most of the complexity and AFAIK still pretty flexible
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is internal doc. Never publicized In the final shape of this PR it introduces complexity not only in code, but in usage reasoning / documentation (must explain that font.family will not merge like other properties - is ignored without src). In fact it breaks a valid use case: defaultStyle: {font.src: 'fontCollection'} cell1.font.family: 'family1' IMO we should either treat font as an atomic setting or we embrace fully the current merging approach ( changing the type or not)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This definitely sounds complex to handle inline. May actually need a dedicated utility function to merge fonts properly without making a mess /**
* Merge font definitions. Front takes precedence
* @param {Font[]} fonts
* @returns {Font} merged font
*/
export function mergeFonts(...fonts) {
const mergedFont = {};
for (const font of fonts) {
if (!mergedFont.size) {
mergedFont.size = font?.size;
}
// ignore font src / family once src is found
if (!mergedFont.src){
// take the first defined family
if (!mergedFont.family){
mergedFont.family = font?.family;
}
if (font?.src) {
mergedFont.src = font.src;
}
}
// return when font src & size are both defined
if (mergedFont.src && mergedFont.size){
return mergedFont;
}
}
return mergedFont;
}
// const mergedFont = fontMerge(cell.font, rowStyle.font, colStyle.font)edited for cleaner branches
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agree that the font merging behaviour should be defined especially for partial options. If we choose the full merging approach while accounting the case in #1744 (comment), the cascading logic would need to work like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW seems that Line 96 in 0036303
Is this intentional?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, thats because the defaults get populated during the normalisation stuff |
||||
|
|
||||
| // Merge defaults | ||||
| colStyle = deepMerge(defaultColStyle, colStyle); | ||||
| colStyle = deepMerge(restDefaultStyle, restStyle); | ||||
| colStyle.font = mergedFont; | ||||
|
|
||||
| if (colStyle.width == null || colStyle.width === '*') { | ||||
| colStyle.width = '*'; | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the logic of merging
If you have a font: {size: 16} in row will be ignored with this last change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now i see the size. Forgive me