mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Yet another code cleanup
This commit is contained in:
parent
ccfcc370d6
commit
085a90e0e5
15
src/text.cpp
15
src/text.cpp
@ -69,18 +69,3 @@ QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Text::avgCharRatio(const QString &str, const QFont &font)
|
|
||||||
{
|
|
||||||
qreal ratio;
|
|
||||||
|
|
||||||
if (str.at(0).unicode() > 0x2E80)
|
|
||||||
ratio = 1.0;
|
|
||||||
else {
|
|
||||||
ratio = (font.capitalization() == QFont::AllUppercase) ? 0.66 : 0.55;
|
|
||||||
if (font.bold())
|
|
||||||
ratio *= 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ratio;
|
|
||||||
}
|
|
||||||
|
@ -38,8 +38,6 @@ public:
|
|||||||
|
|
||||||
void render(QPainter *painter) const;
|
void render(QPainter *painter) const;
|
||||||
|
|
||||||
static qreal avgCharRatio(const QString &str, const QFont &font);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addItem(TextItem *item) {_items.append(item);}
|
void addItem(TextItem *item) {_items.append(item);}
|
||||||
QList<TextItem *> collidingItems(const TextItem *item) const;
|
QList<TextItem *> collidingItems(const TextItem *item) const;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define TEXTITEM_H
|
#define TEXTITEM_H
|
||||||
|
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
class TextItem
|
class TextItem
|
||||||
{
|
{
|
||||||
@ -29,6 +30,23 @@ public:
|
|||||||
return other->shape().intersects(shape());
|
return other->shape().intersects(shape());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static int avgCharWidth(const QString &str, const QFont &font)
|
||||||
|
{
|
||||||
|
qreal ratio;
|
||||||
|
|
||||||
|
if (str.at(0).unicode() >= 0x2E80)
|
||||||
|
ratio = 1.0;
|
||||||
|
else {
|
||||||
|
ratio = (font.capitalization() == QFont::AllUppercase)
|
||||||
|
? 0.66 : 0.55;
|
||||||
|
if (font.bold())
|
||||||
|
ratio *= 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ratio * font.pixelSize();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _text;
|
QString _text;
|
||||||
bool _visible;
|
bool _visible;
|
||||||
|
@ -136,13 +136,12 @@ TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
|
|||||||
const QFont &font, int maxAngle, const QRectF &tileRect)
|
const QFont &font, int maxAngle, const QRectF &tileRect)
|
||||||
: TextItem(text), _font(font)
|
: TextItem(text), _font(font)
|
||||||
{
|
{
|
||||||
qreal acr = Text::avgCharRatio(text, _font);
|
int cw = avgCharWidth(text, font);
|
||||||
int textWidth = text.size() * _font.pixelSize() * acr;
|
int textWidth = text.size() * cw;
|
||||||
if (textWidth > path.length())
|
if (textWidth > path.length())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPainterPath tp(textPath(path, textWidth, maxAngle, _font.pixelSize() * acr,
|
QPainterPath tp(textPath(path, textWidth, maxAngle, cw, tileRect));
|
||||||
tileRect));
|
|
||||||
if (tp.isEmpty())
|
if (tp.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#define FLAGS (Qt::AlignCenter | Qt::TextWordWrap | Qt::TextDontClip)
|
#define FLAGS (Qt::AlignCenter | Qt::TextWordWrap | Qt::TextDontClip)
|
||||||
|
|
||||||
static QRectF exactBoundingRect(const QString &str, const QFont &font,
|
QRectF TextPointItem::exactBoundingRect(const QString &str,
|
||||||
int maxWidth)
|
const QFont &font, int maxWidth)
|
||||||
{
|
{
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
int limit = font.pixelSize() * maxWidth;
|
int limit = font.pixelSize() * maxWidth;
|
||||||
@ -24,11 +24,11 @@ static QRectF exactBoundingRect(const QString &str, const QFont &font,
|
|||||||
return br;
|
return br;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QRectF fuzzyBoundingRect(const QString &str, const QFont &font,
|
QRectF TextPointItem::fuzzyBoundingRect(const QString &str,
|
||||||
int maxWidth)
|
const QFont &font, int maxWidth)
|
||||||
{
|
{
|
||||||
int limit = font.pixelSize() * maxWidth;
|
int limit = font.pixelSize() * maxWidth;
|
||||||
qreal cw = font.pixelSize() * Text::avgCharRatio(str, font);
|
qreal cw = avgCharWidth(str, font);
|
||||||
qreal lh = font.pixelSize() * 1.25;
|
qreal lh = font.pixelSize() * 1.25;
|
||||||
int width = 0, lines = 0;
|
int width = 0, lines = 0;
|
||||||
|
|
||||||
|
@ -21,6 +21,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
typedef QRectF (*BoundingRectFunction)(const QString &, const QFont &, int);
|
typedef QRectF (*BoundingRectFunction)(const QString &, const QFont &, int);
|
||||||
|
|
||||||
|
static QRectF exactBoundingRect(const QString &str, const QFont &font,
|
||||||
|
int maxWidth);
|
||||||
|
static QRectF fuzzyBoundingRect(const QString &str, const QFont &font,
|
||||||
|
int maxWidth);
|
||||||
|
|
||||||
QRectF computeTextRect(BoundingRectFunction brf) const;
|
QRectF computeTextRect(BoundingRectFunction brf) const;
|
||||||
|
|
||||||
QPointF _pos;
|
QPointF _pos;
|
||||||
|
Loading…
Reference in New Issue
Block a user