Escaping characters in translation strings in initrd
Introduction here:
https://bkhome.org/news/202301/first-bootup-2-letter-language-asked-in-initrd.html
But, there are complications, discussed here:
https://forum.puppylinux.com/viewtopic.php?p=79487#p79487
Thinking, will go back to having the strings in single-quotes,
and escape embedded single-quotes. Original:
S104='Ok let's put in single-quote and "double quote" characters in same string'
Now:
S104='Ok let'\''s put in single-quote and "double quote" characters in same string'
Reckon this is the simplest solution. I don't like the S104=$'text' nor the S104="text" formats, as they both involve interpretation of the string, don't treat it as-is. Single-quotes as-is is also faster.
EDIT:
Have implemented the change, see github commit:
"format of translation strings in initrd
changed"
https://github.com/bkauler/woofq/commit/f00f5e72686abf97d4939f7692d32944ea19e332
The strings are now single-quote characters at each end. Furthermore, single-quote characters within the string are not escaped. Instead, they are automatically escaped when EasyOS is built:
"escape single-quote char within initrd
translations"
https://github.com/bkauler/woofq/commit/5148393b4d773f228eb8806f6c3ce8d8c45edbb0
See also the README:
https://github.com/bkauler/woofq/blob/main/easyos/easy-code/boot/initrd-tree/nls/README
Tags: easy
xloadimage and xserver-fb added to Kirkstone build
When run Xorg in the initrd, want to be able to load a background png image, so have compiled 'xloadimage' in OE:
https://github.com/bkauler/oe-qky-kirkstone/commit/d29daba230a4c2233bed33ca11ca01f9380de2c5
Packages 'xloadimage' and 'xserver-fb' are now added to the Kirkstone-series build of EasyOS:
https://github.com/bkauler/woofq/commit/57b949015f292b401d6fa67930559d62ef6daa33
This is a follow-on from the plan to run GTK apps in the initrd:
https://bkhome.org/news/202301/bringing-back-run-gtk-apps-in-the-initrd.html
Tags: easy
Bringing back run GTK apps in the initrd
This is the latest post about gui_engine, the ongoing saga to run GUI apps in the initrd:
https://bkhome.org/news/202301/guiengine-project-put-on-hold.html
...that one has been put on hold. However, there is another solution, that I developed back in 2019, to setup an aufs layer with 'easy.sfs' in the initrd, then chroot onto it. Then run the Xorg server and hence run any GUI app.
Googled for a post on that, had trouble finding the right keywords, then found it, posted March 2019:
https://bkhome.org/news/201903/xorg-gui-running-in-initrd.html
A photo from above post:
A problem I had with that, is all Xorg versions after 1.19.7 do not work in the initrd. Let's see, yes, here are posts about that:
https://bkhome.org/www/news/202105/glibc-bumped-to-233-in-openembedded.html
https://bkhome.org/news/201908/progress-heading-toward-buster-21.html
For the upcoming Kirkstone-series, decided to compile Xorg version 1.19.7 very cutdown, to run on the Linux framebuffer only, and with minimal drivers. This is how I compiled Xorg:
# mkdir build
# cd build
# ../configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --build=x86_64-pc-linux-gnu --with-sha1=libc \
--with-systemd-daemon=no --with-fontrootdir=/usr/share/fonts --with-fontmiscdir=/usr/share/fonts/misc \
--with-fontttfdir=/usr/share/fonts/TTF --with-fonttype1dir=/usr/share/fonts/Type1 --without-xsltproc \
--without-fop --without-xmlto --without-doxygen --disable-secure-rpc --disable-ipv6 --disable-tcp-transport \
--disable-xshmfence --disable-libunwind --disable-kdrive --disable-glamor --disable-xwin --disable-xwayland \
--disable-xquartz --disable-xnest --disable-xvfb --disable-dmx --enable-xorg --disable-suid-wrapper \
--enable-systemd-logind=no --disable-linux-apm --disable-linux-acpi --enable-pciaccess --disable-clientids \
--disable-libdrm --disable-int10-module --disable-vbe --disable-xfree86-utils --disable-vgahw \
--disable-config-wscons --disable-config-hal --disable-config-udev --disable-dpms --disable-xf86bigfont \
--disable-dbe --disable-tslib --disable-xace --disable-xf86vidmode --disable-xinerama --disable-present \
--disable-dri3 --disable-dri2 --disable-dri --disable-glx --disable-xdm-auth-1 --disable-xdmcp \
--disable-screensaver --disable-dga --disable-xvmc --disable-xv --disable-record --disable-mitshm \
--disable-composite --disable-listen-tcp --disable-unit-tests --disable-devel-docs --disable-docs \
--without-dtrace --disable-selective-werror --enable-shared --disable-static
# make
# new2dir make install
Also compiled these:
xf86-input-keyboard 1.9.0
xf86-input-mouse 1.9.2
xf86-video-fbdev 0.5.0
And made it into a PET, named 'xserver-fb-1.19.7-kirkstone64.pet'. The files in this PET are in /usr/lib/xorg-fb, so although the PET will be included in the build of EasyOS, it won't interfere with the normal Xorg.
It is only in the initrd, after the aufs layer is setup, using 'easy.sfs', after chroot onto it, the contents of /usr/lib/xorg-fb can be copied to replace /usr/lib/xorg, and then the Xorg server started.
Have created the PET, not tested yet.
Tags: easy
gui_engine project put on-hold
Have been posting about the gui_engine GUI toolkit, for building statically-linked standalone executables that will run in the initramfs (initrd) and render to the Linux framebuffer. See last post:
https://bkhome.org/news/202301/guiengine-fully-converted-to-ttf.html
I even tentatively constructed a little GUI for asking what language the user requires:
I discovered a problem with button placement, reported it:
https://github.com/AlxHnr/gui_engine/issues/4
That should be fixable; however, there is another issue that
would be more challenging to implement. I want the UI to be fully
operable by keyboard; TAB between widgets, UP-DOWN arrows keys to
choose in the drop-down list, ENTER to select.
Mostly because of that latter issue, I have decided to put the project on-hold. I have forked the original gui_engine with my changes so far:
https://github.com/bkauler/gui_engine
This has been very interesting. OK, has soaked up a lot of time,
but that's the way it is, time rolls on; already approaching end
of January 2023.
I still want to run GUI apps in the initrd; however, there is
another way to do it, that I did implement a year or two ago, then
abandoned. That was to setup an aufs layer in the initrd, with
'easy.sfs', then chroot onto it and run GUI apps based on
gtkdialog. It worked, don't recall why I abandoned it. Will take
another look.
Tags: easy
gui_engine fully converted to TTF
I posted about converting the titlebar of the demo 'example.c' from the 8x8 bitmap font builtin to SDL_gfx, to TTF:
https://bkhome.org/news/202301/ttf-text-in-titlebar-guiengine.html
Basically more of the same, went through and did a full conversion, here is a snapshot:
The down-arrow in the drop-down list was previously a character from the gfx 8x8 set. I changed it to a "trigon", which is a triangle, a shape that is available in SDL_gfx -- might make it a bit smaller. The "x" in the checkbox is still from the gfx 8x8 set.
Just a quick post, heading off into the big wide world for the
rest of the day.
Tags: easy
TTF text in titlebar gui_engine
I posted about starting to analyze how gui_engine works:
https://bkhome.org/news/202301/guiengine-function-hierarchy.html
There are two functions used to draw text on the screen; characterRGBA() and stringRGBA(). These are part of SDL_gfx. The SDL_gfx package is mostly for drawing shapes, such as lines, polygons, circles, etc.; however, it also has some bitmap fonts builtin, of various sizes. The default size is 8x8 pixels. These are basic 256-character ASCI fonts.
These functions call characterRGBA():
g_draw_text(), g_draw_widget_check_box(), g_draw_widget_drop_down_list(), g_draw_window()
This function calls stringRGBA(), to draw text in the window titlebar:
g_draw-window()
Function characterRGBA() draws a character at a time. I am not sure why it is done that way, as that would be less efficient. Anyway, to get going, have converted the call to stringRGBA() to use TTF.
First thing to do is load a font. I put this into 'example.c':
...
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include "gui_engine.h"
#include "example-theme.h"
TTF_Font *ttfFont = NULL;
...
/* Initialize GUI. */
if(g_init_everything() == 0)
{
SDL_FreeSurface(screenSurface);
die("failed to initialize GUI engine");
}
ttfFont = TTF_OpenFont("/usr/share/fonts/TTF/RobotoMono-Bold.ttf", 14);
if( ttfFont == NULL ) die("failed to load ttf font");
g_window *first_window = createDemoWindow(250, 200);
...
SDL_FreeSurface(screenSurface);
TTF_CloseFont(ttfFont);
TTF_Quit();
...
Pretty straightforward. I chose "RobotoMono-Bold", size 14. Note
that the "ttfFont" resource has to be removed when the program
exits.
Over in 'gui_engine.h':
...
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <string.h>
/* gui engine defines */
/* changing this values can make the windows and widgets look shifted */
#define G_MARGIN 8
#define G_CHAR_W 8
#define G_CHAR_H 12
#define TTF_OFFSET_Y 0
...
And 'gui_engine.c':
...
#include "gui_engine.h"
extern TTF_Font *ttfFont;
SDL_Surface *ttfSurface = NULL;
SDL_Color textColorFG = { 255, 255, 0 };
SDL_Rect offset = { 0, 0 };
...
/* write text in center of title bar */
if(window->flags.close_button)
{
/*stringRGBA(dst, window->x + (window->w - G_WINDOW_CLOSE_BUTTON_WIDTH)/2 - (strlen(temp_string) * G_CHAR_W)/2,
window->y - G_WINDOW_TITLE_BAR_HEIGHT + G_MARGIN, temp_string,
window->color.title_text.r, window->color.title_text.g,
window->color.title_text.b, window->color.title_text.a);*/
textColorFG.r = window->color.title_text.r;
textColorFG.g = window->color.title_text.g;
textColorFG.b = window->color.title_text.b;
ttfSurface = TTF_RenderText_Blended(ttfFont, temp_string, textColorFG);
offset.x = window->x + (window->w - G_WINDOW_CLOSE_BUTTON_WIDTH)/2 - (strlen(temp_string) * G_CHAR_W)/2;
offset.y = window->y - G_WINDOW_TITLE_BAR_HEIGHT + TTF_OFFSET_Y;
SDL_BlitSurface(ttfSurface, NULL, dst, &offset);
SDL_FreeSurface(ttfSurface);
}
else
{
/*stringRGBA(dst, window->x + window->w/2 - (strlen(temp_string) * G_CHAR_W)/2,
window->y - G_WINDOW_TITLE_BAR_HEIGHT + G_MARGIN, temp_string,
window->color.title_text.r, window->color.title_text.g,
window->color.title_text.b, window->color.title_text.a);*/
textColorFG.r = window->color.title_text.r;
textColorFG.g = window->color.title_text.g;
textColorFG.b = window->color.title_text.b;
ttfSurface = TTF_RenderText_Blended(ttfFont, temp_string, textColorFG);
offset.x = window->x + window->w/2 - (strlen(temp_string) * G_CHAR_W)/2;
offset.y = window->y - G_WINDOW_TITLE_BAR_HEIGHT + TTF_OFFSET_Y;
SDL_BlitSurface(ttfSurface, NULL, dst, &offset);
SDL_FreeSurface(ttfSurface);
}
...
...I left in the call to stringRGBA(), commented-out, so we can
see how it got replaced.
My understanding also is that once "blitted" to the screen, ttfSurface is no longer required, hence I put in "SDL_FreeSurface(ttfSurface)".
The only slight reservation I have about this, is if the window is dragged, it will go through that entire process again.
Anyway, looking good. Here is a snapshot:
...nice hey! So much prettier than the jagged bitmap text.
There's a nice tutorial on SDL_ttf for SDL v1.2:
http://www.sdltutorials.com/sdl-ttf
Unfortunately, some old SDL v1.2 tutorials have disappeared, good to see this one still online.
Next up, will study the code that calls
characterRGBA().
Tags: easy
gui_engine function hierarchy
Previous post about gui_engine:
https://bkhome.org/news/202301/statically-linked-guiengine-example-with-ttf-support-is-560kb.html
It is looking good as a GUI toolkit for the initrd, so embarking on analyzing how it works. There is no documentation and just one example, 'example.c'. The file 'gui_engine.c' provides functions that an application can call.
First baby step is to look at the function hierarchy. I have constructed this map:
The green boxes are functions called in 'example.c', so gives an indication what functions are most important to consider.
Of particular interest to me is how text is drawn on the screen,
and it looks like that is done in g_draw_text(). Will look at that
to see how to incorporate TTF fonts.
Tags: easy
Statically-linked gui_engine example with TTF support is 560KB
I originally posted about gui_engine here, it runs as a statically-linked binary in the initrd:
https://bkhome.org/news/202301/guiengine-runs-in-initrd.html
Then posted about success with SDL_ttf:
https://bkhome.org/news/202301/back-in-business-with-sdlttf.html
So, compiled SDL-ttf and dependencies freetype and libpng, as static libraries, in OE, then added some SDL_ttf functions into 'example.c' in gui_engine. The compiled example.c, linking in those extra libraries. The statically-linked binary was 304KB, it is now 560KB.
I reckon that is very good. A completely standalone application, with SDL, SDL_gfx, SDL_ttf, freetype, libz and libpng all linked-in, very reasonable size.
The 'example.c' is now ready to be expanded, render TrueType fonts instead of console fonts, add one or two extra widgets -- I would like a list widget, to show the list of languages, as did earlier using 'dialog' in the initrd.
It is all very well wanting to do the above, but first have to
study the code of gui_engine, figure how it all hangs
together.
Tags: easy