diff options
author | luigiiucci <luigi.iucci@collabora.com> | 2023-06-13 22:10:00 +0200 |
---|---|---|
committer | خالد حسني <khaled@libreoffice.org> | 2023-06-19 15:33:24 +0200 |
commit | e7c885389bfb9387acf8a21ea38769e678a76aac (patch) | |
tree | ab885d4b9086a6bc1735ffcf3c90fd9388c3c1a5 /vcl | |
parent | d47b37eea9779e3c354e6c19a7211a306965b7ef (diff) |
tdf#155486 Adding fonts to .odt when there is "no perfect match"
Problem does not seem to have any
relation with .otf files management.
Problem arises when:
- we use a font with setting certain
family/bold/italic/pitch values
- we have this font installed, but
we don't have a version with
matching
family/bold/italic/pitch
In this case the "not a perfect match"
fonts were not saved in the .odt
Change-Id: Ie4e2b9c34b79ac99f03c57bed4fdc5f4d718dcc2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153007
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/embeddedfontshelper.cxx | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index aeb30aa20dee..afddbf41387c 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -261,6 +261,15 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF graphics->GetDevFontList( &fonts ); std::unique_ptr< vcl::font::PhysicalFontFaceCollection > fontInfo( fonts.GetFontFaceCollection()); vcl::font::PhysicalFontFace* selected = nullptr; + + // Maybe we don't find the perfect match for the font. E.G. we have fonts with the same family name + // but not same bold or italic etc.. + // In this case we add all the fonts having the family name of tyhe used font: + // - we store all these fonts in familyNameFonts during loop + // - if we haven't found the perfect match we store all fonts in familyNameFonts + typedef std::vector<vcl::font::PhysicalFontFace*> FontList; + FontList familyNameFonts; + for( int i = 0; i < fontInfo->Count(); ++i ) @@ -288,11 +297,29 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF { // Some fonts specify 'DONTKNOW' for some things, still a good match, if we don't find a better one. selected = f; } + // adding "not perfact match" to familyNameFonts vector + familyNameFonts.push_back(f); + } } - if( selected != nullptr ) + + // if we have found a perfect match we will add only "selected", otherwise all familyNameFonts + FontList fontsToAdd = (selected ? FontList(1, selected) : std::move(familyNameFonts)); + + for (vcl::font::PhysicalFontFace* f : fontsToAdd) { - auto aFontData(selected->GetRawFontData(0)); + if (!selected) { // recalculate file not for "not perfect match" + filename = OUString::Concat(familyName) + "_" + OUString::number(f->GetFamilyType()) + "_" + + OUString::number(f->GetItalic()) + "_" + OUString::number(f->GetWeight()) + "_" + + OUString::number(f->GetPitch()) + ".ttf"; // TODO is it always ttf? + url = path + filename; + if (osl::File(url).open(osl_File_OpenFlag_Read) == osl::File::E_None) // = exists() + { + // File with contents of the font file already exists, assume it's been created by a previous call. + continue; + } + } + auto aFontData(f->GetRawFontData(0)); if (!aFontData.empty()) { auto data = aFontData.data(); |