/*! \brief This saves all family names and styles to the file specified in ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage. This operation is not done very often because the access to disk adds a significant performance hit. The format for storage consists of two things: an array of strings with the name 'family' and a number of small string arrays which have the name of the font family. These are the style lists. Additionally, any fonts which have bitmap strikes contained in them or any fonts which are fixed-width are named in the arrays 'tuned' and 'fixed'. */ void FontServer::SaveList(void) { int32 famcount=0, stycount=0,i=0,j=0; FontFamily *fam; FontStyle *sty; BMessage fontmsg, familymsg('FONT'); BString famname, styname, extraname; bool fixed,tuned; famcount=families->CountItems(); for(i=0; i<famcount; i++) { fam=(FontFamily*)families->ItemAt(i); fixed=false; tuned=false; if(!fam) continue; famname=fam->Name(); // Add the family to the message familymsg.AddString("name",famname); stycount=fam->CountStyles(); for(j=0;j<stycount;j++) { styname.SetTo(fam->GetStyle(j)); if(styname.CountChars()>0) { // Add to list familymsg.AddString("styles", styname); // Check to see if it has prerendered strikes (has "tuned" fonts) sty=fam->GetStyle(styname.String()); if(!sty) continue; if(sty->HasTuned() && sty->IsScalable()) tuned=true; // Check to see if it is fixed-width if(sty->IsFixedWidth()) fixed=true; } } if(tuned) familymsg.AddBool("tuned",true); if(fixed) familymsg.AddBool("fixed",true); fontmsg.AddMessage("family",&familymsg); familymsg.MakeEmpty(); } BFile file(SERVER_FONT_LIST,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); if(file.InitCheck()==B_OK) fontmsg.Flatten(&file); }
/*! \brief Protected function which locates a FontFamily object \param name The family to find \return Pointer to the specified family or NULL if not found. Do NOT delete the FontFamily returned by this function. */ FontFamily *FontServer::_FindFamily(const char *name) { if(!init) return NULL; int32 count=families->CountItems(), i; FontFamily *family; for(i=0; i<count; i++) { family=(FontFamily*)families->ItemAt(i); if(strcmp(family->Name(),name)==0) return family; } return NULL; }
/*! \brief Retrieves the FontStyle object that comes closest to the one specified. \param family The font's family or NULL in which case \a familyID is used \param style The font's style or NULL in which case \a styleID is used \param familyID will only be used if \a family is NULL (or empty) \param styleID will only be used if \a style is NULL (or empty) \param face is used to specify the style if both \a style is NULL or empty and styleID is 0xffff. \return The FontStyle having those attributes or NULL if not available */ FontStyle* FontManager::GetStyle(const char* familyName, const char* styleName, uint16 familyID, uint16 styleID, uint16 face) { FontFamily* family; // find family if (familyName != NULL && familyName[0]) family = GetFamily(familyName); else family = GetFamily(familyID); if (family == NULL) return NULL; // find style if (styleName != NULL && styleName[0]) { FontStyle* fontStyle = family->GetStyle(styleName); if (fontStyle != NULL) return fontStyle; // before we fail, we try the mappings for a match if (_AddMappedFont(family->Name(), styleName) == B_OK) { fontStyle = family->GetStyle(styleName); if (fontStyle != NULL) return fontStyle; } _ScanFonts(); return family->GetStyle(styleName); } if (styleID != 0xffff) return family->GetStyleByID(styleID); // try to get from face return family->GetStyleMatchingFace(face); }