mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add region to TextItem
(#4091)
This commit is contained in:
parent
96b04a7e1a
commit
01b791da83
@ -225,7 +225,6 @@ impl<'a> ShapedText<'a> {
|
|||||||
frame.set_baseline(top);
|
frame.set_baseline(top);
|
||||||
|
|
||||||
let shift = TextElem::baseline_in(self.styles);
|
let shift = TextElem::baseline_in(self.styles);
|
||||||
let lang = TextElem::lang_in(self.styles);
|
|
||||||
let decos = TextElem::deco_in(self.styles);
|
let decos = TextElem::deco_in(self.styles);
|
||||||
let fill = TextElem::fill_in(self.styles);
|
let fill = TextElem::fill_in(self.styles);
|
||||||
let stroke = TextElem::stroke_in(self.styles);
|
let stroke = TextElem::stroke_in(self.styles);
|
||||||
@ -306,7 +305,8 @@ impl<'a> ShapedText<'a> {
|
|||||||
let item = TextItem {
|
let item = TextItem {
|
||||||
font,
|
font,
|
||||||
size: self.size,
|
size: self.size,
|
||||||
lang,
|
lang: self.lang,
|
||||||
|
region: self.region,
|
||||||
fill: fill.clone(),
|
fill: fill.clone(),
|
||||||
stroke: stroke.clone().map(|s| s.unwrap_or_default()),
|
stroke: stroke.clone().map(|s| s.unwrap_or_default()),
|
||||||
text: self.text[range.start - self.base..range.end - self.base].into(),
|
text: self.text[range.start - self.base..range.end - self.base].into(),
|
||||||
|
@ -12,7 +12,7 @@ use crate::math::{
|
|||||||
scaled_font_size, EquationElem, Limits, MathContext, MathSize, Scaled,
|
scaled_font_size, EquationElem, Limits, MathContext, MathSize, Scaled,
|
||||||
};
|
};
|
||||||
use crate::syntax::Span;
|
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;
|
use crate::visualize::Paint;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -206,6 +206,7 @@ pub struct GlyphFragment {
|
|||||||
pub c: char,
|
pub c: char,
|
||||||
pub font: Font,
|
pub font: Font,
|
||||||
pub lang: Lang,
|
pub lang: Lang,
|
||||||
|
pub region: Option<Region>,
|
||||||
pub fill: Paint,
|
pub fill: Paint,
|
||||||
pub shift: Abs,
|
pub shift: Abs,
|
||||||
pub width: Abs,
|
pub width: Abs,
|
||||||
@ -259,6 +260,7 @@ impl GlyphFragment {
|
|||||||
c,
|
c,
|
||||||
font: ctx.font.clone(),
|
font: ctx.font.clone(),
|
||||||
lang: TextElem::lang_in(styles),
|
lang: TextElem::lang_in(styles),
|
||||||
|
region: TextElem::region_in(styles),
|
||||||
fill: TextElem::fill_in(styles).as_decoration(),
|
fill: TextElem::fill_in(styles).as_decoration(),
|
||||||
shift: TextElem::baseline_in(styles),
|
shift: TextElem::baseline_in(styles),
|
||||||
font_size: scaled_font_size(ctx, styles),
|
font_size: scaled_font_size(ctx, styles),
|
||||||
@ -340,6 +342,7 @@ impl GlyphFragment {
|
|||||||
size: self.font_size,
|
size: self.font_size,
|
||||||
fill: self.fill,
|
fill: self.fill,
|
||||||
lang: self.lang,
|
lang: self.lang,
|
||||||
|
region: self.region,
|
||||||
text: self.c.into(),
|
text: self.c.into(),
|
||||||
stroke: None,
|
stroke: None,
|
||||||
glyphs: vec![Glyph {
|
glyphs: vec![Glyph {
|
||||||
|
@ -104,6 +104,7 @@ impl<'f, 't> ColrPainter<'f, 't> {
|
|||||||
fill,
|
fill,
|
||||||
stroke: None,
|
stroke: None,
|
||||||
lang: Lang::ENGLISH,
|
lang: Lang::ENGLISH,
|
||||||
|
region: None,
|
||||||
text: EcoString::new(),
|
text: EcoString::new(),
|
||||||
glyphs: vec![Glyph {
|
glyphs: vec![Glyph {
|
||||||
id: self.current_glyph.0,
|
id: self.current_glyph.0,
|
||||||
|
@ -5,7 +5,7 @@ use ecow::EcoString;
|
|||||||
|
|
||||||
use crate::layout::{Abs, Em};
|
use crate::layout::{Abs, Em};
|
||||||
use crate::syntax::Span;
|
use crate::syntax::Span;
|
||||||
use crate::text::{Font, Lang};
|
use crate::text::{Font, Lang, Region};
|
||||||
use crate::visualize::{FixedStroke, Paint};
|
use crate::visualize::{FixedStroke, Paint};
|
||||||
|
|
||||||
/// A run of shaped text.
|
/// A run of shaped text.
|
||||||
@ -21,6 +21,8 @@ pub struct TextItem {
|
|||||||
pub stroke: Option<FixedStroke>,
|
pub stroke: Option<FixedStroke>,
|
||||||
/// The natural language of the text.
|
/// The natural language of the text.
|
||||||
pub lang: Lang,
|
pub lang: Lang,
|
||||||
|
/// The region of the text.
|
||||||
|
pub region: Option<Region>,
|
||||||
/// The item's plain text.
|
/// The item's plain text.
|
||||||
pub text: EcoString,
|
pub text: EcoString,
|
||||||
/// The glyphs. The number of glyphs may be different from the number of
|
/// The glyphs. The number of glyphs may be different from the number of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user