From 1c3526bfc07cd13636bfb84f5ad45a058ec74415 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 24 Nov 2016 09:54:48 +0200 Subject: Dead code Change-Id: I24d365f8231431a4062d026622c2f72bb5ed7af7 Reviewed-on: https://gerrit.libreoffice.org/31230 Tested-by: Jenkins Reviewed-by: Khaled Hosny --- vcl/unx/generic/fontmanager/fontmanager.cxx | 108 -------- vcl/unx/generic/print/glyphset.cxx | 293 +-------------------- vcl/unx/generic/print/glyphset.hxx | 25 +- vcl/unx/generic/print/text_gfx.cxx | 382 ---------------------------- 4 files changed, 5 insertions(+), 803 deletions(-) (limited to 'vcl/unx') diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index 4c839f4fbf2b..152c01b4a6a1 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -1206,69 +1206,6 @@ int PrintFontManager::getFontDescend( fontID nFontID ) const return pFont ? pFont->m_nDescend : 0; } -void PrintFontManager::hasVerticalSubstitutions( fontID nFontID, - const sal_Unicode* pCharacters, int nCharacters, bool* pHasSubst ) const -{ - PrintFont* pFont = getFont( nFontID ); - if (pFont && pFont->m_nAscend == 0 && pFont->m_nDescend == 0) - { - // might be a truetype font not yet analyzed - if( pFont->m_eType == fonttype::TrueType ) - analyzeTrueTypeFile( pFont ); - } - - if (!pFont || !pFont->m_bHaveVerticalSubstitutedGlyphs) - memset( pHasSubst, 0, sizeof(bool)*nCharacters ); - else - { - for( int i = 0; i < nCharacters; i++ ) - { - sal_Unicode code = pCharacters[i]; - if( ! pFont->m_pMetrics || - ! ( pFont->m_pMetrics->m_aPages[ code >> 11 ] & ( 1 << ( ( code >> 8 ) & 7 ) ) ) ) - pFont->queryMetricPage( code >> 8, m_pAtoms ); - std::unordered_map< sal_Unicode, bool >::const_iterator it = pFont->m_pMetrics->m_bVerticalSubstitutions.find( code ); - pHasSubst[i] = it != pFont->m_pMetrics->m_bVerticalSubstitutions.end(); - } - } -} - -bool PrintFontManager::isFontDownloadingAllowedForPrinting( fontID nFont ) const -{ - static const char* pEnable = getenv( "PSPRINT_ENABLE_TTF_COPYRIGHTAWARENESS" ); - bool bRet = true; - - if( pEnable && *pEnable ) - { - PrintFont* pFont = getFont( nFont ); - if( pFont && pFont->m_eType == fonttype::TrueType ) - { - TrueTypeFontFile* pTTFontFile = static_cast(pFont); - if( pTTFontFile->m_nTypeFlags & TYPEFLAG_INVALID ) - { - TrueTypeFont* pTTFont = nullptr; - OString aFile = getFontFile( pFont ); - if( OpenTTFontFile( aFile.getStr(), pTTFontFile->m_nCollectionEntry, &pTTFont ) == SF_OK ) - { - // get type flags - TTGlobalFontInfo aInfo; - GetTTGlobalFontInfo( pTTFont, & aInfo ); - pTTFontFile->m_nTypeFlags = (unsigned int)aInfo.typeFlags; - CloseTTFont( pTTFont ); - } - } - - unsigned int nCopyrightFlags = pTTFontFile->m_nTypeFlags & TYPEFLAG_COPYRIGHT_MASK; - - // http://www.microsoft.com/typography/tt/ttf_spec/ttch02.doc - // Font embedding is allowed if not restricted completely (only bit 1 set). - // Preview&Print (bit 2), Editable (bit 3) or Installable (==0) fonts are ok. - bRet = ( nCopyrightFlags & 0x02 ) != 0x02; - } - } - return bRet; -} - bool PrintFontManager::getMetrics( fontID nFontID, const sal_Unicode* pString, int nLen, CharacterMetric* pArray ) const { PrintFont* pFont = getFont( nFontID ); @@ -1304,51 +1241,6 @@ bool PrintFontManager::getMetrics( fontID nFontID, const sal_Unicode* pString, i return true; } -bool PrintFontManager::getMetrics( fontID nFontID, sal_Unicode minCharacter, sal_Unicode maxCharacter, CharacterMetric* pArray, bool bVertical ) const -{ - OSL_PRECOND(minCharacter <= maxCharacter, "invalid char. range"); - if (minCharacter > maxCharacter) - return false; - - PrintFont* pFont = getFont( nFontID ); - if( ! pFont ) - return false; - - if( ( pFont->m_nAscend == 0 && pFont->m_nDescend == 0 ) - || ! pFont->m_pMetrics || pFont->m_pMetrics->isEmpty() - ) - { - // might be a font not yet analyzed - if( pFont->m_eType == fonttype::TrueType ) - analyzeTrueTypeFile( pFont ); - } - - sal_Unicode code = minCharacter; - do - { - if( ! pFont->m_pMetrics || - ! ( pFont->m_pMetrics->m_aPages[ code >> 11 ] & ( 1 << ( ( code >> 8 ) & 7 ) ) ) ) - pFont->queryMetricPage( code >> 8, m_pAtoms ); - pArray[ code - minCharacter ].width = -1; - pArray[ code - minCharacter ].height = -1; - if( pFont->m_pMetrics ) - { - int effectiveCode = code; - effectiveCode |= bVertical ? 1 << 16 : 0; - std::unordered_map< int, CharacterMetric >::const_iterator it = - pFont->m_pMetrics->m_aMetrics.find( effectiveCode ); - // if no vertical metrics are available assume rotated horizontal metrics - if( bVertical && (it == pFont->m_pMetrics->m_aMetrics.end()) ) - it = pFont->m_pMetrics->m_aMetrics.find( code ); - // the character metrics are in it->second - if( it != pFont->m_pMetrics->m_aMetrics.end() ) - pArray[ code - minCharacter ] = it->second; - } - } while( code++ != maxCharacter ); - - return true; -} - // TODO: move most of this stuff into the central font-subsetting code bool PrintFontManager::createFontSubset( FontSubsetInfo& rInfo, diff --git a/vcl/unx/generic/print/glyphset.cxx b/vcl/unx/generic/print/glyphset.cxx index 15c0fd87d92f..58b640ab2aa4 100644 --- a/vcl/unx/generic/print/glyphset.cxx +++ b/vcl/unx/generic/print/glyphset.cxx @@ -60,17 +60,6 @@ GlyphSet::~GlyphSet () /* FIXME delete the glyphlist ??? */ } -bool -GlyphSet::GetCharID ( - sal_Unicode nChar, - unsigned char* nOutGlyphID, - sal_Int32* nOutGlyphSetID - ) -{ - return LookupCharID (nChar, nOutGlyphID, nOutGlyphSetID) - || AddCharID (nChar, nOutGlyphID, nOutGlyphSetID); -} - bool GlyphSet::GetGlyphID ( sal_GlyphId nGlyph, @@ -83,37 +72,6 @@ GlyphSet::GetGlyphID ( || AddGlyphID (nGlyph, nUnicode, nOutGlyphID, nOutGlyphSetID); } -bool -GlyphSet::LookupCharID ( - sal_Unicode nChar, - unsigned char* nOutGlyphID, - sal_Int32* nOutGlyphSetID - ) -{ - char_list_t::iterator aGlyphSet; - sal_Int32 nGlyphSetID; - - // loop through all the font subsets - for (aGlyphSet = maCharList.begin(), nGlyphSetID = 1; - aGlyphSet != maCharList.end(); - ++aGlyphSet, nGlyphSetID++) - { - // check every subset if it contains the queried unicode char - char_map_t::const_iterator aGlyph = (*aGlyphSet).find (nChar); - if (aGlyph != (*aGlyphSet).end()) - { - // success: found the unicode char, return the glyphid and the glyphsetid - *nOutGlyphSetID = nGlyphSetID; - *nOutGlyphID = (*aGlyph).second; - return true; - } - } - - *nOutGlyphSetID = -1; - *nOutGlyphID = 0; - return false; -} - bool GlyphSet::LookupGlyphID ( sal_GlyphId nGlyph, @@ -145,27 +103,6 @@ GlyphSet::LookupGlyphID ( return false; } -unsigned char -GlyphSet::GetAnsiMapping (sal_Unicode nUnicodeChar) -{ - static rtl_UnicodeToTextConverter aConverter = - rtl_createUnicodeToTextConverter(RTL_TEXTENCODING_MS_1252); - static rtl_UnicodeToTextContext aContext = - rtl_createUnicodeToTextContext( aConverter ); - - sal_Char nAnsiChar; - sal_uInt32 nCvtInfo; - sal_Size nCvtChars; - const sal_uInt32 nCvtFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR - | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR; - - sal_Size nSize = rtl_convertUnicodeToText( aConverter, aContext, - &nUnicodeChar, 1, &nAnsiChar, 1, - nCvtFlags, &nCvtInfo, &nCvtChars ); - - return nSize == 1 ? (unsigned char)nAnsiChar : (unsigned char)0; -} - unsigned char GlyphSet::GetSymbolMapping (sal_Unicode nUnicodeChar) { @@ -177,76 +114,12 @@ GlyphSet::GetSymbolMapping (sal_Unicode nUnicodeChar) return 0; } -void -GlyphSet::AddNotdef (char_map_t &rCharMap) -{ - if (rCharMap.empty()) - rCharMap[0] = 0; -} - void GlyphSet::AddNotdef (glyph_map_t &rGlyphMap) { if (rGlyphMap.empty()) rGlyphMap[0] = 0; } -bool -GlyphSet::AddCharID ( - sal_Unicode nChar, - unsigned char* nOutGlyphID, - sal_Int32* nOutGlyphSetID - ) -{ - unsigned char nMappedChar; - - // XXX important: avoid to reencode type1 symbol fonts - if (mnBaseEncoding == RTL_TEXTENCODING_SYMBOL) - nMappedChar = GetSymbolMapping (nChar); - else - nMappedChar = GetAnsiMapping (nChar); - - // create an empty glyphmap that is reserved for iso1252 encoded glyphs - // (or -- unencoded -- symbol glyphs) and a second map that takes any other - if (maCharList.empty()) - { - char_map_t aMap, aMapp; - - maCharList.push_back (aMap); - maCharList.push_back (aMapp); - } - // if the last map is full, create a new one - if ((!nMappedChar) && (maCharList.back().size() == 255)) - { - char_map_t aMap; - maCharList.push_back (aMap); - } - - // insert a new glyph in the font subset - if (nMappedChar) - { - // always put iso1252 chars into the first map, map them on itself - char_map_t& aGlyphSet = maCharList.front(); - AddNotdef (aGlyphSet); - - aGlyphSet [nChar] = nMappedChar; - *nOutGlyphSetID = 1; - *nOutGlyphID = nMappedChar; - } - else - { - // other chars are just appended to the list - char_map_t& aGlyphSet = maCharList.back(); - AddNotdef (aGlyphSet); - - int nSize = aGlyphSet.size(); - - aGlyphSet [nChar] = nSize; - *nOutGlyphSetID = maCharList.size(); - *nOutGlyphID = aGlyphSet [nChar]; - } - - return true; -} bool GlyphSet::AddGlyphID ( @@ -305,25 +178,6 @@ GlyphSet::AddGlyphID ( return true; } -OString -GlyphSet::GetCharSetName (sal_Int32 nGlyphSetID) -{ - if (meBaseType == fonttype::TrueType) - { - OStringBuffer aSetName( maBaseName.getLength() + 32 ); - aSetName.append( maBaseName ); - aSetName.append( "FID" ); - aSetName.append( mnFontID ); - aSetName.append( mbVertical ? "VCSet" : "HCSet" ); - aSetName.append( nGlyphSetID ); - return aSetName.makeStringAndClear(); - } - else - { - return maBaseName; - } -} - OString GlyphSet::GetGlyphSetName (sal_Int32 nGlyphSetID) { @@ -343,48 +197,6 @@ GlyphSet::GetGlyphSetName (sal_Int32 nGlyphSetID) } } -sal_Int32 -GlyphSet::GetGlyphSetEncoding (sal_Int32 nGlyphSetID) -{ - if (meBaseType == fonttype::TrueType) - return RTL_TEXTENCODING_DONTKNOW; - else - { - if (mnBaseEncoding == RTL_TEXTENCODING_SYMBOL) - return RTL_TEXTENCODING_SYMBOL; - else - return nGlyphSetID == 1 ? RTL_TEXTENCODING_MS_1252 - : RTL_TEXTENCODING_USER_START + nGlyphSetID; - } -} - -OString -GlyphSet::GetGlyphSetEncodingName (rtl_TextEncoding nEnc, const OString &rFontName) -{ - if ( nEnc == RTL_TEXTENCODING_MS_1252 - || nEnc == RTL_TEXTENCODING_ISO_8859_1) - { - return OString("ISO1252Encoding"); - } - else - if (nEnc >= RTL_TEXTENCODING_USER_START && nEnc <= RTL_TEXTENCODING_USER_END) - { - return rFontName - + OString("Enc") - + OString::number ((nEnc - RTL_TEXTENCODING_USER_START)); - } - else - { - return OString(); - } -} - -OString -GlyphSet::GetGlyphSetEncodingName (sal_Int32 nGlyphSetID) -{ - return GetGlyphSetEncodingName (GetGlyphSetEncoding(nGlyphSetID), maBaseName); -} - OString GlyphSet::GetReencodedFontName (rtl_TextEncoding nEnc, const OString &rFontName) { @@ -413,8 +225,7 @@ void GlyphSet::DrawGlyphs( const sal_GlyphId* pGlyphIds, const sal_Unicode* pUnicodes, sal_Int16 nLen, - const sal_Int32* pDeltaArray, - const bool bUseGlyphs) + const sal_Int32* pDeltaArray) { unsigned char *pGlyphID = static_cast(alloca (nLen * sizeof(unsigned char))); sal_Int32 *pGlyphSetID = static_cast(alloca (nLen * sizeof(sal_Int32))); @@ -423,10 +234,7 @@ void GlyphSet::DrawGlyphs( // convert unicode to font glyph id and font subset for (int nChar = 0; nChar < nLen; nChar++) { - if (bUseGlyphs) - GetGlyphID (pGlyphIds[nChar], pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar); - else - GetCharID (pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar); + GetGlyphID (pGlyphIds[nChar], pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar); aGlyphSet.insert (pGlyphSetID[nChar]); } @@ -475,72 +283,14 @@ void GlyphSet::DrawGlyphs( aPoint.Move (nOffset, 0); OString aGlyphSetName; - if (bUseGlyphs) - aGlyphSetName = GetGlyphSetName(*aSet); - else - aGlyphSetName = GetCharSetName(*aSet); + aGlyphSetName = GetGlyphSetName(*aSet); - rGfx.PSSetFont (aGlyphSetName, GetGlyphSetEncoding(*aSet)); + rGfx.PSSetFont (aGlyphSetName, RTL_TEXTENCODING_DONTKNOW); rGfx.PSMoveTo (aPoint); rGfx.PSShowText (pGlyphSubset, nGlyphs, nGlyphs, nGlyphs > 1 ? pDeltaSubset : nullptr); } } -void -GlyphSet::DrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen, const sal_Int32* pDeltaArray) -{ - // dispatch to the impl method - if (pDeltaArray == nullptr) - ImplDrawText (rGfx, rPoint, pStr, nLen); - else - ImplDrawText (rGfx, rPoint, pStr, nLen, pDeltaArray); -} - -void -GlyphSet::ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen) -{ - rGfx.PSMoveTo (rPoint); - - int nChar; - unsigned char *pGlyphID = static_cast(alloca (nLen * sizeof(unsigned char))); - sal_Int32 *pGlyphSetID = static_cast(alloca (nLen * sizeof(sal_Int32))); - - // convert unicode to glyph id and char set (font subset) - for (nChar = 0; nChar < nLen; nChar++) - GetCharID (pStr[nChar], pGlyphID + nChar, pGlyphSetID + nChar); - - // loop over the string to draw subsequent pieces of chars - // with the same postscript font - for (nChar = 0; nChar < nLen; /* atend */) - { - sal_Int32 nGlyphSetID = pGlyphSetID [nChar]; - sal_Int32 nGlyphs = 1; - for (int nNextChar = nChar + 1; nNextChar < nLen; nNextChar++) - { - if (pGlyphSetID[nNextChar] == nGlyphSetID) - nGlyphs++; - else - break; - } - - // show the text using the PrinterGfx text api - OString aGlyphSetName(GetCharSetName(nGlyphSetID)); - rGfx.PSSetFont (aGlyphSetName, GetGlyphSetEncoding(nGlyphSetID)); - rGfx.PSShowText (pGlyphID + nChar, nGlyphs, nGlyphs); - - nChar += nGlyphs; - } -} - -void -GlyphSet::ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen, const sal_Int32* pDeltaArray) -{ - DrawGlyphs( rGfx, rPoint, nullptr, pStr, nLen, pDeltaArray, false); -} - struct EncEntry { unsigned char aEnc; @@ -608,47 +358,12 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAllowType42 if (pTmpFile == nullptr) return; - // array of unicode source characters - sal_uInt16 pUChars[256]; - // encoding vector maps character encoding to the ordinal number // of the glyph in the output file unsigned char pEncoding[256]; sal_uInt16 pTTGlyphMapping[256]; const bool bAllowCID = false; // TODO: nPSLanguageLevel>=3 - // loop through all the font subsets - sal_Int32 nCharSetID; - char_list_t::iterator aCharSet; - for (aCharSet = maCharList.begin(), nCharSetID = 1; - aCharSet != maCharList.end(); - ++aCharSet, nCharSetID++) - { - if ((*aCharSet).empty()) - continue; - - // loop through all the chars in the subset - char_map_t::const_iterator aChar; - sal_Int32 n = 0; - for (aChar = (*aCharSet).begin(); aChar != (*aCharSet).end(); ++aChar) - { - pUChars [n] = (*aChar).first; - pEncoding [n] = (*aChar).second; - n++; - } - // create a mapping from the unicode chars to the char encoding in - // source TrueType font - MapString (pTTFont, pUChars, (*aCharSet).size(), pTTGlyphMapping, mbVertical); - - // create the current subset - OString aCharSetName = GetCharSetName(nCharSetID); - fprintf( pTmpFile, "%%%%BeginResource: font %s\n", aCharSetName.getStr() ); - CreatePSUploadableFont( pTTFont, pTmpFile, aCharSetName.getStr(), (*aCharSet).size(), - pTTGlyphMapping, pEncoding, bAllowType42, bAllowCID ); - fprintf( pTmpFile, "%%%%EndResource\n" ); - rSuppliedFonts.push_back( aCharSetName ); - } - // loop through all the font glyph subsets sal_Int32 nGlyphSetID; glyph_list_t::iterator aGlyphSet; diff --git a/vcl/unx/generic/print/glyphset.hxx b/vcl/unx/generic/print/glyphset.hxx index d807af45dbef..7b0eba90c442 100644 --- a/vcl/unx/generic/print/glyphset.hxx +++ b/vcl/unx/generic/print/glyphset.hxx @@ -51,21 +51,10 @@ private: typedef std::unordered_map< sal_GlyphId, sal_uInt8 > glyph_map_t; typedef std::list< glyph_map_t > glyph_list_t; - char_list_t maCharList; glyph_list_t maGlyphList; OString GetGlyphSetName (sal_Int32 nGlyphSetID); - OString GetCharSetName (sal_Int32 nGlyphSetID); - sal_Int32 GetGlyphSetEncoding (sal_Int32 nGlyphSetID); - OString GetGlyphSetEncodingName (sal_Int32 nGlyphSetID); - bool GetCharID (sal_Unicode nChar, - unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); - bool LookupCharID (sal_Unicode nChar, - unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); - bool AddCharID (sal_Unicode nChar, - unsigned char* nOutGlyphID, - sal_Int32* nOutGlyphSetID); bool GetGlyphID (sal_GlyphId nGlyphId, sal_Unicode nUnicode, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); bool LookupGlyphID (sal_GlyphId nGlyphId, @@ -73,17 +62,9 @@ private: bool AddGlyphID (sal_GlyphId nGlyphId, sal_Unicode nUnicode, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); - static void AddNotdef (char_map_t &rCharMap); static void AddNotdef (glyph_map_t &rGlyphMap); - static unsigned char GetAnsiMapping (sal_Unicode nUnicodeChar); static unsigned char GetSymbolMapping (sal_Unicode nUnicodeChar); - void ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen); - void ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen, - const sal_Int32* pDeltaArray); - public: GlyphSet (sal_Int32 nFontID, bool bVertical); @@ -99,16 +80,12 @@ public: const OString &rFontName); bool IsVertical () { return mbVertical;} - void DrawText (PrinterGfx &rGfx, const Point& rPoint, - const sal_Unicode* pStr, sal_Int16 nLen, - const sal_Int32* pDeltaArray); void DrawGlyphs (PrinterGfx& rGfx, const Point& rPoint, const sal_GlyphId* pGlyphIds, const sal_Unicode* pUnicodes, sal_Int16 nLen, - const sal_Int32* pDeltaArray, - bool bUseGlyphs=true); + const sal_Int32* pDeltaArray); void PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42, std::list< OString >& rSuppliedFonts ); }; diff --git a/vcl/unx/generic/print/text_gfx.cxx b/vcl/unx/generic/print/text_gfx.cxx index 12f23fd05956..eda0f17b76f6 100644 --- a/vcl/unx/generic/print/text_gfx.cxx +++ b/vcl/unx/generic/print/text_gfx.cxx @@ -32,56 +32,6 @@ using namespace psp ; -namespace psp { -/* - container for a font and its helper fonts: - 1st is the font itself - 2nd is a fallback font, usually a font with unicode glyph repertoire (e.g. andale) - symbol fonts (adobe-fontspecific) may need special glyphmapping - (symbol page vc. latin page) -*/ -class Font2 -{ - private: - - #define Font2Size 2 - - fontID mpFont [Font2Size]; - bool mbSymbol; - - public: - - fontID GetFont (int nIdx) const - { return nIdx < Font2Size ? mpFont[nIdx] : -1 ; } - bool IsSymbolFont () const - { return mbSymbol; } - - explicit Font2 (const PrinterGfx &rGfx); - ~Font2 () {} -}; - -Font2::Font2(const PrinterGfx &rGfx) -{ - mpFont[0] = rGfx.GetFontID(); - mpFont[1] = 0; // fallback ID - - PrintFontManager &rMgr = PrintFontManager::get(); - mbSymbol = mpFont[0] != -1 && - rMgr.getFontEncoding(mpFont[0]) == RTL_TEXTENCODING_SYMBOL; -} - -} // namespace psp - -static int getVerticalDeltaAngle( sal_Unicode nChar ) -{ - int nRotation = GetVerticalFlags(nChar); - if (nRotation == GF_ROTR) - return -900; - if (nRotation == GF_ROTL) - return 900; - return 0; -} - /* * implement text handling printer routines, */ @@ -148,12 +98,6 @@ void PrinterGfx::DrawGlyphs( if( nLen <= 0 ) return; - if ( !mrFontMgr.isFontDownloadingAllowedForPrinting( mnFontID ) ) - { - LicenseWarning(rPoint, pUnicodes, nLen, pDeltaArray); - return; - } - // move and rotate the user coordinate system // avoid the gsave/grestore for the simple cases since it allows // reuse of the current font if it hasn't changed @@ -268,332 +212,6 @@ void PrinterGfx::DrawGlyphs( } } -void -PrinterGfx::DrawText ( - const Point& rPoint, - const sal_Unicode* pStr, - sal_Int16 nLen, - const sal_Int32* pDeltaArray - ) -{ - if (!nLen) - return; - - fontID nRestoreFont = mnFontID; - - // setup font[substitutes] and map the string into the symbol area in case of - // symbol font - Font2 aFont(*this); - sal_Unicode *pEffectiveStr; - if ( aFont.IsSymbolFont() ) - { - pEffectiveStr = static_cast(alloca(nLen * sizeof(pStr[0]))); - for (int i = 0; i < nLen; i++) - pEffectiveStr[i] = pStr[i] < 256 ? pStr[i] + 0xF000 : pStr[i]; - } - else - { - pEffectiveStr = const_cast(pStr); - } - - fontID *pFontMap = static_cast(alloca(nLen * sizeof(fontID))); - sal_Int32 *pCharWidth = static_cast(alloca(nLen * sizeof(sal_Int32))); - - for( int n = 0; n < nLen; n++ ) - { - CharacterMetric aBBox; - // coverity[callee_ptr_arith] - pFontMap[n] = getCharMetric(aFont, pEffectiveStr[n], &aBBox); - pCharWidth[n] = getCharWidth(mbTextVertical, pEffectiveStr[n], &aBBox); - } - - // setup a new delta array, use virtual resolution of 1000 - sal_Int32* pNewDeltaArray = static_cast(alloca( sizeof( sal_Int32 )*nLen )); - if ( pDeltaArray != nullptr) - { - for (int i = 0; i < nLen - 1; i++) - pNewDeltaArray[i] = 1000 * pDeltaArray[i]; - pNewDeltaArray[nLen - 1] = 0; - } - else - { - pNewDeltaArray[0] = pCharWidth[0]; - for (int i = 1; i < nLen; i++) - pNewDeltaArray[i] = pNewDeltaArray[i-1] + pCharWidth[i]; - } - - // move and rotate the user coordinate system - // avoid the gsave/grestore for the simple cases since it allows - // reuse of the current font if it hasn't changed - sal_Int32 nCurrentTextAngle = mnTextAngle; - sal_Int32 nCurrentPointX; - sal_Int32 nCurrentPointY; - - if (nCurrentTextAngle != 0) - { - PSGSave (); - PSTranslate (rPoint); - PSRotate (nCurrentTextAngle); - mnTextAngle = 0; - - nCurrentPointX = 0; - nCurrentPointY = 0; - } - else - { - nCurrentPointX = rPoint.X(); - nCurrentPointY = rPoint.Y(); - } - - // draw the string - sal_Int32 nDelta = 0; - for (int nTo = 0; nTo < nLen; ) - { - int nFrom = nTo; - fontID nFont = pFontMap[ nFrom ]; - - while ((nTo < nLen) && (nFont == pFontMap[nTo])) - { - pNewDeltaArray[ nTo ] = (sal_Int32)(((0.5 + pNewDeltaArray[ nTo ]) / 1000.0) - nDelta); - nTo++ ; - } - - SetFont( nFont, - maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth, - mnTextAngle, - mbTextVertical, - maVirtualStatus.mbArtItalic, - maVirtualStatus.mbArtBold - ); - - if (mbTextVertical) - { - drawVerticalizedText( - Point(nCurrentPointX + nDelta, nCurrentPointY), - pEffectiveStr + nFrom, nTo - nFrom, - pNewDeltaArray + nFrom ); - } - else - { - drawText( - Point(nCurrentPointX + nDelta, nCurrentPointY), - pEffectiveStr + nFrom, nTo - nFrom, - pDeltaArray == nullptr ? nullptr : pNewDeltaArray + nFrom ); - } - nDelta += pNewDeltaArray[ nTo - 1 ]; - } - - // restore the user coordinate system - if (nCurrentTextAngle != 0) - { - PSGRestore (); - mnTextAngle = nCurrentTextAngle; - } - - // restore the original font settings - SetFont( nRestoreFont, - maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth, - mnTextAngle, mbTextVertical, - maVirtualStatus.mbArtItalic, - maVirtualStatus.mbArtBold - ); -} - -void PrinterGfx::drawVerticalizedText( - const Point& rPoint, - const sal_Unicode* pStr, - sal_Int16 nLen, - const sal_Int32* pDeltaArray - ) -{ - PrintFontManager &rMgr = PrintFontManager::get(); - PrintFontInfo aInfo; - if (!rMgr.getFontInfo(mnFontID, aInfo)) - return; - - sal_Int32* pDelta = static_cast(alloca( nLen * sizeof(sal_Int32) )); - - int nTextScale = maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight; - int nNormalAngle = mnTextAngle; - int nLastPos = 0; - - double fSin = sin( -2.0*M_PI*nNormalAngle/3600 ); - double fCos = cos( -2.0*M_PI*nNormalAngle/3600 ); - - bool* pGsubFlags = static_cast(alloca( nLen * sizeof(bool) )); - rMgr.hasVerticalSubstitutions( mnFontID, pStr, nLen, pGsubFlags ); - - Point aPoint( rPoint ); - for( int i = 0; i < nLen; ) - { - int nDeltaAngle; - while( ( nDeltaAngle = getVerticalDeltaAngle( pStr[i] ) ) == 0 && i < nLen ) - i++; - if( i <= nLen && i > nLastPos ) - { - for( int n = nLastPos; n < i; n++ ) - pDelta[n] = pDeltaArray[n] - (aPoint.X() - rPoint.X() ); - - SetFont( mnFontID, - maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth, - nNormalAngle, mbTextVertical, - maVirtualStatus.mbArtItalic, - maVirtualStatus.mbArtBold ); - drawText( aPoint, pStr + nLastPos, i - nLastPos, pDelta + nLastPos ); - - aPoint.X() = (sal_Int32)(rPoint.X() + ((double)pDeltaArray[i-1] * fCos)); - aPoint.Y() = (sal_Int32)(rPoint.Y() + ((double)pDeltaArray[i-1] * fSin)); - } - if( i < nLen ) - { - int nOldWidth = maVirtualStatus.mnTextWidth; - int nOldHeight = maVirtualStatus.mnTextHeight; - SetFont( mnFontID, - nTextScale, - maVirtualStatus.mnTextHeight, - nNormalAngle + nDeltaAngle, - mbTextVertical, - maVirtualStatus.mbArtItalic, - maVirtualStatus.mbArtBold ); - - double nA = nTextScale * aInfo.m_nAscend / 1000.0; - double nD = nTextScale * aInfo.m_nDescend / 1000.0; - double fStretch = (double)maVirtualStatus.mnTextWidth / maVirtualStatus.mnTextHeight; - if( !pGsubFlags[i] ) - nD *= fStretch; - - Point aPos( aPoint ); - switch( nDeltaAngle ) - { - case +900: - aPos.X() += (sal_Int32)(+nA * fCos + nD * fSin); - aPos.Y() += (sal_Int32)(-nA * fSin + nD * fCos); - break; - case -900: - aPos.X() += (sal_Int32)(+nA * fSin + nD * fCos); - aPos.Y() += (sal_Int32)(-(nTextScale*fStretch - nD) * fCos); - break; - } - drawText( aPos, pStr+i, 1 ); - if( i < nLen-1 && pDeltaArray ) - { - aPoint.X() = (sal_Int32)(rPoint.X() + ((double)pDeltaArray[i] * fCos)); - aPoint.Y() = (sal_Int32)(rPoint.Y() + ((double)pDeltaArray[i] * fSin)); - } - - // swap text width/height again - SetFont( mnFontID, - nOldHeight, - nOldWidth, - nNormalAngle, - mbTextVertical, - maVirtualStatus.mbArtItalic, - maVirtualStatus.mbArtBold ); - } - i++; - nLastPos = i; - } - mnTextAngle = nNormalAngle; -} - -void -PrinterGfx::LicenseWarning(const Point& rPoint, const sal_Unicode* pStr, - sal_Int16 nLen, const sal_Int32* pDeltaArray) -{ - // treat it like a builtin font in case a user has that font also in the - // printer. This is not so unlikely as it may seem; no print embedding - // licensed fonts are often used (or so they say) in companies: - // they are installed on displays and printers, but get not embedded in - // print files or documents because they are not licensed for use outside - // the company. - OString aMessage( "The font " ); - aMessage += OUStringToOString( mrFontMgr.getPSName(mnFontID), - RTL_TEXTENCODING_ASCII_US ); - aMessage += " could not be downloaded\nbecause its license does not allow for that"; - PSComment( aMessage.getStr() ); - - OString aFontName = OUStringToOString( - mrFontMgr.getPSName(mnFontID), - RTL_TEXTENCODING_ASCII_US); - PSSetFont (aFontName, RTL_TEXTENCODING_ISO_8859_1); - - std::size_t nSize = 4 * nLen; - unsigned char* pBuffer = static_cast(alloca (nSize* sizeof(unsigned char))); - - ConverterFactory &rCvt = GetConverterFactory (); - nSize = rCvt.Convert (pStr, nLen, pBuffer, nSize, RTL_TEXTENCODING_ISO_8859_1); - - PSMoveTo (rPoint); - PSShowText (pBuffer, nLen, nSize, pDeltaArray); -} - -void -PrinterGfx::drawText( - const Point& rPoint, - const sal_Unicode* pStr, - sal_Int16 nLen, - const sal_Int32* pDeltaArray - ) -{ - if (!(nLen > 0)) - return; - - fonttype::type eType = mrFontMgr.getFontType (mnFontID); - - if ( eType == fonttype::TrueType - && !mrFontMgr.isFontDownloadingAllowedForPrinting(mnFontID)) - { - LicenseWarning(rPoint, pStr, nLen, pDeltaArray); - return; - } - - // search for a glyph set matching the set font - std::list< GlyphSet >::iterator aIter; - for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter) - if ( ((*aIter).GetFontID() == mnFontID) - && ((*aIter).IsVertical() == mbTextVertical)) - { - (*aIter).DrawText (*this, rPoint, pStr, nLen, pDeltaArray); - break; - } - - // not found ? create a new one - if (aIter == maPS3Font.end()) - { - maPS3Font.push_back (GlyphSet(mnFontID, mbTextVertical)); - maPS3Font.back().DrawText (*this, rPoint, pStr, nLen, pDeltaArray); - } -} - -int -PrinterGfx::getCharWidth (bool b_vert, sal_Unicode n_char, CharacterMetric *p_bbox) -{ - b_vert = b_vert && (getVerticalDeltaAngle(n_char) != 0); - int w = b_vert ? p_bbox->height : p_bbox->width; - w *= maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight; - return w; -} - -fontID -PrinterGfx::getCharMetric (const Font2 &rFont, sal_Unicode n_char, CharacterMetric *p_bbox) -{ - p_bbox->width = -1; - p_bbox->height = -1; - - for (fontID n = 0; n < Font2Size; n++) - { - fontID n_font = rFont.GetFont(n); - if (n_font != -1) - mrFontMgr.getMetrics( n_font, n_char, n_char, p_bbox ); - if (p_bbox->width >= 0 && p_bbox->height >= 0) - return n_font; - } - if (n_char != '?') - return getCharMetric (rFont, '?', p_bbox); - - return rFont.GetFont(0) != -1 ? rFont.GetFont(0) : rFont.GetFont(1); -} - /* * spool the converted truetype fonts to the page header after the page body is * complete -- cgit