LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/inc - outfont.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 45 88.9 %
Date: 2013-07-09 Functions: 45 51 88.2 %
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 _SV_OUTFONT_HXX
      21             : #define _SV_OUTFONT_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <tools/string.hxx>
      25             : #include <i18nlangtag/lang.h>
      26             : #include <tools/solar.h>
      27             : #include <vcl/dllapi.h>
      28             : #include <unotools/fontdefs.hxx>
      29             : #include <vcl/vclenum.hxx>
      30             : 
      31             : #include <boost/unordered_map.hpp>
      32             : 
      33             : class ImplDevFontListData;
      34             : class ImplGetDevFontList;
      35             : class ImplGetDevSizeList;
      36             : class ImplFontEntry;
      37             : class ImplDirectFontSubstitution;
      38             : class ImplPreMatchFontSubstitution;
      39             : class ImplGlyphFallbackFontSubstitution;
      40             : class FontSelectPattern;
      41             : class Font;
      42             : class ConvertChar;
      43             : struct FontMatchStatus;
      44             : class OutputDevice;
      45             : class Size;
      46             : 
      47             : namespace com { namespace sun { namespace star { namespace lang { struct Locale; }}}}
      48             : 
      49             : // ----------------------
      50             : // - ImplFontAttributes -
      51             : // ----------------------
      52             : // device independent font properties
      53             : 
      54     3022398 : class ImplFontAttributes
      55             : {
      56             : public: // TODO: create matching interface class
      57     2637978 :     const OUString& GetFamilyName() const   { return maName; }
      58     2553719 :     const OUString& GetStyleName() const    { return maStyleName; }
      59     7682178 :     FontWeight      GetWeight() const       { return meWeight; }
      60     5745095 :     FontItalic      GetSlant() const        { return meItalic; }
      61     1128829 :     FontFamily      GetFamilyType() const   { return meFamily; }
      62     2700622 :     FontPitch       GetPitch() const        { return mePitch; }
      63     2441761 :     FontWidth       GetWidthType() const    { return meWidthType; }
      64    14400395 :     bool            IsSymbolFont() const    { return mbSymbolFlag; }
      65     1073535 :     void            SetFamilyName(const OUString sFamilyName)    { maName = sFamilyName; }
      66      847360 :     void            SetStyleName( const OUString sStyleName)     { maStyleName = sStyleName; }
      67      846648 :     void            SetFamilyType(const FontFamily eFontFamily)  { meFamily = eFontFamily; }
      68      855126 :     void            SetPitch(const FontPitch ePitch )          { mePitch = ePitch; }
      69      854939 :     void            SetItalic(const FontItalic eItalic )       { meItalic = eItalic; }
      70      854939 :     void            SetWeight(const FontWeight eWeight )       { meWeight = eWeight; }
      71      854939 :     void            SetWidthType(const FontWidth eWidthType)   { meWidthType = eWidthType; }
      72      843327 :     void            SetSymbolFlag(const bool bSymbolFlag )     { mbSymbolFlag = bSymbolFlag; }
      73             :     bool operator==(const ImplFontAttributes& rOther) const;
      74      596348 :     bool operator!=(const ImplFontAttributes& rOther) const
      75             :     {
      76      596348 :         return !(*this == rOther);
      77             :     }
      78             : 
      79             : private:
      80             :     OUString        maName;         // Font Family Name
      81             :     OUString        maStyleName;    // Font Style Name
      82             :     FontWeight      meWeight;       // Weight Type
      83             :     FontItalic      meItalic;       // Slant Type
      84             :     FontFamily      meFamily;       // Family Type
      85             :     FontPitch       mePitch;        // Pitch Type
      86             :     FontWidth       meWidthType;    // Width Type
      87             :     bool            mbSymbolFlag;
      88             : };
      89             : 
      90             : // -------------------------
      91             : // - ImplDevFontAttributes -
      92             : // -------------------------
      93             : // device dependent font properties
      94             : 
      95      542523 : class ImplDevFontAttributes : public ImplFontAttributes
      96             : {
      97             : public: // TODO: create matching interface class
      98             :     const String&      GetAliasNames() const     { return maMapNames; }
      99             :     int                GetQuality() const        { return mnQuality; }
     100             :     bool               IsRotatable() const       { return mbOrientation; }
     101             :     bool               IsDeviceFont() const      { return mbDevice; }
     102           0 :     bool               IsEmbeddable() const      { return mbEmbeddable; }
     103           0 :     bool               IsSubsettable() const     { return mbSubsettable; }
     104             : 
     105             : public: // TODO: hide members behind accessor methods
     106             :     String             maMapNames;       // List of family name aliass separated with ';'
     107             :     int                mnQuality;        // Quality (used when similar fonts compete)
     108             :     bool               mbOrientation;    // true: physical font can be rotated
     109             :     bool               mbDevice;         // true: built in font
     110             :     bool               mbSubsettable;    // true: a subset of the font can be created
     111             :     bool               mbEmbeddable;     // true: the font can be embedded
     112             : };
     113             : 
     114             : // ----------------
     115             : // - PhysicalFontFace -
     116             : // ----------------
     117             : // TODO: no more direct access to members
     118             : // TODO: add reference counting
     119             : // TODO: get rid of height/width for scalable fonts
     120             : // TODO: make cloning cheaper
     121             : 
     122             : // abstract base class for physical font faces
     123      173091 : class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplDevFontAttributes
     124             : {
     125             : public:
     126             :     // by using an PhysicalFontFace object as a factory for its corresponding
     127             :     // ImplFontEntry an ImplFontEntry can be extended to cache device and
     128             :     // font instance specific data
     129             :     virtual ImplFontEntry*  CreateFontInstance( FontSelectPattern& ) const = 0;
     130             : 
     131        3088 :     virtual int             GetHeight() const           { return mnHeight; }
     132           0 :     virtual int             GetWidth() const            { return mnWidth; }
     133             :     virtual sal_IntPtr      GetFontId() const = 0;
     134           0 :     int                     GetFontMagic() const        { return mnMagic; }
     135      772324 :     bool                    IsScalable() const          { return (mnHeight == 0); }
     136           0 :     bool                    CheckMagic( int n ) const   { return (n == mnMagic); }
     137      652261 :     PhysicalFontFace*       GetNextFace() const         { return mpNext; }
     138             :     PhysicalFontFace*       CreateAlias() const         { return Clone(); }
     139             : 
     140             :     bool                    IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
     141             :     sal_Int32           CompareWithSize( const PhysicalFontFace& ) const;
     142             :     sal_Int32           CompareIgnoreSize( const PhysicalFontFace& ) const;
     143      205047 :     virtual                 ~PhysicalFontFace() {}
     144             :     virtual PhysicalFontFace* Clone() const = 0;
     145             : 
     146             : protected:
     147             :     explicit                PhysicalFontFace( const ImplDevFontAttributes&, int nMagic );
     148             :     void                    SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
     149             : 
     150             :     long                    mnWidth;    // Width (in pixels)
     151             :     long                    mnHeight;   // Height (in pixels)
     152             : 
     153             : private:
     154             : friend class ImplDevFontListData;
     155             :     const int               mnMagic;    // poor man's RTTI
     156             :     PhysicalFontFace*       mpNext;
     157             : };
     158             : 
     159     1664632 : class FontSelectPatternAttributes : public ImplFontAttributes
     160             : {
     161             : public:
     162             :                         FontSelectPatternAttributes( const Font&, const String& rSearchName,
     163             :                             const Size&, float fExactHeight );
     164             :                         FontSelectPatternAttributes( const PhysicalFontFace&, const Size&,
     165             :                             float fExactHeight, int nOrientation, bool bVertical );
     166             : 
     167             :     size_t              hashCode() const;
     168             :     bool operator==(const FontSelectPatternAttributes& rOther) const;
     169             :     bool operator!=(const FontSelectPatternAttributes& rOther) const
     170             :     {
     171             :         return !(*this == rOther);
     172             :     }
     173             : 
     174             : public:
     175             :     OUString            maTargetName;       // name of the font name token that is chosen
     176             :     OUString            maSearchName;       // name of the font that matches best
     177             :     int                 mnWidth;            // width of font in pixel units
     178             :     int                 mnHeight;           // height of font in pixel units
     179             :     float               mfExactHeight;      // requested height (in pixels with subpixel details)
     180             :     int                 mnOrientation;      // text orientation in 3600 system
     181             :     LanguageType        meLanguage;         // text language
     182             :     bool                mbVertical;         // vertical mode of requested font
     183             :     bool                mbNonAntialiased;   // true if antialiasing is disabled
     184             : 
     185             :     bool                mbEmbolden;         // Force emboldening
     186             :     ItalicMatrix        maItalicMatrix;     // Force matrix for slant
     187             : };
     188             : 
     189     1249096 : class FontSelectPattern : public FontSelectPatternAttributes
     190             : {
     191             : public:
     192             :                         FontSelectPattern( const Font&, const String& rSearchName,
     193             :                             const Size&, float fExactHeight );
     194             : #ifdef WNT
     195             : // ifdeffed to prevent it going into unusedcode.easy
     196             :                         FontSelectPattern( const PhysicalFontFace&, const Size&,
     197             :                             float fExactHeight, int nOrientation, bool bVertical );
     198             : #endif
     199             : 
     200             : public: // TODO: change to private
     201             :     const PhysicalFontFace* mpFontData;         // a matching PhysicalFontFace object
     202             :     ImplFontEntry*      mpFontEntry;        // pointer to the resulting FontCache entry
     203             :     void copyAttributes(const FontSelectPatternAttributes &rAttributes);
     204             : };
     205             : 
     206             : // -------------------
     207             : // - ImplDevFontList -
     208             : // -------------------
     209             : // TODO: merge with ImplFontCache
     210             : // TODO: rename to LogicalFontManager
     211             : 
     212             : class VCL_PLUGIN_PUBLIC ImplDevFontList
     213             : {
     214             : private:
     215             :     friend class WinGlyphFallbackSubstititution;
     216             :     mutable bool            mbMatchData;    // true if matching attributes are initialized
     217             :     bool                    mbMapNames;     // true if MapNames are available
     218             : 
     219             :     typedef boost::unordered_map<const String, ImplDevFontListData*,FontNameHash> DevFontList;
     220             :     DevFontList             maDevFontList;
     221             : 
     222             :     ImplPreMatchFontSubstitution* mpPreMatchHook;       // device specific prematch substitution
     223             :     ImplGlyphFallbackFontSubstitution* mpFallbackHook;  // device specific glyh fallback substitution
     224             : 
     225             : public:
     226             :     explicit                ImplDevFontList();
     227             :     virtual                 ~ImplDevFontList();
     228             : 
     229             :     // fill the list with device fonts
     230             :     void                    Add( PhysicalFontFace* );
     231             :     void                    Clear();
     232     2202910 :     int                     Count() const { return maDevFontList.size(); }
     233             : 
     234             :     // find the device font
     235             :     ImplDevFontListData*    FindFontFamily( const String& rFontName ) const;
     236             :     ImplDevFontListData*    ImplFindByFont( FontSelectPattern&, bool bPrinter, ImplDirectFontSubstitution* ) const;
     237             :     ImplDevFontListData*    ImplFindBySearchName( const OUString& ) const;
     238             : 
     239             :     // suggest fonts for glyph fallback
     240             :     ImplDevFontListData*    GetGlyphFallbackFont( FontSelectPattern&,
     241             :                         OUString& rMissingCodes, int nFallbackLevel ) const;
     242             : 
     243             :     // prepare platform specific font substitutions
     244             :     void                    SetPreMatchHook( ImplPreMatchFontSubstitution* );
     245             :     void                    SetFallbackHook( ImplGlyphFallbackFontSubstitution* );
     246             : 
     247             :     // misc utilities
     248             :     ImplDevFontList*        Clone( bool bScalable, bool bEmbeddable ) const;
     249             :     ImplGetDevFontList*     GetDevFontList() const;
     250             :     ImplGetDevSizeList*     GetDevSizeList( const String& rFontName ) const;
     251             : 
     252             :     ImplDevFontListData*    ImplFindByTokenNames(const OUString& rTokenStr) const;
     253             : 
     254             : protected:
     255             :     void                    InitMatchData() const;
     256             :     bool                    AreMapNamesAvailable() const { return mbMapNames; }
     257             : 
     258             :     ImplDevFontListData*    ImplFindByAliasName(const OUString& rSearchName,
     259             :         const OUString& rShortName) const;
     260             :     ImplDevFontListData*    ImplFindBySubstFontAttr( const utl::FontNameAttr& ) const;
     261             :     ImplDevFontListData*    ImplFindByAttributes(sal_uLong nSearchType, FontWeight, FontWidth,
     262             :                                                  FontItalic, const OUString& rSearchFamily) const;
     263             :     ImplDevFontListData*    FindDefaultFont() const;
     264             : 
     265             : private:
     266             :     void                    InitGenericGlyphFallback() const;
     267             :     mutable ImplDevFontListData**   mpFallbackList;
     268             :     mutable int                     mnFallbackCount;
     269             : };
     270             : 
     271             : // --------------------
     272             : // - ImplKernPairData -
     273             : // --------------------
     274             : 
     275             : struct ImplKernPairData
     276             : {
     277             :     sal_uInt16          mnChar1;
     278             :     sal_uInt16          mnChar2;
     279             :     long                mnKern;
     280             : };
     281             : 
     282             : 
     283             : // -----------------------
     284             : // - ImplFontMetricData -
     285             : // -----------------------
     286             : 
     287        3902 : class ImplFontMetricData : public ImplFontAttributes
     288             : {
     289             : public:
     290             :     explicit ImplFontMetricData( const FontSelectPattern& );
     291             :     void    ImplInitTextLineSize( const OutputDevice* pDev );
     292             :     void    ImplInitAboveTextLineSize();
     293             : 
     294             : public: // TODO: hide members behind accessor methods
     295             :     // font instance attributes from the font request
     296             :     long                mnWidth;                    // Reference Width
     297             :     short               mnOrientation;              // Rotation in 1/10 degrees
     298             : 
     299             :     // font metrics measured for the font instance
     300             :     long                mnAscent;                   // Ascent
     301             :     long                mnDescent;                  // Descent
     302             :     long                mnIntLeading;               // Internal Leading
     303             :     long                mnExtLeading;               // External Leading
     304             :     int                 mnSlant;                    // Slant (Italic/Oblique)
     305             :     long                mnMinKashida;               // Minimal width of kashida (Arabic)
     306             : 
     307             :     // font attributes queried from the font instance
     308             :     int                 meFamilyType;               // Font Family Type
     309             :     bool                mbDevice;                   // Flag for Device Fonts
     310             :     bool                mbScalableFont;
     311             :     bool                mbKernableFont;
     312             : 
     313             :     // font metrics that are usually derived from the measurements
     314             :     long                mnUnderlineSize;            // Lineheight of Underline
     315             :     long                mnUnderlineOffset;          // Offset from Underline to Baseline
     316             :     long                mnBUnderlineSize;           // Height of bold underline
     317             :     long                mnBUnderlineOffset;         // Offset from bold underline to baseline
     318             :     long                mnDUnderlineSize;           // Height of double underline
     319             :     long                mnDUnderlineOffset1;        // Offset from double underline to baseline
     320             :     long                mnDUnderlineOffset2;        // Offset from double underline to baseline
     321             :     long                mnWUnderlineSize;           // Height of WaveLine underline
     322             :     long                mnWUnderlineOffset;         // Offset from WaveLine underline to baseline, but centrered to WaveLine
     323             :     long                mnAboveUnderlineSize;       // Height of single underline (for Vertical Right)
     324             :     long                mnAboveUnderlineOffset;     // Offset from single underline to baseline (for Vertical Right)
     325             :     long                mnAboveBUnderlineSize;      // Height of bold underline (for Vertical Right)
     326             :     long                mnAboveBUnderlineOffset;    // Offset from bold underline to baseline (for Vertical Right)
     327             :     long                mnAboveDUnderlineSize;      // Height of double underline (for Vertical Right)
     328             :     long                mnAboveDUnderlineOffset1;   // Offset from double underline to baseline (for Vertical Right)
     329             :     long                mnAboveDUnderlineOffset2;   // Offset from double underline to baseline (for Vertical Right)
     330             :     long                mnAboveWUnderlineSize;      // Height of WaveLine-strike-out (for Vertical Right)
     331             :     long                mnAboveWUnderlineOffset;    // Offset from WaveLine-strike-out to baseline, but centrered to to WaveLine (for Vertical Right)
     332             :     long                mnStrikeoutSize;            // Height of single strike-out
     333             :     long                mnStrikeoutOffset;          // Offset from single strike-out to baseline
     334             :     long                mnBStrikeoutSize;           // Height of bold strike-out
     335             :     long                mnBStrikeoutOffset;         // Offset of bold strike-out to baseline
     336             :     long                mnDStrikeoutSize;           // Height of double strike-out
     337             :     long                mnDStrikeoutOffset1;        // Offset of double strike-out to baseline
     338             :     long                mnDStrikeoutOffset2;        // Offset of double strike-out to baseline
     339             : };
     340             : 
     341             : // -----------------
     342             : // - ImplFontEntry -
     343             : // ------------------
     344             : // TODO: rename ImplFontEntry to LogicalFontInstance
     345             : // TODO: allow sharing of metrics for related fonts
     346             : 
     347             : class VCL_PLUGIN_PUBLIC ImplFontEntry
     348             : {
     349             : public:
     350             :     explicit            ImplFontEntry( const FontSelectPattern& );
     351             :     virtual             ~ImplFontEntry();
     352             : 
     353             : public: // TODO: make data members private
     354             :     FontSelectPattern  maFontSelData;      // FontSelectionData
     355             :     ImplFontMetricData  maMetric;           // Font Metric
     356             :     const ConvertChar*  mpConversion;       // used e.g. for StarBats->StarSymbol
     357             :     long                mnLineHeight;
     358             :     sal_uLong               mnRefCount;
     359             :     sal_uInt16              mnSetFontFlags;     // Flags returned by SalGraphics::SetFont()
     360             :     short               mnOwnOrientation;   // text angle if lower layers don't rotate text themselves
     361             :     short               mnOrientation;      // text angle in 3600 system
     362             :     bool                mbInit;             // true if maMetric member is valid
     363             : 
     364             :     void                AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
     365             :     bool                GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
     366             :     void                IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName );
     367             : 
     368             : private:
     369             :     // cache of Unicode characters and replacement font names
     370             :     // TODO: a fallback map can be shared with many other ImplFontEntries
     371             :     // TODO: at least the ones which just differ in orientation, stretching or height
     372             :     typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
     373             :     struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
     374             :     typedef ::boost::unordered_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
     375             :     UnicodeFallbackList* mpUnicodeFallbackList;
     376             : };
     377             : 
     378             : 
     379             : class ImplTextLineInfo
     380             : {
     381             : private:
     382             :     long        mnWidth;
     383             :     xub_StrLen  mnIndex;
     384             :     xub_StrLen  mnLen;
     385             : 
     386             : public:
     387        1319 :                 ImplTextLineInfo( long nWidth, xub_StrLen nIndex, xub_StrLen nLen )
     388             :                 {
     389        1319 :                     mnWidth = nWidth;
     390        1319 :                     mnIndex = nIndex;
     391        1319 :                     mnLen   = nLen;
     392        1319 :                 }
     393             : 
     394        1065 :     long        GetWidth() const { return mnWidth; }
     395         935 :     xub_StrLen  GetIndex() const { return mnIndex; }
     396         935 :     xub_StrLen  GetLen() const { return mnLen; }
     397             : };
     398             : 
     399             : #define MULTITEXTLINEINFO_RESIZE    16
     400             : typedef ImplTextLineInfo* PImplTextLineInfo;
     401             : 
     402             : class ImplMultiTextLineInfo
     403             : {
     404             : private:
     405             :     PImplTextLineInfo*  mpLines;
     406             :     xub_StrLen          mnLines;
     407             :     xub_StrLen          mnSize;
     408             : 
     409             : public:
     410             :                         ImplMultiTextLineInfo();
     411             :                         ~ImplMultiTextLineInfo();
     412             : 
     413             :     void                AddLine( ImplTextLineInfo* pLine );
     414             :     void                Clear();
     415             : 
     416        1319 :     ImplTextLineInfo*   GetLine( sal_uInt16 nLine ) const
     417        1319 :                             { return mpLines[nLine]; }
     418        1438 :     xub_StrLen          Count() const { return mnLines; }
     419             : 
     420             : private:
     421             :                             ImplMultiTextLineInfo( const ImplMultiTextLineInfo& );
     422             :     ImplMultiTextLineInfo&  operator=( const ImplMultiTextLineInfo& );
     423             : };
     424             : 
     425             : #endif // _SV_OUTFONT_HXX
     426             : 
     427             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10