RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.74k stars 220 forks source link

Some fonts are ignored during the rendering process #702

Closed rgreinho closed 8 months ago

rgreinho commented 8 months ago

I am reporting the issue here after I found a problem when using svg2pdf. Since they are using ReSVG for the rendering, they suggested to communicate the issue upstream as well.

So my issue is that when I am trying to convert an SVG file to a PNG file (or an PDF file when using svg2pdf), some fonts are not being taken into account, leading to an incorrect rendering. The problematic fonts are the Dharma Gothic E fonts in the example I chose.

Using svg2pdf, I can see that they are correctly detected by fontdb:

β•­ svg2pdf on ξ‚  main [?] via πŸ¦€ v1.75.0
╰❯ git ls -1
49891ef 2024-01-24 (HEAD -> main, upstream/main, upstream/HEAD) Version bump + improvements to svg2pdf (#52) [GitHub]

β•­ svg2pdf on ξ‚  main [?] via πŸ¦€ v1.75.0
╰❯ cargo run -q -- fonts --all|grep -i dharma
Dharma Gothic E
β”œ DharmaGothicE-Bold
β”œ DharmaGothicE-BoldItalic
β”œ DharmaGothicE-ExBold
β”œ DharmaGothicE-ExBoldItalic
β”œ DharmaGothicE-ExLight
β”œ DharmaGothicE-ExLightItalic
β”œ DharmaGothicE-Heavy
β”œ DharmaGothicE-HeavyItalic
β”œ DharmaGothicE-Light
β”œ DharmaGothicE-LightItalic
β”œ DharmaGothicE-Regular
β”œ DharmaGothicE-RegularItalic
β”œ DharmaGothicE-Thin
β”” DharmaGothicE-ThinItalic

But for some reason, the rendering is broken.

Here is a screenshot of the original SVG file:

image

And here the rendering using ReSVG:

image

Bellow is a snippet of the code I used to reproduce the issue:

use resvg::{
    tiny_skia,
    usvg::{self, TreeParsing},
};
use std::error::Error;
use usvg::{fontdb, TreePostProc};

fn main() -> Result<(), Box<dyn Error>> {
    let input_file = include_str!("united_states-fl-tampa.svg");
    let output_file = "resvg.png";

    let mut fontdb = fontdb::Database::new();
    fontdb.load_system_fonts();

    let mut tree = usvg::Tree::from_str(input_file, &usvg::Options::default())?;
    let steps = usvg::PostProcessingSteps {
        convert_text_into_paths: true,
    };
    tree.postprocess(steps, &fontdb);

    let pixmap_size = tree.size.to_int_size();
    let mut pixmap = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height()).unwrap();
    resvg::render(&tree, tiny_skia::Transform::default(), &mut pixmap.as_mut());
    pixmap.save_png(output_file).unwrap();

    Ok(())
}

However, when using Inkscape or CairoSVG the rendering works correctly.

Rendering with CairoSVG:

image

Rendering with Inkscape:

image

And bellow is code of the SVG I am trying to convert:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   id="svg1034"
   viewBox="0 0 883.3 1056"
   version="1.1"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <defs
     id="defs4">
    <style
       id="style2">.cls-1,.cls-2{letter-spacing:-.01em;}.cls-1,.cls-3,.cls-4,.cls-5,.cls-6,.cls-7,.cls-8,.cls-9,.cls-10,.cls-11,.cls-12,.cls-13,.cls-14{font-weight:200;}.cls-1,.cls-3,.cls-4,.cls-5,.cls-6,.cls-8,.cls-9,.cls-10,.cls-11,.cls-13,.cls-14{font-family:Montserrat-ExtraLight, Montserrat;}.cls-15{letter-spacing:-.01em;}.cls-15,.cls-16,.cls-17,.cls-18,.cls-19,.cls-20,.cls-21,.cls-22,.cls-23,.cls-24,.cls-25,.cls-26,.cls-27,.cls-28,.cls-29{font-family:Montserrat-Medium, Montserrat;font-weight:500;}.cls-30{letter-spacing:.19em;}.cls-16,.cls-31,.cls-9{letter-spacing:0em;}.cls-32{letter-spacing:.33em;}.cls-33,.cls-20,.cls-34{fill:#fff;}.cls-35{letter-spacing:-.02em;}.cls-36{letter-spacing:.18em;}.cls-18{letter-spacing:-.01em;}.cls-37{fill:#e1251b;}.cls-37,.cls-38{font-family:DharmaGothicE-Regular, 'Dharma Gothic E';font-size:60px;letter-spacing:.04em;}.cls-19,.cls-39{letter-spacing:-.01em;}.cls-40{letter-spacing:.18em;}.cls-41{letter-spacing:.34em;}.cls-42{letter-spacing:.19em;}.cls-20{font-size:16px;}.cls-20,.cls-34{isolation:isolate;}.cls-43{fill:#8b8a8d;}.cls-44,.cls-45,.cls-23,.cls-46,.cls-7,.cls-47,.cls-12{fill:#00263e;}.cls-44,.cls-23{font-size:23px;}.cls-48{letter-spacing:0em;}.cls-21{letter-spacing:.01em;}.cls-49{letter-spacing:.34em;}.cls-22{letter-spacing:0em;}.cls-3,.cls-50{letter-spacing:-.03em;}.cls-51{fill:#119fda;}.cls-52{letter-spacing:-.03em;}.cls-45{font-size:100px;}.cls-45,.cls-34,.cls-46,.cls-53,.cls-54{font-weight:700;}.cls-45,.cls-46,.cls-53,.cls-54{font-family:DharmaGothicE-Bold, 'Dharma Gothic E';}.cls-55{stroke:#8b8a8d;}.cls-55,.cls-56{fill:none;stroke-miterlimit:10;}.cls-57,.cls-8{letter-spacing:0em;}.cls-5{letter-spacing:-.03em;}.cls-34{font-family:Montserrat-Bold, Montserrat;font-size:24px;}.cls-24{letter-spacing:0em;}.cls-58{letter-spacing:-.03em;}.cls-59{letter-spacing:.33em;}.cls-6,.cls-60{letter-spacing:0em;}.cls-61{letter-spacing:.19em;}.cls-62{letter-spacing:0em;}.cls-46{font-size:61.8px;}.cls-25{letter-spacing:-.02em;}.cls-63{letter-spacing:-.02em;}.cls-64,.cls-53{fill:#009edb;}.cls-53{font-size:33px;letter-spacing:.04em;}.cls-65{fill:#e02726;}.cls-26,.cls-66{letter-spacing:0em;}.cls-7{font-size:29px;}.cls-7,.cls-12{font-family:DharmaGothicE-Thin, 'Dharma Gothic E';}.cls-67{letter-spacing:.19em;}.cls-68{fill:#df271c;}.cls-27{letter-spacing:-.05em;}.cls-69,.cls-13{letter-spacing:-.04em;}.cls-28{letter-spacing:-.02em;}.cls-38,.cls-54{fill:#00a0df;}.cls-10{letter-spacing:0em;}.cls-70{letter-spacing:.2em;}.cls-71{letter-spacing:-.02em;}.cls-72{letter-spacing:.17em;}.cls-11{letter-spacing:-.03em;}.cls-73{fill:#e6e7e8;}.cls-74{letter-spacing:.19em;}.cls-47{font-family:Montserrat-SemiBold, Montserrat;font-size:28px;font-weight:600;}.cls-29,.cls-75{letter-spacing:-.01em;}.cls-54{font-size:85px;}.cls-12{font-size:36.58px;}.cls-76{letter-spacing:.19em;}.cls-77{fill:#8a898c;}.cls-78{fill:#484846;}.cls-56{stroke:#e6e7e8;}.cls-79{letter-spacing:.13em;}.cls-80{letter-spacing:-.02em;}.cls-14{letter-spacing:0em;}</style>
  </defs>
  <rect
  x="0.54"
  y="51.73"
  width="815.16998"
  height="191.02"
  id="rect364"
  style="fill:#ffffff;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none"/>
  <text
     class="cls-45"
     id="text8"
     x="678.03998"
     y="183.97"
     style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:74.6667px;font-family:DharmaGothicE-Bold, 'Dharma Gothic E';-inkscape-font-specification:'DharmaGothicE-Bold, Dharma Gothic E, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#00263e"><tspan
       x="678.03998"
       y="183.97"
       id="tspan6"
       style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:74.6667px;font-family:DharmaGothicE-Bold, 'Dharma Gothic E';-inkscape-font-specification:'DharmaGothicE-Bold, Dharma Gothic E, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">2023</tspan></text>
  <path
     id="header_bar"
     class="cls-73"
     d="M0,242.75H815.71v813.25H0V242.75Z" />
  <path
     id="header_bar-2"
     class="cls-68"
     d="M.54,51.73H816.25V0H.54V51.73Z" />
  <text
     class="cls-34"
     transform="translate(245.79 36.16)"
     id="text22"><tspan
       class="cls-49"
       x="0"
       y="0"
       id="tspan12">CITY S</tspan><tspan
       class="cls-32"
       x="127.08"
       y="0"
       id="tspan14">C</tspan><tspan
       class="cls-41"
       x="151.56"
       y="0"
       id="tspan16">ORE</tspan><tspan
       class="cls-59"
       x="228.91"
       y="0"
       id="tspan18">C</tspan><tspan
       class="cls-49"
       x="253.49"
       y="0"
       id="tspan20">ARD</tspan></text>
  <line
     class="cls-55"
     x1="275.14999"
     y1="220.09"
     x2="275.14999"
     y2="73.410004"
     id="line24" />
  <rect
     class="cls-33"
     x="44.22"
     y="314.58"
     width="729.24"
     height="359.07"
     id="rect26" />
  <rect
     class="cls-64"
     x="43.77"
     y="281.02"
     width="729.24"
     height="33.14"
     id="rect28" />
  <text
     class="cls-20"
     transform="translate(58.45 303.34)"
     id="text50"><tspan
       class="cls-70"
       x="0"
       y="0"
       id="tspan30">BI</tspan><tspan
       class="cls-76"
       x="23.47"
       y="0"
       id="tspan32">C</tspan><tspan
       class="cls-72"
       x="38.05"
       y="0"
       id="tspan34">Y</tspan><tspan
       class="cls-70"
       x="51.12"
       y="0"
       id="tspan36">CLE NE</tspan><tspan
       class="cls-67"
       x="130.13"
       y="0"
       id="tspan38">T</tspan><tspan
       class="cls-36"
       x="142.59"
       y="0"
       id="tspan40">W</tspan><tspan
       class="cls-70"
       x="163.46"
       y="0"
       id="tspan42">ORK ANA</tspan><tspan
       class="cls-79"
       x="263.15"
       y="0"
       id="tspan44">L</tspan><tspan
       class="cls-40"
       x="274.69"
       y="0"
       id="tspan46">Y</tspan><tspan
       class="cls-70"
       x="288"
       y="0"
       id="tspan48">SIS</tspan></text>
  <g
     id="g214"
     transform="translate(16)">
    <text
       class="cls-44"
       transform="translate(104.68,370.63)"
       id="text198"><tspan
         class="cls-29"
         x="0"
         y="0"
         id="tspan52">P</tspan><tspan
         class="cls-17"
         x="16.33"
         y="0"
         id="tspan54">eople</tspan><tspan
         class="cls-4"
         x="81.190002"
         y="0"
         xml:space="preserve"
         id="tspan56"> - </tspan><tspan
         class="cls-11"
         x="103.25"
         y="0"
         id="tspan58">A</tspan><tspan
         class="cls-3"
         x="118.63"
         y="0"
         id="tspan60">cc</tspan><tspan
         class="cls-4"
         x="143.06"
         y="0"
         id="tspan62">ess</tspan><tspan
         class="cls-8"
         x="183.61"
         y="0"
         id="tspan64">t</tspan><tspan
         class="cls-4"
         x="191.96001"
         y="0"
         id="tspan66">o where other people li</tspan><tspan
         class="cls-1"
         x="451.89999"
         y="0"
         id="tspan68">v</tspan><tspan
         class="cls-9"
         x="462.38"
         y="0"
         id="tspan70">e</tspan><tspan
         class="cls-17"
         x="0"
         y="51.889999"
         id="tspan72">Oppo</tspan><tspan
         class="cls-21"
         x="65.300003"
         y="51.889999"
         id="tspan74">r</tspan><tspan
         class="cls-17"
         x="75.07"
         y="51.889999"
         id="tspan76">tuni</tspan><tspan
         class="cls-24"
         x="122.24"
         y="51.889999"
         id="tspan78">t</tspan><tspan
         class="cls-17"
         x="131.53999"
         y="51.889999"
         id="tspan80">y</tspan><tspan
         class="cls-14"
         x="144.39"
         y="51.889999"
         xml:space="preserve"
         id="tspan82"> - </tspan><tspan
         class="cls-5"
         x="166.45"
         y="51.889999"
         id="tspan84">A</tspan><tspan
         class="cls-3"
         x="181.83"
         y="51.889999"
         id="tspan86">cc</tspan><tspan
         class="cls-4"
         x="206.25999"
         y="51.889999"
         id="tspan88">ess</tspan><tspan
         class="cls-6"
         x="246.81"
         y="51.889999"
         id="tspan90">t</tspan><tspan
         class="cls-14"
         x="255.16"
         y="51.889999"
         id="tspan92">o jobs and edu</tspan><tspan
         class="cls-13"
         x="422.37"
         y="51.889999"
         id="tspan94">c</tspan><tspan
         class="cls-4"
         x="434.39001"
         y="51.889999"
         id="tspan96">ation</tspan><tspan
         class="cls-28"
         x="0"
         y="103.79"
         id="tspan98">C</tspan><tspan
         class="cls-17"
         x="16.120001"
         y="103.79"
         id="tspan100">o</tspan><tspan
         class="cls-29"
         x="30.73"
         y="103.79"
         id="tspan102">r</tspan><tspan
         class="cls-17"
         x="39.880001"
         y="103.79"
         id="tspan104">e Se</tspan><tspan
         class="cls-21"
         x="88.5"
         y="103.79"
         id="tspan106">r</tspan><tspan
         class="cls-17"
         x="98.279999"
         y="103.79"
         id="tspan108">vi</tspan><tspan
         class="cls-22"
         x="117.55"
         y="103.79"
         id="tspan110">c</tspan><tspan
         class="cls-17"
         x="130.5"
         y="103.79"
         id="tspan112">es</tspan><tspan
         class="cls-4"
         x="156.10001"
         y="103.79"
         xml:space="preserve"
         id="tspan114"> - </tspan><tspan
         class="cls-5"
         x="178.16"
         y="103.79"
         id="tspan116">A</tspan><tspan
         class="cls-3"
         x="193.53999"
         y="103.79"
         id="tspan118">cc</tspan><tspan
         class="cls-4"
         x="217.97"
         y="103.79"
         id="tspan120">ess</tspan><tspan
         class="cls-8"
         x="258.51999"
         y="103.79"
         id="tspan122">t</tspan><tspan
         class="cls-4"
         x="266.87"
         y="103.79"
         id="tspan124">o basic needs</tspan><tspan
         class="cls-17"
         x="0"
         y="155.67999"
         id="tspan126">Rec</tspan><tspan
         class="cls-29"
         x="43.93"
         y="155.67999"
         id="tspan128">r</tspan><tspan
         class="cls-25"
         x="53.080002"
         y="155.67999"
         id="tspan130">e</tspan><tspan
         class="cls-17"
         x="66.809998"
         y="155.67999"
         id="tspan132">ation</tspan><tspan
         class="cls-14"
         x="126.77"
         y="155.67999"
         xml:space="preserve"
         id="tspan134"> - </tspan><tspan
         class="cls-5"
         x="148.83"
         y="155.67999"
         id="tspan136">A</tspan><tspan
         class="cls-3"
         x="164.22"
         y="155.67999"
         id="tspan138">cc</tspan><tspan
         class="cls-4"
         x="188.64"
         y="155.67999"
         id="tspan140">ess</tspan><tspan
         class="cls-6"
         x="229.19"
         y="155.67999"
         id="tspan142">t</tspan><tspan
         class="cls-14"
         x="237.53999"
         y="155.67999"
         id="tspan144">o par</tspan><tspan
         class="cls-10"
         x="294.98999"
         y="155.67999"
         id="tspan146">k</tspan><tspan
         class="cls-4"
         x="307.62"
         y="155.67999"
         id="tspan148">s and t</tspan><tspan
         class="cls-3"
         x="383.5"
         y="155.67999"
         id="tspan150">r</tspan><tspan
         class="cls-9"
         x="390.89999"
         y="155.67999"
         id="tspan152">ails</tspan><tspan
         class="cls-17"
         x="0"
         y="207.57001"
         id="tspan154">Retail</tspan><tspan
         class="cls-4"
         x="66.910004"
         y="207.57001"
         xml:space="preserve"
         id="tspan156"> - </tspan><tspan
         class="cls-11"
         x="88.959999"
         y="207.57001"
         id="tspan158">A</tspan><tspan
         class="cls-3"
         x="104.35"
         y="207.57001"
         id="tspan160">cc</tspan><tspan
         class="cls-4"
         x="128.77"
         y="207.57001"
         id="tspan162">ess</tspan><tspan
         class="cls-6"
         x="169.32001"
         y="207.57001"
         id="tspan164">t</tspan><tspan
         class="cls-14"
         x="177.67"
         y="207.57001"
         id="tspan166">o shopping</tspan><tspan
         class="cls-3"
         x="310.67999"
         y="207.57001"
         id="tspan168">c</tspan><tspan
         class="cls-4"
         x="322.89001"
         y="207.57001"
         id="tspan170">en</tspan><tspan
         class="cls-6"
         x="351.34"
         y="207.57001"
         id="tspan172">t</tspan><tspan
         class="cls-4"
         x="359.69"
         y="207.57001"
         id="tspan174">ers</tspan><tspan
         class="cls-18"
         x="0"
         y="259.47"
         id="tspan176">T</tspan><tspan
         class="cls-27"
         x="13.2"
         y="259.47"
         id="tspan178">r</tspan><tspan
         class="cls-17"
         x="21.57"
         y="259.47"
         id="tspan180">ansit</tspan><tspan
         class="cls-4"
         x="78.449997"
         y="259.47"
         xml:space="preserve"
         id="tspan182"> - </tspan><tspan
         class="cls-5"
         x="100.51"
         y="259.47"
         id="tspan184">A</tspan><tspan
         class="cls-3"
         x="115.9"
         y="259.47"
         id="tspan186">cc</tspan><tspan
         class="cls-4"
         x="140.32001"
         y="259.47"
         id="tspan188">ess</tspan><tspan
         class="cls-8"
         x="180.87"
         y="259.47"
         id="tspan190">t</tspan><tspan
         class="cls-4"
         x="189.22"
         y="259.47"
         id="tspan192">o major t</tspan><tspan
         class="cls-3"
         x="290.44"
         y="259.47"
         id="tspan194">r</tspan><tspan
         class="cls-9"
         x="297.85001"
         y="259.47"
         id="tspan196">ansit hubs</tspan></text>
    <text
       class="cls-53"
       transform="translate(43.9,373.63)"
       text-anchor="start"
       id="text212"><tspan
         x="0"
         y="0"
         id="tspan200">15</tspan><tspan
         x="0"
         y="51.889999"
         id="tspan202">15</tspan><tspan
         x="0"
         y="103.79"
         id="tspan204">10</tspan><tspan
         x="0"
         y="155.67999"
         id="tspan206">24</tspan><tspan
         x="0"
         y="207.57001"
         id="tspan208">18</tspan><tspan
         x="0"
         y="259.47"
         id="tspan210">4</tspan></text>
  </g>
  <rect
     class="cls-33"
     x="44.45"
     y="746.8"
     width="729.24"
     height="270.11"
     id="rect216" />
  <rect
     class="cls-43"
     x="44"
     y="712.24"
     width="729.24"
     height="33.14"
     id="rect218" />
  <text
     class="cls-20"
     transform="translate(58.67 734.56)"
     id="text236"><tspan
       class="cls-70"
       x="0"
       y="0"
       id="tspan220">INFRA</tspan><tspan
       class="cls-30"
       x="67.46"
       y="0"
       id="tspan222">S</tspan><tspan
       class="cls-70"
       x="80.43"
       y="0"
       id="tspan224">TRU</tspan><tspan
       class="cls-42"
       x="123.71"
       y="0"
       id="tspan226">C</tspan><tspan
       class="cls-74"
       x="138.35"
       y="0"
       id="tspan228">T</tspan><tspan
       class="cls-70"
       x="150.74"
       y="0"
       id="tspan230">URE MILE</tspan><tspan
       class="cls-61"
       x="256.11"
       y="0"
       id="tspan232">A</tspan><tspan
       class="cls-70"
       x="270.86"
       y="0"
       id="tspan234">GE</tspan></text>
  <text
     class="cls-44"
     id="text268"
     x="218.83"
     y="799.84998"><tspan
       class="cls-17"
       id="tspan250"><tspan
         x="218.83"
         y="799.84998"
         id="tspan238">Miles of high-stress roads</tspan></tspan><tspan
       class="cls-4"
       id="tspan266"><tspan
         x="218.83"
         y="829.84998"
         id="tspan252">Roads lacking adequa</tspan><tspan
         class="cls-57"
         x="467.04001"
         y="829.84998"
         id="tspan254">t</tspan><tspan
         x="475.38998"
         y="829.84998"
         id="tspan256">e bi</tspan><tspan
         class="cls-35"
         x="517.02002"
         y="829.84998"
         id="tspan258">k</tspan><tspan
         x="529.21002"
         y="829.84998"
         id="tspan260">e inf</tspan><tspan
         class="cls-50"
         x="577.34998"
         y="829.84998"
         id="tspan262">r</tspan><tspan
         x="584.75"
         y="829.84998"
         id="tspan264">astructure</tspan></tspan></text>
  <text
     class="cls-37"
     id="text272"
     x="59.0"
     y="829.07001"
     text-anchor="start">2695</text>
  <g
     id="g340"
     transform="translate(16)">
    <text
       class="cls-44"
       transform="translate(202.83,919.57)"
       id="text334"><tspan
         class="cls-17"
         x="0"
         y="0"
         id="tspan274">Miles of l</tspan><tspan
         class="cls-15"
         x="101.91"
         y="0"
         id="tspan276">o</tspan><tspan
         class="cls-18"
         x="116.17"
         y="0"
         id="tspan278">w</tspan><tspan
         class="cls-17"
         x="136.55"
         y="0"
         id="tspan280">-st</tspan><tspan
         class="cls-19"
         x="166.39999"
         y="0"
         id="tspan282">r</tspan><tspan
         class="cls-17"
         x="175.56"
         y="0"
         id="tspan284">ess</tspan><tspan
         class="cls-29"
         x="218.87"
         y="0"
         id="tspan286">r</tspan><tspan
         class="cls-26"
         x="228.02"
         y="0"
         id="tspan288">o</tspan><tspan
         class="cls-16"
         x="242.50999"
         y="0"
         id="tspan290">ads and</tspan><tspan
         class="cls-26"
         x="340.95001"
         y="0"
         id="tspan292">p</tspan><tspan
         class="cls-17"
         x="356.51999"
         y="0"
         id="tspan294">aths</tspan><tspan
         class="cls-4"
         x="406.98001"
         y="0"
         id="tspan296" /><tspan
         class="cls-4"
         id="tspan316"><tspan
           x="0"
           y="30"
           id="tspan298">Roads where</tspan><tspan
           class="cls-69"
           x="152.44"
           y="30"
           id="tspan300">c</tspan><tspan
           x="164.47"
           y="30"
           id="tspan302">ars and bi</tspan><tspan
           class="cls-35"
           x="274.06"
           y="30"
           id="tspan304">k</tspan><tspan
           x="286.25"
           y="30"
           id="tspan306">es are sepa</tspan><tspan
           class="cls-52"
           x="410.35999"
           y="30"
           id="tspan308">r</tspan><tspan
           x="417.76001"
           y="30"
           id="tspan310">a</tspan><tspan
           class="cls-60"
           x="430.79999"
           y="30"
           id="tspan312">t</tspan><tspan
           x="439.14999"
           y="30"
           id="tspan314">ed</tspan></tspan><tspan
         class="cls-4"
         id="tspan332"><tspan
           x="0"
           y="60"
           id="tspan318">or t</tspan><tspan
           class="cls-52"
           x="37.540001"
           y="60"
           id="tspan320">r</tspan><tspan
           class="cls-58"
           x="44.939999"
           y="60"
           id="tspan322">a</tspan><tspan
           class="cls-2"
           x="57.360001"
           y="60"
           id="tspan324">v</tspan><tspan
           x="67.849998"
           y="60"
           id="tspan326">el speeds are l</tspan><tspan
           class="cls-2"
           x="226.84"
           y="60"
           id="tspan328">o</tspan><tspan
           class="cls-31"
           x="240.53"
           y="60"
           id="tspan330">w</tspan></tspan></text>
    <text
       class="cls-38"
       transform="translate(41.95,954.03)"
       text-anchor="start"
       id="text338">834</text>
  </g>
  <line
     class="cls-56"
     x1="618.46"
     y1="334.93"
     x2="618.46"
     y2="642.59"
     id="line342" />
  <text
     class="cls-47"
     transform="translate(695.2 375.9)"
     text-anchor="middle"
     id="text360">Overall</text>
  <text
     class="cls-47"
     transform="translate(695.2 405.9)"
     text-anchor="middle"
     id="text170">Score</text>
  <text
     class="cls-54"
     transform="translate(695.2 494.11)"
     text-anchor="middle"
     id="text364">14</text>
  <line
     class="cls-56"
     x1="72.05"
     y1="871.17"
     x2="727.69"
     y2="869.13"
     id="line366" />
  <text
     class="cls-54"
     transform="translate(695.2 616.53)"
     text-anchor="middle"
     id="text370">100</text>
  <text
     class="cls-46"
     text-anchor="middle"
     id="text374"
     lengthAdjust="spacing"
     x="462.26001"
     y="138.19">Tampa</text>
  <text
     class="cls-12"
     text-anchor="middle"
     id="text378"
     x="462.26001"
     y="180.56"><tspan
       x="462.26001"
       y="180.56"
       id="tspan376">FL, United States</tspan></text>
  <text
     class="cls-7"
     text-anchor="middle"
     id="text382"
     x="462.26001"
     y="212.92999"><tspan
       x="462.26001"
       y="212.92999"
       id="tspan380">380476</tspan></text>
  <line
     class="cls-55"
     x1="658.96002"
     y1="221.92999"
     x2="658.96002"
     y2="75.25"
     id="line384" />
  <text
     class="cls-23"
     transform="translate(695.2 534.4)"
     text-anchor="middle"
     id="text388">out of</text>
  <g
     id="g456"
     transform="matrix(0.79513789,0,0,0.79513789,8.8316057,37.567614)">
    <path
       d="m 126.88,174.81 c 0,2.79 0.24,3.68 2.69,3.68 h 1.24 c 2.43,0 2.69,-0.9 2.69,-3.68 v -8.72 h 4.93 v 9.55 c 0,5.99 -1.42,7.71 -6.94,7.71 h -2.85 c -5.46,0 -6.94,-1.72 -6.94,-7.71 v -26.69 c 0,-5.99 1.48,-7.71 6.94,-7.71 h 2.85 c 5.52,0 6.94,1.72 6.94,7.71 v 7.77 h -4.93 v -6.94 c 0,-2.79 -0.24,-3.68 -2.69,-3.68 h -1.28 c -2.43,0 -2.69,0.9 -2.69,3.68 z"
       id="path390" />
    <path
       d="m 141.53,141.53 h 5.22 v 41.52 h -5.22 z"
       id="path392" />
    <path
       d="m 153.65,183.05 v -36.66 h -4.57 v -4.86 h 14.3 v 4.86 h -4.51 v 36.66 z"
       id="path394" />
    <path
       d="m 171.34,183.05 v -14 l -6.52,-27.52 h 5.28 l 2.19,9.78 c 0.88,3.76 1.53,7.56 1.96,11.39 0.46,-3.83 1.11,-7.63 1.96,-11.39 l 2.19,-9.78 h 4.63 l -6.47,27.52 v 14 z"
       id="path396" />
    <path
       d="m 210.78,175.76 c -0.06,2.46 0.24,4.92 0.9,7.29 h -5.46 c -0.6,-1.34 -0.65,-3.86 -0.65,-6.46 v -7.95 c 0,-2.84 -0.47,-4.15 -3.09,-4.15 h -3.5 v 18.57 h -5.22 v -41.52 h 10.08 c 5.52,0 6.94,1.72 6.94,7.71 v 5.63 c 0,4.33 -0.77,6.41 -3.32,7.16 2.55,0.83 3.32,2.91 3.32,7.29 v 6.42 z m -5.22,-25.68 c 0,-2.79 -0.18,-3.68 -2.69,-3.68 h -3.91 v 13.23 h 3.91 c 2.43,0 2.69,-0.9 2.69,-3.68 z"
       id="path398" />
    <path
       d="m 225.98,176.71 h -6.72 l -0.9,6.35 h -4.64 l 5.64,-41.52 h 7.16 l 5.56,41.52 h -5.21 z m -6.05,-4.86 h 5.4 l -0.65,-5.04 c -1.07,-8.31 -1.66,-15.36 -2.08,-20.94 -0.42,5.57 -0.95,12.63 -2.02,20.94 z"
       id="path400" />
    <path
       d="m 235.8,183.05 v -36.66 h -4.57 v -4.86 h 14.28 v 4.86 h -4.48 v 36.66 z"
       id="path402" />
    <path
       d="m 247.89,141.53 h 5.23 v 41.52 h -5.23 z"
       id="path404" />
    <path
       d="m 262.13,159.04 c -0.59,-2.61 -0.95,-5.04 -1.3,-7.48 0.06,2.44 0.12,4.87 0.12,7.61 v 23.9 h -4.5 v -41.54 h 6.58 l 4.93,22.18 c 0.59,2.61 1.01,5.04 1.34,7.47 -0.06,-2.43 -0.24,-4.86 -0.24,-7.53 v -22.13 h 4.57 v 41.52 h -5.91 l -5.58,-24.01 z"
       id="path406" />
    <path
       d="m 285.37,160.04 h 8.19 v 15.6 c 0,5.99 -1.42,7.71 -6.94,7.71 h -2.84 c -5.46,0 -6.94,-1.72 -6.94,-7.71 v -26.69 c 0,-5.99 1.48,-7.71 6.94,-7.71 h 2.84 c 5.52,0 6.94,1.72 6.94,7.71 v 7.06 h -4.93 v -6.23 c 0,-2.79 -0.24,-3.68 -2.69,-3.68 h -1.25 c -2.43,0 -2.69,0.9 -2.69,3.68 v 25.03 c 0,2.79 0.24,3.68 2.69,3.68 h 1.25 c 2.43,0 2.69,-0.9 2.69,-3.68 v -9.91 h -3.26 z"
       id="path408" />
    <path
       d="m 307.49,171.9 c 0,-3.73 -0.9,-4.86 -5.04,-8.6 -4.8,-4.33 -6.05,-6.17 -6.05,-11.64 v -2.71 c 0,-5.99 1.42,-7.71 6.94,-7.71 h 2.43 c 5.52,0 6.94,1.72 6.94,7.71 v 6.47 h -4.93 v -5.64 c 0,-2.79 -0.18,-3.68 -2.69,-3.68 h -0.9 c -2.43,0 -2.69,0.9 -2.69,3.58 v 1.96 c 0,3.73 0.9,4.93 5.04,8.66 4.8,4.33 6.11,6.11 6.11,11.57 v 3.8 c 0,5.99 -1.48,7.71 -6.94,7.71 h -2.45 c -5.46,0 -6.88,-1.72 -6.88,-7.71 V 168 h 4.86 v 6.82 c 0,2.79 0.18,3.68 2.69,3.68 h 0.9 c 2.43,0 2.69,-0.9 2.69,-3.68 l -0.03,-2.91 z"
       id="path410" />
    <path
       class="cls-65"
       d="m 43.11,163.94 v 13.38 c 0,3.08 2.49,5.58 5.57,5.58 h 54.8 c 3.08,0 5.58,-2.5 5.58,-5.58 v 0 -13.38 z m 45.08,7.92 c -6.79,6.4 -17.39,6.4 -24.18,0 l -0.17,-0.15 1.92,-1.92 0.16,0.15 c 5.73,5.36 14.63,5.36 20.36,0 l 0.16,-0.15 1.94,1.93 -0.17,0.13 z"
       id="path412" />
    <path
       class="cls-51"
       d="m 103.49,113.81 h -54.8 c -3.08,0 -5.58,2.5 -5.58,5.58 0,0 0,0 0,0 v 41.77 h 13.88 c -5,-2.23 -7.25,-8.1 -5.02,-13.11 2.23,-5 8.1,-7.25 13.11,-5.02 0.18,0.08 0.35,0.16 0.52,0.25 l 2.92,-4.71 -0.9,-2.69 c -0.65,-0.14 -1.03,0 -2.05,-0.14 -1.02,-0.14 -1.15,-0.45 -0.94,-1 0.21,-0.55 1.34,-0.31 2.35,-0.21 1.01,0.1 2.92,-0.28 3.82,-0.31 0.74,-0.01 1.41,0.45 1.67,1.15 -0.45,0.06 -0.89,0.1 -1.34,0.1 -0.5,-0.04 -1.01,0.05 -1.46,0.27 -0.17,0.06 -0.35,0.11 -0.52,0.15 l 0.67,2.02 h 15.24 l -1.43,-3.93 h 5.33 c 1.45,0 2.62,1.2 2.62,2.65 0,1.45 -1.2,2.62 -2.65,2.62 h -0.18 v -1.4 h 0.17 c 0.68,0 1.24,-0.54 1.25,-1.22 0,-0.68 -0.54,-1.24 -1.22,-1.25 h -3.3 l 2.58,7.12 c 0.86,-0.24 1.76,-0.36 2.66,-0.36 5.48,0 9.93,4.44 9.93,9.92 0,3.94 -2.33,7.51 -5.93,9.09 h 14.18 v -41.77 c 0,-3.08 -2.49,-5.58 -5.57,-5.58 z"
       id="path414" />
    <path
       class="cls-51"
       d="m 80.98,152.09 c 0,-3.94 2.32,-7.5 5.92,-9.09 l -1,-2.73 -11.38,12.05 c -0.31,0.32 -0.73,0.5 -1.17,0.5 h -2.47 c -0.27,3.67 -2.54,6.89 -5.91,8.36 h 21.94 c -3.61,-1.58 -5.94,-5.16 -5.93,-9.1 z"
       id="path416" />
    <path
       class="cls-51"
       d="m 65.73,145.8 -3.46,5.57 h 6.56 c -0.16,-1.84 -0.97,-3.56 -2.27,-4.86 -0.26,-0.26 -0.53,-0.49 -0.83,-0.7 z"
       id="path418" />
    <path
       class="cls-51"
       d="m 66.82,144.05 c 2.36,1.72 3.85,4.4 4.06,7.32 h 1.86 l -3.63,-11.01 z"
       id="path420" />
    <path
       class="cls-51"
       d="m 55.41,146.5 c -3.08,3.08 -3.08,8.07 0,11.15 3.08,3.08 8.07,3.08 11.15,0 1.31,-1.31 2.11,-3.03 2.28,-4.88 h -6.56 c -0.39,0.75 -1.31,1.05 -2.07,0.66 -0.75,-0.39 -1.05,-1.31 -0.66,-2.07 0.27,-0.52 0.8,-0.84 1.39,-0.83 h 0.17 l 3.41,-5.49 c -1.1,-0.55 -2.31,-0.84 -3.53,-0.84 -2.09,0 -4.1,0.82 -5.57,2.3 z"
       id="path422" />
    <path
       class="cls-51"
       d="m 98.79,152.09 c 0,-4.36 -3.53,-7.89 -7.89,-7.89 -0.66,0 -1.31,0.08 -1.95,0.25 l 2.24,6.13 c 0.84,0.13 1.4,0.92 1.27,1.75 -0.13,0.84 -0.92,1.4 -1.75,1.27 -0.84,-0.13 -1.4,-0.92 -1.27,-1.75 0.05,-0.31 0.19,-0.6 0.41,-0.82 l -2.24,-6.11 c -0.85,0.39 -1.62,0.93 -2.27,1.59 -3.08,3.08 -3.09,8.07 -0.01,11.15 3.08,3.08 8.07,3.09 11.15,0.01 1.48,-1.48 2.32,-3.49 2.32,-5.58 v 0 z"
       id="path424" />
    <polygon
       class="cls-51"
       points="84.77,139.37 70.29,139.37 74.07,150.82 74.07,150.83 "
       id="polygon426" />
    <path
       class="cls-78"
       d="m 130.8,132 c -0.76,0.69 -1.76,1.06 -2.79,1.03 -1.05,0.07 -2.07,-0.35 -2.77,-1.14 v 5.2 h -2.87 v -15.67 h 2.77 v 1.07 c 0.71,-0.83 1.77,-1.27 2.86,-1.2 1.03,-0.03 2.03,0.34 2.79,1.03 1.14,1.14 1.16,3.1 1.16,4.81 0,1.71 -0.02,3.69 -1.16,4.84 m -3.63,-8.11 c -1.72,0 -1.93,1.41 -1.93,3.28 0,1.87 0.22,3.3 1.93,3.3 1.71,0 1.93,-1.42 1.93,-3.3 0,-1.88 -0.22,-3.28 -1.93,-3.28"
       id="path428" />
    <path
       class="cls-78"
       d="m 136.13,128.07 c 0,1.47 0.9,2.55 2.5,2.55 0.99,0.06 1.94,-0.33 2.59,-1.08 l 1.74,1.69 c -1.1,1.23 -2.7,1.89 -4.35,1.79 -2.69,0 -5.3,-1.23 -5.3,-5.87 0,-3.74 2.02,-5.85 5,-5.85 3.19,0 4.99,2.33 4.99,5.47 v 1.28 h -7.17 z m 4.09,-3.17 c -0.52,-1.06 -1.8,-1.49 -2.86,-0.97 -0.42,0.21 -0.76,0.55 -0.97,0.97 -0.17,0.39 -0.26,0.81 -0.26,1.23 h 4.35 c 0,-0.42 -0.1,-0.84 -0.26,-1.23"
       id="path430" />
    <path
       class="cls-78"
       d="m 153.44,131.63 c -2,1.87 -5.11,1.87 -7.11,0 -1.03,-1.08 -1.29,-2.38 -1.29,-4.48 0,-2.1 0.26,-3.37 1.29,-4.44 2,-1.88 5.11,-1.88 7.11,0 1.03,1.07 1.3,2.37 1.3,4.44 0,2.07 -0.27,3.39 -1.3,4.48 m -2.24,-7.24 c -0.36,-0.35 -0.84,-0.53 -1.34,-0.51 -0.49,-0.02 -0.97,0.16 -1.32,0.51 -0.57,0.61 -0.64,1.58 -0.64,2.77 0,1.19 0.07,2.2 0.66,2.79 0.35,0.35 0.83,0.53 1.32,0.51 0.5,0.03 0.99,-0.16 1.34,-0.51 0.59,-0.59 0.66,-1.6 0.66,-2.79 0,-1.19 -0.07,-2.18 -0.66,-2.77"
       id="path432" />
    <path
       class="cls-78"
       d="m 165.05,132 c -0.77,0.69 -1.76,1.06 -2.79,1.03 -1.05,0.07 -2.07,-0.35 -2.77,-1.14 v 5.2 h -2.86 v -15.67 h 2.77 v 1.07 c 0.71,-0.83 1.77,-1.27 2.86,-1.2 1.03,-0.03 2.03,0.34 2.79,1.03 1.14,1.14 1.16,3.1 1.16,4.81 0,1.71 -0.02,3.69 -1.16,4.84 m -3.63,-8.11 c -1.72,0 -1.93,1.41 -1.93,3.28 0,1.87 0.22,3.3 1.93,3.3 1.71,0 1.93,-1.42 1.93,-3.3 0,-1.88 -0.22,-3.28 -1.93,-3.28"
       id="path434" />
    <path
       class="cls-78"
       d="m 171.3,132.91 c -2.36,0 -3.34,-1.65 -3.34,-3.28 v -12.38 h 2.86 v 12.2 c 0,0.69 0.28,1.04 1.01,1.04 h 1.1 v 2.42 z"
       id="path436" />
    <path
       class="cls-78"
       d="m 176.58,128.07 c 0,1.47 0.9,2.55 2.5,2.55 0.99,0.06 1.95,-0.33 2.6,-1.08 l 1.74,1.69 c -1.1,1.23 -2.71,1.88 -4.35,1.79 -2.71,0 -5.3,-1.23 -5.3,-5.87 0,-3.74 2.02,-5.85 4.99,-5.85 3.19,0 4.99,2.33 4.99,5.47 v 1.28 h -7.17 z m 4.09,-3.17 c -0.53,-1.06 -1.81,-1.49 -2.86,-0.96 -0.42,0.21 -0.75,0.54 -0.96,0.96 -0.17,0.39 -0.26,0.81 -0.26,1.23 h 4.35 c 0,-0.42 -0.1,-0.84 -0.26,-1.23"
       id="path438" />
    <path
       class="cls-77"
       d="m 188.92,125.63 v 7.28 h -2.32 v -7.28 h -0.97 v -1.77 h 0.97 v -1.16 c -0.07,-1.4 1,-2.59 2.4,-2.67 0.1,0 0.21,0 0.31,0 h 1.32 V 122 h -0.9 c -0.55,0 -0.81,0.31 -0.81,0.85 v 1.02 h 1.72 v 1.77 h -1.74 z"
       id="path440" />
    <path
       class="cls-77"
       d="m 198.07,131.87 c -1.62,1.52 -4.15,1.52 -5.77,0 -0.84,-0.9 -1.06,-1.93 -1.06,-3.63 0,-1.7 0.21,-2.74 1.06,-3.61 1.62,-1.53 4.15,-1.53 5.77,0 0.84,0.87 1.06,1.93 1.06,3.61 0,1.68 -0.22,2.75 -1.06,3.63 m -1.79,-5.88 c -0.29,-0.28 -0.68,-0.43 -1.09,-0.41 -0.4,-0.02 -0.79,0.13 -1.07,0.41 -0.48,0.48 -0.54,1.29 -0.54,2.24 0,0.95 0.05,1.79 0.54,2.27 0.29,0.28 0.68,0.43 1.07,0.41 0.39,0.02 0.77,-0.12 1.06,-0.39 0.48,-0.48 0.54,-1.31 0.54,-2.27 0,-0.96 -0.05,-1.79 -0.54,-2.24"
       id="path442" />
    <path
       class="cls-77"
       d="m 205.73,126.13 c -0.31,-0.36 -0.76,-0.57 -1.24,-0.55 -0.71,0 -1.5,0.53 -1.5,1.72 v 5.62 h -2.32 v -9.32 h 2.27 v 0.9 c 0.6,-0.65 1.45,-1.02 2.34,-1 0.83,-0.04 1.63,0.29 2.2,0.9 l -1.75,1.75 z"
       id="path444" />
    <path
       class="cls-78"
       d="m 217.59,132 c -0.76,0.69 -1.76,1.06 -2.79,1.03 -1.09,0.07 -2.15,-0.38 -2.86,-1.21 v 1.07 h -2.77 v -15.67 h 2.86 v 5.23 c 0.7,-0.79 1.72,-1.21 2.77,-1.14 1.03,-0.03 2.03,0.34 2.79,1.03 1.15,1.14 1.16,3.1 1.16,4.81 0,1.71 0,3.69 -1.16,4.84 m -3.63,-8.11 c -1.72,0 -1.94,1.41 -1.94,3.28 0,1.87 0.22,3.3 1.94,3.3 1.72,0 1.93,-1.42 1.93,-3.3 0,-1.88 -0.22,-3.28 -1.93,-3.28"
       id="path446" />
    <path
       class="cls-78"
       d="m 221.41,117.16 h 2.93 v 2.33 h -2.93 z m 0.04,4.29 h 2.86 v 11.46 h -2.86 z"
       id="path448" />
    <polygon
       class="cls-78"
       points="231.55,128.13 230.35,129.5 230.35,132.91 227.48,132.91 227.48,117.25 230.35,117.25 230.35,126.13 234.15,121.45 237.6,121.45 233.51,126.07 237.9,132.91 234.37,132.91 "
       id="polygon450" />
    <path
       class="cls-78"
       d="m 241.5,128.07 c 0,1.47 0.9,2.55 2.51,2.55 0.98,0.06 1.94,-0.34 2.59,-1.08 l 1.74,1.69 c -1.11,1.23 -2.71,1.89 -4.36,1.79 -2.69,0 -5.3,-1.23 -5.3,-5.87 0,-3.74 2.02,-5.85 5,-5.85 3.19,0 4.99,2.33 4.99,5.47 v 1.28 h -7.17 z m 4.09,-3.17 c -0.52,-1.06 -1.8,-1.49 -2.86,-0.97 -0.42,0.21 -0.76,0.55 -0.97,0.97 -0.17,0.39 -0.26,0.81 -0.26,1.23 h 4.35 c 0,-0.42 -0.1,-0.84 -0.26,-1.23"
       id="path452" />
    <path
       class="cls-78"
       d="m 255.22,133.04 c -1.79,0 -3.43,-0.2 -4.88,-1.65 l 1.89,-1.87 c 0.83,0.76 1.93,1.15 3.05,1.08 0.99,0 2.02,-0.33 2.02,-1.19 0,-0.57 -0.31,-0.97 -1.21,-1.06 l -1.79,-0.17 c -2.06,-0.2 -3.34,-1.1 -3.34,-3.21 0,-2.38 2.1,-3.65 4.42,-3.65 1.79,0 3.28,0.31 4.37,1.34 l -1.76,1.79 c -0.66,-0.6 -1.67,-0.77 -2.66,-0.77 -1.14,0 -1.63,0.53 -1.63,1.1 0,0.42 0.17,0.9 1.19,0.99 l 1.79,0.18 c 2.27,0.22 3.41,1.43 3.41,3.36 0,2.53 -2.15,3.74 -4.86,3.74"
       id="path454" />
  </g>
</svg>
LaurenzV commented 8 months ago

Since it's happening in resvg too I presume that for some reason fontdb fails to select the right font variant when converting the text into paths.

RazrFalcon commented 8 months ago

Just a dumb bug in the font-family parser. We need a better one...

mothsART commented 8 months ago

No regression test required after this correction?

RazrFalcon commented 8 months ago

font-family parser should be rewritten anyway and then it will have proper testing.

LaurenzV commented 8 months ago

Just so there is no duplicate work going on, I'm currently trying to rewrite the font-family parser. Let's see how it goes.

RazrFalcon commented 8 months ago

Got it. I do not plan working on resvg anytime soon, sadly...

LaurenzV commented 8 months ago

I have a small question, while working on this I noticed that as far as I can tell the current implementation does not support escaping of idents. So that you can for example write "\0054imes new Roman" instead of "Times New Roman".

Was it a conscious decision to not implement this or have you just not bothered to do it yet?

RazrFalcon commented 8 months ago

They are simply unimplemented. A very rare edge-case. You can try adding them to simplecss. There are a couple things we do not support: https://github.com/RazrFalcon/simplecss?tab=readme-ov-file#limitations

LaurenzV commented 7 months ago

By the way this bug isn't fixed yet, I think. I tried it out and can still reproduce it on main. This wasn't a font parsing issue but it's some issue within fontdb. So maybe this should be reopened.

LaurenzV commented 7 months ago
image

Okay so the reason is that for some reason both fonts are recognized as being style "Normal", so both are match. Now the question is whether it's a font issue or whether it's fontdb not recognizing it correctly.

LaurenzV commented 7 months ago
/// Returns style.
    pub fn style(&self) -> Style {
        let flags = SelectionFlags(self.fs_selection());
        if flags.italic() {
            Style::Italic
        } else if self.version >= 4 && flags.oblique() {
            Style::Oblique
        } else {
            Style::Normal
        }
    }

I think maybe the boolean condition here is mixed up?

Bit 9: If bit 9 is set, then this font is to be considered an β€œoblique” style by processes which make a distinction between oblique and italic styles, such as Cascading Style Sheets font matching. For example, a font created by algorithmically slanting an upright face will set this bit.

If a font has a version 4 or later OS/2 table and this bit is not set, then this font is not to be considered an β€œoblique” style. For example, a font that has a classic italic design will not set this bit.

I'm not sure what this implies though, obviously if the bit is not set then it's not oblique, I'm not sure how it relates to version 4... In any case, Dharma Gothic Italic's version seems to be 2 and that's why in this case, it matches Normal instead of Oblique. So this seems to be the root of the problem. I can't tell who's right and who's wrong though.

EDIT: Okay, nevermind, I should've kept on reading...

Versions 0 to 3: Only bit 0 (italic) to bit 6 (regular) are assigned. Bits 7 to 15 are reserved and must be set to 0. Applications should ignore bits 7 to 15 in a font that has a version 0 to version 3 OS/2 table.

So I guess this is the fault of the font then.

RazrFalcon commented 7 months ago

Thanks for the investigation!

So I guess this is the fault of the font then.

I guess so. TrueType parsing is a minefield. There is a spec and there is reality.

According to https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#font-style-matching :

If the value is β€˜normal’, normal faces are checked first, then oblique faces, then italic faces. Faces with other style values are excluded from the matching set.

That's why fontdb chooses Normal face instead of Bold. Therefore setting font-style="bold" should help. Both SVG and font are not quite correct.

But honestly, I have no idea how it should be handled...

RazrFalcon commented 7 months ago

@LaurenzV I double checked and resvg selects the correct font on master. Try this:

<svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg">
  <text x="300" y="500" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:240;font-family:DharmaGothicE-Bold, 'Dharma Gothic E';-inkscape-font-specification:'DharmaGothicE-Bold, Dharma Gothic E, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">2023</text>
  <text x="300" y="700" style="font-size:240;font-family:'Dharma Gothic E'">2023</text>
</svg>

out

As you can see, the bold font was choosen correctly. So resvg works just fine, at least "on my machine".

LaurenzV commented 7 months ago

It works fine for me too, assuming that I don't have "Dharma Gothic E Italic" in my fonts folder.

But as soon as I add the italic variant font to my system fonts, the result looks like this: test

RazrFalcon commented 7 months ago

Interesting. The font file I've found isn't marked as italic in OS/2 selection bitflags. But Apple recognizes it as Italic anyway. Maybe because post.italicAngle isn't zero...

Tried looking into freetype2 sources, but got even more confused. Not only there are like 3 ways to mark a TrueType font as italic. But freetype2 treats Oblique as Italic to begin with. Which is against CSS.

Here is what freetype2 does.

I guess I should update ttf_parser::Face::is_italic.

LaurenzV commented 7 months ago

The font file I've found isn't marked as italic in OS/2 selection bitflags.

Yup, the same is the case for my file. Only the oblique flag is set, but since the version is 2 it will be ignored.

RazrFalcon commented 7 months ago

Mine doesn't even have Oblique. But all apps except resvg still match the correct font. Even italic-angle fix in ttf-parser didn't help. Mystery...

RazrFalcon commented 7 months ago

I'm not using ttf-parser methods in fontdb... Will publish a fix soon.

rgreinho commented 7 months ago

Here are the font files we are using in case that helps: https://github.com/PeopleForBikes/brokenspoke/tree/main/assets/fonts/DharmaGothicExtended.

RazrFalcon commented 7 months ago

Thanks!

RazrFalcon commented 7 months ago

Fixed in master.