Skip to content

Commit 60dfc53

Browse files
committed
Font::getGlyphByGlyphIndex(GlyphIndex) #1278
1 parent 6d2de52 commit 60dfc53

File tree

7 files changed

+35
-0
lines changed

7 files changed

+35
-0
lines changed

Siv3D/include/Siv3D/Font.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ namespace s3d
423423
[[nodiscard]]
424424
Glyph getGlyph(StringView ch) const;
425425

426+
/// @brief 指定した文字の描画用のグリフを返します。
427+
/// @param glyphIndex 文字のグリフインデックス
428+
/// @return 描画用グリフ
429+
[[nodiscard]]
430+
Glyph getGlyphByGlyphIndex(GlyphIndex glyphIndex) const;
431+
426432
/// @brief 指定した文字列の描画用のグリフ配列を返します。
427433
/// @param s 文字列
428434
/// @param ligature リガチャ(合字)を有効にするか

Siv3D/src/Siv3D/Font/CFont.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ namespace s3d
372372
return glyph;
373373
}
374374

375+
Glyph CFont::getGlyphByGlyphIndex(const Font::IDType handleID, const GlyphIndex glyphIndex)
376+
{
377+
const auto& font = m_fonts[handleID];
378+
Glyph glyph{ font->getGlyphInfoByGlyphIndex(glyphIndex) };
379+
glyph.codePoint = 0; // 逆引きは不可能(1 つのグリフが複数のコードポイントを持つ場合があるため)
380+
glyph.texture = font->getGlyphCache().getTextureRegion(*font, glyph.glyphIndex);
381+
glyph.buffer = font->getGlyphCache().getBufferThickness(glyph.glyphIndex);
382+
return glyph;
383+
}
384+
375385
Array<Glyph> CFont::getGlyphs(const Font::IDType handleID, const StringView s, const Ligature ligature)
376386
{
377387
const auto& font = m_fonts[handleID];

Siv3D/src/Siv3D/Font/CFont.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ namespace s3d
111111

112112
Glyph getGlyph(Font::IDType handleID, StringView ch) override;
113113

114+
Glyph getGlyphByGlyphIndex(Font::IDType handleID, GlyphIndex glyphIndex) override;
115+
114116
Array<Glyph> getGlyphs(Font::IDType handleID, StringView s, Ligature ligature) override;
115117

116118
Array<double> getXAdvances(Font::IDType handleID, StringView s, const Array<GlyphCluster>& clusters, double fontSize) override;

Siv3D/src/Siv3D/Font/CFont_Headless.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ namespace s3d
286286
return glyph;
287287
}
288288

289+
Glyph CFont_Headless::getGlyphByGlyphIndex(const Font::IDType handleID, const GlyphIndex glyphIndex)
290+
{
291+
const auto& font = m_fonts[handleID];
292+
Glyph glyph{ font->getGlyphInfoByGlyphIndex(glyphIndex) };
293+
glyph.codePoint = 0; // 逆引きは不可能(1 つのグリフが複数のコードポイントを持つ場合があるため)
294+
return glyph;
295+
}
296+
289297
Array<Glyph> CFont_Headless::getGlyphs(const Font::IDType handleID, const StringView s, const Ligature ligature)
290298
{
291299
const auto& font = m_fonts[handleID];

Siv3D/src/Siv3D/Font/CFont_Headless.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ namespace s3d
9191

9292
Glyph getGlyph(Font::IDType handleID, StringView ch) override;
9393

94+
Glyph getGlyphByGlyphIndex(Font::IDType handleID, GlyphIndex glyphIndex) override;
95+
9496
Array<Glyph> getGlyphs(Font::IDType handleID, StringView s, Ligature ligature) override;
9597

9698
Array<double> getXAdvances(Font::IDType handleID, StringView s, const Array<GlyphCluster>& clusters, double fontSize) override;

Siv3D/src/Siv3D/Font/IFont.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ namespace s3d
8787
virtual const Texture& getTexture(Font::IDType handleID) = 0;
8888

8989
virtual Glyph getGlyph(Font::IDType handleID, StringView ch) = 0;
90+
91+
virtual Glyph getGlyphByGlyphIndex(Font::IDType handleID, GlyphIndex glyphIndex) = 0;
9092

9193
virtual Array<Glyph> getGlyphs(Font::IDType handleID, StringView s, Ligature ligature) = 0;
9294

Siv3D/src/Siv3D/Font/SivFont.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ namespace s3d
413413
return SIV3D_ENGINE(Font)->getGlyph(m_handle->id(), ch);
414414
}
415415

416+
Glyph Font::getGlyphByGlyphIndex(GlyphIndex glyphIndex) const
417+
{
418+
return SIV3D_ENGINE(Font)->getGlyphByGlyphIndex(m_handle->id(), glyphIndex);
419+
}
420+
416421
Array<Glyph> Font::getGlyphs(const StringView s, const Ligature ligature) const
417422
{
418423
return SIV3D_ENGINE(Font)->getGlyphs(m_handle->id(), s, ligature);

0 commit comments

Comments
 (0)