| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qquickfontinfo_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | \qmltype FontInfo |
| 10 | \instantiates QQuickFontInfo |
| 11 | \inqmlmodule QtQuick |
| 12 | \since 6.9 |
| 13 | \ingroup qtquick-text-utility |
| 14 | \brief Provides info about how a given font query is resolved. |
| 15 | |
| 16 | FontInfo provides information about the actual font which is matched for a font query by Qt's |
| 17 | font selection system. |
| 18 | |
| 19 | It corresponds to the class QFontInfo in C++. |
| 20 | |
| 21 | \code |
| 22 | FontInfo { |
| 23 | id: fontInfo |
| 24 | font.family: "Arial" |
| 25 | } |
| 26 | |
| 27 | Text { |
| 28 | text: fontInfo.family === "Arial" |
| 29 | ? "System has 'Arial' font" |
| 30 | : "System does not have 'Arial' font" |
| 31 | } |
| 32 | \endcode |
| 33 | |
| 34 | \sa FontMetrics, TextMetrics |
| 35 | */ |
| 36 | QQuickFontInfo::QQuickFontInfo(QObject *parent) |
| 37 | : QObject(parent) |
| 38 | , m_info(m_font) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | \internal |
| 44 | */ |
| 45 | QQuickFontInfo::~QQuickFontInfo() |
| 46 | = default; |
| 47 | |
| 48 | /*! |
| 49 | \qmlproperty font QtQuick::FontInfo::font |
| 50 | |
| 51 | This property holds the font which will be resolved by the FontInfo. |
| 52 | */ |
| 53 | QFont QQuickFontInfo::font() const |
| 54 | { |
| 55 | return m_font; |
| 56 | } |
| 57 | |
| 58 | void QQuickFontInfo::setFont(QFont font) |
| 59 | { |
| 60 | if (m_font != font) { |
| 61 | m_font = font; |
| 62 | m_info = QFontInfo(m_font); |
| 63 | emit fontChanged(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /*! |
| 68 | \qmlproperty string QtQuick::FontInfo::family |
| 69 | |
| 70 | This property holds the family of the matched font. |
| 71 | |
| 72 | \sa {QFontInfo::family()} |
| 73 | */ |
| 74 | QString QQuickFontInfo::family() const |
| 75 | { |
| 76 | return m_info.family(); |
| 77 | } |
| 78 | |
| 79 | /*! |
| 80 | \qmlproperty real QtQuick::FontInfo::styleName |
| 81 | |
| 82 | This property holds the style name (or "sub-family") of the mathed font. |
| 83 | |
| 84 | \sa {QFontInfo::styleName()} |
| 85 | */ |
| 86 | QString QQuickFontInfo::styleName() const |
| 87 | { |
| 88 | return m_info.styleName(); |
| 89 | } |
| 90 | |
| 91 | /*! |
| 92 | \qmlproperty int QtQuick::FontInfo::pixelSize |
| 93 | |
| 94 | This property holds the pixel size of the matched font. |
| 95 | |
| 96 | \sa {QFontInfo::pixelSize()} |
| 97 | */ |
| 98 | int QQuickFontInfo::pixelSize() const |
| 99 | { |
| 100 | return m_info.pixelSize(); |
| 101 | } |
| 102 | |
| 103 | /*! |
| 104 | \qmlproperty real QtQuick::FontInfo::pointSize |
| 105 | |
| 106 | This property holds the point size of the matched font. |
| 107 | |
| 108 | \sa {QFontInfo::pointSizeF()} |
| 109 | */ |
| 110 | qreal QQuickFontInfo::pointSize() const |
| 111 | { |
| 112 | return m_info.pointSizeF(); |
| 113 | } |
| 114 | |
| 115 | /*! |
| 116 | \qmlproperty bool QtQuick::FontInfo::italic |
| 117 | |
| 118 | This property holds the italic value of the matched font. |
| 119 | |
| 120 | \sa {QFontInfo::italic()} |
| 121 | */ |
| 122 | bool QQuickFontInfo::italic() const |
| 123 | { |
| 124 | return m_info.italic(); |
| 125 | } |
| 126 | |
| 127 | /*! |
| 128 | \qmlproperty int QtQuick::FontInfo::weight |
| 129 | |
| 130 | This property holds the weight of the matched font. |
| 131 | |
| 132 | \sa bold, {QFontInfo::weight()} |
| 133 | */ |
| 134 | int QQuickFontInfo::weight() const |
| 135 | { |
| 136 | return m_info.weight(); |
| 137 | } |
| 138 | |
| 139 | /*! |
| 140 | \qmlproperty bool QtQuick::FontInfo::bold |
| 141 | |
| 142 | This property is true if weight() would return a value greater than Font.Normal; otherwise |
| 143 | returns false. |
| 144 | |
| 145 | \sa weight, {QFontInfo::bold()} |
| 146 | */ |
| 147 | bool QQuickFontInfo::bold() const |
| 148 | { |
| 149 | return m_info.bold(); |
| 150 | } |
| 151 | |
| 152 | /*! |
| 153 | \qmlproperty bool QtQuick::FontInfo::fixedPitch |
| 154 | |
| 155 | This property holds the fixed pitch value of the matched font. |
| 156 | |
| 157 | \sa {QFontInfo::fixedPitch()} |
| 158 | */ |
| 159 | bool QQuickFontInfo::fixedPitch() const |
| 160 | { |
| 161 | return m_info.fixedPitch(); |
| 162 | } |
| 163 | |
| 164 | /*! |
| 165 | \qmlproperty enum QtQuick::FontInfo::style |
| 166 | |
| 167 | This property holds the style of the matched font. |
| 168 | |
| 169 | \value Font.StyleNormal Contains normal glyphs without italic slant. |
| 170 | \value Font.StyleItalic Contains glyphs designed to be used for representing italicized |
| 171 | text. |
| 172 | \value Font.StyleOblique Contains glyphs with an italic appearance, typically not |
| 173 | specially designed, but rather produced by applying a slant on the |
| 174 | font family's normal glyphs. |
| 175 | |
| 176 | \sa {QFontInfo::style()} |
| 177 | */ |
| 178 | QQuickFontEnums::Style QQuickFontInfo::style() const |
| 179 | { |
| 180 | return QQuickFontEnums::Style(m_info.style()); |
| 181 | } |
| 182 | |
| 183 | /*! |
| 184 | \qmlproperty list QtQuick::FontInfo::variableAxes |
| 185 | |
| 186 | This property holds the variable axes supported by the matched font. The list consists of |
| 187 | QFontVariableAxis objects, which have the properties \c{tag}, \c{name}, \c{minimumValue}, |
| 188 | \c{maximumValue}, and \c{defaultValue}. |
| 189 | |
| 190 | \sa {QFontInfo::variableAxes()}, QFontVariableAxis |
| 191 | */ |
| 192 | QList<QFontVariableAxis> QQuickFontInfo::variableAxes() const |
| 193 | { |
| 194 | return m_info.variableAxes(); |
| 195 | } |
| 196 | |
| 197 | QT_END_NAMESPACE |
| 198 | |
| 199 | #include "moc_qquickfontinfo_p.cpp" |
| 200 | |