* FontFamily::GetStyle() now looks for alternative names when a specific
style couldn't be found, ie. when looking for "Roman", "Regular", and "Book" are accepted, too, and "Italic"/"Oblique" are now synonyms as well. * This prevents StyledEdit from using the "Condensed" style when it does not find a certain font. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24443 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku.
|
* Copyright 2001-2008, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -64,7 +64,7 @@ FontFamily::FontFamily(const char *name, uint16 id)
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Destructor
|
\brief Destructor
|
||||||
|
|
||||||
Deletes all attached styles. Note that a FontFamily must only be deleted
|
Deletes all attached styles. Note that a FontFamily must only be deleted
|
||||||
by the font manager.
|
by the font manager.
|
||||||
*/
|
*/
|
||||||
@@ -102,7 +102,7 @@ FontFamily::AddStyle(FontStyle *style)
|
|||||||
if (!style)
|
if (!style)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Don't add if it already is in the family.
|
// Don't add if it already is in the family.
|
||||||
int32 count = fStyles.CountItems();
|
int32 count = fStyles.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
FontStyle *item = fStyles.ItemAt(i);
|
FontStyle *item = fStyles.ItemAt(i);
|
||||||
@@ -157,6 +157,23 @@ FontFamily::CountStyles() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FontStyle*
|
||||||
|
FontFamily::_FindStyle(const char* name) const
|
||||||
|
{
|
||||||
|
int32 count = fStyles.CountItems();
|
||||||
|
if (!name || count < 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
FontStyle *style = fStyles.ItemAt(i);
|
||||||
|
if (!strcmp(style->Name(), name))
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Determines whether the style belongs to the family
|
\brief Determines whether the style belongs to the family
|
||||||
\param style Name of the style being checked
|
\param style Name of the style being checked
|
||||||
@@ -165,11 +182,11 @@ FontFamily::CountStyles() const
|
|||||||
bool
|
bool
|
||||||
FontFamily::HasStyle(const char *styleName) const
|
FontFamily::HasStyle(const char *styleName) const
|
||||||
{
|
{
|
||||||
return GetStyle(styleName) != NULL;
|
return _FindStyle(styleName) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the name of a style in the family
|
\brief Returns the name of a style in the family
|
||||||
\param index list index of the style to be found
|
\param index list index of the style to be found
|
||||||
\return name of the style or NULL if the index is not valid
|
\return name of the style or NULL if the index is not valid
|
||||||
@@ -185,20 +202,40 @@ FontFamily::StyleAt(int32 index) const
|
|||||||
\brief Get the FontStyle object for the name given
|
\brief Get the FontStyle object for the name given
|
||||||
\param style Name of the style to be obtained
|
\param style Name of the style to be obtained
|
||||||
\return The FontStyle object or NULL if none was found.
|
\return The FontStyle object or NULL if none was found.
|
||||||
|
|
||||||
The object returned belongs to the family and must not be deleted.
|
The object returned belongs to the family and must not be deleted.
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontFamily::GetStyle(const char *styleName) const
|
FontFamily::GetStyle(const char *name) const
|
||||||
{
|
{
|
||||||
int32 count = fStyles.CountItems();
|
if (name == NULL || !name[0])
|
||||||
if (!styleName || count < 1)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
FontStyle* style = _FindStyle(name);
|
||||||
FontStyle *style = fStyles.ItemAt(i);
|
if (style != NULL)
|
||||||
if (!strcmp(style->Name(), styleName))
|
return style;
|
||||||
return style;
|
|
||||||
|
// try alternative names
|
||||||
|
|
||||||
|
if (!strcmp(name, "Roman") || !strcmp(name, "Regular")
|
||||||
|
|| !strcmp(name, "Book")) {
|
||||||
|
style = _FindStyle("Roman");
|
||||||
|
if (style == NULL) {
|
||||||
|
style = _FindStyle("Regular");
|
||||||
|
if (style == NULL)
|
||||||
|
style = _FindStyle("Book");
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
BString alternative = name;
|
||||||
|
if (alternative.FindFirst("Italic") >= 0) {
|
||||||
|
alternative.ReplaceFirst("Italic", "Oblique");
|
||||||
|
return _FindStyle(alternative.String());
|
||||||
|
}
|
||||||
|
if (alternative.FindFirst("Oblique") >= 0) {
|
||||||
|
alternative.ReplaceFirst("Oblique", "Italic");
|
||||||
|
return _FindStyle(alternative.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -228,7 +265,7 @@ FontFamily::GetStyleMatchingFace(uint16 face) const
|
|||||||
int32 count = fStyles.CountItems();
|
int32 count = fStyles.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
FontStyle* style = fStyles.ItemAt(i);
|
FontStyle* style = fStyles.ItemAt(i);
|
||||||
|
|
||||||
if (style->Face() == face)
|
if (style->Face() == face)
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
@@ -253,6 +290,6 @@ FontFamily::Flags()
|
|||||||
fFlags |= B_HAS_TUNED_FONT;
|
fFlags |= B_HAS_TUNED_FONT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fFlags;
|
return fFlags;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku.
|
* Copyright 2001-2008, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -19,38 +19,40 @@
|
|||||||
/*!
|
/*!
|
||||||
\class FontFamily FontFamily.h
|
\class FontFamily FontFamily.h
|
||||||
\brief Class representing a collection of similar styles
|
\brief Class representing a collection of similar styles
|
||||||
|
|
||||||
FontFamily objects bring together many styles of the same face, such as
|
FontFamily objects bring together many styles of the same face, such as
|
||||||
Arial Roman, Arial Italic, Arial Bold, etc.
|
Arial Roman, Arial Italic, Arial Bold, etc.
|
||||||
*/
|
*/
|
||||||
class FontFamily {
|
class FontFamily {
|
||||||
public:
|
public:
|
||||||
FontFamily(const char* name, uint16 id);
|
FontFamily(const char* name, uint16 id);
|
||||||
virtual ~FontFamily();
|
virtual ~FontFamily();
|
||||||
|
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
bool AddStyle(FontStyle* style);
|
bool AddStyle(FontStyle* style);
|
||||||
bool RemoveStyle(FontStyle* style);
|
bool RemoveStyle(FontStyle* style);
|
||||||
|
|
||||||
FontStyle* GetStyle(const char* style) const;
|
FontStyle* GetStyle(const char* style) const;
|
||||||
FontStyle* GetStyleMatchingFace(uint16 face) const;
|
FontStyle* GetStyleMatchingFace(uint16 face) const;
|
||||||
FontStyle* GetStyleByID(uint16 face) const;
|
FontStyle* GetStyleByID(uint16 face) const;
|
||||||
|
|
||||||
uint16 ID() const
|
uint16 ID() const
|
||||||
{ return fID; }
|
{ return fID; }
|
||||||
uint32 Flags();
|
uint32 Flags();
|
||||||
|
|
||||||
bool HasStyle(const char* style) const;
|
bool HasStyle(const char* style) const;
|
||||||
int32 CountStyles() const;
|
int32 CountStyles() const;
|
||||||
FontStyle* StyleAt(int32 index) const;
|
FontStyle* StyleAt(int32 index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fName;
|
FontStyle* _FindStyle(const char* name) const;
|
||||||
BObjectList<FontStyle> fStyles;
|
|
||||||
uint16 fID;
|
BString fName;
|
||||||
uint16 fNextID;
|
BObjectList<FontStyle> fStyles;
|
||||||
uint32 fFlags;
|
uint16 fID;
|
||||||
|
uint16 fNextID;
|
||||||
|
uint32 fFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FONT_FAMILY_H_
|
#endif // FONT_FAMILY_H_
|
||||||
|
|||||||
@@ -317,11 +317,11 @@ FontManager::_LoadRecentFontMappings()
|
|||||||
// default known mappings
|
// default known mappings
|
||||||
// TODO: load them for real, and use these as a fallback
|
// TODO: load them for real, and use these as a fallback
|
||||||
|
|
||||||
_AddDefaultMapping("Bitstream Vera Sans", "Roman",
|
_AddDefaultMapping("Bitstream Vera Sans", "Roman",
|
||||||
"/boot/beos/etc/fonts/ttfonts/Vera.ttf");
|
"/boot/beos/etc/fonts/ttfonts/Vera.ttf");
|
||||||
_AddDefaultMapping("Bitstream Vera Sans", "Bold",
|
_AddDefaultMapping("Bitstream Vera Sans", "Bold",
|
||||||
"/boot/beos/etc/fonts/ttfonts/VeraBd.ttf");
|
"/boot/beos/etc/fonts/ttfonts/VeraBd.ttf");
|
||||||
_AddDefaultMapping("Bitstream Vera Sans Mono", "Roman",
|
_AddDefaultMapping("Bitstream Vera Sans Mono", "Roman",
|
||||||
"/boot/beos/etc/fonts/ttfonts/VeraMono.ttf");
|
"/boot/beos/etc/fonts/ttfonts/VeraMono.ttf");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -572,7 +572,7 @@ FontManager::_FindDirectory(node_ref& nodeRef)
|
|||||||
for (int32 i = fDirectories.CountItems(); i-- > 0;) {
|
for (int32 i = fDirectories.CountItems(); i-- > 0;) {
|
||||||
font_directory* directory = fDirectories.ItemAt(i);
|
font_directory* directory = fDirectories.ItemAt(i);
|
||||||
|
|
||||||
if (directory->directory == nodeRef)
|
if (directory->directory == nodeRef)
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,7 +768,7 @@ FontManager::_ScanFontDirectory(font_directory& fontDirectory)
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Finds and returns the first valid charmap in a font
|
\brief Finds and returns the first valid charmap in a font
|
||||||
|
|
||||||
\param face Font handle obtained from FT_Load_Face()
|
\param face Font handle obtained from FT_Load_Face()
|
||||||
\return An FT_CharMap or NULL if unsuccessful
|
\return An FT_CharMap or NULL if unsuccessful
|
||||||
*/
|
*/
|
||||||
@@ -943,8 +943,8 @@ FontManager::GetStyleByIndex(const char* familyName, int32 index)
|
|||||||
\return The FontStyle having those attributes or NULL if not available
|
\return The FontStyle having those attributes or NULL if not available
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontManager::GetStyle(const char* familyName, const char* styleName, uint16 familyID,
|
FontManager::GetStyle(const char* familyName, const char* styleName,
|
||||||
uint16 styleID, uint16 face)
|
uint16 familyID, uint16 styleID, uint16 face)
|
||||||
{
|
{
|
||||||
FontFamily* family;
|
FontFamily* family;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user