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

Generated by: LCOV version 1.10