summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-05-07 15:20:30 +0200
committerGitHub <noreply@github.com>2024-05-07 13:20:30 +0000
commit01b791da83ba63a84eab6c1a1e93bfe13fc5bdbb (patch)
tree3dfda0bdeb899f5f1b7cb06283dfcaa03bfc681d /crates
parent96b04a7e1a0f87056980a4f5683abb3682e09586 (diff)
Add region to `TextItem` (#4091)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/layout/inline/shaping.rs4
-rw-r--r--crates/typst/src/math/fragment.rs5
-rw-r--r--crates/typst/src/text/font/color.rs1
-rw-r--r--crates/typst/src/text/item.rs4
4 files changed, 10 insertions, 4 deletions
diff --git a/crates/typst/src/layout/inline/shaping.rs b/crates/typst/src/layout/inline/shaping.rs
index 82a33f9b..aa30688b 100644
--- a/crates/typst/src/layout/inline/shaping.rs
+++ b/crates/typst/src/layout/inline/shaping.rs
@@ -225,7 +225,6 @@ impl<'a> ShapedText<'a> {
frame.set_baseline(top);
let shift = TextElem::baseline_in(self.styles);
- let lang = TextElem::lang_in(self.styles);
let decos = TextElem::deco_in(self.styles);
let fill = TextElem::fill_in(self.styles);
let stroke = TextElem::stroke_in(self.styles);
@@ -306,7 +305,8 @@ impl<'a> ShapedText<'a> {
let item = TextItem {
font,
size: self.size,
- lang,
+ lang: self.lang,
+ region: self.region,
fill: fill.clone(),
stroke: stroke.clone().map(|s| s.unwrap_or_default()),
text: self.text[range.start - self.base..range.end - self.base].into(),
diff --git a/crates/typst/src/math/fragment.rs b/crates/typst/src/math/fragment.rs
index c5396654..084a1241 100644
--- a/crates/typst/src/math/fragment.rs
+++ b/crates/typst/src/math/fragment.rs
@@ -12,7 +12,7 @@ use crate::math::{
scaled_font_size, EquationElem, Limits, MathContext, MathSize, Scaled,
};
use crate::syntax::Span;
-use crate::text::{Font, Glyph, Lang, TextElem, TextItem};
+use crate::text::{Font, Glyph, Lang, Region, TextElem, TextItem};
use crate::visualize::Paint;
#[derive(Debug, Clone)]
@@ -206,6 +206,7 @@ pub struct GlyphFragment {
pub c: char,
pub font: Font,
pub lang: Lang,
+ pub region: Option<Region>,
pub fill: Paint,
pub shift: Abs,
pub width: Abs,
@@ -259,6 +260,7 @@ impl GlyphFragment {
c,
font: ctx.font.clone(),
lang: TextElem::lang_in(styles),
+ region: TextElem::region_in(styles),
fill: TextElem::fill_in(styles).as_decoration(),
shift: TextElem::baseline_in(styles),
font_size: scaled_font_size(ctx, styles),
@@ -340,6 +342,7 @@ impl GlyphFragment {
size: self.font_size,
fill: self.fill,
lang: self.lang,
+ region: self.region,
text: self.c.into(),
stroke: None,
glyphs: vec![Glyph {
diff --git a/crates/typst/src/text/font/color.rs b/crates/typst/src/text/font/color.rs
index 2dfd5545..8ca9e6c5 100644
--- a/crates/typst/src/text/font/color.rs
+++ b/crates/typst/src/text/font/color.rs
@@ -104,6 +104,7 @@ impl<'f, 't> ColrPainter<'f, 't> {
fill,
stroke: None,
lang: Lang::ENGLISH,
+ region: None,
text: EcoString::new(),
glyphs: vec![Glyph {
id: self.current_glyph.0,
diff --git a/crates/typst/src/text/item.rs b/crates/typst/src/text/item.rs
index 3ad481cf..5de30a8d 100644
--- a/crates/typst/src/text/item.rs
+++ b/crates/typst/src/text/item.rs
@@ -5,7 +5,7 @@ use ecow::EcoString;
use crate::layout::{Abs, Em};
use crate::syntax::Span;
-use crate::text::{Font, Lang};
+use crate::text::{Font, Lang, Region};
use crate::visualize::{FixedStroke, Paint};
/// A run of shaped text.
@@ -21,6 +21,8 @@ pub struct TextItem {
pub stroke: Option<FixedStroke>,
/// The natural language of the text.
pub lang: Lang,
+ /// The region of the text.
+ pub region: Option<Region>,
/// The item's plain text.
pub text: EcoString,
/// The glyphs. The number of glyphs may be different from the number of