Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #52799 from mhugent/server_pdf_format_options
Server pdf format options
  • Loading branch information
mhugent committed May 26, 2023
2 parents 26406fe + 86457f3 commit 9f23a2c
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 30 deletions.
163 changes: 142 additions & 21 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -1579,7 +1579,7 @@ namespace QgsWms
bool QgsWmsParameters::isForce2D() const
{
bool force2D = false;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

if ( options.contains( DxfFormatOption::FORCE_2D ) )
{
Expand All @@ -1592,7 +1592,7 @@ namespace QgsWms
bool QgsWmsParameters::noMText() const
{
bool noMText = false;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

if ( options.contains( DxfFormatOption::NO_MTEXT ) )
{
Expand Down Expand Up @@ -2156,7 +2156,7 @@ namespace QgsWms
QStringList QgsWmsParameters::dxfLayerAttributes() const
{
QStringList attributes;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

if ( options.contains( DxfFormatOption::LAYERATTRIBUTES ) )
{
Expand All @@ -2169,7 +2169,7 @@ namespace QgsWms
bool QgsWmsParameters::dxfUseLayerTitleAsName() const
{
bool use = false;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

if ( options.contains( DxfFormatOption::USE_TITLE_AS_LAYERNAME ) )
{
Expand All @@ -2181,7 +2181,7 @@ namespace QgsWms

double QgsWmsParameters::dxfScale() const
{
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

double scale = -1;
if ( options.contains( DxfFormatOption::SCALE ) )
Expand All @@ -2194,7 +2194,7 @@ namespace QgsWms

Qgis::FeatureSymbologyExport QgsWmsParameters::dxfMode() const
{
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();

Qgis::FeatureSymbologyExport symbol = Qgis::FeatureSymbologyExport::NoSymbology;

Expand All @@ -2220,35 +2220,156 @@ namespace QgsWms
{
QString codec = QStringLiteral( "ISO-8859-1" );

if ( dxfFormatOptions().contains( DxfFormatOption::CODEC ) )
if ( formatOptions<QgsWmsParameters::DxfFormatOption>().contains( DxfFormatOption::CODEC ) )
{
codec = dxfFormatOptions()[ DxfFormatOption::CODEC ];
codec = formatOptions<QgsWmsParameters::DxfFormatOption>()[ DxfFormatOption::CODEC ];
}

return codec;
}

QMap<QgsWmsParameters::DxfFormatOption, QString> QgsWmsParameters::dxfFormatOptions() const
bool QgsWmsParameters::writeGeoPdf() const
{
QMap<QgsWmsParameters::DxfFormatOption, QString> options;
bool geoPdf = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::WRITE_GEO_PDF ) )
{
geoPdf = QVariant( options[PdfFormatOption::WRITE_GEO_PDF] ).toBool();
}
return geoPdf;
}

bool QgsWmsParameters::pdfForceVectorOutput() const
{
bool forceVector = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::FORCE_VECTOR_OUTPUT ) )
{
forceVector = QVariant( options[PdfFormatOption::FORCE_VECTOR_OUTPUT] ).toBool();
}
return forceVector;
}

bool QgsWmsParameters::pdfAppendGeoreference() const
{
bool appendGeoref = true;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::APPEND_GEOREFERENCE ) )
{
appendGeoref = QVariant( options[PdfFormatOption::APPEND_GEOREFERENCE] ).toBool();
}
return appendGeoref;
}

bool QgsWmsParameters::pdfSimplifyGeometries() const
{
bool simplify = true;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::SIMPLIFY_GEOMETRY ) )
{
simplify = QVariant( options[PdfFormatOption::SIMPLIFY_GEOMETRY] ).toBool();
}
return simplify;
}

const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameters::DxfFormatOption>() );
const QStringList opts = mWmsParameters.value( QgsWmsParameter::FORMAT_OPTIONS ).toStringList( ';' );
bool QgsWmsParameters::pdfExportMetadata() const
{
bool exportMetadata = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::EXPORT_METADATA ) )
{
exportMetadata = QVariant( options[PdfFormatOption::EXPORT_METADATA] ).toBool();
}
return exportMetadata;
}

for ( auto it = opts.constBegin(); it != opts.constEnd(); ++it )
Qgis::TextRenderFormat QgsWmsParameters::pdfTextRenderFormat() const
{
Qgis::TextRenderFormat format = Qgis::TextRenderFormat::AlwaysOutlines;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::TEXT_RENDER_FORMAT ) )
{
const int equalIdx = it->indexOf( ':' );
if ( equalIdx > 0 && equalIdx < ( it->length() - 1 ) )
if ( options[PdfFormatOption::TEXT_RENDER_FORMAT].compare( QStringLiteral( "AlwaysText" ), Qt::CaseInsensitive ) == 0 )
{
const QString name = it->left( equalIdx ).toUpper();
const QgsWmsParameters::DxfFormatOption option =
( QgsWmsParameters::DxfFormatOption ) metaEnum.keyToValue( name.toStdString().c_str() );
const QString value = it->right( it->length() - equalIdx - 1 );
options.insert( option, value );
format = Qgis::TextRenderFormat::AlwaysText;
}
}
return format;
}

bool QgsWmsParameters::pdfLosslessImageCompression() const
{
bool losslessCompression = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION ) )
{
losslessCompression = QVariant( options[PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION] ).toBool();
}
return losslessCompression;
}

bool QgsWmsParameters::pdfDisableTiledRasterRendering() const
{
bool disableTiledRaster = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::DISABLE_TILED_RASTER_RENDERING ) )
{
disableTiledRaster = QVariant( options[PdfFormatOption::DISABLE_TILED_RASTER_RENDERING] ).toBool();
}
return disableTiledRaster;
}

bool QgsWmsParameters::pdfUseIso32000ExtensionFormatGeoreferencing() const
{
bool useIso32000 = true;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::USE_ISO_32000_EXTENSION_FORMAT_GEOREFERENCING ) )
{
useIso32000 = QVariant( options[PdfFormatOption::USE_ISO_32000_EXTENSION_FORMAT_GEOREFERENCING] ).toBool();
}
return useIso32000;
}

bool QgsWmsParameters::pdfUseOgcBestPracticeFormatGeoreferencing() const
{
bool useOgcGeoreferencing = false;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::USE_OGC_BEST_PRACTICE_FORMAT_GEOREFERENCING ) )
{
useOgcGeoreferencing = QVariant( options[PdfFormatOption::USE_OGC_BEST_PRACTICE_FORMAT_GEOREFERENCING] ).toBool();
}
return useOgcGeoreferencing;
}

QStringList QgsWmsParameters::pdfExportMapThemes() const
{
QStringList themes;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::EXPORT_THEMES ) )
{
themes = options[PdfFormatOption::EXPORT_THEMES].split( ',' );
}
return themes;
}

return options;
QVector<qreal> QgsWmsParameters::pdfPredefinedMapScales() const
{
QVector<qreal> scales;
const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
if ( options.contains( PdfFormatOption::PREDEFINED_MAP_SCALES ) )
{
const QStringList scaleList = options[PdfFormatOption::PREDEFINED_MAP_SCALES].split( ',' );
for ( const QString &it : std::as_const( scaleList ) )
{
bool ok = false;
qreal scale = it.toDouble( &ok );
if ( ok )
{
scales.append( scale );
}
}
}
return scales;
}

QMap<QString, QString> QgsWmsParameters::dimensionValues() const
Expand Down
128 changes: 122 additions & 6 deletions src/server/services/wms/qgswmsparameters.h
Expand Up @@ -366,6 +366,25 @@ namespace QgsWms
};
Q_ENUM( DxfFormatOption )

enum PdfFormatOption
{
RASTERIZE_WHOLE_IMAGE,
FORCE_VECTOR_OUTPUT,
APPEND_GEOREFERENCE,
EXPORT_METADATA,
TEXT_RENDER_FORMAT,
SIMPLIFY_GEOMETRY,
WRITE_GEO_PDF,
USE_ISO_32000_EXTENSION_FORMAT_GEOREFERENCING,
USE_OGC_BEST_PRACTICE_FORMAT_GEOREFERENCING,
INCLUDE_GEO_PDF_FEATURES,
EXPORT_THEMES,
PREDEFINED_MAP_SCALES,
LOSSLESS_IMAGE_COMPRESSION,
DISABLE_TILED_RASTER_RENDERING
};
Q_ENUM( PdfFormatOption )

/**
* Constructor for WMS parameters with specific values.
* \param parameters Map of parameters where keys are parameters' names.
Expand Down Expand Up @@ -1316,12 +1335,6 @@ namespace QgsWms
*/
QStringList atlasPk() const;

/**
* Returns a map of DXF options defined within FORMAT_OPTIONS parameter.
* \since QGIS 3.8
*/
QMap<DxfFormatOption, QString> dxfFormatOptions() const;

/**
* Returns the DXF LAYERATTRIBUTES parameter.
* \since QGIS 3.8
Expand Down Expand Up @@ -1374,11 +1387,114 @@ namespace QgsWms
*/
bool isForce2D() const;

/**
* Returns if a GeoPDF shall be exported
* \since QGIS 3.32
*/
bool writeGeoPdf() const;

/**
* Returns if pdf should be exported as vector
* \since QGIS 3.32
*/
bool pdfForceVectorOutput() const;

/**
* Returns true if georeference info shall be added to the pdf
* \since QGIS 3.32
*/
bool pdfAppendGeoreference() const;

/**
* Returns if geometries shall to be simplified
* \since QGIS 3.32
*/
bool pdfSimplifyGeometries() const;

/**
* Returns true if metadata shall be added to the pdf
* \since QGIS 3.32
*/
bool pdfExportMetadata() const;

/**
* Returns text render format for pdf export
* \since QGIS 3.32
*/
Qgis::TextRenderFormat pdfTextRenderFormat() const;

/**
* Returns true if images embedded in pdf must be compressed using a lossless algorithm
* \since QGIS 3.32
*/
bool pdfLosslessImageCompression() const;

/**
* Returns true if rasters shall be untiled in the pdf
* \since QGIS 3.32
*/
bool pdfDisableTiledRasterRendering() const;

/**
* Returns true, if Iso32000 georeferencing shall be used
* \since QGIS 3.32
*/
bool pdfUseIso32000ExtensionFormatGeoreferencing() const;

/**
* Returns true if OGC best practice georeferencing shall be used
* \since QGIS 3.32
*/
bool pdfUseOgcBestPracticeFormatGeoreferencing() const;

/**
* Returns map themes for GeoPDF export
* \since QGIS 3.32
*/
QStringList pdfExportMapThemes() const;

/**
* Returns list of map scales
* \since QGIS 3.32
*/
QVector<qreal> pdfPredefinedMapScales() const;

QString version() const override;

QString request() const override;

/**
* Returns the format options for an output format. Possible template types are QgsWmsParameters::PdfFormatOption or QgsWmsParameters::DxfFormatOption
* \returns a key-value map
* \since QGIS 3.32
*/
template<typename T> QMap< T, QString > formatOptions() const
{
QMap<T, QString> options;
const QMetaEnum metaEnum( QMetaEnum::fromType<T>() );
const QStringList opts = mWmsParameters.value( QgsWmsParameter::FORMAT_OPTIONS ).toStringList( ';' );

for ( auto it = opts.constBegin(); it != opts.constEnd(); ++it )
{
const int equalIdx = it->indexOf( ':' );
if ( equalIdx > 0 && equalIdx < ( it->length() - 1 ) )
{
const QString name = it->left( equalIdx ).toUpper();
int metaEnumVal = metaEnum.keyToValue( name.toStdString().c_str() );
if ( metaEnumVal < 0 )
{
continue; //option for a different format
}
const T option = ( T )metaEnumVal;
const QString value = it->right( it->length() - equalIdx - 1 );
options.insert( option, value );
}
}
return options;
}

private:

static bool isExternalLayer( const QString &name );

bool loadParameter( const QString &name, const QString &value ) override;
Expand Down

0 comments on commit 9f23a2c

Please sign in to comment.