LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/ports - SkFontHost_FreeType_common.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 4 75.0 %
Date: 2017-07-14 16:53:18 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2006-2012 The Android Open Source Project
       3             :  * Copyright 2012 Mozilla Foundation
       4             :  *
       5             :  * Use of this source code is governed by a BSD-style license that can be
       6             :  * found in the LICENSE file.
       7             :  */
       8             : 
       9             : #ifndef SKFONTHOST_FREETYPE_COMMON_H_
      10             : #define SKFONTHOST_FREETYPE_COMMON_H_
      11             : 
      12             : #include "SkGlyph.h"
      13             : #include "SkMutex.h"
      14             : #include "SkScalerContext.h"
      15             : #include "SkTypeface.h"
      16             : #include "SkTypes.h"
      17             : 
      18             : #include "SkFontMgr.h"
      19             : 
      20             : // These are forward declared to avoid pimpl but also hide the FreeType implementation.
      21             : typedef struct FT_LibraryRec_* FT_Library;
      22             : typedef struct FT_FaceRec_* FT_Face;
      23             : typedef struct FT_StreamRec_* FT_Stream;
      24             : typedef signed long FT_Pos;
      25             : 
      26           0 : class SkScalerContext_FreeType_Base : public SkScalerContext {
      27             : protected:
      28             :     // See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
      29             :     // This value was chosen by eyeballing the result in Firefox and trying to match it.
      30             :     static const FT_Pos kBitmapEmboldenStrength = 1 << 6;
      31             : 
      32           2 :     SkScalerContext_FreeType_Base(sk_sp<SkTypeface> typeface, const SkScalerContextEffects& effects,
      33             :                                   const SkDescriptor *desc)
      34           2 :         : INHERITED(std::move(typeface), effects, desc)
      35           2 :     {}
      36             : 
      37             :     void generateGlyphImage(FT_Face face, const SkGlyph& glyph, const SkMatrix& bitmapTransform);
      38             :     void generateGlyphPath(FT_Face face, SkPath* path);
      39             : private:
      40             :     typedef SkScalerContext INHERITED;
      41             : };
      42             : 
      43             : class SkTypeface_FreeType : public SkTypeface {
      44             : public:
      45             :     /** For SkFontMgrs to make use of our ability to extract
      46             :      *  name and style from a stream, using FreeType's API.
      47             :      */
      48             :     class Scanner : ::SkNoncopyable {
      49             :     public:
      50             :         Scanner();
      51             :         ~Scanner();
      52             :         struct AxisDefinition {
      53             :             SkFourByteTag fTag;
      54             :             SkFixed fMinimum;
      55             :             SkFixed fDefault;
      56             :             SkFixed fMaximum;
      57             :         };
      58             :         using AxisDefinitions = SkSTArray<4, AxisDefinition, true>;
      59             :         bool recognizedFont(SkStreamAsset* stream, int* numFonts) const;
      60             :         bool scanFont(SkStreamAsset* stream, int ttcIndex,
      61             :                       SkString* name, SkFontStyle* style, bool* isFixedPitch,
      62             :                       AxisDefinitions* axes) const;
      63             :         static void computeAxisValues(
      64             :             AxisDefinitions axisDefinitions,
      65             :             const SkFontArguments::VariationPosition position,
      66             :             SkFixed* axisValues,
      67             :             const SkString& name);
      68             : 
      69             :     private:
      70             :         FT_Face openFace(SkStreamAsset* stream, int ttcIndex, FT_Stream ftStream) const;
      71             :         FT_Library fLibrary;
      72             :         mutable SkMutex fLibraryMutex;
      73             :     };
      74             : 
      75             : protected:
      76             :     SkTypeface_FreeType(const SkFontStyle& style, bool isFixedPitch)
      77             :         : INHERITED(style, isFixedPitch)
      78             :     {}
      79             : 
      80             :     virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
      81             :                                                    const SkDescriptor*) const override;
      82             :     void onFilterRec(SkScalerContextRec*) const override;
      83             :     SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
      84             :                         PerGlyphInfo, const uint32_t*, uint32_t) const override;
      85             :     int onGetUPEM() const override;
      86             :     bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
      87             :                                      int32_t adjustments[]) const override;
      88             :     int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
      89             :                         int glyphCount) const override;
      90             :     int onCountGlyphs() const override;
      91             : 
      92             :     LocalizedStrings* onCreateFamilyNameIterator() const override;
      93             : 
      94             :     int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
      95             :                                      int coordinateCount) const override;
      96             :     int onGetTableTags(SkFontTableTag tags[]) const override;
      97             :     size_t onGetTableData(SkFontTableTag, size_t offset,
      98             :                           size_t length, void* data) const override;
      99             : 
     100             : private:
     101             :     typedef SkTypeface INHERITED;
     102             : };
     103             : 
     104             : #endif // SKFONTHOST_FREETYPE_COMMON_H_

Generated by: LCOV version 1.13