Bug 93808 - [PATCH] New FreeType-based label-ft plugin
Summary: [PATCH] New FreeType-based label-ft plugin
Status: RESOLVED MOVED
Alias: None
Product: plymouth
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All All
: medium enhancement
Assignee: Ray Strode [halfline]
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-21 12:13 UTC by Fabian Vogt
Modified: 2018-08-07 09:27 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH 1/3] ply-label: Don't crash if label plugin fails (1.30 KB, patch)
2016-01-21 12:14 UTC, Fabian Vogt
Details | Splinter Review
[PATCH 2/3] Add label-ft plugin (19.92 KB, patch)
2016-01-21 12:15 UTC, Fabian Vogt
Details | Splinter Review
[PATCH 3/3] Install label-ft plugin into initrd, if available (1.22 KB, patch)
2016-01-21 12:16 UTC, Fabian Vogt
Details | Splinter Review
[PATCH 2/3 v2] Add label-ft plugin (20.02 KB, patch)
2016-01-25 08:03 UTC, Fabian Vogt
Details | Splinter Review
[PATCH 1/3 v2] ply-label: Don't crash if label plugin fails (1.35 KB, patch)
2016-02-08 16:02 UTC, Fabian Vogt
Details | Splinter Review
[PATCH 2/3 v2] Add label-ft plugin (20.02 KB, patch)
2017-01-20 13:20 UTC, Fabian Vogt
Details | Splinter Review
[PATCH v3 1/4] ply-label: Don't crash if label plugin fails (1.31 KB, patch)
2017-01-20 13:23 UTC, Fabian Vogt
Details | Splinter Review
[PATCH v3 2/4] Add label-ft plugin (20.08 KB, patch)
2017-01-20 13:23 UTC, Fabian Vogt
Details | Splinter Review
Install label-ft plugin into initrd, if available (1.18 KB, patch)
2017-01-20 13:23 UTC, Fabian Vogt
Details | Splinter Review
[PATCH v3 4/4] Add HiDPI support to label-ft plugin (3.82 KB, patch)
2017-01-20 13:26 UTC, Fabian Vogt
Details | Splinter Review

Description Fabian Vogt 2016-01-21 12:13:58 UTC
The attached patch series introduces a new plugin "label-ft", which only depends on FreeType.
Its purpose is to be as lightweight as possible to be included in the initrd,
to be able to display text, such as the password prompt. (See https://bugzilla.opensuse.org/show_bug.cgi?id=959986)
Is is a replacement for the label plugin, except that it lacks support for Unicode and different font families.
This shouldn't be an issue during the initrd and after the full root is available, the full "label" plugin is used instead, if available.

It requires a font file to be present at a fixed location in the initrd, so the plymouth-populate-initrd script takes care of that with fontconfig.
If fontconfig is available during runtime, label-ft uses fc-match to determine which file to use.

For now, this is only a request for review, as it's not _thoroughly_ tested yet.
Comment 1 Fabian Vogt 2016-01-21 12:14:59 UTC
Created attachment 121178 [details] [review]
[PATCH 1/3] ply-label: Don't crash if label plugin fails
Comment 2 Fabian Vogt 2016-01-21 12:15:24 UTC
Created attachment 121179 [details] [review]
[PATCH 2/3] Add label-ft plugin
Comment 3 Fabian Vogt 2016-01-21 12:16:10 UTC
Created attachment 121180 [details] [review]
[PATCH 3/3] Install label-ft plugin into initrd, if available
Comment 4 Fabian Vogt 2016-01-25 08:03:30 UTC
Created attachment 121254 [details] [review]
[PATCH 2/3 v2] Add label-ft plugin

A small bug was found and fixed now in Patch 2/3.
With specific glyphs the end of a line was cut short by a few pixels.
Comment 5 Fabian Vogt 2016-02-08 16:02:25 UTC
Created attachment 121596 [details] [review]
[PATCH 1/3 v2] ply-label: Don't crash if label plugin fails

Small bug in patch 1 this time. A different code path leading to a similiar nullptr SEGV.
Comment 6 Fabian Vogt 2016-10-17 15:29:56 UTC
Ping.
Comment 7 Fabian Vogt 2017-01-19 09:13:10 UTC
Ping #2.
Comment 8 Ray Strode [halfline] 2017-01-19 14:43:50 UTC
sorry for being slow to review this.  So have you been using the patchset in opensuse the last year ?
Comment 9 Ray Strode [halfline] 2017-01-19 14:50:49 UTC
Comment on attachment 121596 [details] [review]
[PATCH 1/3 v2] ply-label: Don't crash if label plugin fails

Review of attachment 121596 [details] [review]:
-----------------------------------------------------------------

well plymouth makes no attempt to handle alloc failures, but this patch seems okay to me regardless.
Comment 10 Fabian Vogt 2017-01-19 15:34:44 UTC
(In reply to Ray Strode [halfline] from comment #8)
> sorry for being slow to review this.  So have you been using the patchset in
> opensuse the last year ?

Yes, it's used by default instead of the full label plugin. So far I haven't seen any issues or even bug reports about it.

openQA considers it fine as well: https://openqa.opensuse.org/tests/337059#step/boot_encrypt/1

(In reply to Ray Strode [halfline] from comment #9)
> Comment on attachment 121596 [details] [review] [review]
> [PATCH 1/3 v2] ply-label: Don't crash if label plugin fails
> 
> Review of attachment 121596 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> well plymouth makes no attempt to handle alloc failures, but this patch
> seems okay to me regardless.

Creation of label-ft also fails if no font file could be loaded.
Comment 11 Ray Strode [halfline] 2017-01-19 15:39:28 UTC
Comment on attachment 121254 [details] [review]
[PATCH 2/3 v2] Add label-ft plugin

Review of attachment 121254 [details] [review]:
-----------------------------------------------------------------

thanks for working on this. one thing is, the source file probably needs a sed 's/\([^ ]\)(/\1 (/g'.  braces also need to be moved up to the same line.

have you tried this on a hidpi display?

::: src/plugins/controls/Makefile.am
@@ +2,5 @@
>  if ENABLE_PANGO
> +SUBDIRS += label
> +endif
> +if ENABLE_FREETYPE
> +SUBDIRS += label-ft

maybe call it label-minimal instead of label-ft

::: src/plugins/controls/label-ft/plugin.c
@@ +37,5 @@
> +
> +#include "ply-label-plugin.h"
> +
> +/* This is used if fontconfig (fc-match) is not available, like in the initrd. */
> +#define FONT_FALLBACK "/usr/share/fonts/Plymouth.ttf"

i'd put this in /usr/share/plymouth or whatever. If ever ended up in /usr/share/fonts on the rootfs, it would just be a duplicate font, so doesn't make sense in /usr/share/fonts

@@ +68,5 @@
> +{
> +        FILE *fp;
> +        static char fc_match_out[PATH_MAX];
> +
> +        fp = popen("/usr/bin/fc-match -f %{file}", "r");

i wouldn't bother with this.  Let's keep the plugin minimal.  The other one does fontconfig etc, just always use the hard coded font for this plugin.

@@ +226,5 @@
> +static FT_Int
> +min (FT_Int a,
> +     FT_Int b)
> +{
> +    return a < b ? a : b;

we already have this in ply-utils.h as a macro

@@ +308,5 @@
> +        if(target_size.height == 0)
> +                return; /* This happens sometimes. */
> +
> +        /* 64ths of a pixel */
> +        pen.y = label->area.y << 6;

I guess this shift stuff is about freetype using a fixed point representation.  does it have accessor macros you could use?

@@ +320,5 @@
> +                pen.x = label->area.x << 6;
> +
> +                /* Start at start position (alignment) */
> +                if(label->alignment == PLY_LABEL_ALIGN_CENTER)
> +                    pen.x += (label->width - width_of_line(label, cur_c)) << 5;

this is too subtle.  instead put label->width - width_of_line(label, cur_c) in a temporary, empty_space.  Then do

pen.x += empty_space / 2;

@@ +326,5 @@
> +                    pen.x += (label->width - width_of_line(label, cur_c)) << 6;
> +
> +                while(*cur_c && *cur_c != '\n')
> +                {
> +                    /* TODO: Unicode support. */

so of course there will be limits on what kind of support we can do here.  to get full support would need a large collection of fonts and pango etc.
But, we can at least cover some of the european languages relatively painlessly. mbrtowc() and ply_utf8_character_get_size should be useful.
Comment 12 Fabian Vogt 2017-01-19 16:17:58 UTC
(In reply to Ray Strode [halfline] from comment #11)
> Comment on attachment 121254 [details] [review] [review]
> [PATCH 2/3 v2] Add label-ft plugin
> 
> Review of attachment 121254 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> thanks for working on this. one thing is, the source file probably needs a
> sed 's/\([^ ]\)(/\1 (/g'.  braces also need to be moved up to the same line.

Will do.

> have you tried this on a hidpi display?

No, but I will do so later. I don't know what needs to be done to support HiDPI in plymouth.

> ::: src/plugins/controls/Makefile.am
> @@ +2,5 @@
> >  if ENABLE_PANGO
> > +SUBDIRS += label
> > +endif
> > +if ENABLE_FREETYPE
> > +SUBDIRS += label-ft
> 
> maybe call it label-minimal instead of label-ft

IMO minimal is the wrong adjective, what about "basic"?

> ::: src/plugins/controls/label-ft/plugin.c
> @@ +37,5 @@
> > +
> > +#include "ply-label-plugin.h"
> > +
> > +/* This is used if fontconfig (fc-match) is not available, like in the initrd. */
> > +#define FONT_FALLBACK "/usr/share/fonts/Plymouth.ttf"
> 
> i'd put this in /usr/share/plymouth or whatever. If ever ended up in
> /usr/share/fonts on the rootfs, it would just be a duplicate font, so
> doesn't make sense in /usr/share/fonts

Ok. This is so far only used inside the initrd (patch 3).

> @@ +68,5 @@
> > +{
> > +        FILE *fp;
> > +        static char fc_match_out[PATH_MAX];
> > +
> > +        fp = popen("/usr/bin/fc-match -f %{file}", "r");
> 
> i wouldn't bother with this.  Let's keep the plugin minimal.  The other one
> does fontconfig etc, just always use the hard coded font for this plugin.

Ok.

> @@ +226,5 @@
> > +static FT_Int
> > +min (FT_Int a,
> > +     FT_Int b)
> > +{
> > +    return a < b ? a : b;
> 
> we already have this in ply-utils.h as a macro

Ok.

> @@ +308,5 @@
> > +        if(target_size.height == 0)
> > +                return; /* This happens sometimes. */
> > +
> > +        /* 64ths of a pixel */
> > +        pen.y = label->area.y << 6;
> 
> I guess this shift stuff is about freetype using a fixed point
> representation.  does it have accessor macros you could use?

I'm not aware of any. Should I add one to label-ft.c?

> @@ +320,5 @@
> > +                pen.x = label->area.x << 6;
> > +
> > +                /* Start at start position (alignment) */
> > +                if(label->alignment == PLY_LABEL_ALIGN_CENTER)
> > +                    pen.x += (label->width - width_of_line(label, cur_c)) << 5;
> 
> this is too subtle.  instead put label->width - width_of_line(label, cur_c)
> in a temporary, empty_space.  Then do
> 
> pen.x += empty_space / 2;

I could use the macro above here as well.

> 
> @@ +326,5 @@
> > +                    pen.x += (label->width - width_of_line(label, cur_c)) << 6;
> > +
> > +                while(*cur_c && *cur_c != '\n')
> > +                {
> > +                    /* TODO: Unicode support. */
> 
> so of course there will be limits on what kind of support we can do here. 
> to get full support would need a large collection of fonts and pango etc.
> But, we can at least cover some of the european languages relatively
> painlessly. mbrtowc() and ply_utf8_character_get_size should be useful.

I'll need to read some more FreeType documentation for that first.
Comment 13 Fabian Vogt 2017-01-20 13:20:02 UTC
Created attachment 129067 [details] [review]
[PATCH 2/3 v2] Add label-ft plugin
Comment 14 Fabian Vogt 2017-01-20 13:23:03 UTC
Created attachment 129068 [details] [review]
[PATCH v3 1/4] ply-label: Don't crash if label plugin fails
Comment 15 Fabian Vogt 2017-01-20 13:23:32 UTC
Created attachment 129069 [details] [review]
[PATCH v3 2/4] Add label-ft plugin
Comment 16 Fabian Vogt 2017-01-20 13:23:58 UTC
Created attachment 129070 [details] [review]
Install label-ft plugin into initrd, if available
Comment 17 Fabian Vogt 2017-01-20 13:26:32 UTC
Created attachment 129071 [details] [review]
[PATCH v3 4/4] Add HiDPI support to label-ft plugin

v3 of the series fixes formatting and style, as well as macro usage (MIN instead of min, FT_GRID_TO_PX etc. instead of shifting).

I kept the use of fc-match as it would be less useful outside of the initrd otherwise.
Comment 18 GitLab Migration User 2018-08-07 09:27:47 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/plymouth/plymouth/issues/45.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.