Center route-D paragraphs and preview center blocks
This commit is contained in:
1 parent
611e6fec96
commit
472f778e75
5 files changed
+56
-3
No files matched your search
@@ -42,6 +42,9 @@ pub struct ParagraphStyle {
|
||||
pub left_skip: i64,
|
||||
/// Right skip reserved at the end of every line (`\rightskip`).
|
||||
pub right_skip: i64,
|
||||
/// Center each line in the measure instead of justifying it.
|
||||
#[serde(default)]
|
||||
pub centered: bool,
|
||||
pub par_indent: i64,
|
||||
pub line_height: i64,
|
||||
pub char_width: i64,
|
||||
@@ -56,6 +59,7 @@ impl Default for ParagraphStyle {
|
||||
line_width: 400,
|
||||
left_skip: 0,
|
||||
right_skip: 0,
|
||||
centered: false,
|
||||
par_indent: 0,
|
||||
line_height: 12,
|
||||
char_width: 10,
|
||||
@@ -91,6 +95,8 @@ pub struct Paragraph {
|
||||
pub font: ParagraphFont,
|
||||
#[serde(default)]
|
||||
pub left_skip: i64,
|
||||
#[serde(default)]
|
||||
pub centered: bool,
|
||||
}
|
||||
|
||||
impl Paragraph {
|
||||
@@ -150,6 +156,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
width: 0,
|
||||
font: ParagraphFont::Roman,
|
||||
left_skip: style.left_skip,
|
||||
centered: style.centered,
|
||||
};
|
||||
}
|
||||
let mut breakpoints = vec![0_usize];
|
||||
@@ -326,6 +333,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
lines,
|
||||
font: ParagraphFont::Roman,
|
||||
left_skip: style.left_skip,
|
||||
centered: style.centered,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -378,7 +378,20 @@ impl Page {
|
||||
let size = ((line_height as f64) * 0.7) as i64;
|
||||
for line in ¶graph.lines {
|
||||
let baseline = y + ((line_height as f64) * 0.8) as i64;
|
||||
let mut x = paragraph.left_skip;
|
||||
let natural: i64 = line
|
||||
.iter()
|
||||
.map(|item| match item {
|
||||
HorizontalItem::Box(box_) => box_.width,
|
||||
HorizontalItem::Glue { width, .. } => *width,
|
||||
HorizontalItem::Penalty { .. }
|
||||
| HorizontalItem::Discretionary { .. } => 0,
|
||||
})
|
||||
.sum();
|
||||
let mut x = if paragraph.centered {
|
||||
paragraph.left_skip + ((paragraph.width - natural) / 2).max(0)
|
||||
} else {
|
||||
paragraph.left_skip
|
||||
};
|
||||
for item in line {
|
||||
match item {
|
||||
HorizontalItem::Box(box_) => {
|
||||
|
||||
Reference in new issue
Block a user