mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52: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;
|
||||
}
|
||||
|
||||
static QByteArray ft2m(const QByteArray &str)
|
||||
{
|
||||
bool ok;
|
||||
int number = str.toInt(&ok);
|
||||
return ok ? QByteArray::number(qRound(number * 0.3048)) : str;
|
||||
}
|
||||
|
||||
LBLFile::~LBLFile()
|
||||
{
|
||||
@ -130,13 +136,15 @@ void LBLFile::clear()
|
||||
_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;
|
||||
QByteArray label, shieldLabel;
|
||||
QByteArray *bap = &label;
|
||||
Charset curCharSet = Normal;
|
||||
quint8 b1, b2, b3;
|
||||
int split = -1;
|
||||
|
||||
if (!seek(hdl, offset))
|
||||
return Label();
|
||||
@ -149,6 +157,10 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
||||
|
||||
for (int cpt = 0; cpt < 4; cpt++) {
|
||||
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));
|
||||
return Label(capitalize && isAllUpperCase(text)
|
||||
? capitalized(text) : text, Shield(shieldType, shieldLabel));
|
||||
@ -159,7 +171,16 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
|
||||
curCharSet = Symbol;
|
||||
else if (c[cpt] == 0x1b)
|
||||
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);
|
||||
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;
|
||||
QByteArray label, shieldLabel;
|
||||
QByteArray *bap = &label;
|
||||
int split = -1;
|
||||
|
||||
for (int i = 0; i < str.size(); 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)) {
|
||||
if (bap == &shieldLabel)
|
||||
bap = &label;
|
||||
else
|
||||
bap->append(' ');
|
||||
else {
|
||||
if (!bap->isEmpty())
|
||||
bap->append('\n');
|
||||
if (c == 0x1f && split < 0)
|
||||
split = bap->size();
|
||||
}
|
||||
} else if (c < 0x07) {
|
||||
shieldType = static_cast<Shield::Type>(c);
|
||||
bap = &shieldLabel;
|
||||
@ -209,13 +236,17 @@ Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize) const
|
||||
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));
|
||||
|
||||
return Label(capitalize && isAllUpperCase(text) ? capitalized(text) : text,
|
||||
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;
|
||||
quint8 c;
|
||||
@ -229,10 +260,11 @@ Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize) const
|
||||
str.append(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;
|
||||
|
||||
@ -241,7 +273,7 @@ Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const
|
||||
if (!_huffmanText->decode(this, hdl, str))
|
||||
return Label();
|
||||
if (!_table)
|
||||
return str2label(str, capitalize);
|
||||
return str2label(str, capitalize, convert);
|
||||
|
||||
|
||||
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;
|
||||
if (poi) {
|
||||
@ -289,12 +322,12 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize) con
|
||||
|
||||
switch (_encoding) {
|
||||
case 6:
|
||||
return label6b(hdl, labelOffset, capitalize);
|
||||
return label6b(hdl, labelOffset, capitalize, convert);
|
||||
case 9:
|
||||
case 10:
|
||||
return label8b(hdl, labelOffset, capitalize);
|
||||
return label8b(hdl, labelOffset, capitalize, convert);
|
||||
case 11:
|
||||
return labelHuffman(hdl, labelOffset, capitalize);
|
||||
return labelHuffman(hdl, labelOffset, capitalize, convert);
|
||||
default:
|
||||
return Label();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
void clear();
|
||||
|
||||
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;}
|
||||
QPixmap image(Handle &hdl, quint32 id) const;
|
||||
@ -43,10 +43,14 @@ private:
|
||||
quint32 size;
|
||||
};
|
||||
|
||||
Label str2label(const QVector<quint8> &str, bool capitalize) const;
|
||||
Label label6b(Handle &hdl, quint32 offset, bool capitalize) const;
|
||||
Label label8b(Handle &hdl, quint32 offset, bool capitalize) const;
|
||||
Label labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const;
|
||||
Label str2label(const QVector<quint8> &str, bool capitalize,
|
||||
bool convert) const;
|
||||
Label label6b(Handle &hdl, quint32 offset, bool capitalize,
|
||||
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,
|
||||
quint32 recordSize);
|
||||
|
||||
|
@ -21,13 +21,6 @@ static const QColor shieldBgColor1("#dd3e3e");
|
||||
static const QColor shieldBgColor2("#379947");
|
||||
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)
|
||||
{
|
||||
QFont f;
|
||||
@ -350,9 +343,6 @@ void RasterTile::processStreetNames(const QRect &tileRect,
|
||||
|| style.textFontSize() == Style::None)
|
||||
continue;
|
||||
|
||||
if (Style::isContourLine(poly.type))
|
||||
poly.label.setText(convertUnits(poly.label.text()));
|
||||
|
||||
const QFont *fnt = font(style.textFontSize(), Style::Small);
|
||||
const QColor *color = style.textColor().isValid()
|
||||
? &style.textColor() : 0;
|
||||
@ -450,14 +440,6 @@ void RasterTile::processPoints(QList<TextItem*> &textItems)
|
||||
if ((!label || !fnt) && !img)
|
||||
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(),
|
||||
point.coordinates.lat()), label, fnt, img, color, &haloColor);
|
||||
if (item->isValid() && !item->collides(textItems))
|
||||
|
@ -237,9 +237,11 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
|
||||
quint32 lblOff;
|
||||
if (net && net->lblOffset(netHdl, labelPtr & 0x3FFFFF, lblOff)
|
||||
&& lblOff)
|
||||
poly.label = lbl->label(lblHdl, lblOff);
|
||||
poly.label = lbl->label(lblHdl, lblOff, false, true,
|
||||
Style::isContourLine(poly.type));
|
||||
} else
|
||||
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF);
|
||||
poly.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF, false,
|
||||
true, Style::isContourLine(poly.type));
|
||||
}
|
||||
|
||||
polys->append(poly);
|
||||
@ -351,7 +353,8 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
|
||||
return false;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -396,7 +399,7 @@ bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv,
|
||||
if (lbl && (labelPtr & 0x3FFFFF))
|
||||
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF,
|
||||
labelPtr & 0x400000, !(Style::isCountry(point.type)
|
||||
|| Style::isState(point.type)));
|
||||
|| Style::isState(point.type)), Style::isSpot(point.type));
|
||||
|
||||
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.id = pointId(pos, point.type, labelPtr & 0x3FFFFF);
|
||||
if (lbl && (labelPtr & 0x3FFFFF))
|
||||
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF, false);
|
||||
point.label = lbl->label(lblHdl, labelPtr & 0x3FFFFF);
|
||||
|
||||
points->append(point);
|
||||
}
|
||||
|
@ -111,8 +111,6 @@ public:
|
||||
{return (type == TYPE(0x16) || type == 0x10a03);}
|
||||
static bool isSpot(quint32 type)
|
||||
{return (type == TYPE(0x62) || type == TYPE(0x63));}
|
||||
static bool isSummit(quint32 type)
|
||||
{return (type == 0x6616);}
|
||||
static bool isMajorRoad(quint32 type)
|
||||
{return (type <= TYPE(0x04));}
|
||||
static bool isCountry(quint32 type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user