Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

svg draw_text do not preserve spaces #5

@ikod

Description

@ikod

Hello,

this code

use plotters::prelude::*;

fn main() {

    let root_drawing_area = SVGBackend::new("images/0.1.svg", (1159, 539))
        .into_drawing_area();
    root_drawing_area.fill(&WHITE).unwrap();
    let text_style = TextStyle::from(("monospace", 25).into_font());
    root_drawing_area.draw_text("|___|___|", &text_style, (100,100)).unwrap();
    root_drawing_area.draw_text("|   |   |", &text_style, (100,150)).unwrap();
    root_drawing_area.draw_text("|   |   |", &text_style, (100,200)).unwrap();
}

produce next image:
image

while all vertical bars should be aligned.

Looks like the problem is in the svg text tag: If I change from

<text x="100" y="150" dy="0.76em" text-anchor="start" font-family="monospace" font-size="20.161290322580644" opacity="1" fill="#000000">
|   |   |
</text>

to

<text x="100" y="150" dy="0.76em" text-anchor="start" font-family="monospace" font-size="20.161290322580644" opacity="1" fill="#000000" xml:space="preserve">
|   |   |
</text>

(note xml:space="preserve" inside text tag) then it looks better

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions