summaryrefslogtreecommitdiff
path: root/psprint
diff options
context:
space:
mode:
authorPhilipp Lohmann <pl@openoffice.org>2002-07-20 14:21:19 +0000
committerPhilipp Lohmann <pl@openoffice.org>2002-07-20 14:21:19 +0000
commit0efc6d5c88d48c61aea5bdeefcf67a537b82145a (patch)
tree4e44310b95511336d3553c6a647d5ceab464e388 /psprint
parentfe83724c95c5f1c5fe3ed1a791afaba600ff55a9 (diff)
#100608# enhance functionality needed for PDF export
Diffstat (limited to 'psprint')
-rw-r--r--psprint/inc/psprint/fontmanager.hxx40
-rw-r--r--psprint/source/fontmanager/fontcache.cxx8
-rw-r--r--psprint/source/fontmanager/fontmanager.cxx181
-rw-r--r--psprint/source/fontmanager/parseAFM.cxx35
4 files changed, 237 insertions, 27 deletions
diff --git a/psprint/inc/psprint/fontmanager.hxx b/psprint/inc/psprint/fontmanager.hxx
index 4987ae1ea98d..443247996fdf 100644
--- a/psprint/inc/psprint/fontmanager.hxx
+++ b/psprint/inc/psprint/fontmanager.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: fontmanager.hxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: pl $ $Date: 2002-02-28 11:49:51 $
+ * last change: $Author: pl $ $Date: 2002-07-20 15:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -276,6 +276,10 @@ class PrintFontManager
int m_nAscend;
int m_nDescend;
int m_nLeading;
+ int m_nXMin; // font bounding box
+ int m_nYMin;
+ int m_nXMax;
+ int m_nYMax;
bool m_bHaveVerticalSubstitutedGlyphs;
PrintFont( fonttype::type eType );
@@ -472,14 +476,7 @@ public:
}
// get the ttc face number
- int getFontFaceNumber( fontID nFontID ) const
- {
- int nRet = -1;
- PrintFont* pFont = getFont( nFontID );
- if( pFont->m_eType == fonttype::TrueType )
- nRet = static_cast< TrueTypeFontFile* >(pFont)->m_nCollectionEntry;
- return nRet;
- }
+ int getFontFaceNumber( fontID nFontID ) const;
// get a specific fonts global metrics
const CharacterMetric& getGlobalFontMetric( fontID nFontID, bool bHorizontal ) const;
@@ -493,6 +490,9 @@ public:
// get a specific fonts leading
int getFontLeading( fontID nFontID ) const;
+ // get a fonts glyph bounding box
+ bool getFontBoundingBox( fontID nFont, int& xMin, int& yMin, int& xMax, int& yMax );
+
// info whether there are vertical substitutions
bool hasVerticalSubstitutions( fontID nFontID ) const;
@@ -550,6 +550,26 @@ public:
return m_aAdobecodeToUnicode.equal_range( aChar );
}
+ // creates a new font subset of an existing TrueType font
+ // returns true in case of success, else false
+ // nFont: the font to be subsetted
+ // rOutFile: the file to put the new subset into;
+ // must be a valid osl file URL
+ // pGlyphIDs: input array of glyph ids for new font
+ // pNewEncoding: the corresponding encoding in the new font
+ // pWidths: output array of widths of requested glyphs
+ // nGlyphs: number of glyphs in arrays
+ // pCapHeight:: capital height of the produced font
+ // pXMin, pYMin, pXMax, pYMax: outgoing font bounding box
+ bool createFontSubset( fontID nFont,
+ const ::rtl::OUString& rOutFile,
+ long* pGlyphIDs,
+ sal_uInt8* pNewEncoding,
+ sal_Int32* pWidths,
+ int nGlyphs,
+ bool bVertical = false
+ );
+
// font administration functions
// for importFonts to provide the user feedback
diff --git a/psprint/source/fontmanager/fontcache.cxx b/psprint/source/fontmanager/fontcache.cxx
index d4a5850bd66d..229468ce71e9 100644
--- a/psprint/source/fontmanager/fontcache.cxx
+++ b/psprint/source/fontmanager/fontcache.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: fontcache.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: pl $ $Date: 2002-04-12 12:39:43 $
+ * last change: $Author: pl $ $Date: 2002-07-20 15:21:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -475,6 +475,10 @@ void FontCache::copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFo
pTo->m_nAscend = pFrom->m_nAscend;
pTo->m_nDescend = pFrom->m_nDescend;
pTo->m_nLeading = pFrom->m_nLeading;
+ pTo->m_nXMin = pFrom->m_nXMin;
+ pTo->m_nYMin = pFrom->m_nYMin;
+ pTo->m_nXMax = pFrom->m_nXMax;
+ pTo->m_nYMax = pFrom->m_nYMax;
pTo->m_bHaveVerticalSubstitutedGlyphs = pFrom->m_bHaveVerticalSubstitutedGlyphs;
}
diff --git a/psprint/source/fontmanager/fontmanager.cxx b/psprint/source/fontmanager/fontmanager.cxx
index 06e85aeed01d..77371a5fabaf 100644
--- a/psprint/source/fontmanager/fontmanager.cxx
+++ b/psprint/source/fontmanager/fontmanager.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: fontmanager.cxx,v $
*
- * $Revision: 1.24 $
+ * $Revision: 1.25 $
*
- * last change: $Author: pl $ $Date: 2002-05-21 10:44:57 $
+ * last change: $Author: pl $ $Date: 2002-07-20 15:21:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -252,6 +252,10 @@ PrintFontManager::PrintFont::PrintFont( fonttype::type eType ) :
m_nAscend( 0 ),
m_nDescend( 0 ),
m_nLeading( 0 ),
+ m_nXMin( 0 ),
+ m_nYMin( 0 ),
+ m_nXMax( 0 ),
+ m_nYMax( 0 ),
m_bHaveVerticalSubstitutedGlyphs( false )
{
}
@@ -614,6 +618,11 @@ bool PrintFontManager::PrintFont::readAfmMetrics( const OString& rFileName, Mult
m_aGlobalMetricX.height = m_aGlobalMetricY.height =
pInfo->gfi->capHeight ? pInfo->gfi->capHeight : pInfo->gfi->fontBBox.ury;
+ m_nXMin = pInfo->gfi->fontBBox.llx;
+ m_nYMin = pInfo->gfi->fontBBox.lly;
+ m_nXMax = pInfo->gfi->fontBBox.urx;
+ m_nYMax = pInfo->gfi->fontBBox.ury;
+
// fill in character metrics
// first transform the character codes to unicode
@@ -1453,6 +1462,12 @@ bool PrintFontManager::analyzeTrueTypeFile( PrintFont* pFont ) const
if( pFont->m_nAscend )
pFont->m_aGlobalMetricX.height = pFont->m_aGlobalMetricY.height = pFont->m_nAscend + pFont->m_nDescend;
+ // get bounding box
+ pFont->m_nXMin = aInfo.xMin;
+ pFont->m_nYMin = aInfo.yMin;
+ pFont->m_nXMax = aInfo.xMax;
+ pFont->m_nYMax = aInfo.yMax;
+
// get type flags
pTTFontFile->m_nTypeFlags = (unsigned int)aInfo.typeFlags;
@@ -2020,6 +2035,43 @@ bool PrintFontManager::getFontFastInfo( fontID nFontID, FastPrintFontInfo& rInfo
// -------------------------------------------------------------------------
+bool PrintFontManager::getFontBoundingBox( fontID nFontID, int& xMin, int& yMin, int& xMax, int& yMax )
+{
+ bool bSuccess = false;
+ PrintFont* pFont = getFont( nFontID );
+ if( pFont )
+ {
+ if( pFont->m_nXMin == 0 && pFont->m_nYMin == 0 && pFont->m_nXMax == 0 && pFont->m_nYMax == 0 )
+ {
+ // might be a truetype font not analyzed or type1 without metrics read
+ if( pFont->m_eType == fonttype::Type1 )
+ pFont->readAfmMetrics( getAfmFile( pFont ), m_pAtoms );
+ else if( pFont->m_eType == fonttype::TrueType )
+ analyzeTrueTypeFile( pFont );
+ }
+ bSuccess = true;
+ xMin = pFont->m_nXMin;
+ yMin = pFont->m_nYMin;
+ xMax = pFont->m_nXMax;
+ yMax = pFont->m_nYMax;
+ }
+ return bSuccess;
+}
+
+// -------------------------------------------------------------------------
+
+int PrintFontManager::getFontFaceNumber( fontID nFontID ) const
+{
+ int nRet = -1;
+ PrintFont* pFont = getFont( nFontID );
+ if( pFont && pFont->m_eType == fonttype::TrueType )
+ nRet = static_cast< TrueTypeFontFile* >(pFont)->m_nCollectionEntry;
+ return nRet;
+}
+
+// -------------------------------------------------------------------------
+
+
family::type PrintFontManager::matchFamilyName( const ::rtl::OUString& rFamily ) const
{
typedef struct {
@@ -3040,3 +3092,128 @@ bool PrintFontManager::getAlternativeFamilyNames( fontID nFont, ::std::list< OUS
}
return rNames.begin() != rNames.end();
}
+
+// -------------------------------------------------------------------------
+
+bool PrintFontManager::createFontSubset(
+ fontID nFont,
+ const OUString& rOutFile,
+ long* pGlyphIDs,
+ sal_uInt8* pNewEncoding,
+ sal_Int32* pWidths,
+ int nGlyphs,
+ bool bVertical
+ )
+{
+ int i;
+ // glyph 0 is needed in position 0
+ // look if 0 is already there
+ int nDefault = -1;
+ for( i = 0; i < nGlyphs; i++ )
+ {
+ if( ! pGlyphIDs[i] )
+ {
+ nDefault = i;
+ break;
+ }
+ }
+ if( nDefault != 0) // reordering has to take place
+ {
+ if( nDefault == -1 )
+ nGlyphs++;
+
+ long* pIDs = (long*)rtl_allocateMemory( sizeof(long)*nGlyphs );
+ sal_uInt8* pEnc = (sal_uInt8*)rtl_allocateMemory( sizeof(sal_uInt8)*nGlyphs );
+ sal_Int32* pW = (sal_Int32*)rtl_allocateMemory( sizeof(sal_Int32)*nGlyphs );
+ if( nDefault == -1 )
+ {
+ for( i = 0; i < nGlyphs-1; i++ )
+ {
+ pIDs[i+1] = pGlyphIDs[i];
+ pEnc[i+1] = pNewEncoding[i];
+ }
+ }
+ else
+ {
+ for( i = 0; i < nGlyphs; i++ )
+ {
+ pIDs[i] = pGlyphIDs[i];
+ pEnc[i] = pNewEncoding[i];
+ }
+ pIDs[ nDefault ] = pIDs[0];
+ pEnc[ nDefault ] = pIDs[0];
+ }
+ pIDs[0] = 0;
+ pEnc[0] = 0;
+
+ bool bSuccess = createFontSubset( nFont, rOutFile, pIDs, pEnc, pW, nGlyphs, bVertical );
+ if( bSuccess && pWidths )
+ {
+ if( nDefault == -1 )
+ {
+ for( i = 0; i < nGlyphs-1; i++ )
+ pWidths[i] = pW[i+1];
+ }
+ else
+ {
+ for( i = 0; i < nGlyphs; i++ )
+ pWidths[i] = pW[i];
+ pWidths[ nDefault ] = pW[0];
+ pWidths[ 0 ] = pW[ nDefault ];
+ }
+ }
+ rtl_freeMemory( pIDs );
+ rtl_freeMemory( pW );
+ rtl_freeMemory( pEnc );
+
+ return bSuccess;
+ }
+
+ PrintFont* pFont = getFont( nFont );
+ if( pFont->m_eType != fonttype::TrueType )
+ return false;
+
+ OUString aSysPath;
+ if( osl_File_E_None != osl_getSystemPathFromFileURL( rOutFile.pData, &aSysPath.pData ) )
+ return false;
+
+ rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
+ ByteString aFromFile = getFontFile( pFont );
+ ByteString aToFile( OUStringToOString( aSysPath, aEncoding ) );
+
+ TrueTypeFont* pTTFont = NULL;
+ TrueTypeFontFile* pTTFontFile = static_cast< TrueTypeFontFile* >(pFont);
+ if( OpenTTFont( aFromFile.GetBuffer(), pTTFontFile->m_nCollectionEntry < 0 ? 0 : pTTFontFile->m_nCollectionEntry, &pTTFont ) != SF_OK )
+ return false;
+
+ uint16* pTempIDs = (uint16*)rtl_allocateMemory( sizeof(uint16)*nGlyphs );
+ for( i = 0; i < nGlyphs; i++ )
+ pTempIDs[i] = (uint16)pGlyphIDs[i];
+ TTSimpleGlyphMetrics* pMetrics = GetTTSimpleGlyphMetrics( pTTFont,
+ pTempIDs,
+ nGlyphs,
+ bVertical ? 1 : 0 );
+ if( pMetrics )
+ {
+ for( i = 0; i < nGlyphs; i++ )
+ pWidths[i] = pMetrics[i].adv;
+ free( pMetrics );
+ }
+ else
+ {
+ rtl_freeMemory( pTempIDs );
+ return false;
+ }
+
+ bool bSuccess = ( SF_OK == CreateTTFromTTGlyphs( pTTFont,
+ aToFile.GetBuffer(),
+ pTempIDs,
+ pNewEncoding,
+ nGlyphs,
+ 0,
+ NULL,
+ TTCF_IncludeOS2 ) );
+
+ rtl_freeMemory( pTempIDs );
+ return bSuccess;
+}
diff --git a/psprint/source/fontmanager/parseAFM.cxx b/psprint/source/fontmanager/parseAFM.cxx
index 201bb11c8894..179e4e4aef7a 100644
--- a/psprint/source/fontmanager/parseAFM.cxx
+++ b/psprint/source/fontmanager/parseAFM.cxx
@@ -37,9 +37,9 @@
*
* $RCSfile: parseAFM.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: cp $ $Date: 2001-05-22 16:37:39 $
+ * last change: $Author: pl $ $Date: 2002-07-20 15:21:19 $
*
************************************************************************/
@@ -117,14 +117,14 @@ static char *ident = NULL; /* storage buffer for keywords */
// which is not allowed per afm spcification, but let us handle
// this gently
enum parseKey {
- ASCENDER, ASCENT, CHARBBOX, CODE, COMPCHAR, CODEHEX, CAPHEIGHT, CHARWIDTH, CHARACTERS, COMMENT,
+ ASCENDER, ASCENT, CHARBBOX, CODE, COMPCHAR, CODEHEX, CAPHEIGHT, CHARWIDTH, CHARACTERSET, CHARACTERS, COMMENT,
DESCENDER, DESCENT, EM, ENCODINGSCHEME, ENDCHARMETRICS, ENDCOMPOSITES, ENDDIRECTION,
ENDFONTMETRICS, ENDKERNDATA, ENDKERNPAIRS, ENDTRACKKERN,
FAMILYNAME, FONTBBOX, FONTNAME, FULLNAME, ISBASEFONT, ISFIXEDPITCH,
ITALICANGLE, KERNPAIR, KERNPAIRXAMT, LIGATURE, MAPPINGSCHEME, METRICSSETS, CHARNAME,
NOTICE, COMPCHARPIECE, STARTCHARMETRICS, STARTCOMPOSITES, STARTDIRECTION,
STARTFONTMETRICS, STARTKERNDATA, STARTKERNPAIRS,
- STARTTRACKKERN, TRACKKERN, UNDERLINEPOSITION,
+ STARTTRACKKERN, STDHW, STDVW, TRACKKERN, UNDERLINEPOSITION,
UNDERLINETHICKNESS, VVECTOR, VERSION, XYWIDTH, X0WIDTH, XWIDTH, WEIGHT, XHEIGHT,
NOPE
};
@@ -143,14 +143,14 @@ enum parseKey {
*/
static char *keyStrings[] = {
- "Ascender", "Ascent", "B", "C", "CC", "CH", "CapHeight", "CharWidth", "Characters", "Comment",
+ "Ascender", "Ascent", "B", "C", "CC", "CH", "CapHeight", "CharWidth", "CharacterSet" ,"Characters", "Comment",
"Descender", "Descent", "Em", "EncodingScheme", "EndCharMetrics", "EndComposites", "EndDirection",
"EndFontMetrics", "EndKernData", "EndKernPairs", "EndTrackKern",
"FamilyName", "FontBBox", "FontName", "FullName", "IsBaseFont", "IsFixedPitch",
"ItalicAngle", "KP", "KPX", "L", "MappingScheme", "MetricsSets", "N",
"Notice", "PCC", "StartCharMetrics", "StartComposites", "StartDirection",
"StartFontMetrics", "StartKernData", "StartKernPairs",
- "StartTrackKern", "TrackKern", "UnderlinePosition",
+ "StartTrackKern", "StdHW", "StdVW", "TrackKern", "UnderlinePosition",
"UnderlineThickness", "V", "Version", "W", "W0X", "WX", "Weight", "XHeight",
NULL};
@@ -419,6 +419,15 @@ static int parseGlobals( FILE* fp, register GlobalFontInfo* gfi )
case ISBASEFONT:
keyword = token(fp);
break; /* ignore this for now */
+ case CHARACTERSET:
+ keyword=token(fp); //ignore
+ break;
+ case STDHW:
+ keyword=token(fp); //ignore
+ break;
+ case STDVW:
+ keyword=token(fp); //ignore
+ break;
case CHARWIDTH:
keyword = token(fp);
if (direction == 0)
@@ -547,7 +556,7 @@ static int initializeArray( FILE* fp, register int* cwi)
* parseFile to determine if there is more file to parse.
*/
-static parseCharWidths( FILE* fp, register int* cwi)
+static int parseCharWidths( FILE* fp, register int* cwi)
{
bool cont = true, save = (cwi != NULL);
int pos = 0, error = ok;
@@ -701,7 +710,7 @@ enlargeCount( unsigned int n_oldcount )
* parseFile to determine if there is more file to parse.
*/
-static parseCharMetrics( FILE* fp, register FontInfo* fi)
+static int parseCharMetrics( FILE* fp, register FontInfo* fi)
{
bool cont = true, firstTime = true;
int error = ok, count = 0;
@@ -754,7 +763,7 @@ static parseCharMetrics( FILE* fp, register FontInfo* fi)
}
if (count < fi->numOfChars) {
if (firstTime)
- firstTime = FALSE;
+ firstTime = false;
else
temp++;
sscanf(token(fp),"<%x>", &temp->code);
@@ -764,7 +773,7 @@ static parseCharMetrics( FILE* fp, register FontInfo* fi)
}
else {
error = parseError;
- cont = FALSE;
+ cont = false;
}
break;
case XYWIDTH:
@@ -853,7 +862,7 @@ static parseCharMetrics( FILE* fp, register FontInfo* fi)
* parseFile to determine if there is more file to parse.
*/
-static parseTrackKernData( FILE* fp, register FontInfo* fi)
+static int parseTrackKernData( FILE* fp, register FontInfo* fi)
{
bool cont = true, save = (fi->tkd != NULL);
int pos = 0, error = ok, tcount = 0;
@@ -961,7 +970,7 @@ static parseTrackKernData( FILE* fp, register FontInfo* fi)
* parseFile to determine if there is more file to parse.
*/
-static parsePairKernData( FILE* fp, register FontInfo* fi)
+static int parsePairKernData( FILE* fp, register FontInfo* fi)
{
bool cont = true, save = (fi->pkd != NULL);
int pos = 0, error = ok, pcount = 0;
@@ -1091,7 +1100,7 @@ static parsePairKernData( FILE* fp, register FontInfo* fi)
* parseFile to determine if there is more file to parse.
*/
-static parseCompCharData( FILE* fp, register FontInfo* fi)
+static int parseCompCharData( FILE* fp, register FontInfo* fi)
{
bool cont = true, firstTime = true, save = (fi->ccd != NULL);
int pos = 0, j = 0, error = ok, ccount = 0, pcount = 0;