mirror of
https://github.com/storytold/designcraft.git
synced 2026-12-02 20:21:15 -05:00
Merge pull request #1157
This commit is contained in:
commit
6de70c4587
5 files changed
+31
-14
No files matched your search
@@ -207,6 +207,10 @@ impl FontDb {
|
||||
/// The box drawn for `face`'s missing glyph (.notdef) when the font's own has no outline, in
|
||||
/// font units, y-down: a hollow rectangle across the glyph's advance, cap height tall. `None`
|
||||
/// when the font draws its own.
|
||||
///
|
||||
/// Contract: `Some` means exactly that the font's .notdef (glyph 0) has an empty outline, so
|
||||
/// callers may test `missing_box(face).is_some()` for "this font's .notdef is empty" (PDF export
|
||||
/// prints such a glyph as nothing, while [`FontDb::outline`] and the screen show this box).
|
||||
pub fn missing_box(&self, face: &FontFace) -> Option<BezPath> {
|
||||
if !font_outline(face, 0).elements().is_empty() {
|
||||
return None;
|
||||
|
||||
+15
-11
@@ -522,7 +522,7 @@ fn archival_exports_keep_placed_images_without_interpolation() {
|
||||
}
|
||||
|
||||
/// What a page draws: each glyph (its text and outline bounds) and each filled path's bounds.
|
||||
fn drawn(bytes: &[u8]) -> (Vec<(String, kurbo::Rect)>, Vec<kurbo::Rect>) {
|
||||
fn drawn(bytes: &[u8]) -> (Vec<(String, kurbo::Point)>, Vec<kurbo::Rect>) {
|
||||
use hayro_interpret::font::Glyph;
|
||||
use hayro_interpret::{
|
||||
BlendMode, ClipPath, Context, Device, GlyphDrawMode, Image, InterpreterCache, InterpreterSettings, Paint, PathDrawMode, SoftMask,
|
||||
@@ -530,7 +530,7 @@ fn drawn(bytes: &[u8]) -> (Vec<(String, kurbo::Rect)>, Vec<kurbo::Rect>) {
|
||||
};
|
||||
use kurbo::Shape as _;
|
||||
#[derive(Default)]
|
||||
struct Rec(Vec<(String, kurbo::Rect)>, Vec<kurbo::Rect>);
|
||||
struct Rec(Vec<(String, kurbo::Point)>, Vec<kurbo::Rect>);
|
||||
impl Device<'_> for Rec {
|
||||
fn set_soft_mask(&mut self, _: Option<SoftMask<'_>>) {}
|
||||
fn set_blend_mode(&mut self, _: BlendMode) {}
|
||||
@@ -539,17 +539,13 @@ fn drawn(bytes: &[u8]) -> (Vec<(String, kurbo::Rect)>, Vec<kurbo::Rect>) {
|
||||
}
|
||||
fn push_clip_path(&mut self, _: &ClipPath) {}
|
||||
fn push_transparency_group(&mut self, _: f32, _: Option<SoftMask<'_>>, _: BlendMode) {}
|
||||
fn draw_glyph(&mut self, g: &Glyph<'_>, _: kurbo::Affine, _: kurbo::Affine, _: &Paint<'_>, _: &GlyphDrawMode) {
|
||||
fn draw_glyph(&mut self, g: &Glyph<'_>, xf: kurbo::Affine, glyph_xf: kurbo::Affine, _: &Paint<'_>, _: &GlyphDrawMode) {
|
||||
let text = match g.as_unicode() {
|
||||
Some(hayro_cmap::BfString::Char(c)) => c.to_string(),
|
||||
Some(hayro_cmap::BfString::String(s)) => s,
|
||||
None => String::new(),
|
||||
};
|
||||
let bounds = match g {
|
||||
Glyph::Outline(o) => o.outline().bounding_box(),
|
||||
Glyph::Type3(_) => kurbo::Rect::ZERO,
|
||||
};
|
||||
self.0.push((text, bounds));
|
||||
self.0.push((text, xf * glyph_xf * kurbo::Point::ORIGIN));
|
||||
}
|
||||
fn draw_image(&mut self, _: Image<'_, '_>, _: kurbo::Affine) {}
|
||||
fn pop_clip_path(&mut self) {}
|
||||
@@ -667,7 +663,7 @@ fn pdfa_leaves_out_form_fields_added_after_validation() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_glyphs_print_as_boxes() {
|
||||
fn missing_glyphs_print_as_the_fonts_notdef() {
|
||||
// Source Serif 4 lacks 語: its .notdef box is drawn as a path, not as a .notdef glyph
|
||||
// (which PDF/A and PDF/UA forbid).
|
||||
let boxes = |paths: &[kurbo::Rect]| paths.iter().filter(|r| r.width() > 1.0 && r.width() < 12.0 && r.height() > 3.0 && r.height() < 12.0).count();
|
||||
@@ -678,7 +674,7 @@ fn missing_glyphs_print_as_boxes() {
|
||||
assert_eq!(boxes(&paths), 1, "{paths:?}");
|
||||
let a = export_pdf_with_report(&d, &Cache::new(), &PdfOptions { standard: Standard::PdfA2b, ..Default::default() });
|
||||
assert!(a.is_ok(), "PDF/A takes the box: {:?}", a.err());
|
||||
// A font whose .notdef is empty: the box DesignCraft draws for it.
|
||||
// A font whose .notdef is empty prints nothing there, as InDesign exports it.
|
||||
const FAMILY: &str = "DC Test PDF Empty Notdef";
|
||||
let font = designcraft_fonts::testing::font_mapping(FAMILY, &[('a', 'a'), ('b', 'b')]).unwrap();
|
||||
designcraft_fonts::FontDb::global().add_font(designcraft_fonts::testing::with_empty_notdef(font).unwrap());
|
||||
@@ -687,7 +683,15 @@ fn missing_glyphs_print_as_boxes() {
|
||||
d.story_mut(sid).unwrap().format_chars(0.."a語b".len(), |f| f.over.font_family = Some(FAMILY.into()));
|
||||
let (glyphs, paths) = drawn(&export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap());
|
||||
assert_eq!(glyphs.iter().map(|g| g.0.as_str()).collect::<Vec<_>>(), ["a", "b"], "{glyphs:?}");
|
||||
assert_eq!(boxes(&paths), 1, "{paths:?}");
|
||||
assert_eq!(boxes(&paths), 0, "{paths:?}");
|
||||
// The empty .notdef still takes its advance: `b` stays where the layout puts it.
|
||||
let cs = designcraft_compose::compose_story(&d, sid, &designcraft_compose::ComposeOptions::default());
|
||||
let line = &cs.frames[0].lines[0];
|
||||
let x = |c: char| line.glyphs.iter().find(|g| g.rendered_char == c).unwrap().x;
|
||||
let notdef = line.glyphs.iter().find(|g| g.gid == 0).unwrap();
|
||||
assert!(notdef.adv > 0.0 && x('b') - x('a') > notdef.adv, "the .notdef has an advance");
|
||||
let pdf_gap = glyphs[1].1.x - glyphs[0].1.x;
|
||||
assert!((pdf_gap - (x('b') - x('a'))).abs() < 0.01, "pdf {pdf_gap}, layout {}", x('b') - x('a'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+10
-1
@@ -562,7 +562,8 @@ impl Exporter<'_> {
|
||||
} else {
|
||||
stroke
|
||||
};
|
||||
// A missing glyph is drawn as its box: PDF/A and PDF/UA forbid showing .notdef as text.
|
||||
// A missing glyph is drawn as the font's .notdef outline: PDF/A and PDF/UA forbid showing
|
||||
// .notdef as text.
|
||||
if g0.gid == 0 {
|
||||
self.paint_outlines(s, &glyph_outlines(glyphs, size, tan), origin, fill, stroke, weight);
|
||||
} else if let Some(font) = self.font(&face) {
|
||||
@@ -691,6 +692,14 @@ fn glyph_outlines(glyphs: &[PlacedGlyph], size: f64, tan: f64) -> BezPath {
|
||||
let Some(g0) = glyphs.first() else { return bp };
|
||||
let k = size / g0.face.upem;
|
||||
for g in glyphs {
|
||||
// A .notdef the font leaves empty prints as nothing, as InDesign exports it (the screen
|
||||
// shows a box, and Preflight lists the character). `missing_box` is `Some` exactly when
|
||||
// the font's .notdef is empty. Only PDF text painting calls this function: outline
|
||||
// conversion and the screen still get the box from `FontDb::outline`. The glyphs after it
|
||||
// keep their places: each is placed from its own position.
|
||||
if g.gid == 0 && db.missing_box(&g.face).is_some() {
|
||||
continue;
|
||||
}
|
||||
let dy = g.y - g0.y;
|
||||
let a = Affine::translate(((g.x - g0.x + tan * dy) / (g0.sx / g0.sy), dy)) * Affine::scale(k);
|
||||
let mut o = (*db.outline(&g.face, g.gid)).clone();
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ presets or tables are copied. Our default mojikumi and kinsoku tables are built
|
||||
| Grid alignment | against the baseline grid: roman baseline, em box top / centre / bottom, ICF top / bottom; first line only; gyoudori (auto or N grid lines) and paragraph gyoudori (`type.gridSettings`, IDML `GridAlignment`, `GridGyoudori`, `ParagraphGyoudori`). No frame grid; vertical frames have no baseline grid |
|
||||
| Composite fonts | done: model, `style.compositeFont.*`, shaping, IDML, font list, replace and Preflight; no dialog |
|
||||
| Languages | Japanese, Korean, Simplified and Traditional Chinese reach the shaper (`locl`), font fallback, line breaking and typographer's quotes; IDML language names are kept as written; locale codes (`ja_JP`, `ko-KR`, `de_DE_2006`) are their language and region, and Chinese is also recognised in its common spellings ("Simplified Chinese", "Chinese (Traditional)", `zh_CN`, `zh-Hant`) |
|
||||
| Missing glyphs | as in InDesign: characters the applied font lacks are drawn as its missing-glyph box (screen and PDF) and listed by Preflight; the document setting Draw Missing Glyphs from Fallback Fonts (Preferences › Composition, off in new documents and IDML imports, on in documents saved before it existed) draws them from fallback fonts instead |
|
||||
| Missing glyphs | as in InDesign: characters the applied font lacks are drawn as its missing-glyph box (screen and PDF; an empty one shows as a drawn box on screen and prints as nothing) and listed by Preflight; the document setting Draw Missing Glyphs from Fallback Fonts (Preferences › Composition, off in new documents and IDML imports, on in documents saved before it existed) draws them from fallback fonts instead |
|
||||
| Font menus | Western families first, then Japanese, Simplified Chinese, Traditional Chinese and Korean groups (from the font's `meta` languages, CJK family names, OS/2 code pages, else its coverage); CJK families under their native names unless Preferences › Type › Show Font Names in English; the order is recalled from InDesign, not observed |
|
||||
| CJK fonts | Japanese faces (Shippori Mincho first) from the optional craft-fonts build input, in the font menus for users to apply; fallback by language (with fallback fonts on) (Japanese: the craft-fonts faces, then system fonts; Simplified and Traditional Chinese, Korean: system fonts); document fonts: the fonts of a `Document Fonts` folder beside an opened file belong to that document (composition, export, font menus), ahead of installed fonts of the same name, and are forgotten when it closes; Package copies every font file that draws text, fallback fonts included (licence permitting). Font files stay in memory for the session (reopening a document reuses them) and aren't read on the web |
|
||||
| Interface | Preferences › Type › Show CJK Features (`cjkFeatures`; until set, on for a Japanese, Chinese or Korean interface) shows the CJK-only menu items (Type › Tate-Chu-Yoko, Ruby…, Kenten, Warichu); layout, IDML and commands work either way |
|
||||
|
||||
@@ -295,7 +295,7 @@ It is evidence of breadth: each item exists. It is not a claim of InDesign-level
|
||||
- Links panel: every placed graphic with status (OK / Modified / Missing / Embedded, checked against the file on disk), page and effective PPI (low resolution flagged); Relink…, Go To, Update, Embed; `links.*` commands.
|
||||
- Linked text files: `file.place {link: true}` or Preferences › File Handling › Create Links When Placing Text Files keeps a placed .docx/.rtf/.txt story linked to its file (path, size and hash, and the style map and conflict option used). The Links panel shows it OK / Modified / Missing; Update imports the file again into the same frames and thread with the saved style map, replacing edits made in the layout (the Links panel and menu ask first; the `links.update` command updates and returns a warning; undoable); Relink, Go To and Unlink. Saved in the native format; IDML exports the text unlinked.
|
||||
- Missing fonts: highlighted pink on screen (never in output), listed by Preflight; Type › Find/Replace Font (fonts in the document, missing first; replace in text, cells, footnotes and styles); `font.list` (with each face's OS/2 `fsType` embedding bits) / `font.replace`. Type › Reload Fonts (`font.reload`) scans the font folders again and reads again the installed font files edited or removed since they were read, then recomposes the open documents: a font installed or edited while DesignCraft runs needs no restart (#328, #547). InDesign notices such changes by itself.
|
||||
- Missing glyphs, as in InDesign: a character the applied font lacks is drawn as that font's missing-glyph box (its .notdef; a drawn box when the font's is empty), on screen and in PDF (as a path, so PDF/A and PDF/UA exports take it), and Preflight lists the characters by font. Preferences › Composition › Draw Missing Glyphs from Fallback Fonts (`document.preferences {glyphFallback}`, stored with the document) draws them from other fonts instead; it is off in new documents and IDML imports, on in documents saved before it existed. A missing font's substitute always uses fallback fonts.
|
||||
- Missing glyphs, as in InDesign: a character the applied font lacks is drawn as that font's missing-glyph box (its .notdef, as a path in PDF, so PDF/A and PDF/UA exports take it); when the font's .notdef is empty the screen shows a drawn box and the PDF, as InDesign's, nothing, and Preflight lists the characters by font. Preferences › Composition › Draw Missing Glyphs from Fallback Fonts (`document.preferences {glyphFallback}`, stored with the document) draws them from other fonts instead; it is off in new documents and IDML imports, on in documents saved before it existed. A missing font's substitute always uses fallback fonts.
|
||||
- Damage-region repaint: after an edit the canvas re-renders only the frames whose composed text (or the items that) changed and patches its texture — pixel-identical to a full render; typing in a frame repaints in under a millisecond instead of a full-viewport render (22 ms measured on the sample).
|
||||
- Native engine saves, Save a Copy, snippets, books, libraries, swatches and engine/MCP exports use same-folder atomic replacement through craft-libs/craft-atomic, as do desktop Services writes and CLI raster exports. Failed writes before replacement retain the original, and already-open readers retain the old bytes. On Unix a new file gets the permissions ordinary file creation gives it (the umask applies) and a replaced file keeps its permissions. Parent-folder flushing is best effort, so this is not a power-loss durability guarantee.
|
||||
- Save As prepares destination-relative data-source paths before writing and installs them only after a successful save. Failed Save As retains the document, saved state and history; Save a Copy rebases only the saved copy. Library and book collection edits likewise update live values only after persistence succeeds.
|
||||
|
||||
Reference in new issue
Block a user