diff options
author | luigiiucci <luigi.iucci@collabora.com> | 2023-06-13 22:10:00 +0200 |
---|---|---|
committer | Aron Budea <aron.budea@collabora.com> | 2023-07-06 23:27:04 +0200 |
commit | 4da8ce44a6e6a41d1506ba9087c28896c36a2722 (patch) | |
tree | 8abfdbf97daaef44f3b159abd54e616c51b4836e | |
parent | 689a2e36ebcb7f2184210dcd0abee10cd9fac7d3 (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>
(cherry picked from commit e7c885389bfb9387acf8a21ea38769e678a76aac)
(cherry picked from commit a3a00555d4b0e07ee921f85ac088e7b17047c6cf)
-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 34d227e5f5b2..2ca5ccd3c1b7 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,12 +297,30 @@ 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) { + 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; + } + } tools::Long size; - if (const void* data = graphics->GetEmbedFontData(selected, &size)) + if (const void* data = graphics->GetEmbedFontData(f, &size)) { if( sufficientTTFRights( data, size, rights )) { |