mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
fix: use line-height-based bounds for text elements
This commit is contained in:
@@ -81,5 +81,7 @@ changes:
|
|||||||
text: "You can now import transcript files to generate captions instead of running auto-transcription."
|
text: "You can now import transcript files to generate captions instead of running auto-transcription."
|
||||||
- type: new
|
- type: new
|
||||||
text: "Graph editor for keyframe curves. Shape the easing between keyframes by dragging bezier handles."
|
text: "Graph editor for keyframe curves. Shape the easing between keyframes by dragging bezier handles."
|
||||||
|
- type: fixed
|
||||||
|
text: "Text element handles no longer shift position as you type."
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -54,32 +54,19 @@ export function getMetricDescent({
|
|||||||
export function measureTextBlock({
|
export function measureTextBlock({
|
||||||
lineMetrics,
|
lineMetrics,
|
||||||
lineHeightPx,
|
lineHeightPx,
|
||||||
fallbackFontSize,
|
|
||||||
}: {
|
}: {
|
||||||
lineMetrics: TextMetrics[];
|
lineMetrics: TextMetrics[];
|
||||||
lineHeightPx: number;
|
lineHeightPx: number;
|
||||||
fallbackFontSize: number;
|
|
||||||
}): TextBlockMeasurement {
|
}): TextBlockMeasurement {
|
||||||
let top = Number.POSITIVE_INFINITY;
|
|
||||||
let bottom = Number.NEGATIVE_INFINITY;
|
|
||||||
let maxWidth = 0;
|
let maxWidth = 0;
|
||||||
|
|
||||||
for (let index = 0; index < lineMetrics.length; index++) {
|
for (const metrics of lineMetrics) {
|
||||||
const metrics = lineMetrics[index];
|
|
||||||
const lineY = index * lineHeightPx;
|
|
||||||
top = Math.min(
|
|
||||||
top,
|
|
||||||
lineY - getMetricAscent({ metrics, fallbackFontSize }),
|
|
||||||
);
|
|
||||||
bottom = Math.max(
|
|
||||||
bottom,
|
|
||||||
lineY + getMetricDescent({ metrics, fallbackFontSize }),
|
|
||||||
);
|
|
||||||
maxWidth = Math.max(maxWidth, metrics.width);
|
maxWidth = Math.max(maxWidth, metrics.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
const height = bottom - top;
|
const lineCount = lineMetrics.length;
|
||||||
const visualCenterOffset = (top + bottom) / 2;
|
const height = lineCount * lineHeightPx;
|
||||||
|
const visualCenterOffset = ((lineCount - 1) * lineHeightPx) / 2;
|
||||||
|
|
||||||
return { visualCenterOffset, height, maxWidth };
|
return { visualCenterOffset, height, maxWidth };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ export function measureTextElement({
|
|||||||
const block = measureTextBlock({
|
const block = measureTextBlock({
|
||||||
lineMetrics,
|
lineMetrics,
|
||||||
lineHeightPx,
|
lineHeightPx,
|
||||||
fallbackFontSize: scaledFontSize,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const bg = element.background;
|
const bg = element.background;
|
||||||
|
|||||||
Reference in New Issue
Block a user