fritzing / fritzing-app

Fritzing desktop application
http://fritzing.org
Other
4k stars 827 forks source link

Text parts in the library have bounding boxes that are way too long #3630

Open mMerlin opened 4 years ago

mMerlin commented 4 years ago

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.

hello_world_lcd-bb

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:

text_bounding_box.fzz.zip

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.

KjellMorgenstern commented 4 years ago

The mentioned method is not correctly implemented, and Fritzing is jumping through quite some loops to get text sizes. This goes as far as rendering the text on a white sheet, then calculating the bounding rectangle by finding the colored pixels, just to get the bounding box. I don't mind a pull request (or better, someone fixing the QtSVG library, there is an open issue about that since >5 years), but be warned that might get a bit more difficult than expected.

mMerlin commented 4 years ago

Well, that at least points to where the issue should be fixed :)

There is "shell" code for how the length should be computed on the svg web site. But that relies on another function, to get the size of a single character, that is also probably not implemented "correctly". I assume that also means that the function to get the text length along a path does not work, though I have seen a demo using it in a web browser.

To do this properly needs to interface with a bunch of font related information. Might be able to simplify by only working with the fonts that Fritzing uses. To get close. I expect that font scaling will still make getting accurate results challenging.

I did a manual edit on a .fz file to test the alignment. Changing the 'middle' entry to 'start' worked for the general case.

KjellMorgenstern commented 1 year ago

Still an issue, just reproduced: image