#1 Fix font path bug
Merged 2 months ago by brouhaha. Opened 2 months ago by momosomium.
https://pagure.io/lcdtest.git master  into  master

Add patch to determine font path with fontconfig
Morian Sonnet • 2 months ago  
0001-RobustFontPath.patch
file added
+110

@@ -0,0 +1,110 @@

+ diff -urN lcdtest-1.18-old/src/get_font_file.c lcdtest-1.18/src/get_font_file.c

+ --- lcdtest-1.18-old/src/get_font_file.c	1970-01-01 01:00:00.000000000 +0100

+ +++ lcdtest-1.18/src/get_font_file.c	2019-11-20 23:07:52.379800111 +0100

+ @@ -0,0 +1,39 @@

+ +#include "get_font_file.h"

+ +#include <fontconfig/fontconfig.h>

+ +#include <stddef.h>

+ +

+ +static FcPattern *font_file = NULL;

+ +

+ +const char *get_font_file (const char *font_name)

+ +{

+ +  FcConfig* config = FcInitLoadConfigAndFonts();

+ +	//make pattern from font name

+ +	FcPattern* pat = FcNameParse((const FcChar8*)"LiberationMono-Regular");

+ +	FcConfigSubstitute(config, pat, FcMatchPattern);

+ +	FcDefaultSubstitute(pat);

+ +	char* fontFile = NULL;

+ +	// find the font

+ +	FcResult result;

+ +	font_file = FcFontMatch(config, pat, &result);

+ +	if (font_file)

+ +	{

+ +		FcChar8* file = NULL;

+ +		if (FcPatternGetString(font_file, FC_FILE, 0, &file) == FcResultMatch)

+ +		{

+ +			//we found the font

+ +			//This might be a fallback font

+ +      fontFile = (char *) file;

+ +		}

+ +	}

+ +	FcPatternDestroy(pat);

+ +  FcConfigDestroy(config);

+ +  return fontFile;

+ +}

+ +

+ +void free_font_file()

+ +{

+ +  if (font_file != NULL)

+ +  {

+ +    FcPatternDestroy(font_file);

+ +  }

+ +}

+ diff -urN lcdtest-1.18-old/src/get_font_file.h lcdtest-1.18/src/get_font_file.h

+ --- lcdtest-1.18-old/src/get_font_file.h	1970-01-01 01:00:00.000000000 +0100

+ +++ lcdtest-1.18/src/get_font_file.h	2019-11-20 23:03:04.194198571 +0100

+ @@ -0,0 +1,5 @@

+ +#ifndef GETFONTFILE_H

+ +#define GETFONTFILE_H

+ +const char *get_font_file();

+ +void free_font_file();

+ +#endif

+ Binary files lcdtest-1.18-old/src/.get_font_gile.c.swp and lcdtest-1.18/src/.get_font_gile.c.swp differ

+ diff -urN lcdtest-1.18-old/src/lcdtest.c lcdtest-1.18/src/lcdtest.c

+ --- lcdtest-1.18-old/src/lcdtest.c	2019-11-20 21:55:43.769742357 +0100

+ +++ lcdtest-1.18/src/lcdtest.c	2019-11-20 23:07:59.139626577 +0100

+ @@ -33,6 +33,8 @@

+  #include <SDL/SDL_image.h>

+  #include <SDL/SDL_ttf.h>

+  

+ +#include "get_font_file.h"

+ +

+  #define UNUSED __attribute__ ((unused))

+  

+  #define QMAKESTR(x) #x

+ @@ -742,8 +744,6 @@

+  }

+  

+  

+ -const char font_path [] = "/usr/share/fonts/liberation/LiberationMono-Regular.ttf";

+ -

+  int main (int argc, char *argv [])

+  {

+    SDL_Surface *screen;

+ @@ -756,6 +756,13 @@

+  

+    progname = argv [0];

+  

+ +  const char *font_path = get_font_file ("LiberationMono-Regular");

+ +  if (font_path == 0)

+ +  {

+ +    fatal (5, "Could not fint LiberationMono-Regular font\n");

+ +  }

+ +  atexit (free_font_file);

+ +

+    if (SDL_Init (SDL_INIT_VIDEO) < 0)

+      fatal (2, "SDL initialization error %s\n", SDL_GetError ());

+    atexit (SDL_Quit);

+ Binary files lcdtest-1.18-old/src/.lcdtest.c.swp and lcdtest-1.18/src/.lcdtest.c.swp differ

+ diff -urN lcdtest-1.18-old/src/SConscript lcdtest-1.18/src/SConscript

+ --- lcdtest-1.18-old/src/SConscript	2019-11-20 21:55:43.769742357 +0100

+ +++ lcdtest-1.18/src/SConscript	2019-11-20 23:09:31.968243555 +0100

+ @@ -25,7 +25,7 @@

+  #-----------------------------------------------------------------------------

+  

+  headers = []

+ -srcs = Split ("""lcdtest.c""")

+ +srcs = Split ("""lcdtest.c get_font_file.c""")

+  

+  objs = [env.Object(src) for src in srcs]

+  

+ @@ -37,7 +37,7 @@

+  else:

+      env.Append (CCFLAGS = ['-g', '-Wall', '-Wextra'])

+  

+ -env.Append (LIBS = ['SDL', 'SDL_image', 'SDL_ttf']);

+ +env.Append (LIBS = ['SDL', 'SDL_image', 'SDL_ttf', 'fontconfig']);

+  

+  env.Append (CPPDEFINES = [ ('RELEASE', env ['RELEASE'])])

+  

lcdtest.spec
file modified
+9 -1

@@ -1,12 +1,15 @@

  Name:           lcdtest

  URL:            http://www.brouhaha.com/~eric/software/lcdtest/

  Version:        1.18

- Release:        22%{?dist}

+ Release:        23%{?dist}

  License:        GPLv3

  Summary:        Displays monitor test patterns

  Source:         http://www.brouhaha.com/~eric/software/%{name}/download/%{name}-%{version}.tar.gz

  

+ Patch0:         0001-RobustFontPath.patch

+ 

  Requires:       liberation-mono-fonts

+ Requires:       fontconfig

  

  BuildRequires:  gcc

  BuildRequires:  scons >= 1.2.0

@@ -14,6 +17,7 @@

  BuildRequires:  SDL_ttf-devel

  BuildRequires:  netpbm-progs

  BuildRequires:  desktop-file-utils

+ BuildRequires:  fontconfig-devel

  

  %description

  lcdtest is a utility to display LCD monitor test patterns.  It may be

@@ -23,6 +27,7 @@

  

  %prep

  %setup -q

+ %patch0 -p1

  

  %build

  scons %{_smp_mflags} CFLAGS="%{optflags}"

@@ -47,6 +52,9 @@

  %{_datadir}/pixmaps/%{name}.svg

  

  %changelog

+ * Wed Nov 20 2019 Morian Sonnet <MorianSonnet@googlemail.com> - 1.18-23

+ - Add patch to automatically determine font path

+ 

  * Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.18-22

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

  

no initial comment

From Fedora 30 to Fedora 31 the font path for LiberationMono-Regular.ttf changed from /usr/share/fonts/liberation/LiberationMono-Regular.ttf to
/usr/share/fonts/liberation-mono/LiberationMono-Regular.ttf.

As the font file path is hardcoded in the code of lcdtest, the program does not work anymore as expected, see bug report.

This pull request adds code to determine the font file path using fontconfig. This approach was chosen over the change of the hardcoded path to make the package more robust against possible changes of the file paths as seen inf F30->F31.

As the current version of lcdtest in the Fedora 31 Repo is broken, this should also be merged into the appropriate branch.

Pull-Request has been merged by brouhaha

2 months ago