Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

GraphemeClusterSample

Unicode grapheme cluster and east asian width implementations and samples for Delphi.

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

# GraphemeClusterSample https://github.com/owlsperspective/GraphemeClusterSample

概要

  • DelphiでUnicode Standard Annex #11 East Asian Width(UAX #11)を実装します。
  • EastAsianWidthConverterはUnicode Inc.の提供するデータベースファイル(EastAsianWidth.txt)をDelphiのコード上から参照できるように変換します。
  • GraphemeClusterTestはDelphiの正規表現ライブラリ(PCRE)およびSkia4Delphiによる書記素クラスタの分割と、表示文字幅の計算を行うサンプルプログラムです。

実行環境

  • サンプルプログラムはVCLで作られており、Windows上で動作します。
  • Unicode.EastAsianWidthユニットおよび生成されたEastAsianWidth.incはDelphiが動作するすべてのプラットフォームで動作します。

開発環境

使用方法

EastAsianWidth.incの生成

  • DelphiのIDEでEastAsianWidthConverter.dprを開きます。
  • UnicodeのwebサイトからEastAsianWidth.txtをダウンロードしてプロジェクトフォルダの直下に配置します。最新版は以下のURLにあります。
  • プロジェクトEastAsianWidthConverterをコンパイルし、実行します。
  • Source、Outputが正しく設定されていることを確認し、"Convert"ボタンをクリックします。
  • EastAsianWidth.txtからEastAsianWidth.incが生成され、その内容がMemoに表示されます。

サンプルプログラムの実行

  • Delphi 11 Alexandriaおよびそれ以前のバージョンではあらかじめSkia4Delphiをインストールしておきます。
  • DelphiのIDEでGraphemeClusterTest.dprを開きます。
  • プロジェクトツールウィンドウでプロジェクトを右クリック→"Skiaを有効化"を選択します。
  • コンパイル、実行します。
  • RegExボタンをクリックすると正規表現ライブラリ(PCRE)で、SkiaボタンをクリックするとSkia4Delphiで、書記素クラスタの分割が行われ、文字列のコードポイント数(L)と表示幅(W)が表示されます。

Unicode.EastAsianWidthユニットの使用

  • Unicode.EastAsianWidth.pasとEastAsianWidth.incは同じフォルダに配置します。
  • 使用したいプロジェクトにUnicode.EastAsianWidth.pasを追加し、参照するユニットのusesにUnicode.EastAsianWidthを追加します。
  • class function TEastAsianWidth.GetEastAsianWidthにUCS4で文字を渡すとTEastAsianWidthが返されます。
  • function TEastAsianWidth.GetWidthで文字幅を取得できます。
  • "Ambiguous"を欧文フォントなどで半角幅として扱いたいときはclass property TEastAsianWidth.EastAsianをFalseに、日本語フォントなどで全角幅として扱いたいときはTrueに設定します。

ライセンス

このプログラムに固有のコードについてはMITライセンスが適用されます。

Copyright 2023 Owl's Perspective

The MIT License – Open Source Initiative

https://opensource.org/license/mit/

(日本語参考訳)

https://licenses.opensource.jp/MIT/MIT.html

Skia4DelphiはMITライセンスの元で公開されています。

https://github.com/skia4delphi/skia4delphi/blob/main/LICENSE

UnicodeのデータベースはUNICODE LICENSE V3の元で公開されています。

https://www.unicode.org/license.txt

更新履歴

  • 2023-12-27 新規作成