--- nono/wx/wxtextpanel.cpp 2026/04/29 17:04:37 1.1.1.3 +++ nono/wx/wxtextpanel.cpp 2026/04/29 17:04:39 1.1.1.4 @@ -23,21 +23,18 @@ // テキストフォントを管理するクラス // -static struct fontinfo { - int width; - int height; -} fontinfo[] = { - // 順序はヘッダの FONT_* 識別子の順と揃えること - { 6, 12 }, - { 8, 16 }, +static const wxSize fontinfo[] = { + // 順序はヘッダの FontId_* 識別子の順と揃えること + FONT_6x12, + FONT_8x16, }; -static_assert(countof(fontinfo) == FONT_MAX, ""); +static_assert(countof(fontinfo) == FontId::Max, ""); // コンストラクタ WXTextPanel::WXTextPanel(wxWindow *parent) : inherited(parent, wxID_ANY) { - UpdateFont(global_fontsize); + UpdateFont(global_fontid); // デフォルト色 SetTextColor(*wxBLACK, LIGHT_GREY, wxColour(0x50, 0x50, 0x50)); @@ -46,59 +43,60 @@ WXTextPanel::WXTextPanel(wxWindow *paren // デストラクタ WXTextPanel::~WXTextPanel() { - FreeFont(fontsize); + FreeFont(fontid); } // フォント関連の内部情報をよしなに更新する void -WXTextPanel::UpdateFont(fontsize_t new_fontsize) +WXTextPanel::UpdateFont(FontId new_fontid) { - assert(fontsize != new_fontsize); + assert(fontid != new_fontid); // フォントデータを更新 - FreeFont(fontsize); - AllocFont(new_fontsize); + FreeFont(fontid); + AllocFont(new_fontid); // 内部変数を更新 - fontsize = new_fontsize; - font_width = fontinfo[fontsize].width; - font_height = fontinfo[fontsize].height; - ascii_glyph = ascii_glyph_table[fontsize]; - bold_glyph = bold_glyph_table[fontsize]; + fontid = new_fontid; + fontsize = fontinfo[fontid]; + ascii_glyph = ascii_glyph_table[fontid]; + bold_glyph = bold_glyph_table[fontid]; } // 必要ならフォントを用意する /*static*/ void -WXTextPanel::AllocFont(fontsize_t fontsize) +WXTextPanel::AllocFont(FontId fontid) { const uint8 *base; std::unique_lock lock(global_font_mutex); - if (font_refcnt[fontsize]++ != 0) { + if (font_refcnt[fontid]++ != 0) { return; } // 6x12, 8x16 半角は X68030 CGROM にあるのでそれを使う - switch (fontsize) { - case FONT_6x12: + switch (fontid) { + case FontId::_6x12: base = BuiltinCGROM::Get6x12(); break; - case FONT_8x16: + case FontId::_8x16: base = BuiltinCGROM::Get8x16(); break; default: - assertmsg(0, "fontsize=%d", fontsize); + assertmsg(0, "fontid=%d", fontid); } - // フォントの行ストライド[byte] - int font_width = fontinfo[fontsize].width; - int font_height = fontinfo[fontsize].height; + // フォントの行ストライド[byte] を計算。 + // ここは static 関数内なので WXTextPanel インスタンス内の変数 + // font_width, font_height は見えない。(shadow にもならない) + int font_width = fontinfo[fontid].GetWidth(); + int font_height = fontinfo[fontid].GetHeight(); int font_stride = (font_width + 7) / 8; int bytes = font_stride * font_height; std::vector buf(bytes); - wxBitmap **ascii_glyph = ascii_glyph_table[fontsize]; - wxBitmap **bold_glyph = bold_glyph_table[fontsize]; + wxBitmap **ascii_glyph = ascii_glyph_table[fontid]; + wxBitmap **bold_glyph = bold_glyph_table[fontid]; // ASCII というか半角というかは通常 0x7f までだが // X680x0 の CGROM の 0x80, 0x81, 0x82 には '\\', '~', '|' が // 収納されているのでここまで含めてデータを作っておく。 @@ -125,19 +123,19 @@ WXTextPanel::AllocFont(fontsize_t fontsi // 最後の一人ならフォントを解放する /*static*/ void -WXTextPanel::FreeFont(fontsize_t fontsize) +WXTextPanel::FreeFont(FontId fontid) { std::unique_lock lock(global_font_mutex); - if (fontsize < 0 || fontsize >= FONT_MAX) { + if (fontid < 0 || fontid >= FontId::Max) { return; } - if (--font_refcnt[fontsize] != 0) { + if (--font_refcnt[fontid] != 0) { return; } - wxBitmap **ascii_glyph = ascii_glyph_table[fontsize]; - wxBitmap **bold_glyph = bold_glyph_table[fontsize]; + wxBitmap **ascii_glyph = ascii_glyph_table[fontid]; + wxBitmap **bold_glyph = bold_glyph_table[fontid]; for (int i = 0; i < countof(ascii_glyph_table[0]); i++) { if (ascii_glyph[i]) { delete ascii_glyph[i]; @@ -286,11 +284,11 @@ WXTextPanel::KanaBitmap(uint16 sjiscode, { const uint8 *base; // X680x0 CGROM - switch (fontsize) { - case FONT_6x12: + switch (fontid) { + case FontId::_6x12: base = BuiltinCGROM::Get6x12(); break; - case FONT_8x16: + case FontId::_8x16: base = BuiltinCGROM::Get8x16(); break; default: @@ -354,12 +352,12 @@ WXTextPanel::KanjiBitmap(uint16 sjiscode // フォント領域 const uint8 *base; - switch (fontsize) { - case FONT_6x12: + switch (fontid) { + case FontId::_6x12: // 12x12 は内蔵フォントデータ base = builtin_kanji12; break; - case FONT_8x16: + case FontId::_8x16: // 16x16 は X680x0 CGROM のを使う。 base = BuiltinCGROM::Get16x16(); break; @@ -388,8 +386,8 @@ WXTextPanel::KanjiBitmap(uint16 sjiscode } // スタティック変数 -fontsize_t WXTextPanel::global_fontsize; +FontId WXTextPanel::global_fontid; std::mutex WXTextPanel::global_font_mutex; -u_int WXTextPanel::font_refcnt[FONT_MAX]; -wxBitmap *WXTextPanel::ascii_glyph_table[FONT_MAX][0x83]; -wxBitmap *WXTextPanel::bold_glyph_table[FONT_MAX][0x83]; +u_int WXTextPanel::font_refcnt[FontId::Max]; +wxBitmap *WXTextPanel::ascii_glyph_table[FontId::Max][0x83]; +wxBitmap *WXTextPanel::bold_glyph_table[FontId::Max][0x83];