웹 안전하지 않은 특정 글꼴을 표시하려는 시도가 놀랍게도 상상할 수 없었던 것보다 훨씬 더 어렵다는 것이 입증되었습니다. 나는 폰트를 표시하는 것이 어렵지 않아야하기 때문에 내 코드 또는 일부 이스케이프 오류에 오타가 있다고 가정합니다.지정된 Google 글꼴이 EasleJS 캔버스로 표시되지 않음
된 index.html :
<!doctype html>
<html lang="en">
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="resources/css/main.css">
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script type="text/javascript" src="resources/js/main.js"></script>
</body>
</html>
main.css가 :
@import url("fonts.css");
body {
width: 100%;
height: 100%;
margin: 0px;
}
canvas {
position: absolute;
top: 0px;
left: 0px;
margin: inherit;
}
fonts.css :
@font-face {
font-family: "Muli-Regular";
src: url("https://fonts.googleapis.com/css?family=Muli:400");
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: "Muli-Semi-Bold";
src: url("https://fonts.googleapis.com/css?family=Muli:600");
font-weight: 600;
font-style: normal;
}
@font-face {
font-family: "Muli-Bold";
src: url("https://fonts.googleapis.com/css?family=Muli:700");
font-weight: 700;
font-style: normal;
}
main.js :
const stage = new createjs.Stage("canvas");
stage.canvas.width = window.innerWidth;
stage.canvas.height = window.innerHeight;
const title = new createjs.Text();
title.text = "This is my text to display";
title.font = "50px Muli-Regular";
title.color = "#000000";
stage.addChild(title);
stage.update();
결과 : (이 올바른 글꼴 없음)
Google 웹 글꼴을 다운로드하고 작동하는 CSS 파일을 생성하여 서버없이 이러한 글꼴을 사용하려면 http://www.localfont.com을 사용했습니다. – TheDarkIn1978