Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Hyphenate Greek (#1008)

Hamza76d0560ff839
diff --git a/NOTICE b/NOTICE
index 5e37b0d72..f4e3184f6 100644
--- a/NOTICE
+++ b/NOTICE
@@ -52,6 +52,22 @@ list (author, source, license) is in ASSETS.md.
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+- Greek hyphenation patterns, embedded through the hypher crate (feature "greek"):
+ hyph-el-monoton.tex 5.0 from hyph-utf8, https://github.com/hyphenation/tex-hyphen (patterns for
+ Modern Greek, monotonic spelling; hypher maps the language code "el" to these).
+ Copyright (C) 2008-2011 Dimitrios Filippou. Available under the LPPL or the MIT License; taken
+ here under the MIT License: Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ The above copyright notice and this permission notice shall be included in all copies or
+ substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
- Norwegian hyphenation patterns, embedded through the hypher crate (feature "norwegian"):
hyph-no.tex from hyph-utf8, https://github.com/hyphenation/tex-hyphen.
Copyright (C) Rune Kleveland and Ole Michael Selberg. Copying and distribution of this file,
diff --git a/crates/compose/Cargo.toml b/crates/compose/Cargo.toml
index cc1b6701d..0dab3183e 100644
--- a/crates/compose/Cargo.toml
+++ b/crates/compose/Cargo.toml
@@ -19,7 +19,7 @@ designcraft-fonts = { workspace = true }
log = { workspace = true }
regex = { workspace = true }
miniz_oxide = "0.8"
-hypher = { version = "0.1.8", default-features = false, features = ["alloc", "portuguese", "spanish", "norwegian"] }
+hypher = { version = "0.1.8", default-features = false, features = ["alloc", "greek", "portuguese", "spanish", "norwegian"] }
[dev-dependencies]
designcraft-fonts = { workspace = true, features = ["testing"] }
diff --git a/crates/compose/src/hyphen/mod.rs b/crates/compose/src/hyphen/mod.rs
index ae5997e52..57b75d63b 100644
--- a/crates/compose/src/hyphen/mod.rs
+++ b/crates/compose/src/hyphen/mod.rs
@@ -2,7 +2,10 @@
//! Liang patterns compiled into `hypher`, one cargo feature per language: Spanish is Javier Bezos's
//! `hyph-es.tex` 5.0 from hyph-utf8, MIT; Portuguese is `hyph-pt.tex` 1.4 from hyph-utf8 (Pedro J.
//! de Rezende, J. Joao Dias Almeida, Leonardo Araujo, Aline Benevides), BSD-3-Clause; Norwegian is
-//! `hyph-no.tex` from hyph-utf8 (Rune Kleveland, Ole Michael Selberg), permissive (see NOTICE).
+//! `hyph-no.tex` from hyph-utf8 (Rune Kleveland, Ole Michael Selberg), permissive (see NOTICE);
+//! Greek is `hyph-el-monoton.tex` 5.0 from hyph-utf8 (Dimitrios Filippou), LPPL or MIT, taken
+//! under MIT. Those are the **monotonic** patterns, which is what `hypher` maps `el` to, so
+//! polytonic text hyphenates by them as well.
//!
//! English lookup order for each word:
//! 1. the **dictionary** ([`Dictionary::en_us`]) — the public-domain Moby Hyphenator II word list
diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs
index 97eeb8cd4..6be1509ee 100644
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@ -4454,3 +4454,33 @@ fn an_empty_last_paragraph_isnt_overset() {
let (d, sid, _) = doc_with("One\nTwo\n\n", Rect::new(0.0, 0.0, 200.0, 35.0), ParaAttrs::default());
assert!(compose_story(&d, sid, &ComposeOptions::default()).is_overset(), "an empty paragraph before the last one is text");
}
+
+#[test]
+fn greek_text_gets_greek_hyphenation() {
+ // Greek had no hyphenation at all: `hypher`'s Greek patterns were not among the features
+ // the crate asks for, so `Lang::for_language` found nothing and Greek text set unhyphenated
+ // however narrow the column (#1008).
+ let text = "δημοκρατια ανθρωπος πολιτισμος δημοκρατια ανθρωπος πολιτισμος";
+ let (mut d, sid, _) = doc_with(text, Rect::new(36.0, 36.0, 76.0, 700.0), ParaAttrs::default());
+ let st = d.story_mut(sid).unwrap();
+ let n = st.len();
+ st.format_chars(0..n, |f| f.over.language = Some("Greek".into()));
+ let cs = compose_story(&d, sid, &ComposeOptions::default());
+ let breaks: Vec<&str> = all_lines(&cs).into_iter().filter(|l| l.hyphenated).map(|l| text[l.range.clone()].trim_end()).collect();
+ assert!(!breaks.is_empty(), "Greek text is hyphenated");
+ // Every break the composer took is a break the patterns give for that word.
+ for b in breaks {
+ let tail = b.rsplit(' ').next().unwrap_or(b);
+ let whole = text[text.find(b).unwrap() + b.len() - tail.len()..].split(|c: char| !c.is_alphabetic()).next().unwrap_or("");
+ let el = hyphen::Lang::for_language("Greek").unwrap();
+ let pts = hyphen::hyphen_points_in(whole, &hyphen::Limits::default(), el);
+ assert!(pts.contains(&tail.chars().count()), "break {tail}- in {whole} is a hyph-el point");
+ }
+ // The language is reached by name and by tag, as the other languages are.
+ for name in ["Greek", "Greek: Greece", "el", "el-GR"] {
+ assert!(hyphen::Lang::for_language(name).is_some(), "{name} has hyphenation");
+ }
+ // αν-θρω-πος, the syllables hyph-el gives.
+ let el = hyphen::Lang::for_language("Greek").unwrap();
+ assert_eq!(hyphen::hyphen_points_in("ανθρωπος", &hyphen::Limits::default(), el), vec![2, 5]);
+}
diff --git a/docs/gaps.md b/docs/gaps.md
index 21a18b369..7a82f923d 100644
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@ -131,7 +131,7 @@ Kind: **F** feature · **U** UI/UX · **T** typography · **FF** file format ·
- **Estimate:** 25–40 h.
### 13. Hyphenation and spelling languages (T, L)
-- **Missing:** hyphenation patterns for every language but English, Spanish, Portuguese and Norwegian; spelling for
+- **Missing:** hyphenation patterns for every language but English, Spanish, Portuguese, Norwegian and Greek; spelling for
every language but English. InDesign ships dictionaries for ~40 languages.
- **Estimate:** 30–60 h (permissively licensed patterns exist for most; spelling word lists need
licence review). **Doc:** [typography-parity.md](typography-parity.md)
diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md
index 62ba7f08a..fa8afbc23 100644
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@ -59,7 +59,7 @@ they receive, setting type exactly, and basic editing that never fails.
| Dimension | Weight | Ready | Remaining (Opus 5.5 h) | Evidence | Doc |
|---|---|---|---|---|---|
| Features (depth of each area) | 25% | 55% | 250–400 | 275 catalogue rows exist; many lack options (e.g. Books is 258 lines of engine code, Liquid Layout 329); see the area table | this file |
-| Typography and composition fidelity | 15% | 45% | 120–200 | Knuth–Plass composer, keeps, grids, CJK, Arabic all exist; no comparison with InDesign's line breaks; optical kerning falls back to metrics (#181); overset rule differs (#180); hyphenation patterns for English, Spanish, Portuguese and Norwegian only | [typography-parity.md](typography-parity.md) |
+| Typography and composition fidelity | 15% | 45% | 120–200 | Knuth–Plass composer, keeps, grids, CJK, Arabic all exist; no comparison with InDesign's line breaks; optical kerning falls back to metrics (#181); overset rule differs (#180); hyphenation patterns for English, Spanish, Portuguese, Norwegian and Greek only | [typography-parity.md](typography-parity.md) |
| File formats | 20% | 40% | 150–250 (+20–60 for INDD integration) | INDD cannot be opened (#21); IDML both ways and verified in InDesign 2026, but real-file bugs open (#193, #338, #339, #340); PDF export strong; PDF/X-4 only | [file-format-parity.md](file-format-parity.md) |
| UI/UX fidelity | 15% | 45% | 120–180 | Measured InDesign 2026 look; but users report object copy/paste (#351, #348, #185, #164), right-click menus (#238, #187, #160), out-port threading (#352, #194, #165), canvas IME (#322) failing | [ui-parity.md](ui-parity.md) |
| Stability | 10% | 45% | 60–100 | Never-crash rules and last-resort guards; startup failures on some GPUs and machines (#334, #273, #220, #192, #167, #166); no CI runs the tests on pull requests | [gaps.md](gaps.md) |
diff --git a/docs/typography-parity.md b/docs/typography-parity.md
index 0c63d206e..72ee327f2 100644
--- a/docs/typography-parity.md
+++ b/docs/typography-parity.md
@@ -36,7 +36,7 @@ Fidelity: **unmeasured** unless stated.
| Single-line Composer | greedy | greedy with the same ranges | ✓ | |
| World-Ready composers | Paragraph / Single-line World-Ready | RTL, Arabic and bidi in the main composer | ~ | Indic scripts (Devanagari etc.) shape through harfrust but are untested |
| Justification | word/letter spacing, glyph scaling min/desired/max, single-word, last line | all of these | ✓ | a justified line with a tab now justifies after the tab (#284) |
-| Hyphenation | per-language dictionaries (~40), zone, limits, capitalized, last word, across columns | Liang patterns: English (trained from the public-domain Moby list), Spanish (Bezos), Portuguese (hyph-pt) and Norwegian (hyph-no); zone, limits, exceptions in the user dictionary | ~ | other languages don't hyphenate (#87 reported "doesn't work") |
+| Hyphenation | per-language dictionaries (~40), zone, limits, capitalized, last word, across columns | Liang patterns: English (trained from the public-domain Moby list), Spanish (Bezos), Portuguese (hyph-pt), Norwegian (hyph-no) and Greek (hyph-el-monoton); zone, limits, exceptions in the user dictionary | ~ | other languages don't hyphenate (#87 reported "doesn't work") |
| Spelling | per-language dictionaries | English (Moby) + document/user dictionary | ~ | |
| Kerning | Metrics, Optical, manual, none | Metrics, manual, none | ~ | **Optical treated as Metrics** (#181): imported display text sets wider and can overset |
| Tracking, scale, skew, baseline shift | ✓ | ✓ | ✓ | |