mirror of
https://github.com/typst/typst
synced 2025-08-06 03:07:54 +08:00
Compare commits
13 Commits
6710b4417a
...
d8419c4a23
Author | SHA1 | Date | |
---|---|---|---|
|
d8419c4a23 | ||
|
627f5b9d4f | ||
|
4aa6dcf578 | ||
|
34e2e43445 | ||
|
0148a5913d | ||
|
c8d45148f1 | ||
|
a445a3108f | ||
|
69d0d9e26d | ||
|
4fa7e5cfd9 | ||
|
7d6d46c4d8 | ||
|
07ba1c1636 | ||
|
422eb36f16 | ||
|
7f9adfac22 |
@ -14,8 +14,8 @@ use typst_library::model::{
|
|||||||
RefElem, StrongElem, TableCell, TableElem, TermsElem,
|
RefElem, StrongElem, TableCell, TableElem, TermsElem,
|
||||||
};
|
};
|
||||||
use typst_library::text::{
|
use typst_library::text::{
|
||||||
HighlightElem, LinebreakElem, OverlineElem, RawElem, RawLine, SpaceElem, StrikeElem,
|
HighlightElem, LinebreakElem, OverlineElem, RawElem, RawLine, SmallcapsElem,
|
||||||
SubElem, SuperElem, UnderlineElem,
|
SpaceElem, StrikeElem, SubElem, SuperElem, UnderlineElem,
|
||||||
};
|
};
|
||||||
use typst_library::visualize::ImageElem;
|
use typst_library::visualize::ImageElem;
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ pub fn register(rules: &mut NativeRuleMap) {
|
|||||||
rules.register(Html, OVERLINE_RULE);
|
rules.register(Html, OVERLINE_RULE);
|
||||||
rules.register(Html, STRIKE_RULE);
|
rules.register(Html, STRIKE_RULE);
|
||||||
rules.register(Html, HIGHLIGHT_RULE);
|
rules.register(Html, HIGHLIGHT_RULE);
|
||||||
|
rules.register(Html, SMALLCAPS_RULE);
|
||||||
rules.register(Html, RAW_RULE);
|
rules.register(Html, RAW_RULE);
|
||||||
rules.register(Html, RAW_LINE_RULE);
|
rules.register(Html, RAW_LINE_RULE);
|
||||||
|
|
||||||
@ -390,6 +391,20 @@ const STRIKE_RULE: ShowFn<StrikeElem> =
|
|||||||
const HIGHLIGHT_RULE: ShowFn<HighlightElem> =
|
const HIGHLIGHT_RULE: ShowFn<HighlightElem> =
|
||||||
|elem, _, _| Ok(HtmlElem::new(tag::mark).with_body(Some(elem.body.clone())).pack());
|
|elem, _, _| Ok(HtmlElem::new(tag::mark).with_body(Some(elem.body.clone())).pack());
|
||||||
|
|
||||||
|
const SMALLCAPS_RULE: ShowFn<SmallcapsElem> = |elem, _, styles| {
|
||||||
|
Ok(HtmlElem::new(tag::span)
|
||||||
|
.with_attr(
|
||||||
|
attr::style,
|
||||||
|
if elem.all.get(styles) {
|
||||||
|
"font-variant-caps: all-small-caps"
|
||||||
|
} else {
|
||||||
|
"font-variant-caps: small-caps"
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.with_body(Some(elem.body.clone()))
|
||||||
|
.pack())
|
||||||
|
};
|
||||||
|
|
||||||
const RAW_RULE: ShowFn<RawElem> = |elem, _, styles| {
|
const RAW_RULE: ShowFn<RawElem> = |elem, _, styles| {
|
||||||
let lines = elem.lines.as_deref().unwrap_or_default();
|
let lines = elem.lines.as_deref().unwrap_or_default();
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use ttf_parser::Tag;
|
|||||||
use typst_library::engine::Engine;
|
use typst_library::engine::Engine;
|
||||||
use typst_library::foundations::{Smart, StyleChain};
|
use typst_library::foundations::{Smart, StyleChain};
|
||||||
use typst_library::layout::{Abs, Dir, Em, Frame, FrameItem, Point, Size};
|
use typst_library::layout::{Abs, Dir, Em, Frame, FrameItem, Point, Size};
|
||||||
|
use typst_library::model::{Microtype, ParElem};
|
||||||
use typst_library::text::{
|
use typst_library::text::{
|
||||||
families, features, is_default_ignorable, language, variant, Font, FontFamily,
|
families, features, is_default_ignorable, language, variant, Font, FontFamily,
|
||||||
FontVariant, Glyph, Lang, Region, ShiftSettings, TextEdgeBounds, TextElem, TextItem,
|
FontVariant, Glyph, Lang, Region, ShiftSettings, TextEdgeBounds, TextElem, TextItem,
|
||||||
@ -144,7 +145,11 @@ impl ShapedGlyph {
|
|||||||
|| self.c.is_ascii_digit()
|
|| self.c.is_ascii_digit()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base_adjustability(&self, style: CjkPunctStyle) -> Adjustability {
|
pub fn base_adjustability(
|
||||||
|
&self,
|
||||||
|
style: CjkPunctStyle,
|
||||||
|
microtype: Microtype,
|
||||||
|
) -> Adjustability {
|
||||||
let width = self.x_advance;
|
let width = self.x_advance;
|
||||||
if self.is_space() {
|
if self.is_space() {
|
||||||
Adjustability {
|
Adjustability {
|
||||||
@ -168,7 +173,10 @@ impl ShapedGlyph {
|
|||||||
shrinkability: (width / 4.0, width / 4.0),
|
shrinkability: (width / 4.0, width / 4.0),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Adjustability::default()
|
Adjustability {
|
||||||
|
stretchability: (Em::zero(), microtype.max_expand.em),
|
||||||
|
shrinkability: (Em::zero(), microtype.max_retract.em),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,9 +1118,10 @@ fn track_and_space(ctx: &mut ShapingContext) {
|
|||||||
/// and CJK punctuation adjustments according to Chinese Layout Requirements.
|
/// and CJK punctuation adjustments according to Chinese Layout Requirements.
|
||||||
fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<Region>) {
|
fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<Region>) {
|
||||||
let style = cjk_punct_style(lang, region);
|
let style = cjk_punct_style(lang, region);
|
||||||
|
let microtype = ParElem::microtype_in(ctx.styles);
|
||||||
|
|
||||||
for glyph in &mut ctx.glyphs {
|
for glyph in &mut ctx.glyphs {
|
||||||
glyph.adjustability = glyph.base_adjustability(style);
|
glyph.adjustability = glyph.base_adjustability(style, microtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut glyphs = ctx.glyphs.iter_mut().peekable();
|
let mut glyphs = ctx.glyphs.iter_mut().peekable();
|
||||||
|
@ -136,6 +136,9 @@ pub struct ParElem {
|
|||||||
#[default(false)]
|
#[default(false)]
|
||||||
pub justify: bool,
|
pub justify: bool,
|
||||||
|
|
||||||
|
/// Microtypographical settings that are used during justification.
|
||||||
|
pub microtype: Microtype,
|
||||||
|
|
||||||
/// How to determine line breaks.
|
/// How to determine line breaks.
|
||||||
///
|
///
|
||||||
/// When this property is set to `{auto}`, its default value, optimized line
|
/// When this property is set to `{auto}`, its default value, optimized line
|
||||||
@ -224,6 +227,36 @@ impl ParElem {
|
|||||||
type ParLine;
|
type ParLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configuration for microtypographical settings to be used during
|
||||||
|
/// justification.
|
||||||
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Hash)]
|
||||||
|
pub struct Microtype {
|
||||||
|
/// How much a glyph is allowed to translate into its neighbor.
|
||||||
|
pub max_retract: Length,
|
||||||
|
/// How much a glyph is allowed to translate away from its neighbor.
|
||||||
|
pub max_expand: Length,
|
||||||
|
}
|
||||||
|
|
||||||
|
cast! {
|
||||||
|
Microtype,
|
||||||
|
self => Value::Dict(self.into()),
|
||||||
|
mut dict: Dict => {
|
||||||
|
let max_retract = dict.take("max-retract")?.cast()?;
|
||||||
|
let max_expand = dict.take("max-expand")?.cast()?;
|
||||||
|
dict.finish(&["max-retract", "max-expand"])?;
|
||||||
|
Self { max_retract, max_expand }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Microtype> for Dict {
|
||||||
|
fn from(microtype: Microtype) -> Self {
|
||||||
|
dict! {
|
||||||
|
"max-retract" => microtype.max_retract,
|
||||||
|
"max-expand" => microtype.max_expand,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// How to determine line breaks in a paragraph.
|
/// How to determine line breaks in a paragraph.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
|
||||||
pub enum Linebreaks {
|
pub enum Linebreaks {
|
||||||
|
10
tests/ref/html/smallcaps-all.html
Normal file
10
tests/ref/html/smallcaps-all.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p><span style="font-variant-caps: small-caps">Test 012</span><br><span style="font-variant-caps: all-small-caps">Test 012</span></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -11,6 +11,6 @@
|
|||||||
#show smallcaps: set text(fill: red)
|
#show smallcaps: set text(fill: red)
|
||||||
#smallcaps[Smallcaps]
|
#smallcaps[Smallcaps]
|
||||||
|
|
||||||
--- smallcaps-all ---
|
--- smallcaps-all render html ---
|
||||||
#smallcaps(all: false)[Test 012] \
|
#smallcaps(all: false)[Test 012] \
|
||||||
#smallcaps(all: true)[Test 012]
|
#smallcaps(all: true)[Test 012]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user