tdf#151039: use the same defaults also for FontSubsetInfo::m_aFontBBox
The defaults for "maFontBBox is not valid" case were already introduced
in commit 2d1f08d63942666c0094904f50ba8c512ab69b9d
Author Release Engineers <releng@openoffice.org>
Date Thu Aug 27 12:02:29 2009 +0000
CWS-TOOLING: integrate CWS otf01
but it used the four elements of maFontBBox unconditionally in later
calculations. Possibly that code path is untested, because unless the
wrong size is greater than 4, it would always crash.
Unfortunately, use of { 0, 0, 0, 0 } here (as Khaled proposed in the
bug, for "garbage in, garbage out" principle) is impossible: the PDF
with such data shows an error in Acrobat Reader: "The font contains
a bad /BBox".
As Khaled mentioned, a better fix would be to use the equivalent font
extents from head table.
Change-Id: I949db23d8af7c1fd4c2362655bf602eea0e70062
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140121
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 1f985cb4779b581a77d419605ceb084707d408b8)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139993
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 7d418ef..fdc210e 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -1801,10 +1801,10 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter,
else // emit default FontMatrix if needed
pOut += sprintf( pOut, "/FontMatrix [0.001 0 0 0.001 0 0]readonly def\n");
// emit FontBBox
if( maFontBBox.size() == 4)
rEmitter.emitValVector( "/FontBBox {", "}readonly def\n", maFontBBox);
else // emit default FontBBox if needed
pOut += sprintf( pOut, "/FontBBox {0 0 999 999}readonly def\n");
auto aFontBBox = maFontBBox;
if (aFontBBox.size() != 4)
aFontBBox = { 0, 0, 999, 999 }; // emit default FontBBox if needed
rEmitter.emitValVector( "/FontBBox {", "}readonly def\n", aFontBBox);
// emit FONTINFO into TOPDICT
pOut += sprintf( pOut,
"/FontInfo 2 dict dup begin\n" // TODO: check fontinfo entry count
@@ -2026,10 +2026,10 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter,
fXFactor = 1000.0F * maFontMatrix[0];
fYFactor = 1000.0F * maFontMatrix[3];
}
rFSInfo.m_aFontBBox = tools::Rectangle( Point( static_cast<sal_Int32>(maFontBBox[0] * fXFactor),
static_cast<sal_Int32>(maFontBBox[1] * fYFactor) ),
Point( static_cast<sal_Int32>(maFontBBox[2] * fXFactor),
static_cast<sal_Int32>(maFontBBox[3] * fYFactor) ) );
rFSInfo.m_aFontBBox = { Point(static_cast<sal_Int32>(aFontBBox[0] * fXFactor),
static_cast<sal_Int32>(aFontBBox[1] * fYFactor)),
Point(static_cast<sal_Int32>(aFontBBox[2] * fXFactor),
static_cast<sal_Int32>(aFontBBox[3] * fYFactor)) };
// PDF-Spec says the values below mean the ink bounds!
// TODO: use better approximations for these ink bounds
rFSInfo.m_nAscent = +rFSInfo.m_aFontBBox.Bottom(); // for capital letters