summaryrefslogtreecommitdiff
path: root/print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c
diff options
context:
space:
mode:
authorHiroki Sato <hrs@FreeBSD.org>2015-01-31 12:48:14 +0000
committerHiroki Sato <hrs@FreeBSD.org>2015-01-31 12:48:14 +0000
commit06be6f2de88d7c64bd5371c5c01cd27d9dbfb986 (patch)
treea405788599bab9ad7365316e1484954d9d847f81 /print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c
parent- Fix a bug that deactivate-input-method was not called in (diff)
- Add pTeX support to xdvik. This improvement is imported from
the latest j1.42 patchset by adjusting it to the 22.87 code base. - Move files in TEXMFDISTDIR/xdvi to TEXMFDISTDIR/dvips/xdvi.
Notes
Notes: svn path=/head/; revision=378203
Diffstat (limited to 'print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c')
-rw-r--r--print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c b/print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c
new file mode 100644
index 000000000000..24afa1fc6131
--- /dev/null
+++ b/print/tex-xdvik/files/patch-texk-xdvik-fontconfig.c
@@ -0,0 +1,95 @@
+--- /dev/null 2015-01-31 21:35:05.000000000 +0900
++++ texk/xdvik/fontconfig.c 2015-01-31 21:02:18.000000000 +0900
+@@ -0,0 +1,92 @@
++#include "xdvi-config.h"
++#include "xdvi.h"
++#include <stdio.h>
++#include "util.h"
++#include "string-utils.h"
++
++#ifdef PTEX
++#include "kpathsea/tex-file.h"
++
++#if HAVE_FONTCONFIG
++#include <fontconfig/fontconfig.h>
++
++char *fc_match(char *name)
++{
++ FcFontSet *fs;
++ FcPattern *pat;
++ FcResult result;
++ FcPattern *match;
++ char *ret = NULL;
++ static int inited = false;
++
++ if (!inited) {
++ if (FcInit() == 0) {
++ XDVI_WARNING((stderr, "fontconfig: Can't init library.\n"));
++ return NULL;
++ }
++ inited = true;
++ }
++
++ pat = FcNameParse((FcChar8 *)name);
++ FcConfigSubstitute(0, pat, FcMatchPattern);
++ FcDefaultSubstitute(pat);
++ fs = FcFontSetCreate();
++ match = FcFontMatch(0, pat, &result);
++ if (match != NULL) FcFontSetAdd(fs, match);
++ if (pat != NULL) FcPatternDestroy(pat);
++
++ if (fs != NULL) {
++ if (fs->nfont > 0) {
++ FcChar8 *file;
++ if (FcPatternGetString(fs->fonts[0], FC_FILE, 0, &file)
++ == FcResultMatch) {
++ ret = strdup(file);
++ }
++ }
++ FcFontSetDestroy(fs);
++ }
++ if (kpathsea_debug) {
++ fprintf(stderr, "fontconfig:fc_match(%s) => %s\n", name, ret);
++ }
++ return ret;
++}
++
++char *fc_convert(char *name) {
++ char *tmp, *s;
++
++ if (str_is_suffix(".otf", name, false)) return NULL;
++ if (str_is_suffix(".ttf", name, false)) return NULL;
++ if (str_is_suffix(".ttc", name, false)) return NULL;
++ tmp = strdup(name);
++ s = strstr(tmp, "-Light"); if (s != NULL) *s = '\0';
++ s = strstr(tmp, "-Medium"); if (s != NULL) *s = '\0';
++ s = strstr(tmp, "-Regular"); if (s != NULL) *s = '\0';
++ s = fc_match(tmp);
++ free(tmp);
++ return s;
++}
++#endif /* HAVE_FONTCONFIG */
++
++
++const char *get_ptex_font_pathname(char *name)
++{
++ char *s = NULL;
++ FILE *fp;
++
++ if ((fp=XFOPEN(name, "r")) != NULL) {
++ fclose(fp);
++ s = name;
++ }
++
++ if (s == NULL) s = kpse_find_file(name, kpse_opentype_format, true);
++ if (s == NULL) s = kpse_find_file(name, kpse_truetype_format, true);
++ if (s == NULL) s = kpse_find_file(name, kpse_miscfonts_format, true);
++ if (s == NULL) s = kpse_find_file(name, kpse_program_text_format, true);
++#if HAVE_FONTCONFIG
++ if (s == NULL) s = fc_convert(name);
++#endif /* HAVE_FONTCONFIG */
++ if (s == NULL) s = name;
++ return s;
++}
++
++#endif /* PTEX */