Improved dpi handling
This commit is contained in:
parent
5696afcadd
commit
f737c6da24
2 changed files with 8 additions and 54 deletions
|
|
@ -370,8 +370,7 @@ impl Renderer {
|
||||||
translated,
|
translated,
|
||||||
bounds,
|
bounds,
|
||||||
target,
|
target,
|
||||||
(dpi * 96.0) as u16,
|
dpi,
|
||||||
(dpi * 20.0) as u16,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,6 @@ impl Pipeline {
|
||||||
|
|
||||||
let mut opt = resvg::Options::default();
|
let mut opt = resvg::Options::default();
|
||||||
opt.usvg.path = Some(handle.path.clone());
|
opt.usvg.path = Some(handle.path.clone());
|
||||||
opt.usvg.dpi = handle.dpi as f64;
|
|
||||||
opt.usvg.font_size = handle.font_size as f64;
|
|
||||||
|
|
||||||
let mem =
|
let mem =
|
||||||
match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) {
|
match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) {
|
||||||
|
|
@ -237,8 +235,7 @@ impl Pipeline {
|
||||||
transformation: Transformation,
|
transformation: Transformation,
|
||||||
bounds: Rectangle<u32>,
|
bounds: Rectangle<u32>,
|
||||||
target: &wgpu::TextureView,
|
target: &wgpu::TextureView,
|
||||||
dpi: u16,
|
dpi: f32,
|
||||||
font_size: u16,
|
|
||||||
) {
|
) {
|
||||||
let uniforms_buffer = device
|
let uniforms_buffer = device
|
||||||
.create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC)
|
.create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC)
|
||||||
|
|
@ -259,19 +256,15 @@ impl Pipeline {
|
||||||
//
|
//
|
||||||
// [1]: https://github.com/nical/guillotiere
|
// [1]: https://github.com/nical/guillotiere
|
||||||
for svg in svgs {
|
for svg in svgs {
|
||||||
let mut handle = svg.handle.clone();
|
self.load(&svg.handle);
|
||||||
handle.set_dpi(dpi);
|
|
||||||
handle.set_font_size(font_size);
|
|
||||||
|
|
||||||
self.load(&handle);
|
|
||||||
|
|
||||||
if let Some(texture) =
|
if let Some(texture) =
|
||||||
self.cache.borrow_mut().get(&handle).unwrap().upload(
|
self.cache.borrow_mut().get(&svg.handle).unwrap().upload(
|
||||||
device,
|
device,
|
||||||
encoder,
|
encoder,
|
||||||
&self.texture_layout,
|
&self.texture_layout,
|
||||||
svg.scale[0] as u32,
|
(svg.scale[0] * dpi) as u32,
|
||||||
svg.scale[1] as u32,
|
(svg.scale[1] * dpi) as u32,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let instance_buffer = device
|
let instance_buffer = device
|
||||||
|
|
@ -339,8 +332,6 @@ impl Pipeline {
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
id: u64,
|
id: u64,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
dpi: u16,
|
|
||||||
font_size: u16,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
|
|
@ -356,57 +347,19 @@ impl Handle {
|
||||||
/// [`Handle`]: struct.Handle.html
|
/// [`Handle`]: struct.Handle.html
|
||||||
pub fn from_path<T: Into<PathBuf>>(path: T) -> Handle {
|
pub fn from_path<T: Into<PathBuf>>(path: T) -> Handle {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let dpi = 96;
|
|
||||||
let font_size = 20;
|
|
||||||
let mut hasher = Hasher::default();
|
let mut hasher = Hasher::default();
|
||||||
path.hash(&mut hasher);
|
path.hash(&mut hasher);
|
||||||
dpi.hash(&mut hasher);
|
|
||||||
font_size.hash(&mut hasher);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: hasher.finish(),
|
id: hasher.finish(),
|
||||||
path,
|
path,
|
||||||
dpi,
|
|
||||||
font_size,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_dpi(&mut self, dpi: u16) {
|
|
||||||
if self.dpi == dpi {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.dpi = dpi;
|
|
||||||
|
|
||||||
let mut hasher = Hasher::default();
|
|
||||||
self.path.hash(&mut hasher);
|
|
||||||
self.dpi.hash(&mut hasher);
|
|
||||||
self.font_size.hash(&mut hasher);
|
|
||||||
|
|
||||||
self.id = hasher.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_font_size(&mut self, font_size: u16) {
|
|
||||||
if self.font_size == font_size {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.font_size = font_size;
|
|
||||||
|
|
||||||
let mut hasher = Hasher::default();
|
|
||||||
self.path.hash(&mut hasher);
|
|
||||||
self.dpi.hash(&mut hasher);
|
|
||||||
self.font_size.hash(&mut hasher);
|
|
||||||
|
|
||||||
self.id = hasher.finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for Handle {
|
impl Hash for Handle {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
self.id.hash(state);
|
self.id.hash(state);
|
||||||
self.dpi.hash(state);
|
|
||||||
self.font_size.hash(state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -428,6 +381,8 @@ impl Memory {
|
||||||
) -> Option<Rc<wgpu::BindGroup>> {
|
) -> Option<Rc<wgpu::BindGroup>> {
|
||||||
match self {
|
match self {
|
||||||
Memory::Host { tree } => {
|
Memory::Host { tree } => {
|
||||||
|
println!("{} {}", width, height);
|
||||||
|
|
||||||
let extent = wgpu::Extent3d {
|
let extent = wgpu::Extent3d {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue