Commit fe5dfd2e authored by Victor Ananjevsky's avatar Victor Ananjevsky

add pfd utility

parent 16f28e71
......@@ -23,4 +23,5 @@ po/*.gmo
po/stamp-it
src/yad
src/yad-icon-browser
src/pfd
stamp-h1
......@@ -126,6 +126,18 @@ if test x$have_sourceview = xyes; then
AC_DEFINE([HAVE_SOURCEVIEW], [1], [Define this if you need GtkSourceView support])
fi
dnl pfd
AC_ARG_ENABLE([pfd],
[AS_HELP_STRING([--enable-pfd],
[Build pfd utility])],
[build_pfd=$enableval], [build_pfd=yes])
if test x$build_pfd = xyes; then
PKG_CHECK_MODULES([PFD], [pango], [build_pfd=yes], [build_pfd=no])
fi
AC_SUBST([PFD_CFLAGS])
AC_SUBST([PFD_LIBS])
AM_CONDITIONAL([BUILD_PFD], [test x$build_pfd = xyes])
dnl icon browser
AC_ARG_ENABLE([icon-browser],
[AS_HELP_STRING([--enable-icon-browser],
......@@ -177,5 +189,6 @@ echo " HTML widget - $have_html"
echo " Spell checking - $have_spell"
echo " GtkSourceView - $have_sourceview"
echo " GIO support - $have_gio"
echo " pfd - $build_pfd"
echo " Icon browser - $build_ib"
echo
......@@ -8,6 +8,9 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
endif
dist_man_MANS = yad.1
if BUILD_PFD
dist_man_MANS += pfd.1
endif
m4dir = $(datadir)/aclocal
m4_DATA = yad.m4
......
.TH PFD "1" "February 2019" "pfd" "User Commands"
.SH NAME
pfd \- convert font description between xft and pango formats
.SH SYNOPSIS
.B pfd
.RI [ OPTIONS ] FONT
.SH DESCRIPTION
\fBpfd\fR is a small command-line utility to transform font names from pango to xft specification and vice versa.
.SH OPTIONS
.TP
\fB\-x\fR, \fB\-\-xft\fR
Print font name in xft format. This is default.
.TP
\fB\-p\fR, \fB\-\-pango\fR
Print font name in pango format.
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help.
.TP
\fB\-v\fR, \fB\-\-version\fR
Print current version.
......@@ -20,4 +20,5 @@ src/color.c
src/text.c
src/browser.c
src/notebook.c
src/pfd.c
data/yad-icon-browser.desktop.in
......@@ -37,6 +37,14 @@ endif
yad_CFLAGS = $(GTK_CFLAGS) $(HTML_CFLAGS) $(SPELL_CFLAGS) $(SOURCEVIEW_CFLAGS)
yad_LDADD = $(GTK_LIBS) $(HTML_LIBS) $(SPELL_LIBS) $(SOURCEVIEW_LIBS)
if BUILD_PFD
bin_PROGRAMS += pfd
pfd_SOURCES = pfd.c
pfd_CFLAGS = $(PFD_CFLAGS)
pfd_LDADD = $(PFD_LIBS)
endif
if BUILD_IB
bin_PROGRAMS += yad-icon-browser
......
/*
* This file is part of YAD.
*
* YAD is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* YAD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2019, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <config.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <pango/pango.h>
typedef enum {
PANGO_SPEC,
XFT_SPEC
} FontType;
static FontType font_type = XFT_SPEC;
static gboolean
set_type (const gchar *name, const gchar *val, gpointer d, GError **err)
{
gint i = 1;
if (name[i] == '-')
i = 2;
if (name[i] == 'p')
font_type = PANGO_SPEC;
else if (name[i] == 'x')
font_type = XFT_SPEC;
else
return FALSE;
return TRUE;
}
static gchar *
parse_font (gchar *fn)
{
gchar **fnt;
gint i = 1;
GString *pfd = g_string_new (NULL);
fnt = g_strsplit (fn, ":", -1);
if (g_ascii_strcasecmp (fnt[0], "xft") != 0)
return fnt[0];
while (fnt[i])
{
if (g_ascii_strncasecmp (fnt[i], "style=", 6) == 0)
g_string_append_printf (pfd, "%s ", fnt[i] + 6);
else if (g_ascii_strncasecmp (fnt[i], "size=", 5) == 0)
g_string_append_printf (pfd, "%s ", fnt[i] + 5);
else if (g_ascii_strncasecmp (fnt[i], "pixelsize=", 10) == 0)
g_string_append_printf (pfd, "%spx ", fnt[i] + 10);
else
g_string_append_printf (pfd, "%s ", fnt[i]);
i++;
}
return pfd->str;
}
static gchar **fonts = NULL;
static gboolean ver = FALSE;
static GOptionEntry ents[] = {
{ "xft", 'x', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, set_type, N_("Print font name in xft format"), NULL },
{ "pango", 'p', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, set_type, N_("Print font name in pango format"), NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &ver, N_("Print version"), NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &fonts, 0, N_("FONT") },
{ NULL }
};
int
main (int argc, char *argv[])
{
GOptionContext *ctx;
GError *err = NULL;
PangoFontDescription *fnd = NULL;
setlocale (LC_ALL, "");
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
ctx = g_option_context_new (_("- convert font description"));
g_option_context_add_main_entries (ctx, ents, GETTEXT_PACKAGE);
if (!g_option_context_parse (ctx, &argc, &argv, &err))
{
g_printerr (_("option parsing failed: %s\n"), err->message);
return 1;
}
if (ver)
{
g_print ("%s\n", VERSION);
return 0;
}
if (!fonts || !fonts[0])
{
g_printerr (_("no font specified\n"));
return 1;
}
/* parse font */
fnd = pango_font_description_from_string (parse_font (fonts[0]));
if (!fnd)
{
g_printerr (_("cannot get font description for for string \"%s\"\n"), fonts[0]);
return 1;
}
/* print font */
switch (font_type)
{
case PANGO_SPEC:
g_print ("%s\n", pango_font_description_to_string (fnd));
break;
case XFT_SPEC:
{
PangoFontMask mask = pango_font_description_get_set_fields (fnd);
if (mask & PANGO_FONT_MASK_FAMILY)
g_print ("xft:%s", pango_font_description_get_family (fnd));
else
g_print ("xft:Sans"); /* simple default */
if (mask & PANGO_FONT_MASK_WEIGHT)
{
switch (pango_font_description_get_weight (fnd))
{
case PANGO_WEIGHT_THIN:
g_print (":Thin");
break;
case PANGO_WEIGHT_ULTRALIGHT:
g_print (":Ultralight");
break;
case PANGO_WEIGHT_LIGHT:
g_print (":Light");
break;
case PANGO_WEIGHT_SEMILIGHT:
g_print (":Semilight");
break;
case PANGO_WEIGHT_BOOK:
g_print (":Book");
break;
case PANGO_WEIGHT_NORMAL:
break;
case PANGO_WEIGHT_MEDIUM:
g_print (":Medium");
break;
case PANGO_WEIGHT_SEMIBOLD:
g_print (":Semibold");
break;
case PANGO_WEIGHT_BOLD:
g_print (":Bold");
break;
case PANGO_WEIGHT_ULTRABOLD:
g_print (":Ultrabold");
break;
case PANGO_WEIGHT_HEAVY:
g_print (":Heavy");
break;
case PANGO_WEIGHT_ULTRAHEAVY:
g_print (":Ultraheavy");
break;
}
}
if (mask & PANGO_FONT_MASK_STYLE)
{
switch (pango_font_description_get_style (fnd))
{
case PANGO_STYLE_NORMAL:
break;
case PANGO_STYLE_OBLIQUE:
g_print (":Oblique");
break;
case PANGO_STYLE_ITALIC:
g_print (":Italic");
break;
}
}
if (mask & PANGO_FONT_MASK_SIZE)
{
if (pango_font_description_get_size_is_absolute (fnd))
g_print (":pixelsize=%d", pango_font_description_get_size (fnd) / PANGO_SCALE);
else
g_print (":size=%d", pango_font_description_get_size (fnd) / PANGO_SCALE);
}
g_print ("\n");
break;
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment