Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SVGinOT = "SVGinOT"

# Match Inside a Word - Case Insensitive
[default.extend-words]
wdth = "wdth"

[files]
# Include .github, .cargo, etc.
Expand Down
133 changes: 95 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/resvg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ workspace = "../.."
name = "resvg"
required-features = ["text", "system-fonts", "memmap-fonts"]

[[example]]
name = "generate_hinting_comparison"
required-features = ["text", "hinting"]

[dependencies]
gif = { version = "0.13", optional = true }
image-webp = { version = "0.2.0", optional = true }
Expand Down Expand Up @@ -42,3 +46,5 @@ memmap-fonts = ["usvg/memmap-fonts"]
# When disabled, `image` elements with SVG data will still be rendered.
# Adds around 200KiB to your binary.
raster-images = ["gif", "image-webp", "dep:zune-jpeg"]
# Enables font hinting via skrifa (requires `text`).
hinting = ["usvg/hinting"]
78 changes: 78 additions & 0 deletions crates/resvg/examples/generate_hinting_comparison.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//! Run with: cargo run --example generate_hinting_comparison --features text,hinting

use std::sync::Arc;
use usvg::fontdb;

fn main() {
// Load fonts
let mut fontdb = fontdb::Database::new();
fontdb.load_fonts_dir("crates/resvg/tests/fonts");
fontdb.set_sans_serif_family("Noto Sans");
let fontdb = Arc::new(fontdb);

// SVG with small text where hinting is most visible
let svg = br#"
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="200" style="background: white">
<text x="10" y="30" font-family="Noto Sans" font-size="12" text-rendering="optimizeLegibility">
The quick brown fox jumps over the lazy dog. (12px)
</text>
<text x="10" y="60" font-family="Noto Sans" font-size="14" text-rendering="optimizeLegibility">
The quick brown fox jumps over the lazy dog. (14px)
</text>
<text x="10" y="95" font-family="Noto Sans" font-size="16" text-rendering="optimizeLegibility">
The quick brown fox jumps over the lazy dog. (16px)
</text>
<text x="10" y="135" font-family="Noto Sans" font-size="20" text-rendering="optimizeLegibility">
The quick brown fox jumps over. (20px)
</text>
<text x="10" y="180" font-family="Noto Sans" font-size="24" text-rendering="optimizeLegibility">
The quick brown fox. (24px)
</text>
</svg>
"#;

// Render with hinting
let opt_hinted = usvg::Options {
fontdb: fontdb.clone(),
hinting: usvg::HintingOptions {
enabled: true,
dpi: Some(96.0),
},
..usvg::Options::default()
};

let tree = usvg::Tree::from_data(svg, &opt_hinted).unwrap();
let size = tree.size().to_int_size();
let mut pixmap = tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
pixmap.fill(tiny_skia::Color::WHITE);
resvg::render(
&tree,
tiny_skia::Transform::identity(),
&mut pixmap.as_mut(),
);
pixmap.save_png("hinted.png").unwrap();
println!("Saved hinted.png");

// Render without hinting
let opt_unhinted = usvg::Options {
fontdb: fontdb.clone(),
hinting: usvg::HintingOptions {
enabled: false,
dpi: Some(96.0),
},
..usvg::Options::default()
};

let tree = usvg::Tree::from_data(svg, &opt_unhinted).unwrap();
let mut pixmap = tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
pixmap.fill(tiny_skia::Color::WHITE);
resvg::render(
&tree,
tiny_skia::Transform::identity(),
&mut pixmap.as_mut(),
);
pixmap.save_png("unhinted.png").unwrap();
println!("Saved unhinted.png");

println!("Done! Compare hinted.png and unhinted.png");
}
2 changes: 2 additions & 0 deletions crates/resvg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ fn parse_args() -> Result<Args, String> {
image_href_resolver: usvg::ImageHrefResolver::default(),
font_resolver: usvg::FontResolver::default(),
fontdb: Arc::new(fontdb::Database::new()),
#[cfg(feature = "text")]
hinting: usvg::HintingOptions::default(),
style_sheet,
};

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added crates/resvg/tests-hinted/tests/text/text/nested.png
Loading