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