Inkscape for cartography: fill the background of a text

I want to produce a geographic map with Inkscape. I have cities with names. I mean I have dozens of city names. I want to fill the background of cities names with a semi transparent background so that texts are readable over colors and lines etc. on the map.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Since there is no background attribute in a text object in SVG, you’d need to use another method, such as drawing a filled rectangle under the text, however as you say that’s inconvenient as you’d have to resize the rectangle every time you type a name that’s shorter or longer.

One method is to use an SVG filter applied to some text to create a box around the text which you can then fill. In this example, I used the Cutout Glow filter, and modified the settings of the filter using the Filter Editor.

Here are the steps for setting it up.

  1. Type some text, and make sure the text object is selected
  2. Click Filters > Shadows and Glows > Cutout Glow Filter
  3. Click Filters > Filter Editor and change the settings as follows:

Offset: Set Delta X and Y to -100

Gaussian Blur: 0.01 (this is the lowest possible setting)

Flood: select any colour and opacity as required

Composite – Operator: Destination over

You can also adjust the positioning of the text within and the size of the box by going back into the Offset settings, and click on the Filter General Settings tab, where you can change the Co-ordinates and Dimensions as required.

To use it on your map, copy (Ctrl+C) the filtered text object and paste (Ctrl+V) where every city should be, and then simply edit the text for each. The box will fit to the text automatically.

enter image description here

Note: You can change the text colour itself as you normally would by highlighting the text with the text tool, and changing the fill colour of the text object in the Fill and Stroke panel.

Method 2

I had the same issue that Tom brought up in the comments under Billy Kerr’s answer, which led me to find a different solution…

I found that using the Fill Background filter worked much better to add an opaque box behind text.

Do the following:

  1. Select Filters>Fill and Transparency>Fill Background
  2. Open the Filter Editor using Filters>Filter Editor
  3. Click on the “Fill Background” filter in the Filter Editor
  4. Change the Effect Parameters – Pick a Flood Color that I want for the background and change the desired Opacity level
  5. Select Filter General Settings – change the Coordinates & Dimensions to determine the size of the box that I want around the text.

The easy way to add this to all text of interest is to click on all the text boxes that you want to add the background to and then just turn on the “Fill Background” filter under the Filter Editor toolbar.

Another option is adding an outline color around the text to increase readability. Normally I like to add a white background around black text. This makes the text readable but doesn’t cause it to obscure so much of the background, especially useful if the text is multiple lines. To do this you can do the following:

  1. Open the Fill and Stroke toolbox by selecting the text object and then clicking Object > Fill and Stroke…
  2. Click “Stroke paint” under the Fill and Stroke toolbar
  3. Select Flat Color to add a stroke to the text
  4. Choose the outline color that you want, set the desired Opacity
  5. Click Stroke style under the Fill and Stroke Toolbar
  6. Under the Order option, select the top middle option (Stroke, Fill, Markers).
  7. Change the desired width of the outline around the text by changing the size of the Width parameter.

Here’s a link to a video showing how to do this.

enter image description here

Method 3

You can draw a rectangle with your semi-transparent fill color. Then you select the text plus the rectangle, and go to Text -> Flow into frame (Alt-W).

This will place your text inside the rectangle (or whatever shape you like).

Manual here.

Method 4

This is a good start, but works better if you disable all except Flood and Composite. Composite->Filter General Settings will adjust the location and size of the box in relation to the text. Composite->Effect Parameters set to Destination Over will ensure your text color isn’t messed with by the background color you choose.

This is great and all, but totally fails if you need to rotate the text.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x