mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 00:38:14 +00:00
Generate a pile of images for status messages during system firmware update. (#133)
This generates a pile of .bmp files to use as our status messages. Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
parent
b86484a585
commit
2297c09f81
@ -5,15 +5,21 @@ RUN echo "deb-src http://deb.debian.org/debian/ experimental main" >> /etc/apt/s
|
||||
RUN apt-get update -qq
|
||||
RUN apt-get install -yq --no-install-recommends \
|
||||
docbook-utils \
|
||||
fontconfig \
|
||||
fontconfig-config \
|
||||
fonts-dejavu \
|
||||
gcab \
|
||||
gettext \
|
||||
gobject-introspection \
|
||||
gtk-doc-tools \
|
||||
libarchive-dev \
|
||||
libcairo-dev \
|
||||
libcairo-gobject2 \
|
||||
libcolord-dev \
|
||||
libcolorhug-dev \
|
||||
libefivar-dev \
|
||||
libelf-dev \
|
||||
libfreetype6-dev \
|
||||
libfwup-dev \
|
||||
libgcab-dev \
|
||||
libgirepository1.0-dev \
|
||||
@ -21,6 +27,7 @@ RUN apt-get install -yq --no-install-recommends \
|
||||
libgpgme11-dev \
|
||||
libgudev-1.0-dev \
|
||||
libgusb-dev \
|
||||
libpango1.0-dev \
|
||||
libpolkit-gobject-1-dev \
|
||||
libsmbios-dev \
|
||||
libsoup2.4-dev \
|
||||
@ -29,6 +36,10 @@ RUN apt-get install -yq --no-install-recommends \
|
||||
meson \
|
||||
pkg-config \
|
||||
policykit-1 \
|
||||
python3 \
|
||||
python3-cairo \
|
||||
python3-gi-cairo \
|
||||
python3-pil \
|
||||
udev \
|
||||
systemd
|
||||
#deps not yet in unstable:
|
||||
|
@ -4,6 +4,9 @@ RUN echo "deb-src http://deb.debian.org/debian/ unstable main" >> /etc/apt/sourc
|
||||
RUN apt-get update -qq
|
||||
RUN apt-get install -yq --no-install-recommends \
|
||||
docbook-utils \
|
||||
fontconfig \
|
||||
fontconfig-config \
|
||||
fonts-dejavu \
|
||||
gcab \
|
||||
gettext \
|
||||
gir1.2-appstreamglib-1.0 \
|
||||
@ -11,10 +14,13 @@ RUN apt-get install -yq --no-install-recommends \
|
||||
gtk-doc-tools \
|
||||
libappstream-glib-dev \
|
||||
libarchive-dev \
|
||||
libcairo-dev \
|
||||
libcairo-gobject2 \
|
||||
libcolord-dev \
|
||||
libcolorhug-dev \
|
||||
libefivar-dev \
|
||||
libelf-dev \
|
||||
libfreetype6-dev \
|
||||
libfwup-dev \
|
||||
libgcab-dev \
|
||||
libgirepository1.0-dev \
|
||||
@ -22,6 +28,7 @@ RUN apt-get install -yq --no-install-recommends \
|
||||
libgpgme11-dev \
|
||||
libgudev-1.0-dev \
|
||||
libgusb-dev \
|
||||
libpango1.0-dev \
|
||||
libpolkit-gobject-1-dev \
|
||||
libsmbios-dev \
|
||||
libsoup2.4-dev \
|
||||
@ -30,6 +37,10 @@ RUN apt-get install -yq --no-install-recommends \
|
||||
meson \
|
||||
pkg-config \
|
||||
policykit-1 \
|
||||
python3 \
|
||||
python3-cairo \
|
||||
python3-gi-cairo \
|
||||
python3-pil \
|
||||
udev \
|
||||
systemd
|
||||
RUN mkdir /build
|
||||
|
@ -2,9 +2,15 @@ FROM fedora:25
|
||||
|
||||
RUN dnf --enablerepo=updates-testing -y update
|
||||
RUN dnf --enablerepo=updates-testing -y install \
|
||||
adobe-source-han-sans-cn-fonts \
|
||||
cairo-devel \
|
||||
cairo-gobject-devel \
|
||||
colord-devel \
|
||||
dejavu-sans-fonts \
|
||||
docbook-utils \
|
||||
elfutils-libelf-devel \
|
||||
freetype \
|
||||
fontconfig \
|
||||
fwupdate-devel \
|
||||
gcab \
|
||||
gettext \
|
||||
@ -19,7 +25,12 @@ RUN dnf --enablerepo=updates-testing -y install \
|
||||
libsmbios-devel \
|
||||
libsoup-devel \
|
||||
meson \
|
||||
pango-devel \
|
||||
polkit-devel \
|
||||
python3 \
|
||||
python3-cairo \
|
||||
python3-gobject \
|
||||
python3-pillow \
|
||||
redhat-rpm-config \
|
||||
sqlite-devel \
|
||||
systemd \
|
||||
|
@ -43,6 +43,13 @@ BuildRequires: valgrind-devel
|
||||
BuildRequires: elfutils-libelf-devel
|
||||
BuildRequires: gtk-doc
|
||||
BuildRequires: meson
|
||||
BuildRequires: python3 python3-cairo python3-gobject python3-pillow
|
||||
BuildRequires: pango-devel
|
||||
BuildRequires: cairo-devel cairo-gobject-devel
|
||||
BuildRequires: freetype
|
||||
BuildRequires: fontconfig
|
||||
BuildRequires: dejavu-sans-fonts
|
||||
BuildRequires: adobe-source-han-sans-cn-fonts
|
||||
|
||||
%if 0%{?have_smbios}
|
||||
BuildRequires: libsmbios-devel >= 2.3.0
|
||||
@ -61,6 +68,7 @@ Requires: glib2%{?_isa} >= %{glib2_version}
|
||||
Requires: libappstream-glib%{?_isa} >= %{libappstream_version}
|
||||
Requires: libgusb%{?_isa} >= %{libgusb_version}
|
||||
Requires: libsoup%{?_isa} >= %{libsoup_version}
|
||||
Requires: fwupd-labels = %{version}-%{release}
|
||||
|
||||
Obsoletes: fwupd-sign < 0.1.6
|
||||
Obsoletes: libebitdo < 0.7.5-3
|
||||
@ -89,6 +97,13 @@ Requires: libdfu%{?_isa} = %{version}-%{release}
|
||||
%description -n libdfu-devel
|
||||
Files for development with libdfu.
|
||||
|
||||
%package labels
|
||||
Summary: Rendered labels for display during system firmware updates.
|
||||
BuildArch: noarch
|
||||
|
||||
%description labels
|
||||
Rendered labels for display during system firmware updates.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
@ -208,6 +223,9 @@ mkdir -p --mode=0700 $RPM_BUILD_ROOT%{_localstatedir}/lib/fwupd/gnupg
|
||||
%{_libdir}/libdfu*.so
|
||||
%{_libdir}/pkgconfig/dfu.pc
|
||||
|
||||
%files labels
|
||||
%{_datadir}/locale/*/LC_IMAGES/fwupd*
|
||||
|
||||
%changelog
|
||||
* #LONGDATE# Richard Hughes <richard@hughsie.com> #VERSION#-0.#BUILD##ALPHATAG#
|
||||
- Update from git
|
||||
|
@ -128,6 +128,11 @@ gpgerror = cc.find_library('gpg-error')
|
||||
libm = cc.find_library('m', required: false)
|
||||
udev = dependency('udev')
|
||||
|
||||
cairo = dependency('cairo')
|
||||
pango = dependency('pango')
|
||||
fontconfig = cc.find_library('fontconfig')
|
||||
freetype = cc.find_library('freetype')
|
||||
|
||||
if valgrind.found()
|
||||
conf.set('HAVE_VALGRIND', '1')
|
||||
endif
|
||||
|
194
po/make-images
Executable file
194
po/make-images
Executable file
@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
""" This thing rasterizes text for use later """
|
||||
|
||||
# pylint: disable=wrong-import-position,too-many-locals,unused-argument
|
||||
# pylint: disable=invalid-name,too-many-instance-attributes
|
||||
|
||||
"""
|
||||
Licensed under the GNU General Public License Version 2
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
import gettext
|
||||
import math
|
||||
import cairo
|
||||
import gi
|
||||
gi.require_version('Pango', '1.0')
|
||||
gi.require_version('PangoCairo', '1.0')
|
||||
from gi.repository import Pango, PangoCairo
|
||||
from PIL import Image
|
||||
|
||||
def usage(return_code):
|
||||
""" print usage and exit with the supplied return code """
|
||||
if return_code == 0:
|
||||
out = sys.stdout
|
||||
else:
|
||||
out = sys.stderr
|
||||
out.write("usage: make-images <label text> <mo file directory> <LINGUAS> <installdir>")
|
||||
sys.exit(return_code)
|
||||
|
||||
class Rasterizer:
|
||||
""" Rasterize some text """
|
||||
|
||||
def __init__(self, label, modir, linguas):
|
||||
self.text = label
|
||||
self.modir = modir
|
||||
while modir.endswith('/'):
|
||||
modir = modir[:-1]
|
||||
self.linguas = linguas
|
||||
self.directory = modir
|
||||
self.domain = "fwupd"
|
||||
self.font_face = "sans-serif"
|
||||
self.pattern = "{directory}/{language}/LC_IMAGES/fwupd-{width}-{height}.{suffix}"
|
||||
self.fontmap = PangoCairo.font_map_get_default()
|
||||
|
||||
gettext.textdomain(self.domain)
|
||||
gettext.bind_textdomain_codeset(self.domain, self.modir)
|
||||
gettext.install(self.domain, self.modir)
|
||||
|
||||
@property
|
||||
def languages(self):
|
||||
""" Find all of our languages """
|
||||
for x in open(self.linguas, "r").readlines():
|
||||
x = x.strip()
|
||||
# currently ligatures seem completely broken in hi, and I don't know
|
||||
# why. They get LANG=C.
|
||||
if x == 'hi':
|
||||
continue
|
||||
yield x
|
||||
yield "C"
|
||||
|
||||
def render(self):
|
||||
""" Do the work... """
|
||||
def render_one(language, string, width, height, filename):
|
||||
""" Do the work... """
|
||||
|
||||
font_desc = "Sans %fpx" % (height / 32,)
|
||||
fd = Pango.FontDescription(font_desc)
|
||||
fo = cairo.FontOptions()
|
||||
fo.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
|
||||
l = Pango.Language.from_string(language)
|
||||
|
||||
img = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
cctx = cairo.Context(img)
|
||||
layout = PangoCairo.create_layout(cctx)
|
||||
pctx = layout.get_context()
|
||||
pctx.set_font_description(fd)
|
||||
pctx.set_language(l)
|
||||
fs = pctx.load_fontset(fd, l)
|
||||
PangoCairo.context_set_font_options(pctx, fo)
|
||||
|
||||
attrs = Pango.AttrList()
|
||||
length = len(bytes(string, "utf8"))
|
||||
items = Pango.itemize(pctx, string, 0, length, attrs, None)
|
||||
gs = Pango.GlyphString()
|
||||
Pango.shape(string, length, items[0].analysis, gs)
|
||||
|
||||
def find_size(fs, f, data):
|
||||
""" find our size, I hope... """
|
||||
(ink, log) = gs.extents(f)
|
||||
if ink.height == 0 or ink.width == 0:
|
||||
return False
|
||||
data.update({"log": log, "ink": ink})
|
||||
return True
|
||||
data = {}
|
||||
fs.foreach(find_size, data)
|
||||
|
||||
log = data['log']
|
||||
ink = data['ink']
|
||||
|
||||
height = math.ceil(max(ink.height, log.height) / Pango.SCALE)
|
||||
width = math.ceil(max(ink.width, log.width) / Pango.SCALE)
|
||||
|
||||
x = -math.ceil(log.x / Pango.SCALE)
|
||||
y = -math.ceil(log.y / Pango.SCALE)
|
||||
|
||||
del img, cctx, pctx, layout
|
||||
img = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
|
||||
cctx = cairo.Context(img)
|
||||
layout = PangoCairo.create_layout(cctx)
|
||||
pctx = layout.get_context()
|
||||
PangoCairo.context_set_font_options(pctx, fo)
|
||||
|
||||
cctx.set_source_rgb(1, 1, 1)
|
||||
cctx.move_to(x, y)
|
||||
def do_write(fs, f, data):
|
||||
""" write out glyphs """
|
||||
ink = gs.extents(f)[0]
|
||||
if ink.height == 0 or ink.width == 0:
|
||||
return False
|
||||
PangoCairo.show_glyph_string(cctx, f, gs)
|
||||
return True
|
||||
fs.foreach(do_write, None)
|
||||
img.flush()
|
||||
try:
|
||||
tmpname = filename[len(os.environ['DESTDIR']):]
|
||||
except KeyError:
|
||||
tmpname = filename[len(os.environ['MESON_BUILD_ROOT']):]
|
||||
print("Writing %s " % (tmpname,), end='\r')
|
||||
def make_dir(d):
|
||||
""" make our parent dir and then our own dir """
|
||||
if os.access(d, os.O_RDWR):
|
||||
return
|
||||
parts = os.path.split(d)
|
||||
if parts and parts[0]:
|
||||
make_dir(parts[0])
|
||||
os.mkdir(d, 0o755)
|
||||
d = os.path.split(filename)[0]
|
||||
make_dir(d)
|
||||
img.write_to_png(filename)
|
||||
pimg = Image.open(filename)
|
||||
img = pimg.copy()
|
||||
del pimg
|
||||
img.save(filename)
|
||||
|
||||
for lang in self.languages:
|
||||
#print("lang:\"%s\" string:\"%s\"" % (lang, string))
|
||||
# these are the 1.6:1 of some common(ish) screen widths
|
||||
sizes = ((640, 480), (800, 600), (1024, 768), (1920, 1080),
|
||||
(3840, 2160), (5120, 2880), (5688, 3200), (7680, 4320))
|
||||
nameinfo = {
|
||||
'directory': self.directory,
|
||||
'language': lang,
|
||||
}
|
||||
if lang == 'C':
|
||||
string = self.text
|
||||
else:
|
||||
tl = gettext.translation(self.domain, self.modir,
|
||||
languages=[lang])
|
||||
string = tl.gettext(self.text)
|
||||
if string == self.text:
|
||||
continue
|
||||
for width, height in sizes:
|
||||
nameinfo.update({'width': width,
|
||||
'height': height,
|
||||
'suffix': 'bmp'})
|
||||
filename = self.pattern.format_map(nameinfo)
|
||||
render_one(lang, string, width, height, filename)
|
||||
print("")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if {'-?', '--help', '--usage'}.intersection(set(sys.argv)):
|
||||
usage(0)
|
||||
if len(sys.argv) != 4:
|
||||
usage(1)
|
||||
|
||||
r = Rasterizer(label=sys.argv[1], modir=sys.argv[2],
|
||||
linguas=sys.argv[3])
|
||||
r.render()
|
12
po/make-images.sh
Normal file
12
po/make-images.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# make-images.sh
|
||||
# Copyright (C) 2017 Peter Jones <pjones@redhat.com>
|
||||
#
|
||||
# Distributed under terms of the GPLv2 license.
|
||||
#
|
||||
install -m 0755 -d ${MESON_INSTALL_DESTDIR_PREFIX}/share/fwupd/labels/
|
||||
${MESON_SOURCE_ROOT}/po/make-images "Please wait while we install a system update" ${MESON_INSTALL_DESTDIR_PREFIX}/share/locale/ ${MESON_SOURCE_ROOT}/po/LINGUAS
|
||||
for x in ${MESON_INSTALL_DESTDIR_PREFIX}/share/locale/*/LC_IMAGES/*.bmp ; do
|
||||
gzip -f ${x}
|
||||
done
|
@ -4,3 +4,5 @@ i18n.gettext(meson.project_name(),
|
||||
'--default-domain=' + meson.project_name(),
|
||||
]
|
||||
)
|
||||
|
||||
meson.add_install_script('make-images.sh')
|
||||
|
Loading…
Reference in New Issue
Block a user