Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When required text codecs aren't available on the system, proxy
the conversion over to GDAL's API Resolves missing text codecs like CP852 on windows builds. These were previously available, but then Qt upstream dropped the ICU library from their windows builds, and accordingly a whole bunch of older text codecs are no longer available by default on the windows builds. Fixes #36871
- Loading branch information
1 parent
c5af382
commit c3ca85e
Showing
12 changed files
with
212 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*************************************************************************** | ||
qgsogrproxytextcodec.cpp | ||
------------- | ||
begin : June 2020 | ||
copyright : (C) 2020 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsogrproxytextcodec.h" | ||
#include "qgslogger.h" | ||
#include <cpl_string.h> | ||
#include <mutex> | ||
|
||
QgsOgrProxyTextCodec::QgsOgrProxyTextCodec( const QByteArray &name ) | ||
: mName( name ) | ||
{ | ||
|
||
} | ||
|
||
QString QgsOgrProxyTextCodec::convertToUnicode( const char *chars, int, ConverterState * ) const | ||
{ | ||
if ( !chars ) | ||
return QString(); | ||
|
||
char *res = CPLRecode( chars, mName.constData(), CPL_ENC_UTF8 ); | ||
if ( !res ) | ||
{ | ||
QgsDebugMsg( "convertToUnicode failed" ); | ||
return QString(); | ||
} | ||
|
||
const QString result = QString::fromUtf8( res ); | ||
CPLFree( res ); | ||
return result; | ||
} | ||
|
||
QByteArray QgsOgrProxyTextCodec::convertFromUnicode( const QChar *unicode, int length, ConverterState * ) const | ||
{ | ||
if ( !unicode ) | ||
return QByteArray(); | ||
|
||
const QString src = QString( unicode, length ); | ||
char *res = CPLRecode( src.toUtf8().constData(), CPL_ENC_UTF8, mName.constData() ); | ||
if ( !res ) | ||
{ | ||
QgsDebugMsg( "convertFromUnicode failed" ); | ||
return QByteArray(); | ||
} | ||
|
||
const QByteArray result = QByteArray( res ); | ||
CPLFree( res ); | ||
return result; | ||
} | ||
|
||
// MY 5 YEAR OLD DAUGHTER WROTE THIS LINE, REMOVE AT YOUR OWN RISK!!! | ||
// i don't want this to be here | ||
|
||
QByteArray QgsOgrProxyTextCodec::name() const | ||
{ | ||
return mName; | ||
} | ||
|
||
QList<QByteArray> QgsOgrProxyTextCodec::aliases() const | ||
{ | ||
return QList<QByteArray>(); | ||
} | ||
|
||
int QgsOgrProxyTextCodec::mibEnum() const | ||
{ | ||
// doesn't seem required in this case | ||
return 0; | ||
} | ||
|
||
QStringList QgsOgrProxyTextCodec::supportedCodecs() | ||
{ | ||
static QStringList codecs; | ||
static std::once_flag initialized; | ||
std::call_once( initialized, [&]( ) | ||
{ | ||
// there's likely others that are supported by GDAL, but we're primarily concerned here | ||
// with codecs used by the shapefile driver, and which are no longer supported on the | ||
// windows Qt builds (due to removal of ICU support in windows Qt builds) | ||
// see https://github.com/qgis/QGIS/issues/36871 | ||
for ( int i = 437; i <= 950; ++i ) | ||
codecs << QStringLiteral( "CP%1" ).arg( i ); | ||
for ( int i = 1250; i <= 1258; ++i ) | ||
codecs << QStringLiteral( "CP%1" ).arg( i ); | ||
codecs << QStringLiteral( "CP1251" ); | ||
} ); | ||
return codecs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*************************************************************************** | ||
qgsogrproxytextcodec.h | ||
------------- | ||
begin : June 2020 | ||
copyright : (C) 2020 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSOGRPROXYTEXTCODEC_H | ||
#define QGSOGRPROXYTEXTCODEC_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis_core.h" | ||
|
||
#include <QTextCodec> | ||
|
||
/** | ||
* \ingroup core | ||
* \class QgsOgrProxyTextCodec | ||
* \brief A QTextCodec implementation which relies on OGR to do the text conversion. | ||
* \note not available in Python bindings | ||
* \since QGIS 3.14 | ||
*/ | ||
class CORE_EXPORT QgsOgrProxyTextCodec: public QTextCodec | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor for QgsOgrProxyTextCodec, for the specified encoding \a name. | ||
*/ | ||
QgsOgrProxyTextCodec( const QByteArray &name ); | ||
~QgsOgrProxyTextCodec() override = default; | ||
|
||
QString convertToUnicode( const char *in, int length, ConverterState *state ) const override; | ||
QByteArray convertFromUnicode( const QChar *in, int length, ConverterState *state ) const override; | ||
QByteArray name() const override; | ||
QList<QByteArray> aliases() const override; | ||
int mibEnum() const override; | ||
|
||
/** | ||
* Returns a list of supported text codecs. | ||
*/ | ||
static QStringList supportedCodecs(); | ||
|
||
private: | ||
|
||
QByteArray mName; | ||
}; | ||
|
||
#endif // QGSOGRPROXYTEXTCODEC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
852 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["WGS_1984_UTM_Zone_33N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",15.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["WGS 84 / UTM zone 33N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",15],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32633"]] |
Binary file not shown.
Binary file not shown.