Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svl/source/config/languageoptions.cxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
21
#include <svl/languageoptions.hxx>
22
#include <i18nlangtag/mslangid.hxx>
23
#include <i18nlangtag/languagetag.hxx>
24
#include <com/sun/star/i18n/ScriptType.hpp>
25
#include <unotools/syslocale.hxx>
26
27
#ifdef _WIN32
28
#if !defined WIN32_LEAN_AND_MEAN
29
# define WIN32_LEAN_AND_MEAN
30
#endif
31
#include <windows.h>
32
#endif
33
34
using namespace ::com::sun::star;
35
36
37
namespace SvtLanguageOptions
38
{
39
40
// returns for a language the scripttype
41
SvtScriptType GetScriptTypeOfLanguage( LanguageType nLang )
42
18.4M
{
43
18.4M
    if( LANGUAGE_DONTKNOW == nLang )
44
5.15M
        nLang = LANGUAGE_ENGLISH_US;
45
13.2M
    else if (LANGUAGE_SYSTEM == nLang || LANGUAGE_PROCESS_OR_USER_DEFAULT == nLang)
46
0
        nLang = SvtSysLocale().GetLanguageTag().getLanguageType();
47
48
18.4M
    sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
49
18.4M
    SvtScriptType nScript;
50
18.4M
    switch (nScriptType)
51
18.4M
    {
52
40
        case css::i18n::ScriptType::ASIAN:
53
40
            nScript = SvtScriptType::ASIAN;
54
40
            break;
55
1
        case css::i18n::ScriptType::COMPLEX:
56
1
            nScript = SvtScriptType::COMPLEX;
57
1
            break;
58
18.4M
        default:
59
18.4M
            nScript = SvtScriptType::LATIN;
60
18.4M
    }
61
18.4M
    return nScript;
62
18.4M
}
63
64
SvtScriptType FromI18NToSvtScriptType( sal_Int16 nI18NType )
65
38.3M
{
66
38.3M
    switch ( nI18NType )
67
38.3M
    {
68
30.7M
        case i18n::ScriptType::LATIN:   return SvtScriptType::LATIN;
69
3.86M
        case i18n::ScriptType::ASIAN:   return SvtScriptType::ASIAN;
70
3.68M
        case i18n::ScriptType::COMPLEX: return SvtScriptType::COMPLEX;
71
0
        case i18n::ScriptType::WEAK:    return SvtScriptType::NONE; // no mapping
72
0
        default: assert(false && nI18NType && "Unknown i18n::ScriptType"); break;
73
38.3M
    }
74
0
    return SvtScriptType::NONE;
75
38.3M
}
76
77
sal_Int16 FromSvtScriptTypeToI18N( SvtScriptType nItemType )
78
13.0M
{
79
13.0M
    switch ( nItemType )
80
13.0M
    {
81
0
        case SvtScriptType::NONE:       return 0;
82
13.0M
        case SvtScriptType::LATIN:      return i18n::ScriptType::LATIN;
83
0
        case SvtScriptType::ASIAN:      return i18n::ScriptType::ASIAN;
84
0
        case SvtScriptType::COMPLEX:    return i18n::ScriptType::COMPLEX;
85
0
        case SvtScriptType::UNKNOWN:    return 0; // no mapping
86
0
        default: assert(false && static_cast<int>(nItemType) && "unknown SvtScriptType"); break;
87
13.0M
    }
88
0
    return 0;
89
13.0M
}
90
91
sal_Int16 GetI18NScriptTypeOfLanguage( LanguageType nLang )
92
13.0M
{
93
13.0M
    return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang ) );
94
13.0M
}
95
96
} // namespace SvtLanguageOptions
97
98
static bool isKeyboardLayoutTypeInstalled(sal_Int16 scriptType)
99
0
{
100
0
    bool isInstalled = false;
101
#ifdef _WIN32
102
    int nLayouts = GetKeyboardLayoutList(0, nullptr);
103
    if (nLayouts > 0)
104
    {
105
        HKL *lpList = static_cast<HKL*>(LocalAlloc(LPTR, (nLayouts * sizeof(HKL))));
106
        if (lpList)
107
        {
108
            nLayouts = GetKeyboardLayoutList(nLayouts, lpList);
109
110
            for(int i = 0; i < nLayouts; ++i)
111
            {
112
                LCID lang = MAKELCID(LOWORD(lpList[i]), SORT_DEFAULT);
113
                if (MsLangId::getScriptType(LanguageType(lang)) == scriptType)
114
                {
115
                    isInstalled = true;
116
                    break;
117
                }
118
            }
119
120
            LocalFree(lpList);
121
        }
122
    }
123
#else
124
0
    (void)scriptType;
125
0
#endif
126
0
    return isInstalled;
127
0
}
128
129
namespace SvtSystemLanguageOptions
130
{
131
    bool isCJKKeyboardLayoutInstalled()
132
0
    {
133
0
        return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN);
134
0
    }
135
}
136
137
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */