Skip to content

Commit

Permalink
Fix embedded fonts code if no fonts are available
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasf committed Jan 3, 2025
1 parent 0994926 commit a6ba012
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
30 changes: 16 additions & 14 deletions Source/AttachedFileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ class AttachedFileHelper
}

std::vector<std::shared_ptr<AttachedFile>> AttachedFiles() { return attachedFiles; }
winrt::hstring InstanceId() { return instanceId; }
winrt::hstring InstanceId()
{
if (this->instanceId.empty())
{
GUID gdn;
auto hr = CoCreateGuid(&gdn);
if (FAILED(hr))
{
winrt::throw_hresult(hr);
}
instanceId = winrt::to_hstring(winrt::guid(gdn));
}
return instanceId;
}

void AddAttachedFile(std::shared_ptr<AttachedFile> const& file)
{
Expand All @@ -47,20 +60,9 @@ class AttachedFileHelper
}
else
{
if (this->instanceId.empty())
{
GUID gdn;
auto hr = CoCreateGuid(&gdn);
if (FAILED(hr))
{
winrt::throw_hresult(hr);
}
instanceId = winrt::to_hstring(winrt::guid(gdn));
}

auto folder = co_await ApplicationData::Current().TemporaryFolder().CreateFolderAsync(
config.General().AttachmentCacheFolderName(), CreationCollisionOption::OpenIfExists);
auto instanceFolder = co_await folder.CreateFolderAsync(instanceId, CreationCollisionOption::OpenIfExists);
auto instanceFolder = co_await folder.CreateFolderAsync(InstanceId(), CreationCollisionOption::OpenIfExists);
file = (co_await instanceFolder.CreateFileAsync(attachment->Name(), CreationCollisionOption::ReplaceExisting));
co_await FileIO::WriteBufferAsync(file, attachment->GetBuffer());

Expand Down Expand Up @@ -92,7 +94,7 @@ class AttachedFileHelper
{
auto folder = co_await ApplicationData::Current().TemporaryFolder().CreateFolderAsync(
config.General().AttachmentCacheFolderName(), CreationCollisionOption::OpenIfExists);
auto instanceFolder = co_await folder.CreateFolderAsync(instanceId, CreationCollisionOption::OpenIfExists);
auto instanceFolder = co_await folder.CreateFolderAsync(InstanceId(), CreationCollisionOption::OpenIfExists);
co_return instanceFolder;
}

Expand Down
16 changes: 11 additions & 5 deletions Source/SubtitleProviderLibass.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SubtitleProviderLibass : public SubtitleProvider

virtual SoftwareBitmap RenderSubtitles(winrt::Windows::Foundation::TimeSpan videoPosition, Size const& renderSize) override
{
std::lock_guard lock(mutex);
if (!assRenderer)
return GetDummyBitmap();

Expand Down Expand Up @@ -470,10 +471,12 @@ class SubtitleProviderLibass : public SubtitleProvider
void SetFonts()
{
try {
ExtractFonts();
/*auto fontFolder = attachedFileHelper->GetInstanceFolder().get();
auto fontDirectory = StringUtils::PlatformStringToUtf8String(fontFolder.Path());
ass_set_fonts_dir(assLibrary, fontDirectory.data());*/
if (ExtractFonts())
{
auto fontFolder = attachedFileHelper->GetInstanceFolder().get();
auto fontDirectory = StringUtils::PlatformStringToUtf8String(fontFolder.Path());
ass_set_fonts_dir(assLibrary, fontDirectory.data());
}
ass_set_fonts(assRenderer, NULL, "Segoe UI", ASS_FONTPROVIDER_AUTODETECT, nullptr, 0);
}
catch (exception e)
Expand All @@ -483,8 +486,9 @@ class SubtitleProviderLibass : public SubtitleProvider
}


void ExtractFonts()
bool ExtractFonts()
{
bool hasFonts = false;
try
{
if (m_config.Subtitles().UseEmbeddedSubtitleFonts())
Expand All @@ -495,13 +499,15 @@ class SubtitleProviderLibass : public SubtitleProvider
if (mime.find(L"font") != mime.npos)
{
attachedFileHelper->ExtractFileAsync(attachment).get();
hasFonts = true;
}
}
}
}
catch (...)
{
}
return hasFonts;
}


Expand Down

0 comments on commit a6ba012

Please sign in to comment.