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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • 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.
32 I18N_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.
35 I18N_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.
38 I18N_NOOP2("@item Font name", "Monospace")
39 
40 #endif
41 
42 void 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 
64 QString 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 
91 static bool localeLessThan (const QString &a, const QString &b)
92 {
93  return QString::localeAwareCompare(a, b) < 0;
94 }
95 
96 QStringList 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 }
localeLessThan
static bool localeLessThan(const QString &a, const QString &b)
Definition: fonthelpers.cpp:91
I18N_NOOP2
#define I18N_NOOP2(comment, x)
We need to remember the context to get the correct translation.
Definition: kstandardshortcut.cpp:68
splitFontString
void splitFontString(const QString &name, QString *family, QString *foundry)
Definition: fonthelpers.cpp:42
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
QString
QHash< QString, QString >
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
QStringList
translateFontNameList
QStringList translateFontNameList(const QStringList &names, QHash< QString, QString > *trToRawNames)
Definition: fonthelpers.cpp:96
translateFontName
QString translateFontName(const QString &name)
Definition: fonthelpers.cpp:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:13 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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