1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <stdlib.h>
#include "cd-lcms-helpers.h"
/*
* _cmsWriteTagTextAscii:
*/
cmsBool
_cmsWriteTagTextAscii (cmsHPROFILE lcms_profile,
cmsTagSignature sig,
const gchar *text)
{
cmsBool ret;
cmsMLU *mlu = cmsMLUalloc (0, 1);
cmsMLUsetASCII (mlu, "EN", "us", text);
ret = cmsWriteTag (lcms_profile, sig, mlu);
cmsMLUfree (mlu);
return ret;
}
static wchar_t *
utf8_to_wchar_t (const char *src)
{
gsize len;
gsize converted;
wchar_t *buf = NULL;
len = mbstowcs (NULL, src, 0);
if (len < 0) {
g_warning ("Invalid UTF-8 in string %s", src);
goto out;
}
len += 1;
buf = g_malloc (sizeof (wchar_t) * len);
converted = mbstowcs (buf, src, len - 1);
g_assert (converted != -1);
buf[converted] = '\0';
out:
return buf;
}
/*
* _cmsDictAddEntryAscii:
*/
cmsBool
_cmsDictAddEntryAscii (cmsHANDLE dict,
const gchar *key,
const gchar *value)
{
cmsBool ret = FALSE;
wchar_t *mb_key = NULL;
wchar_t *mb_value = NULL;
mb_key = utf8_to_wchar_t (key);
if (mb_key == NULL)
goto out;
mb_value = utf8_to_wchar_t (value);
if (mb_value == NULL)
goto out;
ret = cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL);
out:
g_free (mb_key);
g_free (mb_value);
return ret;
}
|