mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 03:47:18 +02:00
🔧 Add vertical alignment for text shapes
This commit is contained in:
parent
0010d61ae2
commit
134fb1ab4c
8 changed files with 2436 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
use super::{RenderState, Shape, SurfaceId};
|
||||
use crate::shapes::VerticalAlign;
|
||||
use skia_safe::{textlayout::Paragraph, Paint, Path};
|
||||
|
||||
pub fn render(
|
||||
|
@ -11,8 +12,16 @@ pub fn render(
|
|||
.surfaces
|
||||
.canvas(surface_id.unwrap_or(SurfaceId::Fills));
|
||||
|
||||
let container_height = shape.selrect().height();
|
||||
for group in paragraphs {
|
||||
let mut offset_y = 0.0;
|
||||
let total_paragraphs_height: f32 = group.iter().map(|p| p.height()).sum();
|
||||
|
||||
let mut offset_y = match shape.vertical_align() {
|
||||
VerticalAlign::Center => (container_height - total_paragraphs_height) / 2.0,
|
||||
VerticalAlign::Bottom => container_height - total_paragraphs_height,
|
||||
_ => 0.0,
|
||||
};
|
||||
|
||||
for skia_paragraph in group {
|
||||
let xy = (shape.selrect().x(), shape.selrect.y() + offset_y);
|
||||
skia_paragraph.paint(canvas, xy);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue