# FontDef

フォント定義と関連する手続きをまとめたクラスです。

このクラスオブジェクトはフォントジェネレータ[`createFont???()`](/0.9-1/references/untitled/twefont/createfont.md)によりライブラリ内部で生成・管理され、ユーザがコンストラクタを用いて直接オブジェクトを生成することはありません。

## メソッド（ユーザ利用）

### get\_width()

```cpp
uint8_t get_width()
uint8_t get_width(uint16_t wc)
```

パラメータを省略した場合は、フォントのシングル幅文字の幅を返します。この値にはフォント生成時に指定した文字間スペースも含まれます。

`wc`を指定した場合は、Unicode `wc`に対応するフォントの幅を返します。日本語などダブル幅のフォントの場合は、シングル幅の２倍の値が戻ります。

### get\_height()

```cpp
uint8_t get_height()
```

フォントの高さを返します。この値にはフォント生成時に指定した行間スペースも含まれます。

### is\_default()

```cpp
bool is_default()
```

デフォルトフォントのオブジェクトである場合 `true` を返します。

{% hint style="info" %}
デフォルトフォントのオブジェクトは[`createFont???()`](/0.9-1/references/untitled/twefont/createfont.md)や[`queryFont()`](/0.9-1/references/untitled/twefont/queryfont.md)のエラー時など例外時にも利用されます。
{% endhint %}

### get\_font\_code()

```cpp
uint8_t get_font_code()
```

フォントIDを取得します。

## メソッド（内部利用）

### find\_font\_index()

```cpp
int find_font_index(uint16_t c)
```

Unicode `c` に対応する、ダブル幅フォント定義配列インデックスを検索します。

戻り値は、字形データが存在する場合は、インデックス配列のインデックス（データ配列のインデックスが計算できる）、存在しない場合は`-1`を返します。

フォント定義は、インデックス配列、データ配列の２つから構成されます。インデックス配列の各値は昇順に並んだ Unicode になっていて、データ配列のインデックスに対応しています。

以下の例ではインデックス配列の IDX=829 が U+5a2f で "娯" という文字です。データ配列の対応する番地を参照すれば、この字形データが格納されています。

```cpp
// インデックス配列 M+10dotフォント
const uint16_t font_mplus_f10j_idx[FONT_MP10_DBL_CHARS] {
  0x0391, // IDX=0 U+0391
  0x0392, // IDX=1 U+0392
  0x0393, // IDX=2 U+0392
  ...
  0x5a2f, // IDX=892 U+5a2f (娯)
  ...
}

// データ配列
const uint8_t font_mplus_f10j_data[FONT_MP10_DBL_CHARS*FONT_MP10_DATA_ROWS*2] = {
  ...
  0x00,0x00,0x47,0x80,0x54,0x80,0xf7,0x80,0x50,0x00,
　  0x5f,0x80,0xa0,0x80,0xff,0x80,0x45,0x00,0x58,0x80, // 3864/u5a2f idx=892
  ...
};

```

インデックス配列内の値は昇順に並ぶよう構成した目的は、本関数で実装されている二分探索を利用するためです。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwm5.twelite.info/0.9-1/references/untitled/twefont/fontdef.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
