• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • fonts
fonthelpers.cpp
Go to the documentation of this file.
1/*
2 Requires the Qt widget libraries, available at no cost at
3 http://www.troll.no
4
5 Copyright (C) 2008 Chusslove Illich <caslav.ilic@gmx.net>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "fonthelpers_p.h"
24
25#include "klocale.h"
26
27#ifdef NEVERDEFINE // never true
28// Font names up for translation, listed for extraction.
29
30// i18n: Generic sans serif font presented in font choosers. When selected,
31// the system will choose a real font, mandated by distro settings.
32I18N_NOOP2("@item Font name", "Sans Serif")
33// i18n: Generic serif font presented in font choosers. When selected,
34// the system will choose a real font, mandated by distro settings.
35I18N_NOOP2("@item Font name", "Serif")
36// i18n: Generic monospace font presented in font choosers. When selected,
37// the system will choose a real font, mandated by distro settings.
38I18N_NOOP2("@item Font name", "Monospace")
39
40#endif
41
42void splitFontString (const QString &name, QString *family, QString *foundry)
43{
44 int p1 = name.indexOf('[');
45 if (p1 < 0) {
46 if (family) {
47 *family = name.trimmed();
48 }
49 if (foundry) {
50 foundry->clear();
51 }
52 } else {
53 int p2 = name.indexOf(']', p1);
54 p2 = p2 > p1 ? p2 : name.length();
55 if (family) {
56 *family = name.left(p1).trimmed();
57 }
58 if (foundry) {
59 *foundry = name.mid(p1 + 1, p2 - p1 - 1).trimmed();
60 }
61 }
62}
63
64QString translateFontName (const QString &name)
65{
66 QString family, foundry;
67 splitFontString(name, &family, &foundry);
68
69 // Obtain any regular translations for the family and foundry.
70 QString trFamily = i18nc("@item Font name", family.toUtf8());
71 QString trFoundry = foundry;
72 if (!foundry.isEmpty()) {
73 trFoundry = i18nc("@item Font foundry", foundry.toUtf8());
74 }
75
76 // Assemble full translation.
77 QString trfont;
78 if (foundry.isEmpty()) {
79 // i18n: Filter by which the translators can translate, or otherwise
80 // operate on the font names not put up for regular translation.
81 trfont = i18nc("@item Font name", "%1", trFamily);
82 } else {
83 // i18n: Filter by which the translators can translate, or otherwise
84 // operate on the font names not put up for regular translation.
85 trfont = i18nc("@item Font name [foundry]", "%1 [%2]",
86 trFamily, trFoundry);
87 }
88 return trfont;
89}
90
91static bool localeLessThan (const QString &a, const QString &b)
92{
93 return QString::localeAwareCompare(a, b) < 0;
94}
95
96QStringList translateFontNameList (const QStringList &names,
97 QHash<QString, QString> *trToRawNames)
98{
99 // Generic fonts, in the inverse of desired order.
100 QStringList genericNames;
101 genericNames.append("Monospace");
102 genericNames.append("Serif");
103 genericNames.append("Sans Serif");
104
105 // Translate fonts, but do not add generics to the list right away.
106 QStringList trNames;
107 QHash<QString, QString> trMap;
108 foreach (const QString &name, names) {
109 QString trName = translateFontName(name);
110 if (!genericNames.contains(name)) {
111 trNames.append(trName);
112 }
113 trMap.insert(trName, name);
114 }
115
116 // Sort real fonts alphabetically.
117 qSort(trNames.begin(), trNames.end(), localeLessThan);
118
119 // Prepend generic fonts, in the predefined order.
120 foreach (const QString &genericName, genericNames) {
121 QString trGenericName = translateFontName(genericName);
122 if (trMap.contains(trGenericName)) {
123 trNames.prepend(trGenericName);
124 }
125 }
126
127 if (trToRawNames) {
128 *trToRawNames = trMap;
129 }
130 return trNames;
131}
QHash
translateFontName
QString translateFontName(const QString &name)
Definition: fonthelpers.cpp:64
translateFontNameList
QStringList translateFontNameList(const QStringList &names, QHash< QString, QString > *trToRawNames)
Definition: fonthelpers.cpp:96
splitFontString
void splitFontString(const QString &name, QString *family, QString *foundry)
Definition: fonthelpers.cpp:42
localeLessThan
static bool localeLessThan(const QString &a, const QString &b)
Definition: fonthelpers.cpp:91
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
I18N_NOOP2
#define I18N_NOOP2(comment, x)
We need to remember the context to get the correct translation.
Definition: kstandardshortcut.cpp:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal