Ticket #14489 (closed defect: fixed)

Opened 10 months ago

Last modified 8 months ago

Incorrect SVG text coordinates in wxSVGFileDC

Reported by: neilc Owned by:
Priority: normal Milestone: 2.9.5
Component: GUI-all Version: 2.9.3
Keywords: wxDC SVG text descent Cc:
Blocked By: Patch: yes
Blocking:

Description

When using DrawRotatedText() drawing to wxSVGFileDC, the SVG coordinates generated in the SVG XML do not properly take into account the text descent (in wxSVGFileDCImpl::DoDrawRotatedText() ). Furthermore, the calls to CalcBoundingBox() use the wrong trigonometry transforms for the bottom-right point and also for the rectangle when the background mode in solid. Patch to fix the issue attached including a test in the SVG sample which draws boxes around where the text should be.

A bit more detail:

When using wxDC::DrawRotatedText(), the position coordinates refer to the top-left of the text. In SVG, the position coordinates refer to the left (thinking of unrotated text) of the text baseline. (info here: http://commons.oreilly.com/wiki/index.php/SVG_Essentials/Text)`wxSVGFileDCImpl::DoDrawRotatedText()` was previously setting the SVG position coordinates to the bottom left of the text rather than the baseline. i.e. it wasn't taking the text descent into account.

The incorrect bottom-right point stands out if you follow through the code assuming no rotation (angle of 0).

For when the background mode is solid, the text descent is used in the y-coordinate calculation but this coordinate is incorrect.

It would be useful if these modifications were double-checked.

Attachments

SVG Test Window 7 orig.svg download (1.7 KB) - added by neilc 10 months ago.
SVG sample of text with boxes before fix.
SVG Test Window 7 patched.svg download (1.7 KB) - added by neilc 10 months ago.
SVG sample of text with boxes after fix.
fix_wxSVGFileDC_text_position.patch download (4.7 KB) - added by neilc 10 months ago.

Change History

Changed 10 months ago by neilc

SVG sample of text with boxes before fix.

Changed 10 months ago by neilc

SVG sample of text with boxes after fix.

Changed 10 months ago by neilc

I should add that even the file "SVG Test Window 7 patched.svg" doesn't look the same as on screen with extra space appearing above and at the end of the strings. I'm afraid I don't know enough about SVG to know why but could be something to do with the wxSVGFileDCImpl::DoGetTextExtent() method.

Changed 10 months ago by biol75

I was never sure quite what the "correct" behaviour for doing rotated text was, as the MSW and GTK ports differed in their rotation point when I did the code

chris

Changed 10 months ago by neilc

My fixes have been based on GTK (on ubuntu 11.10). I'll try to compile under windows (Win7) to see what that appears like.

Changed 10 months ago by neilc

Changed 10 months ago by neilc

I've just tested on Win7 and the changes also work there. One thing to note though is that I was using wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT) as part of my test but rotation of this text on the screen-rendered wxDC does not work under Windows - I've updated the patch to simply use the default font from the top of the tests.

Changed 8 months ago by neilc

Will this make it into 2.9.5?

Changed 8 months ago by vadz

  • milestone set to 2.9.5

Yes, I'll apply it before the release, thanks for the reminder.

Changed 8 months ago by VZ

  • status changed from new to closed
  • resolution set to fixed

(In [72494]) Fix text origin and bounding box computations in wxSVGFileDC.

Text origin was calculated incorrectly for the rotated text and the bounding
box was wrong even in non-rotated case.

Fix this by using correct definition of the text anchor according to the SVG
specification and add a test to the svg sample demonstrating this.

Closes #14489.

Note: See TracTickets for help on using tickets.