2014-08-19 12:27:14 -07: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>
|
|
|
|
|
2014-08-26 10:25:49 -07:00
|
|
|
#include <util/base.h>
|
2014-08-19 12:27:14 -07:00
|
|
|
#include <util/dstr.h>
|
|
|
|
|
|
|
|
#include "find-font.h"
|
|
|
|
#include "text-freetype2.h"
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
void free_os_font_list(void) {}
|
2014-08-19 12:27:14 -07:00
|
|
|
|
2015-10-04 03:30:20 -07:00
|
|
|
bool load_cached_os_font_list(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
void load_os_font_list(void) {}
|
2014-08-19 12:27:14 -07:00
|
|
|
|
|
|
|
const char *get_font_path(const char *family, uint16_t size, const char *style,
|
2019-06-22 22:13:45 -07:00
|
|
|
uint32_t flags, FT_Long *idx)
|
2014-08-19 12:27:14 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
bool bold = !!(flags & OBS_FONT_BOLD);
|
|
|
|
bool italic = !!(flags & OBS_FONT_ITALIC);
|
2014-08-19 12:27:14 -07:00
|
|
|
FcPattern *pattern = FcPatternCreate();
|
2019-06-22 22:13:45 -07:00
|
|
|
FcPattern *match = NULL;
|
|
|
|
bool success = false;
|
|
|
|
FcResult match_result;
|
2014-08-19 12:27:14 -07:00
|
|
|
|
|
|
|
/* somewhat of a cheap hack */
|
|
|
|
static __thread char result[512];
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *)family);
|
|
|
|
FcPatternAddString(pattern, FC_STYLE, (const FcChar8 *)style);
|
2014-08-19 12:27:14 -07:00
|
|
|
FcPatternAddInteger(pattern, FC_WEIGHT,
|
2019-06-22 22:13:45 -07:00
|
|
|
bold ? FC_WEIGHT_BOLD : FC_WEIGHT_REGULAR);
|
2014-08-19 12:27:14 -07:00
|
|
|
FcPatternAddInteger(pattern, FC_SLANT,
|
2019-06-22 22:13:45 -07:00
|
|
|
italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
|
2014-08-19 12:27:14 -07:00
|
|
|
FcPatternAddDouble(pattern, FC_SIZE, (double)size);
|
|
|
|
|
|
|
|
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
|
|
|
|
FcDefaultSubstitute(pattern);
|
|
|
|
|
|
|
|
match = FcFontMatch(NULL, pattern, &match_result);
|
|
|
|
if (match) {
|
2019-06-22 22:13:45 -07:00
|
|
|
FcChar8 *path =
|
|
|
|
FcPatternFormat(match, (const FcChar8 *)"%{file}");
|
|
|
|
strncpy(result, (char *)path, 511);
|
2014-08-19 12:27:14 -07:00
|
|
|
FcStrFree(path);
|
|
|
|
|
|
|
|
int fc_index = 0;
|
|
|
|
FcPatternGetInteger(match, FC_INDEX, 1, &fc_index);
|
|
|
|
*idx = (FT_Long)fc_index;
|
|
|
|
|
|
|
|
FcPatternDestroy(match);
|
|
|
|
success = true;
|
2014-08-26 10:25:49 -07:00
|
|
|
} else {
|
2019-06-22 22:13:45 -07:00
|
|
|
blog(LOG_WARNING, "no matching font for '%s' found", family);
|
2014-08-19 12:27:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
FcPatternDestroy(pattern);
|
|
|
|
return success ? &result[0] : NULL;
|
|
|
|
}
|