LCOV - code coverage report
Current view: top level - vcl/inc - graphite_layout.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 26 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 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_GRAPHITE_LAYOUT_HXX
      21             : #define INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
      22             : // Description: An implementation of the SalLayout interface that uses the
      23             : //              Graphite engine.
      24             : 
      25             : // We need this to enable namespace support in libgrengine headers.
      26             : #define GR_NAMESPACE
      27             : 
      28             : #include <memory>
      29             : #include <vector>
      30             : #include <map>
      31             : #include <utility>
      32             : 
      33             : #include <graphite_static.hxx>
      34             : #include <graphite2/Font.h>
      35             : #include <graphite2/Segment.h>
      36             : 
      37             : #include <vcl/dllapi.h>
      38             : 
      39             : #include "sallayout.hxx"
      40             : 
      41             : class ServerFont;
      42             : class PhysicalFontFace;
      43             : 
      44             : namespace grutils { class GrFeatureParser; }
      45             : 
      46             : class GraphiteFaceWrapper
      47             : {
      48             : public:
      49             :     typedef std::pair<int, int> GrFontMapKey;
      50             :     typedef std::map<GrFontMapKey, gr_font*> GrFontMap;
      51           0 :     GraphiteFaceWrapper(gr_face * pFace) : m_pFace(pFace) {}
      52           0 :     ~GraphiteFaceWrapper()
      53           0 :     {
      54           0 :         GrFontMap::iterator i = m_fonts.begin();
      55           0 :         while (i != m_fonts.end())
      56           0 :             gr_font_destroy((*i++).second);
      57           0 :         m_fonts.clear();
      58           0 :         gr_face_destroy(m_pFace);
      59           0 :     }
      60           0 :     const gr_face * face() const { return m_pFace; }
      61           0 :     gr_font * font(int ppm, bool isBold, bool isItalic) const
      62             :     {
      63           0 :         int styleKey = int(isBold) | (int(isItalic) << 1);
      64           0 :         GrFontMap::const_iterator i = m_fonts.find(GrFontMapKey(ppm, styleKey));
      65           0 :         if (i != m_fonts.end())
      66           0 :             return i->second;
      67           0 :         return NULL;
      68             :     };
      69           0 :     void addFont(int ppm, gr_font * pFont, bool isBold, bool isItalic)
      70             :     {
      71           0 :         int styleKey = int(isBold) | (int(isItalic) << 1);
      72           0 :         GrFontMapKey key(ppm, styleKey);
      73           0 :         if (m_fonts[key])
      74           0 :             gr_font_destroy(m_fonts[key]);
      75           0 :         m_fonts[key] = pFont;
      76           0 :     }
      77             : private:
      78             :     gr_face * m_pFace;
      79             :     GrFontMap m_fonts;
      80             : };
      81             : 
      82             : // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
      83             : // @author tse
      84             : 
      85             : class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout
      86             : {
      87             : public:
      88             :     typedef std::vector<GlyphItem> Glyphs;
      89             : 
      90             :     mutable Glyphs          mvGlyphs;
      91             :     void clear();
      92             : 
      93             : private:
      94             :     const gr_face *         mpFace; // not owned by layout
      95             :     gr_font *               mpFont; // not owned by layout
      96             :     int                     mnSegCharOffset; // relative to ImplLayoutArgs::mpStr
      97             :     long                    mnWidth;
      98             :     std::vector<int>        mvChar2BaseGlyph;
      99             :     std::vector<int>        mvGlyph2Char;
     100             :     std::vector<int>        mvCharDxs;
     101             :     std::vector<int>        mvCharBreaks;
     102             :     float                   mfScaling;
     103             :     const grutils::GrFeatureParser * mpFeatures;
     104             : 
     105             : public:
     106             :     GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
     107             :         const grutils::GrFeatureParser * features = NULL) throw();
     108             : 
     109             :     // used by upper layers
     110             :     virtual bool  LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE;    // first step of layout
     111             :     // split into two stages to allow dc to be restored on the segment
     112             :     gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
     113             :     bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
     114             : 
     115             :     virtual void  AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE;  // adjusting positions
     116             : 
     117             :     // methods using string indexing
     118             :     virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra=0, int nFactor=1) const SAL_OVERRIDE;
     119             :     virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const SAL_OVERRIDE;
     120             :     void  ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth);
     121             : 
     122             :     virtual void  GetCaretPositions( int nArraySize, long* pCaretXArray ) const SAL_OVERRIDE;
     123             : 
     124             :     // methods using glyph indexing
     125             :     virtual int   GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
     126             :             long* pGlyphAdvAry = NULL, int* pCharPosAry = NULL,
     127             :             const PhysicalFontFace** pFallbackFonts = NULL ) const SAL_OVERRIDE;
     128             : 
     129             :     // used by glyph+font+script fallback
     130             :     virtual void    MoveGlyph( int nStart, long nNewXPos ) SAL_OVERRIDE;
     131             :     virtual void    DropGlyph( int nStart ) SAL_OVERRIDE;
     132             :     virtual void    Simplify( bool bIsBase ) SAL_OVERRIDE;
     133             : 
     134             :     // Dummy implementation so layout can be shared between Linux/Windows
     135           0 :     virtual void    DrawText(SalGraphics&) const SAL_OVERRIDE {};
     136             : 
     137             :     virtual ~GraphiteLayout() throw();
     138           0 :     void SetFont(gr_font * pFont) { mpFont = pFont; }
     139             :     gr_font * GetFont() { return mpFont; }
     140           0 :     void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
     141             :     void SetFontScale(float s) { mfScaling = s; };
     142             :     virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
     143             :     void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
     144             : 
     145             :     static const int EXTRA_CONTEXT_LENGTH;
     146             : private:
     147             :     void expandOrCondense(ImplLayoutArgs &rArgs);
     148             :     void    fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
     149             : 
     150             :     float append(gr_segment * pSeg,
     151             :                 ImplLayoutArgs & rArgs,
     152             :                 const gr_slot * pSlot, float gOrigin,
     153             :                 float nextGlyphOrigin, float fScaling,
     154             :                 long & rDXOffset, bool bIsBase, int baseChar);
     155             : };
     156             : 
     157             : #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11