[Libreoffice-commits] core.git: vcl/inc vcl/quartz vcl/source vcl/unx vcl/win

Noel Grandin noel.grandin at collabora.co.uk
Thu Feb 9 08:09:33 UTC 2017


 vcl/inc/fontsubset.hxx                      |   34 ++++++++++++++------------
 vcl/quartz/salgdicommon.cxx                 |    6 ++--
 vcl/source/fontsubset/cff.cxx               |    4 +--
 vcl/source/fontsubset/fontsubset.cxx        |   36 ++++++++++++++--------------
 vcl/source/gdi/pdfwriter_impl.cxx           |   18 +++++++-------
 vcl/unx/generic/fontmanager/fontmanager.cxx |    6 ++--
 vcl/unx/generic/print/glyphset.cxx          |    4 +--
 vcl/win/gdi/salfont.cxx                     |    6 ++--
 8 files changed, 59 insertions(+), 55 deletions(-)

New commits:
commit eecf39c6e44e25a5a78aa7b435d07a9c53c628c4
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 8 13:32:40 2017 +0200

    convert FontType to scoped enum
    
    Change-Id: Ieb8f90be8effde5f25bc872784c3ea2177b14bf9
    Reviewed-on: https://gerrit.libreoffice.org/34056
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/inc/fontsubset.hxx b/vcl/inc/fontsubset.hxx
index 11f5810..58cdb1e 100644
--- a/vcl/inc/fontsubset.hxx
+++ b/vcl/inc/fontsubset.hxx
@@ -22,35 +22,39 @@
 
 #include <rtl/ustring.hxx>
 #include <tools/gen.hxx>
+#include <o3tl/typed_flags_set.hxx>
 
 #include "salglyphid.hxx"
 
 namespace vcl { struct TrueTypeFont; }         ///< SFT's idea of a TTF font
 
+enum class FontType {
+    NO_FONT     = 0,
+    SFNT_TTF    = 1<<1,                     ///< SFNT container with TrueType glyphs
+    SFNT_CFF    = 1<<2,                     ///< SFNT container with CFF-container
+    TYPE1_PFA   = 1<<3,                     ///< PSType1 Postscript Font Ascii
+    TYPE1_PFB   = 1<<4,                     ///< PSType1 Postscript Font Binary
+    CFF_FONT    = 1<<5,                     ///< CFF-container with PSType2 glyphs
+    TYPE3_FONT  = 1<<6,                     ///< PSType3 Postscript font
+    TYPE42_FONT = 1<<7,                     ///< PSType42 wrapper for an SFNT_TTF
+    ANY_SFNT    = SFNT_TTF | SFNT_CFF,
+    ANY_TYPE1   = TYPE1_PFA | TYPE1_PFB
+};
+namespace o3tl {
+    template<> struct typed_flags<FontType> : is_typed_flags<FontType, (1<<8)-1> {};
+}
+
 class FontSubsetInfo final
 {
 public:
     explicit    FontSubsetInfo();
                 ~FontSubsetInfo();
 
-    enum FontType {
-        NO_FONT     = 0,
-        SFNT_TTF    = 1<<1,                     ///< SFNT container with TrueType glyphs
-        SFNT_CFF    = 1<<2,                     ///< SFNT container with CFF-container
-        TYPE1_PFA   = 1<<3,                     ///< PSType1 Postscript Font Ascii
-        TYPE1_PFB   = 1<<4,                     ///< PSType1 Postscript Font Binary
-        CFF_FONT    = 1<<5,                     ///< CFF-container with PSType2 glyphs
-        TYPE3_FONT  = 1<<6,                     ///< PSType3 Postscript font
-        TYPE42_FONT = 1<<7,                     ///< PSType42 wrapper for an SFNT_TTF
-        ANY_SFNT    = SFNT_TTF | SFNT_CFF,
-        ANY_TYPE1   = TYPE1_PFA | TYPE1_PFB
-    };
-
     bool        LoadFont( FontType eInFontType,
                     const unsigned char* pFontBytes, int nByteLength );
     bool        LoadFont( vcl::TrueTypeFont* pSftTrueTypeFont );
 
-    bool        CreateFontSubset( int nOutFontTypeMask,
+    bool        CreateFontSubset( FontType nOutFontTypeMask,
                     FILE* pOutFile, const char* pOutFontName,
                     const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncodedIds,
                     int nReqGlyphCount, sal_Int32* pOutGlyphWidths = nullptr );
@@ -72,7 +76,7 @@ private:
     vcl::TrueTypeFont*      mpSftTTFont;
 
     // subset-request details
-    int                     mnReqFontTypeMask;  ///< allowed subset-target font types
+    FontType                mnReqFontTypeMask;  ///< allowed subset-target font types
     FILE*                   mpOutFile;
     const char*             mpReqFontName;
     const sal_GlyphId*      mpReqGlyphIds;
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx
index db14e36..b472a49 100644
--- a/vcl/quartz/salgdicommon.cxx
+++ b/vcl/quartz/salgdicommon.cxx
@@ -208,13 +208,13 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
     {
         // provide the raw-CFF data to the subsetter
         ByteCount nCffLen = aBuffer.size();
-        rInfo.LoadFont( FontSubsetInfo::CFF_FONT, &aBuffer[0], nCffLen );
+        rInfo.LoadFont( FontType::CFF_FONT, &aBuffer[0], nCffLen );
 
         // NOTE: assuming that all glyphids requested on Aqua are fully translated
 
         // make the subsetter provide the requested subset
         FILE* pOutFile = fopen( aToFile.getStr(), "wb" );
-        bool bRC = rInfo.CreateFontSubset( FontSubsetInfo::TYPE1_PFB, pOutFile, nullptr,
+        bool bRC = rInfo.CreateFontSubset( FontType::TYPE1_PFB, pOutFile, nullptr,
                                            pGlyphIds, pEncoding, nGlyphCount, pGlyphWidths );
         fclose( pOutFile );
         return bRC;
@@ -234,7 +234,7 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
     // get details about the subsetted font
     TTGlobalFontInfo aTTInfo;
     ::GetTTGlobalFontInfo( pSftFont, &aTTInfo );
-    rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
+    rInfo.m_nFontType = FontType::SFNT_TTF;
     rInfo.m_aPSName = OUString( aTTInfo.psname, std::strlen(aTTInfo.psname),
                                 RTL_TEXTENCODING_UTF8 );
     rInfo.m_aFontBBox = Rectangle( Point( aTTInfo.xMin, aTTInfo.yMin ),
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 184f29e..9da87efe 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -2135,7 +2135,7 @@ bool CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter,
     rFSInfo.m_nDescent = -rFSInfo.m_aFontBBox.Top();    // for all letters
     rFSInfo.m_nCapHeight = rFSInfo.m_nAscent;           // for top-flat capital letters
 
-    rFSInfo.m_nFontType = rEmitter.mbPfbSubset ? FontSubsetInfo::TYPE1_PFB : FontSubsetInfo::TYPE1_PFA;
+    rFSInfo.m_nFontType = rEmitter.mbPfbSubset ? FontType::TYPE1_PFB : FontType::TYPE1_PFA;
     rFSInfo.m_aPSName   = OUString( rEmitter.maSubsetName, strlen(rEmitter.maSubsetName), RTL_TEXTENCODING_UTF8 );
 
     return true;
@@ -2150,7 +2150,7 @@ bool FontSubsetInfo::CreateFontSubsetFromCff( GlyphWidth* pOutGlyphWidths )
 
     // emit Type1 subset from the CFF input
     // TODO: also support CFF->CFF subsetting (when PDF-export and PS-printing need it)
-    const bool bPfbSubset = (0 != (mnReqFontTypeMask & FontSubsetInfo::TYPE1_PFB));
+    const bool bPfbSubset(mnReqFontTypeMask & FontType::TYPE1_PFB);
     Type1Emitter aType1Emitter( mpOutFile, bPfbSubset);
     aType1Emitter.setSubsetName( mpReqFontName);
     bRC = aCff.emitAsType1( aType1Emitter,
diff --git a/vcl/source/fontsubset/fontsubset.cxx b/vcl/source/fontsubset/fontsubset.cxx
index 3e496b1..cc18c4d 100644
--- a/vcl/source/fontsubset/fontsubset.cxx
+++ b/vcl/source/fontsubset/fontsubset.cxx
@@ -28,12 +28,12 @@ FontSubsetInfo::FontSubsetInfo()
     : m_nAscent( 0)
     , m_nDescent( 0)
     , m_nCapHeight( 0)
-    , m_nFontType( FontSubsetInfo::NO_FONT)
+    , m_nFontType( FontType::NO_FONT)
     , mpInFontBytes( nullptr)
     , mnInByteLength( 0)
-    , meInFontType( FontSubsetInfo::NO_FONT)
+    , meInFontType( FontType::NO_FONT)
     , mpSftTTFont( nullptr)
-    , mnReqFontTypeMask(0)
+    , mnReqFontTypeMask( FontType::NO_FONT )
     , mpOutFile(nullptr)
     , mpReqFontName(nullptr)
     , mpReqGlyphIds(nullptr)
@@ -48,7 +48,7 @@ FontSubsetInfo::~FontSubsetInfo()
 
 // prepare subsetting for fonts where the input font file is mapped
 bool FontSubsetInfo::LoadFont(
-    FontSubsetInfo::FontType eInFontType,
+    FontType eInFontType,
     const unsigned char* pInFontBytes, int nInByteLength)
 {
     SAL_WARN_IF( (mpSftTTFont != nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
@@ -63,12 +63,12 @@ bool FontSubsetInfo::LoadFont( vcl::TrueTypeFont* pSftTTFont )
 {
     SAL_WARN_IF( (mpInFontBytes != nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
     mpSftTTFont = pSftTTFont;
-    meInFontType = ANY_SFNT;
+    meInFontType = FontType::ANY_SFNT;
     return (mpSftTTFont == nullptr);
 }
 
 bool FontSubsetInfo::CreateFontSubset(
-    int nReqFontTypeMask,
+    FontType nReqFontTypeMask,
     FILE* pOutFile, const char* pReqFontName,
     const sal_GlyphId* pReqGlyphIds, const sal_uInt8* pReqEncodedIds, int nReqGlyphCount,
     sal_Int32* pOutGlyphWidths)
@@ -88,21 +88,21 @@ bool FontSubsetInfo::CreateFontSubset(
 
     // TODO: better match available input-type to possible subset-types
     switch( meInFontType) {
-    case SFNT_TTF:
-    case SFNT_CFF:
-    case ANY_SFNT:
+    case FontType::SFNT_TTF:
+    case FontType::SFNT_CFF:
+    case FontType::ANY_SFNT:
         bOK = CreateFontSubsetFromSfnt( pOutGlyphWidths);
         break;
-    case CFF_FONT:
+    case FontType::CFF_FONT:
         bOK = CreateFontSubsetFromCff( pOutGlyphWidths);
         break;
-    case TYPE1_PFA:
-    case TYPE1_PFB:
-    case ANY_TYPE1:
+    case FontType::TYPE1_PFA:
+    case FontType::TYPE1_PFB:
+    case FontType::ANY_TYPE1:
         bOK = CreateFontSubsetFromType1( pOutGlyphWidths);
         break;
         // fall through
-    case NO_FONT:
+    case FontType::NO_FONT:
         // fall through
     default:
         OSL_FAIL( "unhandled type in CreateFontSubset()");
@@ -120,7 +120,7 @@ bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths )
     const sal_uInt8* pCffBytes = nullptr;
     if( GetSfntTable( mpSftTTFont, O_CFF, &pCffBytes, &nCffLength))
     {
-        LoadFont( CFF_FONT, pCffBytes, nCffLength);
+        LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength);
         const bool bOK = CreateFontSubsetFromCff( pOutGlyphWidths);
         return bOK;
     }
@@ -136,18 +136,18 @@ bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths )
     sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds );
 #endif
     int nSFTErr = vcl::SF_BADARG;
-    if( (mnReqFontTypeMask & TYPE42_FONT) != 0 )
+    if( mnReqFontTypeMask & FontType::TYPE42_FONT )
     {
         nSFTErr = CreateT42FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName,
             aShortGlyphIds.data(), pEncArray, mnReqGlyphCount );
     }
-    else if( (mnReqFontTypeMask & TYPE3_FONT) != 0 )
+    else if( mnReqFontTypeMask & FontType::TYPE3_FONT )
     {
         nSFTErr = CreateT3FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName,
             aShortGlyphIds.data(), pEncArray, mnReqGlyphCount,
                     0 /* 0 = horizontal, 1 = vertical */ );
     }
-    else if( (mnReqFontTypeMask & SFNT_TTF) != 0 )
+    else if( mnReqFontTypeMask & FontType::SFNT_TTF )
     {
         // TODO: use CreateTTFromTTGlyphs()
         // TODO: move functionality from callers here
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index b3e0e38..73aa7f2 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -3228,12 +3228,12 @@ sal_Int32 PDFWriterImpl::emitFontDescriptor( const PhysicalFontFace* pFont, Font
         aLine.append( "/FontFile" );
         switch( rInfo.m_nFontType )
         {
-            case FontSubsetInfo::SFNT_TTF:
+            case FontType::SFNT_TTF:
                 aLine.append( '2' );
                 break;
-            case FontSubsetInfo::TYPE1_PFA:
-            case FontSubsetInfo::TYPE1_PFB:
-            case FontSubsetInfo::ANY_TYPE1:
+            case FontType::TYPE1_PFA:
+            case FontType::TYPE1_PFB:
+            case FontType::ANY_TYPE1:
                 break;
             default:
                 OSL_FAIL( "unknown fonttype in PDF font descriptor" );
@@ -3348,7 +3348,7 @@ bool PDFWriterImpl::emitFonts()
                                  "/Length1 " );
 
                 sal_uInt64 nStartPos = 0;
-                if( aSubsetInfo.m_nFontType == FontSubsetInfo::SFNT_TTF )
+                if( aSubsetInfo.m_nFontType == FontType::SFNT_TTF )
                 {
                     aLine.append( (sal_Int32)nLength1 );
 
@@ -3370,12 +3370,12 @@ bool PDFWriterImpl::emitFonts()
                         if ( osl::File::E_None != aFontFile.isEndOfFile(&bEOF) ) return false;
                     } while( ! bEOF );
                 }
-                else if( (aSubsetInfo.m_nFontType & FontSubsetInfo::CFF_FONT) != 0 )
+                else if( aSubsetInfo.m_nFontType & FontType::CFF_FONT)
                 {
                     // TODO: implement
                     OSL_FAIL( "PDFWriterImpl does not support CFF-font subsets yet!" );
                 }
-                else if( (aSubsetInfo.m_nFontType & FontSubsetInfo::TYPE1_PFB) != 0 ) // TODO: also support PFA?
+                else if( aSubsetInfo.m_nFontType & FontType::TYPE1_PFB) // TODO: also support PFA?
                 {
                     std::unique_ptr<unsigned char[]> xBuffer(new unsigned char[nLength1]);
 
@@ -3408,7 +3408,7 @@ bool PDFWriterImpl::emitFonts()
                 }
                 else
                 {
-                    SAL_INFO("vcl.pdfwriter", "PDF: CreateFontSubset result in not yet supported format=" << aSubsetInfo.m_nFontType);
+                    SAL_INFO("vcl.pdfwriter", "PDF: CreateFontSubset result in not yet supported format=" << (int)aSubsetInfo.m_nFontType);
                     aLine.append( "0 >>\nstream\n" );
                 }
 
@@ -3445,7 +3445,7 @@ bool PDFWriterImpl::emitFonts()
                 aLine.append( nFontObject );
 
                 aLine.append( " 0 obj\n" );
-                aLine.append( ((aSubsetInfo.m_nFontType & FontSubsetInfo::ANY_TYPE1) != 0) ?
+                aLine.append( (aSubsetInfo.m_nFontType & FontType::ANY_TYPE1) ?
                              "<</Type/Font/Subtype/Type1/BaseFont/" :
                              "<</Type/Font/Subtype/TrueType/BaseFont/" );
                 appendSubsetName( lit->m_nFontID, aSubsetInfo.m_aPSName, aLine );
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index f34960f..9a0193d 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -1006,7 +1006,7 @@ bool PrintFontManager::createFontSubset(
     if( !pFont )
         return false;
 
-    rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
+    rInfo.m_nFontType = FontType::SFNT_TTF;
 
     // reshuffle array of requested glyphs to make sure glyph0==notdef
     sal_uInt8  pEnc[256];
@@ -1057,7 +1057,7 @@ bool PrintFontManager::createFontSubset(
     const sal_uInt8* pCffBytes = nullptr;
     if( GetSfntTable( pTTFont, O_CFF, &pCffBytes, &nCffLength ) )
     {
-        rInfo.LoadFont( FontSubsetInfo::CFF_FONT, pCffBytes, nCffLength );
+        rInfo.LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength );
 #if 1 // TODO: remove 16bit->long conversion when related methods handle non-16bit glyphids
         sal_GlyphId aRequestedGlyphIds[256];
         for( int i = 0; i < nGlyphs; ++i )
@@ -1073,7 +1073,7 @@ bool PrintFontManager::createFontSubset(
         // create font subset
         const char* const pGlyphSetName = nullptr; // TODO: better name?
         const bool bOK = rInfo.CreateFontSubset(
-            FontSubsetInfo::TYPE1_PFB,
+            FontType::TYPE1_PFB,
             pOutFile, pGlyphSetName,
             aRequestedGlyphIds, pEnc, nGlyphs, pWidths );
         fclose( pOutFile );
diff --git a/vcl/unx/generic/print/glyphset.cxx b/vcl/unx/generic/print/glyphset.cxx
index 3641fe1..531af28 100644
--- a/vcl/unx/generic/print/glyphset.cxx
+++ b/vcl/unx/generic/print/glyphset.cxx
@@ -217,9 +217,9 @@ static void CreatePSUploadableFont( TrueTypeFont* pSrcFont, FILE* pTmpFile,
 {
     // match the font-subset to the printer capabilities
      // TODO: allow CFF for capable printers
-    int nTargetMask = FontSubsetInfo::TYPE1_PFA | FontSubsetInfo::TYPE3_FONT;
+    FontType nTargetMask = FontType::TYPE1_PFA | FontType::TYPE3_FONT;
     if( bAllowType42 )
-        nTargetMask |= FontSubsetInfo::TYPE42_FONT;
+        nTargetMask |= FontType::TYPE42_FONT;
 
     std::vector< EncEntry > aSorted( nGlyphCount, EncEntry() );
     for( int i = 0; i < nGlyphCount; i++ )
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index b6b4915..e9bc239 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1658,8 +1658,8 @@ bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
 
         // provide a font subset from the CFF-table
         FILE* pOutFile = fopen( aToFile.getStr(), "wb" );
-        rInfo.LoadFont( FontSubsetInfo::CFF_FONT, aRawCffData.get(), aRawCffData.size() );
-        bool bRC = rInfo.CreateFontSubset( FontSubsetInfo::TYPE1_PFB, pOutFile, nullptr,
+        rInfo.LoadFont( FontType::CFF_FONT, aRawCffData.get(), aRawCffData.size() );
+        bool bRC = rInfo.CreateFontSubset( FontType::TYPE1_PFB, pOutFile, nullptr,
                 pGlyphIds, pEncoding, nGlyphCount, pGlyphWidths );
         fclose( pOutFile );
         return bRC;
@@ -1682,7 +1682,7 @@ bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
 
     TTGlobalFontInfo aTTInfo;
     ::GetTTGlobalFontInfo( aSftTTF.get(), &aTTInfo );
-    rInfo.m_nFontType   = FontSubsetInfo::SFNT_TTF;
+    rInfo.m_nFontType   = FontType::SFNT_TTF;
     rInfo.m_aPSName     = ImplSalGetUniString( aTTInfo.psname );
     rInfo.m_nAscent     = aTTInfo.winAscent;
     rInfo.m_nDescent    = aTTInfo.winDescent;


More information about the Libreoffice-commits mailing list