연구실(키네틱) 프로젝트

텍스트 생성, 폰트 속성, 텍스트 속성 설정 함수 - javascript

FireStone 2020. 11. 4. 16:31
/////////////////////////////////////////////텍스트 생성 관련/////////////////////////////////////////////
  function ffcreateText (contents, textType){
    var textArray = new Array();
     if (textType == "word") {
        textArray=contents.split(" ")
     } else if (textType == "char") {
        textArray=contents.split("")
        while(true){
           var search = textArray.indexOf(" ");
           if(search!=-1){
              textArray.splice(search,1);
           }else{
              break;
           }
        console.log("gere"+textArray[0]+textArray[1]+textArray[2]);
        }
     } else if (textType == "line") {
        textArray=[contents];
     }
     console.log("textArray "+textArray.length);
     return textArray;
  }

  /////////////////////////////////////////////폰트 속성 관련/////////////////////////////////////////////
  function ffSetFontAttr(target, options) {
     options = options || {};
     var defaults = {
       fontFamily: "맑은 고딕",
        fontSize : 60,
        fontOpacity : 1,
        fontRotation : 0,
       fontStyle: "normal",
       fontWeight: "normal"
     };
     for ( var prop in defaults) {
        options[prop] = typeof options[prop] !== 'undefined' ? options[prop]
              : defaults[prop];
     }

     target.style.color = options.fontColor;
     target.style.fontSize = options.fontSize + 'px';
     target.style.opacity = options.fontOpacity;
     target.style.fontFamily = options.fontFamily;
     target.style.fontStyle = options.fontStyle;
     target.style.fontWeight = options.fontWeight;
     target.style.textShadow = "-" + options.fontOutlineWidth + "px " + "0 " + options.textSpreadWidth + "px " + options.fontOutlineColor + ", " + "0 " + options.fontOutlineWidth + "px " + options.textSpreadWidth + "px " + options.fontOutlineColor + ", " + options.fontOutlineWidth + "px " + "0 " + options.textSpreadWidth + "px " + options.fontOutlineColor + ", " + "0 " + "-" + options.fontOutlineWidth + "px " + options.textSpreadWidth + "px " + options.fontOutlineColor;
  };

  /////////////////////////////////////////////텍스트 속성 관련/////////////////////////////////////////////
  function ffSetTextAttr(target, options) {
     options = options || {};
     var defaults = {
        initX : 0,
        initY : 0,
       textDecoration: "none",
       letterSpacing: 0,
       wordSpacing : 5,
       lineHeight: 10,
       textAlign: "center"
     };
     for ( var prop in defaults) {
        options[prop] = typeof options[prop] !== 'undefined' ? options[prop]
              : defaults[prop];
     }

     target.style.display = 'inline-block';
     target.style.top = options.initY + "px";
     target.style.left = options.initX + 'px';
     target.style.textDecoration = options.textDecoration;
     target.style.textShadow = options.textShadowWidth + "px " + options.textShadowWidth + "px " + options.textShadowColor;
     target.style.letterSpacing = options.letterSpacing + "px";
     target.style.wordSpacing = options.wordSpacing + "px";
     target.style.lineHeight = options.lineHeight + "px";
     target.style.textAlign = options.textAlign;
  };

'연구실(키네틱) 프로젝트' 카테고리의 다른 글

eval 함수 변환 기록  (0) 2020.09.21
예제 만들기-에펙 영상  (0) 2020.04.08
javascript 함수  (0) 2020.03.25
kity.html & js doc  (0) 2020.02.18
FFexample_line_second.js document  (0) 2020.02.18