Beispiel #1
0
static
int set_default_iconv_charsets(FlocaleCharset *fc)
{
	int i=0,j=0;

	if (!FiconvSupport || FLCIconvUtf8Charset == NULL || fc == NULL)
		return False;

	while(FLC_GET_LOCALE_CHARSET(FLCIconvUtf8Charset,i) != NULL)
	{
		j = 0;
		while(FLC_GET_LOCALE_CHARSET(fc,j) != NULL)
		{
			if (is_iconv_supported(
				  FLC_GET_LOCALE_CHARSET(
					  FLCIconvUtf8Charset,i),
				  FLC_GET_LOCALE_CHARSET(fc,j)))
			{
				FLC_SET_ICONV_INDEX(FLCIconvUtf8Charset,i);
				FLC_SET_ICONV_INDEX(fc,j);

				if (is_translit_supported(
					    FLC_GET_LOCALE_CHARSET(
						    FLCIconvUtf8Charset,i),
					    FLC_GET_LOCALE_CHARSET(fc,j)))
				{
					FLC_SET_ICONV_TRANSLIT_CHARSET(
						fc, safestrdup(translit_csname(
							FLC_GET_LOCALE_CHARSET(
								fc,j))));
				} else {
					FLC_SET_ICONV_TRANSLIT_CHARSET(
						fc, FLC_TRANSLIT_NOT_SUPPORTED);
				}

				return 1;
			}
			j++;
		}
		i++;
	}
	FLC_SET_ICONV_INDEX(FLCIconvUtf8Charset,
			    FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
	FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
	return 0;
}
Beispiel #2
0
static
void set_iconv_charset_index(FlocaleCharset *fc)
{
	int i = 0;

	if (!FiconvSupport || fc == NULL)
		return;

	if (FLC_DO_ICONV_CHARSET_INITIALIZED(fc))
		return; /* already set */
	if (FLCIconvUtf8Charset == NULL ||
	    !FLC_DO_ICONV_CHARSET_INITIALIZED(FLCIconvUtf8Charset))
	{
		FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
		return;
	}
	while(FLC_GET_LOCALE_CHARSET(fc,i) != NULL)
	{
		if (is_iconv_supported(
			FLC_GET_ICONV_CHARSET(FLCIconvUtf8Charset),
			FLC_GET_LOCALE_CHARSET(fc,i)))
		{
			FLC_SET_ICONV_INDEX(fc,i);
			if (is_translit_supported(
				    FLC_GET_ICONV_CHARSET(FLCIconvUtf8Charset),
				    FLC_GET_LOCALE_CHARSET(fc,i)))
			{
				FLC_SET_ICONV_TRANSLIT_CHARSET(
					fc, safestrdup(
						translit_csname(
							FLC_GET_LOCALE_CHARSET(
								fc,i))));
			} else {
				FLC_SET_ICONV_TRANSLIT_CHARSET(
					fc, FLC_TRANSLIT_NOT_SUPPORTED);
			}
			return;
		}
		i++;
	}
	FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
}
Beispiel #3
0
void FlocaleCharsetSetFlocaleCharset(
	Display *dpy, FlocaleFont *flf, char *hints, char *encoding,
	char *module)
{
	char *charset = NULL;
	char *iconv = NULL;
	Bool iconv_found = False;
	int i = 0;

	FlocaleCharsetInit(dpy, module);

	if (hints && *hints)
	{
		iconv = GetQuotedString(
			hints, &charset, "/", NULL, NULL, NULL);
		if (charset && *charset && *charset != '*' )
		{
			flf->fc = FlocaleCharsetOfXCharset(charset);
		}
		if (flf->fc == NULL && charset && *charset && *charset != '*')
		{
			flf->fc = FlocaleCharsetOfLocaleCharset(charset);
		}
		if (flf->fc == NULL && iconv && *iconv)
		{
			flf->fc = FlocaleCharsetOfLocaleCharset(iconv);
		}
	}
	if (flf->fc == NULL)
	{
		if (FftSupport && flf->fftf.fftfont != NULL)
		{
			flf->fc = FlocaleCharsetOfXCharset(flf->fftf.encoding);
		}
		else if (flf->fontset != None)
		{
			if (FLCXOMCharset != NULL)
			{
				flf->fc = FLCXOMCharset;
			}
			else
			{
				/* we are here if !HAVE_XOUTPUT_METHOD */
				XFontStruct **fs_list;
				char **ml;

				if (XFontsOfFontSet(
					    flf->fontset, &fs_list, &ml) > 0)
				{
					flf->fc = FLCXOMCharset =
						FlocaleCharsetOfFontStruct(
							dpy, fs_list[0]);
				}
			}
		}
		else if (flf->font != NULL)
		{
			flf->fc = FlocaleCharsetOfFontStruct(dpy, flf->font);
		}
	}
	if (flf->fc != NULL && iconv && *iconv)
	{
		/* the user has specified an iconv converter name:
		 * check if we have it and force user choice */
		while(!iconv_found &&
		      FLC_GET_LOCALE_CHARSET(flf->fc,i) != NULL)
		{
			if (
				strcmp(
					iconv,
					FLC_GET_LOCALE_CHARSET(flf->fc,i)) ==
				0)
			{
				iconv_found = True;
				/* Trust the user? yes ... */
				FLC_SET_ICONV_INDEX(flf->fc,i);
			}
			i++;
		}
	}
	if (iconv && *iconv && !iconv_found)
	{
		FlocaleCharset *fc;

		/* the user has specified an iconv converter name and we do not
		 * have it: must create a FlocaleCharset */
		flf->flags.must_free_fc = True;
		fc = (FlocaleCharset *)safemalloc(sizeof(FlocaleCharset));
		if (flf->fc != NULL)
		{
			CopyString(&fc->x, flf->fc->x);
			fc->encoding_type = flf->fc->encoding_type;
			if (flf->fc->bidi)
				CopyString(&fc->bidi, flf->fc->bidi);
			else
				fc->bidi = NULL;
		}
		else
		{
			CopyString(&fc->x, "Unknown"); /* for simplicity */
			fc->bidi = NULL;
			fc->encoding_type = FLC_ENCODING_TYPE_FONT;
		}
		fc->locale = (char **)safemalloc(2*sizeof(char *));
		CopyString(&fc->locale[0], iconv);
		fc->locale[1] = NULL;
		fc->iconv_index =  FLC_INDEX_ICONV_CHARSET_NOT_INITIALIZED;
		flf->fc = fc;
	}
	if (charset != NULL)
	{
		free(charset);
	}
	if (flf->fc == NULL)
	{
		flf->fc = &UnknownCharset;
	}

	/* now the string charset */
	if (encoding != NULL)
	{
		flf->str_fc = FlocaleCharsetOfXCharset(encoding);
		if (flf->str_fc == NULL)
		{
			flf->str_fc = FlocaleCharsetOfLocaleCharset(encoding);
		}
		if (flf->str_fc == NULL)
		{
			flf->str_fc = &UnknownCharset;
		}
	}
	else if (FftSupport && flf->fftf.fftfont != NULL)
	{
		if (flf->fftf.str_encoding != NULL)
		{
			flf->str_fc = FlocaleCharsetOfXCharset(
				flf->fftf.str_encoding);
			if (flf->str_fc == NULL)
			{
				flf->str_fc = FlocaleCharsetOfLocaleCharset(
					flf->fftf.str_encoding);
			}
			if (flf->str_fc == NULL)
			{
				flf->str_fc = &UnknownCharset;
			}
		}
		else
		{
			flf->str_fc =
				FlocaleCharsetGetDefaultCharset(dpy, module);
		}
	}
	if (flf->str_fc == NULL)
	{
		if (flf->fc != &UnknownCharset)
		{
			flf->str_fc = flf->fc;
		}
		else
		{
			flf->str_fc =
				FlocaleCharsetGetDefaultCharset(dpy, module);
		}
	}
}