Try to improve font rendering on Windows by using freetype for pango/cairo. v2.13.105
authorCarl Hetherington <cth@carlh.net>
Tue, 22 Jan 2019 23:34:20 +0000 (23:34 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 23 Jan 2019 00:00:48 +0000 (00:00 +0000)
fonts/fonts.conf [new file with mode: 0644]
hacks/.gitignore
hacks/fonts.conf [new file with mode: 0644]
hacks/text-win.sh [new file with mode: 0644]
hacks/text.cc [new file with mode: 0644]
hacks/text.sh [new file with mode: 0644]
platform/windows/wscript
src/lib/render_text.cc
src/lib/util.cc

diff --git a/fonts/fonts.conf b/fonts/fonts.conf
new file mode 100644 (file)
index 0000000..2f04037
--- /dev/null
@@ -0,0 +1,4 @@
+<fontconfig>
+<dir>C:\windows\fonts</dir>
+</fontconfig>
+
index 01dc078a3fe4e70e055e85b86886b9a07801cf4c..fbadc130feddecf307e9e9aff9958adff7303458 100644 (file)
@@ -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 (file)
index 0000000..2f04037
--- /dev/null
@@ -0,0 +1,4 @@
+<fontconfig>
+<dir>C:\windows\fonts</dir>
+</fontconfig>
+
diff --git a/hacks/text-win.sh b/hacks/text-win.sh
new file mode 100644 (file)
index 0000000..62e6fed
--- /dev/null
@@ -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 (file)
index 0000000..bf391a3
--- /dev/null
@@ -0,0 +1,59 @@
+#include <cairomm/cairomm.h>
+#include <pangomm.h>
+#include <pangomm/init.h>
+#include <glibmm.h>
+#include <stdint.h>
+
+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<Cairo::ImageSurface> 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<Cairo::Context> context = Cairo::Context::create (surface);
+
+       Glib::RefPtr<Pango::Layout> 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 (file)
index 0000000..f24e9be
--- /dev/null
@@ -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
index 5dc9cf1822023dd6a6c8efe67a291042b21edb5f..3b8892997b2b61e5b74e7f6a2aabe2ea85abb745 100644 (file)
@@ -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"
index 2619b5d0db969fd49ea4a7c9038388a6cab14a3f..7ae7d91524ddd3d6a03b2eb90cac8d4f8507172f 100644 (file)
@@ -244,10 +244,6 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > 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;
index cd2d2e753b3827c74e6491c49583b2595c97ed7f..ac1c96f975f9318f5b9588b9c6b37f0f724d6f59 100644 (file)
@@ -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 ();