1

Using VIPS, how to reduce the space between lines in a text? There is an optional parameter for vips.Image.text() called spacing that determines this space between lines. However, I can make spacing larger but not smaller. E.g., in the code below (using the Lua binding for VIPS, lua-vips), passing 0 as the argument for spacing...

local vips = require 'vips'
local t = vips.Image.text("This is a\nrandom test.", {
  spacing = 0
})
t:write_to_file("test.png")

produces the following output:

Test with 0 spacing

As expected, using greater values makes spacing larger, so maybe using negative values would make spacing smaller. However, what happens is that the lib gives me a warning:

(lua-vips:17404): GLib-GObject-WARNING **: value "-1" of type 'gint' is invalid or out of range for property 'spacing' of type 'gint'

I know VIPS uses Pango to work with text, so I'm not sure if perhaps this is something that VIPS does not yet support, or something that Pango does not yet support.

PiFace
  • 526
  • 3
  • 19

1 Answers1

2

It looks like pango does not support spacing < 0:

https://developer.gnome.org/pango/stable/pango-Layout-Objects.html#pango-layout-set-line-spacing

https://developer.gnome.org/pango/stable/pango-Layout-Objects.html#pango-layout-set-spacing

So I think you might be out of luck. You could render lines separately and then position them yourself, I suppose.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • Oh, that's unfortunate. That workaround would be nice, but I would like to reduce spacing in lines of text generated by a width limit as well, not necessarily by newline characters. So I wonder if this approach would still be possible – PiFace Jan 05 '20 at 18:18
  • I think you'd have to do line breaks too then, sorry. Render a word at a time and assemble the chunks with libvips `insert`. Or perhaps patch pango? I wouldn't think it would be too hard. – jcupitt Jan 05 '20 at 18:31
  • Sorry, thinking out loud, you could also modify an existing font and shrink the vertical metrics. That might be simpler. – jcupitt Jan 05 '20 at 18:34
  • Oh, that's true, editing the font itself would do all the work! Since it's a small detail for my application, I guess that should do it. – PiFace Jan 05 '20 at 19:12