diff --git a/avenger-python/src/lib.rs b/avenger-python/src/lib.rs index 0589e3b..a23c68b 100644 --- a/avenger-python/src/lib.rs +++ b/avenger-python/src/lib.rs @@ -1,6 +1,7 @@ use avenger::scene_graph::SceneGraph as RsSceneGraph; use avenger_vega::scene_graph::VegaSceneGraph; use avenger_wgpu::canvas::{Canvas, CanvasDimensions, PngCanvas}; +use avenger_wgpu::register_font_directory as register_font_directory_rs; use image::{EncodableLayout, ImageOutputFormat}; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; @@ -43,9 +44,20 @@ impl SceneGraph { } } +/// Register a directory of fonts for use in subsequent rendering +/// +/// Args: +/// font_dir (str): Absolute path to a directory containing font files +#[pyfunction] +#[pyo3(text_signature = "(font_dir)")] +fn register_font_directory(font_dir: &str) { + register_font_directory_rs(font_dir); +} + #[pymodule] fn _avenger(_py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; + m.add_function(wrap_pyfunction!(register_font_directory, m)?)?; m.add("__version__", env!("CARGO_PKG_VERSION"))?; Ok(()) } diff --git a/avenger-vega-test-data/fonts/Caveat/Caveat-VariableFont_wght.ttf b/avenger-vega-test-data/fonts/Caveat/Caveat-VariableFont_wght.ttf new file mode 100644 index 0000000..c083501 Binary files /dev/null and b/avenger-vega-test-data/fonts/Caveat/Caveat-VariableFont_wght.ttf differ diff --git a/avenger-vega-test-data/fonts/Caveat/OFL.txt b/avenger-vega-test-data/fonts/Caveat/OFL.txt new file mode 100644 index 0000000..6e5220c --- /dev/null +++ b/avenger-vega-test-data/fonts/Caveat/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2014 The Caveat Project Authors (https://github.com/googlefonts/caveat) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/avenger-vega-test-data/fonts/Caveat/README.txt b/avenger-vega-test-data/fonts/Caveat/README.txt new file mode 100644 index 0000000..34124c0 --- /dev/null +++ b/avenger-vega-test-data/fonts/Caveat/README.txt @@ -0,0 +1,66 @@ +Caveat Variable Font +==================== + +This download contains Caveat as both a variable font and static fonts. + +Caveat is a variable font with this axis: + wght + +This means all the styles are contained in a single file: + Caveat-VariableFont_wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Caveat: + static/Caveat-Regular.ttf + static/Caveat-Medium.ttf + static/Caveat-SemiBold.ttf + static/Caveat-Bold.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/avenger-vega-test-data/fonts/Caveat/static/Caveat-Bold.ttf b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Bold.ttf new file mode 100644 index 0000000..5b05296 Binary files /dev/null and b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Bold.ttf differ diff --git a/avenger-vega-test-data/fonts/Caveat/static/Caveat-Medium.ttf b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Medium.ttf new file mode 100644 index 0000000..ec96174 Binary files /dev/null and b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Medium.ttf differ diff --git a/avenger-vega-test-data/fonts/Caveat/static/Caveat-Regular.ttf b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Regular.ttf new file mode 100644 index 0000000..9654095 Binary files /dev/null and b/avenger-vega-test-data/fonts/Caveat/static/Caveat-Regular.ttf differ diff --git a/avenger-vega-test-data/fonts/Caveat/static/Caveat-SemiBold.ttf b/avenger-vega-test-data/fonts/Caveat/static/Caveat-SemiBold.ttf new file mode 100644 index 0000000..113d70d Binary files /dev/null and b/avenger-vega-test-data/fonts/Caveat/static/Caveat-SemiBold.ttf differ diff --git a/avenger-vega-test-data/src/main.rs b/avenger-vega-test-data/src/main.rs index aba7f8a..dbbbc8e 100644 --- a/avenger-vega-test-data/src/main.rs +++ b/avenger-vega-test-data/src/main.rs @@ -1,7 +1,19 @@ use std::fs::DirEntry; use std::path::Path; +use std::sync::Once; use std::{fs, io}; +use vl_convert_rs::text::register_font_directory; use vl_convert_rs::VlConverter; +static INIT: Once = Once::new(); + +pub fn initialize() { + INIT.call_once(|| { + let root_path = Path::new(env!("CARGO_MANIFEST_DIR")); + let fonts_dir = root_path.join("fonts"); + register_font_directory(fonts_dir.to_str().unwrap()) + .expect("Failed to register test font directory"); + }); +} /// Generate test data for each Vega spec located in `avenger-vega-test-data/vega-specs` /// For each spec, the following three files are saved to `avenger-vega-test-data/vega-scenegraphs` @@ -9,6 +21,7 @@ use vl_convert_rs::VlConverter; /// 2. spec_name.sg.json: This is a JSON file containing the chart's scene graph /// 3. spec_name.png: This is a PNG rendering of the chart using vl-convert with resvg fn main() { + initialize(); let mut converter = VlConverter::new(); let specs_dir = format!("{}/vega-specs", env!("CARGO_MANIFEST_DIR")); diff --git a/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.png b/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.png new file mode 100644 index 0000000..3682726 Binary files /dev/null and b/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.png differ diff --git a/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.sg.json b/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.sg.json new file mode 100644 index 0000000..6db299f --- /dev/null +++ b/avenger-vega-test-data/vega-scenegraphs/vl-convert/stacked_bar_h.sg.json @@ -0,0 +1,1590 @@ +{ + "width": 434, + "height": 259, + "origin": [ + 124, + 22 + ], + "scenegraph": { + "clip": false, + "interactive": true, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 0, + "y": 0, + "y2": -200 + }, + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 40, + "y": 0, + "y2": -200 + }, + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 80, + "y": 0, + "y2": -200 + }, + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 120, + "y": 0, + "y2": -200 + }, + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 160, + "y": 0, + "y2": -200 + }, + { + "opacity": 1, + "stroke": "#ddd", + "strokeWidth": 1, + "x": 200, + "y": 0, + "y2": -200 + } + ], + "marktype": "rule", + "role": "axis-grid", + "zindex": 0 + } + ], + "orient": "bottom", + "offset": 0, + "x": 0.5, + "y": 200.5 + } + ], + "marktype": "group", + "role": "axis", + "zindex": 0, + "aria": false + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 0 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 40 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 80 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 120 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 160 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 0, + "y2": 5, + "x": 200 + } + ], + "marktype": "rule", + "role": "axis-tick", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 0, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "0", + "align": "left", + "baseline": "top" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 40, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "100", + "align": "center", + "baseline": "top" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 80, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "200", + "align": "center", + "baseline": "top" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 120, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "300", + "align": "center", + "baseline": "top" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 160, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "400", + "align": "center", + "baseline": "top" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 200, + "y": 7, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "500", + "align": "right", + "baseline": "top" + } + ], + "marktype": "text", + "role": "axis-label", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "x": 0, + "x2": 200, + "y": 0 + } + ], + "marktype": "rule", + "role": "axis-domain", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 11, + "fontWeight": "bold", + "opacity": 1, + "align": "center", + "angle": 0, + "baseline": "top", + "font": "serif", + "text": "Sum of yield", + "x": 100, + "y": 21 + } + ], + "marktype": "text", + "role": "axis-title", + "zindex": 0 + } + ], + "orient": "bottom", + "offset": 0, + "x": 0.5, + "y": 200.5 + } + ], + "marktype": "group", + "role": "axis", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 10, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 30, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 50, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 70, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 90, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 110, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 130, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 150, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 170, + "x": 0, + "x2": -5 + }, + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "y": 190, + "x": 0, + "x2": -5 + } + ], + "marktype": "rule", + "role": "axis-tick", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 9.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Glabron", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 29.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Manchuria", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 49.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "No. 457", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 69.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "No. 462", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 89.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "No. 475", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 109.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Peatland", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 129.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Svansota", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 149.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Trebi", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 169.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Velvet", + "align": "right", + "baseline": "middle" + }, + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": -7, + "y": 189.5, + "angle": 0, + "font": "monospace", + "limit": 180, + "text": "Wisconsin No. 38", + "align": "right", + "baseline": "middle" + } + ], + "marktype": "text", + "role": "axis-label", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "stroke": "#888", + "strokeWidth": 1, + "x": 0, + "y": 0, + "y2": 200 + } + ], + "marktype": "rule", + "role": "axis-domain", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 11, + "fontWeight": "bold", + "opacity": 1, + "align": "center", + "angle": -90, + "baseline": "bottom", + "font": "serif", + "text": "variety", + "y": 100, + "x": -107.015625 + } + ], + "marktype": "text", + "role": "axis-title", + "zindex": 0 + } + ], + "orient": "left", + "offset": 0, + "x": 0.5, + "y": 0.5 + } + ], + "marktype": "group", + "role": "axis", + "zindex": 0 + }, + { + "clip": false, + "interactive": true, + "items": [ + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 53.9; variety: Manchuria; site: University Farm", + "x": 96.533336, + "x2": 118.09333600000001, + "y": 21, + "height": 18, + "width": 21.560000000000002 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 82.33334; variety: Manchuria; site: Waseca", + "x": 118.09333600000001, + "x2": 151.02667200000002, + "y": 21, + "height": 18, + "width": 32.93333600000001 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 61.8; variety: Manchuria; site: Morris", + "x": 71.813336, + "x2": 96.533336, + "y": 21, + "height": 18, + "width": 24.72 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 72.9; variety: Manchuria; site: Crookston", + "x": 0, + "x2": 29.160000000000004, + "y": 21, + "height": 18, + "width": 29.160000000000004 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 55.1; variety: Manchuria; site: Grand Rapids", + "x": 49.773336, + "x2": 71.813336, + "y": 21, + "height": 18, + "width": 22.040000000000006 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 51.53334; variety: Manchuria; site: Duluth", + "x": 29.160000000000004, + "x2": 49.773336, + "y": 21, + "height": 18, + "width": 20.613335999999997 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 79.86666; variety: Glabron; site: University Farm", + "x": 90.91999999999999, + "x2": 122.86666399999999, + "y": 1, + "height": 18, + "width": 31.946664 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 92.93333; variety: Glabron; site: Waseca", + "x": 122.86666399999999, + "x2": 160.039996, + "y": 1, + "height": 18, + "width": 37.173332000000016 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 63.9; variety: Glabron; site: Morris", + "x": 65.36, + "x2": 90.91999999999999, + "y": 1, + "height": 18, + "width": 25.559999999999988 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 64.3; variety: Glabron; site: Crookston", + "x": 0, + "x2": 25.72, + "y": 1, + "height": 18, + "width": 25.72 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 43.56666; variety: Glabron; site: Grand Rapids", + "x": 47.933336, + "x2": 65.36, + "y": 1, + "height": 18, + "width": 17.426664000000002 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 55.53334; variety: Glabron; site: Duluth", + "x": 25.72, + "x2": 47.933336, + "y": 1, + "height": 18, + "width": 22.213335999999998 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 62.56667; variety: Svansota; site: University Farm", + "x": 86.453332, + "x2": 111.48, + "y": 121, + "height": 18, + "width": 25.026668 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 85.83333; variety: Svansota; site: Waseca", + "x": 111.48, + "x2": 145.813332, + "y": 121, + "height": 18, + "width": 34.333332 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 60.8; variety: Svansota; site: Morris", + "x": 62.133331999999996, + "x2": 86.453332, + "y": 121, + "height": 18, + "width": 24.320000000000007 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 61.1; variety: Svansota; site: Crookston", + "x": 0, + "x2": 24.44, + "y": 121, + "height": 18, + "width": 24.44 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 46.3; variety: Svansota; site: Grand Rapids", + "x": 43.61333200000001, + "x2": 62.133331999999996, + "y": 121, + "height": 18, + "width": 18.51999999999999 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 47.93333; variety: Svansota; site: Duluth", + "x": 24.44, + "x2": 43.61333200000001, + "y": 121, + "height": 18, + "width": 19.173332000000006 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 66.7; variety: Velvet; site: University Farm", + "x": 96.959992, + "x2": 123.63999199999999, + "y": 161, + "height": 18, + "width": 26.679999999999993 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 87.63333; variety: Velvet; site: Waseca", + "x": 123.63999199999999, + "x2": 158.693324, + "y": 161, + "height": 18, + "width": 35.053332 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 64.96666; variety: Velvet; site: Morris", + "x": 70.97332800000001, + "x2": 96.959992, + "y": 161, + "height": 18, + "width": 25.98666399999999 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 73.39999; variety: Velvet; site: Crookston", + "x": 0, + "x2": 29.359996, + "y": 161, + "height": 18, + "width": 29.359996 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 55.26666; variety: Velvet; site: Grand Rapids", + "x": 48.86666400000001, + "x2": 70.97332800000001, + "y": 161, + "height": 18, + "width": 22.106664000000002 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 48.76667; variety: Velvet; site: Duluth", + "x": 29.359996, + "x2": 48.86666400000001, + "y": 161, + "height": 18, + "width": 19.50666800000001 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 65.63333; variety: Trebi; site: University Farm", + "x": 117.63999600000001, + "x2": 143.893328, + "y": 141, + "height": 18, + "width": 26.253331999999986 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 113.0666; variety: Trebi; site: Waseca", + "x": 143.893328, + "x2": 189.11996800000003, + "y": 141, + "height": 18, + "width": 45.22664000000003 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 90.4; variety: Trebi; site: Morris", + "x": 81.47999600000001, + "x2": 117.63999600000001, + "y": 141, + "height": 18, + "width": 36.16 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 88.76666; variety: Trebi; site: Crookston", + "x": 0, + "x2": 35.506664, + "y": 141, + "height": 18, + "width": 35.506664 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 50.4; variety: Trebi; site: Grand Rapids", + "x": 61.319995999999996, + "x2": 81.47999600000001, + "y": 141, + "height": 18, + "width": 20.160000000000018 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 64.53333; variety: Trebi; site: Duluth", + "x": 35.506664, + "x2": 61.319995999999996, + "y": 141, + "height": 18, + "width": 25.813331999999996 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 69.70001; variety: No. 457; site: University Farm", + "x": 104.06667200000001, + "x2": 131.94667600000002, + "y": 41, + "height": 18, + "width": 27.880004000000014 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 100.3; variety: No. 457; site: Waseca", + "x": 131.94667600000002, + "x2": 172.06667600000003, + "y": 41, + "height": 18, + "width": 40.120000000000005 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 72.23334; variety: No. 457; site: Morris", + "x": 75.173336, + "x2": 104.06667200000001, + "y": 41, + "height": 18, + "width": 28.893336000000005 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 80; variety: No. 457; site: Crookston", + "x": 0, + "x2": 32, + "y": 41, + "height": 18, + "width": 32 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 51.63334; variety: No. 457; site: Grand Rapids", + "x": 54.52, + "x2": 75.173336, + "y": 41, + "height": 18, + "width": 20.653336000000003 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 56.3; variety: No. 457; site: Duluth", + "x": 32, + "x2": 54.52, + "y": 41, + "height": 18, + "width": 22.520000000000003 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 62.16667; variety: No. 462; site: University Farm", + "x": 100.75999999999998, + "x2": 125.626668, + "y": 61, + "height": 18, + "width": 24.86666800000002 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 110.4667; variety: No. 462; site: Waseca", + "x": 125.626668, + "x2": 169.813348, + "y": 61, + "height": 18, + "width": 44.186679999999996 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 77.36667; variety: No. 462; site: Morris", + "x": 69.81333199999999, + "x2": 100.75999999999998, + "y": 61, + "height": 18, + "width": 30.94666799999999 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 79.09999; variety: No. 462; site: Crookston", + "x": 0, + "x2": 31.639995999999996, + "y": 61, + "height": 18, + "width": 31.639995999999996 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 44.83334; variety: No. 462; site: Grand Rapids", + "x": 51.87999599999999, + "x2": 69.81333199999999, + "y": 61, + "height": 18, + "width": 17.933335999999997 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 50.6; variety: No. 462; site: Duluth", + "x": 31.639995999999996, + "x2": 51.87999599999999, + "y": 61, + "height": 18, + "width": 20.239999999999995 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 60.83334; variety: Peatland; site: University Farm", + "x": 105.89333599999999, + "x2": 130.226672, + "y": 101, + "height": 18, + "width": 24.333336000000017 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 84.59999; variety: Peatland; site: Waseca", + "x": 130.226672, + "x2": 164.066668, + "y": 101, + "height": 18, + "width": 33.839995999999985 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 73.06667; variety: Peatland; site: Morris", + "x": 76.666668, + "x2": 105.89333599999999, + "y": 101, + "height": 18, + "width": 29.22666799999999 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 66.83333; variety: Peatland; site: Crookston", + "x": 0, + "x2": 26.733332000000004, + "y": 101, + "height": 18, + "width": 26.733332000000004 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 61.46667; variety: Peatland; site: Grand Rapids", + "x": 52.07999999999999, + "x2": 76.666668, + "y": 101, + "height": 18, + "width": 24.58666800000001 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 63.36667; variety: Peatland; site: Duluth", + "x": 26.733332000000004, + "x2": 52.07999999999999, + "y": 101, + "height": 18, + "width": 25.346667999999987 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 54.66667; variety: No. 475; site: University Farm", + "x": 95.37332799999999, + "x2": 117.23999599999999, + "y": 81, + "height": 18, + "width": 21.866668000000004 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 88.03334; variety: No. 475; site: Waseca", + "x": 117.23999599999999, + "x2": 152.453332, + "y": 81, + "height": 18, + "width": 35.213336 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 66.83333; variety: No. 475; site: Morris", + "x": 68.639996, + "x2": 95.37332799999999, + "y": 81, + "height": 18, + "width": 26.73333199999999 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 76.23333; variety: No. 475; site: Crookston", + "x": 0, + "x2": 30.493332000000002, + "y": 81, + "height": 18, + "width": 30.493332000000002 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 34.93333; variety: No. 475; site: Grand Rapids", + "x": 54.66666399999999, + "x2": 68.639996, + "y": 81, + "height": 18, + "width": 13.973332000000006 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 60.43333; variety: No. 475; site: Duluth", + "x": 30.493332000000002, + "x2": 54.66666399999999, + "y": 81, + "height": 18, + "width": 24.173331999999988 + }, + { + "fill": "#54a24b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 77.3; variety: Wisconsin No. 38; site: University Farm", + "x": 111.386672, + "x2": 142.306672, + "y": 181, + "height": 18, + "width": 30.919999999999987 + }, + { + "fill": "#eeca3b", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 116.96667; variety: Wisconsin No. 38; site: Waseca", + "x": 142.306672, + "x2": 189.09334, + "y": 181, + "height": 18, + "width": 46.78666800000002 + }, + { + "fill": "#72b7b2", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 76.63334; variety: Wisconsin No. 38; site: Morris", + "x": 80.733336, + "x2": 111.386672, + "y": 181, + "height": 18, + "width": 30.65333600000001 + }, + { + "fill": "#4c78a8", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 85.76667; variety: Wisconsin No. 38; site: Crookston", + "x": 0, + "x2": 34.306668, + "y": 181, + "height": 18, + "width": 34.306668 + }, + { + "fill": "#e45756", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 55.13334; variety: Wisconsin No. 38; site: Grand Rapids", + "x": 58.68, + "x2": 80.733336, + "y": 181, + "height": 18, + "width": 22.053335999999994 + }, + { + "fill": "#f58518", + "ariaRoleDescription": "bar", + "description": "Sum of yield: 60.93333; variety: Wisconsin No. 38; site: Duluth", + "x": 34.306668, + "x2": 58.68, + "y": 181, + "height": 18, + "width": 24.373331999999998 + } + ], + "marktype": "rect", + "name": "marks", + "role": "mark", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#4c78a8" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "Crookston" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 0 + }, + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#f58518" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "Duluth" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 13 + }, + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#e45756" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "Grand Rapids" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 26 + }, + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#72b7b2" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "Morris" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 39 + }, + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#54a24b" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "University Farm" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 52 + }, + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "opacity": 1, + "x": 6, + "y": 6, + "shape": "square", + "size": 100, + "strokeWidth": 1.5, + "fill": "#eeca3b" + } + ], + "marktype": "symbol", + "role": "legend-symbol", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 10, + "opacity": 1, + "x": 16, + "y": 6, + "align": "left", + "baseline": "middle", + "font": "sans-serif", + "limit": 160, + "text": "Waseca" + } + ], + "marktype": "text", + "role": "legend-label", + "zindex": 0 + } + ], + "width": 86.0048828125, + "height": 11, + "opacity": 1, + "x": 0, + "y": 65 + } + ], + "marktype": "group", + "role": "scope", + "zindex": 0 + } + ], + "x": 0, + "y": 16 + } + ], + "marktype": "group", + "role": "legend-entry", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "fontSize": 11, + "fontWeight": "bold", + "opacity": 1, + "orient": "top", + "text": "site", + "font": "serif", + "limit": 180, + "x": 0, + "y": 0, + "angle": 0, + "align": "left", + "baseline": "top" + } + ], + "marktype": "text", + "role": "legend-title", + "zindex": 0 + } + ], + "orient": "right", + "x": 218, + "y": 0, + "width": 87, + "height": 92 + } + ], + "marktype": "group", + "role": "legend", + "zindex": 0 + }, + { + "clip": false, + "interactive": false, + "items": [ + { + "items": [ + { + "clip": false, + "interactive": false, + "items": [ + { + "fill": "#000", + "font": "Caveat", + "fontSize": 13, + "fontWeight": "bold", + "opacity": 1, + "text": "Figure & Title < ' >", + "baseline": "top", + "align": "center", + "angle": 0 + } + ], + "marktype": "text", + "role": "title-text", + "zindex": 0 + } + ], + "orient": "top", + "offset": 4, + "align": "center", + "angle": 0, + "x": 100, + "y": -17 + } + ], + "marktype": "group", + "role": "title", + "zindex": 0 + } + ], + "fill": "transparent", + "stroke": "#ddd", + "x": 0, + "y": 0, + "width": 200, + "height": 200 + } + ], + "marktype": "group", + "name": "root", + "role": "frame", + "zindex": 0 + } +} \ No newline at end of file diff --git a/avenger-vega-test-data/vega-specs/vl-convert/stacked_bar_h.vg.json b/avenger-vega-test-data/vega-specs/vl-convert/stacked_bar_h.vg.json new file mode 100644 index 0000000..5efdd80 --- /dev/null +++ b/avenger-vega-test-data/vega-specs/vl-convert/stacked_bar_h.vg.json @@ -0,0 +1,130 @@ +{ + "$schema": "https://vega.github.io/schema/vega/v5.json", + "background": "white", + "padding": 5, + "width": 200, + "title": {"text": "Figure & Title < ' >", "frame": "group"}, + "style": "cell", + "data": [ + { + "name": "source_0", + "url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/barley.json", + "format": {"type": "json"}, + "transform": [ + { + "type": "aggregate", + "groupby": ["variety", "site"], + "ops": ["sum"], + "fields": ["yield"], + "as": ["sum_yield"] + }, + { + "type": "stack", + "groupby": ["variety"], + "field": "sum_yield", + "sort": {"field": ["site"], "order": ["ascending"]}, + "as": ["sum_yield_start", "sum_yield_end"], + "offset": "zero" + }, + { + "type": "filter", + "expr": "isValid(datum[\"sum_yield\"]) && isFinite(+datum[\"sum_yield\"])" + } + ] + } + ], + "signals": [ + {"name": "y_step", "value": 20}, + { + "name": "height", + "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" + } + ], + "marks": [ + { + "name": "marks", + "type": "rect", + "style": ["bar"], + "from": {"data": "source_0"}, + "encode": { + "update": { + "fill": {"scale": "color", "field": "site"}, + "ariaRoleDescription": {"value": "bar"}, + "description": { + "signal": "\"Sum of yield: \" + (format(datum[\"sum_yield\"], \"\")) + \"; variety: \" + (isValid(datum[\"variety\"]) ? datum[\"variety\"] : \"\"+datum[\"variety\"]) + \"; site: \" + (isValid(datum[\"site\"]) ? datum[\"site\"] : \"\"+datum[\"site\"])" + }, + "x": {"scale": "x", "field": "sum_yield_end"}, + "x2": {"scale": "x", "field": "sum_yield_start"}, + "y": {"scale": "y", "field": "variety"}, + "height": {"signal": "max(0.25, bandwidth('y'))"} + } + } + } + ], + "scales": [ + { + "name": "x", + "type": "linear", + "domain": { + "data": "source_0", + "fields": ["sum_yield_start", "sum_yield_end"] + }, + "range": [0, {"signal": "width"}], + "nice": true, + "zero": true + }, + { + "name": "y", + "type": "band", + "domain": {"data": "source_0", "field": "variety", "sort": true}, + "range": {"step": {"signal": "y_step"}}, + "paddingInner": 0.1, + "paddingOuter": 0.05 + }, + { + "name": "color", + "type": "ordinal", + "domain": {"data": "source_0", "field": "site", "sort": true}, + "range": "category" + } + ], + "axes": [ + { + "scale": "x", + "orient": "bottom", + "gridScale": "y", + "grid": true, + "tickCount": {"signal": "ceil(width/40)"}, + "domain": false, + "labels": false, + "aria": false, + "maxExtent": 0, + "minExtent": 0, + "ticks": false, + "zindex": 0 + }, + { + "scale": "x", + "orient": "bottom", + "grid": false, + "title": "Sum of yield", + "labelFlush": true, + "labelOverlap": true, + "tickCount": {"signal": "ceil(width/40)"}, + "zindex": 0 + }, + { + "scale": "y", + "orient": "left", + "grid": false, + "title": "variety", + "zindex": 0 + } + ], + "legends": [{"fill": "color", "symbolType": "square", "title": "site"}], + "config": { + "axis": {"labelFont": "monospace", "titleFont": "serif"}, + "legend": {"labelFont": "sans-serif", "titleFont": "serif"}, + "style": {"group-title": {"font": "Caveat"}} + } +} \ No newline at end of file diff --git a/avenger-wgpu/src/lib.rs b/avenger-wgpu/src/lib.rs index 6916c88..393fbad 100644 --- a/avenger-wgpu/src/lib.rs +++ b/avenger-wgpu/src/lib.rs @@ -4,3 +4,4 @@ extern crate lazy_static; pub mod canvas; pub mod error; pub mod marks; +pub use marks::text::register_font_directory; diff --git a/avenger-wgpu/src/marks/text.rs b/avenger-wgpu/src/marks/text.rs index c15f1a0..bcd42d3 100644 --- a/avenger-wgpu/src/marks/text.rs +++ b/avenger-wgpu/src/marks/text.rs @@ -4,6 +4,7 @@ use avenger::marks::text::{ FontStyleSpec, FontWeightNameSpec, FontWeightSpec, TextAlignSpec, TextBaselineSpec, TextMark, }; +use avenger_glyphon::fontdb::Database; use avenger_glyphon::{ Attrs, Buffer, Color, ColorMode, Family, FontSystem, Metrics, Resolution, Shaping, SwashCache, TextArea, TextAtlas, TextBounds, TextRenderer, Weight, @@ -26,6 +27,11 @@ fn build_font_system() -> FontSystem { // Override default families based on what system fonts are available let fontdb = font_system.db_mut(); + setup_default_fonts(fontdb); + font_system +} + +fn setup_default_fonts(fontdb: &mut Database) { let families: HashSet = fontdb .faces() .flat_map(|face| { @@ -69,8 +75,15 @@ fn build_font_system() -> FontSystem { break; } } +} - font_system +pub fn register_font_directory(dir: &str) { + let mut font_system = FONT_SYSTEM + .lock() + .expect("Failed to acquire lock on FONT_SYSTEM"); + let fontdb = font_system.db_mut(); + fontdb.load_fonts_dir(dir); + setup_default_fonts(fontdb); } #[derive(Clone, Debug)] diff --git a/avenger-wgpu/tests/test_image_baselines.rs b/avenger-wgpu/tests/test_image_baselines.rs index 9a2a792..4f1fc03 100644 --- a/avenger-wgpu/tests/test_image_baselines.rs +++ b/avenger-wgpu/tests/test_image_baselines.rs @@ -1,5 +1,23 @@ +use avenger_wgpu::register_font_directory; +use std::path::Path; +use std::sync::Once; + +static INIT: Once = Once::new(); + +pub fn initialize() { + INIT.call_once(|| { + let root_path = Path::new(env!("CARGO_MANIFEST_DIR")); + let fonts_dir = root_path + .join("..") + .join("avenger-vega-test-data") + .join("fonts"); + register_font_directory(fonts_dir.to_str().unwrap()); + }); +} + #[cfg(test)] mod test_image_baselines { + use crate::initialize; use avenger::scene_graph::SceneGraph; use avenger_vega::scene_graph::VegaSceneGraph; use avenger_wgpu::canvas::{Canvas, CanvasDimensions, PngCanvas}; @@ -153,8 +171,11 @@ mod test_image_baselines { case("vl-convert", "seattle-weather", 0.01), case("vl-convert", "stocks_locale", 0.01), case("vl-convert", "table_heatmap", 0.02), + case("vl-convert", "stacked_bar_h", 0.02), )] fn test_image_baseline(category: &str, spec_name: &str, tolerance: f64) { + initialize(); + println!("{spec_name}"); let specs_dir = format!( "{}/../avenger-vega-test-data/vega-scenegraphs/{category}",