Skip to content

Commit 82ceba3

Browse files
committedAug 19, 2024
directvt#571 WIP: Refactoring
1 parent f0544a4 commit 82ceba3

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed
 

‎src/netxs/desktopio/gui.hpp

+16-25
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,11 @@ namespace netxs::gui
590590
}
591591
};
592592

593-
IDWriteFactory2* factory2; // fonts: DWrite factory.
594-
IDWriteFontCollection* fontlist; // fonts: System font collection.
595-
IDWriteTextAnalyzer2* analyzer; // fonts: Glyph indicies reader.
596-
std::thread bgworker; // fonts: Background thread.
593+
ComPtr<IDWriteFactory2> factory2; // fonts: DWrite factory.
594+
ComPtr<IDWriteFontCollection> fontlist; // fonts: System font collection.
595+
ComPtr<IDWriteTextAnalyzer2> analyzer; // fonts: Glyph indicies reader.
596+
std::future<void> bgworker; // fonts: Background fallback reindex.
597597
wide oslocale; // fonts: User locale.
598-
flag complete; // fonts: Fallback index is ready.
599598
shaper fontshaper{ *this }; // fonts: .
600599

601600
static ui16 msscript(ui32 code) // fonts: ISO<->MS script map.
@@ -715,7 +714,7 @@ namespace netxs::gui
715714
};
716715
for (auto& f : fallback) if ((f.color || f.fixed) && hittest(f.fontface[0].face_inst)) return f;
717716
for (auto& f : fallback) if ((!f.color && !f.fixed) && hittest(f.fontface[0].face_inst)) return f;
718-
complete.wait(faux);
717+
if (bgworker.valid()) bgworker.get();
719718
auto try_font = [&](auto i, bool test)
720719
{
721720
auto hit = faux;
@@ -766,12 +765,11 @@ namespace netxs::gui
766765
}
767766

768767
fonts(std::list<text>& family_names, si32 cell_height)
769-
: factory2{ (IDWriteFactory2*)[]{ auto f = (IUnknown*)nullptr; ::DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &f); return f; }() },
770-
fontlist{ [&]{ auto c = (IDWriteFontCollection*)nullptr; factory2->GetSystemFontCollection(&c, TRUE); return c; }() },
771-
analyzer{ [&]{ auto a = (IDWriteTextAnalyzer2*)nullptr; factory2->CreateTextAnalyzer((IDWriteTextAnalyzer**)&a); return a; }() },
772-
oslocale(LOCALE_NAME_MAX_LENGTH, '\0'),
773-
complete{ faux }
768+
: oslocale(LOCALE_NAME_MAX_LENGTH, '\0')
774769
{
770+
::DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), (IUnknown**)factory2.GetAddressOf());
771+
factory2->GetSystemFontCollection(fontlist.GetAddressOf(), TRUE);
772+
factory2->CreateTextAnalyzer((IDWriteTextAnalyzer**)analyzer.GetAddressOf());
775773
fontstat.resize(fontlist ? fontlist->GetFontFamilyCount() : 0);
776774
if (!fontlist || !analyzer)
777775
{
@@ -786,7 +784,7 @@ namespace netxs::gui
786784
log("%%Using default locale 'en-US'.", prompt::gui);
787785
}
788786
oslocale.shrink_to_fit();
789-
bgworker = std::thread{ [&]
787+
bgworker = std::async(std::launch::async, [&]
790788
{
791789
for (auto i = 0u; i < fontstat.size(); i++)
792790
{
@@ -837,10 +835,8 @@ namespace netxs::gui
837835
}
838836
sort();
839837
//for (auto f : fontstat) log("id=", utf::to_hex(f.s), " i= ", f.i, " n=", f.n);
840-
complete.exchange(true);
841-
complete.notify_all();
842838
log("%%Font fallback index initialized.", prompt::gui);
843-
}};
839+
});
844840
if (fallback.empty())
845841
{
846842
auto default_font = std::list{ "Courier New"s };
@@ -854,13 +850,6 @@ namespace netxs::gui
854850
}
855851
set_cellsz(cell_height);
856852
}
857-
~fonts()
858-
{
859-
if (bgworker.joinable()) bgworker.join();
860-
if (analyzer) analyzer->Release();
861-
if (fontlist) fontlist->Release();
862-
if (factory2) factory2->Release();
863-
}
864853
};
865854

866855
#else
@@ -892,7 +881,7 @@ namespace netxs::gui
892881
bool is_monochromatic;
893882
void rasterize_layer_pack(auto& /*glyf_masks*/, auto& /*buffer_pool*/)
894883
{
895-
using irgb = netxs::irgb<fp32>;
884+
//using irgb = netxs::irgb<fp32>;
896885
//...
897886
}
898887
void rasterize_single_layer(auto& /*glyph_mask*/, fp2d /*base_line*/)
@@ -914,7 +903,10 @@ namespace netxs::gui
914903
}
915904
auto take_glyph_run(bool monochromatic, bool aamode, bool is_rtl, twod base_line, fp32 em_height, bool is_box_drawing)
916905
{
917-
auto t = monochromatic || aamode || is_rtl || base_line || em_height || is_box_drawing;
906+
if (monochromatic || aamode || is_rtl || base_line || em_height || is_box_drawing)
907+
{
908+
//...
909+
}
918910
return gr{};
919911
}
920912
};
@@ -1190,7 +1182,6 @@ namespace netxs::gui
11901182
if (alpha == 255) dst = { 0.f, 0.f, 0.f, 256.f + 255.f };
11911183
else if (alpha != 0)
11921184
{
1193-
static constexpr auto kk = (si32)netxs::saturate_cast<byte>(- 256.f);
11941185
auto fgc_alpha = (si32)netxs::saturate_cast<byte>(dst.a - 256.f);
11951186
dst.a = dst.a + (-(si32)dst.a + 256 + alpha + (255 - alpha) * fgc_alpha / 255);
11961187
}

0 commit comments

Comments
 (0)
Please sign in to comment.