#14489 closed defect (fixed)

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: Blocking:
Patch: yes

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 (3)

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

Download all attachments as: .zip

Change History (10)

Changed 21 months ago by neilc

SVG sample of text with boxes before fix.

Changed 21 months ago by neilc

SVG sample of text with boxes after fix.

comment:1 Changed 21 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.

comment:2 Changed 21 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

comment:3 Changed 21 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 21 months ago by neilc

comment:4 Changed 21 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.

comment:5 Changed 19 months ago by neilc

Will this make it into 2.9.5?

comment:6 Changed 19 months ago by vadz

  • Milestone set to 2.9.5

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

comment:7 Changed 19 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(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.