mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-10 18:15:18 -04:00
Add minimum font size in chat.
This commit is contained in:
parent
7195d4c20d
commit
3f155b9b75
5 changed files with 62 additions and 8 deletions
|
@ -376,7 +376,7 @@ static QString saveSpace(const QString text)
|
|||
return savedSpaceText;
|
||||
}
|
||||
|
||||
QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor, qreal desiredContrast)
|
||||
QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor, qreal desiredContrast, int desiredMinimumFontSize)
|
||||
{
|
||||
if (flag == 0 || text.isEmpty()) {
|
||||
// nothing to do
|
||||
|
@ -416,7 +416,7 @@ QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulo
|
|||
formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
|
||||
|
||||
if (flag & RSHTML_OPTIMIZEHTML_MASK) {
|
||||
optimizeHtml(formattedText, flag, backgroundColor, desiredContrast);
|
||||
optimizeHtml(formattedText, flag, backgroundColor, desiredContrast, desiredMinimumFontSize);
|
||||
}
|
||||
|
||||
return formattedText;
|
||||
|
@ -734,12 +734,14 @@ static void optimizeHtml(QDomDocument& doc
|
|||
* is passed inside flag.
|
||||
* @param desiredContrast: Minimum contrast between text and background color,
|
||||
* between 1 and 21.
|
||||
* @param desiredMinimumFontSize: Minimum font size.
|
||||
*/
|
||||
static void styleCreate(QDomDocument& doc
|
||||
, QHash<QString, QStringList*> stylesList
|
||||
, unsigned int flag
|
||||
, qreal bglum
|
||||
, qreal desiredContrast)
|
||||
, qreal desiredContrast
|
||||
, int desiredMinimumFontSize)
|
||||
{
|
||||
QDomElement styleElem;
|
||||
do{
|
||||
|
@ -792,6 +794,15 @@ static void styleCreate(QDomDocument& doc
|
|||
QString key = keyvalue.at(0).trimmed();
|
||||
QString val = keyvalue.at(1).trimmed();
|
||||
|
||||
if (key == "font-size") {
|
||||
QRegExp re("(\\d+)(\\D*)");
|
||||
if (re.indexIn(val) != -1) {
|
||||
bool ok; int iVal = re.cap(1).toInt(&ok);
|
||||
if (ok && (iVal < desiredMinimumFontSize)) {
|
||||
val = QString::number(desiredMinimumFontSize) + re.cap(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((flag & RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY && key == "font-family") ||
|
||||
(flag & RSHTML_FORMATTEXT_REMOVE_FONT_SIZE && key == "font-size") ||
|
||||
(flag & RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT && key == "font-weight") ||
|
||||
|
@ -864,9 +875,12 @@ void RsHtml::optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag
|
|||
* is passed inside flag.
|
||||
* @param desiredContrast Minimum contrast between text and background color,
|
||||
* between 1 and 21.
|
||||
* @param desiredMinimumFontSize Minimum font size.
|
||||
*/
|
||||
void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
|
||||
, const QColor &backgroundColor /*= Qt::white*/, qreal desiredContrast /*= 1.0*/
|
||||
, const QColor &backgroundColor /*= Qt::white*/
|
||||
, qreal desiredContrast /*= 1.0*/
|
||||
, int desiredMinimumFontSize /*=10*/
|
||||
)
|
||||
{
|
||||
|
||||
|
@ -888,7 +902,7 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
|
|||
QHash<QString, QString> knownStyle;
|
||||
|
||||
::optimizeHtml(doc, body, stylesList, knownStyle);
|
||||
::styleCreate(doc, stylesList, flag, ::getRelativeLuminance(backgroundColor), desiredContrast);
|
||||
::styleCreate(doc, stylesList, flag, ::getRelativeLuminance(backgroundColor), desiredContrast, desiredMinimumFontSize);
|
||||
text = doc.toString(-1);
|
||||
|
||||
// std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << originalLength << std::endl;
|
||||
|
|
|
@ -59,11 +59,11 @@ public:
|
|||
|
||||
static void initEmoticons(const QHash< QString, QString >& hash);
|
||||
|
||||
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0);
|
||||
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0, int desiredMinimumFontSize = 10);
|
||||
static bool findAnchors(const QString &text, QStringList& urls);
|
||||
|
||||
static void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag = 0);
|
||||
static void optimizeHtml(QString &text, unsigned int flag = 0, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0);
|
||||
static void optimizeHtml(QString &text, unsigned int flag = 0, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0, int desiredMinimumFontSize = 10);
|
||||
static QString toHtml(QString text, bool realHtml = true);
|
||||
|
||||
static bool makeEmbeddedImage(const QString &fileName, QString &embeddedImage, const int maxPixels);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue