Improve vertical text alignment of OxyPlot.SvgExporter · Issue #1531 · oxyplot/oxyplot · GitHub
Skip to content

Improve vertical text alignment of OxyPlot.SvgExporter #1531

Open

Description

@Jonarw

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

Activity

  1. VisualMelon commented on May 6, 2020

    @VisualMelon
    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).

  2. Jonarw commented on May 8, 2020

    @Jonarw
    MemberAuthor

    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?

  3. VisualMelon commented on May 8, 2020

    @VisualMelon
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions