mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
Improved handling of labels with separators
This commit is contained in:
parent
78e8b03d66
commit
ab062cc3ff
@ -57,6 +57,12 @@ static QString capitalized(const QString &str)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QByteArray ft2m(const QByteArray &str)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
int number = str.toInt(&ok);
|
||||||
|
return ok ? QByteArray::number(qRound(number * 0.3048)) : str;
|
||||||
|
}
|
||||||
|
|
||||||
LBLFile::~LBLFile()
|
LBLFile::~LBLFile()
|
||||||
{
|
{
|
||||||
@ -130,13 +136,15 @@ void LBLFile::clear()
|
|||||||
_rasters = 0;
|
_rasters = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
|
bool convert) const
|
||||||
{
|
{
|
||||||
Shield::Type shieldType = Shield::None;
|
Shield::Type shieldType = Shield::None;
|
||||||
QByteArray label, shieldLabel;
|
QByteArray label, shieldLabel;
|
||||||
QByteArray *bap = &label;
|
QByteArray *bap = &label;
|
||||||
Charset curCharSet = Normal;
|
Charset curCharSet = Normal;
|
||||||
quint8 b1, b2, b3;
|
quint8 b1, b2, b3;
|
||||||
|
int split = -1;
|
||||||
|
|
||||||
if (!seek(hdl, offset))
|
if (!seek(hdl, offset))
|
||||||
return Label();
|
return Label();
|
||||||
@ -149,6 +157,10 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
|
|
||||||
for (int cpt = 0; cpt < 4; cpt++) {
|
for (int cpt = 0; cpt < 4; cpt++) {
|
||||||
if (c[cpt] > 0x2f || (curCharSet == Normal && c[cpt] == 0x1d)) {
|
if (c[cpt] > 0x2f || (curCharSet == Normal && c[cpt] == 0x1d)) {
|
||||||
|
if (split >= 0)
|
||||||
|
label = label.left(split) + ft2m(label.mid(split));
|
||||||
|
else if (convert)
|
||||||
|
label = ft2m(label);
|
||||||
QString text(QString::fromLatin1(label));
|
QString text(QString::fromLatin1(label));
|
||||||
return Label(capitalize && isAllUpperCase(text)
|
return Label(capitalize && isAllUpperCase(text)
|
||||||
? capitalized(text) : text, Shield(shieldType, shieldLabel));
|
? capitalized(text) : text, Shield(shieldType, shieldLabel));
|
||||||
@ -159,7 +171,16 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
curCharSet = Symbol;
|
curCharSet = Symbol;
|
||||||
else if (c[cpt] == 0x1b)
|
else if (c[cpt] == 0x1b)
|
||||||
curCharSet = Special;
|
curCharSet = Special;
|
||||||
else if (c[cpt] >= 0x2a && c[cpt] <= 0x2f) {
|
else if (c[cpt] >= 0x1e && c[cpt] <= 0x1f) {
|
||||||
|
if (bap == &shieldLabel)
|
||||||
|
bap = &label;
|
||||||
|
else {
|
||||||
|
if (!bap->isEmpty())
|
||||||
|
bap->append('\n');
|
||||||
|
if (c[cpt] == 0x1f && split < 0)
|
||||||
|
split = bap->size();
|
||||||
|
}
|
||||||
|
} else if (c[cpt] >= 0x2a && c[cpt] <= 0x2f) {
|
||||||
shieldType = static_cast<Shield::Type>(c[cpt] - 0x29);
|
shieldType = static_cast<Shield::Type>(c[cpt] - 0x29);
|
||||||
bap = &shieldLabel;
|
bap = &shieldLabel;
|
||||||
} else if (bap == &shieldLabel
|
} else if (bap == &shieldLabel
|
||||||
@ -181,11 +202,13 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize) const
|
Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize,
|
||||||
|
bool convert) const
|
||||||
{
|
{
|
||||||
Shield::Type shieldType = Shield::None;
|
Shield::Type shieldType = Shield::None;
|
||||||
QByteArray label, shieldLabel;
|
QByteArray label, shieldLabel;
|
||||||
QByteArray *bap = &label;
|
QByteArray *bap = &label;
|
||||||
|
int split = -1;
|
||||||
|
|
||||||
for (int i = 0; i < str.size(); i++) {
|
for (int i = 0; i < str.size(); i++) {
|
||||||
const quint8 &c = str.at(i);
|
const quint8 &c = str.at(i);
|
||||||
@ -198,8 +221,12 @@ Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize) const
|
|||||||
else if ((c >= 0x1e && c <= 0x1f)) {
|
else if ((c >= 0x1e && c <= 0x1f)) {
|
||||||
if (bap == &shieldLabel)
|
if (bap == &shieldLabel)
|
||||||
bap = &label;
|
bap = &label;
|
||||||
else
|
else {
|
||||||
bap->append(' ');
|
if (!bap->isEmpty())
|
||||||
|
bap->append('\n');
|
||||||
|
if (c == 0x1f && split < 0)
|
||||||
|
split = bap->size();
|
||||||
|
}
|
||||||
} else if (c < 0x07) {
|
} else if (c < 0x07) {
|
||||||
shieldType = static_cast<Shield::Type>(c);
|
shieldType = static_cast<Shield::Type>(c);
|
||||||
bap = &shieldLabel;
|
bap = &shieldLabel;
|
||||||
@ -209,13 +236,17 @@ Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize) const
|
|||||||
bap->append(c);
|
bap->append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (split >= 0)
|
||||||
|
label = label.left(split) + ft2m(label.mid(split));
|
||||||
|
else if (convert)
|
||||||
|
label = ft2m(label);
|
||||||
QString text(_codec.toString(label));
|
QString text(_codec.toString(label));
|
||||||
|
|
||||||
return Label(capitalize && isAllUpperCase(text) ? capitalized(text) : text,
|
return Label(capitalize && isAllUpperCase(text) ? capitalized(text) : text,
|
||||||
Shield(shieldType, _codec.toString(shieldLabel)));
|
Shield(shieldType, _codec.toString(shieldLabel)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize) const
|
Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
|
bool convert) const
|
||||||
{
|
{
|
||||||
QVector<quint8> str;
|
QVector<quint8> str;
|
||||||
quint8 c;
|
quint8 c;
|
||||||
@ -229,10 +260,11 @@ Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
str.append(c);
|
str.append(c);
|
||||||
} while (c);
|
} while (c);
|
||||||
|
|
||||||
return str2label(str, capitalize);
|
return str2label(str, capitalize, convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const
|
Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
|
bool convert) const
|
||||||
{
|
{
|
||||||
QVector<quint8> str;
|
QVector<quint8> str;
|
||||||
|
|
||||||
@ -241,7 +273,7 @@ Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
if (!_huffmanText->decode(this, hdl, str))
|
if (!_huffmanText->decode(this, hdl, str))
|
||||||
return Label();
|
return Label();
|
||||||
if (!_table)
|
if (!_table)
|
||||||
return str2label(str, capitalize);
|
return str2label(str, capitalize, convert);
|
||||||
|
|
||||||
|
|
||||||
QVector<quint8> str2;
|
QVector<quint8> str2;
|
||||||
@ -268,10 +300,11 @@ Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str2label(str2, capitalize);
|
return str2label(str2, capitalize, convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize) const
|
Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize,
|
||||||
|
bool convert) const
|
||||||
{
|
{
|
||||||
quint32 labelOffset;
|
quint32 labelOffset;
|
||||||
if (poi) {
|
if (poi) {
|
||||||
@ -289,12 +322,12 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize) con
|
|||||||
|
|
||||||
switch (_encoding) {
|
switch (_encoding) {
|
||||||
case 6:
|
case 6:
|
||||||
return label6b(hdl, labelOffset, capitalize);
|
return label6b(hdl, labelOffset, capitalize, convert);
|
||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
return label8b(hdl, labelOffset, capitalize);
|
return label8b(hdl, labelOffset, capitalize, convert);
|
||||||
case 11:
|
case 11:
|
||||||
return labelHuffman(hdl, labelOffset, capitalize);
|
return labelHuffman(hdl, labelOffset, capitalize, convert);
|
||||||
default:
|
default:
|
||||||
return Label();
|
return Label();
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
Label label(Handle &hdl, quint32 offset, bool poi = false,
|
Label label(Handle &hdl, quint32 offset, bool poi = false,
|
||||||
bool capitalize = true) const;
|
bool capitalize = true, bool convert = false) const;
|
||||||
|
|
||||||
quint8 imageIdSize() const {return _imgOffsetIdSize;}
|
quint8 imageIdSize() const {return _imgOffsetIdSize;}
|
||||||
QPixmap image(Handle &hdl, quint32 id) const;
|
QPixmap image(Handle &hdl, quint32 id) const;
|
||||||
@ -43,10 +43,14 @@ private:
|
|||||||
quint32 size;
|
quint32 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
Label str2label(const QVector<quint8> &str, bool capitalize) const;
|
Label str2label(const QVector<quint8> &str, bool capitalize,
|
||||||
Label label6b(Handle &hdl, quint32 offset, bool capitalize) const;
|
bool convert) const;
|
||||||
Label label8b(Handle &hdl, quint32 offset, bool capitalize) const;
|
Label label6b(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
Label labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const;
|
bool convert) const;
|
||||||
|
Label label8b(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
|
bool convert) const;
|
||||||
|
Label labelHuffman(Handle &hdl, quint32 offset, bool capitalize,
|
||||||
|
bool convert) const;
|
||||||
bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
|
bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
|
||||||
quint32 recordSize);
|
quint32 recordSize);
|
||||||
|
|
||||||
|
@ -21,13 +21,6 @@ static const QColor shieldBgColor1("#dd3e3e");
|
|||||||
static const QColor shieldBgColor2("#379947");
|
static const QColor shieldBgColor2("#379947");
|
||||||
static const QColor shieldBgColor3("#4a7fc1");
|
static const QColor shieldBgColor3("#4a7fc1");
|
||||||
|
|
||||||
static QString convertUnits(const QString &str)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
int number = str.toInt(&ok);
|
|
||||||
return ok ? QString::number(qRound(number * 0.3048)) : str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QFont pixelSizeFont(int pixelSize)
|
static QFont pixelSizeFont(int pixelSize)
|
||||||
{
|
{
|
||||||
QFont f;
|
QFont f;
|
||||||
@ -350,9 +343,6 @@ void RasterTile::processStreetNames(const QRect &tileRect,
|
|||||||
|| style.textFontSize() == Style::None)
|
|| style.textFontSize() == Style::None)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Style::isContourLine(poly.type))
|
|
||||||
poly.label.setText(convertUnits(poly.label.text()));
|
|
||||||
|
|
||||||
const QFont *fnt = font(style.textFontSize(), Style::Small);
|
const QFont *fnt = font(style.textFontSize(), Style::Small);
|
||||||
const QColor *color = style.textColor().isValid()
|
const QColor *color = style.textColor().isValid()
|
||||||
? &style.textColor() : 0;
|
? &style.textColor() : 0;
|
||||||
@ -450,14 +440,6 @@ void RasterTile::processPoints(QList<TextItem*> &textItems)
|
|||||||
if ((!label || !fnt) && !img)
|
if ((!label || !fnt) && !img)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Style::isSpot(point.type))
|
|
||||||
point.label.setText(convertUnits(point.label.text()));
|
|
||||||
if (Style::isSummit(point.type) && !point.label.text().isEmpty()) {
|
|
||||||
QStringList list = point.label.text().split(" ");
|
|
||||||
list.last() = convertUnits(list.last());
|
|
||||||
point.label = list.join(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
TextPointItem *item = new TextPointItem(QPoint(point.coordinates.lon(),
|
TextPointItem *item = new TextPointItem(QPoint(point.coordinates.lon(),
|
||||||
point.coordinates.lat()), label, fnt, img, color, &haloColor);
|
point.coordinates.lat()), label, fnt, img, color, &haloColor);
|
||||||
if (item->isValid() && !item->collides(textItems))
|
if (item->isValid() && !item->collides(textItems))
|
||||||
|
@ -237,9 +237,11 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
|
|||||||
quint32 lblOff;
|
quint32 lblOff;
|
||||||
if (net && net->lblOffset(netHdl, labelPtr & 0x3FFFFF, lblOff)
|
if (net && net->lblOffset(netHdl, labelPtr & 0x3FFFFF, lblOff)
|
||||||
&& lblOff)
|
&& lblOff)
|
||||||
poly.label = lbl->label(lblHdl, lblOff);
|
poly.label = lbl->label(lblHdl, lblOff, false, true,
|
||||||
|
Style::isContourLine(poly.type));
|
||||||
} else
|
} else
|
||||||
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF);
|
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF, false,
|
||||||
|
true, Style::isContourLine(poly.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
polys->append(poly);
|
polys->append(poly);
|
||||||
@ -351,7 +353,8 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (lbl && (labelPtr & 0x3FFFFF))
|
if (lbl && (labelPtr & 0x3FFFFF))
|
||||||
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF);
|
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF, false, true,
|
||||||
|
Style::isContourLine(poly.type));
|
||||||
|
|
||||||
polys->append(poly);
|
polys->append(poly);
|
||||||
}
|
}
|
||||||
@ -396,7 +399,7 @@ bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv,
|
|||||||
if (lbl && (labelPtr & 0x3FFFFF))
|
if (lbl && (labelPtr & 0x3FFFFF))
|
||||||
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF,
|
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF,
|
||||||
labelPtr & 0x400000, !(Style::isCountry(point.type)
|
labelPtr & 0x400000, !(Style::isCountry(point.type)
|
||||||
|| Style::isState(point.type)));
|
|| Style::isState(point.type)), Style::isSpot(point.type));
|
||||||
|
|
||||||
points->append(point);
|
points->append(point);
|
||||||
}
|
}
|
||||||
@ -446,7 +449,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv,
|
|||||||
point.coordinates = Coordinates(toWGS24(pos.x()), toWGS24(pos.y()));
|
point.coordinates = Coordinates(toWGS24(pos.x()), toWGS24(pos.y()));
|
||||||
point.id = pointId(pos, point.type, labelPtr & 0x3FFFFF);
|
point.id = pointId(pos, point.type, labelPtr & 0x3FFFFF);
|
||||||
if (lbl && (labelPtr & 0x3FFFFF))
|
if (lbl && (labelPtr & 0x3FFFFF))
|
||||||
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF, false);
|
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF);
|
||||||
|
|
||||||
points->append(point);
|
points->append(point);
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,6 @@ public:
|
|||||||
{return (type == TYPE(0x16) || type == 0x10a03);}
|
{return (type == TYPE(0x16) || type == 0x10a03);}
|
||||||
static bool isSpot(quint32 type)
|
static bool isSpot(quint32 type)
|
||||||
{return (type == TYPE(0x62) || type == TYPE(0x63));}
|
{return (type == TYPE(0x62) || type == TYPE(0x63));}
|
||||||
static bool isSummit(quint32 type)
|
|
||||||
{return (type == 0x6616);}
|
|
||||||
static bool isMajorRoad(quint32 type)
|
static bool isMajorRoad(quint32 type)
|
||||||
{return (type <= TYPE(0x04));}
|
{return (type <= TYPE(0x04));}
|
||||||
static bool isCountry(quint32 type)
|
static bool isCountry(quint32 type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user