Bug 440985 - Make it possible to use px in the svg to determine font size as well as pt
Summary: Make it possible to use px in the svg to determine font size as well as pt
Status: CONFIRMED
Alias: None
Product: krita
Classification: Applications
Component: Tool/Text (show other bugs)
Version: 4.4.2
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-14 21:29 UTC by forestbeasts
Modified: 2022-08-04 01:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
An example of blurred vs. pixel-perfect (although with kerning issues) bitmap font rendering. Left is Krita 4.4.3, right is Krita 4.3.0. (3.10 KB, image/png)
2021-08-14 21:29 UTC, forestbeasts
Details
Inkscape-made text vs. native text tool (2.29 KB, image/png)
2021-09-07 19:42 UTC, forestbeasts
Details
Terminus 12pt (23.38 KB, application/gzip)
2021-09-08 07:24 UTC, forestbeasts
Details
Krita 5.0.2 text units demo (64.08 KB, application/x-krita)
2022-03-29 22:37 UTC, forestbeasts
Details

Note You need to log in before you can comment on or make changes to this bug.
Description forestbeasts 2021-08-14 21:29:33 UTC
Created attachment 140733 [details]
An example of blurred vs. pixel-perfect (although with kerning issues) bitmap font rendering. Left is Krita 4.4.3, right is Krita 4.3.0.

SUMMARY
In Krita 4.3.0, the text tool rendered bitmap fonts pixel-perfect, which is great for pixel art. (There were kerning issues though, which got fixed when the pixel-perfect rendering broke.)

In Krita 4.4.3, though, it's not pixel-aligned, which makes it look awful at small sizes.

STEPS TO REPRODUCE
1. Make a piece of text with the text tool.
2. Set it to a bitmap font, e.g. Terminus or Fixed.

OBSERVED RESULT
The text is blurry.

EXPECTED RESULT
The text is pixel-perfect.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kubuntu 20.10
(available in About System)
KDE Plasma Version: 5.19.5
KDE Frameworks Version: 5.74.0
Qt Version: 5.14.2

ADDITIONAL INFORMATION
I tried the nightly build last night (e89467b) and it was still happening there.
Comment 1 forestbeasts 2021-09-07 19:40:06 UTC
Okay, here's an update: it turns out that if you copy and paste an SVG text object from Inkscape, it'll actually be perfectly sharp – and it's still editable with the text tool, and /stays/ pixel-sharp! Very odd.

This is the Inkscape-made text's source:
<text fill="#ffffff" stroke-opacity="0" stroke="#000000" stroke-width="0" stroke-linecap="square" stroke-linejoin="bevel" font-family="Terminus" font-size="9" font-size-adjust="1" font-stretch="normal" kerning="0" letter-spacing="0" word-spacing="0"><tspan x="0">Copied from Inkscape</tspan></text>

And this is the native text tool text's source:
<text fill="#ffffff" stroke-opacity="0" stroke="#000000" stroke-width="0" stroke-linecap="square" stroke-linejoin="bevel" font-family="Terminus" font-size="9" font-size-adjust="1" font-stretch="normal" letter-spacing="0" word-spacing="0"><tspan x="0">Native</tspan><tspan x="0" dy="12">text tool</tspan></text>

But pasting the Inkscape-made one's source into the native text tool one's source doesn't make it sharp. It stays blurry and misaligned.
Comment 2 forestbeasts 2021-09-07 19:42:25 UTC
Created attachment 141368 [details]
Inkscape-made text vs. native text tool

Nearest-neighbor upscaled 4x to show detail.
Comment 3 forestbeasts 2021-09-07 19:59:48 UTC
Oh, I forgot to mention -- this is with Krita 5.0.0-prealpha (git e89467b) same as before. But it also happens on the latest nightly, 5.1.0-prealpha (git c34330b).

-- Frost
Comment 4 Halla Rempt 2021-09-08 07:19:39 UTC
Can you please please attach that font to this report?
Comment 5 forestbeasts 2021-09-08 07:23:41 UTC
Sure! It's Terminus, I think it's from the Ubuntu xfonts-terminus package... and there seems to be a lot of them (one for each size), so I hope I have the right one.
Comment 6 forestbeasts 2021-09-08 07:24:53 UTC
Created attachment 141378 [details]
Terminus 12pt
Comment 7 Bug Janitor Service 2021-09-09 04:36:14 UTC
Thanks for your comment!

Automatically switching the status of this bug to REPORTED so that the KDE team
knows that the bug is ready to get confirmed.

In the future you may also do this yourself when providing needed information.
Comment 8 forestbeasts 2022-03-29 20:50:24 UTC
Update: Apparently with Krita 5, the copy-from-Inkscape workaround broke! And all the text in our previous documents /disappeared/. (The objects are still there, but won't display.)
Comment 9 forestbeasts 2022-03-29 20:56:03 UTC
(In reply to forestbeasts from comment #8)
> And all the text in our previous documents /disappeared/. (The objects are still there, but won't display.)

Okay, apparently the text straight-up disappearing was a system configuration issue, never mind about that. Now that that's resolved, some of the (workaround-pasted) text is still sharp and some is blurry, which is odd.
Comment 10 forestbeasts 2022-03-29 22:27:48 UTC
I think I found the bug!!

The issue is that the view box for the text SVG objects is specified in pt, so the font isn't an exact number of pixels tall. Unzipping the .kra file and editing the layer SVG to use px makes it pixel-perfect!

...except then Krita then converts this back to a pt size and adds a matrix transform to compensate, for some reason. But it's still pixel-sharp after that.

(Is there a reason the SVG units have to be in pt instead of px? It might be easier to just do everything in px.)
Comment 11 forestbeasts 2022-03-29 22:37:46 UTC
Created attachment 147831 [details]
Krita 5.0.2 text units demo

A demo of the different units to use for text. Bitmap font in pt, bitmap font in px (although Krita reconverted it to pt, it added a matrix transform to compensate), non-bitmap font in px (same), non-bitmap font in pt.
Comment 12 Halla Rempt 2022-04-06 13:05:04 UTC
Now that I think of it, I'm actually surprised that bitmap fonts "work" -- they aren't supported by Qt itself...
Comment 13 forestbeasts 2022-08-04 01:31:48 UTC
Okay, sometime between Krita 5.0.2 and 5.0.8, this broke again, blurring fonts in existing documents. I'm not sure exactly what changed here, don't have the energy to go digging at the moment. Haven't tried making a new document and repeating the "unzip, mess with SVG, rezip" dance just yet, because it's a pain in the tail...

-- Frost