yolobs-studio/plugins/text-freetype2/find-font-unix.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.2 KiB
C
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
/*
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fontconfig/fontconfig.h>
#include <util/base.h>
#include <util/dstr.h>
#include "find-font.h"
#include "text-freetype2.h"
2019-09-22 21:19:10 +00:00
void free_os_font_list(void) {}
2016-02-23 23:16:51 +00:00
bool load_cached_os_font_list(void)
{
return true;
}
2019-09-22 21:19:10 +00:00
void load_os_font_list(void) {}
2016-02-23 23:16:51 +00:00
const char *get_font_path(const char *family, uint16_t size, const char *style,
2019-09-22 21:19:10 +00:00
uint32_t flags, FT_Long *idx)
2016-02-23 23:16:51 +00:00
{
2019-09-22 21:19:10 +00:00
bool bold = !!(flags & OBS_FONT_BOLD);
bool italic = !!(flags & OBS_FONT_ITALIC);
2016-02-23 23:16:51 +00:00
FcPattern *pattern = FcPatternCreate();
2019-09-22 21:19:10 +00:00
FcPattern *match = NULL;
bool success = false;
FcResult match_result;
2016-02-23 23:16:51 +00:00
/* somewhat of a cheap hack */
static __thread char result[512];
2019-09-22 21:19:10 +00:00
FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *)family);
FcPatternAddString(pattern, FC_STYLE, (const FcChar8 *)style);
2016-02-23 23:16:51 +00:00
FcPatternAddInteger(pattern, FC_WEIGHT,
2019-09-22 21:19:10 +00:00
bold ? FC_WEIGHT_BOLD : FC_WEIGHT_REGULAR);
2016-02-23 23:16:51 +00:00
FcPatternAddInteger(pattern, FC_SLANT,
2019-09-22 21:19:10 +00:00
italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
2016-02-23 23:16:51 +00:00
FcPatternAddDouble(pattern, FC_SIZE, (double)size);
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
match = FcFontMatch(NULL, pattern, &match_result);
if (match) {
2019-09-22 21:19:10 +00:00
FcChar8 *path =
FcPatternFormat(match, (const FcChar8 *)"%{file}");
strncpy(result, (char *)path, 511);
2016-02-23 23:16:51 +00:00
FcStrFree(path);
int fc_index = 0;
FcPatternGetInteger(match, FC_INDEX, 1, &fc_index);
*idx = (FT_Long)fc_index;
FcPatternDestroy(match);
success = true;
} else {
2019-09-22 21:19:10 +00:00
blog(LOG_WARNING, "no matching font for '%s' found", family);
2016-02-23 23:16:51 +00:00
}
FcPatternDestroy(pattern);
return success ? &result[0] : NULL;
}