LCOV - code coverage report
Current view: directory - gfx/thebes - gfxFT2Utils.h (source / functions) Found Hit Coverage
Test: app.info Lines: 16 0 0.0 %
Date: 2012-06-02 Functions: 4 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Foundation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Vladimir Vukicevic <vladimir@mozilla.com>
      23                 :  *   Masayuki Nakano <masayuki@d-toybox.com>
      24                 :  *   Behdad Esfahbod <behdad@gnome.org>
      25                 :  *   Mats Palmgren <mats.palmgren@bredband.net>
      26                 :  *   Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
      27                 :  *   Takuro Ashie <ashie@clear-code.com>
      28                 :  *
      29                 :  * Alternatively, the contents of this file may be used under the terms of
      30                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      31                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      32                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      33                 :  * of those above. If you wish to allow use of your version of this file only
      34                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      35                 :  * use your version of this file under the terms of the MPL, indicate your
      36                 :  * decision by deleting the provisions above and replace them with the notice
      37                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      38                 :  * the provisions above, a recipient may use your version of this file under
      39                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      40                 :  *
      41                 :  * ***** END LICENSE BLOCK ***** */
      42                 : 
      43                 : #ifndef GFX_FT2UTILS_H
      44                 : #define GFX_FT2UTILS_H
      45                 : 
      46                 : #include "cairo-ft.h"
      47                 : #include "gfxFT2FontBase.h"
      48                 : 
      49                 : // Rounding and truncation functions for a FreeType fixed point number 
      50                 : // (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
      51                 : // part and low 6 bits for the fractional part. 
      52                 : #define FLOAT_FROM_26_6(x) ((x) / 64.0)
      53                 : #define FLOAT_FROM_16_16(x) ((x) / 65536.0)
      54                 : #define ROUND_26_6_TO_INT(x) ((x) >= 0 ?  ((32 + (x)) >> 6) \
      55                 :                                        : -((32 - (x)) >> 6))
      56                 : 
      57                 : typedef struct FT_FaceRec_* FT_Face;
      58                 : 
      59                 : class gfxFT2LockedFace {
      60                 : public:
      61               0 :     gfxFT2LockedFace(gfxFT2FontBase *aFont) :
      62                 :         mGfxFont(aFont),
      63               0 :         mFace(cairo_ft_scaled_font_lock_face(aFont->CairoScaledFont()))
      64               0 :     { }
      65               0 :     ~gfxFT2LockedFace()
      66               0 :     {
      67               0 :         if (mFace) {
      68               0 :             cairo_ft_scaled_font_unlock_face(mGfxFont->CairoScaledFont());
      69                 :         }
      70               0 :     }
      71                 : 
      72               0 :     FT_Face get() { return mFace; };
      73                 : 
      74                 :     /**
      75                 :      * Get the glyph id for a Unicode character representable by a single
      76                 :      * glyph, or return zero if there is no such glyph.  This does no caching,
      77                 :      * so you probably want gfxFcFont::GetGlyph.
      78                 :      */
      79                 :     PRUint32 GetGlyph(PRUint32 aCharCode);
      80                 :     /**
      81                 :      * Returns 0 if there is no variation selector cmap subtable.
      82                 :      */
      83                 :     PRUint32 GetUVSGlyph(PRUint32 aCharCode, PRUint32 aVariantSelector);
      84                 : 
      85                 :     void GetMetrics(gfxFont::Metrics* aMetrics, PRUint32* aSpaceGlyph);
      86                 : 
      87                 :     bool GetFontTable(PRUint32 aTag, FallibleTArray<PRUint8>& aBuffer);
      88                 : 
      89                 :     // A scale factor for use in converting horizontal metrics from font units
      90                 :     // to pixels.
      91               0 :     gfxFloat XScale()
      92                 :     {
      93               0 :         if (NS_UNLIKELY(!mFace))
      94               0 :             return 0.0;
      95                 : 
      96               0 :         const FT_Size_Metrics& ftMetrics = mFace->size->metrics;
      97                 : 
      98               0 :         if (FT_IS_SCALABLE(mFace)) {
      99                 :             // Prefer FT_Size_Metrics::x_scale to x_ppem as x_ppem does not
     100                 :             // have subpixel accuracy.
     101                 :             //
     102                 :             // FT_Size_Metrics::x_scale is in 16.16 fixed point format.  Its
     103                 :             // (fractional) value is a factor that converts vertical metrics
     104                 :             // from design units to units of 1/64 pixels, so that the result
     105                 :             // may be interpreted as pixels in 26.6 fixed point format.
     106               0 :             return FLOAT_FROM_26_6(FLOAT_FROM_16_16(ftMetrics.x_scale));
     107                 :         }
     108                 : 
     109                 :         // Not scalable.
     110                 :         // FT_Size_Metrics doc says x_scale is "only relevant for scalable
     111                 :         // font formats".
     112               0 :         return gfxFloat(ftMetrics.x_ppem) / gfxFloat(mFace->units_per_EM);
     113                 :     }
     114                 : 
     115                 : protected:
     116                 :     /**
     117                 :      * Get extents for a simple character representable by a single glyph.
     118                 :      * The return value is the glyph id of that glyph or zero if no such glyph
     119                 :      * exists.  aExtents is only set when this returns a non-zero glyph id.
     120                 :      */
     121                 :     PRUint32 GetCharExtents(char aChar, cairo_text_extents_t* aExtents);
     122                 : 
     123                 :     typedef FT_UInt (*CharVariantFunction)(FT_Face  face,
     124                 :                                            FT_ULong charcode,
     125                 :                                            FT_ULong variantSelector);
     126                 :     CharVariantFunction FindCharVariantFunction();
     127                 : 
     128                 :     nsRefPtr<gfxFT2FontBase> mGfxFont;
     129                 :     FT_Face mFace;
     130                 : };
     131                 : 
     132                 : #endif /* GFX_FT2UTILS_H */

Generated by: LCOV version 1.7