Warning, file /plasma/plasma-workspace/kcms/fonts/previewrenderengine.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2018 Julian Wolff <wolff@julianwolff.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "previewrenderengine.h" 0008 #include "Fc.h" 0009 0010 #include <QApplication> 0011 #include <QScreen> 0012 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0013 #include <private/qtx11extras_p.h> 0014 #else 0015 #include <QX11Info> 0016 #endif 0017 0018 #include <X11/Xft/Xft.h> 0019 0020 #ifdef HAVE_FONTCONFIG 0021 0022 static int qtToFcWeight(int weight) 0023 { 0024 switch (weight) { 0025 case 0: 0026 return FC_WEIGHT_THIN; 0027 case QFont::Light >> 1: 0028 return FC_WEIGHT_EXTRALIGHT; 0029 case QFont::Light: 0030 return FC_WEIGHT_LIGHT; 0031 default: 0032 case QFont::Normal: 0033 return FC_WEIGHT_REGULAR; 0034 case (QFont::Normal + QFont::DemiBold) >> 1: 0035 #ifdef KFI_HAVE_MEDIUM_WEIGHT 0036 return FC_WEIGHT_MEDIUM; 0037 #endif 0038 case QFont::DemiBold: 0039 return FC_WEIGHT_DEMIBOLD; 0040 case QFont::Bold: 0041 return FC_WEIGHT_BOLD; 0042 case (QFont::Bold + QFont::Black) >> 1: 0043 return FC_WEIGHT_EXTRABOLD; 0044 case QFont::Black: 0045 return FC_WEIGHT_BLACK; 0046 } 0047 } 0048 0049 #ifndef KFI_FC_NO_WIDTHS 0050 static int qtToFcWidth(int weight) 0051 { 0052 switch (weight) { 0053 case QFont::UltraCondensed: 0054 return KFI_FC_WIDTH_ULTRACONDENSED; 0055 case QFont::ExtraCondensed: 0056 return KFI_FC_WIDTH_EXTRACONDENSED; 0057 case QFont::Condensed: 0058 return KFI_FC_WIDTH_CONDENSED; 0059 case QFont::SemiCondensed: 0060 return KFI_FC_WIDTH_SEMICONDENSED; 0061 default: 0062 case QFont::Unstretched: 0063 return KFI_FC_WIDTH_NORMAL; 0064 case QFont::SemiExpanded: 0065 return KFI_FC_WIDTH_SEMIEXPANDED; 0066 case QFont::Expanded: 0067 return KFI_FC_WIDTH_EXPANDED; 0068 case QFont::ExtraExpanded: 0069 return KFI_FC_WIDTH_EXTRAEXPANDED; 0070 case QFont::UltraExpanded: 0071 return KFI_FC_WIDTH_ULTRAEXPANDED; 0072 } 0073 } 0074 #endif 0075 0076 static bool qtToFcSlant(int slant) 0077 { 0078 switch (slant) { 0079 default: 0080 case QFont::StyleNormal: 0081 return FC_SLANT_ROMAN; 0082 case QFont::StyleItalic: 0083 return FC_SLANT_ITALIC; 0084 case QFont::StyleOblique: 0085 return FC_SLANT_OBLIQUE; 0086 } 0087 } 0088 0089 static quint32 qtToFcStyle(const QFont &font) 0090 { 0091 return KFI::FC::createStyleVal(qtToFcWeight(font.weight()), qtToFcWidth(font.stretch()), qtToFcSlant(font.style())); 0092 } 0093 0094 PreviewRenderEngine::PreviewRenderEngine(bool init) 0095 : CFcEngine(init) 0096 { 0097 if (init) 0098 FcInitReinitialize(); 0099 } 0100 0101 PreviewRenderEngine::~PreviewRenderEngine() 0102 { 0103 } 0104 0105 QImage PreviewRenderEngine::drawAutoSize(const QFont &font, const QColor &txt, const QColor &bgnd, const QString &text) 0106 { 0107 const QString &name = font.family(); 0108 const quint32 style = qtToFcStyle(font); 0109 int faceNo = 0; 0110 0111 double ratio = QGuiApplication::primaryScreen()->devicePixelRatio(); 0112 double dpi = QX11Info::appDpiY(); 0113 0114 int fSize((int)(((font.pointSizeF() * dpi * ratio) / 72.0) + 0.5)); 0115 0116 QImage image(draw(name, style, faceNo, txt, bgnd, fSize, text)); 0117 image.setDevicePixelRatio(ratio); 0118 return image; 0119 } 0120 0121 #endif // HAVE_FONTCONFIG