Add support for structured content margins (#1920)

This commit is contained in:
toasted-nutbread 2021-08-31 21:08:30 -04:00 committed by GitHub
parent ce1a862df4
commit 02194fcb9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View File

@ -215,6 +215,22 @@
"type": "string", "type": "string",
"enum": ["baseline", "sub", "super", "text-top", "text-bottom", "middle", "top", "bottom"], "enum": ["baseline", "sub", "super", "text-top", "text-bottom", "middle", "top", "bottom"],
"default": "baseline" "default": "baseline"
},
"marginTop": {
"type": "number",
"default": 0
},
"marginLeft": {
"type": "number",
"default": 0
},
"marginRight": {
"type": "number",
"default": 0
},
"marginBottom": {
"type": "number",
"default": 0
} }
} }
} }

View File

@ -216,7 +216,17 @@ class StructuredContentGenerator {
_setStructuredContentElementStyle(node, contentStyle) { _setStructuredContentElementStyle(node, contentStyle) {
const {style} = node; const {style} = node;
const {fontStyle, fontWeight, fontSize, textDecorationLine, verticalAlign} = contentStyle; const {
fontStyle,
fontWeight,
fontSize,
textDecorationLine,
verticalAlign,
marginTop,
marginLeft,
marginRight,
marginBottom
} = contentStyle;
if (typeof fontStyle === 'string') { style.fontStyle = fontStyle; } if (typeof fontStyle === 'string') { style.fontStyle = fontStyle; }
if (typeof fontWeight === 'string') { style.fontWeight = fontWeight; } if (typeof fontWeight === 'string') { style.fontWeight = fontWeight; }
if (typeof fontSize === 'string') { style.fontSize = fontSize; } if (typeof fontSize === 'string') { style.fontSize = fontSize; }
@ -226,5 +236,9 @@ class StructuredContentGenerator {
} else if (Array.isArray(textDecorationLine)) { } else if (Array.isArray(textDecorationLine)) {
style.textDecoration = textDecorationLine.join(' '); style.textDecoration = textDecorationLine.join(' ');
} }
if (typeof marginTop === 'number') { style.marginTop = `${marginTop}em`; }
if (typeof marginLeft === 'number') { style.marginLeft = `${marginLeft}em`; }
if (typeof marginRight === 'number') { style.marginRight = `${marginRight}em`; }
if (typeof marginBottom === 'number') { style.marginBottom = `${marginBottom}em`; }
} }
} }

View File

@ -148,6 +148,22 @@
]} ]}
]} ]}
]} ]}
]},
{"type": "structured-content", "content": [
"margin",
{
"tag": "div",
"style": {
"marginTop": 1,
"marginLeft": 1,
"marginRight": 1,
"marginBottom": 1
},
"content": [
"inner"
]
},
"margin"
]} ]}
], ],
100, "P E1" 100, "P E1"