Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
SkFontConfigInterfaceDirect Class Reference

#include <SkFontConfigInterface_direct.h>

Inheritance diagram for SkFontConfigInterfaceDirect:
SkFontConfigInterface SkRefCnt SkRefCntBase

Public Member Functions

 SkFontConfigInterfaceDirect (FcConfig *fc)
 
 ~SkFontConfigInterfaceDirect () override
 
bool matchFamilyName (const char familyName[], SkFontStyle requested, FontIdentity *outFontIdentifier, SkString *outFamilyName, SkFontStyle *outStyle) override
 
SkStreamAssetopenStream (const FontIdentity &) override
 
- Public Member Functions inherited from SkFontConfigInterface
virtual bool matchFamilyName (const char familyName[], SkFontStyle requested, FontIdentity *outFontIdentifier, SkString *outFamilyName, SkFontStyle *outStyle)=0
 
virtual SkStreamAssetopenStream (const FontIdentity &)=0
 
virtual sk_sp< SkTypefacemakeTypeface (const FontIdentity &identity, sk_sp< SkFontMgr > mgr)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

virtual bool isAccessible (const char *filename)
 

Additional Inherited Members

- Public Types inherited from SkFontConfigInterface
using INHERITED = SkRefCnt
 
- Static Public Member Functions inherited from SkFontConfigInterface
static sk_sp< SkFontConfigInterfaceRefGlobal ()
 
static void SetGlobal (sk_sp< SkFontConfigInterface > fc)
 
static SkFontConfigInterfaceGetSingletonDirectInterface ()
 

Detailed Description

Definition at line 16 of file SkFontConfigInterface_direct.h.

Constructor & Destructor Documentation

◆ SkFontConfigInterfaceDirect()

SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect ( FcConfig *  fc)

Create around a FontConfig instance. If 'fc' is nullptr, each method call will use the current config. Takes ownership of 'fc' and will call FcConfigDestroy on it.

Definition at line 496 of file SkFontConfigInterface_direct.cpp.

496 : fFC(fc)
497{
498 SkDEBUGCODE(fontconfiginterface_unittest();)
499}
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()

◆ ~SkFontConfigInterfaceDirect()

SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect ( )
override

Definition at line 501 of file SkFontConfigInterface_direct.cpp.

501 {
502 if (fFC) {
503 FcConfigDestroy(fFC);
504 }
505}

Member Function Documentation

◆ isAccessible()

bool SkFontConfigInterfaceDirect::isAccessible ( const char *  filename)
protectedvirtual

Definition at line 507 of file SkFontConfigInterface_direct.cpp.

507 {
508 if (access(filename, R_OK) != 0) {
509 return false;
510 }
511 return true;
512}

◆ matchFamilyName()

bool SkFontConfigInterfaceDirect::matchFamilyName ( const char  familyName[],
SkFontStyle  requested,
FontIdentity outFontIdentifier,
SkString outFamilyName,
SkFontStyle outStyle 
)
overridevirtual

Given a familyName and style, find the best match.

If a match is found, return true and set its outFontIdentifier. If outFamilyName is not null, assign the found familyName to it (which may differ from the requested familyName). If outStyle is not null, assign the found style to it (which may differ from the requested style).

If a match is not found, return false, and ignore all out parameters.

Implements SkFontConfigInterface.

Definition at line 588 of file SkFontConfigInterface_direct.cpp.

592 {
593 SkString familyStr(familyName ? familyName : "");
594 if (familyStr.size() > kMaxFontFamilyLength) {
595 return false;
596 }
597
598 FcConfig* fc = fFC;
599 UniqueFCConfig fcStorage;
600 if (!fc) {
601 fcStorage.reset(FcConfigReference(nullptr));
602 fc = fcStorage.get();
603 }
604
605 FCLocker lock;
606 FcPattern* pattern = FcPatternCreate();
607
608 if (familyName) {
609 FcPatternAddString(pattern, FC_FAMILY, (const FcChar8*)familyName);
610 }
611 fcpattern_from_skfontstyle(style, pattern);
612
613 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
614
615 FcConfigSubstitute(fc, pattern, FcMatchPattern);
616 FcDefaultSubstitute(pattern);
617
618 // Font matching:
619 // CSS often specifies a fallback list of families:
620 // font-family: a, b, c, serif;
621 // However, fontconfig will always do its best to find *a* font when asked
622 // for something so we need a way to tell if the match which it has found is
623 // "good enough" for us. Otherwise, we can return nullptr which gets piped up
624 // and lets WebKit know to try the next CSS family name. However, fontconfig
625 // configs allow substitutions (mapping "Arial -> Helvetica" etc) and we
626 // wish to support that.
627 //
628 // Thus, if a specific family is requested we set @family_requested. Then we
629 // record two strings: the family name after config processing and the
630 // family name after resolving. If the two are equal, it's a good match.
631 //
632 // So consider the case where a user has mapped Arial to Helvetica in their
633 // config.
634 // requested family: "Arial"
635 // post_config_family: "Helvetica"
636 // post_match_family: "Helvetica"
637 // -> good match
638 //
639 // and for a missing font:
640 // requested family: "Monaco"
641 // post_config_family: "Monaco"
642 // post_match_family: "Times New Roman"
643 // -> BAD match
644 //
645 // However, we special-case fallback fonts; see IsFallbackFontAllowed().
646
647 const char* post_config_family = get_string(pattern, FC_FAMILY);
648 if (!post_config_family) {
649 // we can just continue with an empty name, e.g. default font
650 post_config_family = "";
651 }
652
653 FcResult result;
654 FcFontSet* font_set = FcFontSort(fc, pattern, 0, nullptr, &result);
655 if (!font_set) {
656 FcPatternDestroy(pattern);
657 return false;
658 }
659
660 FcPattern* match = this->MatchFont(font_set, post_config_family, familyStr);
661 if (!match) {
662 FcPatternDestroy(pattern);
663 FcFontSetDestroy(font_set);
664 return false;
665 }
666
667 FcPatternDestroy(pattern);
668
669 // From here out we just extract our results from 'match'
670
671 post_config_family = get_string(match, FC_FAMILY);
672 if (!post_config_family) {
673 FcFontSetDestroy(font_set);
674 return false;
675 }
676
677 const char* c_filename = get_string(match, FC_FILE);
678 if (!c_filename) {
679 FcFontSetDestroy(font_set);
680 return false;
681 }
682 const char* sysroot = (const char*)FcConfigGetSysRoot(fc);
683 SkString resolvedFilename;
684 if (sysroot) {
685 resolvedFilename = sysroot;
686 resolvedFilename += c_filename;
687 c_filename = resolvedFilename.c_str();
688 }
689
690 int face_index = get_int(match, FC_INDEX, 0);
691
692 FcFontSetDestroy(font_set);
693
694 if (outIdentity) {
695 outIdentity->fTTCIndex = face_index;
696 outIdentity->fString.set(c_filename);
697 }
698 if (outFamilyName) {
699 outFamilyName->set(post_config_family);
700 }
701 if (outStyle) {
703 }
704 return true;
705}
static uint32_t get_int(const uint8_t *buffer, uint32_t i)
Definition: SkCodecPriv.h:168
#define kMaxFontFamilyLength
static const char * get_string(FcPattern *pattern, const char field[], int index=0)
static SkFontStyle skfontstyle_from_fcpattern(FcPattern *pattern)
static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern *pattern)
void set(const SkString &src)
Definition: SkString.h:186
const char * c_str() const
Definition: SkString.h:133
GAsyncResult * result
def match(bench, filt)
Definition: benchmark.py:23

◆ openStream()

SkStreamAsset * SkFontConfigInterfaceDirect::openStream ( const FontIdentity )
overridevirtual

Given a FontRef, open a stream to access its data, or return null if the FontRef's data is not available. The caller is responsible for deleting the stream when it is done accessing the data.

Implements SkFontConfigInterface.

Definition at line 707 of file SkFontConfigInterface_direct.cpp.

707 {
708 return SkStream::MakeFromFile(identity.fString.c_str()).release();
709}
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition: SkStream.cpp:922

The documentation for this class was generated from the following files: