diff options
author | Christof Pintaske <cp@openoffice.org> | 2001-07-06 15:11:14 +0000 |
---|---|---|
committer | Christof Pintaske <cp@openoffice.org> | 2001-07-06 15:11:14 +0000 |
commit | 1bd09fea1c26c2d491e12ab0c14f86e40139caba (patch) | |
tree | 01acb9808d1710b459e87dd106734aa86b925c90 /psprint/source | |
parent | a21bdc4f4c0ee2b80e5e19275b0580a1ed955fa0 (diff) |
#89352# use glyphset technique for type1 fonts as well
Diffstat (limited to 'psprint/source')
-rw-r--r-- | psprint/source/printergfx/common_gfx.cxx | 49 | ||||
-rw-r--r-- | psprint/source/printergfx/glyphset.cxx | 243 | ||||
-rw-r--r-- | psprint/source/printergfx/glyphset.hxx | 29 | ||||
-rw-r--r-- | psprint/source/printergfx/printerjob.cxx | 20 | ||||
-rw-r--r-- | psprint/source/printergfx/text_gfx.cxx | 145 |
5 files changed, 342 insertions, 144 deletions
diff --git a/psprint/source/printergfx/common_gfx.cxx b/psprint/source/printergfx/common_gfx.cxx index 4384feefe468..098bba2d80c9 100644 --- a/psprint/source/printergfx/common_gfx.cxx +++ b/psprint/source/printergfx/common_gfx.cxx @@ -2,9 +2,9 @@ * * $RCSfile: common_gfx.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: pl $ $Date: 2001-06-08 16:32:30 $ + * last change: $Author: cp $ $Date: 2001-07-06 16:10:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -625,7 +625,7 @@ void PrinterGfx::PSSetFont () { GraphicsStatus& rCurrent( currentState() ); - if( maVirtualStatus.maFont != rCurrent.maFont || + if( maVirtualStatus.maFont != rCurrent.maFont || maVirtualStatus.mnTextHeight != rCurrent.mnTextHeight || maVirtualStatus.maEncoding != rCurrent.maEncoding || maVirtualStatus.mnTextWidth != rCurrent.mnTextWidth ) @@ -636,28 +636,41 @@ PrinterGfx::PSSetFont () rCurrent.mnTextHeight = maVirtualStatus.mnTextHeight; sal_Int32 nTextHeight = rCurrent.mnTextHeight; - sal_Int32 nTextWidth = rCurrent.mnTextWidth ? rCurrent.mnTextWidth : rCurrent.mnTextHeight; + sal_Int32 nTextWidth = rCurrent.mnTextWidth ? rCurrent.mnTextWidth + : rCurrent.mnTextHeight; sal_Char pSetFont [256]; sal_Int32 nChar = 0; - nChar = psp::appendStr ("/", pSetFont); - nChar += psp::appendStr (rCurrent.maFont.getStr(), pSetFont + nChar); - switch (rCurrent.maEncoding) + nChar += psp::appendStr ("/", pSetFont + nChar); + nChar += psp::appendStr (rCurrent.maFont.getStr(), pSetFont + nChar); + + // postscript based fonts need reencoding + if ( ( rCurrent.maEncoding == RTL_TEXTENCODING_MS_1252) + || ( rCurrent.maEncoding == RTL_TEXTENCODING_ISO_8859_1) + || ( rCurrent.maEncoding >= RTL_TEXTENCODING_USER_START + && rCurrent.maEncoding <= RTL_TEXTENCODING_USER_END) + ) { - case RTL_TEXTENCODING_MS_1252: - case RTL_TEXTENCODING_ISO_8859_1: - nChar += psp::appendStr (" findfont1252 ", pSetFont + nChar); - break; - default: - nChar += psp::appendStr (" findfont ", pSetFont + nChar); - break; + rtl::OString aEncoding = + psp::GlyphSet::GetGlyphSetEncodingName (rCurrent.maEncoding, + rCurrent.maFont); + + nChar += psp::appendStr (" ", pSetFont + nChar); + nChar += psp::appendStr (aEncoding, pSetFont + nChar); + nChar += psp::appendStr (" psp_findfont ", pSetFont + nChar); } + else + // tt based fonts mustn't reencode, the encoding is implied by the fontname + // same for symbol type1 fonts, dont try to touch them + { + nChar += psp::appendStr (" findfont ", pSetFont + nChar); + } + nChar += psp::getValueOf (nTextWidth, pSetFont + nChar); - nChar += psp::appendStr (" ", pSetFont + nChar); - nChar += psp::getValueOf (-nTextHeight, pSetFont + nChar); - nChar += psp::appendStr (" matrix scale makefont setfont\n", - pSetFont + nChar); + nChar += psp::appendStr (" ", pSetFont + nChar); + nChar += psp::getValueOf (-nTextHeight, pSetFont + nChar); + nChar += psp::appendStr (" matrix scale makefont setfont\n", pSetFont + nChar); WritePS (mpPageBody, pSetFont); } diff --git a/psprint/source/printergfx/glyphset.cxx b/psprint/source/printergfx/glyphset.cxx index be0b3688b291..2e0d02fd1156 100644 --- a/psprint/source/printergfx/glyphset.cxx +++ b/psprint/source/printergfx/glyphset.cxx @@ -2,9 +2,9 @@ * * $RCSfile: glyphset.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: pl $ $Date: 2001-05-08 11:46:04 $ + * last change: $Author: cp $ $Date: 2001-07-06 16:10:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,6 +65,9 @@ #ifndef _PSPRINT_GLYPHSET_HXX_ #include <glyphset.hxx> #endif +#ifndef _PSPRINT_PRINTERUTIL_HXX_ +#include <psputil.hxx> +#endif #ifndef _PSPRINT_PRINTERGFX_HXX_ #include <psprint/printergfx.hxx> #endif @@ -77,6 +80,7 @@ #ifndef __SGI_STL_SET #include <set> #endif +#include <map> #ifndef _RTL_USTRING_HXX_ #include <rtl/ustring.hxx> @@ -96,7 +100,13 @@ GlyphSet::GlyphSet () GlyphSet::GlyphSet (sal_Int32 nFontID, sal_Bool bVertical) : mnFontID (nFontID), mbVertical (bVertical) -{} +{ + PrintFontManager &rMgr = PrintFontManager::get(); + meBaseType = rMgr.getFontType (mnFontID); + maBaseName = ::rtl::OUStringToOString (rMgr.getPSName(mnFontID), + RTL_TEXTENCODING_ASCII_US); + mnBaseEncoding = rMgr.getFontEncoding(mnFontID); +} GlyphSet::~GlyphSet () { @@ -109,6 +119,12 @@ GlyphSet::GetFontID () return mnFontID; } +fonttype::type +GlyphSet::GetFontType () +{ + return meBaseType; +} + sal_Bool GlyphSet::IsVertical () { @@ -124,6 +140,12 @@ GlyphSet::SetFont (sal_Int32 nFontID, sal_Bool bVertical) mnFontID = nFontID; mbVertical = bVertical; + PrintFontManager &rMgr = PrintFontManager::get(); + meBaseType = rMgr.getFontType (mnFontID); + maBaseName = ::rtl::OUStringToOString (rMgr.getPSName(mnFontID), + RTL_TEXTENCODING_ASCII_US); + mnBaseEncoding = rMgr.getFontEncoding(mnFontID); + return sal_True; } @@ -131,8 +153,8 @@ sal_Bool GlyphSet::GetGlyphID (sal_Unicode nChar, sal_uChar* nOutGlyphID, sal_Int32* nOutGlyphSetID) { - return LookupGlyphID (nChar, nOutGlyphID, nOutGlyphSetID) - || AddGlyphID (nChar, nOutGlyphID, nOutGlyphSetID); + return LookupGlyphID (nChar, nOutGlyphID, nOutGlyphSetID) + || AddGlyphID (nChar, nOutGlyphID, nOutGlyphSetID); } sal_Bool @@ -163,12 +185,52 @@ GlyphSet::LookupGlyphID (sal_Unicode nChar, return sal_False; } +sal_uChar +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 ? (sal_uChar)nAnsiChar : (sal_uChar)0; +} + +sal_uChar +GlyphSet::GetSymbolMapping (sal_Unicode nUnicodeChar) +{ + if (0x0000 < nUnicodeChar && nUnicodeChar < 0x0100) + return (sal_uChar)nUnicodeChar; + if (0xf000 < nUnicodeChar && nUnicodeChar < 0xf100) + return (sal_uChar)nUnicodeChar; + + return 0; +} + sal_Bool GlyphSet::AddGlyphID (sal_Unicode nChar, sal_uChar* nOutGlyphID, sal_Int32* nOutGlyphSetID) { - // create an empty glyphmap that is reserved for iso8859-1 glyphs - // and a second map that takes any other + sal_uChar 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 (maGlyphList.empty()) { glyph_mapping_t aMap, aMapp; @@ -177,20 +239,20 @@ GlyphSet::AddGlyphID (sal_Unicode nChar, maGlyphList.push_back (aMapp); } // if the last map is full, create a new one - if ((nChar > 255) && (maGlyphList.back().size() == 255)) + if ((!nMappedChar) && (maGlyphList.back().size() == 255)) { glyph_mapping_t aMap; maGlyphList.push_back (aMap); } // insert a new glyph in the font subset - if (nChar < 256) + if (nMappedChar) { - // always put latin1 chars into the first map, map them on itself + // always put iso1252 chars into the first map, map them on itself glyph_mapping_t& aGlyphSet = maGlyphList.front(); - aGlyphSet [nChar] = nChar; + aGlyphSet [nChar] = nMappedChar; *nOutGlyphSetID = 1; - *nOutGlyphID = nChar; + *nOutGlyphID = nMappedChar; } else { @@ -205,16 +267,62 @@ GlyphSet::AddGlyphID (sal_Unicode nChar, } rtl::OString -GlyphSet::GetGlyphSetName (sal_Int32 nGlyphSetID, PrintFontManager& rFontMgr) +GlyphSet::GetGlyphSetName (sal_Int32 nGlyphSetID) +{ + if (meBaseType == fonttype::TrueType) + { + return maBaseName + + (mbVertical ? rtl::OString ("VSet") : rtl::OString ("HSet") ) + + rtl::OString::valueOf (nGlyphSetID); + } + else + /* (meBaseType == fonttype::Type1 || meBaseType == fonttype::Builtin) */ + { + return maBaseName; + } +} + +sal_Int32 +GlyphSet::GetGlyphSetEncoding (sal_Int32 nGlyphSetID) +{ + if (meBaseType == fonttype::TrueType) + return RTL_TEXTENCODING_DONTKNOW; + else + { + /* (meBaseType == fonttype::Type1 || meBaseType == fonttype::Builtin) */ + if (mnBaseEncoding == RTL_TEXTENCODING_SYMBOL) + return RTL_TEXTENCODING_SYMBOL; + else + return nGlyphSetID == 1 ? RTL_TEXTENCODING_MS_1252 + : RTL_TEXTENCODING_USER_START + nGlyphSetID; + } +} + +rtl::OString +GlyphSet::GetGlyphSetEncodingName (rtl_TextEncoding nEnc, const rtl::OString &rFontName) +{ + if ( nEnc == RTL_TEXTENCODING_MS_1252 + || nEnc == RTL_TEXTENCODING_ISO_8859_1) + { + return rtl::OString("ISO1252Encoding"); + } + else + if (nEnc >= RTL_TEXTENCODING_USER_START && nEnc <= RTL_TEXTENCODING_USER_END) + { + return rFontName + + rtl::OString("Enc") + + rtl::OString::valueOf ((sal_Int32)(nEnc - RTL_TEXTENCODING_USER_START)); + } + else + { + return rtl::OString(); + } +} + +rtl::OString +GlyphSet::GetGlyphSetEncodingName (sal_Int32 nGlyphSetID) { - // concatenate the postscript name and the glyphsetid to make a unique name - if (maBaseName.getLength() == 0) - maBaseName = ::rtl::OUStringToOString (rFontMgr.getPSName(mnFontID), - RTL_TEXTENCODING_ASCII_US); - - return maBaseName - + (mbVertical ? rtl::OString ("VSet") : rtl::OString ("HSet") ) - + rtl::OString::valueOf (nGlyphSetID); + return GetGlyphSetEncodingName (GetGlyphSetEncoding(nGlyphSetID), maBaseName); } void @@ -258,7 +366,7 @@ GlyphSet::ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, } // show the text using the PrinterGfx text api - rGfx.PSSetFont (GetGlyphSetName(nGlyphSetID, rGfx.GetFontMgr())); + rGfx.PSSetFont (GetGlyphSetName(nGlyphSetID), GetGlyphSetEncoding(nGlyphSetID)); rGfx.PSShowText (pGlyphID + nChar, nGlyphs, nGlyphs); nChar += nGlyphs; @@ -312,15 +420,92 @@ GlyphSet::ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, // show the text using the PrinterGfx text api aPoint.Move (pDeltaSubset[0], 0); - rGfx.PSSetFont (GetGlyphSetName(*aSet, rGfx.GetFontMgr())); + rGfx.PSSetFont (GetGlyphSetName(*aSet), GetGlyphSetEncoding(*aSet)); rGfx.PSMoveTo (aPoint); rGfx.PSShowText (pGlyphSubset, nGlyphs, nGlyphs, nGlyphs > 1 ? pDeltaSubset + 1 : NULL); } } sal_Bool +GlyphSet::PSUploadEncoding(osl::File* pOutFile, PrinterGfx &rGfx) +{ + // only for ps fonts + if ((meBaseType != fonttype::Builtin) && (meBaseType != fonttype::Type1)) + return sal_False; + + PrintFontManager &rMgr = rGfx.GetFontMgr(); + + // loop thru all the font subsets + sal_Int32 nGlyphSetID = 0; + glyphlist_t::iterator aGlyphSet; + for (aGlyphSet = maGlyphList.begin(); aGlyphSet != maGlyphList.end(); ++aGlyphSet) + { + ++nGlyphSetID; + + if (nGlyphSetID == 1) // iso1252 anyway, doesn't need reencoding + continue; + if ((*aGlyphSet).size() == 0) // empty set, doesn't need reencoding + continue; + + sal_Char pEncodingVector [256]; + sal_Int32 nSize = 0; + + nSize += psp::appendStr ("/", + pEncodingVector + nSize); + nSize += psp::appendStr (GetGlyphSetEncodingName(nGlyphSetID), + pEncodingVector + nSize); + nSize += psp::appendStr (" [ ", + pEncodingVector + nSize); + + // need a list of glyphs, sorted by glyphid + typedef std::map< sal_uInt8, sal_Unicode > ps_mapping_t; + typedef ps_mapping_t::value_type ps_value_t; + ps_mapping_t aSortedGlypSet; + + glyph_mapping_t::const_iterator aUnsortedGlyph; + for (aUnsortedGlyph = (*aGlyphSet).begin(); + aUnsortedGlyph != (*aGlyphSet).end(); + aUnsortedGlyph++) + { + aSortedGlypSet.insert(ps_value_t((*aUnsortedGlyph).second, + (*aUnsortedGlyph).first)); + } + + ps_mapping_t::const_iterator aSortedGlyph; + // loop thru all the glyphs in the subset + for (aSortedGlyph = (aSortedGlypSet).begin(); + aSortedGlyph != (aSortedGlypSet).end(); + aSortedGlyph++) + { + nSize += psp::appendStr ("/", + pEncodingVector + nSize); + nSize += psp::appendStr (rMgr.getAdobeNameFromUnicode((*aSortedGlyph).second), + pEncodingVector + nSize); + nSize += psp::appendStr (" ", + pEncodingVector + nSize); + // flush line + if (nSize >= 70) + { + nSize += psp::appendStr ("\n", pEncodingVector + nSize); + psp::WritePS (pOutFile, pEncodingVector); + nSize = 0; + } + } + + nSize += psp::appendStr ("] def\n", pEncodingVector + nSize); + psp::WritePS (pOutFile, pEncodingVector); + } + + return sal_True; +} + +sal_Bool GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42 ) { + // only for truetype fonts + if (meBaseType != fonttype::TrueType) + return sal_False; + TrueTypeFont *pTTFont; rtl::OString aTTFileName (rGfx.GetFontMgr().getFontFileSysPath(mnFontID)); int nFace = rGfx.GetFontMgr().getFontFaceNumber(mnFontID); @@ -364,14 +549,12 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42 ) // create the current subset if( bAsType42 ) - CreateT42FromTTGlyphs(pTTFont, pTmpFile, - GetGlyphSetName(nGlyphSetID, rGfx.GetFontMgr()), - pTTGlyphMapping, pEncoding, (*aGlyphSet).size() ); + CreateT42FromTTGlyphs (pTTFont, pTmpFile, GetGlyphSetName(nGlyphSetID), + pTTGlyphMapping, pEncoding, (*aGlyphSet).size() ); else - CreateT3FromTTGlyphs(pTTFont, pTmpFile, - GetGlyphSetName(nGlyphSetID, rGfx.GetFontMgr()), - pTTGlyphMapping, pEncoding, (*aGlyphSet).size(), - 0 /* 0 = horizontal, 1 = vertical */ ); + CreateT3FromTTGlyphs (pTTFont, pTmpFile, GetGlyphSetName(nGlyphSetID), + pTTGlyphMapping, pEncoding, (*aGlyphSet).size(), + 0 /* 0 = horizontal, 1 = vertical */ ); } // copy the file into the page header diff --git a/psprint/source/printergfx/glyphset.hxx b/psprint/source/printergfx/glyphset.hxx index 163fffdcf60a..da089f29b4c3 100644 --- a/psprint/source/printergfx/glyphset.hxx +++ b/psprint/source/printergfx/glyphset.hxx @@ -2,9 +2,9 @@ * * $RCSfile: glyphset.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: pl $ $Date: 2001-05-08 11:46:04 $ + * last change: $Author: cp $ $Date: 2001-07-06 16:10:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,6 +62,9 @@ #ifndef _PSPRINT_GLYPHSET_HXX_ #define _PSPRINT_GLYPHSET_HXX_ +#ifndef _PSPRINT_FONTMANAGER_HXX_ +#include <psprint/fontmanager.hxx> +#endif #ifndef _OSL_FILE_HXX_ #include <osl/file.hxx> #endif @@ -87,24 +90,28 @@ class GlyphSet { private: - sal_Int32 mnFontID; - sal_Bool mbVertical; - rtl::OString maBaseName; - bool mbUploadPS42Fonts; + sal_Int32 mnFontID; + sal_Bool mbVertical; + rtl::OString maBaseName; + fonttype::type meBaseType; + rtl_TextEncoding mnBaseEncoding; typedef std::hash_map< sal_Unicode, sal_uInt8 > glyph_mapping_t; typedef std::list< glyph_mapping_t > glyphlist_t; glyphlist_t maGlyphList; - rtl::OString GetGlyphSetName (sal_Int32 nGlyphSetID, - PrintFontManager& rFontMgr); + rtl::OString GetGlyphSetName (sal_Int32 nGlyphSetID); + sal_Int32 GetGlyphSetEncoding (sal_Int32 nGlyphSetID); + rtl::OString GetGlyphSetEncodingName (sal_Int32 nGlyphSetID); sal_Bool GetGlyphID (sal_Unicode nChar, sal_uChar* nOutGlyphID, sal_Int32* nOutGlyphSetID); sal_Bool LookupGlyphID (sal_Unicode nChar, sal_uChar* nOutGlyphID, sal_Int32* nOutGlyphSetID); sal_Bool AddGlyphID (sal_Unicode nChar, sal_uChar* nOutGlyphID, sal_Int32* nOutGlyphSetID); + sal_uChar GetAnsiMapping (sal_Unicode nUnicodeChar); + sal_uChar GetSymbolMapping (sal_Unicode nUnicodeChar); void ImplDrawText (PrinterGfx &rGfx, const Point& rPoint, const sal_Unicode* pStr, sal_Int16 nLen); @@ -119,6 +126,10 @@ class GlyphSet ~GlyphSet (); sal_Int32 GetFontID (); + fonttype::type GetFontType (); + static rtl::OString + GetGlyphSetEncodingName (rtl_TextEncoding nEnc, + const rtl::OString &rFontName); sal_Bool IsVertical (); sal_Bool SetFont (sal_Int32 nFontID, sal_Bool bVertical); @@ -126,7 +137,7 @@ class GlyphSet void DrawText (PrinterGfx &rGfx, const Point& rPoint, const sal_Unicode* pStr, sal_Int16 nLen, const sal_Int32* pDeltaArray = NULL); - + sal_Bool PSUploadEncoding(osl::File* pOutFile, PrinterGfx &rGfx); sal_Bool PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42 ); }; diff --git a/psprint/source/printergfx/printerjob.cxx b/psprint/source/printergfx/printerjob.cxx index 1767c4d3ae8e..7f1151c310a7 100644 --- a/psprint/source/printergfx/printerjob.cxx +++ b/psprint/source/printergfx/printerjob.cxx @@ -2,9 +2,9 @@ * * $RCSfile: printerjob.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: pl $ $Date: 2001-07-05 16:36:55 $ + * last change: $Author: cp $ $Date: 2001-07-06 16:11:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -795,17 +795,11 @@ bool PrinterJob::writeProlog (osl::File* pFile) "/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis\n" "/eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide\n" "/oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis] def\n" - "/findfont1252 {\n" - "findfont\n" - "dup length dict begin\n" - "{ 1 index /FID ne\n" - " { def }\n" - " { pop pop }\n" - " ifelse\n" - "} forall\n" - "/Encoding ISO1252Encoding def\n" - "currentdict end\n" - "/reenc1252font exch definefont } def\n" + "\n" + "/psp_findfont { exch dup findfont dup length dict begin\n" + "{ 1 index /FID ne { def } { pop pop } ifelse } forall\n" + "/Encoding 3 -1 roll def currentdict end /psp_reencodedfont\n" + "exch definefont } def\n" "\n" "/pathdict dup 8 dict def load begin\n" "/rcmd { { currentfile 1 string readstring pop 0 get dup 32 gt { exit }\n" diff --git a/psprint/source/printergfx/text_gfx.cxx b/psprint/source/printergfx/text_gfx.cxx index 96ce29fc439a..8000845f85ae 100644 --- a/psprint/source/printergfx/text_gfx.cxx +++ b/psprint/source/printergfx/text_gfx.cxx @@ -2,9 +2,9 @@ * * $RCSfile: text_gfx.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: pl $ $Date: 2001-06-13 13:09:46 $ + * last change: $Author: cp $ $Date: 2001-07-06 16:11:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -413,6 +413,37 @@ void PrinterGfx::drawVerticalizedText( } void +PrinterGfx::LicenceWarning(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. + rtl::OString aMessage( "The font " ); + aMessage += rtl::OUStringToOString( mrFontMgr.getPSName(mnFontID), + RTL_TEXTENCODING_ASCII_US ); + aMessage += " could not be downloaded\nbecause its license does not allow for that"; + PSComment( aMessage.getStr() ); + + rtl::OString aFontName = rtl::OUStringToOString( + mrFontMgr.getPSName(mnFontID), + RTL_TEXTENCODING_ASCII_US); + PSSetFont (aFontName, RTL_TEXTENCODING_ISO_8859_1); + + sal_Size nSize = 4 * nLen; + sal_uChar* pBuffer = (sal_uChar*)alloca (nSize* sizeof(sal_uChar)); + + ConverterFactory* pCvt = GetConverterFactory (); + nSize = pCvt->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, @@ -423,82 +454,35 @@ PrinterGfx::drawText( if (!(nLen > 0)) return; - fonttype::type eType = mrFontMgr.getFontType (mnFontID); - rtl_TextEncoding nEncoding = mrFontMgr.getFontEncoding (mnFontID); + fonttype::type eType = mrFontMgr.getFontType (mnFontID); + fonttype::type eEffectiveType = fonttype::Unknown; + rtl_TextEncoding nEncoding = mrFontMgr.getFontEncoding (mnFontID); - switch (eType) - { - case fonttype::Type1: - PSUploadPS1Font (mnFontID); - case fonttype::TrueType: - // not nice but necessary since both fonttype::Type1 and - // fonttype::TrueType rely on not breaking here - if( eType == fonttype::TrueType ) - { - if( mrFontMgr.isFontDownloadingAllowed( mnFontID ) ) - { - // 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); - } - break; - } - else - { - // 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. - rtl::OString aMessage( "The font " ); - aMessage += rtl::OUStringToOString( mrFontMgr.getPSName(mnFontID), RTL_TEXTENCODING_ASCII_US ); - aMessage += " could not be downloaded\nbecause its license does not allow for that"; - PSComment( aMessage.getStr() ); - } - } - case fonttype::Builtin: - { - rtl::OString aFontName = rtl::OUStringToOString( - mrFontMgr.getPSName(mnFontID), - RTL_TEXTENCODING_ASCII_US); - PSSetFont (aFontName, nEncoding); - - sal_Size nSize = 4 * nLen; - sal_uChar* pBuffer = (sal_uChar*)alloca (nSize* sizeof(sal_uChar)); + if (eType == fonttype::Type1) + PSUploadPS1Font (mnFontID); - ConverterFactory* pCvt = GetConverterFactory (); - nSize = pCvt->Convert (pStr, nLen, pBuffer, nSize, nEncoding); - - PSMoveTo (rPoint); - PSShowText (pBuffer, nLen, nSize, pDeltaArray); - } - break; + if ( eType == fonttype::TrueType + && !mrFontMgr.isFontDownloadingAllowed(mnFontID)) + { + LicenceWarning(rPoint, pStr, nLen, pDeltaArray); + return; + } - default: + // 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)) { - WritePS (mpPageBody, "%%%% Error: unsupported font "); - WritePS (mpPageBody, mrFontMgr.getPSName(mnFontID)); - WritePS (mpPageBody, " ID: "); - WritePS (mpPageBody, rtl::OString::valueOf (mnFontID)); - WritePS (mpPageBody, " Type: "); - WritePS (mpPageBody, rtl::OString::valueOf ((sal_Int32)eType)); - WritePS (mpPageBody, "\n"); + (*aIter).DrawText (*this, rPoint, pStr, nLen, pDeltaArray); + break; } - 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); } } @@ -607,6 +591,8 @@ PrinterGfx::GetGlyphOutline (sal_Unicode c, /* * spool the converted truetype fonts to the page header after the page body is * complete + * for Type1 fonts spool additional reencoding vectors that are necessary to access the + * whole font */ void @@ -614,6 +600,17 @@ PrinterGfx::OnEndPage () { std::list< GlyphSet >::iterator aIter; for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter) - aIter->PSUploadFont (*mpPageHeader, *this, mbUploadPS42Fonts ? true : false ); + { + if (aIter->GetFontType() == fonttype::TrueType) + { + aIter->PSUploadFont (*mpPageHeader, *this, mbUploadPS42Fonts ? true : false ); + } + else + // ( aIter->GetFontType() == fonttype::Type1 + // || aIter->GetFontType() == fonttype::Builtin ) + { + aIter->PSUploadEncoding (mpPageHeader, *this); + } + } } |