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

inaccurate calculation in unit conversion to point #124

Open
Kanahiro opened this issue Aug 9, 2023 · 6 comments
Open

inaccurate calculation in unit conversion to point #124

Kanahiro opened this issue Aug 9, 2023 · 6 comments
Labels
enhancement New feature or request Low priority

Comments

@Kanahiro
Copy link
Member

Kanahiro commented Aug 9, 2023

<ラベルのポイント数について>
v0.0.9プラグインでエクスポートした際、JSONに書き出されるラベルのサイズが設定値と若干変わってしまうようです。
(例) QGIS設定値 ⇒ JSONの値
7.0pt ⇒ 6.75pt
8.0pt ⇒ 8.25pt
10.0pt ⇒ 9.75pt
2.0mm ⇒ 6.0pt (実際は2mmは約5.7pt)
添付画像は、P_districtsレイヤのラベルが7ptに設定されているところ、JSONでは6.75ptになってしまっているところです。
恐れ入りますが、ご確認をいただけますと幸いです。

@Kanahiro Kanahiro added this to the for release milestone Aug 9, 2023
@bordoray
Copy link
Collaborator

bordoray commented Aug 10, 2023

No difference when convert point to point in P_districts
image

@bordoray
Copy link
Collaborator

Point to point conversion looks not have problem

mm to pt has small gap
To be: 2mm = 5.699 pt
image

@bordoray
Copy link
Collaborator

Looks to come directly from "extract label" processing tool.
Size in point for 4mm should be 11.338582677 pt.

I am suspecting something wrong to extract label algorithm based on dpi, crs and scale...

image

@bordoray
Copy link
Collaborator

Dpi looks to vary depending on dpi
here implemented iface.mapCanvas().mapSettings().outputDpi() is 144
Default dpi is set as 96

Label is set as 4mm which is truely 11.338582677 pt
image

@bordoray
Copy link
Collaborator

size may be calculated as below
const double fontSize = static_cast<double>( font.pixelSize() ) * 72 / context.painter()->device()->logicalDpiX();
https://github.com/qgis/QGIS/blob/3a4a9f08bdc7630120ab7a0f55d5f8e68371c50b/src/analysis/processing/qgsalgorithmextractlabels.cpp#L246

@Kanahiro
Copy link
Member Author

Kanahiro commented Aug 14, 2023

We guess why this occurs:

  • fontsize any units might be converted to pixelsize
  • return value of QFont.pixelSize() is int. this is discrete value despite fontsize is countinuous value.
  • countinuous value(fontsize) is rounded into discrete value (pixelsize). this may cause error.

IMO, this is QGIS natural behaivior and not bug. Labels rendered in canvas may be sized in pixel. Then there is no problem inside QGIS.

@Kanahiro Kanahiro removed this from the for release milestone Aug 16, 2023
@Kanahiro Kanahiro added enhancement New feature or request Low priority labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Low priority
Projects
None yet
Development

No branches or pull requests

2 participants