Fix text baseline position for some fonts #669
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Text drawn with some fonts (for example Calibri and the free metric-equivalent Carlito) is not aligned to the same baseline as on Windows.
This is because fonts have three sets of roughly equivalent metrics, and different platforms use different ones. Windows uses one set, and Pango primarily uses a combination of the other two. The set Windows uses has the line spacing included in the ascent and descent. The other sets allow the gap to be specified separately, but for many fonts (even most) the one Pango uses has got only a minimal gap with the ascent roughly matching Window's one (hence why this problem is not common). For the first line of text the baseline is positioned according to the ascent.
However, these two fonts have a significant difference between the Windows ascent and the other two. As the text baseline is positioned according to the ascent, the text is positioned equivalently higher in the bounding box:
This works around the problem by calculating the correct baseline and adding the difference between it and the baseline used by Pango to the offset for text drawn with
StringFormat->lineAlignment
set toNear
. As long as the metrics returned byGdipGetCellAscent
and co are correct this should not make drawing wrong.With fix:
Windows 8.1: