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

Svg Widget doesn't render fonts #1827

Closed
DrGabble opened this issue Jun 16, 2021 · 1 comment · Fixed by #1850
Closed

Svg Widget doesn't render fonts #1827

DrGabble opened this issue Jun 16, 2021 · 1 comment · Fixed by #1850
Labels
bug does not behave the way it is supposed to

Comments

@DrGabble
Copy link
Contributor

I've got an .svg I'm trying to render which has text on it. The image comes up fine but none of the text is rendered.

I turned on console debug logging and it looks like fontdb (via usvg) is failing to find any of the fonts on my system (Ubuntu 20.04). Tried it with a bunch of fonts I know there are files for, no luck.

Digging around in the Druid source, looks like it might be the default usvg constructor not initializing its fontdb properly (load_system_fonts() etc). If I haven't got the wrong end of the stick, would you like me to open a merge request to add that?

How It Looks In Druid (screenshot)

Screenshot from 2021-06-16 22-48-33

How It Looks in Firefox

Screenshot from 2021-06-16 22-49-06

SVG I was using

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.0 (0)
 -->
<!-- Title: graph_0 Pages: 1 -->
<svg width="191pt" height="301pt"
 viewBox="0.00 0.00 191.00 301.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 297)">
<title>graph_0</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-297 187,-297 187,4 -4,4"/>
<text text-anchor="middle" x="91.5" y="-7.8" font-family="Times,serif" font-size="14.00">Case: 1 / 1, Step: 0 / 10</text>
<g id="clust1" class="cluster">
<title>cluster_1</title>
<polygon fill="none" stroke="black" points="16.5,-31 16.5,-285 166.5,-285 166.5,-31 16.5,-31"/>
<text text-anchor="middle" x="91.5" y="-269.8" font-family="Times,serif" font-size="14.00">And</text>
</g>
<!-- node_0 -->
<g id="node1" class="node">
<title>node_0</title>
<polygon fill="none" stroke="black" points="82.5,-156.5 82.5,-177.5 99.5,-177.5 99.5,-156.5 82.5,-156.5"/>
<text text-anchor="start" x="87" y="-163.3" font-family="sahadeva" font-size="14.00">P</text>
<polygon fill="none" stroke="black" points="99.5,-156.5 99.5,-177.5 117.5,-177.5 117.5,-156.5 99.5,-156.5"/>
<text text-anchor="start" x="103.5" y="-163.3" font-family="sahadeva" font-size="14.00">C</text>
<polygon fill="none" stroke="black" points="82.5,-135.5 82.5,-156.5 117.5,-156.5 117.5,-135.5 82.5,-135.5"/>
<text text-anchor="start" x="85.5" y="-142.3" font-family="sahadeva" font-size="14.00">T000</text>
<polygon fill="none" stroke="black" points="82.5,-114.5 82.5,-135.5 99.5,-135.5 99.5,-114.5 82.5,-114.5"/>
<text text-anchor="start" x="86" y="-121.3" font-family="sahadeva" font-size="14.00">G</text>
<polygon fill="none" stroke="black" points="99.5,-114.5 99.5,-135.5 117.5,-135.5 117.5,-114.5 99.5,-114.5"/>
<text text-anchor="start" x="104" y="-121.3" font-family="sahadeva" font-size="14.00">E</text>
</g>
<!-- auto_node_4 -->
<g id="node4" class="node">
<title>auto_node_4</title>
<polygon fill="none" stroke="black" points="107.5,-75 53.5,-75 53.5,-39 107.5,-39 107.5,-75"/>
<text text-anchor="middle" x="80.5" y="-53.3" font-family="sahadeva" font-size="14.00">output</text>
</g>
<!-- node_0&#45;&gt;auto_node_4 -->
<g id="edge3" class="edge">
<title>node_0:e&#45;&gt;auto_node_4</title>
<path fill="none" stroke="black" d="M108.5,-113.5C108.5,-103.25 104.64,-92.96 99.79,-84.08"/>
<polygon fill="black" stroke="black" points="102.69,-82.11 94.5,-75.39 96.71,-85.75 102.69,-82.11"/>
</g>
<!-- auto_node_2 -->
<g id="node2" class="node">
<title>auto_node_2</title>
<polygon fill="none" stroke="black" points="82.5,-254 24.5,-254 24.5,-218 82.5,-218 82.5,-254"/>
<text text-anchor="middle" x="53.5" y="-232.3" font-family="sahadeva" font-size="14.00">input 0</text>
</g>
<!-- auto_node_2&#45;&gt;node_0 -->
<g id="edge1" class="edge">
<title>auto_node_2&#45;&gt;node_0:p</title>
<path fill="none" stroke="black" d="M72.43,-217.52C79.4,-209.61 86.29,-199.6 89.14,-188.71"/>
<polygon fill="black" stroke="black" points="92.65,-188.88 90.5,-178.5 85.71,-187.95 92.65,-188.88"/>
</g>
<!-- auto_node_2&#45;&gt;auto_node_4 -->
<!-- auto_node_3 -->
<g id="node3" class="node">
<title>auto_node_3</title>
<polygon fill="none" stroke="black" points="158.5,-254 100.5,-254 100.5,-218 158.5,-218 158.5,-254"/>
<text text-anchor="middle" x="129.5" y="-232.3" font-family="sahadeva" font-size="14.00">input 1</text>
</g>
<!-- auto_node_3&#45;&gt;node_0 -->
<g id="edge2" class="edge">
<title>auto_node_3&#45;&gt;node_0:c</title>
<path fill="none" stroke="black" d="M119.49,-217.8C115.39,-209.54 111.19,-199.16 109.4,-188.61"/>
<polygon fill="black" stroke="black" points="112.87,-188.15 108.5,-178.5 105.9,-188.77 112.87,-188.15"/>
</g>
</g>
</svg>

Log Output

RUST_LOG=debug cargo run
   Compiling logic v0.1.0 (/home/myuser/myproject)
    Finished dev [unoptimized + debuginfo] target(s) in 7.65s
     Running `target/debug/gui`
[2021-06-16T20:11:10Z WARN  usvg::svgtree::parse] Failed to parse stroke value: 'transparent'.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'Times,serif' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'Times,serif' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  usvg::convert::text::convert] No match for 'sahadeva' font-family.
[2021-06-16T20:11:10Z WARN  druid::menu] MenuDesc::platform_default is not implemented for this platform.
[2021-06-16T20:11:10Z DEBUG druid::localization] available locales [], current en-GB
[2021-06-16T20:11:10Z DEBUG druid::localization] resolved: [en-US]
[2021-06-16T20:11:10Z INFO  druid_shell::platform::gtk::application] gtk: Activated application

Code

(Cribbed from the svg example)

use druid::{
    widget::{FillStrat, Flex, Svg, SvgData, WidgetExt},
    AppLauncher, LocalizedString, Widget, WindowDesc,
};

pub fn main() {
    env_logger::init();
    let main_window = WindowDesc::new(|| ui_builder())
        .title(LocalizedString::new("svg-demo-window-title").with_placeholder("Rawr!"));
    let data = 0_u32;
    AppLauncher::with_window(main_window)
        .launch(data)
        .expect("launch failed");
}

fn ui_builder() -> impl Widget<u32> {
    let tiger_svg = include_str!("../../run/chip_000.svg")
        .parse::<SvgData>()
        .unwrap();

    let mut col = Flex::column();
    col.add_flex_child(Svg::new(tiger_svg.clone()).fill_mode(FillStrat::Fill), 1.0);
    col.debug_paint_layout()
}

Using this toml:

[package]
authors = ["Me [email protected]"]
edition = "2018"
name = "myproject"
version = "0.1.0"

[dependencies]
druid = {version = "*", features = ["svg"]}
env_logger = "*"
@cmyr
Copy link
Member

cmyr commented Jun 29, 2021

Sorry to let this sit. I haven't really played around much with the svg support myself, and I don't have any particular insight, but if you are able to come up with a concise patch that gets this working for you, I'd be happy to merge!

@cmyr cmyr added the bug does not behave the way it is supposed to label Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug does not behave the way it is supposed to
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants