Text parts in the library have bounding boxes that are way too long #3630
Description
Current Behaviour
Text parts in all views tend to take up way more room (per their bounding box) than the actual rendered text content. Some testing shows that the width is being calculated as if a fixed width font was being used. Specifically, every character is being assumed to take up the same space as an em dash
character. The Droid Sans font used with the text part has proportional character spacing.
When the text is placed near the edges of the view content, any exported image includes the empty space at the ends of the text element, causing image extents to expand for no visible reason.
Using the ruler tool shows that the bounding box extent matches what Inspector reports, but the visual rendered content is a little, to a lot, shorter unless the content is all em dash
(— == U+2014) characters.
This is important (to me), because I export fritzing images to be included in other documents. I get much better results if I do not need to do post processing of the images. Cropping SVG images is not as simple as cropping bit map files.
.fzz and all exported svg files renamed to append .zip to the name. Just rename again to remove the .zip to be able to use.
Reference breadboard export
bare_lcd-bb.svg.zip
hello world breadboard export
hello_world_lcd-bb.svg.zip
Reference schematic export
bare_lcd-sch.svg.zip
2 line schematic export
2_line_lcd-sch.svg.zip
Reference pcb export
bare_lcd-pcb.svg.zip
connection pins pcb export
connection_pins_lcd-pcb.svg.zip
Build:
<e.g. Version 0.9.3 (b5c895d32 2016-04-19) Cocoa [Qt 5.12.2]
app/org.fritzing.Fritzing/x86_64/stable
Version: 0.9.4b
Commit: c595162a1d06f01eab9b66092c7ca68518974b9887295cd59950c439bfba3a72
Operating System:
% cat /etc/os-release
NAME=Fedora
VERSION="31 (Workstation Edition)"
ID=fedora
VERSION_ID=31
VERSION_CODENAME=""
PLATFORM_ID="platform:f31"
PRETTY_NAME="Fedora 31 (Workstation Edition)"
ANSI_COLOR="0;34"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:31"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f31/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=31
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=31
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Workstation Edition"
VARIANT_ID=workstation
Steps to reproduce:
- in a new sketch, in the breadboard view, delete the breadboard and place and place an LCD display.
- on the pcb vew, reduce the size of the board so that it does not affect export boundaries.
- export all three views to get reference images
- place a text element in the breadboard view: "HELLO BIG WORLD!"; set width to 104.6mm; position to approximately line up with LCD text row;
- place a text element in the schematic view, "A two line display"; leave default width of 45.7mm; position along bottom of LCD1 part, rendered text aligned to left edge of connection pins
- place a text element in the pcb view, "The connection pins for the LCD"; leave default width of 78.7mm; position below connection pads, rendered text aligned to the left edge of the LCD1 part.
- export svg images of all views, and compare to the reference images. Full screen sometimes shows the shifted content better.
- place a new text element in the breadboard view with 16 em dash characters "————————————————"; set width to 60.3; position over a row of the LCD display.
- use rulers to measure things, though simply selecting, or hovering over, the text elements shows the empty leading and trailing white space.
Expected Behaviour
The bounding box should (fairly closely) match the rendered content. There are better ways to calculate text length than multiplying by the size of an em dash. Since Fritzing is using SVG images, the getComputedTextLength method should do the right thing. Assuming it is implemented in the underlying tools being used.
Even changing the text to left align would help in my (general) case. It is easier to trim blank content from the right of an svg image. Just reduce the svg element width attribute (and viewBox). Which of course would not help if the text was rotated.