ND2: rework text annotation parsing so that dimensions are not overlooked

Fixes #12205.