From 2d1f08d63942666c0094904f50ba8c512ab69b9d Mon Sep 17 00:00:00 2001 From: Release Engineers Date: Thu, 27 Aug 2009 12:02:29 +0000 Subject: CWS-TOOLING: integrate CWS otf01 2009-08-26 15:25:19 +0200 hdu r275426 : #i10000# make ubuntu-8.10 buildbot happy 2009-08-21 11:58:07 +0200 hdu r275230 : #i43029# another compile fix for 64bit platforms 2009-08-21 09:00:26 +0200 hdu r275216 : #i43029# sal_Int32 is defined differently on some platforms 2009-08-19 13:41:07 +0200 hdu r275149 : #i43029# fix use of sft-based subsetting in centralized code 2009-08-19 10:42:23 +0200 hdu r275140 : #i43029# --amend previous commit with omitted files 2009-08-19 10:14:54 +0200 hdu r275137 : #i43029# finishing touches for CWS otf01 start to centralize the previously open-coded font-subset/font-embed requests do the rest when the SCM allows source-file moves and commits with finer granularity 2009-08-17 15:11:24 +0200 hdu r275057 : CWS-TOOLING: rebase CWS otf01 to trunk@275001 (milestone: DEV300:m55) 2009-08-14 17:07:06 +0200 hdu r274998 : #i43029# CFF-subsetting now works on all platforms for PDF-export and PS-printing 2009-08-14 15:13:23 +0200 hdu r274984 : #i43029# OOo-build-baseline allows avoiding brute-forcing codepoint coverage calculation 2009-08-14 14:33:36 +0200 hdu r274981 : #i43029# CmapResult becomes a class 2009-08-13 15:57:55 +0200 hdu r274948 : #i43029# start implementing glue-code for CFF-subsetting on WIN 2009-08-10 17:10:46 +0200 hdu r274828 : #100000# WAE: signedness-warning 2009-08-10 14:08:05 +0200 hdu r274810 : #100000# 2009-08-10 13:34:55 +0200 hdu r274807 : #i43029# update ParseCmap() as we need to handle glyph-mapping ourselves on win for non-sft-supported fonts 2009-07-11 11:32:37 +0200 hdu r273909 : CWS-TOOLING: rebase CWS otf01 to trunk@273858 (milestone: DEV300:m52) 2009-07-03 17:14:55 +0200 hdu r273714 : #i43029# last step before centralizing UNX fontsubset code into platform independent layer 2009-07-03 17:00:14 +0200 hdu r273712 : #i10000# remove compile warning when debug=t 2009-07-03 16:28:29 +0200 hdu r273710 : #i43029# another step to centralize fontsubset code 2009-07-03 15:23:45 +0200 hdu r273705 : #i43029# PDF-export on UNX now starts to support OTF/CFF 2009-07-02 16:19:46 +0200 hdu r273663 : #i43029# warn when subsetting encounters glyph with deprecated SEAC-like endchar 2009-06-25 11:40:55 +0200 hdu r273372 : #i43029# ensure validity of cff-subsetted glyph name 2009-06-24 10:22:13 +0200 hdu r273318 : #i43029# check validity of exported sfnt subtable 2009-06-23 16:25:54 +0200 hdu r273292 : #i43029# use direct CFF->PFA font subsetting 2009-06-23 16:24:33 +0200 hdu r273289 : #i43029# allow font subset directly into a provided FILE handle 2009-06-23 16:22:44 +0200 hdu r273286 : #i43029# implement direct CFF->PFA font subsetting 2009-06-19 17:13:02 +0200 hdu r273171 : #i43029# CFF subsetting starts to work for psprinting 2009-06-18 15:48:42 +0200 hdu r273122 : #i43029# psprint requires explicit control of font subset name 2009-06-18 15:43:21 +0200 hdu r273121 : #i43029# psprint requires explicit control of font subset name 2009-06-16 18:15:43 +0200 hdu r273033 : #i43029# minor reshuffling to prepare CFF->PS font uploading 2009-06-16 16:25:21 +0200 hdu r273025 : #i43029# minimal-invasive change to sft.cxx to access a SFNT's CFF subtable 2009-06-12 15:51:42 +0200 hdu r272925 : #i43029# support OT/CFF subsetting for our PDF export on MacOSX 2009-06-12 15:43:26 +0200 hdu r272924 : #i43029# provide subset metrics as required by subset requesters 2009-05-27 13:58:59 +0200 hdu r272342 : #i43029# TripleInt is already reserved by OSX Carbon 2009-05-27 13:41:12 +0200 hdu r272339 : #i43029# fix warnings and make it compile on different platforms 2009-05-26 18:18:38 +0200 hdu r272315 : #i43029# start moving font subsetting into specialized class 2009-05-26 17:23:55 +0200 hdu r272312 : #i43029# improve name for CFF->PFB subsetted font 2009-05-25 17:12:27 +0200 hdu r272264 : #i43029# PDF-export: get type1-subsetting of the ground 2009-05-25 11:15:39 +0200 hdu r272227 : #i43029# fix BlueValues/FontBBox topdict entries 2009-05-25 10:59:16 +0200 hdu r272222 : #i43029# better PFB-DICT entries for FontBBox and BlueValues 2009-05-25 10:26:46 +0200 hdu r272219 : #i43029# emit other PRIVDICT hints for CFF->PFB subsetting 2009-05-25 10:10:25 +0200 hdu r272218 : #i43029# sign-extend shortint/longint typeopts/dictops 2009-05-25 09:38:33 +0200 hdu r272217 : #i43029# better glyph names for CFF-subsetted PFB 2009-05-20 18:57:11 +0200 hdu r272147 : #i43029# a CFF-subsetter gets the Blues 2009-05-20 14:05:35 +0200 hdu r272127 : #i43029# implement CreateFontSubsetFromCff() 2009-05-18 12:33:05 +0200 hdu r272012 : #i43029# add and use CffSubsetterContext::writeCurveTo() 2009-05-15 11:38:08 +0200 hdu r271931 : CffTable: allow charwidth parameter for type2 endchar operator 2009-05-14 18:55:25 +0200 hdu r271916 : #i43029# implement flex/flex1/hflex/hflex1 typeop conversion, fix type1val writing 2009-05-11 09:53:26 +0200 hdu r271750 : #i101695# improve import of ghostscript-PDF font names 2009-05-07 11:35:12 +0200 hdu r271644 : #i43029# adusted whitespace conventions from previously private code 2009-05-06 12:33:11 +0200 hdu r271579 : #i43029# change copyright header, fix warnings on some compilers 2009-05-06 10:50:50 +0200 hdu r271576 : improve whitespace and constness in some POS code 2009-05-05 16:10:56 +0200 hdu r271532 : #i43029# makefile support for new cff subsetter code 2009-05-05 14:56:29 +0200 hdu r271519 : #i43029# start integrating my CFF->Type1 subsetter code 2009-05-04 17:07:14 +0200 hdu r271474 : #i100140# remove obsoleted tables used for encoding conversion 2009-05-04 17:05:20 +0200 hdu r271473 : #i100140# use generic encoding converters in xlat.cxx 2009-04-15 11:58:25 +0200 hdu r270829 : #i101102# remove build dependency to removed module psprint 2009-04-14 15:57:13 +0200 hdu r270788 : CWS-TOOLING: rebase CWS otf01 to trunk@270723 (milestone: DEV300:m46) 2009-03-11 14:49:56 +0100 hdu r269335 : CWS-TOOLING: rebase CWS otf01 to trunk@269297 (milestone: DEV300:m43) 2009-02-06 12:32:22 +0100 hdu r267451 : resync CWS across CVS->SVN change 2009-02-06 12:32:04 +0100 hdu r267450 : resync CWS across CVS->SVN change --- vcl/source/gdi/pdfwriter_impl.cxx | 112 +++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 13 deletions(-) (limited to 'vcl/source/gdi/pdfwriter_impl.cxx') diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 25f02a1b2718..2cbebf6f23e2 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -2812,6 +2813,38 @@ sal_Int32 PDFWriterImpl::emitBuiltinFont( const ImplFontData* pFont, sal_Int32 n return nFontObject; } +typedef int ThreeInts[3]; +static bool getPfbSegmentLengths( const unsigned char* pFontBytes, int nByteLen, + ThreeInts& rSegmentLengths ) +{ + if( !pFontBytes || (nByteLen < 0) ) + return false; + const unsigned char* pPtr = pFontBytes; + const unsigned char* pEnd = pFontBytes + nByteLen; + + for( int i = 0; i < 3; ++i) { + // read segment1 header + if( pPtr+6 >= pEnd ) + return false; + if( (pPtr[0] != 0x80) || (pPtr[1] >= 0x03) ) + return false; + const int nLen = (pPtr[5]<<24) + (pPtr[4]<<16) + (pPtr[3]<<8) + pPtr[2]; + if( nLen <= 0) + return false; + rSegmentLengths[i] = nLen; + pPtr += nLen + 6; + } + + // read segment-end header + if( pPtr+2 >= pEnd ) + return false; + if( (pPtr[0] != 0x80) || (pPtr[1] != 0x03) ) + return false; + + return true; +} + +// TODO: always subset instead of embedding the full font => this method becomes obsolete then std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitEmbeddedFont( const ImplFontData* pFont, EmbedFont& rEmbed ) { std::map< sal_Int32, sal_Int32 > aRet; @@ -2852,7 +2885,7 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitEmbeddedFont( const ImplFont sal_Int32 nLength1, nLength2; if( (pFontData = (const unsigned char*)m_pReferenceDevice->mpGraphics->GetEmbedFontData( pFont, nEncodedCodes, pWidths, aInfo, &nFontLen )) != NULL ) { - if( aInfo.m_nFontType != SAL_FONTSUBSETINFO_TYPE_TYPE1 ) + if( (aInfo.m_nFontType & FontSubsetInfo::ANY_TYPE1) == 0 ) goto streamend; // see whether it is pfb or pfa; if it is a pfb, fill ranges // of 6 bytes that are not part of the font program @@ -2873,6 +2906,7 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitEmbeddedFont( const ImplFont } // search for eexec + // TODO: use getPfbSegmentLengths() if possible to skip the search thingies below nIndex = 0; int nEndAsciiIndex; int nBeginBinaryIndex; @@ -3573,10 +3607,11 @@ sal_Int32 PDFWriterImpl::emitFontDescriptor( const ImplFontData* pFont, FontSubs "/FontFile" ); switch( rInfo.m_nFontType ) { - case SAL_FONTSUBSETINFO_TYPE_TRUETYPE: + case FontSubsetInfo::SFNT_TTF: aLine.append( '2' ); break; - case SAL_FONTSUBSETINFO_TYPE_TYPE1: + case FontSubsetInfo::TYPE1_PFA: + case FontSubsetInfo::TYPE1_PFB: break; default: DBG_ERROR( "unknown fonttype in PDF font descriptor" ); @@ -3609,7 +3644,6 @@ bool PDFWriterImpl::emitFonts() return false; OStringBuffer aLine( 1024 ); - char buf[8192]; std::map< sal_Int32, sal_Int32 > aFontIDToObject; @@ -3652,14 +3686,13 @@ bool PDFWriterImpl::emitFonts() FontSubsetInfo aSubsetInfo; if( m_pReferenceDevice->mpGraphics->CreateFontSubset( aTmpName, it->first, pGlyphIDs, pEncoding, pWidths, nGlyphs, aSubsetInfo ) ) { - DBG_ASSERT( aSubsetInfo.m_nFontType == SAL_FONTSUBSETINFO_TYPE_TRUETYPE, "wrong font type in font subset" ); // create font stream oslFileHandle aFontFile; CHECK_RETURN( (osl_File_E_None == osl_openFile( aTmpName.pData, &aFontFile, osl_File_OpenFlag_Read ) ) ); // get file size - sal_uInt64 nLength; + sal_uInt64 nLength1; CHECK_RETURN( (osl_File_E_None == osl_setFilePos( aFontFile, osl_Pos_End, 0 ) ) ); - CHECK_RETURN( (osl_File_E_None == osl_getFilePos( aFontFile, &nLength ) ) ); + CHECK_RETURN( (osl_File_E_None == osl_getFilePos( aFontFile, &nLength1 ) ) ); CHECK_RETURN( (osl_File_E_None == osl_setFilePos( aFontFile, osl_Pos_Absolut, 0 ) ) ); #if OSL_DEBUG_LEVEL > 1 @@ -3681,25 +3714,74 @@ bool PDFWriterImpl::emitFonts() "/Filter/FlateDecode" #endif "/Length1 " ); - aLine.append( (sal_Int32)nLength ); + + sal_uInt64 nStartPos = 0; + if( aSubsetInfo.m_nFontType == FontSubsetInfo::SFNT_TTF ) + { + aLine.append( (sal_Int32)nLength1 ); + aLine.append( ">>\n" "stream\n" ); CHECK_RETURN( writeBuffer( aLine.getStr(), aLine.getLength() ) ); - - sal_uInt64 nStartPos = 0; CHECK_RETURN( (osl_File_E_None == osl_getFilePos( m_aFile, &nStartPos ) ) ); // copy font file beginCompression(); checkAndEnableStreamEncryption( nFontStream ); - sal_uInt64 nRead; sal_Bool bEOF = sal_False; do { + char buf[8192]; + sal_uInt64 nRead; CHECK_RETURN( (osl_File_E_None == osl_readFile( aFontFile, buf, sizeof( buf ), &nRead ) ) ); CHECK_RETURN( writeBuffer( buf, nRead ) ); CHECK_RETURN( (osl_File_E_None == osl_isEndOfFile( aFontFile, &bEOF ) ) ); } while( ! bEOF ); + } + else if( (aSubsetInfo.m_nFontType & FontSubsetInfo::CFF_FONT) != 0 ) + { + // TODO: implement + DBG_ERROR( "PDFWriterImpl does not support CFF-font subsets yet!" ); + } + else if( (aSubsetInfo.m_nFontType & FontSubsetInfo::TYPE1_PFB) != 0 ) // TODO: also support PFA? + { + unsigned char* pBuffer = new unsigned char[ (int)nLength1 ]; + + sal_uInt64 nBytesRead = 0; + CHECK_RETURN( (osl_File_E_None == osl_readFile( aFontFile, pBuffer, nLength1, &nBytesRead ) ) ); + DBG_ASSERT( nBytesRead==nLength1, "PDF-FontSubset read incomplete!" ); + CHECK_RETURN( (osl_File_E_None == osl_setFilePos( aFontFile, osl_Pos_Absolut, 0 ) ) ); + // get the PFB-segment lengths + ThreeInts aSegmentLengths = {0,0,0}; + getPfbSegmentLengths( pBuffer, (int)nBytesRead, aSegmentLengths ); + // the lengths below are mandatory for PDF-exported Type1 fonts + // because the PFB segment headers get stripped! WhyOhWhy. + aLine.append( (sal_Int32)aSegmentLengths[0] ); + aLine.append( "/Length2 " ); + aLine.append( (sal_Int32)aSegmentLengths[1] ); + aLine.append( "/Length3 " ); + aLine.append( (sal_Int32)aSegmentLengths[2] ); + + aLine.append( ">>\n" + "stream\n" ); + CHECK_RETURN( writeBuffer( aLine.getStr(), aLine.getLength() ) ); + CHECK_RETURN( (osl_File_E_None == osl_getFilePos( m_aFile, &nStartPos ) ) ); + + // emit PFB-sections without section headers + beginCompression(); + checkAndEnableStreamEncryption( nFontStream ); + CHECK_RETURN( writeBuffer( pBuffer+ 6, aSegmentLengths[0] ) ); + CHECK_RETURN( writeBuffer( pBuffer+12 + aSegmentLengths[0], aSegmentLengths[1] ) ); + CHECK_RETURN( writeBuffer( pBuffer+18 + aSegmentLengths[0] + aSegmentLengths[1], aSegmentLengths[2] ) ); + + delete[] pBuffer; + } + else + { + fprintf( stderr, "PDF: CreateFontSubset result in not yet supported format=%d\n",aSubsetInfo.m_nFontType); + aLine.append( "0 >>\nstream\n" ); + } + endCompression(); disableStreamEncryption(); // close the file @@ -3731,8 +3813,11 @@ bool PDFWriterImpl::emitFonts() CHECK_RETURN( updateObject( nFontObject ) ); aLine.setLength( 0 ); aLine.append( nFontObject ); - aLine.append( " 0 obj\n" - "<m_nFontID, aSubsetInfo.m_aPSName, aLine ); aLine.append( "\n" "/FirstChar 0\n" @@ -11811,3 +11896,4 @@ according to the table 3.15, pdf v 1.4 */ m_aContext.Encrypt = false; //then turn the encryption off } /* end i12626 methods */ + -- cgit From 20e02da5b2d5328b0e31443e19d769ff2aa521f4 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Tue, 8 Sep 2009 10:44:42 +0000 Subject: CWS-TOOLING: integrate CWS vcl104 --- vcl/source/gdi/pdfwriter_impl.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'vcl/source/gdi/pdfwriter_impl.cxx') diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 2cbebf6f23e2..e7ee18ec7705 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -805,7 +805,7 @@ class Matrix3 { double f[6]; - void set( double *pn ) { for( int i = 0 ; i < 5; i++ ) f[i] = pn[i]; } + void set( double *pn ) { for( int i = 0 ; i < 6; i++ ) f[i] = pn[i]; } public: Matrix3(); ~Matrix3() {} @@ -6787,14 +6787,15 @@ void PDFWriterImpl::drawHorizontalGlyphs( for( sal_uInt32 nPos = nBeginRun+1; nPos < aRunEnds[nRun]; nPos++ ) { appendHex( rGlyphs[nPos].m_nMappedGlyphId, aUnkernedLine ); - // check if glyph advance matches with the width of the previous glyph, else adjust + // check if default glyph positioning is sufficient const Point aThisPos = aMat.transform( rGlyphs[nPos].m_aPos ); const Point aPrevPos = aMat.transform( rGlyphs[nPos-1].m_aPos ); double fAdvance = aThisPos.X() - aPrevPos.X(); - fAdvance *= 1000.0 / (fXScale * nPixelFontHeight); - const sal_Int32 nAdjustment = rGlyphs[nPos-1].m_nNativeWidth - sal_Int32(fAdvance+0.5); + fAdvance *= 1000.0 / nPixelFontHeight; + const sal_Int32 nAdjustment = (sal_Int32)(rGlyphs[nPos-1].m_nNativeWidth - fAdvance + 0.5); if( nAdjustment != 0 ) { + // apply individual glyph positioning bNeedKern = true; aKernedLine.append( ">" ); aKernedLine.append( nAdjustment ); @@ -8643,6 +8644,8 @@ void PDFWriterImpl::drawPolyLine( const Polygon& rPoly, const PDFWriter::ExtLine for(sal_uInt32 a(0); a < nEdgeCount; a++) { + if( a > 0 ) + aLine.append( " " ); const sal_uInt32 nNextIndex((a + 1) % nPointCount); const basegfx::B2DPoint aNext(aPoly.getB2DPoint(nNextIndex)); -- cgit