Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OgrFileImport: Improve DXF import of text objects #2135

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/gdal/ogr_file_format.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 Kai Pastor
* Copyright 2016-2023 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -1166,6 +1166,7 @@ OgrFileImport::ObjectList OgrFileImport::importGeometryCollection(OGRFeatureH fe

Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geometry)
{
object_properties.clear();
auto style = OGR_F_GetStyleString(feature);
auto symbol = getSymbol(Symbol::Point, style);
if (symbol->getType() == Symbol::Point)
Expand All @@ -1175,15 +1176,9 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo
return object;
}

if (symbol->getType() == Symbol::Text)
if (symbol->getType() == Symbol::Text && !object_properties.isEmpty())
{
const auto& description = symbol->getDescription();
auto length = description.length();
auto split = description.indexOf(QLatin1Char(' '));
FILEFORMAT_ASSERT(split > 0);
FILEFORMAT_ASSERT(split < length);

auto label = description.right(length - split - 1);
auto label = object_properties.value(QLatin1String("label")).toString();
if (label.startsWith(QLatin1Char{'{'}) && label.endsWith(QLatin1Char{'}'}))
{
label.remove(0, 1);
Expand All @@ -1204,13 +1199,13 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo
object->setText(label);

bool ok;
auto anchor = QStringRef(&description, 1, 2).toInt(&ok);
auto anchor = object_properties.value(QLatin1String("anchor"), 1).toInt(&ok);
if (ok)
{
applyLabelAnchor(anchor, object);
}
auto angle = QStringRef(&description, 3, split-3).toDouble(&ok);

auto angle = object_properties.value(QLatin1String("angle"), 0.0).toDouble(&ok);
if (ok)
{
object->setRotation(qDegreesToRadians(angle));
Expand Down Expand Up @@ -1676,21 +1671,15 @@ TextSymbol* OgrFileImport::getSymbolForLabel(OGRStyleToolH tool, const QByteArra
map->addSymbol(copy.release(), map->getNumSymbols());
}

object_properties.insert(QLatin1String("label"), QVariant(QString::fromUtf8(label_string)));

auto anchor = qBound(1, OGR_ST_GetParamNum(tool, OGRSTLabelAnchor, &is_null), 12);
if (is_null)
anchor = 1;
if (!is_null)
object_properties.insert(QLatin1String("anchor"), QVariant(anchor));

auto angle = OGR_ST_GetParamDbl(tool, OGRSTLabelAngle, &is_null);
if (is_null)
angle = 0.0;

QString description;
description.reserve(int(qstrlen(label_string) + 100));
description.append(QString::number(100 + anchor));
description.append(QString::number(angle, 'g', 1));
description.append(QLatin1Char(' '));
description.append(QString::fromUtf8(label_string));
text_symbol->setDescription(description);
if (!is_null)
object_properties.insert(QLatin1String("angle"), QVariant(angle));

return text_symbol;
}
Expand Down
4 changes: 3 additions & 1 deletion src/gdal/ogr_file_format_p.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 Kai Pastor
* Copyright 2016-2023 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -356,6 +356,8 @@ class OgrFileImport : public Importer
QHash<QByteArray, MapColor*> colors;
MapColor* default_pen_color;

QVariantHash object_properties;

MapCoordConstructor to_map_coord;

ogr::unique_srs map_srs;
Expand Down