howardjones / network-weathermap

Network Weathermap draws diagrams from data
http://www.network-weathermap.com/
MIT License
425 stars 94 forks source link

V offset #36

Closed hawson closed 8 years ago

hawson commented 8 years ago

This small patch adds a new attribute to defined fonts, allowing for a vertical offset anywhere a TrueType font is used. The patch is against the 0.97-maintenance branch.

I have a number of links that have poor bounding boxes, and they display poorly in links, as shown in this example: screen shot 2016-07-13 at 12 44 42 pm

However, with the patch, and adding a small offset, it looks much better, and works on angled text: screen shot 2016-07-13 at 12 49 15 pm screen shot 2016-07-13 at 3 55 22 pm

Note that this can be (ab)used to allow for BWLABELs that are rendered above or below the link line, instead directly on top of it...similar to how BWLABELPOS can move the label to the left and right. A quick example that shows the BWLABEL text rendered just "below" it's link: screen shot 2016-07-13 at 12 54 55 pm.

In the configuration file, the offset is noted as a new, optional, element to FONTDEFINE. To create the 2nd image (with less overhead whitespace): FONTDEFINE 200 docs/example/Vera 8 6

Positive values move the text "up", while negative values move the text "down" (in the X,Y plane).

The 3rd image uses an offset in the other direction, plus a using existing BW* options:

FONTDEFINE 200 docs/example/Vera 8 -16
BWBOXCOLOR none
BWOUTLINECOLOR none

Unfortunately, the offset will depend entirely on the font used. An offset of 6 looks good for this font (Bitstream Vera Sans 8pt), but other fonts have different baselines, and will need different values. It also depends on the size of the font: a pt size of 12 needs a different offset than a pt size of 8, for example.

howardjones commented 8 years ago

Awesome. Thanks! And for the 5.3 tweak also. I've got to get Vagrant or TravisCI or something working better for catching those kinds of things... there's lots of testing for the map generation now, but not so much for the user-facing parts, and not across multiple platforms or php versions.