Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ of use.
| Worldviews (`countries_<code>.geojson` and `original/countries_<code>.geojson.gz` on [source.coop](https://source.coop/opengeos/data/rustgis/worldviews)), downloaded by the app when one is chosen, not part of it | Natural Earth's Admin 0 Countries (1:10m) and its points of view, with the sample countries' attributes by `scripts/worldviews.py` in [rustgis-assets](https://github.com/opengeos/rustgis-assets): simplified to 1:110m density, or at their original detail | Public domain |
| QGIS screenshot (`qgis-world-atlas.webp` in [rustgis-assets](https://github.com/opengeos/rustgis-assets/tree/main/images)), on the [RustGIS and QGIS](docs/comparison/qgis.md) page | Taken by the RustGIS project: [QGIS](https://qgis.org) 4.2 showing the Natural Earth sample data above | QGIS is GPL-2.0-or-later; the data is public domain |
| QGIS test corpus (`crates/map/testdata/qgis/generated/`: styles, projects and their sample data) | Dominik Strebel ([@pick2510](https://github.com/pick2510)) for the RustGIS project: written by [QGIS](https://qgis.org) 4.2.3 through its API, from `generate.py` there; the data is made up | Apache-2.0 |
| CFF test font (`crates/render/testdata/test-cff.otf`), read only by the PDF font tests | The RustGIS project: generated for this test with [fontTools](https://github.com/fonttools/fonttools) by the script in `crates/render/testdata/README.md`; its glyphs are made up | Apache-2.0 |
| JAXA Earth catalog test copy (`crates/tiles/tests/data/jaxa_catalog.v2.md`), read only by tests | JAXA: the [JAXA Earth API](https://data.earth.jaxa.jp/) dataset catalog ([catalog.v2.md](https://data.earth.jaxa.jp/app/mcp/catalog.v2.md)), copied on 2026-11-08 | JAXA's [terms of use](https://earth.jaxa.jp/en/data/policy/): free to use and redistribute, with credit to JAXA |
| Analysis reference corpus (`crates/analysis/tests/reference/`: layers and expected results) | Written for the RustGIS project from `generate.py` there: the layers are made up; the expected results were computed by [GEOS](https://libgeos.org) 3.13.1 through [Shapely](https://shapely.readthedocs.io) 2.1.2, and distances, buffers, areas and lengths by GeographicLib in [PROJ](https://proj.org) 9.5.1 through [pyproj](https://pyproj4.github.io/pyproj/) 3.7.2, run only to write them (GEOS is LGPL-2.1, Shapely BSD-3-Clause, PROJ and pyproj MIT; none is included in or linked into RustGIS) | Apache-2.0 |

Expand Down
11 changes: 11 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ crs-definitions = { version = "0.6", default-features = false, features = ["proj
base64 = "0.23"
# Deflate for PDF image streams.
miniz_oxide = "0.9"
# Vector PDF text in the faces it is set in: each face embedded as a subset of its glyphs
# (opengeos/RustGIS#1815). Without its variable-font instancing, which brings skrifa and write-fonts.
subsetter = { version = "0.2", default-features = false }
# A face's embedding permissions, names and metrics for its PDF font (already in the tree through
# ab_glyph).
ttf-parser = { version = "0.25", default-features = false, features = ["std"] }
roxmltree = "0.21"
# CityGML: where each city object lies in a document, found without building its tree (already in
# the tree through calamine).
Expand Down
539 changes: 538 additions & 1 deletion THIRD-PARTY-LICENSES.txt

Large diffs are not rendered by default.

558 changes: 548 additions & 10 deletions apps/rustgis-python/THIRD-PARTY-LICENSES.txt

Large diffs are not rendered by default.

47 changes: 39 additions & 8 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn commands() -> Vec<C> {
.params(r#"{"layout"?}"#),
C::new("layout.export", "Export Layout", "Publish › Output", |s, p| super::exports::write_here(s, p, "layout.export")).inputs(layout_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.view()
.params(r#"{"layout"?, "path": "*.png|*.pdf|*.svg" (PNG/SVG: current page; SVG: each element a group of its own; text and shapes as SVG, map frames and surrounds as vectors, rasters and tiles in them as pictures at dpi), "dpi"?: 72..600, "allPages"?: bool (PDF only; default true: every map series page, up to 500; false: the current page), "georeference"?: bool (PDF only; default true: map frames carry their coordinates, a GeoPDF; false: none), "pdf"?: {"layers"?: bool (default true: each element, and in a map frame each layer and its labels, a PDF layer that vector editors open as a layer; false: none)}}"#),
.params(r#"{"layout"?, "path": "*.png|*.pdf|*.svg" (PNG/SVG: current page; SVG: each element a group of its own; text and shapes as SVG, map frames and surrounds as vectors, rasters and tiles in them as pictures at dpi), "dpi"?: 72..600, "allPages"?: bool (PDF only; default true: every map series page, up to 500; false: the current page), "georeference"?: bool (PDF only; default true: map frames carry their coordinates, a GeoPDF; false: none), "pdf"?: {"layers"?: bool (default true: each element, and in a map frame each layer and its labels, a PDF layer that vector editors open as a layer; false: none), "text"?: "fonts" (default: text in its faces, embedded as subsets, editable in a vector editor; a face that can't be is set in outlines, and said)|"outlines" (glyphs as outlines, as print shops ask)}}"#),
C::new("layout.save", "Save Layout File", "Publish › Save As", |s, p| {
let path = ps(p, "path").ok_or("path is required")?;
let l = active(s, p)?.clone();
Expand Down Expand Up @@ -4623,7 +4623,7 @@ pub fn layout_bytes(s: &mut Session, li: usize, pdf: bool, dpi: f64, all: bool)
}

/// [`layout_bytes`], a PDF's map frames georeferenced only when `georeference` (#1191), written
/// as `options` say (its layers, #1815). Returns an actionable error if a linked archive changes
/// as `options` say (its layers and text, #1815). Returns an actionable error if a linked archive changes
/// while the pages are drawn.
pub fn layout_bytes_with(
s: &mut Session,
Expand Down Expand Up @@ -4757,7 +4757,30 @@ fn layout_bytes_inner(
let (pages, png) = result?;
pictured_notices(s, &frames_pictured, &pages_pictured);
georeference_notices(s, &left_out, &by_corners, pages.len());
if pdf { Ok(rustgis_render::pdf::write_with(&pages, &saved.name, options)) } else { png.ok_or_else(|| "nothing to draw".to_string()) }
if !pdf {
return png.ok_or_else(|| "nothing to draw".to_string());
}
let (bytes, outlined) = rustgis_render::pdf::write_with(&pages, &saved.name, options);
outlined_notice(s, &outlined);
Ok(bytes)
}

/// Says which faces a PDF set in outlines though its text was to be in fonts (#1815), with why:
/// their text is drawings, not text, in a vector editor. One notice, the faces counted.
pub(crate) fn outlined_notice(s: &mut Session, outlined: &[rustgis_render::pdf::Outlined]) {
let n = outlined.len();
if n == 0 {
return;
}
let mut each: Vec<String> = outlined.iter().take(10).map(|o| format!("{} ({})", o.face, o.why)).collect();
if n > 10 {
each.push(format!("and {} more", n - 10));
}
s.warn(format!(
"The PDF sets the text of {n} face{} as outlines, not as text a vector editor can edit: {}",
if n == 1 { "" } else { "s" },
each.join(", ")
));
}

/// Says which map frames a PDF doesn't georeference, with why, and which it georeferences by their
Expand Down Expand Up @@ -4874,15 +4897,17 @@ pub(crate) fn pictured_notices(s: &mut Session, frames: &[(u32, String)], pages:
}

/// The keys `layout.export`'s `"pdf"` takes.
const PDF_KEYS: &[&str] = &["layers"];
const PDF_KEYS: &[&str] = &["layers", "text"];

/// How `layout.export`'s `"pdf": {…}` asks a PDF to be written: with its layers unless
/// `"layers": false` (#1815). A key it doesn't know is refused, with the keys it takes.
/// How `layout.export`'s `"pdf": {…}` asks a PDF to be written (#1815): with its layers unless
/// `"layers": false`, its text in its fonts unless `"text": "outlines"`. It is checked whatever
/// the export writes, a PNG or SVG too, so a script's mistake shows on its first run; a key it
/// doesn't know is refused, with the keys it takes.
fn pdf_options(p: &Value) -> Result<rustgis_render::pdf::Options, String> {
use rustgis_render::pdf::Text;
let mut options = rustgis_render::pdf::Options::default();
let Some(pdf) = p.get("pdf").filter(|v| !v.is_null()) else { return Ok(options) };
let Some(pdf) = pdf.as_object() else { return Err(r#"pdf is an object: {"layers": true|false}"#.into()) };
// A key it doesn't know (a typo) is refused, not left to change nothing unsaid.
let Some(pdf) = pdf.as_object() else { return Err(r#"pdf is an object: {"layers": true|false, "text": "fonts"|"outlines"}"#.into()) };
if let Some(key) = pdf.keys().find(|k| !PDF_KEYS.contains(&k.as_str())) {
return Err(format!("pdf has no key \"{key}\": its keys are {}", PDF_KEYS.join(", ")));
}
Expand All @@ -4891,6 +4916,12 @@ fn pdf_options(p: &Value) -> Result<rustgis_render::pdf::Options, String> {
Some(Value::Bool(on)) => options.layers = *on,
Some(_) => return Err("pdf.layers is true or false".into()),
}
options.text = match pdf.get("text") {
None | Some(Value::Null) => Text::Fonts,
Some(v) if v == "fonts" => Text::Fonts,
Some(v) if v == "outlines" => Text::Outlines,
Some(_) => return Err(r#"pdf.text is "fonts" or "outlines""#.into()),
};
Ok(options)
}

Expand Down
92 changes: 90 additions & 2 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9712,9 +9712,9 @@ fn layouts_compose_export_and_round_trip() {
let pdf = std::fs::read(&pdf_path).unwrap();
let count = format!("/Count {pages}");
assert!(pdf.windows(count.len()).any(|w| w == count.as_bytes()), "one PDF page per series page");
// Kept as vectors: its text in outline fonts, no page a picture, and nothing too large.
// Kept as vectors: its text in its fonts (#1815), no page a picture, and nothing too large.
let has = |needle: &[u8]| pdf.windows(needle.len()).any(|w| w == needle);
assert!(has(b"/Subtype /Type3") && has(b"/ToUnicode") && has(b"/Contents"));
assert!(has(b"/Subtype /Type0") && has(b"/ToUnicode") && has(b"/Contents"));
assert!(!has(b"/Im0 Do"), "no page is one picture");
assert!(!s.notices_since(mark).iter().any(|n| n.text.contains("as pictures, not vectors")));
assert_eq!(s.project.layouts[0].series.as_ref().unwrap().page, 1, "the shown page is restored");
Expand Down Expand Up @@ -38313,6 +38313,35 @@ fn must_be_covered_by_says_which_polygons_it_left_out_at_a_pole() {
}
}

/// The faces a PDF sets in outlines though fonts were asked for (#1815) are said in one notice:
/// none, nothing said; one face, singular; more, plural; past ten, the first ten and how many more.
#[test]
fn a_pdf_says_which_faces_it_sets_in_outlines() {
let mut s = Session::new(Project::default());
let faces = |n: usize| -> Vec<rustgis_render::pdf::Outlined> {
(1..=n).map(|i| rustgis_render::pdf::Outlined { face: format!("Face {i}"), why: "its licence forbids embedding".into() }).collect()
};
let said = |s: &mut Session, n: usize| {
let mark = s.notice_mark();
crate::cmd::layout::outlined_notice(s, &faces(n));
s.notices_since(mark).iter().map(|n| n.text.clone()).collect::<Vec<_>>()
};
assert!(said(&mut s, 0).is_empty(), "every face embedded, nothing said");
let lead = "The PDF sets the text of";
let tail = "as outlines, not as text a vector editor can edit:";
assert_eq!(said(&mut s, 1), [format!("{lead} 1 face {tail} Face 1 (its licence forbids embedding)")]);
let two = said(&mut s, 2);
assert_eq!(two.len(), 1, "one notice");
assert!(
two[0].starts_with(&format!("{lead} 2 faces {tail} Face 1 (")) && two[0].ends_with(", Face 2 (its licence forbids embedding)"),
"{two:?}"
);
let eleven = said(&mut s, 11);
assert_eq!(eleven.len(), 1, "one notice");
assert!(eleven[0].starts_with(&format!("{lead} 11 faces {tail}")), "{eleven:?}");
assert!(eleven[0].contains("Face 10 (") && !eleven[0].contains("Face 11") && eleven[0].ends_with(", and 1 more"), "{eleven:?}");
}

#[test]
fn a_pdf_says_which_frames_and_pages_it_draws_as_pictures() {
let mut s = Session::new(Project::default());
Expand All @@ -38338,6 +38367,65 @@ fn a_pdf_says_which_frames_and_pages_it_draws_as_pictures() {
);
}

/// A layout's PDF sets its text in its faces, embedded as subsets (#1815): a layout text and a
/// map's labels come out as Type 0 fonts over CID fonts, their text read back through each font's
/// map; `"pdf": {"text": "outlines"}` keeps the Type 3 outlines, and anything else is refused.
#[test]
fn a_layout_pdf_sets_its_text_in_its_fonts() {
let mut s = world();
s.run("labels.field", &json!({"layer": "Countries", "field": "name"})).unwrap();
s.run("layout.new", &json!({"page": "a4", "orientation": "landscape", "template": "map"})).unwrap();
s.run("layout.addElement", &json!({"kind": "text", "text": "Ocupação do solo"})).unwrap();
let path = std::env::temp_dir().join(format!("rustgis-fonts-{}.pdf", std::process::id()));
// Removed however the test ends.
struct Removed(std::path::PathBuf);
impl Drop for Removed {
fn drop(&mut self) {
let _ = std::fs::remove_file(&self.0);
}
}
let _removed = Removed(path.clone());
let export = |s: &mut Session, p: Value| {
let mark = s.notice_mark();
let mut p = p;
p["path"] = json!(path);
p["dpi"] = json!(72);
s.run("layout.export", &p).map(|_| {
let said: Vec<String> = s.notices_since(mark).iter().map(|n| n.text.clone()).collect();
(String::from_utf8_lossy(&std::fs::read(&path).unwrap()).into_owned(), said)
})
};
let (pdf, said) = export(&mut s, json!({})).unwrap();
assert!(pdf.contains("/Subtype /Type0") && pdf.contains("/Encoding /Identity-H"), "{said:?}");
assert!(pdf.contains("/Subtype /CIDFontType2") || pdf.contains("/Subtype /CIDFontType0"));
assert!(!pdf.contains("/Subtype /Type3"), "every face embedded: {said:?}");
assert!(!said.iter().any(|t| t.contains("as outlines")), "{said:?}");
// The text read back: the title's and the labels' characters are in the fonts' maps.
let raw = std::fs::read(&path).unwrap();
let maps: String = raw
.windows(8)
.enumerate()
.filter(|(_, w)| w == b"\nstream\n")
.filter_map(|(i, _)| miniz_oxide::inflate::decompress_to_vec_zlib(&raw[i + 8..]).ok())
.map(|d| String::from_utf8_lossy(&d).into_owned())
.filter(|d| d.contains("<0000> <FFFF>"))
.collect();
for ch in ['O', 'ç', 'ã'] {
assert!(maps.contains(&format!("> <{:04X}>", ch as u32)), "{ch}");
}
let (outlines, said) = export(&mut s, json!({"pdf": {"text": "outlines"}})).unwrap();
assert!(outlines.contains("/Subtype /Type3") && !outlines.contains("/Type0"), "{said:?}");
export(&mut s, json!({"pdf": {"text": "fonts"}})).unwrap();
assert!(std::fs::read(&path).unwrap() == raw, "\"fonts\" is the default, byte for byte");
for bad in
[json!({"pdf": {"text": "curves"}}), json!({"pdf": "outlines"}), json!({"pdf": {"text": 1}}), json!({"pdf": {"txt": "outlines"}})]
{
let err = export(&mut s, bad.clone()).unwrap_err();
let said = ["\"fonts\" or \"outlines\"", "fonts\"|\"outlines", "pdf has no key \"txt\": its keys are layers, text"];
assert!(said.iter().any(|s| err.contains(s)), "{bad}: {err}");
}
}

/// A layout's PDF has layers (#1815): each element an optional content group named after it,
/// its map frame's map layers and their labels inside the frame's; the GeoPDF viewports stay.
/// `"pdf": {"layers": false}` leaves them out, a bad value is refused, and a layout with no map
Expand Down
2 changes: 2 additions & 0 deletions crates/render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ base64 = { workspace = true }
web-time = { workspace = true }
serde_json = { workspace = true }
miniz_oxide = { workspace = true }
subsetter = { workspace = true }
ttf-parser = { workspace = true }
rustgis-tiles = { workspace = true }

[dev-dependencies]
Expand Down
Loading
Loading