Flutter Engine
The Flutter Engine
Classes | Macros | Typedefs | Functions | Variables
SkFontHost_FreeType.cpp File Reference
#include "include/core/SkBBHFactory.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkDrawable.h"
#include "include/core/SkFontMetrics.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkPath.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkScalar.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkMutex.h"
#include "include/private/base/SkTPin.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkTSearch.h"
#include "src/core/SkAdvancedTypefaceMetrics.h"
#include "src/core/SkDescriptor.h"
#include "src/core/SkFDot6.h"
#include "src/core/SkFontDescriptor.h"
#include "src/core/SkFontScanner.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkMask.h"
#include "src/core/SkMaskGamma.h"
#include "src/core/SkScalerContext.h"
#include "src/ports/SkFontHost_FreeType_common.h"
#include "src/ports/SkTypeface_FreeType.h"
#include "src/sfnt/SkOTUtils.h"
#include "src/sfnt/SkSFNTHeader.h"
#include "src/sfnt/SkTTCFHeader.h"
#include "src/utils/SkCallableTraits.h"
#include "src/utils/SkMatrix22.h"
#include <memory>
#include <optional>
#include <tuple>
#include <ft2build.h>
#include <freetype/ftadvanc.h>
#include <freetype/ftimage.h>
#include <freetype/ftbitmap.h>
#include <freetype/freetype.h>
#include <freetype/ftlcdfil.h>
#include <freetype/ftmodapi.h>
#include <freetype/ftmm.h>
#include <freetype/ftoutln.h>
#include <freetype/ftsizes.h>
#include <freetype/ftsystem.h>
#include <freetype/tttables.h>
#include <freetype/t1tables.h>
#include <freetype/ftfntfmt.h>
#include <dlfcn.h>
#include "src/base/SkUtils.h"

Go to the source code of this file.

Classes

class  FreeTypeLibrary
 
class  SkTypeface_FreeType::FaceRec
 
class  AutoFTAccess
 
class  SkScalerContext_FreeType
 

Macros

#define SK_FREETYPE_DLOPEN   (0x1)
 
#define SK_FREETYPE_MINIMUM_RUNTIME_VERSION   ((2 << 24) | (8 << 16) | (1 << 8) | (SK_FREETYPE_DLOPEN))
 
#define LOG_INFO(...)
 
#define SK_OUTLINE_EMBOLDEN_DIVISOR   24
 

Typedefs

using FT_Alloc_size_t = SkCallableTraits< FT_Alloc_Func >::argument< 1 >::type
 

Functions

static bool isLCD (const SkScalerContextRec &rec)
 
static SkScalar SkFT_FixedToScalar (FT_Fixed x)
 
static void * sk_ft_alloc (FT_Memory, FT_Alloc_size_t size)
 
static void sk_ft_free (FT_Memory, void *block)
 
static void * sk_ft_realloc (FT_Memory, FT_Alloc_size_t cur_size, FT_Alloc_size_t new_size, void *block)
 
static SkMutex & f_t_mutex ()
 
static unsigned long sk_ft_stream_io (FT_Stream ftStream, unsigned long offset, unsigned char *buffer, unsigned long count)
 
static void sk_ft_stream_close (FT_Stream)
 
static bool canEmbed (FT_Face face)
 
static bool canSubset (FT_Face face)
 
static SkAdvancedTypefaceMetrics::FontType get_font_type (FT_Face face)
 
static bool is_opentype_font_data_standard_format (const SkTypeface &typeface)
 
static bool bothZero (SkScalar a, SkScalar b)
 
static bool isAxisAligned (const SkScalerContextRec &rec)
 
static int GetVariationDesignPosition (AutoFTAccess &fta, SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount)
 
static FT_Int chooseBitmapStrike (FT_Face face, FT_F26Dot6 scaleY)
 

Variables

FT_MemoryRec_ gFTMemory = { nullptr, sk_ft_alloc, sk_ft_free, sk_ft_realloc }
 
static FreeTypeLibrarygFTLibrary
 
constexpr int kMaxC2GCacheCount = 512
 

Macro Definition Documentation

◆ LOG_INFO

#define LOG_INFO (   ...)

Definition at line 112 of file SkFontHost_FreeType.cpp.

◆ SK_FREETYPE_DLOPEN

#define SK_FREETYPE_DLOPEN   (0x1)

Definition at line 77 of file SkFontHost_FreeType.cpp.

◆ SK_FREETYPE_MINIMUM_RUNTIME_VERSION

#define SK_FREETYPE_MINIMUM_RUNTIME_VERSION   ((2 << 24) | (8 << 16) | (1 << 8) | (SK_FREETYPE_DLOPEN))

Definition at line 84 of file SkFontHost_FreeType.cpp.

◆ SK_OUTLINE_EMBOLDEN_DIVISOR

#define SK_OUTLINE_EMBOLDEN_DIVISOR   24

Definition at line 1671 of file SkFontHost_FreeType.cpp.

Typedef Documentation

◆ FT_Alloc_size_t

using FT_Alloc_size_t = SkCallableTraits<FT_Alloc_Func>::argument<1>::type

Definition at line 127 of file SkFontHost_FreeType.cpp.

Function Documentation

◆ bothZero()

static bool bothZero ( SkScalar  a,
SkScalar  b 
)
static

Definition at line 681 of file SkFontHost_FreeType.cpp.

681 {
682 return 0 == a && 0 == b;
683}
static bool b
struct MyStruct a[10]

◆ canEmbed()

static bool canEmbed ( FT_Face  face)
static

Definition at line 505 of file SkFontHost_FreeType.cpp.

505 {
506 FT_UShort fsType = FT_Get_FSType_Flags(face);
507 return (fsType & (FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING |
508 FT_FSTYPE_BITMAP_EMBEDDING_ONLY)) == 0;
509}

◆ canSubset()

static bool canSubset ( FT_Face  face)
static

Definition at line 511 of file SkFontHost_FreeType.cpp.

511 {
512 FT_UShort fsType = FT_Get_FSType_Flags(face);
513 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0;
514}

◆ chooseBitmapStrike()

static FT_Int chooseBitmapStrike ( FT_Face  face,
FT_F26Dot6  scaleY 
)
static

Returns the bitmap strike equal to or just larger than the requested size.

Definition at line 861 of file SkFontHost_FreeType.cpp.

861 {
862 if (face == nullptr) {
863 LOG_INFO("chooseBitmapStrike aborted due to nullptr face.\n");
864 return -1;
865 }
866
867 FT_Pos requestedPPEM = scaleY; // FT_Bitmap_Size::y_ppem is in 26.6 format.
868 FT_Int chosenStrikeIndex = -1;
869 FT_Pos chosenPPEM = 0;
870 for (FT_Int strikeIndex = 0; strikeIndex < face->num_fixed_sizes; ++strikeIndex) {
871 FT_Pos strikePPEM = face->available_sizes[strikeIndex].y_ppem;
872 if (strikePPEM == requestedPPEM) {
873 // exact match - our search stops here
874 return strikeIndex;
875 } else if (chosenPPEM < requestedPPEM) {
876 // attempt to increase chosenPPEM
877 if (chosenPPEM < strikePPEM) {
878 chosenPPEM = strikePPEM;
879 chosenStrikeIndex = strikeIndex;
880 }
881 } else {
882 // attempt to decrease chosenPPEM, but not below requestedPPEM
883 if (requestedPPEM < strikePPEM && strikePPEM < chosenPPEM) {
884 chosenPPEM = strikePPEM;
885 chosenStrikeIndex = strikeIndex;
886 }
887 }
888 }
889 return chosenStrikeIndex;
890}
#define LOG_INFO(...)
signed long FT_Pos

◆ f_t_mutex()

static SkMutex & f_t_mutex ( )
static

Definition at line 193 of file SkFontHost_FreeType.cpp.

193 {
194 static SkMutex& mutex = *(new SkMutex);
195 return mutex;
196}

◆ get_font_type()

static SkAdvancedTypefaceMetrics::FontType get_font_type ( FT_Face  face)
static

Definition at line 516 of file SkFontHost_FreeType.cpp.

516 {
517 const char* fontType = FT_Get_X11_Font_Format(face);
518 static struct { const char* s; SkAdvancedTypefaceMetrics::FontType t; } values[] = {
523 };
524 for(const auto& v : values) { if (strcmp(fontType, v.s) == 0) { return v.t; } }
526}
struct MyStruct s

◆ GetVariationDesignPosition()

static int GetVariationDesignPosition ( AutoFTAccess fta,
SkFontArguments::VariationPosition::Coordinate  coordinates[],
int  coordinateCount 
)
static

Copy the design variation coordinates into 'coordinates'.

Parameters
coordinatesthe buffer into which to write the design variation coordinates.
coordinateCountthe number of entries available through 'coordinates'.
Returns
The number of axes, or -1 if there is an error. If 'coordinates != nullptr' and 'coordinateCount >= numAxes' then 'coordinates' will be filled with the variation coordinates describing the position of this typeface in design variation space. It is possible the number of axes can be retrieved but actual position cannot.

Definition at line 715 of file SkFontHost_FreeType.cpp.

717{
718 FT_Face face = fta.face();
719 if (!face) {
720 return -1;
721 }
722
723 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) {
724 return 0;
725 }
726
727 FT_MM_Var* variations = nullptr;
728 if (FT_Get_MM_Var(face, &variations)) {
729 return -1;
730 }
731 UniqueVoidPtr autoFreeVariations(variations);
732
733 if (!coordinates || coordinateCount < SkToInt(variations->num_axis)) {
734 return variations->num_axis;
735 }
736
737 AutoSTMalloc<4, FT_Fixed> coords(variations->num_axis);
738 if (FT_Get_Var_Design_Coordinates(face, variations->num_axis, coords.get())) {
739 return -1;
740 }
741 for (FT_UInt i = 0; i < variations->num_axis; ++i) {
742 coordinates[i].axis = variations->axis[i].tag;
743 coordinates[i].value = SkFixedToScalar(coords[i]);
744 }
745
746 return variations->num_axis;
747}
#define SkFixedToScalar(x)
Definition: SkFixed.h:124
struct FT_FaceRec_ * FT_Face
constexpr int SkToInt(S x)
Definition: SkTo.h:29
std::unique_ptr< void, SkOverloadedFunctionObject< void(void *), sk_free > > UniqueVoidPtr
Definition: SkTemplates.h:431

◆ is_opentype_font_data_standard_format()

static bool is_opentype_font_data_standard_format ( const SkTypeface typeface)
static

Definition at line 528 of file SkFontHost_FreeType.cpp.

528 {
529 // FreeType reports TrueType for any data that can be decoded to TrueType or OpenType.
530 // However, there are alternate data formats for OpenType, like wOFF and wOF2.
531 std::unique_ptr<SkStreamAsset> stream = typeface.openStream(nullptr);
532 if (!stream) {
533 return false;
534 }
535 char buffer[4];
536 if (stream->read(buffer, 4) < 4) {
537 return false;
538 }
539
541 SK_OT_ULONG otTag = SkEndian_SwapBE32(tag);
546 otTag == SkTTCFHeader::TAG;
547}
#define SkEndian_SwapBE32(n)
Definition: SkEndian.h:136
uint32_t SK_OT_ULONG
uint32_t SkFourByteTag
Definition: SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
Definition: SkTypeface.cpp:332
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
static const SK_OT_ULONG TAG
Definition: SkSFNTHeader.h:34
static const SK_OT_ULONG TAG
Definition: SkSFNTHeader.h:48
static const SK_OT_ULONG TAG
Definition: SkSFNTHeader.h:41
static const SK_OT_ULONG TAG
Definition: SkSFNTHeader.h:27
static const SK_OT_ULONG TAG
Definition: SkTTCFHeader.h:22

◆ isAxisAligned()

static bool isAxisAligned ( const SkScalerContextRec rec)
static

Definition at line 686 of file SkFontHost_FreeType.cpp.

686 {
687 return 0 == rec.fPreSkewX &&
688 (bothZero(rec.fPost2x2[0][1], rec.fPost2x2[1][0]) ||
689 bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1]));
690}
static bool bothZero(SkScalar a, SkScalar b)
SkScalar fPost2x2[2][2]

◆ isLCD()

static bool isLCD ( const SkScalerContextRec rec)
static

Definition at line 117 of file SkFontHost_FreeType.cpp.

117 {
119}
@ kLCD16_Format
565 alpha for r/g/b
Definition: SkMask.h:31
SkMask::Format fMaskFormat

◆ sk_ft_alloc()

static void * sk_ft_alloc ( FT_Memory  ,
FT_Alloc_size_t  size 
)
static

Definition at line 132 of file SkFontHost_FreeType.cpp.

132 {
133 return sk_malloc_canfail(size);
134 }
static void * sk_malloc_canfail(size_t size)
Definition: SkMalloc.h:93
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ sk_ft_free()

static void sk_ft_free ( FT_Memory  ,
void *  block 
)
static

Definition at line 135 of file SkFontHost_FreeType.cpp.

135 {
136 sk_free(block);
137 }
SK_API void sk_free(void *)

◆ sk_ft_realloc()

static void * sk_ft_realloc ( FT_Memory  ,
FT_Alloc_size_t  cur_size,
FT_Alloc_size_t  new_size,
void *  block 
)
static

Definition at line 138 of file SkFontHost_FreeType.cpp.

139 {
140 return sk_realloc_throw(block, new_size);
141 }
SK_API void * sk_realloc_throw(void *buffer, size_t size)

◆ sk_ft_stream_close()

static void sk_ft_stream_close ( FT_Stream  )
static

Definition at line 266 of file SkFontHost_FreeType.cpp.

266{}

◆ sk_ft_stream_io()

static unsigned long sk_ft_stream_io ( FT_Stream  ftStream,
unsigned long  offset,
unsigned char *  buffer,
unsigned long  count 
)
static

Definition at line 250 of file SkFontHost_FreeType.cpp.

254 {
255 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor.pointer);
256
257 if (count) {
258 if (!stream->seek(offset)) {
259 return 0;
260 }
261 count = stream->read(buffer, count);
262 }
263 return count;
264 }
int count
Definition: FontMgrTest.cpp:50
SeparatedVector2 offset

◆ SkFT_FixedToScalar()

static SkScalar SkFT_FixedToScalar ( FT_Fixed  x)
static

Definition at line 121 of file SkFontHost_FreeType.cpp.

121 {
122 return SkFixedToScalar(x);
123}
double x

Variable Documentation

◆ gFTLibrary

FreeTypeLibrary* gFTLibrary
static

Definition at line 198 of file SkFontHost_FreeType.cpp.

◆ gFTMemory

FT_MemoryRec_ gFTMemory = { nullptr, sk_ft_alloc, sk_ft_free, sk_ft_realloc }

Definition at line 143 of file SkFontHost_FreeType.cpp.

◆ kMaxC2GCacheCount

constexpr int kMaxC2GCacheCount = 512
constexpr

Definition at line 1718 of file SkFontHost_FreeType.cpp.