From: Carl Hetherington Date: Tue, 22 Jan 2019 23:34:20 +0000 (+0000) Subject: Try to improve font rendering on Windows by using freetype for pango/cairo. X-Git-Tag: v2.13.105^0 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=d702ba9f67da8a08277f83ec692bf6b90736b243 Try to improve font rendering on Windows by using freetype for pango/cairo. --- diff --git a/fonts/fonts.conf b/fonts/fonts.conf new file mode 100644 index 000000000..2f0403761 --- /dev/null +++ b/fonts/fonts.conf @@ -0,0 +1,4 @@ + +C:\windows\fonts + + diff --git a/hacks/.gitignore b/hacks/.gitignore index 01dc078a3..fbadc130f 100644 --- a/hacks/.gitignore +++ b/hacks/.gitignore @@ -16,3 +16,8 @@ subtitle_alignment/dcp_4/info subtitle_alignment/dcp_4/log subtitle_alignment/dcp_4/video pixfmts +*.dll +text.png +text +text.exe +LOCAL_APPDATA_FONTCONFIG_CACHE diff --git a/hacks/fonts.conf b/hacks/fonts.conf new file mode 100644 index 000000000..2f0403761 --- /dev/null +++ b/hacks/fonts.conf @@ -0,0 +1,4 @@ + +C:\windows\fonts + + diff --git a/hacks/text-win.sh b/hacks/text-win.sh new file mode 100644 index 000000000..62e6fed4c --- /dev/null +++ b/hacks/text-win.sh @@ -0,0 +1 @@ +/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-g++ -o text.exe text.cc $(/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-pkg-config pkg-config --cflags --libs cairomm-1.0 glibmm-2.4 pangomm-1.4) diff --git a/hacks/text.cc b/hacks/text.cc new file mode 100644 index 000000000..bf391a325 --- /dev/null +++ b/hacks/text.cc @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +int main () +{ +#ifdef __MINGW32__ + putenv ("PANGOCAIRO_BACKEND=fontconfig"); + putenv ("FONTCONFIG_PATH=."); +#endif + + Pango::init (); + + int const width = 640; + int const height = 480; + uint8_t* data = new uint8_t[width * height * 4]; + + Cairo::RefPtr surface = Cairo::ImageSurface::create ( + data, + Cairo::FORMAT_ARGB32, + width, height, + /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */ + Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, width) + ); + + Cairo::RefPtr context = Cairo::Context::create (surface); + + Glib::RefPtr layout = Pango::Layout::create (context); + + context->set_source_rgb (1, 0.2, 0.3); + context->rectangle (0, 0, width, height); + context->fill (); + + layout->set_alignment (Pango::ALIGN_LEFT); + + context->set_line_width (1); + // Cairo::FontOptions fo; + // context->get_font_options (fo); + // fo.set_antialias (Cairo::ANTIALIAS_NONE); + // context->set_font_options (fo); + + Pango::FontDescription font ("Arial"); + layout->set_font_description (font); + layout->set_markup ("Hello world!"); + + layout->update_from_cairo_context (context); + + context->set_source_rgb (1, 1, 1); + context->set_line_width (0); + context->move_to (0, 0); + context->scale (2, 2); + layout->show_in_cairo_context (context); + + surface->write_to_png ("text.png"); + + return 0; +} diff --git a/hacks/text.sh b/hacks/text.sh new file mode 100644 index 000000000..f24e9be5c --- /dev/null +++ b/hacks/text.sh @@ -0,0 +1,3 @@ +#!/bin/bash +g++ -o text text.cc `pkg-config --cflags --libs cairomm-1.0 glibmm-2.4 pangomm-1.4` +docker run -u $USER -w $(pwd) -v $(pwd):$(pwd) -e PKG_CONFIG_PATH=/opt/mxe/usr/x86_64-w64-mingw32.shared/lib/pkgconfig -it windows /bin/bash text-win.sh diff --git a/platform/windows/wscript b/platform/windows/wscript index 5dc9cf182..3b8892997 100644 --- a/platform/windows/wscript +++ b/platform/windows/wscript @@ -290,6 +290,7 @@ SetOutPath "$INSTDIR" File "%resources%/../../fonts/LiberationSans-Regular.ttf" File "%resources%/../../fonts/LiberationSans-Italic.ttf" File "%resources%/../../fonts/LiberationSans-Bold.ttf" +File "%resources%/../../fonts/fonts.conf" File "%graphics%/splash.png" File "%graphics%/zoom.png" File "%graphics%/zoom_all.png" diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 2619b5d0d..7ae7d9152 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -244,10 +244,6 @@ render_line (list subtitles, list > fonts, dcp::Siz layout->set_alignment (Pango::ALIGN_LEFT); context->set_line_width (1); - Cairo::FontOptions fo; - context->get_font_options (fo); - fo.set_antialias (Cairo::ANTIALIAS_NONE); - context->set_font_options (fo); /* Compute fade factor */ float fade_factor = 1; diff --git a/src/lib/util.cc b/src/lib/util.cc index cd2d2e753..ac1c96f97 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -358,6 +358,11 @@ dcpomatic_setup () set_terminate (terminate); +#ifdef DCPOMATIC_WINDOWS + putenv ("PANGOCAIRO_BACKEND=fontconfig"); + putenv (String::compose("FONTCONFIG_PATH=%1", shared_path().string()).c_str()); +#endif + Pango::init (); dcp::init ();