xref: /aoo41x/main/vcl/unx/headless/svptext.cxx (revision b5926b45)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist #
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
25cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx>
26cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
33cdf0e10cSrcweir #include <basebmp/debug.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <outfont.hxx>
37cdf0e10cSrcweir #include <glyphcache.hxx>
38cdf0e10cSrcweir #include <impfont.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "svpgdi.hxx"
41cdf0e10cSrcweir #include "svpbmp.hxx"
42cdf0e10cSrcweir #include "svppspgraphics.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace basegfx;
45cdf0e10cSrcweir using namespace basebmp;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // ===========================================================================
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class SvpGlyphPeer
50cdf0e10cSrcweir :   public GlyphCachePeer
51cdf0e10cSrcweir {
52cdf0e10cSrcweir public:
SvpGlyphPeer()53cdf0e10cSrcweir     SvpGlyphPeer() {}
54cdf0e10cSrcweir 
55248a599fSHerbert Dürr     BitmapDeviceSharedPtr GetGlyphBmp( ServerFont&, sal_GlyphId,
56cdf0e10cSrcweir                             sal_uInt32 nBmpFormat, B2IPoint& rTargetPos );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir protected:
59cdf0e10cSrcweir     virtual void    RemovingFont( ServerFont& );
60248a599fSHerbert Dürr     virtual void    RemovingGlyph( ServerFont&, GlyphData&, sal_GlyphId );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     class SvpGcpHelper
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir     public:
65cdf0e10cSrcweir         RawBitmap               maRawBitmap;
66cdf0e10cSrcweir         BitmapDeviceSharedPtr   maBitmapDev;
67cdf0e10cSrcweir     };
68cdf0e10cSrcweir };
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // ===========================================================================
71cdf0e10cSrcweir 
72cdf0e10cSrcweir class SvpGlyphCache : public GlyphCache
73cdf0e10cSrcweir {
74cdf0e10cSrcweir public:
GetPeer()75cdf0e10cSrcweir     SvpGlyphPeer&       GetPeer() { return reinterpret_cast<SvpGlyphPeer&>( mrPeer ); }
76cdf0e10cSrcweir static SvpGlyphCache&   GetInstance();
77cdf0e10cSrcweir private:
SvpGlyphCache(SvpGlyphPeer & rPeer)78cdf0e10cSrcweir     SvpGlyphCache( SvpGlyphPeer& rPeer ) : GlyphCache( rPeer) {}
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //--------------------------------------------------------------------------
82cdf0e10cSrcweir 
GetInstance()83cdf0e10cSrcweir SvpGlyphCache& SvpGlyphCache::GetInstance()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     static SvpGlyphPeer aSvpGlyphPeer;
86cdf0e10cSrcweir     static SvpGlyphCache aGC( aSvpGlyphPeer );
87cdf0e10cSrcweir     return aGC;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // ===========================================================================
91cdf0e10cSrcweir 
GetGlyphBmp(ServerFont & rServerFont,sal_GlyphId aGlyphId,sal_uInt32 nBmpFormat,B2IPoint & rTargetPos)92cdf0e10cSrcweir BitmapDeviceSharedPtr SvpGlyphPeer::GetGlyphBmp( ServerFont& rServerFont,
93248a599fSHerbert Dürr     sal_GlyphId aGlyphId, sal_uInt32 nBmpFormat, B2IPoint& rTargetPos )
94cdf0e10cSrcweir {
95248a599fSHerbert Dürr     GlyphData& rGlyphData = rServerFont.GetGlyphData( aGlyphId );
96cdf0e10cSrcweir     SvpGcpHelper* pGcpHelper = (SvpGcpHelper*)rGlyphData.ExtDataRef().mpData;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     // nothing to do if the GlyphPeer hasn't allocated resources for the glyph
99cdf0e10cSrcweir     if( rGlyphData.ExtDataRef().meInfo != sal::static_int_cast<int>(nBmpFormat) )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         if( rGlyphData.ExtDataRef().meInfo == Format::NONE )
102cdf0e10cSrcweir             pGcpHelper = new SvpGcpHelper;
103cdf0e10cSrcweir         RawBitmap& rRawBitmap = pGcpHelper->maRawBitmap;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         // get glyph bitmap in matching format
106cdf0e10cSrcweir         bool bFound = false;
107cdf0e10cSrcweir         switch( nBmpFormat )
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             case Format::ONE_BIT_LSB_GREY:
110248a599fSHerbert Dürr                 bFound = rServerFont.GetGlyphBitmap1( aGlyphId, pGcpHelper->maRawBitmap );
111cdf0e10cSrcweir                 break;
112cdf0e10cSrcweir             case Format::EIGHT_BIT_GREY:
113248a599fSHerbert Dürr                 bFound = rServerFont.GetGlyphBitmap8( aGlyphId, pGcpHelper->maRawBitmap );
114cdf0e10cSrcweir                 break;
115cdf0e10cSrcweir             default:
116cdf0e10cSrcweir                 DBG_ERROR( "SVP GCP::GetGlyphBmp(): illegal scanline format");
117cdf0e10cSrcweir                 // fall back to black&white mask
118cdf0e10cSrcweir                 nBmpFormat = Format::ONE_BIT_LSB_GREY;
119cdf0e10cSrcweir                 bFound = false;
120cdf0e10cSrcweir                 break;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         // return .notdef glyph if needed
124248a599fSHerbert Dürr         if( !bFound && (aGlyphId != 0) )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             delete pGcpHelper;
127cdf0e10cSrcweir             return GetGlyphBmp( rServerFont, 0, nBmpFormat, rTargetPos );
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // construct alpha mask from raw bitmap
131cdf0e10cSrcweir         const B2IVector aSize( rRawBitmap.mnScanlineSize, rRawBitmap.mnHeight );
132cdf0e10cSrcweir         if( aSize.getX() && aSize.getY() )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             static PaletteMemorySharedVector aDummyPAL;
135cdf0e10cSrcweir             RawMemorySharedArray aRawPtr( rRawBitmap.mpBits );
136cdf0e10cSrcweir             pGcpHelper->maBitmapDev = createBitmapDevice( aSize, true, nBmpFormat, aRawPtr, aDummyPAL );
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         rServerFont.SetExtended( nBmpFormat, (void*)pGcpHelper );
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     rTargetPos += B2IPoint( pGcpHelper->maRawBitmap.mnXOffset, pGcpHelper->maRawBitmap.mnYOffset );
143cdf0e10cSrcweir     return pGcpHelper->maBitmapDev;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //--------------------------------------------------------------------------
147cdf0e10cSrcweir 
RemovingFont(ServerFont &)148cdf0e10cSrcweir void SvpGlyphPeer::RemovingFont( ServerFont& )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     // nothing to do: no font resources held in SvpGlyphPeer
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //--------------------------------------------------------------------------
154cdf0e10cSrcweir 
RemovingGlyph(ServerFont &,GlyphData & rGlyphData,sal_GlyphId)155248a599fSHerbert Dürr void SvpGlyphPeer::RemovingGlyph( ServerFont&, GlyphData& rGlyphData, sal_GlyphId /*aGlyphId*/ )
156cdf0e10cSrcweir {
157*b5926b45SAriel Constenla-Haile     if( rGlyphData.ExtDataRef().mpData != NULL )
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         // release the glyph related resources
160cdf0e10cSrcweir         DBG_ASSERT( (rGlyphData.ExtDataRef().meInfo <= Format::MAX), "SVP::RG() invalid alpha format" );
161cdf0e10cSrcweir         SvpGcpHelper* pGcpHelper = (SvpGcpHelper*)rGlyphData.ExtDataRef().mpData;
162cdf0e10cSrcweir         delete[] pGcpHelper->maRawBitmap.mpBits;
163cdf0e10cSrcweir         delete pGcpHelper;
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // ===========================================================================
168cdf0e10cSrcweir 
169cdf0e10cSrcweir // PspKernInfo allows on-demand-querying of psprint provided kerning info (#i29881#)
170cdf0e10cSrcweir class PspKernInfo : public ExtraKernInfo
171cdf0e10cSrcweir {
172cdf0e10cSrcweir public:
PspKernInfo(int nFontId)173cdf0e10cSrcweir     PspKernInfo( int nFontId ) : ExtraKernInfo(nFontId) {}
174cdf0e10cSrcweir protected:
175cdf0e10cSrcweir     virtual void Initialize() const;
176cdf0e10cSrcweir };
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //--------------------------------------------------------------------------
179cdf0e10cSrcweir 
Initialize() const180cdf0e10cSrcweir void PspKernInfo::Initialize() const
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     mbInitialized = true;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     // get the kerning pairs from psprint
185cdf0e10cSrcweir     const psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
186cdf0e10cSrcweir     typedef std::list< psp::KernPair > PspKernPairs;
187cdf0e10cSrcweir     const PspKernPairs& rKernPairs = rMgr.getKernPairs( mnFontId );
188cdf0e10cSrcweir     if( rKernPairs.empty() )
189cdf0e10cSrcweir         return;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     // feed psprint's kerning list into a lookup-friendly container
19275c24b65SHerbert Dürr     maUnicodeKernPairs.rehash( rKernPairs.size() );
193cdf0e10cSrcweir     PspKernPairs::const_iterator it = rKernPairs.begin();
194cdf0e10cSrcweir     for(; it != rKernPairs.end(); ++it )
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         ImplKernPairData aKernPair = { it->first, it->second, it->kern_x };
197cdf0e10cSrcweir         maUnicodeKernPairs.insert( aKernPair );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // ===========================================================================
202cdf0e10cSrcweir 
SetFont(ImplFontSelectData * pIFSD,int nFallbackLevel)203cdf0e10cSrcweir sal_uInt16 SvpSalGraphics::SetFont( ImplFontSelectData* pIFSD, int nFallbackLevel )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     // release all no longer needed font resources
206cdf0e10cSrcweir     for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         if( m_pServerFont[i] != NULL )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             // old server side font is no longer referenced
211cdf0e10cSrcweir             SvpGlyphCache::GetInstance().UncacheFont( *m_pServerFont[i] );
212cdf0e10cSrcweir             m_pServerFont[i] = NULL;
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     // return early if there is no new font
217cdf0e10cSrcweir     if( !pIFSD )
218cdf0e10cSrcweir         return 0;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     // handle the request for a non-native X11-font => use the GlyphCache
221cdf0e10cSrcweir     ServerFont* pServerFont = SvpGlyphCache::GetInstance().CacheFont( *pIFSD );
222cdf0e10cSrcweir     if( !pServerFont )
223cdf0e10cSrcweir         return SAL_SETFONT_BADFONT;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     // check selected font
226cdf0e10cSrcweir     if( !pServerFont->TestFont() )
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         SvpGlyphCache::GetInstance().UncacheFont( *pServerFont );
229cdf0e10cSrcweir         return SAL_SETFONT_BADFONT;
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     // update SalGraphics font settings
233cdf0e10cSrcweir     m_pServerFont[ nFallbackLevel ] = pServerFont;
234cdf0e10cSrcweir     return SAL_SETFONT_USEDRAWTEXTARRAY;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir // ---------------------------------------------------------------------------
238cdf0e10cSrcweir 
GetFontMetric(ImplFontMetricData * pMetric,int nFallbackLevel)239cdf0e10cSrcweir void SvpSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLevel )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     if( nFallbackLevel >= MAX_FALLBACK )
242cdf0e10cSrcweir         return;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     if( m_pServerFont[nFallbackLevel] != NULL )
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         long rDummyFactor;
247cdf0e10cSrcweir         m_pServerFont[nFallbackLevel]->FetchFontMetric( *pMetric, rDummyFactor );
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // ---------------------------------------------------------------------------
252cdf0e10cSrcweir 
GetKernPairs(sal_uLong nPairs,ImplKernPairData * pKernPairs)253cdf0e10cSrcweir sal_uLong SvpSalGraphics::GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     sal_uLong nGotPairs = 0;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     if( m_pServerFont[0] != NULL )
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         ImplKernPairData* pTmpKernPairs = NULL;
260cdf0e10cSrcweir         nGotPairs = m_pServerFont[0]->GetKernPairs( &pTmpKernPairs );
261cdf0e10cSrcweir         for( sal_uLong i = 0; i < nPairs && i < nGotPairs; ++i )
262cdf0e10cSrcweir             pKernPairs[ i ] = pTmpKernPairs[ i ];
263cdf0e10cSrcweir         delete[] pTmpKernPairs;
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     return nGotPairs;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir // ---------------------------------------------------------------------------
270cdf0e10cSrcweir 
GetImplFontCharMap() const271cdf0e10cSrcweir const ImplFontCharMap* SvpSalGraphics::GetImplFontCharMap() const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     if( !m_pServerFont[0] )
274cdf0e10cSrcweir         return NULL;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     const ImplFontCharMap* pIFCMap = m_pServerFont[0]->GetImplFontCharMap();
277cdf0e10cSrcweir     return pIFCMap;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // ---------------------------------------------------------------------------
281cdf0e10cSrcweir 
GetDevFontList(ImplDevFontList * pDevFontList)282cdf0e10cSrcweir void SvpSalGraphics::GetDevFontList( ImplDevFontList* pDevFontList )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     GlyphCache& rGC = SvpGlyphCache::GetInstance();
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
287cdf0e10cSrcweir     psp::FastPrintFontInfo aInfo;
288cdf0e10cSrcweir     ::std::list< psp::fontID > aList;
289cdf0e10cSrcweir     rMgr.getFontList( aList );
290cdf0e10cSrcweir     ::std::list< psp::fontID >::iterator it;
291cdf0e10cSrcweir     for( it = aList.begin(); it != aList.end(); ++it )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         if( !rMgr.getFontFastInfo( *it, aInfo ) )
294cdf0e10cSrcweir             continue;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         // the GlyphCache must not bother with builtin fonts because
297cdf0e10cSrcweir         // it cannot access or use them anyway
298cdf0e10cSrcweir         if( aInfo.m_eType == psp::fonttype::Builtin )
299cdf0e10cSrcweir             continue;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         // normalize face number to the GlyphCache
302cdf0e10cSrcweir         int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
303cdf0e10cSrcweir         if( nFaceNum < 0 )
304cdf0e10cSrcweir             nFaceNum = 0;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir         // for fonts where extra kerning info can be provided on demand
307cdf0e10cSrcweir         // an ExtraKernInfo object is supplied
308cdf0e10cSrcweir         const ExtraKernInfo* pExtraKernInfo = NULL;
309cdf0e10cSrcweir         if( aInfo.m_eType == psp::fonttype::Type1 )
310cdf0e10cSrcweir             pExtraKernInfo = new PspKernInfo( *it );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir         // inform GlyphCache about this font provided by the PsPrint subsystem
313cdf0e10cSrcweir         ImplDevFontAttributes aDFA = PspGraphics::Info2DevFontAttributes( aInfo );
314cdf0e10cSrcweir         aDFA.mnQuality += 4096;
315cdf0e10cSrcweir         const rtl::OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
316cdf0e10cSrcweir         rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA, pExtraKernInfo );
317cdf0e10cSrcweir    }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     // announce glyphcache fonts
320cdf0e10cSrcweir     rGC.AnnounceFonts( pDevFontList );
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir // ---------------------------------------------------------------------------
324cdf0e10cSrcweir 
GetDevFontSubstList(OutputDevice *)325cdf0e10cSrcweir void SvpSalGraphics::GetDevFontSubstList( OutputDevice* )
326cdf0e10cSrcweir {}
327cdf0e10cSrcweir 
328cdf0e10cSrcweir // ---------------------------------------------------------------------------
329cdf0e10cSrcweir 
AddTempDevFont(ImplDevFontList *,const String &,const String &)330cdf0e10cSrcweir bool SvpSalGraphics::AddTempDevFont( ImplDevFontList*,
331cdf0e10cSrcweir     const String&, const String& )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     return false;
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir // ---------------------------------------------------------------------------
337cdf0e10cSrcweir 
CreateFontSubset(const rtl::OUString & rToFile,const ImplFontData * pFont,sal_GlyphId * pGlyphIds,sal_uInt8 * pEncoding,sal_Int32 * pWidths,int nGlyphCount,FontSubsetInfo & rInfo)338cdf0e10cSrcweir sal_Bool SvpSalGraphics::CreateFontSubset(
339cdf0e10cSrcweir     const rtl::OUString& rToFile,
340cdf0e10cSrcweir     const ImplFontData* pFont,
341248a599fSHerbert Dürr     sal_GlyphId* pGlyphIds,
342cdf0e10cSrcweir     sal_uInt8* pEncoding,
343cdf0e10cSrcweir     sal_Int32* pWidths,
344cdf0e10cSrcweir     int nGlyphCount,
345cdf0e10cSrcweir     FontSubsetInfo& rInfo
346cdf0e10cSrcweir     )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
349cdf0e10cSrcweir     // font since they are the only ones left after the PDF
350cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
351cdf0e10cSrcweir     // which this method was created). The correct way would
352cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
353cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
354cdf0e10cSrcweir 
355cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
356cdf0e10cSrcweir     bool bSuccess = rMgr.createFontSubset( rInfo,
357cdf0e10cSrcweir                                  aFont,
358cdf0e10cSrcweir                                  rToFile,
359248a599fSHerbert Dürr                                  pGlyphIds,
360cdf0e10cSrcweir                                  pEncoding,
361cdf0e10cSrcweir                                  pWidths,
362cdf0e10cSrcweir                                  nGlyphCount );
363cdf0e10cSrcweir     return bSuccess;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir // ---------------------------------------------------------------------------
367cdf0e10cSrcweir 
GetFontEncodingVector(const ImplFontData * pFont,const Ucs2OStrMap ** pNonEncoded)368cdf0e10cSrcweir const Ucs2SIntMap* SvpSalGraphics::GetFontEncodingVector( const ImplFontData* pFont, const Ucs2OStrMap** pNonEncoded )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
371cdf0e10cSrcweir     // font since they are the only ones left after the PDF
372cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
373cdf0e10cSrcweir     // which this method was created). The correct way would
374cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
375cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
376cdf0e10cSrcweir     return PspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // ---------------------------------------------------------------------------
380cdf0e10cSrcweir 
GetEmbedFontData(const ImplFontData * pFont,const sal_Ucs * pUnicodes,sal_Int32 * pWidths,FontSubsetInfo & rInfo,long * pDataLen)381cdf0e10cSrcweir const void* SvpSalGraphics::GetEmbedFontData(
382cdf0e10cSrcweir     const ImplFontData* pFont,
383cdf0e10cSrcweir     const sal_Ucs* pUnicodes,
384cdf0e10cSrcweir     sal_Int32* pWidths,
385cdf0e10cSrcweir     FontSubsetInfo& rInfo,
386cdf0e10cSrcweir     long* pDataLen
387cdf0e10cSrcweir     )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
390cdf0e10cSrcweir     // font since they are the only ones left after the PDF
391cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
392cdf0e10cSrcweir     // which this method was created). The correct way would
393cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
394cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
395cdf0e10cSrcweir     return PspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir // ---------------------------------------------------------------------------
399cdf0e10cSrcweir 
FreeEmbedFontData(const void * pData,long nLen)400cdf0e10cSrcweir void SvpSalGraphics::FreeEmbedFontData( const void* pData, long nLen )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir     PspGraphics::DoFreeEmbedFontData( pData, nLen );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
GetGlyphWidths(const ImplFontData * pFont,bool bVertical,Int32Vector & rWidths,Ucs2UIntMap & rUnicodeEnc)405cdf0e10cSrcweir void SvpSalGraphics::GetGlyphWidths( const ImplFontData* pFont,
406cdf0e10cSrcweir                                    bool bVertical,
407cdf0e10cSrcweir                                    Int32Vector& rWidths,
408cdf0e10cSrcweir                                    Ucs2UIntMap& rUnicodeEnc )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
411cdf0e10cSrcweir     // font since they are the only ones left after the PDF
412cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
413cdf0e10cSrcweir     // which this method was created). The correct way would
414cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
415cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
416cdf0e10cSrcweir     PspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir // ---------------------------------------------------------------------------
420cdf0e10cSrcweir 
GetGlyphBoundRect(sal_GlyphId aGlyphId,Rectangle & rRect)421248a599fSHerbert Dürr bool SvpSalGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
422cdf0e10cSrcweir {
423248a599fSHerbert Dürr     const int nLevel = aGlyphId >> GF_FONTSHIFT;
424cdf0e10cSrcweir     if( nLevel >= MAX_FALLBACK )
425248a599fSHerbert Dürr         return false;
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     ServerFont* pSF = m_pServerFont[ nLevel ];
428cdf0e10cSrcweir     if( !pSF )
429248a599fSHerbert Dürr         return false;
430cdf0e10cSrcweir 
431248a599fSHerbert Dürr     aGlyphId &= ~GF_FONTMASK;
432248a599fSHerbert Dürr     const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
433cdf0e10cSrcweir     rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
434248a599fSHerbert Dürr     return true;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir // ---------------------------------------------------------------------------
438cdf0e10cSrcweir 
GetGlyphOutline(sal_GlyphId aGlyphId,B2DPolyPolygon & rPolyPoly)439248a599fSHerbert Dürr bool SvpSalGraphics::GetGlyphOutline( sal_GlyphId aGlyphId, B2DPolyPolygon& rPolyPoly )
440cdf0e10cSrcweir {
441248a599fSHerbert Dürr     const int nLevel = aGlyphId >> GF_FONTSHIFT;
442cdf0e10cSrcweir     if( nLevel >= MAX_FALLBACK )
443248a599fSHerbert Dürr         return false;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     const ServerFont* pSF = m_pServerFont[ nLevel ];
446cdf0e10cSrcweir     if( !pSF )
447248a599fSHerbert Dürr         return false;
448cdf0e10cSrcweir 
449248a599fSHerbert Dürr     aGlyphId &= ~GF_FONTMASK;
450248a599fSHerbert Dürr     bool bOK = pSF->GetGlyphOutline( aGlyphId, rPolyPoly );
451248a599fSHerbert Dürr     return bOK;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir // ---------------------------------------------------------------------------
455cdf0e10cSrcweir 
GetTextLayout(ImplLayoutArgs &,int nFallbackLevel)456cdf0e10cSrcweir SalLayout* SvpSalGraphics::GetTextLayout( ImplLayoutArgs&, int nFallbackLevel )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     GenericSalLayout* pLayout = NULL;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     if( m_pServerFont[ nFallbackLevel ] )
461cdf0e10cSrcweir         pLayout = new ServerFontLayout( *m_pServerFont[ nFallbackLevel ] );
462cdf0e10cSrcweir 
463cdf0e10cSrcweir     return pLayout;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir // ---------------------------------------------------------------------------
467cdf0e10cSrcweir 
DrawServerFontLayout(const ServerFontLayout & rSalLayout)468cdf0e10cSrcweir void SvpSalGraphics::DrawServerFontLayout( const ServerFontLayout& rSalLayout )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     // iterate over all glyphs in the layout
471cdf0e10cSrcweir     Point aPos;
472248a599fSHerbert Dürr     sal_GlyphId aGlyphId;
473cdf0e10cSrcweir     SvpGlyphPeer& rGlyphPeer = SvpGlyphCache::GetInstance().GetPeer();
474248a599fSHerbert Dürr     for( int nStart = 0; rSalLayout.GetNextGlyphs( 1, &aGlyphId, aPos, nStart ); )
475cdf0e10cSrcweir     {
476248a599fSHerbert Dürr         int nLevel = aGlyphId >> GF_FONTSHIFT;
477cdf0e10cSrcweir         DBG_ASSERT( nLevel < MAX_FALLBACK, "SvpGDI: invalid glyph fallback level" );
478cdf0e10cSrcweir         ServerFont* pSF = m_pServerFont[ nLevel ];
479cdf0e10cSrcweir         if( !pSF )
480cdf0e10cSrcweir             continue;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir         // get the glyph's alpha mask and adjust the drawing position
483248a599fSHerbert Dürr         aGlyphId &= ~GF_FONTMASK;
484cdf0e10cSrcweir         B2IPoint aDstPoint( aPos.X(), aPos.Y() );
485cdf0e10cSrcweir         BitmapDeviceSharedPtr aAlphaMask
486248a599fSHerbert Dürr             = rGlyphPeer.GetGlyphBmp( *pSF, aGlyphId, m_eTextFmt, aDstPoint );
487cdf0e10cSrcweir         if( !aAlphaMask )   // ignore empty glyphs
488cdf0e10cSrcweir             continue;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir         // blend text color into target using the glyph's mask
491cdf0e10cSrcweir         const B2IRange aSrcRect( B2ITuple(0,0), aAlphaMask->getSize() );
492cdf0e10cSrcweir         m_aDevice->drawMaskedColor( m_aTextColor, aAlphaMask, aSrcRect, aDstPoint, m_aClipMap );
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // ===========================================================================
497