Categories
AE

[익스프레션] 포인트텍스트 기준 문장 나누기

타입 1

const layerNameNum = parseInt(thisLayer.name.replace(/[^0-9]/g, ""));
const totalText = thisComp.layer("Text_" + layerNameNum).text.sourceText;
const pointTextArray = thisComp.layer("PointText_" + layerNameNum).text.sourceText.split("$$");

function splitTextByWords(text, words) {
let currentIndex = 0;
const result = [];

for (const word of words) {
const index = text.indexOf(word, currentIndex);
if (index !== -1) {
const preWord = text.substring(currentIndex, index).trim();
if (preWord !== '') result.push(preWord);
result.push(word);
currentIndex = index + word.length;
}
}

// 마지막 단어 이후의 텍스트를 결과에 추가
if (currentIndex < text.length) {
const lastText = text.substring(currentIndex).trim();
if (lastText !== '') result.push(lastText);
}

return result;
}

const thisLayerRenderText = splitTextByWords(totalText, pointTextArray);


[thisLayerRenderText]

타입 2

const layerNameNum = parseInt(thisLayer.name.replace(/[^0-9]/g, ""));
const totalText = thisComp.layer("Text_" + layerNameNum).text.sourceText;
const pointTextArray = thisComp.layer("PointText_" + layerNameNum).text.sourceText.split("$$");

// splitTextByWords 함수 정의
function splitTextByWords(text, words) {
let result = [];
let currentIndex = 0;

for (let i = 0; i < words.length; i++) {
const word = words[i];
const index = text.indexOf(word, currentIndex);

if (index !== -1) {
// 단어 이전의 텍스트를 결과에 추가
if (index > currentIndex) {
result.push(text.substring(currentIndex, index).trim());
}
result.push(word);
currentIndex = index + word.length;
}
// 해당 단어가 발견되지 않았을 때는 다음 단어를 찾기 위해 현재 인덱스를 유지
}

// 마지막 단어 이후의 텍스트를 결과에 추가
if (currentIndex < text.length) {
result.push(text.substring(currentIndex).trim());
}

// 결과 배열에서 빈 문자열을 필터링하여 반환
return result.filter(word => word !== "");
}

// 결과 계산
const thisLayerRenderText = splitTextByWords(totalText, pointTextArray);
[thisLayerRenderText]

포지션

const layerNameNum = parseInt(thisLayer.name.replace(/[^0-9]/g, ""))-1;
const totalText = thisComp.layer("Text_1").text.sourceText.toString();
const thisLayerText = thisLayer.text.sourceText.toString();

baseTextLayer = thisComp.layer("SecondLine_Render_Text_" + layerNameNum);
baseTextXPosition = baseTextLayer.transform.position[0];
baseTextWidth = baseTextLayer.sourceRectAtTime().width;

spaceBlankWidth = thisComp.layer("Control_Text_1").effect("Space_Blank_Width")("Slider");
spaceDefaultWidth = thisComp.layer("Control_Text_1").effect("Space_Default_Width")("Slider");

const checkSpaceBefore = (totalCheckText, word) => {
const thisTextindex = totalCheckText.indexOf(word);
return thisTextindex > 0 && totalCheckText[thisTextindex - 1] === ' ';
};

const spaceBefore = checkSpaceBefore(totalText, thisLayerText);

if (spaceBefore === true) {
x = baseTextXPosition + baseTextWidth + spaceBlankWidth;
} else {
x = baseTextXPosition + baseTextWidth + spaceDefaultWidth;
}

[x, baseTextLayer.transform.position[1]]

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다