Implement XeTeX contextual interword spacing and shipout shaping
This commit is contained in:
1 parent
7e5428ec35
commit
4a77540e46
23 files changed
+491
-42
No files matched your search
@@ -797,6 +797,7 @@ fn empty_alignment_box(width: i64, horizontal: bool, span: Span) -> NativeBox {
|
||||
},
|
||||
diagnostic: Vec::new(),
|
||||
setting: GlueSetting::default(),
|
||||
interword_runs: Vec::new(),
|
||||
badness: 0,
|
||||
diagnostic_eligible: false,
|
||||
excess: 0,
|
||||
@@ -857,7 +858,7 @@ fn set_alignment_cell(
|
||||
match &cell.content {
|
||||
BoxContent::Horizontal(v) => {
|
||||
for n in v {
|
||||
if let TextNode::Glue(g)
|
||||
if let TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
|
||||
{
|
||||
@@ -1031,7 +1032,7 @@ fn mark_unset(b: &mut NativeBox, span: u8) -> Result<(), String> {
|
||||
match &b.content {
|
||||
BoxContent::Horizontal(v) => {
|
||||
for n in v {
|
||||
if let TextNode::Glue(g)
|
||||
if let TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
|
||||
{
|
||||
|
||||
@@ -522,6 +522,7 @@ impl Executor {
|
||||
content: BoxContent::Horizontal(Vec::new()),
|
||||
diagnostic: Vec::new(),
|
||||
setting: GlueSetting::default(),
|
||||
interword_runs: Vec::new(),
|
||||
badness: 0,
|
||||
diagnostic_eligible: false,
|
||||
excess: 0,
|
||||
|
||||
@@ -152,7 +152,7 @@ impl Executor {
|
||||
if b.width + q > width {
|
||||
let mut shrink = [0i64; 4];
|
||||
for node in &material {
|
||||
if let TextNode::Glue(g)
|
||||
if let TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = node
|
||||
{
|
||||
@@ -180,7 +180,7 @@ impl Executor {
|
||||
displacement = (width - b.width - e + 1).div_euclid(2);
|
||||
if matches!(
|
||||
material.first(),
|
||||
Some(TextNode::Glue(_) | TextNode::NamedGlue(_, _) | TextNode::Leaders(_))
|
||||
Some(TextNode::Glue(_) | TextNode::FontSpace(_, _, _) | TextNode::NamedGlue(_, _) | TextNode::Leaders(_))
|
||||
) {
|
||||
displacement = 0;
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ impl Tail {
|
||||
}
|
||||
fn text(node: &TextNode) -> Self {
|
||||
match node {
|
||||
TextNode::Glue(g)
|
||||
TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue: g, .. }) => Self::Glue(*g, false),
|
||||
TextNode::Kern { width, .. } | TextNode::AccentKern(width) | TextNode::AutoKern(width) => {
|
||||
TextNode::Kern { width, .. } | TextNode::AccentKern(width) | TextNode::AutoKern(width) | TextNode::SpaceAdjustment(width) => {
|
||||
Self::Kern(*width)
|
||||
}
|
||||
TextNode::Penalty(n) => Self::Penalty(*n),
|
||||
|
||||
@@ -767,7 +767,7 @@ impl Executor {
|
||||
_ => MathStyle::ScriptScript,
|
||||
})),
|
||||
Explicitspace => {
|
||||
let space = match self.explicit_space()? {
|
||||
let space = match self.explicit_space(None)? {
|
||||
TextNode::NamedGlue(glue, parameter) => {
|
||||
MathNode::ExplicitSpace(glue, Some(parameter))
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ impl Executor {
|
||||
}
|
||||
pub(super) fn ship_box(
|
||||
&mut self,
|
||||
b: NativeBox,
|
||||
mut b: NativeBox,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
self.native_page_mut()?;
|
||||
@@ -314,6 +314,14 @@ impl Executor {
|
||||
pdf,
|
||||
};
|
||||
self.trace_shipout(&b, files)?;
|
||||
if self.state.input_profile() == InputProfile::XeTeX
|
||||
&& self.read_parameter(Parameter::XeTeXinterwordspaceshaping).width() > 1
|
||||
{
|
||||
let limit = self.limits.steps.saturating_sub(self.steps);
|
||||
let work = b.prepare_interword_shipout(limit, self.cancellation.as_ref())
|
||||
.map_err(|error| self.error(error, b.span))?;
|
||||
self.steps += work;
|
||||
}
|
||||
let current = self.current;
|
||||
let (pdf_resource_entries, pdf_page_attributes) = if device.pdf.is_some() {
|
||||
(
|
||||
|
||||
@@ -142,7 +142,7 @@ impl Executor {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
pub(super) fn explicit_space(&mut self) -> Result<TextNode, Error> {
|
||||
pub(super) fn explicit_space(&mut self, token: Option<&Token>) -> Result<TextNode, Error> {
|
||||
let glue = self.read_parameter(Parameter::Spaceskip).glue();
|
||||
if glue != Glue::default() {
|
||||
return Ok(TextNode::NamedGlue(glue, Parameter::Spaceskip));
|
||||
@@ -154,6 +154,13 @@ impl Executor {
|
||||
.fonts
|
||||
.font(self.state.text_font())
|
||||
.map_err(|error| self.error(error, self.current))?;
|
||||
if self.state.input_profile() == InputProfile::XeTeX && font.opentype().is_some()
|
||||
&& let Some(token) = token
|
||||
{
|
||||
return Ok(TextNode::FontSpace(
|
||||
font.space(), self.state.text_font(), TokenOrigin::from(token),
|
||||
));
|
||||
}
|
||||
Ok(TextNode::Glue(font.space()))
|
||||
}
|
||||
|
||||
@@ -345,7 +352,7 @@ impl Executor {
|
||||
.insert(Dependency::Parameter(Parameter::Spaceskip));
|
||||
self.reads
|
||||
.insert(Dependency::Parameter(Parameter::Xspaceskip));
|
||||
b.space(&self.state)
|
||||
b.space(&self.state, TokenOrigin::from(token))
|
||||
.map_err(|e| self.error(e, token.invocation.unwrap_or(token.span)))?;
|
||||
}
|
||||
return Ok(());
|
||||
@@ -390,6 +397,7 @@ impl Executor {
|
||||
if self.state.input_profile() == InputProfile::XeTeX {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXuseglyphmetrics));
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXgenerateactualtext));
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXinterwordspaceshaping));
|
||||
if !self.restricted() {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXdashbreakstate));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user