Corrected locale management.
This commit is contained in:
parent
8da3f06c96
commit
2c9df3c76c
|
@ -81,6 +81,10 @@ size_t fc_tounicode(wchar_t *dest, const FONTCHARACTER *src, size_t n);
|
|||
|
||||
int fc_setlocale(const char *locale);
|
||||
|
||||
/* List the available locales: */
|
||||
|
||||
int fc_listlocales(void (*callback)(void*, const char*), void *cookie);
|
||||
|
||||
# endif /* FC_DISABLED_REFERENCE */
|
||||
|
||||
# ifdef __cplusplus
|
||||
|
|
|
@ -46,7 +46,8 @@ extern const fc_locale_t fc_locales[];
|
|||
extern const fc_locale_t *fc_locale;
|
||||
|
||||
/* get an entry */
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode);
|
||||
const fc_locale_t *fc_get_locale(const char *name);
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode, const fc_locale_t *locale);
|
||||
|
||||
# endif
|
||||
#endif /* LIBFONTCHARACTER_INTERNALS_H */
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
int fc_tomulti(FONTCHARACTER *dest, FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_char_t *chr = fc_get_char(opcode);
|
||||
const fc_char_t *chr = fc_get_char(opcode, fc_locale);
|
||||
if (!chr || !chr->multi)
|
||||
return (-1);
|
||||
memcpy(dest, chr->multi,
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
static int to_unicode(wchar_t *dest, FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_char_t *chr;
|
||||
if (!(chr = fc_get_char(opcode)) || !chr->uni)
|
||||
if (!(chr = fc_get_char(opcode, fc_locale)) || !chr->uni)
|
||||
return (-1);
|
||||
memcpy(dest, chr->uni, chr->unisize * sizeof(wchar_t));
|
||||
return ((int)chr->unisize);
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/* *****************************************************************************
|
||||
* utils/locale.c -- locale-related utilities.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey
|
||||
*
|
||||
* This file is part of libfontcharacter.
|
||||
* libfontcharacter is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libfontcharacter 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libfontcharacter; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libfontcharacter/internals.h>
|
||||
#include <string.h>
|
||||
#ifndef FC_DISABLED_REFERENCE
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Locale management */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* fc_get_locale:
|
||||
* Get a locale from its name.
|
||||
*
|
||||
* @arg name the name of the locale to get.
|
||||
* @return the pointer (NULL if not found).
|
||||
*/
|
||||
|
||||
const fc_locale_t *fc_get_locale(const char *name)
|
||||
{
|
||||
const fc_locale_t *loc, *result = NULL;
|
||||
for (loc = fc_locales; loc->name; loc++) if (!strcmp(name, loc->name)) {
|
||||
result = loc;
|
||||
break;
|
||||
}
|
||||
|
||||
/* return the result */
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* fc_listlocales:
|
||||
* List the available locales.
|
||||
*
|
||||
* @arg callback the listing callback.
|
||||
* @arg cookie the callback cookie.
|
||||
* @return the number of found locales.
|
||||
*/
|
||||
|
||||
int fc_listlocales(void (*callback)(void*, const char*), void *cookie)
|
||||
{
|
||||
const fc_locale_t *loc; int num = 0;
|
||||
for (loc = fc_locales; loc->name; num++, loc++)
|
||||
if (callback) (*callback)(cookie, loc->name);
|
||||
return (num);
|
||||
}
|
||||
|
||||
/**
|
||||
* fc_setlocale:
|
||||
* Set the locale.
|
||||
*
|
||||
* @arg name name of the locale to set.
|
||||
* @return 0 if the locale was set successfully, -1 otherwise.
|
||||
*/
|
||||
|
||||
int fc_setlocale(const char *name)
|
||||
{
|
||||
const fc_locale_t *loc = fc_get_locale(name);
|
||||
if (!loc) return (-1);
|
||||
fc_locale = loc;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Locale character utilities */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* fc_get_char:
|
||||
* Get a FONTCHARACTER entry from the locale.
|
||||
*
|
||||
* @arg opcode the opcode
|
||||
* @arg locale the locale
|
||||
* @return the entry address
|
||||
*/
|
||||
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode, const fc_locale_t *locale)
|
||||
{
|
||||
const fc_char_t **chars = locale->chars[opcode >> 8];
|
||||
if (!chars) return (NULL);
|
||||
|
||||
const fc_char_t *chr = chars[opcode & 0xFF];
|
||||
return (chr);
|
||||
}
|
||||
|
||||
#endif /* FC_DISABLED_REFERENCE */
|
|
@ -1,60 +0,0 @@
|
|||
/* *****************************************************************************
|
||||
* utils/setlocale.c -- set the FONTCHARACTER locale.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey
|
||||
*
|
||||
* This file is part of libfontcharacter.
|
||||
* libfontcharacter is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libfontcharacter 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libfontcharacter; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libfontcharacter/internals.h>
|
||||
#include <string.h>
|
||||
#ifndef FC_DISABLED_REFERENCE
|
||||
|
||||
/**
|
||||
* fc_setlocale:
|
||||
* Set the locale.
|
||||
*
|
||||
* @arg locale the locale to set.
|
||||
* @return 0 if the locale was set successfully, -1 otherwise.
|
||||
*/
|
||||
|
||||
int fc_setlocale(const char *locale)
|
||||
{
|
||||
const fc_locale_t *loc;
|
||||
for (loc = fc_locales; loc->name; loc++) if (!strcmp(locale, loc->name)) {
|
||||
fc_locale = loc;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* locale not found */
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* fc_get_char:
|
||||
* Get a FONTCHARACTER entry from the locale.
|
||||
*
|
||||
* @arg opcode the opcode
|
||||
* @return the entry address
|
||||
*/
|
||||
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_char_t **chars = fc_locale->chars[opcode >> 8];
|
||||
if (!chars) return (NULL);
|
||||
|
||||
const fc_char_t *chr = chars[opcode & 0xFF];
|
||||
return (chr);
|
||||
}
|
||||
|
||||
#endif /* FC_DISABLED_REFERENCE */
|
Reference in New Issue