mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: masks, properties refactor, shaders, storage migrations, and more
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DEFAULT_TEXT_BACKGROUND } from "@/constants/text-constants";
|
||||
import type { TextBackground, TextElement } from "@/types/timeline";
|
||||
import type { TextBackground, TextElement } from "@/lib/timeline";
|
||||
import { DEFAULTS } from "@/lib/timeline/defaults";
|
||||
|
||||
type TextRect = {
|
||||
left: number;
|
||||
@@ -14,6 +14,23 @@ export interface TextBlockMeasurement {
|
||||
maxWidth: number;
|
||||
}
|
||||
|
||||
type CanvasContext =
|
||||
| CanvasRenderingContext2D
|
||||
| OffscreenCanvasRenderingContext2D;
|
||||
|
||||
export function setCanvasLetterSpacing({
|
||||
ctx,
|
||||
letterSpacingPx,
|
||||
}: {
|
||||
ctx: CanvasContext;
|
||||
letterSpacingPx: number;
|
||||
}): void {
|
||||
if ("letterSpacing" in ctx) {
|
||||
(ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing =
|
||||
`${letterSpacingPx}px`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricAscent({
|
||||
metrics,
|
||||
fallbackFontSize,
|
||||
@@ -118,11 +135,11 @@ export function getTextBackgroundRect({
|
||||
|
||||
const textRect = getTextRect({ textAlign, block });
|
||||
const paddingX =
|
||||
(background.paddingX ?? DEFAULT_TEXT_BACKGROUND.paddingX) * fontSizeRatio;
|
||||
(background.paddingX ?? DEFAULTS.text.background.paddingX) * fontSizeRatio;
|
||||
const paddingY =
|
||||
(background.paddingY ?? DEFAULT_TEXT_BACKGROUND.paddingY) * fontSizeRatio;
|
||||
const offsetX = background.offsetX ?? DEFAULT_TEXT_BACKGROUND.offsetX;
|
||||
const offsetY = background.offsetY ?? DEFAULT_TEXT_BACKGROUND.offsetY;
|
||||
(background.paddingY ?? DEFAULTS.text.background.paddingY) * fontSizeRatio;
|
||||
const offsetX = background.offsetX ?? DEFAULTS.text.background.offsetX;
|
||||
const offsetY = background.offsetY ?? DEFAULTS.text.background.offsetY;
|
||||
|
||||
return {
|
||||
left: textRect.left - paddingX + offsetX,
|
||||
|
||||
Reference in New Issue
Block a user