Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve vertical text alignment of OxyPlot.SvgExporter #1531

Open
Jonarw opened this issue May 1, 2020 · 3 comments · May be fixed by #1556
Open

Improve vertical text alignment of OxyPlot.SvgExporter #1531

Jonarw opened this issue May 1, 2020 · 3 comments · May be fixed by #1556
Labels

Comments

@Jonarw
Copy link
Member

Jonarw commented May 1, 2020

See discussion in #1518.
Output of SkiaSharp SVG export could give some inspiration.

@VisualMelon
Copy link
Contributor

It looks like the Skia svg exporter doesn't touch the dominant-baseline alignment, which is the svg parameter that has little browser support. It 'defaults' to baseline, which is a problem, because the Svg exporter has no idea where this is (MeasureText only tells it the height). This means the best we can do is to 'guess' where the baseline is (e.g. ~1/4 of the way up) unless we extend some interfaces.

An implementation of this 'just sort of guess where the baseline might be' approach is implemented in 6790236 and produces results like these when using ImageSharp for text measurement.

image

image

That commit also does a few other things:

  • Adds an ImageSharp based Svg exporter
  • Changes everything to use the SVG vertical text workaround by default, since support for dominant-baseline is extremely limited.
  • Improves the multi-line text alignment for SVGs
  • Adds a multi-line aligned text example from Add multi-line text support to SkiaRenderContext #1538
  • Changes multi-line support in various places to split on the regex "\r?\n" rather than "\r\n"

I'll wait until the nightmare inducing ImageSharp changes have been pulled/rejected/whatever before I add a PR for any of this, and will probably break it up into separate PRs (assuming the descent kludge is acceptable at least for the time being).

While I'm typing, I noticed that the PortableDocumentFont stuff doesn't add gaps between lines (which explains some of the deficiencies in the SvgRenderContext I lazily didn't fix last time round).

@Jonarw
Copy link
Member Author

Jonarw commented May 8, 2020

It 'defaults' to baseline, which is a problem, because the Svg exporter has no idea where this is (MeasureText only tells it the height). This means the best we can do is to 'guess' where the baseline is (e.g. ~1/4 of the way up) unless we extend some interfaces.

Could we improve this by overriding DrawText in an e.g. ImageSharp-based SvgRenderContext implementation? There we have access to more sophisticated text measurements and should be able to properly align the text using the baseline only, right?

@VisualMelon
Copy link
Contributor

@Jonarw yeah, good idea. I keep thinking we'd have to modify IRenderContext to do this properly, but there's nothing stopping us doing Svg specific work as you suggest.

VisualMelon added a commit to VisualMelon/oxyplot that referenced this issue May 10, 2020
@VisualMelon VisualMelon linked a pull request May 10, 2020 that will close this issue
4 tasks
VisualMelon added a commit to VisualMelon/oxyplot that referenced this issue May 11, 2020
VisualMelon added a commit to VisualMelon/oxyplot that referenced this issue May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants