LCOV - code coverage report
Current view: top level - vcl/inc - graphite_layout.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 23 0.0 %
Date: 2014-11-03 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             : // 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             :     typedef std::vector<GlyphItem> Glyphs;
      91             : 
      92             :     mutable Glyphs          mvGlyphs;
      93             :     void clear();
      94             : 
      95             : private:
      96             :     const gr_face *         mpFace; // not owned by layout
      97             :     gr_font *               mpFont; // not owned by layout
      98             :     int                     mnSegCharOffset; // relative to ImplLayoutArgs::mpStr
      99             :     long                    mnWidth;
     100             :     std::vector<int>        mvChar2BaseGlyph;
     101             :     std::vector<int>        mvGlyph2Char;
     102             :     std::vector<int>        mvCharDxs;
     103             :     std::vector<int>        mvCharBreaks;
     104             :     float                   mfScaling;
     105             :     const grutils::GrFeatureParser * mpFeatures;
     106             : 
     107             : public:
     108             :     GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
     109             :         const grutils::GrFeatureParser * features = NULL) throw();
     110             : 
     111             :     // used by upper layers
     112             :     virtual bool  LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE;    // first step of layout
     113             :     // split into two stages to allow dc to be restored on the segment
     114             :     gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
     115             :     bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
     116             : 
     117             :     virtual void  AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE;  // adjusting positions
     118             : 
     119             :     // methods using string indexing
     120             :     virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra=0, int nFactor=1) const SAL_OVERRIDE;
     121             :     virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const SAL_OVERRIDE;
     122             :     virtual void  ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth);
     123             : 
     124             :     virtual void  GetCaretPositions( int nArraySize, long* pCaretXArray ) const SAL_OVERRIDE;
     125             : 
     126             :     // methods using glyph indexing
     127             :     virtual int   GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
     128             :             long* pGlyphAdvAry = NULL, int* pCharPosAry = NULL,
     129             :             const PhysicalFontFace** pFallbackFonts = NULL ) const SAL_OVERRIDE;
     130             : 
     131             :     // used by glyph+font+script fallback
     132             :     virtual void    MoveGlyph( int nStart, long nNewXPos ) SAL_OVERRIDE;
     133             :     virtual void    DropGlyph( int nStart ) SAL_OVERRIDE;
     134             :     virtual void    Simplify( bool bIsBase ) SAL_OVERRIDE;
     135             : 
     136             :     // Dummy implementation so layout can be shared between Linux/Windows
     137           0 :     virtual void    DrawText(SalGraphics&) const SAL_OVERRIDE {};
     138             : 
     139             :     virtual ~GraphiteLayout() throw();
     140           0 :     void SetFont(gr_font * pFont) { mpFont = pFont; }
     141             :     gr_font * GetFont() { return mpFont; }
     142           0 :     void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
     143             :     void SetFontScale(float s) { mfScaling = s; };
     144             :     virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
     145             :     void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
     146             : 
     147             :     static const int EXTRA_CONTEXT_LENGTH;
     148             : private:
     149             :     void expandOrCondense(ImplLayoutArgs &rArgs);
     150             :     void    fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
     151             : 
     152             :     float append(gr_segment * pSeg,
     153             :                 ImplLayoutArgs & rArgs,
     154             :                 const gr_slot * pSlot, float gOrigin,
     155             :                 float nextGlyphOrigin, float fScaling,
     156             :                 long & rDXOffset, bool bIsBase, int baseChar);
     157             : };
     158             : 
     159             : #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10