mirror of
https://github.com/typst/typst
synced 2025-08-21 18:24:14 +08:00
Better name for subperscripts
This commit is contained in:
parent
6ac77bc1d1
commit
3fd2570533
@ -420,7 +420,7 @@ pub fn apply_shift<'a>(
|
|||||||
) {
|
) {
|
||||||
let mut baseline = TextElem::baseline_in(styles);
|
let mut baseline = TextElem::baseline_in(styles);
|
||||||
let mut compensation = Abs::zero();
|
let mut compensation = Abs::zero();
|
||||||
if let Some(scripts) = TextElem::subperscript_in(styles) {
|
if let Some(scripts) = TextElem::shift_settings_in(styles) {
|
||||||
let font_metrics = TextElem::font_in(styles)
|
let font_metrics = TextElem::font_in(styles)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|family| {
|
.find_map(|family| {
|
||||||
|
@ -13,7 +13,7 @@ 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::text::{
|
use typst_library::text::{
|
||||||
families, features, is_default_ignorable, variant, Font, FontFamily, FontVariant,
|
families, features, is_default_ignorable, variant, Font, FontFamily, FontVariant,
|
||||||
Glyph, Lang, Region, ScriptSettings, TextEdgeBounds, TextElem, TextItem,
|
Glyph, Lang, Region, ShiftSettings, TextEdgeBounds, TextElem, TextItem,
|
||||||
};
|
};
|
||||||
use typst_library::World;
|
use typst_library::World;
|
||||||
use typst_utils::SliceExt;
|
use typst_utils::SliceExt;
|
||||||
@ -672,7 +672,7 @@ fn shape<'a>(
|
|||||||
region: Option<Region>,
|
region: Option<Region>,
|
||||||
) -> ShapedText<'a> {
|
) -> ShapedText<'a> {
|
||||||
let size = TextElem::size_in(styles);
|
let size = TextElem::size_in(styles);
|
||||||
let script_settings = TextElem::subperscript_in(styles);
|
let script_settings = TextElem::shift_settings_in(styles);
|
||||||
let mut ctx = ShapingContext {
|
let mut ctx = ShapingContext {
|
||||||
engine,
|
engine,
|
||||||
size,
|
size,
|
||||||
@ -736,7 +736,7 @@ fn shape_segment<'a>(
|
|||||||
base: usize,
|
base: usize,
|
||||||
text: &str,
|
text: &str,
|
||||||
mut families: impl Iterator<Item = &'a FontFamily> + Clone,
|
mut families: impl Iterator<Item = &'a FontFamily> + Clone,
|
||||||
script_settings: Option<ScriptSettings>,
|
script_settings: Option<ShiftSettings>,
|
||||||
) {
|
) {
|
||||||
// Don't try shaping newlines, tabs, or default ignorables.
|
// Don't try shaping newlines, tabs, or default ignorables.
|
||||||
if text
|
if text
|
||||||
|
@ -755,10 +755,11 @@ pub struct TextElem {
|
|||||||
#[ghost]
|
#[ghost]
|
||||||
pub smallcaps: Option<Smallcaps>,
|
pub smallcaps: Option<Smallcaps>,
|
||||||
|
|
||||||
/// The settings for superscripts or subscripts, if one of them is enabled.
|
/// The configuration for superscripts or subscripts, if one of them is
|
||||||
|
/// enabled.
|
||||||
#[internal]
|
#[internal]
|
||||||
#[ghost]
|
#[ghost]
|
||||||
pub subperscript: Option<ScriptSettings>,
|
pub shift_settings: Option<ShiftSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextElem {
|
impl TextElem {
|
||||||
|
@ -153,7 +153,7 @@ fn show_script(
|
|||||||
kind: ScriptKind,
|
kind: ScriptKind,
|
||||||
) -> SourceResult<Content> {
|
) -> SourceResult<Content> {
|
||||||
let outer_text_size = TextElem::size_in(styles);
|
let outer_text_size = TextElem::size_in(styles);
|
||||||
Ok(body.styled(TextElem::set_subperscript(Some(ScriptSettings {
|
Ok(body.styled(TextElem::set_shift_settings(Some(ShiftSettings {
|
||||||
typographic,
|
typographic,
|
||||||
shift: baseline.map(|l| -l.to_em(outer_text_size)),
|
shift: baseline.map(|l| -l.to_em(outer_text_size)),
|
||||||
size: size.map(|t| t.0.to_em(outer_text_size)),
|
size: size.map(|t| t.0.to_em(outer_text_size)),
|
||||||
@ -163,7 +163,7 @@ fn show_script(
|
|||||||
|
|
||||||
/// Configuration values for sub- or superscript text.
|
/// Configuration values for sub- or superscript text.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct ScriptSettings {
|
pub struct ShiftSettings {
|
||||||
/// Whether the OpenType feature should be used if possible.
|
/// Whether the OpenType feature should be used if possible.
|
||||||
pub typographic: bool,
|
pub typographic: bool,
|
||||||
/// The baseline shift of the script, relative to the outer text size.
|
/// The baseline shift of the script, relative to the outer text size.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user