LCOV - code coverage report
Current view: top level - vcl/inc/generic - glyphcache.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 36 0.0 %
Date: 2014-04-14 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
      21             : #define INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
      22             : 
      23             : #include <vcl/dllapi.h>
      24             : 
      25             : class GlyphCache;
      26             : class GlyphMetric;
      27             : class GlyphData;
      28             : class ServerFont;
      29             : class GlyphCachePeer;
      30             : class ServerFontLayoutEngine;
      31             : class ServerFontLayout;
      32             : class ImplFontOptions;
      33             : class PhysicalFontCollection;
      34             : 
      35             : #include <tools/gen.hxx>
      36             : #include <basebmp/bitmapdevice.hxx>
      37             : #include <boost/unordered_map.hpp>
      38             : #include <boost/unordered_set.hpp>
      39             : #include <boost/shared_ptr.hpp>
      40             : #include <com/sun/star/i18n/XBreakIterator.hpp>
      41             : 
      42             : namespace basegfx { class B2DPolyPolygon; }
      43             : 
      44             : class RawBitmap;
      45             : 
      46             : #include <outfont.hxx>
      47             : #include <impfont.hxx>
      48             : 
      49             : class ServerFontLayout;
      50             : #include <sallayout.hxx>
      51             : 
      52             : #include <config_graphite.h>
      53             : #if ENABLE_GRAPHITE
      54             : class GraphiteFaceWrapper;
      55             : #endif
      56             : 
      57             : #include <ft2build.h>
      58             : #include FT_FREETYPE_H
      59             : #include FT_GLYPH_H
      60             : 
      61             : namespace vcl
      62             : {
      63             :     struct FontCapabilities;
      64             : }
      65             : 
      66             : class VCL_DLLPUBLIC GlyphCache
      67             : {
      68             : public:
      69             :     explicit                    GlyphCache( GlyphCachePeer& );
      70             :     /*virtual*/                 ~GlyphCache();
      71             : 
      72             :     static GlyphCache&      GetInstance();
      73             : 
      74             :     void                        AddFontFile( const OString& rNormalizedName,
      75             :                                              int nFaceNum, sal_IntPtr nFontId,
      76             :                                              const ImplDevFontAttributes&);
      77             :     void                        AnnounceFonts( PhysicalFontCollection* ) const;
      78             : 
      79             :     ServerFont*                 CacheFont( const FontSelectPattern& );
      80             :     void                        UncacheFont( ServerFont& );
      81             :     void                        ClearFontCache();
      82             :     void                        InvalidateAllGlyphs();
      83             : 
      84             : protected:
      85             :     GlyphCachePeer&             mrPeer;
      86             : 
      87             : private:
      88             :     friend class ServerFont;
      89             :     // used by ServerFont class only
      90             :     void                        AddedGlyph( ServerFont&, GlyphData& );
      91             :     void                        RemovingGlyph( GlyphData& );
      92             :     void                        UsingGlyph( ServerFont&, GlyphData& );
      93             :     void                        GrowNotify();
      94             : 
      95             : private:
      96             :     void                        GarbageCollect();
      97             : 
      98             :     // the GlyphCache's FontList matches a font request to a serverfont instance
      99             :     // the FontList key's mpFontData member is reinterpreted as integer font id
     100             :     struct IFSD_Equal{  bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; };
     101             :     struct IFSD_Hash{ size_t operator()( const FontSelectPattern& ) const; };
     102             :     typedef ::boost::unordered_map<FontSelectPattern,ServerFont*,IFSD_Hash,IFSD_Equal > FontList;
     103             :     FontList                    maFontList;
     104             :     sal_uLong                       mnMaxSize;      // max overall cache size in bytes
     105             :     mutable sal_uLong               mnBytesUsed;
     106             :     mutable long                mnLruIndex;
     107             :     mutable int                 mnGlyphCount;
     108             :     ServerFont*                 mpCurrentGCFont;
     109             : 
     110             :     class FreetypeManager*      mpFtManager;
     111             : };
     112             : 
     113             : class GlyphMetric
     114             : {
     115             : public:
     116           0 :     GlyphMetric() : mnAdvanceWidth(0) {}
     117             : 
     118           0 :     Point                   GetOffset() const   { return maOffset; }
     119             :     Point                   GetDelta() const    { return maDelta; }
     120           0 :     Size                    GetSize() const     { return maSize; }
     121           0 :     long                    GetCharWidth() const { return mnAdvanceWidth; }
     122             : 
     123             : protected:
     124             :     friend class GlyphData;
     125           0 :     void                    SetOffset( int nX, int nY ) { maOffset = Point( nX, nY); }
     126           0 :     void                    SetDelta( int nX, int nY )  { maDelta = Point( nX, nY); }
     127           0 :     void                    SetSize( const Size& s )    { maSize = s; }
     128           0 :     void                    SetCharWidth( long nW )     { mnAdvanceWidth = nW; }
     129             : 
     130             : private:
     131             :     long                    mnAdvanceWidth;
     132             :     Point                   maDelta;
     133             :     Point                   maOffset;
     134             :     Size                    maSize;
     135             : };
     136             : 
     137             : // the glyph specific data needed by a GlyphCachePeer is usually trivial,
     138             : // not attaching it to the corresponding GlyphData would be overkill;
     139             : // this is currently only used by the headless (aka svp) plugin, where meInfo is
     140             : // basebmp::Format and mpData is SvpGcpHelper*
     141             : struct ExtGlyphData
     142             : {
     143             :     int     meInfo;
     144             :     void*   mpData;
     145             : 
     146           0 :     ExtGlyphData() : meInfo(0), mpData(NULL) {}
     147             : };
     148             : 
     149             : class GlyphData
     150             : {
     151             : public:
     152           0 :     GlyphData() : mnLruValue(0) {}
     153             : 
     154           0 :     const GlyphMetric&      GetMetric() const           { return maMetric; }
     155             :     Size                    GetSize() const             { return maMetric.GetSize(); }
     156             : 
     157           0 :     void                    SetSize( const Size& s)     { maMetric.SetSize( s ); }
     158           0 :     void                    SetOffset( int nX, int nY ) { maMetric.SetOffset( nX, nY ); }
     159           0 :     void                    SetDelta( int nX, int nY )  { maMetric.SetDelta( nX, nY ); }
     160           0 :     void                    SetCharWidth( long nW )     { maMetric.SetCharWidth( nW ); }
     161             : 
     162           0 :     void                    SetLruValue( int n ) const  { mnLruValue = n; }
     163           0 :     long                    GetLruValue() const         { return mnLruValue;}
     164             : 
     165           0 :     ExtGlyphData&           ExtDataRef()                { return maExtData; }
     166             :     const ExtGlyphData&     ExtDataRef() const          { return maExtData; }
     167             : 
     168             : private:
     169             :     GlyphMetric             maMetric;
     170             :     ExtGlyphData            maExtData;
     171             : 
     172             :     // used by GlyphCache for cache LRU algorithm
     173             :     mutable long            mnLruValue;
     174             : };
     175             : 
     176             : class FtFontInfo;
     177             : 
     178             : class VCL_DLLPUBLIC ServerFont
     179             : {
     180             : public:
     181             :     ServerFont( const FontSelectPattern&, FtFontInfo* );
     182             :     virtual ~ServerFont();
     183             : 
     184             :     const OString* GetFontFileName() const;
     185             :     bool                TestFont() const;
     186             :     FT_Face             GetFtFace() const;
     187           0 :     int                 GetLoadFlags() const { return (mnLoadFlags & ~FT_LOAD_IGNORE_TRANSFORM); }
     188             :     void                SetFontOptions( boost::shared_ptr<ImplFontOptions> );
     189             :     boost::shared_ptr<ImplFontOptions> GetFontOptions() const;
     190           0 :     bool                NeedsArtificialBold() const { return mbArtBold; }
     191           0 :     bool                NeedsArtificialItalic() const { return mbArtItalic; }
     192             : 
     193           0 :     const FontSelectPattern&   GetFontSelData() const      { return maFontSelData; }
     194             : 
     195             :     void                FetchFontMetric( ImplFontMetricData&, long& rFactor ) const;
     196             :     const unsigned char* GetTable( const char* pName, sal_uLong* pLength );
     197             :     int                 GetEmUnits() const;
     198             :     const FT_Size_Metrics& GetMetricsFT() const { return maSizeFT->metrics; }
     199             :     const ImplFontCharMap* GetImplFontCharMap() const;
     200             :     bool                GetFontCapabilities(vcl::FontCapabilities &) const;
     201             : 
     202             :     GlyphData&                  GetGlyphData( sal_GlyphId );
     203           0 :     const GlyphMetric&          GetGlyphMetric( sal_GlyphId aGlyphId )
     204           0 :                                 { return GetGlyphData( aGlyphId ).GetMetric(); }
     205             : #if ENABLE_GRAPHITE
     206             :     virtual GraphiteFaceWrapper* GetGraphiteFace() const;
     207             : #endif
     208             : 
     209             :     sal_GlyphId         GetGlyphIndex( sal_UCS4 ) const;
     210             :     sal_GlyphId         GetRawGlyphIndex( sal_UCS4, sal_UCS4 = 0 ) const;
     211             :     sal_GlyphId         FixupGlyphIndex( sal_GlyphId aGlyphId, sal_UCS4 ) const;
     212             :     bool                GetGlyphOutline( sal_GlyphId aGlyphId, ::basegfx::B2DPolyPolygon& ) const;
     213             :     bool                GetAntialiasAdvice( void ) const;
     214             :     bool                GetGlyphBitmap1( sal_GlyphId aGlyphId, RawBitmap& ) const;
     215             :     bool                GetGlyphBitmap8( sal_GlyphId aGlyphId, RawBitmap& ) const;
     216             : 
     217             : private:
     218             :     friend class GlyphCache;
     219             :     friend class ServerFontLayout;
     220             :     friend class ImplServerFontEntry;
     221             :     friend class X11SalGraphics;
     222             : 
     223           0 :     void                        AddRef() const      { ++mnRefCount; }
     224           0 :     long                        GetRefCount() const { return mnRefCount; }
     225             :     long                        Release() const;
     226           0 :     sal_uLong                       GetByteCount() const { return mnBytesUsed; }
     227             : 
     228             :     void                InitGlyphData( sal_GlyphId, GlyphData& ) const;
     229             :     void                GarbageCollect( long );
     230             :     void                        ReleaseFromGarbageCollect();
     231             : 
     232             :     int                 ApplyGlyphTransform( int nGlyphFlags, FT_GlyphRec_*, bool ) const;
     233             :     bool                ApplyGSUB( const FontSelectPattern& );
     234             : 
     235             :     ServerFontLayoutEngine* GetLayoutEngine();
     236             : 
     237             :     typedef ::boost::unordered_map<int,GlyphData> GlyphList;
     238             :     mutable GlyphList           maGlyphList;
     239             : 
     240             :     const FontSelectPattern    maFontSelData;
     241             : 
     242             :     // used by GlyphCache for cache LRU algorithm
     243             :     mutable long                mnRefCount;
     244             :     mutable sal_uLong               mnBytesUsed;
     245             : 
     246             :     ServerFont*                 mpPrevGCFont;
     247             :     ServerFont*                 mpNextGCFont;
     248             : 
     249             :     // 16.16 fixed point values used for a rotated font
     250             :     long                        mnCos;
     251             :     long                        mnSin;
     252             : 
     253             :     bool                        mbCollectedZW;
     254             : 
     255             :     int                         mnWidth;
     256             :     int                         mnPrioEmbedded;
     257             :     int                         mnPrioAntiAlias;
     258             :     int                         mnPrioAutoHint;
     259             :     FtFontInfo*                 mpFontInfo;
     260             :     FT_Int                      mnLoadFlags;
     261             :     double                      mfStretch;
     262             :     FT_FaceRec_*                maFaceFT;
     263             :     FT_SizeRec_*                maSizeFT;
     264             : 
     265             :     boost::shared_ptr<ImplFontOptions> mpFontOptions;
     266             : 
     267             :     bool                        mbFaceOk;
     268             :     bool            mbArtItalic;
     269             :     bool            mbArtBold;
     270             :     bool            mbUseGamma;
     271             : 
     272             :     typedef ::boost::unordered_map<int,int> GlyphSubstitution;
     273             :     GlyphSubstitution           maGlyphSubstitution;
     274             : 
     275             :     ServerFontLayoutEngine*     mpLayoutEngine;
     276             : };
     277             : 
     278             : // a class for cache entries for physical font instances that are based on serverfonts
     279             : class VCL_DLLPUBLIC ImplServerFontEntry : public ImplFontEntry
     280             : {
     281             : private:
     282             :     ServerFont*    mpServerFont;
     283             :     boost::shared_ptr<ImplFontOptions> mpFontOptions;
     284             :     bool           mbGotFontOptions;
     285             : 
     286             : public:
     287             :                    ImplServerFontEntry( FontSelectPattern& );
     288             :     virtual        ~ImplServerFontEntry();
     289             :     void           SetServerFont(ServerFont* p);
     290             :     void           HandleFontOptions();
     291             : };
     292             : 
     293           0 : class VCL_DLLPUBLIC ServerFontLayout : public GenericSalLayout
     294             : {
     295             : private:
     296             :     ServerFont&     mrServerFont;
     297             :     com::sun::star::uno::Reference<com::sun::star::i18n::XBreakIterator> mxBreak;
     298             : 
     299             :     // enforce proper copy semantic
     300             :     SAL_DLLPRIVATE  ServerFontLayout( const ServerFontLayout& );
     301             :     SAL_DLLPRIVATE  ServerFontLayout& operator=( const ServerFontLayout& );
     302             : 
     303             : public:
     304             :                     ServerFontLayout( ServerFont& );
     305             :     virtual bool    LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE;
     306             :     virtual void    AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE;
     307             :     virtual void    DrawText( SalGraphics& ) const SAL_OVERRIDE;
     308             :     void            setNeedFallback(ImplLayoutArgs& rArgs, sal_Int32 nIndex,
     309             :                         bool bRightToLeft);
     310             : 
     311           0 :     ServerFont&     GetServerFont() const   { return mrServerFont; }
     312             : };
     313             : 
     314           0 : class ServerFontLayoutEngine
     315             : {
     316             : public:
     317           0 :     virtual         ~ServerFontLayoutEngine() {}
     318             :     virtual bool    layout(ServerFontLayout&, ImplLayoutArgs&) = 0;
     319             : };
     320             : 
     321             : class GlyphCachePeer
     322             : {
     323             : protected:
     324           0 :                     GlyphCachePeer() : mnBytesUsed(0) {}
     325           0 :     virtual         ~GlyphCachePeer() {}
     326             : 
     327             : public:
     328           0 :     sal_Int32       GetByteCount() const { return mnBytesUsed; }
     329           0 :     virtual void    RemovingFont( ServerFont& ) {}
     330           0 :     virtual void    RemovingGlyph( GlyphData& ) {}
     331             : 
     332             : protected:
     333             :     sal_Int32       mnBytesUsed;
     334             : };
     335             : 
     336             : class VCL_DLLPUBLIC RawBitmap
     337             : {
     338             : public:
     339             :                     RawBitmap();
     340             :                     ~RawBitmap();
     341             :     bool            Rotate( int nAngle );
     342             : 
     343             : public:
     344             :     basebmp::RawMemorySharedArray mpBits;
     345             :     sal_uLong           mnAllocated;
     346             : 
     347             :     sal_uLong           mnWidth;
     348             :     sal_uLong           mnHeight;
     349             : 
     350             :     sal_uLong           mnScanlineSize;
     351             :     sal_uLong           mnBitCount;
     352             : 
     353             :     int             mnXOffset;
     354             :     int             mnYOffset;
     355             : };
     356             : 
     357             : #endif // INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10