Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: title and subtitle support splitByGrapheme #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,15 @@ See also [Ken Burns parameters](#ken-burns-parameters).
- `text` - Title text to show, keep it short
- `textColor` - default `#ffffff`
- `position` - See [Position parameter](#position-parameter)
- `splitByGrapheme` - To split strings that have no white space concept. This is a cheap way to help with chinese/japanese. Default `false`

See also [Ken Burns parameters](#ken-burns-parameters)

#### Layer type 'subtitle'
- `fontPath` - See `defaults.layer.fontPath`
- `text` - Subtitle text to show
- `textColor` - default `#ffffff`
- `splitByGrapheme` - To split strings that have no white space concept. This is a cheap way to help with chinese/japanese. Default `false`

#### Layer type 'title-background'

Expand Down
12 changes: 10 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@ declare namespace Editly {
* Position.
*/
position?: Position;

/**
* To split strings that have no white space concept. This is a cheap way to help with chinese/japanese
* Defaults to `false`.
*/
splitByGrapheme?: boolean;
}

interface SubtitleLayer extends BaseLayer {
Expand Down Expand Up @@ -559,7 +563,11 @@ declare namespace Editly {
* WARNING: Undocumented feature!
*/
backgroundColor?: string;

/**
* To split strings that have no white space concept. This is a cheap way to help with chinese/japanese
* Defaults to `false`.
*/
splitByGrapheme?: boolean;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions sources/fabric/fabricFrameSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export async function linearGradientFrameSource({ width, height, params }) {
}

export async function subtitleFrameSource({ width, height, params }) {
const { text, textColor = '#ffffff', backgroundColor = 'rgba(0,0,0,0.3)', fontFamily = defaultFontFamily, delay = 0, speed = 1 } = params;
const { text, textColor = '#ffffff', backgroundColor = 'rgba(0,0,0,0.3)', fontFamily = defaultFontFamily, delay = 0, speed = 1, splitByGrapheme } = params;

async function onRender(progress, canvas) {
const easedProgress = easeOutExpo(Math.max(0, Math.min((progress - delay) * speed, 1)));
Expand All @@ -199,7 +199,7 @@ export async function subtitleFrameSource({ width, height, params }) {
const textBox = new fabric.Textbox(text, {
fill: textColor,
fontFamily,

splitByGrapheme,
fontSize: min / 20,
textAlign: 'left',
width: width - padding * 2,
Expand Down Expand Up @@ -263,7 +263,7 @@ export async function imageOverlayFrameSource({ params, width, height }) {
}

export async function titleFrameSource({ width, height, params }) {
const { text, textColor = '#ffffff', fontFamily = defaultFontFamily, position = 'center', zoomDirection = 'in', zoomAmount = 0.2 } = params;
const { text, textColor = '#ffffff', fontFamily = defaultFontFamily, position = 'center', zoomDirection = 'in', zoomAmount = 0.2, splitByGrapheme } = params;

async function onRender(progress, canvas) {
// console.log('progress', progress);
Expand All @@ -278,6 +278,7 @@ export async function titleFrameSource({ width, height, params }) {

const textBox = new fabric.Textbox(text, {
fill: textColor,
splitByGrapheme,
fontFamily,
fontSize,
textAlign: 'center',
Expand Down