따라쟁이

승근이의 LifeLog – We learn many things by imitation!

@font-face rule

one comment

@font-face는 새로운 font-family를 생성하는 CSS rule로, 이를 이용하면 local이 아닌 remote server 상에 있는 폰트로 웹 페이지를 렌더링 할 수 있습니다. 원래는 Internet Explorer 4에서부터 독자적으로 지원했었던 기능이었지만, CSS 3에서 공식적으로 채택되어 현재 Firefox 3.5, Safari 3.1, Opera 10에서도 지원하고 있습니다. 다만 IE에서는 Embedded OpenType (EOT) 포맷만을 지원하고 있고, 최근에 지원하기 시작한 FF, Safari, Opera의 경우 TrueType과 OpenType만을 지원하고 있습니다.

Syntax

font-face를 정의하는 syntax는 다음과 같고,

@font-face {
font-family: <a-font-name>;
src: <source> [,<source>]*;
[font-weight: <weight>];
[font-style: <style>];
[unicode-range: <U+nnn-nnn> [,<U+nnn-nnn>]*];
}

실제 사용은 다음과 같이 합니다. @font-face에서 명시한 font-family를 일반적인 폰트 이름처럼 사용하면 됩니다.

@font-face {
font-family: Graublau Sans Web;
src: url(GraublauWeb.otf) format("opentype");
}
body {
font-family: Graublau Sans Web, Lucida Grande, sans-serif;
}

새로 알게된 내용들

local hint : src descriptor에는 서버에 있는 폰트 url을 명시하는 url hint 외에도 local hint를 이용해서 로컬에 있는 폰트를 지정할 수 있습니다. 또한 소스를 하나 이상 명시할 수 있습니다. 이들을 사용하는 이유는, 해당 폰트가 설치되어 있으면 설치된 폰트를 사용하고 그렇지 않은 경우에만 다운로드 받도록 하기 위함입니다.

@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue"),
local("HelveticaNeue"),
url(MgOpenModernaRegular.ttf);
}

format hint : 여러 가지 유형의 폰트를 지원할 수 있으므로 source의 포맷을 명시하는 format hint 키워드가 있습니다. CSS Fonts Module Level 3(W3C Working Draft 18 June 2009) 문서에서는 “truetype”, “opentype”, “truetype-aat”, “embedded-opentype”, “svg”를 예제로 들고 있는데, 실제 브라우저에 따라 지원의 차이가 있을 수 있고 또 다른 포맷이 생길수도 있습니다. 참고로 IE에서는 format hint를 인식하지 못하며 포함된 경우 이를 무시하게 됩니다.

@font-face {
font-family: Gentium;
src: url(Gentium.ttf) format("opentype");
}

Cross Browsed @font-face

IE의 경우 eot 파일을, 그 외 브라우저(위에서 언급한 것들)에서는 TrueType 및 OpenType만을 지원하므로 크로스 브라우징이 가능하게끔 코딩을 해야 합니다. 앞서 언급한 src descriptor의 format hint를 이용하여 다음과 같이 코딩할 수 있습니다. 다음 코드에서 어떤 @font-face를 먼저 코딩하는지가 중요합니다.

@font-face { /* for IE */
font-family: Gentium;
src: url('Gentium.eot');
}
@font-face { /* for non-IE */
font-family: Gentium;
src: url('Gentium.ttf') format('opentype');
}

Ajaxian의 @font-face: How to embed it, and how it looks across browsers에서는 하나의 @font-face에 src descriptor를 두 번 선언해서 사용하고 있습니다. 이런식으로도 가능하다면 위 코드는 다음과 같이 변경할 수 있습니다.

@font-face {
font-family: Gentium;
src: url('Gentium.eot');
src: url('Gentium.ttf') format('opentype');
}

Bulletproof @font-face syntax

Bulletproof @font-face syntax을 읽고 추가한 사항입니다.

위의 Cross Browsed @font-face 단락에서 제시한 방법 모두 겉으로 보기에는 크로스 브라우징에는 문제가 없으나, IE에서 조금 이상한 request가 발생하는 문제(?)가 있습니다. IE에서는 먼저 Gentium.eot 파일을 요청(HTTP request)하고 다음번 src에 대해서는 Gentium.ttf’)%20format(’opentype 로 요청을 발생시킴니다. IE가 src를 파싱하는 구조때문인것으로 보이는데 이 경우 404 응답(response)이 올 것입니다.

다음 코드는 이러한 문제를 해결하기 위한 것으로 ttf를 요청할 때 반드시 local hint를 먼저 입력하는 방식입니다. 이 방식은 non-IE 브라우저에서는 로컬에 설치된 경우 이를 사용할 수 있다는 장점이 있으며, IE에서는 local hint 자체를 인식하지 못하므로 파싱 오류가 발생할 것이고 어떤 요청도 하지 않게 됩니다. 참고로 local hint가 2번 사용된 것은 OS X의 Safari에서는 전체 폰트 이름과 Postscript 이름이 틀린 경우 Postscript 이름만을 사용하기 때문에 이를 추가해 준 것입니다(두번째 local hint에 있는 이름).

@font-face {
font-family: 'Graublau Web';
src: url('GraublauWeb.eot);
src: local('Graublau Web Regular'), local('Graublau Web'),
url('GraublauWeb.otf') format('opentype');
}

다음과 같은 방식으로도 불필요한 요청(request)이 발생하지 않게 할 수 있다고 하지만 너무 tricky한 코드라 사용하지 않는게 좋을듯 하네요.

@font-face{
font-family:'Graublau Web';
src: url('GraublauWeb.eot'); /* here you go, IE */
}
@font-face{
font-family:'Graublau Web';
src: url(//:) format ('no404'), url('GraublauWeb.otf') format('opentype'); /* tricky! */
}

의문 사항

font-weight, font-style: font-weightfont-style을 지정할 경우 해당 font-family는 한가지 스타일만을 가질 수 있는 것일까요?

unicode-range 지원 : CSS Fonts Module Level 3(W3C Working Draft 18 June 2009) 문서에서는 존재하지만 MDCMSDN에서는 찾아볼 수 없습니다. 만일 Firefox에서 지원하고, font-family 글에서 언급한 동작방식을 고려한다면 한글과 영문 폰트를 css font-family에 명시되는 순서에 무관하게 사용할 수 있을것 같습니다.

References

본 문서에 나온 예제 코드들은 모두 아래의 문서들에서 가져온 것들입니다.

Written by suguni

October 25th, 2009 at 12:06 am

Posted in Front-end

XMind default style 변경

leave a comment

MS Windows에서 설정 파일 경로
C:\Program Files\XMind\plugins\org.xmind.ui.resources_3.0.1.200812152237\styles\defaultStyles.xml
참조
Google Groups XMind User Forum – default settings

Written by suguni

September 7th, 2009 at 11:46 am

Posted in 생활

Tagged with

Babel fish

leave a comment

The Babel Fish is small, yellow, leech-like, and is a universal translator which simultaneously translates from one spoken language to another. When inserted into the ear, its nutrition processes convert sound waves into brain waves, neatly crossing the language divide between any species you should happen to meet whilst travelling in space. Meanwhile, the poor Babel fish, by effectively removing all barriers to communication between different races and cultures, has caused more and bloodier wars than anything else in the history of creation. Arthur Dent, a surviving Earthling, commented only ‘Eurgh!’ when first inserting the fish into his ear canal. It did, however, enable him to understand Vogon Poetry – not necessarily a good thing. The book points out that the Babel Fish could not possibly have developed naturally, and therefore proves the existence of God as its creator. However, as Man points out, God needs faith to exist, and this proof dispels the need for faith, therefore causing God to vanish “in a puff of logic”.

From Wikipedia – List of races and species in The Hitchhiker’s Guide to the Galaxy

Written by suguni

July 11th, 2009 at 3:20 pm

Posted in 생활

More – IE6 bug : Horizontal scroll bar in frame.

leave a comment

제목은 NARADESIGN:BLOG포스트 제목을 그대로 채용한 것입니다.

위 포스트에서 제시한 “적당한 문제 해결 방법”을 사용할 경우 가장 치명적인 문제는, frame 문서 내에 absolute position 된 요소가 있을 경우 이 요소가 스크롤을 덮는다는 것입니다. 다음은 이에 대한 예제 화면.

IE6 - frame bug

그래서 “좀 더 적당한 문제 해결 방법”은 frame의 scroll 속성은 auto로 하고(auto가 기본값이니 scroll 속성은 없어도 됩니다) frame 문서의 css에 다음을 추가하는 것입니다.

html { overflow-y:scroll; }

장접
  • absolute position 요소가 스크롤을 덮는 버그 없어짐
  • 수평 스크롤은 필요시에만 생김
단점
  • 수직 스크롤이 항상 생긴다는 점에서는 원래의 해결 방법과 동일
  • 프레임 내 문서를 수정할 수 없다면 적용할 수 없음

Frameset을 사용하면서 단일 프레임만 보여주는 페이지 구성을 할 경우 필수 적용해야 할 듯 합니다(경험상 ^^). 또 IE에서만 발생하는 문제 및 해결법이니, IE Conditional Comment 혹은 IE css hack을 사용해서 적용하면 되겠습니다.

Written by suguni

May 18th, 2009 at 1:58 am

Posted in Front-end

Tagged with , ,

Structure and Interpretation of Computer Programs

leave a comment

Structure and Interpretation of Computer Programs

올해 목표로 삼은 것 중 하나가 SICP를 모두 읽는 것입니다. 번역본 제목은 컴퓨터 프로그램의 구조와 해석입니다. 처음 이 책을 알게 되었을 때는 원서 가격이 너무 비싸 온라인 문서를 읽으려고 했는데, 이것 저것 핑계 삼아 잘 안되더군요. 그래서 작년 말에 번역본을 구매해서 책꽂이에 꽂아두었다가 이제야 본격적으로 읽고 있습니다. 연습 문제도 대부분 해 보려고 생각하고 있습니다.

SICP 공부 중 연습 문제 관련해서 궁금한점이 있어 검색 중 Eli Bendersky’s website란 블로그를 발견했는데 이분 대단하시네요. 2006년부터 시작해서 각 chapter 별로 review와 함께 exam 에 대한 코드를 포스팅 해 두었습니다. Archive에서 보면 SICP라는 category가 있습니다. 이거 보면 쫙~~~. 1980년생이라는데 올해 30. 적은 나이는 아니지만 저보다 어리다고 생각하니 … 에궁 빨리 읽어야 겠다는… 암튼 저도 Eli Bendersky 따라해볼까 생각중입니다.

상반기에 SICP 다 읽으면 HTDP(How To Design Program)까지 도전해 보려고 했는데, 이건 너무 과한 욕심이었네요. –;;;

참고 자료

Written by suguni

March 30th, 2009 at 10:08 pm

Posted in 생활

Tagged with ,