mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2025-07-01 13:39:16 +02:00
Compare commits
59 Commits
2.3
...
cb86e30fab
Author | SHA1 | Date | |
---|---|---|---|
cb86e30fab | |||
407f543039 | |||
f24a8a47a9 | |||
ce7b3d9158 | |||
f064148a0f | |||
733375fb74 | |||
440f7f91a4 | |||
dbcfd9b9d3 | |||
672de3919b | |||
0a696a6ab8 | |||
d8a521623a | |||
f5f006dc7b | |||
c86eb7bac2 | |||
3ef6c55d20 | |||
98933deb0e | |||
6e1bc09d62 | |||
ea98da4a74 | |||
8261ee2e79 | |||
d5c315efbe | |||
39ffdaf616 | |||
38b6e2320b | |||
b36fb5fa92 | |||
a7b7d16f4f | |||
8cf73b5bb5 | |||
038f4e7d64 | |||
aaff1c0bdb | |||
37c6c36204 | |||
f901243baa | |||
19c6b9854f | |||
52d15c63bd | |||
71331b06f1 | |||
d6a24a4498 | |||
a26c86dbd8 | |||
0db93fd5ee | |||
f8044efda6 | |||
450a1458a3 | |||
bff8c7229c | |||
ff569644b6 | |||
6a32f0a447 | |||
1051a1c5b2 | |||
11e360d9a4 | |||
5577590f6b | |||
9dba35082b | |||
76f1a23f8d | |||
f931b653c4 | |||
b0885a4b05 | |||
7c34a2c4e1 | |||
0cb3edda05 | |||
871aad37da | |||
12c878d8e2 | |||
44862114ab | |||
1065a27bfb | |||
3c22cd7823 | |||
1afd242302 | |||
ae8b2f00db | |||
e22ea9aa12 | |||
62a78fdaae | |||
63f86a900e | |||
ea8819a381 |
32
.appveyor.yml
Normal file
32
.appveyor.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
version: 3.0.{build}
|
||||||
|
|
||||||
|
configuration:
|
||||||
|
- Release
|
||||||
|
|
||||||
|
image:
|
||||||
|
- Visual Studio 2022
|
||||||
|
|
||||||
|
environment:
|
||||||
|
VCPKGDIR: C:\tools\vcpkg\installed\x64-windows-static-md
|
||||||
|
matrix:
|
||||||
|
- QTDIR: C:\Qt\5.15\msvc2019_64
|
||||||
|
- QTDIR: C:\Qt\6.5\msvc2019_64
|
||||||
|
|
||||||
|
install:
|
||||||
|
- cmd: |-
|
||||||
|
set PATH=%QTDIR%\bin;%VCPKGDIR%\tools\protobuf;%PATH%
|
||||||
|
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||||
|
vcpkg install protobuf:x64-windows-static-md
|
||||||
|
vcpkg install zlib:x64-windows-static-md
|
||||||
|
copy /y %VCPKGDIR%\lib\zlib.lib %VCPKGDIR%\lib\zlibstatic.lib
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- cmd: |-
|
||||||
|
qmake PROTOBUF=%VCPKGDIR% ZLIB=%VCPKGDIR% pbfplugin.pro
|
||||||
|
nmake release
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
- path: release\pbf3.dll
|
||||||
|
|
||||||
|
cache:
|
||||||
|
- C:\tools\vcpkg\installed\
|
54
.github/workflows/android.yml
vendored
Normal file
54
.github/workflows/android.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
name: Android
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: QtPBFImagePlugin
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install protobuf compiler
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install protobuf-compiler
|
||||||
|
- name: set up JDK 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'zulu'
|
||||||
|
java-version: '11'
|
||||||
|
- name: Setup Android SDK
|
||||||
|
uses: android-actions/setup-android@v2
|
||||||
|
- name: Run sdkmanager update
|
||||||
|
run: ${ANDROID_HOME}/tools/bin/sdkmanager --update
|
||||||
|
- name: Install android platform, platform-tools, build-tools and ndk
|
||||||
|
run: ${ANDROID_HOME}/tools/bin/sdkmanager --install "cmdline-tools;latest" "platform-tools" "platforms;android-33" "build-tools;33.0.0" "ndk;23.1.7779620"
|
||||||
|
- name: Setup NDK path
|
||||||
|
run: echo "ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/23.1.7779620/" >> $GITHUB_ENV
|
||||||
|
- name: Install Qt (Desktop)
|
||||||
|
uses: jurplel/install-qt-action@v3
|
||||||
|
with:
|
||||||
|
aqtversion: '==3.1.*'
|
||||||
|
version: '6.4.0'
|
||||||
|
- name: Install Qt (Android)
|
||||||
|
uses: jurplel/install-qt-action@v3
|
||||||
|
with:
|
||||||
|
aqtversion: '==3.1.*'
|
||||||
|
version: '6.4.0'
|
||||||
|
target: 'android'
|
||||||
|
arch: 'android_arm64_v8a'
|
||||||
|
- name: Install Android Google Protocol Buffers
|
||||||
|
run: git clone https://github.com/tumic0/android_protobuf.git
|
||||||
|
- name: Configure build
|
||||||
|
run: qmake pbfplugin.pro PROTOBUF=android_protobuf
|
||||||
|
- name: Build project
|
||||||
|
run: make -j2
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: libplugins_imageformats_libpbf_arm64-v8a.so
|
||||||
|
path: plugins/libpbf/libplugins_imageformats_libpbf_arm64-v8a.so
|
22
.github/workflows/linux.yml
vendored
Normal file
22
.github/workflows/linux.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
name: Linux
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: QtPBFImagePlugin
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install qtbase5-dev qtbase5-dev-tools qt5-qmake libprotobuf-dev protobuf-compiler zlib1g-dev
|
||||||
|
- name: Configure build
|
||||||
|
run: qmake pbfplugin.pro
|
||||||
|
- name: Build project
|
||||||
|
run: make -j2
|
37
.github/workflows/osx.yml
vendored
Normal file
37
.github/workflows/osx.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
name: OS X
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
qt5:
|
||||||
|
name: QtPBFImagePlugin Qt5 build
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Set environment variables
|
||||||
|
run: echo "PATH=/usr/local/opt/qt@5/bin:/usr/local/opt/protobuf@21/bin:$PATH" >> $GITHUB_ENV
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install dependencies
|
||||||
|
run: brew install qt@5 protobuf@21
|
||||||
|
- name: Configure build
|
||||||
|
run: qmake PROTOBUF=/usr/local/opt/protobuf@21 pbfplugin.pro
|
||||||
|
- name: Build project
|
||||||
|
run: make -j3
|
||||||
|
|
||||||
|
qt6:
|
||||||
|
name: QtPBFImagePlugin Qt6 build
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Set environment variables
|
||||||
|
run: echo "PATH=/usr/local/opt/qt@6/bin:/usr/local/opt/protobuf@21/bin:$PATH" >> $GITHUB_ENV
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install dependencies
|
||||||
|
run: brew install qt@6 protobuf@21
|
||||||
|
- name: Configure build
|
||||||
|
run: qmake PROTOBUF=/usr/local/opt/protobuf@21 pbfplugin.pro
|
||||||
|
- name: Build project
|
||||||
|
run: make -j3
|
23
.travis.yml
23
.travis.yml
@ -1,23 +0,0 @@
|
|||||||
language: c++
|
|
||||||
dist: focal
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
|
|
||||||
env:
|
|
||||||
- QT_SELECT=qt5
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
|
|
||||||
|
|
||||||
install:
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install qt protobuf; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install qtbase5-dev qtbase5-dev-tools qt5-qmake libprotobuf-dev protobuf-compiler; fi
|
|
||||||
|
|
||||||
script:
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then PATH=/usr/local/opt/qt/bin/:${PATH}; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then qmake PROTOBUF=/usr/local pbfplugin.pro; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then qmake pbfplugin.pro; fi
|
|
||||||
- make
|
|
40
README.md
40
README.md
@ -7,7 +7,7 @@ displaying raster MBTiles maps or raster XYZ online maps to also display
|
|||||||
PBF(MVT) vector tiles without (almost, see usage) any application modifications.
|
PBF(MVT) vector tiles without (almost, see usage) any application modifications.
|
||||||
|
|
||||||
Standard Mapbox GL Styles are used for styling the maps. Most relevant style
|
Standard Mapbox GL Styles are used for styling the maps. Most relevant style
|
||||||
features used by [Maputnik](http://editor.openmaptiles.org) are supported.
|
features used by [Maputnik](https://maputnik.github.io/editor) are supported.
|
||||||
A default fallback style (OSM-Liberty) for OpenMapTiles is part of the plugin.
|
A default fallback style (OSM-Liberty) for OpenMapTiles is part of the plugin.
|
||||||
|
|
||||||
"Plain" PBF files as well as gzip compressed files (as used in MBTiles) are
|
"Plain" PBF files as well as gzip compressed files (as used in MBTiles) are
|
||||||
@ -18,24 +18,39 @@ to fit the styles and available data (OpenMapTiles, Mapbox tiles).
|
|||||||
Due to a major design flaw in the Mapbox vector tiles specification - the zoom
|
Due to a major design flaw in the Mapbox vector tiles specification - the zoom
|
||||||
is not part of the PBF data - the plugin can not be used "as is", but passing
|
is not part of the PBF data - the plugin can not be used "as is", but passing
|
||||||
the zoom level is necessary. This is done by exploiting the optional *format*
|
the zoom level is necessary. This is done by exploiting the optional *format*
|
||||||
parameter of the QImage constructor or the QImage::fromData() or
|
parameter of the QImage constructor or the *QImage::loadFromData()* or
|
||||||
QPixmap::loadFromData() functions. The zoom number is passed as ASCII string
|
*QPixmap::loadFromData()* functions. The zoom number is passed as ASCII string
|
||||||
to the functions:
|
to the functions:
|
||||||
```cpp
|
```cpp
|
||||||
QPixmap pm;
|
QImage img;
|
||||||
pm.loadFromData(tileData, QString::number(zoom).toLatin1());
|
img.loadFromData(data, QByteArray::number(zoom));
|
||||||
```
|
```
|
||||||
The plugin supports vector scaling using QImageReader's setScaledSize() method,
|
|
||||||
|
For a complete code sample see the [pbf2png](https://github.com/tumic0/pbf2png)
|
||||||
|
conversion utility.
|
||||||
|
|
||||||
|
### HiDPI
|
||||||
|
The plugin supports vector scaling using QImageReader's *setScaledSize()* method,
|
||||||
so when used like in the following example:
|
so when used like in the following example:
|
||||||
```cpp
|
```cpp
|
||||||
QImageReader reader(file, QString::number(zoom).toLatin1());
|
QImage img;
|
||||||
|
QImageReader reader(file, QByteArray::number(zoom));
|
||||||
reader.setScaledSize(QSize(1024, 1024));
|
reader.setScaledSize(QSize(1024, 1024));
|
||||||
reader.read(&image);
|
reader.read(&img);
|
||||||
```
|
```
|
||||||
you will get 1024x1024px tiles with a pixel ratio of 2 (= HiDPI tiles).
|
you will get 1024x1024px tiles with a pixel ratio of 2 (= HiDPI tiles).
|
||||||
|
|
||||||
For a sample code see the [pbf2png](https://github.com/tumic0/pbf2png)
|
### Overzoom
|
||||||
conversion utility.
|
Since version 3 of the plugin tile overzoom is supported. If you set *format*
|
||||||
|
to `$zoom;$overzoom`:
|
||||||
|
```cpp
|
||||||
|
QImage img;
|
||||||
|
QByteArray fmt(QByteArray::number(zoom) + ';' + QByteArray::number(overzoom));
|
||||||
|
img.loadFromData(data, fmt);
|
||||||
|
```
|
||||||
|
you will get (512<<overzoom)x(512<<overzoom)px tiles with a pixel ratio of 1.
|
||||||
|
When overzoom is combined with setScaledSize(), the base size is the overzoomed
|
||||||
|
tile size.
|
||||||
|
|
||||||
## Styles
|
## Styles
|
||||||
The map style is loaded from the
|
The map style is loaded from the
|
||||||
@ -43,7 +58,8 @@ The map style is loaded from the
|
|||||||
file on plugin load. If the style uses a sprite, the sprite JSON file must
|
file on plugin load. If the style uses a sprite, the sprite JSON file must
|
||||||
be named `sprite.json` and the sprite image `sprite.png` and both files must be
|
be named `sprite.json` and the sprite image `sprite.png` and both files must be
|
||||||
placed in the same directory as the style itself. *A style compatible with the
|
placed in the same directory as the style itself. *A style compatible with the
|
||||||
tiles data schema (Mapbox, OpenMapTiles, Tilezen) must be used.*
|
tiles data schema (Mapbox, OpenMapTiles, Tilezen, Ordnance Survey, Esri, ...)
|
||||||
|
must be used.*
|
||||||
|
|
||||||
For a list of "ready to use" styles see the
|
For a list of "ready to use" styles see the
|
||||||
[QtPBFImagePlugin-styles](https://github.com/tumic0/QtPBFImagePlugin-styles)
|
[QtPBFImagePlugin-styles](https://github.com/tumic0/QtPBFImagePlugin-styles)
|
||||||
@ -51,7 +67,7 @@ repository.
|
|||||||
|
|
||||||
## Build
|
## Build
|
||||||
### Requirements
|
### Requirements
|
||||||
* Qt5 >= 5.12 or Qt6
|
* Qt5 >= 5.11 or Qt6
|
||||||
* Google Protocol Buffers (protobuf-lite)
|
* Google Protocol Buffers (protobuf-lite)
|
||||||
* Zlib
|
* Zlib
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ TARGET = pbf
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin
|
||||||
QT += gui
|
QT += gui
|
||||||
|
VERSION = 3.0
|
||||||
|
|
||||||
PROTOS = protobuf/vector_tile.proto
|
PROTOS = protobuf/vector_tile.proto
|
||||||
include(protobuf/vector_tile.pri)
|
include(protobuf/vector_tile.pri)
|
||||||
@ -38,21 +39,34 @@ RESOURCES += pbfplugin.qrc
|
|||||||
|
|
||||||
DEFINES += QT_NO_DEPRECATED_WARNINGS
|
DEFINES += QT_NO_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
unix:!macx{
|
unix:!macx:!android {
|
||||||
LIBS += -lprotobuf-lite \
|
LIBS += -lprotobuf-lite \
|
||||||
-lz
|
-lz
|
||||||
|
|
||||||
|
target.path += $$[QT_INSTALL_PLUGINS]/imageformats
|
||||||
|
INSTALLS += target
|
||||||
}
|
}
|
||||||
win32 {
|
win32 {
|
||||||
INCLUDEPATH += $$PROTOBUF/include \
|
INCLUDEPATH += $$PROTOBUF/include \
|
||||||
$$ZLIB/include
|
$$ZLIB/include
|
||||||
LIBS += $$PROTOBUF/lib/libprotobuf-lite.lib \
|
LIBS += $$PROTOBUF/lib/libprotobuf-lite.lib \
|
||||||
$$ZLIB/lib/zlibstatic.lib
|
$$ZLIB/lib/zlibstatic.lib
|
||||||
|
|
||||||
|
QMAKE_TARGET_PRODUCT = QtPBFImagePlugin
|
||||||
|
QMAKE_TARGET_DESCRIPTION = Qt $$QT_VERSION MVT/PBF image plugin
|
||||||
|
QMAKE_TARGET_COPYRIGHT = Copyright (c) 2023 Martin Tuma
|
||||||
}
|
}
|
||||||
macx {
|
macx {
|
||||||
INCLUDEPATH += $$PROTOBUF/include
|
INCLUDEPATH += $$PROTOBUF/include
|
||||||
LIBS += $$PROTOBUF/lib/libprotobuf-lite.a \
|
LIBS += $$PROTOBUF/lib/libprotobuf-lite.a \
|
||||||
-lz
|
-lz
|
||||||
}
|
}
|
||||||
|
android {
|
||||||
|
INCLUDEPATH += $$PROTOBUF/include
|
||||||
|
LIBS += $$PROTOBUF/$$ANDROID_TARGET_ARCH/libprotobuf-lite.a \
|
||||||
|
-lz
|
||||||
|
|
||||||
target.path += $$[QT_INSTALL_PLUGINS]/imageformats
|
top_builddir=$$shadowed($$PWD)
|
||||||
INSTALLS += target
|
DESTDIR = $$top_builddir/plugins/libpbf
|
||||||
|
TARGET = $$qt5LibraryTarget(libpbf, "plugins/imageformats/")
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
QByteArray Gzip::uncompress(QIODevice *device, int limit)
|
QByteArray Gzip::uncompress(QIODevice *device, int limit)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = Z_STREAM_END;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
unsigned char in[CHUNK];
|
unsigned char in[CHUNK];
|
||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
|
@ -79,16 +79,19 @@ bool PBFHandler::read(QImage *image)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
QList<QByteArray> list(format().split(';'));
|
||||||
int zoom = format().toInt(&ok);
|
int zoom = list.size() ? list.first().toInt() : 0;
|
||||||
|
int overzoom = (list.size() > 1) ? list.at(1).toInt() : 0;
|
||||||
|
|
||||||
|
QSize scaledSize(_scaledSize.isValid()
|
||||||
|
? _scaledSize : QSize(TILE_SIZE, TILE_SIZE));
|
||||||
|
QSize size(scaledSize.width()<<overzoom,
|
||||||
|
scaledSize.height()<<overzoom);
|
||||||
|
QPointF scale((qreal)scaledSize.width() / TILE_SIZE,
|
||||||
|
(qreal)scaledSize.height() / TILE_SIZE);
|
||||||
|
|
||||||
QSize size = _scaledSize.isValid()
|
|
||||||
? _scaledSize : QSize(TILE_SIZE, TILE_SIZE);
|
|
||||||
QPointF scale = _scaledSize.isValid()
|
|
||||||
? QPointF((qreal)_scaledSize.width() / TILE_SIZE,
|
|
||||||
(qreal)_scaledSize.height() / TILE_SIZE) : QPointF(1.0, 1.0);
|
|
||||||
*image = QImage(size, QImage::Format_ARGB32_Premultiplied);
|
*image = QImage(size, QImage::Format_ARGB32_Premultiplied);
|
||||||
Tile tile(image, ok ? zoom : -1, scale);
|
Tile tile(image, zoom, scale);
|
||||||
|
|
||||||
_style->render(data, tile);
|
_style->render(data, tile);
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ qreal TextItem::avgCharWidth() const
|
|||||||
ratio = 1.0;
|
ratio = 1.0;
|
||||||
// Greek & Cyrilic
|
// Greek & Cyrilic
|
||||||
else if (cp >= 0x03FF && cp <= 0x04FF) {
|
else if (cp >= 0x03FF && cp <= 0x04FF) {
|
||||||
ratio = (_font.capitalization() == QFont::AllUppercase) ? 0.80 : 0.73;
|
ratio = (_font.capitalization() == QFont::AllUppercase) ? 0.80 : 0.70;
|
||||||
if (_font.bold())
|
if (_font.bold())
|
||||||
ratio *= 1.1;
|
ratio *= 1.1;
|
||||||
if (_font.italic())
|
if (_font.italic())
|
||||||
ratio *= 0.9;
|
ratio *= 0.9;
|
||||||
// The rest (Latin scripts, Arabic, ...)
|
// The rest (Latin scripts, Arabic, ...)
|
||||||
} else {
|
} else {
|
||||||
ratio = (_font.capitalization() == QFont::AllUppercase) ? 0.75 : 0.63;
|
ratio = (_font.capitalization() == QFont::AllUppercase) ? 0.75 : 0.60;
|
||||||
if (_font.bold())
|
if (_font.bold())
|
||||||
ratio *= 1.1;
|
ratio *= 1.1;
|
||||||
if (_font.italic())
|
if (_font.italic())
|
||||||
|
@ -9,23 +9,20 @@
|
|||||||
#define INTERSECTS intersects
|
#define INTERSECTS intersects
|
||||||
#endif // QT 5.15
|
#endif // QT 5.15
|
||||||
|
|
||||||
static bool intersection(const QLineF &line, const QRectF &rect,
|
static void swap(const QLineF &line, QPointF *p1, QPointF *p2)
|
||||||
QPointF *p)
|
|
||||||
{
|
{
|
||||||
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.topRight()), p)
|
|
||||||
== QLineF::BoundedIntersection)
|
|
||||||
return true;
|
|
||||||
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
|
|
||||||
== QLineF::BoundedIntersection)
|
|
||||||
return true;
|
|
||||||
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
|
|
||||||
== QLineF::BoundedIntersection)
|
|
||||||
return true;
|
|
||||||
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
|
|
||||||
== QLineF::BoundedIntersection)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
QPointF lp1(line.p1());
|
||||||
|
QPointF lp2(line.p2());
|
||||||
|
|
||||||
|
if ((lp1.rx() < lp2.rx() && p1->rx() > p2->rx())
|
||||||
|
|| (lp1.ry() < lp2.ry() && p1->ry() > p2->ry())
|
||||||
|
|| (lp1.rx() > lp2.rx() && p1->rx() < p2->rx())
|
||||||
|
|| (lp1.ry() > lp2.ry() && p1->ry() < p2->ry())) {
|
||||||
|
QPointF tmp(*p2);
|
||||||
|
*p2 = *p1;
|
||||||
|
*p1 = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p1,
|
static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p1,
|
||||||
@ -38,20 +35,26 @@ static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p1,
|
|||||||
p = p2;
|
p = p2;
|
||||||
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
|
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
|
||||||
== QLineF::BoundedIntersection) {
|
== QLineF::BoundedIntersection) {
|
||||||
if (p == p2)
|
if (p == p2) {
|
||||||
|
swap(line, p1, p2);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
p = p2;
|
p = p2;
|
||||||
}
|
}
|
||||||
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
|
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
|
||||||
== QLineF::BoundedIntersection) {
|
== QLineF::BoundedIntersection) {
|
||||||
if (p == p2)
|
if (p == p2) {
|
||||||
|
swap(line, p1, p2);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
p = p2;
|
p = p2;
|
||||||
}
|
}
|
||||||
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
|
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
|
||||||
== QLineF::BoundedIntersection) {
|
== QLineF::BoundedIntersection) {
|
||||||
if (p == p2)
|
if (p == p2) {
|
||||||
|
swap(line, p1, p2);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(p != p2);
|
Q_ASSERT(p != p2);
|
||||||
@ -59,22 +62,42 @@ static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p1,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QPainterPath subpath(const QList<QLineF> &lines, int start, int end,
|
static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p)
|
||||||
|
{
|
||||||
|
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.topRight()), p)
|
||||||
|
== QLineF::BoundedIntersection)
|
||||||
|
return true;
|
||||||
|
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
|
||||||
|
== QLineF::BoundedIntersection)
|
||||||
|
return true;
|
||||||
|
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
|
||||||
|
== QLineF::BoundedIntersection)
|
||||||
|
return true;
|
||||||
|
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
|
||||||
|
== QLineF::BoundedIntersection)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QPainterPath subpath(const QPolygonF &path, int start, int end,
|
||||||
qreal cut)
|
qreal cut)
|
||||||
{
|
{
|
||||||
qreal ss = 0, es = 0;
|
qreal ss = 0, es = 0;
|
||||||
int si = start, ei = end;
|
int si = start, ei = end;
|
||||||
|
|
||||||
for (int i = start; i <= end; i++) {
|
for (int i = start; i < end; i++) {
|
||||||
qreal len = lines.at(i).length();
|
QLineF l(path.at(i), path.at(i+1));
|
||||||
|
qreal len = l.length();
|
||||||
if (ss + len < cut / 2) {
|
if (ss + len < cut / 2) {
|
||||||
ss += len;
|
ss += len;
|
||||||
si++;
|
si++;
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (int i = end; i >= start; i--) {
|
for (int i = end; i > start; i--) {
|
||||||
qreal len = lines.at(i).length();
|
QLineF l(path.at(i), path.at(i-1));
|
||||||
|
qreal len = l.length();
|
||||||
if (es + len < cut / 2) {
|
if (es + len < cut / 2) {
|
||||||
es += len;
|
es += len;
|
||||||
ei--;
|
ei--;
|
||||||
@ -82,98 +105,117 @@ static QPainterPath subpath(const QList<QLineF> &lines, int start, int end,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineF sl(lines.at(si).p2(), lines.at(si).p1());
|
QLineF sl(path.at(si+1), path.at(si));
|
||||||
sl.setLength(sl.length() - (cut / 2 - ss));
|
sl.setLength(sl.length() - (cut / 2 - ss));
|
||||||
QLineF el(lines.at(ei));
|
QLineF el(path.at(ei-1), path.at(ei));
|
||||||
el.setLength(el.length() - (cut / 2 - es));
|
el.setLength(el.length() - (cut / 2 - es));
|
||||||
|
|
||||||
QPainterPath p(sl.p2());
|
QPainterPath p(sl.p2());
|
||||||
for (int i = si; i <= ei; i++)
|
for (int i = si + 1; i < ei; i++)
|
||||||
p.lineTo(lines.at(i).p2());
|
p.lineTo(path.at(i));
|
||||||
p.setElementPositionAt(p.elementCount() - 1, el.p2().x(), el.p2().y());
|
p.lineTo(el.p2());
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<QLineF> lineString(const QPainterPath &path,
|
static QList<QPolygonF> polyLines(const QPainterPath &path, const QRectF &rect)
|
||||||
const QRectF &boundingRect)
|
|
||||||
{
|
{
|
||||||
QList<QLineF> lines;
|
QList<QPolygonF> lines;
|
||||||
int start = -1, end = -1;
|
QPolygonF line;
|
||||||
|
bool lastIn = rect.contains(path.elementAt(0));
|
||||||
|
|
||||||
|
for (int i = 1; i < path.elementCount(); i++) {
|
||||||
|
if (rect.contains(path.elementAt(i))) {
|
||||||
|
if (lastIn) {
|
||||||
|
if (line.isEmpty())
|
||||||
|
line.append(path.elementAt(i-1));
|
||||||
|
line.append(path.elementAt(i));
|
||||||
|
} else {
|
||||||
|
QPointF p;
|
||||||
|
QLineF l(path.elementAt(i-1), path.elementAt(i));
|
||||||
|
|
||||||
for (int i = 0; i < path.elementCount(); i++) {
|
if (intersection(l, rect, &p))
|
||||||
if (boundingRect.contains(path.elementAt(i))) {
|
line.append(p);
|
||||||
start = i;
|
line.append(path.elementAt(i));
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = path.elementCount() - 1; i >= 0; i--) {
|
|
||||||
if (boundingRect.contains(path.elementAt(i))) {
|
|
||||||
end = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start < 0) {
|
|
||||||
QPointF p1, p2;
|
|
||||||
|
|
||||||
for (int i = 1; i < path.elementCount(); i++) {
|
|
||||||
QLineF l(path.elementAt(i-1), path.elementAt(i));
|
|
||||||
if (intersection(l, boundingRect, &p1, &p2)) {
|
|
||||||
lines.append(QLineF(p1, p2));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QPointF p;
|
|
||||||
|
|
||||||
if (start > 0) {
|
lastIn = true;
|
||||||
QLineF l(path.elementAt(start-1), path.elementAt(start));
|
} else {
|
||||||
if (intersection(l, boundingRect, &p))
|
QLineF l(path.elementAt(i-1), path.elementAt(i));
|
||||||
lines.append(QLineF(p, path.elementAt(start)));
|
|
||||||
}
|
if (lastIn) {
|
||||||
for (int i = start + 1; i <= end; i++)
|
QPointF p;
|
||||||
lines.append(QLineF(path.elementAt(i-1), path.elementAt(i)));
|
if (line.isEmpty())
|
||||||
if (end < path.elementCount() - 1) {
|
line.append(path.elementAt(i-1));
|
||||||
QLineF l(path.elementAt(end), path.elementAt(end+1));
|
if (intersection(l, rect, &p))
|
||||||
if (intersection(l, boundingRect, &p))
|
line.append(p);
|
||||||
lines.append(QLineF(path.elementAt(end), p));
|
lines.append(line);
|
||||||
|
line.clear();
|
||||||
|
} else {
|
||||||
|
QPointF p1, p2;
|
||||||
|
if (intersection(l, rect, &p1, &p2)) {
|
||||||
|
line.append(p1);
|
||||||
|
line.append(p2);
|
||||||
|
lines.append(line);
|
||||||
|
line.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastIn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!line.isEmpty())
|
||||||
|
lines.append(line);
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static qreal diff(qreal a1, qreal a2)
|
||||||
|
{
|
||||||
|
qreal d = qAbs(a1 - a2);
|
||||||
|
return (d > 180) ? 360 - d : d;
|
||||||
|
}
|
||||||
|
|
||||||
static QPainterPath textPath(const QPainterPath &path, qreal textWidth,
|
static QPainterPath textPath(const QPainterPath &path, qreal textWidth,
|
||||||
qreal maxAngle, qreal charWidth, const QRectF &tileRect)
|
qreal maxAngle, qreal charWidth, const QRectF &tileRect)
|
||||||
{
|
{
|
||||||
QList<QLineF> lines(lineString(path, tileRect));
|
if (path.isEmpty())
|
||||||
if (lines.isEmpty())
|
|
||||||
return QPainterPath();
|
return QPainterPath();
|
||||||
qreal length = 0;
|
|
||||||
qreal angle = lines.first().angle();
|
QList<QPolygonF> lines(polyLines(path, tileRect));
|
||||||
int last = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
qreal sl = lines.at(i).length();
|
const QPolygonF &pl = lines.at(i);
|
||||||
qreal a = lines.at(i).angle();
|
qreal angle = 0, length = 0;
|
||||||
|
int last = 0;
|
||||||
|
|
||||||
if (!tileRect.contains(lines.at(i).p2()) || sl < charWidth
|
for (int j = 1; j < pl.size(); j ++) {
|
||||||
|| qAbs(angle - a) > maxAngle) {
|
QLineF l(pl.at(j-1), pl.at(j));
|
||||||
if (length > textWidth)
|
qreal sl = l.length();
|
||||||
return subpath(lines, last, i - 1, length - textWidth);
|
qreal a = l.angle();
|
||||||
last = i;
|
|
||||||
length = 0;
|
|
||||||
} else
|
|
||||||
length += sl;
|
|
||||||
|
|
||||||
angle = a;
|
if (sl < charWidth) {
|
||||||
|
if (length > textWidth)
|
||||||
|
return subpath(pl, last, j - 1, length - textWidth);
|
||||||
|
last = j;
|
||||||
|
length = 0;
|
||||||
|
} else if (j > 1 && diff(angle, a) > maxAngle) {
|
||||||
|
if (length > textWidth)
|
||||||
|
return subpath(pl, last, j - 1, length - textWidth);
|
||||||
|
last = j - 1;
|
||||||
|
length = sl;
|
||||||
|
} else
|
||||||
|
length += sl;
|
||||||
|
|
||||||
|
angle = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length > textWidth)
|
||||||
|
return subpath(pl, last, pl.size() - 1, length - textWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (length > textWidth)
|
return QPainterPath();
|
||||||
? subpath(lines, last, lines.size() - 1, length - textWidth)
|
|
||||||
: QPainterPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool reverse(const QPainterPath &path)
|
static bool reverse(const QPainterPath &path)
|
||||||
@ -208,9 +250,6 @@ TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
|
|||||||
|
|
||||||
void TextPathItem::paint(QPainter *painter) const
|
void TextPathItem::paint(QPainter *painter) const
|
||||||
{
|
{
|
||||||
//painter->setPen(Qt::red);
|
|
||||||
//painter->drawPath(_shape);
|
|
||||||
|
|
||||||
QFontMetrics fm(font());
|
QFontMetrics fm(font());
|
||||||
int textWidth = fm.boundingRect(text()).width();
|
int textWidth = fm.boundingRect(text()).width();
|
||||||
|
|
||||||
@ -259,4 +298,9 @@ void TextPathItem::paint(QPainter *painter) const
|
|||||||
int width = fm.horizontalAdvance(text().at(i));
|
int width = fm.horizontalAdvance(text().at(i));
|
||||||
percent += ((qreal)width / (qreal)textWidth) * factor;
|
percent += ((qreal)width / (qreal)textWidth) * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//painter->setBrush(Qt::NoBrush);
|
||||||
|
//painter->setPen(Qt::red);
|
||||||
|
//painter->setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
//painter->drawPath(_shape);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,10 @@ public:
|
|||||||
: _zoom(zoom), _size(img->size()), _scale(scale),
|
: _zoom(zoom), _size(img->size()), _scale(scale),
|
||||||
_text(QSize(img->size().width() / scale.x(),
|
_text(QSize(img->size().width() / scale.x(),
|
||||||
img->size().height() / scale.y())), _painter(img)
|
img->size().height() / scale.y())), _painter(img)
|
||||||
{_painter.scale(scale.x(), scale.y());}
|
{
|
||||||
|
img->fill(Qt::transparent);
|
||||||
|
_painter.scale(scale.x(), scale.y());
|
||||||
|
}
|
||||||
|
|
||||||
int zoom() const {return _zoom;}
|
int zoom() const {return _zoom;}
|
||||||
const QSize &size() const {return _size;}
|
const QSize &size() const {return _size;}
|
||||||
|
@ -2265,7 +2265,6 @@
|
|||||||
"source": "openmaptiles",
|
"source": "openmaptiles",
|
||||||
"source-layer": "building",
|
"source-layer": "building",
|
||||||
"minzoom": 13,
|
"minzoom": 13,
|
||||||
"maxzoom": 14,
|
|
||||||
"layout": {
|
"layout": {
|
||||||
"visibility": "visible"
|
"visibility": "visible"
|
||||||
},
|
},
|
||||||
@ -4059,4 +4058,4 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"id": "osm-liberty"
|
"id": "osm-liberty"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user