File indexing completed on 2024-12-22 05:15:54

0001 /*
0002     SPDX-FileCopyrightText: 2003-2007 Craig Drummond <craig@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #pragma once
0007 
0008 #include "Misc.h"
0009 #include "kfontinst_export.h"
0010 #include <QUrl>
0011 #include <fontconfig/fontconfig.h>
0012 
0013 #include "kfontinst_export.h"
0014 
0015 #if (FC_VERSION < 20200)
0016 
0017 #define KFI_FC_NO_WIDTHS
0018 #define KFI_FC_LIMITED_WEIGHTS
0019 
0020 #endif
0021 
0022 #ifdef KFI_FC_LIMITED_WEIGHTS
0023 
0024 #undef FC_WEIGHT_LIGHT
0025 #define FC_WEIGHT_THIN 0
0026 #define FC_WEIGHT_EXTRALIGHT 40
0027 #define FC_WEIGHT_ULTRALIGHT FC_WEIGHT_EXTRALIGHT
0028 #define FC_WEIGHT_LIGHT 50
0029 #define FC_WEIGHT_BOOK 75
0030 #define FC_WEIGHT_REGULAR 80
0031 #define FC_WEIGHT_NORMAL FC_WEIGHT_REGULAR
0032 #define FC_WEIGHT_SEMIBOLD FC_WEIGHT_DEMIBOLD
0033 #define FC_WEIGHT_EXTRABOLD 205
0034 #define FC_WEIGHT_ULTRABOLD FC_WEIGHT_EXTRABOLD
0035 #define FC_WEIGHT_HEAVY FC_WEIGHT_BLACK
0036 
0037 #endif
0038 
0039 class QString;
0040 
0041 namespace KFI
0042 {
0043 namespace FC
0044 {
0045 //
0046 // Ideally only want this class to contain KFI_FC_NO_WIDTHS
0047 #ifdef KFI_FC_NO_WIDTHS
0048 #define KFI_FC_WIDTH_ULTRACONDENSED 50
0049 #define KFI_FC_WIDTH_EXTRACONDENSED 63
0050 #define KFI_FC_WIDTH_CONDENSED 75
0051 #define KFI_FC_WIDTH_SEMICONDENSED 87
0052 #define KFI_FC_WIDTH_NORMAL 100
0053 #define KFI_FC_WIDTH_SEMIEXPANDED 113
0054 #define KFI_FC_WIDTH_EXPANDED 125
0055 #define KFI_FC_WIDTH_EXTRAEXPANDED 150
0056 #define KFI_FC_WIDTH_ULTRAEXPANDED 200
0057 #else
0058 #define KFI_FC_WIDTH_ULTRACONDENSED FC_WIDTH_ULTRACONDENSED
0059 #define KFI_FC_WIDTH_EXTRACONDENSED FC_WIDTH_EXTRACONDENSED
0060 #define KFI_FC_WIDTH_CONDENSED FC_WIDTH_CONDENSED
0061 #define KFI_FC_WIDTH_SEMICONDENSED FC_WIDTH_SEMICONDENSED
0062 #define KFI_FC_WIDTH_NORMAL FC_WIDTH_NORMAL
0063 #define KFI_FC_WIDTH_SEMIEXPANDED FC_WIDTH_SEMIEXPANDED
0064 #define KFI_FC_WIDTH_EXPANDED FC_WIDTH_EXPANDED
0065 #define KFI_FC_WIDTH_EXTRAEXPANDED FC_WIDTH_EXTRAEXPANDED
0066 #define KFI_FC_WIDTH_ULTRAEXPANDED FC_WIDTH_ULTRAEXPANDED
0067 #endif
0068 
0069 extern KFONTINST_EXPORT QUrl encode(const QString &name, quint32 style, const QString &file = QString(), int index = 0);
0070 extern KFONTINST_EXPORT Misc::TFont decode(const QUrl &url);
0071 extern KFONTINST_EXPORT QString getFile(const QUrl &url);
0072 extern KFONTINST_EXPORT int getIndex(const QUrl &url);
0073 extern KFONTINST_EXPORT int weight(int w); // round w to nearest fc weight
0074 extern KFONTINST_EXPORT int width(int w); // round w to nearest fc width
0075 extern KFONTINST_EXPORT int slant(int s); // round s to nearest fc slant
0076 extern KFONTINST_EXPORT int spacing(int s); // round s to nearest fc spacing
0077 extern KFONTINST_EXPORT int strToWeight(const QString &str, QString &newStr);
0078 extern KFONTINST_EXPORT int strToWidth(const QString &str, QString &newStr);
0079 extern KFONTINST_EXPORT int strToSlant(const QString &str);
0080 extern KFONTINST_EXPORT quint32 createStyleVal(const QString &name);
0081 inline KFONTINST_EXPORT quint32 createStyleVal(int weight, int width, int slant)
0082 {
0083     return ((weight & 0xFF) << 16) + ((width & 0xFF) << 8) + (slant & 0xFF);
0084 }
0085 extern KFONTINST_EXPORT QString styleValToStr(quint32 style);
0086 extern KFONTINST_EXPORT void decomposeStyleVal(quint32 styleInfo, int &weight, int &width, int &slant);
0087 extern KFONTINST_EXPORT quint32 styleValFromStr(const QString &style);
0088 
0089 extern KFONTINST_EXPORT QString getFcString(FcPattern *pat, const char *val, int index = 0);
0090 #ifdef KFI_USE_TRANSLATED_FAMILY_NAME
0091 extern KFONTINST_EXPORT QString getFcLangString(FcPattern *pat, const char *val, const char *valLang);
0092 #endif
0093 extern KFONTINST_EXPORT int getFcInt(FcPattern *pat, const char *val, int index = 0, int def = -1);
0094 extern KFONTINST_EXPORT QString getName(const QString &file);
0095 extern KFONTINST_EXPORT void getDetails(FcPattern *pat, QString &family, quint32 &styleVal, int &index, QString &foundry);
0096 extern KFONTINST_EXPORT QString createName(FcPattern *pat);
0097 extern KFONTINST_EXPORT QString createName(const QString &family, quint32 styleInfo);
0098 extern KFONTINST_EXPORT QString createName(const QString &family, int weight, int width, int slant);
0099 inline KFONTINST_EXPORT QString createName(const Misc::TFont &font)
0100 {
0101     return createName(font.family, font.styleInfo);
0102 }
0103 extern KFONTINST_EXPORT QString createStyleName(quint32 styleInfo);
0104 extern KFONTINST_EXPORT QString createStyleName(int weight, int width, int slant);
0105 extern KFONTINST_EXPORT QString weightStr(int w, bool emptyNormal = true);
0106 extern KFONTINST_EXPORT QString widthStr(int w, bool emptyNormal = true);
0107 extern KFONTINST_EXPORT QString slantStr(int s, bool emptyNormal = true);
0108 extern KFONTINST_EXPORT QString spacingStr(int s);
0109 extern KFONTINST_EXPORT bool bitmapsEnabled();
0110 }
0111 }