@@ -1430,19 +1430,19 @@ BackendD3D::AtlasGlyphEntry* BackendD3D::_drawBuiltinGlyph(const RenderingPayloa
14301430 _d2dBeginDrawing ();
14311431
14321432 auto shadingType = ShadingType::TextGrayscale;
1433+ const D2D1_RECT_F r{
1434+ static_cast <f32 >(rect.x ),
1435+ static_cast <f32 >(rect.y ),
1436+ static_cast <f32 >(rect.x + rect.w ),
1437+ static_cast <f32 >(rect.y + rect.h ),
1438+ };
14331439
14341440 if (BuiltinGlyphs::IsSoftFontChar (glyphIndex))
14351441 {
1436- _drawSoftFontGlyph (p, rect , glyphIndex);
1442+ _drawSoftFontGlyph (p, r , glyphIndex);
14371443 }
14381444 else
14391445 {
1440- const D2D1_RECT_F r{
1441- static_cast <f32 >(rect.x ),
1442- static_cast <f32 >(rect.y ),
1443- static_cast <f32 >(rect.x + rect.w ),
1444- static_cast <f32 >(rect.y + rect.h ),
1445- };
14461446 BuiltinGlyphs::DrawBuiltinGlyph (p.d2dFactory .get (), _d2dRenderTarget.get (), _brush.get (), r, glyphIndex);
14471447 shadingType = ShadingType::TextBuiltinGlyph;
14481448 }
@@ -1465,15 +1465,31 @@ BackendD3D::AtlasGlyphEntry* BackendD3D::_drawBuiltinGlyph(const RenderingPayloa
14651465 return glyphEntry;
14661466}
14671467
1468- void BackendD3D::_drawSoftFontGlyph (const RenderingPayload& p, const stbrp_rect & rect, u32 glyphIndex)
1468+ void BackendD3D::_drawSoftFontGlyph (const RenderingPayload& p, const D2D1_RECT_F & rect, u32 glyphIndex)
14691469{
1470+ _d2dRenderTarget->PushAxisAlignedClip (&rect, D2D1_ANTIALIAS_MODE_ALIASED);
1471+ const auto restoreD2D = wil::scope_exit ([&]() {
1472+ _d2dRenderTarget->PopAxisAlignedClip ();
1473+ });
1474+
1475+ const auto width = static_cast <size_t >(p.s ->font ->softFontCellSize .width );
1476+ const auto height = static_cast <size_t >(p.s ->font ->softFontCellSize .height );
1477+ const auto softFontIndex = glyphIndex - 0xEF20u ;
1478+ const auto data = til::clamp_slice_len (p.s ->font ->softFontPattern , height * softFontIndex, height);
1479+
1480+ if (data.empty () || data.size () != height)
1481+ {
1482+ _d2dRenderTarget->Clear ();
1483+ return ;
1484+ }
1485+
14701486 if (!_softFontBitmap)
14711487 {
14721488 // Allocating such a tiny texture is very wasteful (min. texture size on GPUs
1473- // right now is 64kB), but this is a seldomly used feature so it's fine...
1489+ // right now is 64kB), but this is a seldom used feature, so it's fine...
14741490 const D2D1_SIZE_U size{
1475- static_cast <UINT32>(p. s -> font -> softFontCellSize . width ),
1476- static_cast <UINT32>(p. s -> font -> softFontCellSize . height ),
1491+ static_cast <UINT32>(width),
1492+ static_cast <UINT32>(height),
14771493 };
14781494 const D2D1_BITMAP_PROPERTIES1 bitmapProperties{
14791495 .pixelFormat = { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED },
@@ -1484,17 +1500,11 @@ void BackendD3D::_drawSoftFontGlyph(const RenderingPayload& p, const stbrp_rect&
14841500 }
14851501
14861502 {
1487- const auto width = static_cast <size_t >(p.s ->font ->softFontCellSize .width );
1488- const auto height = static_cast <size_t >(p.s ->font ->softFontCellSize .height );
1489-
14901503 auto bitmapData = Buffer<u32 >{ width * height };
1491- const auto softFontIndex = glyphIndex - 0xEF20u ;
1492- auto src = p.s ->font ->softFontPattern .begin () + height * softFontIndex;
14931504 auto dst = bitmapData.begin ();
14941505
1495- for (size_t y = 0 ; y < height; y++ )
1506+ for (auto srcBits : data )
14961507 {
1497- auto srcBits = *src++;
14981508 for (size_t x = 0 ; x < width; x++)
14991509 {
15001510 const auto srcBitIsSet = (srcBits & 0x8000 ) != 0 ;
@@ -1508,15 +1518,7 @@ void BackendD3D::_drawSoftFontGlyph(const RenderingPayload& p, const stbrp_rect&
15081518 }
15091519
15101520 const auto interpolation = p.s ->font ->antialiasingMode == AntialiasingMode::Aliased ? D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR : D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC;
1511- const D2D1_RECT_F dest{
1512- static_cast <f32 >(rect.x ),
1513- static_cast <f32 >(rect.y ),
1514- static_cast <f32 >(rect.x + rect.w ),
1515- static_cast <f32 >(rect.y + rect.h ),
1516- };
1517-
1518- _d2dBeginDrawing ();
1519- _d2dRenderTarget->DrawBitmap (_softFontBitmap.get (), &dest, 1 , interpolation, nullptr , nullptr );
1521+ _d2dRenderTarget->DrawBitmap (_softFontBitmap.get (), &rect, 1 , interpolation, nullptr , nullptr );
15201522}
15211523
15221524void BackendD3D::_drawGlyphAtlasAllocate (const RenderingPayload& p, stbrp_rect& rect)
0 commit comments