Home > hanpok

hanpok

Hanpok is a project mainly written in PHP, based on the LGPL-3.0, GPL-3.0 licenses found.

한글, 영문, 숫자 등이 섞인 문자열의 픽셀 폭을 계산하는 클래스

H A N P O K : On-Screen Display Width Calculator for Mixed Korean Text

Web designers in Korea often need to trim text to fit inside a given box. Although Hangeul, the Korean writing system, consists of characters that have identical widths, the calculation gets tricky when alphanumeric symbols are mixed with Korean characters. Designers often underestimate or overestimate the width required to display a given number of bytes or characters, leading to broken layouts and other annoying results.

This library provides a simple means to solve this problem. Given a commonly used font name and size, this library will quickly calculate the number of pixels required to display a string. Even better, one can use this library to trim strings automatically to a given width.

This library requires PHP 5 or later, and PCRE must be installed with support for multibyte strings. (Compile options: --with-pcre-regex --enable-mbregex) Currently, only UTF-8 strings are supported. Don't use EUC-KR with it!

HanPok is free software; it is released under LGPL v3.

Supported fonts:

Gulim, Dotum, Batang, Malgun Gothic
8-12pt (11-16px)

How to use:

$hw = new HanPok('Gulim', '12px');  // normal 9pt
$width = $hw->width($str);
$cut = $hw->cut($str, $max);  // use default end marker: ...

$hw = new HanPok('Gulim', '16px', true);  // bold 12pt
$width = $hw->width($str);
$cut = $hw->cut($str, $max, '~');  // use different end marker

한폭 : 웹 한글 폭 계산기

한국의 웹 개발자들은 주어진 상자의 크기에 맞게 문자열을 표시해야 하는 경우가 종종 있습니다. 대부분의 한글 및 한자은 화면상에서 일정한 폭으로 표시되지만, 영문자, 숫자, 기호 등이 섞이면 화면상의 폭을 예측하기가 매우 어려워집니다. 그 때문에 문자열을 표시하는 데 필요한 픽셀 수를 잘못 계산하여, 글자가 넘치거나 디자인이 깨지는 등의 불상사가 발생합니다.

이 라이브러리는 위와 같은 문제를 해결하는 아주 간단한 방법을 제공합니다. 흔히 사용되는 글꼴과 크기를 지정하면, 주어진 문자열을 표시하는 데 필요한 픽셀 수를 쉽게 계산할 수 있습니다. 또한 주어진 문자열을 일정 픽셀 수 이내로 간단히 자를 수도 있습니다.

이 라이브러리를 사용하려면 PHP 5 또는 상위 버전이 필요하며, 다국어 지원 PCRE가 설치되어 있어야 합니다. (컴파일 옵션: --with-pcre-regex --enable-mbregex) 현재는 UTF-8 인코딩된 문자열만 지원합니다. EUC-KR 인코딩은 지원되지 않습니다.

한폭은 LGPL v3 라이센스 하에 공개된 무료 소프트웨어입니다.

지원되는 글꼴:

굴림, 돋움, 바탕, 맑은 고딕
8-12pt (11-16px)

사용 방법:

$hw = new HanPok('Gulim', '12px');  // normal 9pt
$width = $hw->width($str);
$cut = $hw->cut($str, $max);  // use default end marker: ...

$hw = new HanPok('Gulim', '16px', true);  // bold 12pt
$width = $hw->width($str);
$cut = $hw->cut($str, $max, '~');  // use different end marker
Previous:autolycus