summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2020-09-13 15:01:22 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2020-09-15 06:43:42 +0200
commitbdde33ea94b77f50ca58b82bed86d6fcde77749c (patch)
tree3f605a937a3f239a21f588c967ebe543f5d6cd65 /vcl/qt5
parent5ebc5f9df6972ac3d9ce7ed6a1504c48535c0881 (diff)
WIN OSX Qt5 unify CreateFontSubset code
This is basically just some refactoring. Most interestingly the MacOS used to work with 257 glyphs. I couldn't find any explaination for the 256 glyph limit. Sadly the PrintFontManager is out of scope. That needs more inspection. Change-Id: Ibfa0e905f5efeb7d4a609884d64b4ed2615a9d3d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102688 Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de> Tested-by: Jenkins
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/Qt5Graphics_Text.cxx63
1 files changed, 7 insertions, 56 deletions
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index 351bb3023213..de39fc7009b8 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -219,7 +219,6 @@ bool Qt5Graphics::CreateFontSubset(const OUString& rToFile, const PhysicalFontFa
const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
sal_Int32* pGlyphWidths, int nGlyphCount, FontSubsetInfo& rInfo)
{
- // prepare the requested file name for writing the font-subset file
OUString aSysPath;
if (osl_File_E_None != osl_getSystemPathFromFileURL(rToFile.pData, &aSysPath.pData))
return false;
@@ -228,23 +227,16 @@ bool Qt5Graphics::CreateFontSubset(const OUString& rToFile, const PhysicalFontFa
const Qt5FontFace* pQt5FontFace = static_cast<const Qt5FontFace*>(pFontFace);
const QFont aFont = pQt5FontFace->CreateFont();
const QRawFont aRawFont(QRawFont::fromFont(aFont));
- const QFontInfo aFontInfo(aFont);
const OString aToFile(OUStringToOString(aSysPath, osl_getThreadTextEncoding()));
- const int nOrigGlyphCount = nGlyphCount;
+ // handle CFF-subsetting
QByteArray aCFFtable = aRawFont.fontTable("CFF ");
if (!aCFFtable.isEmpty())
- {
- FILE* pOutFile = fopen(aToFile.getStr(), "wb");
- rInfo.LoadFont(FontType::CFF_FONT, reinterpret_cast<const sal_uInt8*>(aCFFtable.data()),
- aCFFtable.size());
- bool bRet = rInfo.CreateFontSubset(FontType::TYPE1_PFB, pOutFile, nullptr, pGlyphIds,
- pEncoding, nGlyphCount, pGlyphWidths);
- fclose(pOutFile);
- return bRet;
- }
+ return SalGraphics::CreateCFFfontSubset(
+ reinterpret_cast<const sal_uInt8*>(aCFFtable.data()), aCFFtable.size(), aToFile,
+ pGlyphIds, pEncoding, pGlyphWidths, nGlyphCount, rInfo);
- // get details about the subsetted font
+ // fill details about the subsetted font
rInfo.m_nFontType = FontType::SFNT_TTF;
rInfo.m_aPSName = toOUString(aRawFont.familyName());
rInfo.m_nCapHeight = aRawFont.capHeight();
@@ -257,49 +249,8 @@ bool Qt5Graphics::CreateFontSubset(const OUString& rToFile, const PhysicalFontFa
if (GetTTGlobalFontHeadInfo(&aTTF, nXmin, nYmin, nXmax, nYmax, nMacStyleFlags))
rInfo.m_aFontBBox = tools::Rectangle(Point(nXmin, nYmin), Point(nXmax, nYmax));
- sal_uInt16 aShortIDs[nGlyphCount + 1];
- sal_uInt8 aTempEncs[nGlyphCount + 1];
-
- int nNotDef = -1;
-
- for (int i = 0; i < nGlyphCount; ++i)
- {
- aTempEncs[i] = pEncoding[i];
-
- sal_GlyphId aGlyphId(pGlyphIds[i]);
- aShortIDs[i] = static_cast<sal_uInt16>(aGlyphId);
- if (!aGlyphId && nNotDef < 0)
- nNotDef = i; // first NotDef glyph found
- }
-
- if (nNotDef != 0)
- {
- // add fake NotDef glyph if needed
- if (nNotDef < 0)
- nNotDef = nGlyphCount++;
- // NotDef glyph must be in pos 0 => swap glyphids
- aShortIDs[nNotDef] = aShortIDs[0];
- aTempEncs[nNotDef] = aTempEncs[0];
- aShortIDs[0] = 0;
- aTempEncs[0] = 0;
- }
-
- std::unique_ptr<sal_uInt16[]> pGlyphMetrics
- = GetTTSimpleGlyphMetrics(&aTTF, aShortIDs, nGlyphCount, false);
- if (!pGlyphMetrics)
- return false;
-
- sal_uInt16 nNotDefAdv = pGlyphMetrics[0];
- pGlyphMetrics[0] = pGlyphMetrics[nNotDef];
- pGlyphMetrics[nNotDef] = nNotDefAdv;
-
- for (int i = 0; i < nOrigGlyphCount; ++i)
- pGlyphWidths[i] = pGlyphMetrics[i];
-
- // write subset into destination file
- vcl::SFErrCodes nRC
- = vcl::CreateTTFromTTGlyphs(&aTTF, aToFile.getStr(), aShortIDs, aTempEncs, nGlyphCount);
- return (nRC == vcl::SFErrCodes::Ok);
+ return SalGraphics::CreateTTFfontSubset(aTTF, aToFile, false /* use FontSelectPattern? */,
+ pGlyphIds, pEncoding, pGlyphWidths, nGlyphCount);
}
const void* Qt5Graphics::GetEmbedFontData(const PhysicalFontFace*, long* /*pDataLen*/)