[gtksourceview/wip/font: 17/17] Use a custom font for the overview map
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/font: 17/17] Use a custom font for the overview map
- Date: Fri, 25 Mar 2016 11:59:15 +0000 (UTC)
commit 83c7013d8b569abd0c0bcc46ae273bde050a6a39
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Feb 9 18:39:19 2016 +0100
Use a custom font for the overview map
Add the BuilderBlocks font that was used in Builder.
configure.ac | 1 +
data/Makefile.am | 2 +-
data/fonts/BuilderBlocks.ttf | Bin 0 -> 388 bytes
data/fonts/BuilderBlocks.ttx | 120 ++++++++++++++++++++++++++++++++++++++++++
data/fonts/Makefile.am | 6 ++
gtksourceview/gtksourcemap.c | 77 +++++++++++++++++++++++----
6 files changed, 195 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c04c94c..82d52af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -233,6 +233,7 @@ build/win32/vs11/Makefile
build/win32/vs12/Makefile
build/win32/vs14/Makefile
data/Makefile
+data/fonts/Makefile
data/glade/Makefile
data/language-specs/Makefile
data/styles/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index d48ae4a..ecaa955 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = language-specs styles
+SUBDIRS = fonts language-specs styles
if GLADE_CATALOG
SUBDIRS += glade
diff --git a/data/fonts/BuilderBlocks.ttf b/data/fonts/BuilderBlocks.ttf
new file mode 100644
index 0000000..e7538a8
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 0000000..e3f7b29
--- /dev/null
+++ b/data/fonts/BuilderBlocks.ttx
@@ -0,0 +1,120 @@
+<?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"/>
+ </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="2"/>
+ <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"/>
+ </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>
+ </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 -->
+ 00000028 <!-- length -->
+ 00000000 <!-- language -->
+ 00000002 <!-- nGroups -->
+ 00000001 <!-- startCharCode -->
+ 00000020 <!-- endCharCode -->
+ 00000002 <!-- glyphID -->
+ 00000021 <!-- startCharCode -->
+ 0010FFFE <!-- endCharCode -->
+ 00000001 <!-- glyphID -->
+ </hexdata>
+ </cmap>
+
+</ttFont>
diff --git a/data/fonts/Makefile.am b/data/fonts/Makefile.am
new file mode 100644
index 0000000..036ef5f
--- /dev/null
+++ b/data/fonts/Makefile.am
@@ -0,0 +1,6 @@
+fontdir = $(datadir)/gtksourceview-3.0/fonts
+
+dist_font_DATA = \
+ BuilderBlocks.ttf
+
+-include $(top_srcdir)/git.mk
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 2e7265e..e6a2666 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -29,6 +29,7 @@
#include "gtksourcestyle-private.h"
#include "gtksourcestylescheme.h"
#include "gtksourceview-utils.h"
+#include <pango/pangofc-fontmap.h>
/**
* SECTION:map
@@ -100,8 +101,8 @@
* embedding fonts in the application, so it is at least possible to bundle
* our own font as a resource.
*
- * By default we use a 1pt Monospace font. However, if the Gtksourcemap:font-desc
- * property is set, we will use that instead.
+ * By default we use a 1pt custom font that shows rectangles. However,
+ * if the Gtksourcemap:font-desc property is set, we will use that instead.
*
* We do not render the background grid as it requires a bunch of
* cpu time for something that will essentially just create a solid
@@ -123,17 +124,15 @@
typedef struct
{
/*
- * By default, we use "Monospace 1pt". However, most text editing
- * applications will have a custom font, so we allow them to set
- * that here. Generally speaking, you will want to continue using
- * a 1pt font, but if they set GtkSourceMap:font-desc, then they
+ * By default, we use a custom "BuilderBlocks 1pt" font that is
+ * designed just for the case of drawing the overview.
+ * However, if an application wants to use another font, it can
+ * be set here. Generally speaking, you will want to continue using
+ * a 1pt font, and if you set GtkSourceMap:font-desc, then you
* should also shrink the font to the desired size.
*
* For example:
* pango_font_description_set_size(font_desc, 1 * PANGO_SCALE);
- *
- * Would set a 1pt font on whatever PangoFontDescription you have
- * in your text editor.
*/
PangoFontDescription *font_desc;
@@ -1057,6 +1056,54 @@ gtk_source_map_realize (GtkWidget *widget)
set_view_cursor (GTK_SOURCE_MAP (widget));
}
+static PangoFontMap *font_map;
+
+static gchar *
+get_font_path (void)
+{
+ gchar *font_path;
+#ifdef G_OS_WIN32
+ gchar *module_path;
+
+ module_path = g_win32_get_package_installation_directory_of_module (NULL);
+ font_path = g_build_filename (module_path, "share", "gtksourceview-3.0", "fonts",
"BuilderBlocks.ttf", NULL);
+ g_free (module_path);
+#else
+ font_path = g_build_filename (DATADIR, "gtksourceview-3.0", "fonts", "BuilderBlocks.ttf", NULL);
+#endif
+
+ if (!g_file_test (font_path, G_FILE_TEST_EXISTS))
+ {
+ g_clear_pointer (&font_path, g_free);
+ }
+
+ return font_path;
+}
+
+static void
+load_custom_font (void)
+{
+ gchar *font_path;
+
+ font_path = get_font_path ();
+
+ if (font_path != NULL)
+ {
+ font_map = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
+ if (font_map != NULL)
+ {
+ FcConfig *config;
+
+ config = FcInitLoadConfigAndFonts ();
+
+ FcConfigAppFontAddFile (config, (const FcChar8 *)font_path);
+ g_free (font_path);
+
+ pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (font_map), config);
+ }
+ }
+}
+
static void
gtk_source_map_class_init (GtkSourceMapClass *klass)
{
@@ -1093,6 +1140,8 @@ gtk_source_map_class_init (GtkSourceMapClass *klass)
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, LAST_PROP, pspecs);
+
+ load_custom_font ();
}
static void
@@ -1129,7 +1178,15 @@ gtk_source_map_init (GtkSourceMap *map)
completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (map));
gtk_source_completion_block_interactive (completion);
- gtk_source_map_set_font_name (map, "Monospace 1");
+ if (font_map != NULL)
+ {
+ gtk_widget_set_font_map (GTK_WIDGET (map), font_map);
+ gtk_source_map_set_font_name (map, "BuilderBlocks 1");
+ }
+ else
+ {
+ gtk_source_map_set_font_name (map, "Monospace 1");
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]