mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 15:26:12 +00:00
PSD: type in a language other than English: USA or set with a Standard composer stays pixels
A type layer records neither the language nor the composer, so point type whose runs name another language, or whose paragraphs use a Standard composer, is written as pixels. New type's default paragraph settings (the every-line composer, Burasagari and Mojikumi) no longer keep it from becoming a type layer; Mojikumi other than the default still does in type with Chinese, Japanese or Korean characters.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
use vectorcraft_color::Paint;
|
||||
use vectorcraft_doc::text::TypeAntiAlias;
|
||||
use vectorcraft_doc::{CharStyle, Justify, Node, NodeKind, ParaStyle, TextKind, TextObject};
|
||||
use vectorcraft_doc::{CharStyle, Composer, Justify, Node, NodeKind, ParaStyle, TextKind, TextObject};
|
||||
use vectorcraft_geom::{Affine, Point, Rect};
|
||||
|
||||
/// Point type that a type layer draws as `n` draws: horizontal or vertical point type with text,
|
||||
@@ -18,6 +18,8 @@ use vectorcraft_geom::{Affine, Point, Rect};
|
||||
pub(super) fn editable(n: &Node) -> Option<&TextObject> {
|
||||
let NodeKind::Text(t) = &n.kind else { return None };
|
||||
let text = t.plain_text();
|
||||
let has_cjk = text.chars().any(cjk);
|
||||
let flat = |p: &ParaStyle| flat(p, has_cjk);
|
||||
let plain = matches!(t.kind, TextKind::Point)
|
||||
&& !text.is_empty()
|
||||
&& !t.system_layout
|
||||
@@ -56,29 +58,46 @@ fn face(s: &CharStyle) -> Option<std::sync::Arc<vectorcraft_text::FontFace>> {
|
||||
|
||||
/// Does paragraph `p` set only its alignment, the others being at their defaults (no indents,
|
||||
/// spacing, tabs, bullets or numbers, direction, Auto Leading, word or letter spacing, glyph scaling
|
||||
/// or hanging punctuation)? Settings that only choose where area type breaks its lines (hyphenation,
|
||||
/// kinsoku, Bunri-Kinshi, breaking Korean anywhere) and the paragraph style's name may be set.
|
||||
fn flat(p: &ParaStyle) -> bool {
|
||||
/// or hanging punctuation)? Settings that only choose where area type breaks its lines or what
|
||||
/// hangs where it breaks them (hyphenation, the single-line or every-line composer, kinsoku,
|
||||
/// Burasagari, Bunri-Kinshi, breaking Korean anywhere) and the paragraph style's name may be set,
|
||||
/// and so may Mojikumi when `cjk` is false (it spaces only Chinese, Japanese and Korean characters).
|
||||
/// A paragraph set to a Standard composer is not flat.
|
||||
fn flat(p: &ParaStyle, cjk: bool) -> bool {
|
||||
let only = ParaStyle {
|
||||
justify: p.justify,
|
||||
style_name: p.style_name.clone(),
|
||||
hyphenate: p.hyphenate,
|
||||
hyphenation: p.hyphenation.clone(),
|
||||
composer: if matches!(p.composer, Composer::SingleLine | Composer::EveryLine) { p.composer } else { ParaStyle::default().composer },
|
||||
kinsoku: p.kinsoku,
|
||||
kinsoku_type: p.kinsoku_type,
|
||||
burasagari: p.burasagari,
|
||||
bunri_kinshi: p.bunri_kinshi,
|
||||
korean_line_break_anywhere: p.korean_line_break_anywhere,
|
||||
mojikumi: if cjk { ParaStyle::default().mojikumi } else { p.mojikumi },
|
||||
..ParaStyle::default()
|
||||
};
|
||||
only == *p
|
||||
}
|
||||
|
||||
/// Is `c` in a block of Chinese, Japanese or Korean characters or their punctuation?
|
||||
fn cjk(c: char) -> bool {
|
||||
matches!(c, '\u{1100}'..='\u{11FF}' | '\u{2E80}'..='\u{9FFF}' | '\u{A960}'..='\u{A97F}' | '\u{AC00}'..='\u{D7FF}' | '\u{F900}'..='\u{FAFF}' | '\u{FE30}'..='\u{FE4F}' | '\u{FF00}'..='\u{FFEF}' | '\u{20000}'..='\u{3FFFF}')
|
||||
}
|
||||
|
||||
/// Does `s` set only attributes a type layer carries (font and its version, size, leading,
|
||||
/// tracking, scaling, baseline shift, all caps, underline, strikethrough, fill), the others being
|
||||
/// at their defaults? Attributes that change nothing drawn without a stroke (the stroke's own
|
||||
/// settings, overprint, the character style's name) may be set.
|
||||
/// settings, overprint, the character style's name) may be set, and so may the language when it
|
||||
/// is the default, English: USA. The type layer does not record the language, so type in another
|
||||
/// language stays pixels.
|
||||
fn carried(s: &CharStyle) -> bool {
|
||||
if !s.language.as_deref().is_none_or(|l| l.eq_ignore_ascii_case("en-US")) {
|
||||
return false;
|
||||
}
|
||||
let only = CharStyle {
|
||||
language: s.language.clone(),
|
||||
font_family: s.font_family.clone(),
|
||||
font_style: s.font_style.clone(),
|
||||
font_version: s.font_version.clone(),
|
||||
|
||||
@@ -562,6 +562,8 @@ fn type_a_type_layer_cant_draw_stays_pixels() {
|
||||
b.add(tabbed);
|
||||
let leading = type_node(&mut b, (40.0, 10.0), "Auto", |t| t.para.justification.auto_leading = 150.0);
|
||||
b.add(leading);
|
||||
let standard = type_node(&mut b, (40.0, 20.0), "Std", |t| t.para.composer = vectorcraft_doc::Composer::StandardEveryLine);
|
||||
b.add(standard);
|
||||
// Hebrew: right to left from its first strong character, so Auto alignment is right. In an
|
||||
// installed font that covers it when there is one; otherwise its font lacks it.
|
||||
let hebrew_face = vectorcraft_text::FontDb::global().face_covering('ש');
|
||||
@@ -573,6 +575,8 @@ fn type_a_type_layer_cant_draw_stays_pixels() {
|
||||
b.add(hebrew);
|
||||
let tracked = type_node(&mut b, (10.0, 58.0), "Tracked", |t| t.runs[0].style.tracking = 0.5);
|
||||
b.add(tracked);
|
||||
let british = type_node(&mut b, (70.0, 58.0), "Colour", |t| t.runs[0].style.language = Some("en-GB".into()));
|
||||
b.add(british);
|
||||
// Drawn partly with a fallback font: the bundled fonts have no 縦.
|
||||
let fallback = type_node(&mut b, (40.0, 58.0), "A縦", |_| {});
|
||||
b.add(fallback);
|
||||
@@ -661,7 +665,8 @@ fn type_layer_keeps_the_anti_aliasing_method() {
|
||||
#[test]
|
||||
fn variation_selectors_and_joiners_need_no_glyph() {
|
||||
let mut b = DocBuilder::new(100.0, 60.0);
|
||||
let t = type_node(&mut b, (10.0, 30.0), "A\u{FE0F}\u{200D}B\u{E0100}", |_| {});
|
||||
// In English: USA, the default language, given by its tag.
|
||||
let t = type_node(&mut b, (10.0, 30.0), "A\u{FE0F}\u{200D}B\u{E0100}", |t| t.runs[0].style.language = Some("en-US".into()));
|
||||
b.add(t);
|
||||
let file = export(&b.build(), &opts(PsdOptions { preserve_text: true, ..PsdOptions::default() }));
|
||||
assert_eq!(parse(&file).records.iter().filter(|r| r.type_tool.is_some()).count(), 1);
|
||||
|
||||
+6
-4
@@ -8645,14 +8645,16 @@ baseline shift, caps, underline, strikethrough, fill color, Fractional Widths, p
|
||||
anti-aliasing method (None with `antiAlias: none`), at the export's resolution, and keeps its pixels for readers that
|
||||
show them. The font is the installed version the character style names, if any. VectorCraft writes only point type in
|
||||
solid colors with whole-number tracking whose characters are all in their own font (none drawn with a fallback font),
|
||||
that sets no other character attribute (no stroke, kerning, rotation, OpenType feature, small caps, position or East
|
||||
Asian setting), whose paragraphs set nothing but their alignment and line breaking (no indents, spacing, tabs,
|
||||
bullets or numbers, Auto Leading, word or letter spacing) and run left to right (set, or from their first strong
|
||||
that sets no other character attribute (no stroke, kerning, rotation, OpenType feature, small caps, position, East
|
||||
Asian setting or language other than the default English: USA), whose paragraphs set nothing but their alignment
|
||||
and line breaking (no indents, spacing, tabs, bullets or numbers, Auto Leading, word or letter spacing, Standard
|
||||
composer, and no Mojikumi other than the default in type with Chinese, Japanese or Korean characters) and run left to right (set, or from their first strong
|
||||
character), and that has no inline graphics, ruby, System Layout, Optical Margin Alignment, effects, appearance of its
|
||||
own or opacity mask as a type layer; other type, area type and type on a path stay pixels. Without `maxEditability`, a
|
||||
layer or sublayer that holds such type becomes a group of its type layers and one pixel layer for each stretch of art
|
||||
between them, unless other art in it blends in a mode other than Normal: then the layer stays one pixel layer. Hidden
|
||||
type counts only with `hiddenLayers`. With `maxEditability`, every object is a layer as above. The PSD Options dialog has the option as Preserve Text Editability
|
||||
type counts only with `hiddenLayers`. With `maxEditability`, every object is a layer as above. The PSD Options dialog
|
||||
has the option as Preserve Text Editability
|
||||
(<https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/export-file-format-options-in-illustrator.html>).
|
||||
|
||||
```json
|
||||
|
||||
Reference in New Issue
Block a user