Attached patch fixes alignment rendering for legends and matches FireFox. Attached html file demonstrates the issue in all cases with both LTR and RTL. Unfortunately we also exhibit some fieldset rendering problems it seems, but they're unrelated as far as I can tell.