mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Made text-transform zoom dependend
This commit is contained in:
parent
e9bf62dd2e
commit
3ea8ce64a7
@ -279,7 +279,7 @@ bool Style::Layer::Paint::antialias(Layer::Type type, int zoom) const
|
||||
|
||||
Style::Layer::Layout::Layout(const QJsonObject &json)
|
||||
: _lineCap(Qt::FlatCap), _lineJoin(Qt::MiterJoin), _font("Open Sans"),
|
||||
_capitalize(false), _viewportAlignment(false)
|
||||
_viewportAlignment(false)
|
||||
{
|
||||
// line
|
||||
_lineCap = FunctionS(json["line-cap"], "butt");
|
||||
@ -291,10 +291,10 @@ Style::Layer::Layout::Layout(const QJsonObject &json)
|
||||
_textSize = FunctionF(json["text-size"], 16);
|
||||
_textMaxWidth = FunctionF(json["text-max-width"], 10);
|
||||
_textMaxAngle = FunctionF(json["text-max-angle"], 45);
|
||||
_textTransform = FunctionS(json["text-transform"], "none");
|
||||
|
||||
if (json.contains("text-font") && json["text-font"].isArray())
|
||||
_font = Font::fromJsonArray(json["text-font"].toArray());
|
||||
if (json.contains("text-transform") && json["text-transform"].isString())
|
||||
_capitalize = json["text-transform"].toString() == "uppercase";
|
||||
if (json.contains("text-rotation-alignment")
|
||||
&& json["text-rotation-alignment"].isString())
|
||||
if (json["text-rotation-alignment"].toString() == "viewport")
|
||||
@ -330,6 +330,18 @@ Text::Anchor Style::Layer::Layout::textAnchor(int zoom) const
|
||||
return Text::Center;
|
||||
}
|
||||
|
||||
Text::Transform Style::Layer::Layout::textTransform(int zoom) const
|
||||
{
|
||||
QString transform(_textTransform.value(zoom));
|
||||
|
||||
if (transform == "uppercase")
|
||||
return Text::Uppercase;
|
||||
else if (transform == "lowercase")
|
||||
return Text::Lowercase;
|
||||
else
|
||||
return Text::None;
|
||||
}
|
||||
|
||||
Qt::PenCapStyle Style::Layer::Layout::lineCap(int zoom) const
|
||||
{
|
||||
QString cap(_lineCap.value(zoom));
|
||||
@ -433,6 +445,7 @@ void Style::Layer::setTextProperties(Tile &tile) const
|
||||
prop.maxWidth = _layout.maxTextWidth(tile.zoom());
|
||||
prop.maxAngle = _layout.maxTextAngle(tile.zoom());
|
||||
prop.anchor = _layout.textAnchor(tile.zoom());
|
||||
prop.transform = _layout.textTransform(tile.zoom());
|
||||
|
||||
tile.text().setProperties(prop);
|
||||
}
|
||||
@ -444,8 +457,6 @@ void Style::Layer::addSymbol(Tile &tile, const QPainterPath &path,
|
||||
QString tt(text.trimmed());
|
||||
if (tt.isEmpty())
|
||||
return;
|
||||
if (_layout.capitalize())
|
||||
tt = tt.toUpper();
|
||||
|
||||
QString icon = _layout.icon(tile.zoom(), tags);
|
||||
|
||||
|
@ -96,8 +96,7 @@ private:
|
||||
class Layout {
|
||||
public:
|
||||
Layout() : _textSize(16), _textMaxWidth(10), _textMaxAngle(45),
|
||||
_font("Open Sans"), _capitalize(false),
|
||||
_viewportAlignment(false) {}
|
||||
_font("Open Sans"), _viewportAlignment(false) {}
|
||||
Layout(const QJsonObject &json);
|
||||
|
||||
qreal maxTextWidth(int zoom) const
|
||||
@ -112,9 +111,9 @@ private:
|
||||
Qt::PenCapStyle lineCap(int zoom) const;
|
||||
Qt::PenJoinStyle lineJoin(int zoom) const;
|
||||
Text::Anchor textAnchor(int zoom) const;
|
||||
Text::Transform textTransform(int zoom) const;
|
||||
|
||||
bool viewportAlignment() const {return _viewportAlignment;}
|
||||
bool capitalize() const {return _capitalize;}
|
||||
|
||||
private:
|
||||
Template _text;
|
||||
@ -125,8 +124,8 @@ private:
|
||||
FunctionS _lineCap;
|
||||
FunctionS _lineJoin;
|
||||
FunctionS _textAnchor;
|
||||
FunctionS _textTransform;
|
||||
QFont _font;
|
||||
bool _capitalize;
|
||||
bool _viewportAlignment;
|
||||
};
|
||||
|
||||
|
@ -187,7 +187,7 @@ void Text::addLabel(const QString &text, const QPainterPath &path,
|
||||
return;
|
||||
|
||||
TextPathItem *pi = new TextPathItem(text, reverse(tp) ? tp.toReversed()
|
||||
: tp, painter.font());
|
||||
: tp, painter.font(), _properties);
|
||||
if (!_sceneRect.contains(pi->boundingRect())) {
|
||||
delete pi;
|
||||
return;
|
||||
|
@ -16,10 +16,17 @@ public:
|
||||
Bottom
|
||||
};
|
||||
|
||||
enum Transform {
|
||||
None,
|
||||
Uppercase,
|
||||
Lowercase
|
||||
};
|
||||
|
||||
struct Properties {
|
||||
int maxWidth;
|
||||
int maxAngle;
|
||||
Anchor anchor;
|
||||
Transform transform;
|
||||
};
|
||||
|
||||
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
|
||||
TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
|
||||
const QFont &font) : TextItem(text), _path(path), _font(font)
|
||||
const QFont &font, const Text::Properties &prop)
|
||||
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
|
||||
_path(path), _font(font)
|
||||
{
|
||||
QPainterPathStroker s;
|
||||
s.setWidth(font.pixelSize());
|
||||
|
@ -4,12 +4,13 @@
|
||||
#include <QFont>
|
||||
#include <QString>
|
||||
#include "textitem.h"
|
||||
#include "text.h"
|
||||
|
||||
class TextPathItem : public TextItem
|
||||
{
|
||||
public:
|
||||
TextPathItem(const QString &text, const QPainterPath &path,
|
||||
const QFont &font);
|
||||
const QFont &font, const Text::Properties &prop);
|
||||
|
||||
QPainterPath shape() const {return _shape;}
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
|
@ -98,7 +98,8 @@ QRectF TextPointItem::computeTextRect(BoundingRectFunction brf) const
|
||||
|
||||
TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
|
||||
const QFont &font, const Text::Properties &prop, const QImage &icon)
|
||||
: TextItem(text), _pos(pos), _font(font), _icon(icon), _properties(prop)
|
||||
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
|
||||
_pos(pos), _font(font), _icon(icon), _properties(prop)
|
||||
{
|
||||
_boundingRect = computeTextRect(fuzzyBoundingRect);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user