[gtksourceview/wip/chergert/gsv-gtk4: 142/144] fonts: bundle BuilderBlocks
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 142/144] fonts: bundle BuilderBlocks
- Date: Fri, 6 Mar 2020 23:55:40 +0000 (UTC)
commit e8c73ef3eaa28a4a5c8d69f34103a6539e257c84
Author: Christian Hergert <chergert redhat com>
Date: Thu Jan 30 09:08:36 2020 -0800
fonts: bundle BuilderBlocks
If we have fontconfig and pangoft2, we can override the font that is used
within the GtkSourceMap to be our "block" font. This is much more readable
than the scaled down 1pt font we fallback to. It is also faster to raster.
This, in practice, will only work where those libraries are available but
certainly covers Linux and BSD. Possibly covers Mac (needs testing) and
optionally covers Windows.
Other font loaders would be happily accepted.
data/fonts/BuilderBlocks.ttf | Bin 0 -> 444 bytes
data/fonts/BuilderBlocks.ttx | 137 +++++++++++++++++++++++++++++++++++++++++++
data/meson.build | 5 ++
gtksourceview/gtksourcemap.c | 55 +++++++++++++++++
gtksourceview/meson.build | 2 +
meson.build | 4 ++
6 files changed, 203 insertions(+)
---
diff --git a/data/fonts/BuilderBlocks.ttf b/data/fonts/BuilderBlocks.ttf
new file mode 100644
index 00000000..8fe89420
Binary files /dev/null and b/data/fonts/BuilderBlocks.ttf differ
diff --git a/data/fonts/BuilderBlocks.ttx b/data/fonts/BuilderBlocks.ttx
new file mode 100644
index 00000000..23c47c40
--- /dev/null
+++ b/data/fonts/BuilderBlocks.ttx
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.4">
+
+ <GlyphOrder>
+ <!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
+ <GlyphID id="0" name=".notdef"/>
+ <GlyphID id="1" name="block"/>
+ <GlyphID id="2" name="empty"/>
+ <GlyphID id="3" name="smallblock"/>
+ </GlyphOrder>
+
+ <head>
+ <!-- Most of this table will be recalculated by the compiler -->
+ <tableVersion value="1.0"/>
+ <fontRevision value="1.0"/>
+ <checkSumAdjustment value="0x2a3f4cae"/>
+ <magicNumber value="0x5f0f3cf5"/>
+ <flags value="00000000 00000010"/>
+ <unitsPerEm value="2048"/>
+ <created value="Mon Oct 7 00:00:00 2013"/>
+ <modified value="Fri Jan 31 15:45:50 2014"/>
+ <xMin value="0"/>
+ <yMin value="0"/>
+ <xMax value="0"/>
+ <yMax value="0"/>
+ <macStyle value="00000000 00000000"/>
+ <lowestRecPPEM value="1"/>
+ <fontDirectionHint value="2"/>
+ <indexToLocFormat value="0"/>
+ <glyphDataFormat value="0"/>
+ </head>
+
+ <hhea>
+ <tableVersion value="1.0"/>
+ <ascent value="2048"/>
+ <descent value="0"/>
+ <lineGap value="0"/>
+ <advanceWidthMax value="20480"/>
+ <minLeftSideBearing value="0"/>
+ <minRightSideBearing value="0"/>
+ <xMaxExtent value="0"/>
+ <caretSlopeRise value="1"/>
+ <caretSlopeRun value="0"/>
+ <caretOffset value="0"/>
+ <reserved0 value="0"/>
+ <reserved1 value="0"/>
+ <reserved2 value="0"/>
+ <reserved3 value="0"/>
+ <metricDataFormat value="0"/>
+ <numberOfHMetrics value="2"/>
+ </hhea>
+
+ <maxp>
+ <!-- Most of this table will be recalculated by the compiler -->
+ <tableVersion value="0x10000"/>
+ <numGlyphs value="4"/>
+ <maxPoints value="0"/>
+ <maxContours value="0"/>
+ <maxCompositePoints value="0"/>
+ <maxCompositeContours value="0"/>
+ <maxZones value="1"/>
+ <maxTwilightPoints value="0"/>
+ <maxStorage value="0"/>
+ <maxFunctionDefs value="0"/>
+ <maxInstructionDefs value="0"/>
+ <maxStackElements value="0"/>
+ <maxSizeOfInstructions value="0"/>
+ <maxComponentElements value="0"/>
+ <maxComponentDepth value="0"/>
+ </maxp>
+
+ <hmtx>
+ <mtx name=".notdef" width="1024" lsb="0"/>
+ <mtx name="block" width="1024" lsb="0"/>
+ <mtx name="empty" width="1024" lsb="0"/>
+ <mtx name="smallblock" width="1024" lsb="0"/>
+ </hmtx>
+
+ <loca>
+ </loca>
+
+ <glyf> <!-- Will result in empty table -->
+ <TTGlyph name=".notdef"/>
+ <TTGlyph name="empty"/>
+ <TTGlyph name="block">
+ <contour>
+ <pt x="0" y="0" on="1"/>
+ <pt x="1024" y="0" on="1"/>
+ <pt x="1024" y="2048" on="1"/>
+ <pt x="0" y="2048" on="1"/>
+ </contour>
+ <instructions><assembly></assembly></instructions>
+ </TTGlyph>
+ <TTGlyph name="smallblock">
+ <contour>
+ <pt x="0" y="0" on="1"/>
+ <pt x="1024" y="0" on="1"/>
+ <pt x="1024" y="1024" on="1"/>
+ <pt x="0" y="1024" on="1"/>
+ </contour>
+ <instructions><assembly></assembly></instructions>
+ </TTGlyph>
+ </glyf>
+
+ <name>
+ <namerecord nameID="0" platformID="1" platEncID="0" langID="0x0" unicode="True">
+ BuilderBlocks
+ </namerecord>
+ </name>
+
+ <cmap ERROR="">
+ <!-- Hand-coded format13 table mapping all Unicode
+ characters to glyph00001. -->
+ <hexdata>
+ 0000 0001 <!-- version numTables -->
+ 0003 000A <!-- platformID encodingID -->
+ 0000000C <!-- offset -->
+ 000D 0000 <!-- format reserved -->
+ 00000040 <!-- length -->
+ 00000000 <!-- language -->
+ 00000004 <!-- nGroups -->
+ 00000001 <!-- startCharCode -->
+ 00000020 <!-- endCharCode -->
+ 00000002 <!-- glyphID -->
+ 00000021 <!-- startCharCode -->
+ 00000060 <!-- endCharCode -->
+ 00000001 <!-- glyphID -->
+ 00000061 <!-- startCharCode -->
+ 0000007A <!-- endCharCode -->
+ 00000003 <!-- glyphID -->
+ 0000007B <!-- startCharCode -->
+ 0010FFFE <!-- endCharCode -->
+ 00000001 <!-- glyphID -->
+ </hexdata>
+ </cmap>
+
+</ttFont>
diff --git a/data/meson.build b/data/meson.build
index 45387d48..a5164d34 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -19,3 +19,8 @@ install_subdir('styles',
'testdark.xml',
'update-pot.sh' ]
)
+
+install_subdir('fonts',
+ install_dir: pkgdatadir,
+ exclude_files: [ 'BuilderBlocks.ttx' ]
+)
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index f820ffe6..92ea548b 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -20,6 +20,12 @@
#include <string.h>
+#if ENABLE_FONT_CONFIG
+# include <fontconfig/fontconfig.h>
+# include <pango/pangocairo.h>
+# include <pango/pangofc-fontmap.h>
+#endif
+
#include "gtksourcemap.h"
#include "gtksourcebuffer.h"
#include "gtksourcecompletion.h"
@@ -181,6 +187,44 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMap, gtk_source_map, GTK_SOURCE_TYPE_VIEW)
static GParamSpec *properties[N_PROPERTIES];
+#if ENABLE_FONT_CONFIG
+static FcConfig *map_font_config;
+
+static void
+load_override_font (GtkSourceMap *map)
+{
+ PangoFontDescription *font_desc;
+ PangoFontMap *font_map;
+
+ if (g_once_init_enter (&map_font_config))
+ {
+ const gchar *font_path = PACKAGE_DATADIR"/fonts/BuilderBlocks.ttf";
+ FcConfig *config = FcInitLoadConfigAndFonts ();
+
+ if (!g_file_test (font_path, G_FILE_TEST_IS_REGULAR))
+ g_debug ("\"%s\" is missing or inaccessible", font_path);
+
+ FcConfigAppFontAddFile (config, (const FcChar8 *)font_path);
+
+ g_once_init_leave (&map_font_config, config);
+ }
+
+ font_map = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
+ pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (font_map), map_font_config);
+ gtk_widget_set_font_map (GTK_WIDGET (map), font_map);
+ font_desc = pango_font_description_from_string ("Builder Blocks 1");
+
+ g_assert (map_font_config != NULL);
+ g_assert (font_map != NULL);
+ g_assert (font_desc != NULL);
+
+ g_object_set (map, "font-desc", font_desc, NULL);
+
+ pango_font_description_free (font_desc);
+ g_object_unref (font_map);
+}
+#endif
+
static void
update_scrubber_position (GtkSourceMap *map)
{
@@ -1030,6 +1074,16 @@ gtk_source_map_hide (GtkWidget *widget)
}
}
+static void
+gtk_source_map_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (gtk_source_map_parent_class)->constructed (object);
+
+#ifdef ENABLE_FONT_CONFIG
+ load_override_font (GTK_SOURCE_MAP (object));
+#endif
+}
+
static void
gtk_source_map_class_init (GtkSourceMapClass *klass)
{
@@ -1037,6 +1091,7 @@ gtk_source_map_class_init (GtkSourceMapClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
+ object_class->constructed = gtk_source_map_constructed;
object_class->get_property = gtk_source_map_get_property;
object_class->set_property = gtk_source_map_set_property;
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index e0f3945d..83bfc646 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -115,6 +115,8 @@ core_deps = [
gio_dep,
gtk_dep,
libxml_dep,
+ pangoft2_dep,
+ fontconfig_dep,
]
if config_h.has('OS_OSX')
diff --git a/meson.build b/meson.build
index 53480da3..2bf58e3d 100644
--- a/meson.build
+++ b/meson.build
@@ -84,6 +84,8 @@ gio_dep = dependency('gio-2.0', version: glib_req)
gtk_dep = dependency('gtk4', version: gtk_req)
libxml_dep = dependency('libxml-2.0', version: libxml_req, required: cc.get_id() != 'msvc')
fribidi_dep = dependency('fribidi', version: fribidi_req)
+fontconfig_dep = dependency('fontconfig', required: false)
+pangoft2_dep = dependency('pangoft2', required: false)
gtk_quartz_dep = dependency('gtk4-quartz', version: gtk_doc_req, required: false)
@@ -140,9 +142,11 @@ add_project_arguments([
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', package_string)
config_h.set_quoted('DATADIR', datadir)
+config_h.set_quoted('PACKAGE_DATADIR', pkgdatadir)
config_h.set_quoted('GSV_API_VERSION_S', api_version)
config_h.set('GSV_API_VERSION', api_version)
config_h.set('PACKAGE_VERSION', version)
+config_h.set10('ENABLE_FONT_CONFIG', fontconfig_dep.found() and pangoft2_dep.found())
check_headers = [
['unistd.h', 'HAVE_UNISTD_H'],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]