File indexing completed on 2024-07-14 04:00:01

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2009 Albert Astals Cid <aacid@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef KFONTUTILS_H
0008 #define KFONTUTILS_H
0009 
0010 // Qt
0011 #include <QGraphicsTextItem>
0012 
0013 class QSizeF;
0014 
0015 namespace KFontUtils
0016 {
0017 
0018 /** Modifiers for the adaptFontSize function */
0019 enum AdaptFontSizeOption {
0020     NoFlags = 0x01, ///< No modifier
0021     DoNotAllowWordWrap = 0x02, ///< Do not use word wrapping
0022 };
0023 Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption)
0024 
0025 /**
0026  * Helper function that calculates the biggest font size (in points) used
0027  * drawing a centered text using word wrapping.
0028  * @param text The QGraphicsTextItem you want to draw
0029  * @param width The available width for drawing
0030  * @param height The available height for drawing
0031  * @param maxFontSize The maximum font size (in points) to consider
0032  * @param minFontSize The minimum font size (in points) to consider
0033  * @param flags The modifiers for how the text is painted
0034  * @param precision The maximum unused space (in pixels) in any axys
0035  * @return The calculated biggest font size (in points) that draws the text
0036  *         in the given dimensions. Cannot return smaller than minFontSize neither
0037  *         bigger than maxFontSize. Can return -1 on error.
0038 */
0039 qreal adaptFontSize(QGraphicsTextItem *text, qreal width, qreal height, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, qreal precision = 1.0);
0040 
0041 /**
0042  * Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
0043  */
0044 qreal adaptFontSize(QGraphicsTextItem *text, const QSizeF &availableSize, qreal maxFontSize = 28.0, qreal minFontSize = 1.0, qreal precision = 1.0);
0045 
0046 }
0047 
0048 Q_DECLARE_OPERATORS_FOR_FLAGS(KFontUtils::AdaptFontSizeOptions)
0049 
0050 #endif