소개
이 랩에서는 전역 글꼴 속성을 설명하는 .FT2Font 객체의 속성에 대해 배우게 됩니다. 또한 .load_char에 의해 반환되는 .Glyph 객체를 사용하여 개별 문자 메트릭을 사용하는 방법도 배우게 됩니다.
VM 팁
VM 시작이 완료되면 왼쪽 상단을 클릭하여 Notebook 탭으로 전환하여 실습을 위해 Jupyter Notebook에 액세스하십시오.
때로는 Jupyter Notebook 이 로딩을 완료하는 데 몇 초 정도 기다려야 할 수 있습니다. Jupyter Notebook 의 제한으로 인해 작업의 유효성 검사는 자동화될 수 없습니다.
학습 중에 문제가 발생하면 Labby 에게 문의하십시오. 세션 후 피드백을 제공해주시면 문제를 즉시 해결해 드리겠습니다.
필요한 라이브러리 가져오기
이 단계에서는 필요한 라이브러리를 가져오겠습니다.
import os
import matplotlib
import matplotlib.ft2font as ft
글꼴 로드
이 단계에서는 작업할 글꼴을 로드합니다. Matplotlib 과 함께 제공되는 글꼴을 사용합니다.
font = ft.FT2Font(
os.path.join(matplotlib.get_data_path(),
'fonts/ttf/DejaVuSans-Oblique.ttf'))
글꼴 속성 출력
이 단계에서는 글꼴의 속성을 출력합니다.
print('Num faces: ', font.num_faces) ## number of faces in file
print('Num glyphs: ', font.num_glyphs) ## number of glyphs in the face
print('Family name:', font.family_name) ## face family name
print('Style name: ', font.style_name) ## face style name
print('PS name: ', font.postscript_name) ## the postscript name
print('Num fixed: ', font.num_fixed_sizes) ## number of embedded bitmaps
추가 글꼴 속성 출력
이 단계에서는 face 가 확장 가능 (scalable) 한 경우에만 사용할 수 있는 추가 글꼴 속성을 출력합니다.
if font.scalable:
## the face global bounding box (xmin, ymin, xmax, ymax)
print('Bbox: ', font.bbox)
## number of font units covered by the EM
print('EM: ', font.units_per_EM)
## the ascender in 26.6 units
print('Ascender: ', font.ascender)
## the descender in 26.6 units
print('Descender: ', font.descender)
## the height in 26.6 units
print('Height: ', font.height)
## maximum horizontal cursor advance
print('Max adv width: ', font.max_advance_width)
## same for vertical layout
print('Max adv height: ', font.max_advance_height)
## vertical position of the underline bar
print('Underline pos: ', font.underline_position)
## vertical thickness of the underline
print('Underline thickness:', font.underline_thickness)
글꼴 스타일 출력
이 단계에서는 글꼴 스타일을 출력합니다.
for style in ('Italic',
'Bold',
'Scalable',
'Fixed sizes',
'Fixed width',
'SFNT',
'Horizontal',
'Vertical',
'Kerning',
'Fast glyphs',
'Multiple masters',
'Glyph names',
'External stream'):
bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
print(f"{style+':':17}", bool(font.style_flags & (1 << bitpos)))
요약
이 랩에서는 전역 글꼴 속성을 설명하는 .FT2Font 객체의 속성에 대해 배웠습니다. 또한 .load_char에 의해 반환되는 .Glyph 객체를 사용하여 개별 문자 메트릭을 사용하는 방법을 배웠습니다.