Skip to content

Commit e121f78

Browse files
committed
fix(resolvers): simple text in position cases
1 parent 38597fe commit e121f78

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

demo/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pdfeasy.add([
1111
{ raw: 'A simple pdf', text: { font: 'Roboto' }},
1212
{ lineBreak: {} },
1313
{ raw: 'using...', text: {}, position: { x: 250, y: 0 } },
14-
{ raw: 'hm...' },
14+
{ raw: 'https://i.imgur.com/myEASIr.png', image: {} },
1515
'aaaaa...',
1616
{ pageBreak: {} },
1717
{ raw: 'pdfeasy!', text: {} },

packages/core/src/resolvers.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,22 @@ export const resolveContent = async (
5151
globals: InternalGlobals,
5252
run: RunOptionsBase
5353
) => {
54+
const possibleLastPos = globals.__LAST_POSITION__
55+
56+
let position =
57+
typeof content !== 'string' && content?.position
58+
? { x: app.x + content.position.x, y: app.y + content.position.y }
59+
: { x: app.x, y: app.y }
60+
61+
if (possibleLastPos) {
62+
position.x -= possibleLastPos.x
63+
position.y -= possibleLastPos.y
64+
65+
globals.__LAST_POSITION__ = null
66+
}
67+
5468
const addOnlyStringText = async (str: string) => {
55-
await app.text(str, {
69+
await app.text(str, position.x, position.y, {
5670
indent: defaults.text.indent,
5771
align: defaults.text.align,
5872
paragraphGap: defaults.text.paragraphMargin,
@@ -68,17 +82,6 @@ export const resolveContent = async (
6882
return
6983
}
7084

71-
const possibleLastPos = globals.__LAST_POSITION__
72-
73-
let position = content?.position
74-
? { x: app.x + content.position.x, y: app.y + content.position.y }
75-
: { x: app.x, y: app.y }
76-
77-
if (possibleLastPos) {
78-
position.x -= possibleLastPos.x
79-
position.y -= possibleLastPos.y
80-
}
81-
8285
const addStack = async () => {
8386
const stack = content.stack as Content[]
8487

0 commit comments

Comments
 (0)