mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Allow zero image coordinates - fixes #25
This commit is contained in:
parent
1812f90281
commit
753e41462b
@ -5,13 +5,13 @@ module.exports =
|
||||
@_imageRegistry = {}
|
||||
@_imageCount = 0
|
||||
|
||||
image: (src, x, y, options) ->
|
||||
image: (src, x, y, options = {}) ->
|
||||
if typeof x is 'object'
|
||||
options = x
|
||||
x = null
|
||||
|
||||
x = x or options?.x or @x
|
||||
y = y or options?.y or @y
|
||||
x = x ? options.x ? @x
|
||||
y = y ? options.y ? @y
|
||||
|
||||
if @_imageRegistry[src]
|
||||
[image, obj, label] = @_imageRegistry[src]
|
||||
@ -22,34 +22,33 @@ module.exports =
|
||||
label = "I" + (++@_imageCount)
|
||||
@_imageRegistry[src] = [image, obj, label]
|
||||
|
||||
w = options?.width or image.width
|
||||
h = options?.height or image.height
|
||||
w = options.width or image.width
|
||||
h = options.height or image.height
|
||||
|
||||
if options
|
||||
if options.width and not options.height
|
||||
wp = w / image.width
|
||||
w = image.width * wp
|
||||
h = image.height * wp
|
||||
if options.width and not options.height
|
||||
wp = w / image.width
|
||||
w = image.width * wp
|
||||
h = image.height * wp
|
||||
|
||||
else if options.height and not options.width
|
||||
hp = h / image.height
|
||||
w = image.width * hp
|
||||
h = image.height * hp
|
||||
else if options.height and not options.width
|
||||
hp = h / image.height
|
||||
w = image.width * hp
|
||||
h = image.height * hp
|
||||
|
||||
else if options.scale
|
||||
w = image.width * options.scale
|
||||
h = image.height * options.scale
|
||||
else if options.scale
|
||||
w = image.width * options.scale
|
||||
h = image.height * options.scale
|
||||
|
||||
else if options.fit
|
||||
[bw, bh] = options.fit
|
||||
bp = bw / bh
|
||||
ip = image.width / image.height
|
||||
if ip > bp
|
||||
w = bw
|
||||
h = bw / ip
|
||||
else
|
||||
h = bh
|
||||
w = bh * ip
|
||||
else if options.fit
|
||||
[bw, bh] = options.fit
|
||||
bp = bw / bh
|
||||
ip = image.width / image.height
|
||||
if ip > bp
|
||||
w = bw
|
||||
h = bw / ip
|
||||
else
|
||||
h = bh
|
||||
w = bh * ip
|
||||
|
||||
# Set the current y position to below the image if it is in the document flow
|
||||
@y += h if @y is y
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user